Skip to content

Commit

Permalink
Merge tag 'for-linus-5.10-rc1' of git://git.kernel.org/pub/scm/linux/…
Browse files Browse the repository at this point in the history
…kernel/git/rw/uml

Pull UML updates from Richard Weinberger:

 - Improve support for non-glibc systems

 - Vector: Add support for scripting and dynamic tap devices

 - Various fixes for the vector networking driver

 - Various fixes for time travel mode

* tag 'for-linus-5.10-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rw/uml:
  um: vector: Add dynamic tap interfaces and scripting
  um: Clean up stacktrace dump
  um: Fix incorrect assumptions about max pid length
  um: Remove dead usage of TIF_IA32
  um: Remove redundant NULL check
  um: change sigio_spinlock to a mutex
  um: time-travel: Return the sequence number in ACK messages
  um: time-travel: Fix IRQ handling in time_travel_handle_message()
  um: Allow static linking for non-glibc implementations
  um: Some fixes to build UML with musl
  um: vector: Use GFP_ATOMIC under spin lock
  um: Fix null pointer dereference in vector_user_bpf
  • Loading branch information
torvalds committed Oct 18, 2020
2 parents 4297312 + f06885b commit 9453b2d
Show file tree
Hide file tree
Showing 14 changed files with 91 additions and 61 deletions.
6 changes: 3 additions & 3 deletions arch/um/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ config NR_CPUS

source "arch/$(HEADER_ARCH)/um/Kconfig"

config FORBID_STATIC_LINK
bool
config MAY_HAVE_RUNTIME_DEPS
bool

config STATIC_LINK
bool "Force a static link"
depends on !FORBID_STATIC_LINK
depends on CC_CAN_LINK_STATIC_NO_RUNTIME_DEPS || !MAY_HAVE_RUNTIME_DEPS
help
This option gives you the ability to force a static link of UML.
Normally, UML is linked as a shared binary. This is inconvenient for
Expand Down
6 changes: 3 additions & 3 deletions arch/um/drivers/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ config UML_NET_DAEMON
config UML_NET_VECTOR
bool "Vector I/O high performance network devices"
depends on UML_NET
select FORBID_STATIC_LINK
select MAY_HAVE_RUNTIME_DEPS
help
This User-Mode Linux network driver uses multi-message send
and receive functions. The host running the UML guest must have
Expand All @@ -246,7 +246,7 @@ config UML_NET_VECTOR
config UML_NET_VDE
bool "VDE transport (obsolete)"
depends on UML_NET
select FORBID_STATIC_LINK
select MAY_HAVE_RUNTIME_DEPS
help
This User-Mode Linux network transport allows one or more running
UMLs on a single host to communicate with each other and also
Expand Down Expand Up @@ -294,7 +294,7 @@ config UML_NET_MCAST
config UML_NET_PCAP
bool "pcap transport (obsolete)"
depends on UML_NET
select FORBID_STATIC_LINK
select MAY_HAVE_RUNTIME_DEPS
help
The pcap transport makes a pcap packet stream on the host look
like an ethernet device inside UML. This is useful for making
Expand Down
1 change: 1 addition & 0 deletions arch/um/drivers/daemon_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

#include <stdint.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <sys/types.h>
Expand Down
12 changes: 6 additions & 6 deletions arch/um/drivers/pcap_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ static int pcap_user_init(void *data, void *dev)
return 0;
}

static int pcap_open(void *data)
static int pcap_user_open(void *data)
{
struct pcap_data *pri = data;
__u32 netmask;
Expand All @@ -44,29 +44,29 @@ static int pcap_open(void *data)
if (pri->filter != NULL) {
err = dev_netmask(pri->dev, &netmask);
if (err < 0) {
printk(UM_KERN_ERR "pcap_open : dev_netmask failed\n");
printk(UM_KERN_ERR "pcap_user_open : dev_netmask failed\n");
return -EIO;
}

pri->compiled = uml_kmalloc(sizeof(struct bpf_program),
UM_GFP_KERNEL);
if (pri->compiled == NULL) {
printk(UM_KERN_ERR "pcap_open : kmalloc failed\n");
printk(UM_KERN_ERR "pcap_user_open : kmalloc failed\n");
return -ENOMEM;
}

err = pcap_compile(pri->pcap,
(struct bpf_program *) pri->compiled,
pri->filter, pri->optimize, netmask);
if (err < 0) {
printk(UM_KERN_ERR "pcap_open : pcap_compile failed - "
printk(UM_KERN_ERR "pcap_user_open : pcap_compile failed - "
"'%s'\n", pcap_geterr(pri->pcap));
goto out;
}

err = pcap_setfilter(pri->pcap, pri->compiled);
if (err < 0) {
printk(UM_KERN_ERR "pcap_open : pcap_setfilter "
printk(UM_KERN_ERR "pcap_user_open : pcap_setfilter "
"failed - '%s'\n", pcap_geterr(pri->pcap));
goto out;
}
Expand Down Expand Up @@ -127,7 +127,7 @@ int pcap_user_read(int fd, void *buffer, int len, struct pcap_data *pri)

const struct net_user_info pcap_user_info = {
.init = pcap_user_init,
.open = pcap_open,
.open = pcap_user_open,
.close = NULL,
.remove = pcap_remove,
.add_address = NULL,
Expand Down
2 changes: 1 addition & 1 deletion arch/um/drivers/slip_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <errno.h>
#include <fcntl.h>
#include <string.h>
#include <sys/termios.h>
#include <termios.h>
#include <sys/wait.h>
#include <net_user.h>
#include <os.h>
Expand Down
4 changes: 2 additions & 2 deletions arch/um/drivers/vector_kern.c
Original file line number Diff line number Diff line change
Expand Up @@ -1403,7 +1403,7 @@ static int vector_net_load_bpf_flash(struct net_device *dev,
kfree(vp->bpf->filter);
vp->bpf->filter = NULL;
} else {
vp->bpf = kmalloc(sizeof(struct sock_fprog), GFP_KERNEL);
vp->bpf = kmalloc(sizeof(struct sock_fprog), GFP_ATOMIC);
if (vp->bpf == NULL) {
netdev_err(dev, "failed to allocate memory for firmware\n");
goto flash_fail;
Expand All @@ -1415,7 +1415,7 @@ static int vector_net_load_bpf_flash(struct net_device *dev,
if (request_firmware(&fw, efl->data, &vdevice->pdev.dev))
goto flash_fail;

vp->bpf->filter = kmemdup(fw->data, fw->size, GFP_KERNEL);
vp->bpf->filter = kmemdup(fw->data, fw->size, GFP_ATOMIC);
if (!vp->bpf->filter)
goto free_buffer;

Expand Down
71 changes: 54 additions & 17 deletions arch/um/drivers/vector_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
#include <fcntl.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <net/ethernet.h>
#include <netinet/ip.h>
#include <netinet/ether.h>
#include <linux/if_ether.h>
#include <linux/if_packet.h>
#include <sys/wait.h>
Expand All @@ -39,6 +37,7 @@
#define ID_MAX 2

#define TOKEN_IFNAME "ifname"
#define TOKEN_SCRIPT "ifup"

#define TRANS_RAW "raw"
#define TRANS_RAW_LEN strlen(TRANS_RAW)
Expand All @@ -55,6 +54,9 @@

#define MAX_UN_LEN 107

static const char padchar[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
static const char *template = "tapXXXXXX";

/* This is very ugly and brute force lookup, but it is done
* only once at initialization so not worth doing hashes or
* anything more intelligent
Expand Down Expand Up @@ -191,16 +193,21 @@ static int create_raw_fd(char *iface, int flags, int proto)
return err;
}


static struct vector_fds *user_init_tap_fds(struct arglist *ifspec)
{
int fd = -1;
int fd = -1, i;
char *iface;
struct vector_fds *result = NULL;
bool dynamic = false;
char dynamic_ifname[IFNAMSIZ];
char *argv[] = {NULL, NULL, NULL, NULL};

iface = uml_vector_fetch_arg(ifspec, TOKEN_IFNAME);
if (iface == NULL) {
printk(UM_KERN_ERR "uml_tap: failed to parse interface spec\n");
goto tap_cleanup;
dynamic = true;
iface = dynamic_ifname;
srand(getpid());
}

result = uml_kmalloc(sizeof(struct vector_fds), UM_GFP_KERNEL);
Expand All @@ -214,14 +221,30 @@ static struct vector_fds *user_init_tap_fds(struct arglist *ifspec)
result->remote_addr_size = 0;

/* TAP */
do {
if (dynamic) {
strcpy(iface, template);
for (i = 0; i < strlen(iface); i++) {
if (iface[i] == 'X') {
iface[i] = padchar[rand() % strlen(padchar)];
}
}
}
fd = create_tap_fd(iface);
if ((fd < 0) && (!dynamic)) {
printk(UM_KERN_ERR "uml_tap: failed to create tun interface\n");
goto tap_cleanup;
}
result->tx_fd = fd;
result->rx_fd = fd;
} while (fd < 0);

fd = create_tap_fd(iface);
if (fd < 0) {
printk(UM_KERN_ERR "uml_tap: failed to create tun interface\n");
goto tap_cleanup;
argv[0] = uml_vector_fetch_arg(ifspec, TOKEN_SCRIPT);
if (argv[0]) {
argv[1] = iface;
run_helper(NULL, NULL, argv);
}
result->tx_fd = fd;
result->rx_fd = fd;

return result;
tap_cleanup:
printk(UM_KERN_ERR "user_init_tap: init failed, error %d", fd);
Expand All @@ -233,6 +256,7 @@ static struct vector_fds *user_init_hybrid_fds(struct arglist *ifspec)
{
char *iface;
struct vector_fds *result = NULL;
char *argv[] = {NULL, NULL, NULL, NULL};

iface = uml_vector_fetch_arg(ifspec, TOKEN_IFNAME);
if (iface == NULL) {
Expand Down Expand Up @@ -266,6 +290,12 @@ static struct vector_fds *user_init_hybrid_fds(struct arglist *ifspec)
"uml_tap: failed to create paired raw socket: %i\n", result->rx_fd);
goto hybrid_cleanup;
}

argv[0] = uml_vector_fetch_arg(ifspec, TOKEN_SCRIPT);
if (argv[0]) {
argv[1] = iface;
run_helper(NULL, NULL, argv);
}
return result;
hybrid_cleanup:
printk(UM_KERN_ERR "user_init_hybrid: init failed");
Expand Down Expand Up @@ -332,7 +362,7 @@ static struct vector_fds *user_init_unix_fds(struct arglist *ifspec, int id)
}
switch (id) {
case ID_BESS:
if (connect(fd, remote_addr, sizeof(struct sockaddr_un)) < 0) {
if (connect(fd, (const struct sockaddr *) remote_addr, sizeof(struct sockaddr_un)) < 0) {
printk(UM_KERN_ERR "bess open:cannot connect to %s %i", remote_addr->sun_path, -errno);
goto unix_cleanup;
}
Expand Down Expand Up @@ -399,8 +429,7 @@ static struct vector_fds *user_init_fd_fds(struct arglist *ifspec)
fd_cleanup:
if (fd >= 0)
os_close_file(fd);
if (result != NULL)
kfree(result);
kfree(result);
return NULL;
}

Expand All @@ -410,6 +439,7 @@ static struct vector_fds *user_init_raw_fds(struct arglist *ifspec)
int err = -ENOMEM;
char *iface;
struct vector_fds *result = NULL;
char *argv[] = {NULL, NULL, NULL, NULL};

iface = uml_vector_fetch_arg(ifspec, TOKEN_IFNAME);
if (iface == NULL)
Expand All @@ -432,6 +462,11 @@ static struct vector_fds *user_init_raw_fds(struct arglist *ifspec)
result->remote_addr = NULL;
result->remote_addr_size = 0;
}
argv[0] = uml_vector_fetch_arg(ifspec, TOKEN_SCRIPT);
if (argv[0]) {
argv[1] = iface;
run_helper(NULL, NULL, argv);
}
return result;
raw_cleanup:
printk(UM_KERN_ERR "user_init_raw: init failed, error %d", err);
Expand Down Expand Up @@ -789,10 +824,12 @@ void *uml_vector_user_bpf(char *filename)
return false;
}
bpf_prog = uml_kmalloc(sizeof(struct sock_fprog), UM_GFP_KERNEL);
if (bpf_prog != NULL) {
bpf_prog->len = statbuf.st_size / sizeof(struct sock_filter);
bpf_prog->filter = NULL;
if (bpf_prog == NULL) {
printk(KERN_ERR "Failed to allocate bpf prog buffer");
return NULL;
}
bpf_prog->len = statbuf.st_size / sizeof(struct sock_filter);
bpf_prog->filter = NULL;
ffd = os_open_file(filename, of_read(OPENFLAGS()), 0);
if (ffd < 0) {
printk(KERN_ERR "Error %d opening bpf file", -errno);
Expand Down
6 changes: 3 additions & 3 deletions arch/um/kernel/sigio.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ int write_sigio_irq(int fd)
}

/* These are called from os-Linux/sigio.c to protect its pollfds arrays. */
static DEFINE_SPINLOCK(sigio_spinlock);
static DEFINE_MUTEX(sigio_mutex);

void sigio_lock(void)
{
spin_lock(&sigio_spinlock);
mutex_lock(&sigio_mutex);
}

void sigio_unlock(void)
{
spin_unlock(&sigio_spinlock);
mutex_unlock(&sigio_mutex);
}
4 changes: 1 addition & 3 deletions arch/um/kernel/sysrq.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,10 @@ void show_stack(struct task_struct *task, unsigned long *stack,
if (kstack_end(stack))
break;
if (i && ((i % STACKSLOTS_PER_LINE) == 0))
printk("%s\n", loglvl);
pr_cont("\n");
pr_cont(" %08lx", *stack++);
}
printk("%s\n", loglvl);

printk("%sCall Trace:\n", loglvl);
dump_trace(current, &stackops, (void *)loglvl);
printk("%s\n", loglvl);
}
15 changes: 10 additions & 5 deletions arch/um/kernel/time.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,17 @@ static void time_travel_handle_message(struct um_timetravel_msg *msg,
* read of the message and write of the ACK.
*/
if (mode != TTMH_READ) {
bool disabled = irqs_disabled();

BUG_ON(mode == TTMH_IDLE && !disabled);

if (disabled)
local_irq_enable();
while (os_poll(1, &time_travel_ext_fd) != 0) {
if (mode == TTMH_IDLE) {
BUG_ON(!irqs_disabled());
local_irq_enable();
local_irq_disable();
}
/* nothing */
}
if (disabled)
local_irq_disable();
}

ret = os_read_file(time_travel_ext_fd, msg, sizeof(*msg));
Expand All @@ -102,6 +106,7 @@ static void time_travel_handle_message(struct um_timetravel_msg *msg,
break;
}

resp.seq = msg->seq;
os_write_file(time_travel_ext_fd, &resp, sizeof(resp));
}

Expand Down
8 changes: 4 additions & 4 deletions arch/um/os-Linux/umid.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ static int remove_files_and_dir(char *dir)
while ((ent = readdir(directory)) != NULL) {
if (!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, ".."))
continue;
len = strlen(dir) + sizeof("/") + strlen(ent->d_name) + 1;
len = strlen(dir) + strlen("/") + strlen(ent->d_name) + 1;
if (len > sizeof(file)) {
ret = -E2BIG;
goto out;
Expand Down Expand Up @@ -135,7 +135,7 @@ static int remove_files_and_dir(char *dir)
*/
static inline int is_umdir_used(char *dir)
{
char pid[sizeof("nnnnn\0")], *end, *file;
char pid[sizeof("nnnnnnnnn")], *end, *file;
int dead, fd, p, n, err;
size_t filelen;

Expand Down Expand Up @@ -217,10 +217,10 @@ static int umdir_take_if_dead(char *dir)

static void __init create_pid_file(void)
{
char pid[sizeof("nnnnn\0")], *file;
char pid[sizeof("nnnnnnnnn")], *file;
int fd, n;

n = strlen(uml_dir) + UMID_LEN + sizeof("/pid\0");
n = strlen(uml_dir) + UMID_LEN + sizeof("/pid");
file = malloc(n);
if (!file)
return;
Expand Down
2 changes: 1 addition & 1 deletion arch/um/os-Linux/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <signal.h>
#include <string.h>
#include <termios.h>
#include <wait.h>
#include <sys/wait.h>
#include <sys/mman.h>
#include <sys/utsname.h>
#include <init.h>
Expand Down
Loading

0 comments on commit 9453b2d

Please sign in to comment.