Skip to content

Commit 9453b2d

Browse files
committed
Merge tag 'for-linus-5.10-rc1' of git://git.kernel.org/pub/scm/linux/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
2 parents 4297312 + f06885b commit 9453b2d

File tree

14 files changed

+91
-61
lines changed

14 files changed

+91
-61
lines changed

arch/um/Kconfig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,12 @@ config NR_CPUS
6262

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

65-
config FORBID_STATIC_LINK
66-
bool
65+
config MAY_HAVE_RUNTIME_DEPS
66+
bool
6767

6868
config STATIC_LINK
6969
bool "Force a static link"
70-
depends on !FORBID_STATIC_LINK
70+
depends on CC_CAN_LINK_STATIC_NO_RUNTIME_DEPS || !MAY_HAVE_RUNTIME_DEPS
7171
help
7272
This option gives you the ability to force a static link of UML.
7373
Normally, UML is linked as a shared binary. This is inconvenient for

arch/um/drivers/Kconfig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ config UML_NET_DAEMON
234234
config UML_NET_VECTOR
235235
bool "Vector I/O high performance network devices"
236236
depends on UML_NET
237-
select FORBID_STATIC_LINK
237+
select MAY_HAVE_RUNTIME_DEPS
238238
help
239239
This User-Mode Linux network driver uses multi-message send
240240
and receive functions. The host running the UML guest must have
@@ -246,7 +246,7 @@ config UML_NET_VECTOR
246246
config UML_NET_VDE
247247
bool "VDE transport (obsolete)"
248248
depends on UML_NET
249-
select FORBID_STATIC_LINK
249+
select MAY_HAVE_RUNTIME_DEPS
250250
help
251251
This User-Mode Linux network transport allows one or more running
252252
UMLs on a single host to communicate with each other and also
@@ -294,7 +294,7 @@ config UML_NET_MCAST
294294
config UML_NET_PCAP
295295
bool "pcap transport (obsolete)"
296296
depends on UML_NET
297-
select FORBID_STATIC_LINK
297+
select MAY_HAVE_RUNTIME_DEPS
298298
help
299299
The pcap transport makes a pcap packet stream on the host look
300300
like an ethernet device inside UML. This is useful for making

arch/um/drivers/daemon_user.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88

99
#include <stdint.h>
10+
#include <string.h>
1011
#include <unistd.h>
1112
#include <errno.h>
1213
#include <sys/types.h>

arch/um/drivers/pcap_user.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ static int pcap_user_init(void *data, void *dev)
3232
return 0;
3333
}
3434

35-
static int pcap_open(void *data)
35+
static int pcap_user_open(void *data)
3636
{
3737
struct pcap_data *pri = data;
3838
__u32 netmask;
@@ -44,29 +44,29 @@ static int pcap_open(void *data)
4444
if (pri->filter != NULL) {
4545
err = dev_netmask(pri->dev, &netmask);
4646
if (err < 0) {
47-
printk(UM_KERN_ERR "pcap_open : dev_netmask failed\n");
47+
printk(UM_KERN_ERR "pcap_user_open : dev_netmask failed\n");
4848
return -EIO;
4949
}
5050

5151
pri->compiled = uml_kmalloc(sizeof(struct bpf_program),
5252
UM_GFP_KERNEL);
5353
if (pri->compiled == NULL) {
54-
printk(UM_KERN_ERR "pcap_open : kmalloc failed\n");
54+
printk(UM_KERN_ERR "pcap_user_open : kmalloc failed\n");
5555
return -ENOMEM;
5656
}
5757

5858
err = pcap_compile(pri->pcap,
5959
(struct bpf_program *) pri->compiled,
6060
pri->filter, pri->optimize, netmask);
6161
if (err < 0) {
62-
printk(UM_KERN_ERR "pcap_open : pcap_compile failed - "
62+
printk(UM_KERN_ERR "pcap_user_open : pcap_compile failed - "
6363
"'%s'\n", pcap_geterr(pri->pcap));
6464
goto out;
6565
}
6666

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

128128
const struct net_user_info pcap_user_info = {
129129
.init = pcap_user_init,
130-
.open = pcap_open,
130+
.open = pcap_user_open,
131131
.close = NULL,
132132
.remove = pcap_remove,
133133
.add_address = NULL,

arch/um/drivers/slip_user.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <errno.h>
1010
#include <fcntl.h>
1111
#include <string.h>
12-
#include <sys/termios.h>
12+
#include <termios.h>
1313
#include <sys/wait.h>
1414
#include <net_user.h>
1515
#include <os.h>

arch/um/drivers/vector_kern.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,7 +1403,7 @@ static int vector_net_load_bpf_flash(struct net_device *dev,
14031403
kfree(vp->bpf->filter);
14041404
vp->bpf->filter = NULL;
14051405
} else {
1406-
vp->bpf = kmalloc(sizeof(struct sock_fprog), GFP_KERNEL);
1406+
vp->bpf = kmalloc(sizeof(struct sock_fprog), GFP_ATOMIC);
14071407
if (vp->bpf == NULL) {
14081408
netdev_err(dev, "failed to allocate memory for firmware\n");
14091409
goto flash_fail;
@@ -1415,7 +1415,7 @@ static int vector_net_load_bpf_flash(struct net_device *dev,
14151415
if (request_firmware(&fw, efl->data, &vdevice->pdev.dev))
14161416
goto flash_fail;
14171417

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

arch/um/drivers/vector_user.c

Lines changed: 54 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@
1818
#include <fcntl.h>
1919
#include <sys/socket.h>
2020
#include <sys/un.h>
21-
#include <net/ethernet.h>
2221
#include <netinet/ip.h>
23-
#include <netinet/ether.h>
2422
#include <linux/if_ether.h>
2523
#include <linux/if_packet.h>
2624
#include <sys/wait.h>
@@ -39,6 +37,7 @@
3937
#define ID_MAX 2
4038

4139
#define TOKEN_IFNAME "ifname"
40+
#define TOKEN_SCRIPT "ifup"
4241

4342
#define TRANS_RAW "raw"
4443
#define TRANS_RAW_LEN strlen(TRANS_RAW)
@@ -55,6 +54,9 @@
5554

5655
#define MAX_UN_LEN 107
5756

57+
static const char padchar[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
58+
static const char *template = "tapXXXXXX";
59+
5860
/* This is very ugly and brute force lookup, but it is done
5961
* only once at initialization so not worth doing hashes or
6062
* anything more intelligent
@@ -191,16 +193,21 @@ static int create_raw_fd(char *iface, int flags, int proto)
191193
return err;
192194
}
193195

196+
194197
static struct vector_fds *user_init_tap_fds(struct arglist *ifspec)
195198
{
196-
int fd = -1;
199+
int fd = -1, i;
197200
char *iface;
198201
struct vector_fds *result = NULL;
202+
bool dynamic = false;
203+
char dynamic_ifname[IFNAMSIZ];
204+
char *argv[] = {NULL, NULL, NULL, NULL};
199205

200206
iface = uml_vector_fetch_arg(ifspec, TOKEN_IFNAME);
201207
if (iface == NULL) {
202-
printk(UM_KERN_ERR "uml_tap: failed to parse interface spec\n");
203-
goto tap_cleanup;
208+
dynamic = true;
209+
iface = dynamic_ifname;
210+
srand(getpid());
204211
}
205212

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

216223
/* TAP */
224+
do {
225+
if (dynamic) {
226+
strcpy(iface, template);
227+
for (i = 0; i < strlen(iface); i++) {
228+
if (iface[i] == 'X') {
229+
iface[i] = padchar[rand() % strlen(padchar)];
230+
}
231+
}
232+
}
233+
fd = create_tap_fd(iface);
234+
if ((fd < 0) && (!dynamic)) {
235+
printk(UM_KERN_ERR "uml_tap: failed to create tun interface\n");
236+
goto tap_cleanup;
237+
}
238+
result->tx_fd = fd;
239+
result->rx_fd = fd;
240+
} while (fd < 0);
217241

218-
fd = create_tap_fd(iface);
219-
if (fd < 0) {
220-
printk(UM_KERN_ERR "uml_tap: failed to create tun interface\n");
221-
goto tap_cleanup;
242+
argv[0] = uml_vector_fetch_arg(ifspec, TOKEN_SCRIPT);
243+
if (argv[0]) {
244+
argv[1] = iface;
245+
run_helper(NULL, NULL, argv);
222246
}
223-
result->tx_fd = fd;
224-
result->rx_fd = fd;
247+
225248
return result;
226249
tap_cleanup:
227250
printk(UM_KERN_ERR "user_init_tap: init failed, error %d", fd);
@@ -233,6 +256,7 @@ static struct vector_fds *user_init_hybrid_fds(struct arglist *ifspec)
233256
{
234257
char *iface;
235258
struct vector_fds *result = NULL;
259+
char *argv[] = {NULL, NULL, NULL, NULL};
236260

237261
iface = uml_vector_fetch_arg(ifspec, TOKEN_IFNAME);
238262
if (iface == NULL) {
@@ -266,6 +290,12 @@ static struct vector_fds *user_init_hybrid_fds(struct arglist *ifspec)
266290
"uml_tap: failed to create paired raw socket: %i\n", result->rx_fd);
267291
goto hybrid_cleanup;
268292
}
293+
294+
argv[0] = uml_vector_fetch_arg(ifspec, TOKEN_SCRIPT);
295+
if (argv[0]) {
296+
argv[1] = iface;
297+
run_helper(NULL, NULL, argv);
298+
}
269299
return result;
270300
hybrid_cleanup:
271301
printk(UM_KERN_ERR "user_init_hybrid: init failed");
@@ -332,7 +362,7 @@ static struct vector_fds *user_init_unix_fds(struct arglist *ifspec, int id)
332362
}
333363
switch (id) {
334364
case ID_BESS:
335-
if (connect(fd, remote_addr, sizeof(struct sockaddr_un)) < 0) {
365+
if (connect(fd, (const struct sockaddr *) remote_addr, sizeof(struct sockaddr_un)) < 0) {
336366
printk(UM_KERN_ERR "bess open:cannot connect to %s %i", remote_addr->sun_path, -errno);
337367
goto unix_cleanup;
338368
}
@@ -399,8 +429,7 @@ static struct vector_fds *user_init_fd_fds(struct arglist *ifspec)
399429
fd_cleanup:
400430
if (fd >= 0)
401431
os_close_file(fd);
402-
if (result != NULL)
403-
kfree(result);
432+
kfree(result);
404433
return NULL;
405434
}
406435

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

414444
iface = uml_vector_fetch_arg(ifspec, TOKEN_IFNAME);
415445
if (iface == NULL)
@@ -432,6 +462,11 @@ static struct vector_fds *user_init_raw_fds(struct arglist *ifspec)
432462
result->remote_addr = NULL;
433463
result->remote_addr_size = 0;
434464
}
465+
argv[0] = uml_vector_fetch_arg(ifspec, TOKEN_SCRIPT);
466+
if (argv[0]) {
467+
argv[1] = iface;
468+
run_helper(NULL, NULL, argv);
469+
}
435470
return result;
436471
raw_cleanup:
437472
printk(UM_KERN_ERR "user_init_raw: init failed, error %d", err);
@@ -789,10 +824,12 @@ void *uml_vector_user_bpf(char *filename)
789824
return false;
790825
}
791826
bpf_prog = uml_kmalloc(sizeof(struct sock_fprog), UM_GFP_KERNEL);
792-
if (bpf_prog != NULL) {
793-
bpf_prog->len = statbuf.st_size / sizeof(struct sock_filter);
794-
bpf_prog->filter = NULL;
827+
if (bpf_prog == NULL) {
828+
printk(KERN_ERR "Failed to allocate bpf prog buffer");
829+
return NULL;
795830
}
831+
bpf_prog->len = statbuf.st_size / sizeof(struct sock_filter);
832+
bpf_prog->filter = NULL;
796833
ffd = os_open_file(filename, of_read(OPENFLAGS()), 0);
797834
if (ffd < 0) {
798835
printk(KERN_ERR "Error %d opening bpf file", -errno);

arch/um/kernel/sigio.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ int write_sigio_irq(int fd)
3535
}
3636

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

4040
void sigio_lock(void)
4141
{
42-
spin_lock(&sigio_spinlock);
42+
mutex_lock(&sigio_mutex);
4343
}
4444

4545
void sigio_unlock(void)
4646
{
47-
spin_unlock(&sigio_spinlock);
47+
mutex_unlock(&sigio_mutex);
4848
}

arch/um/kernel/sysrq.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,10 @@ void show_stack(struct task_struct *task, unsigned long *stack,
4747
if (kstack_end(stack))
4848
break;
4949
if (i && ((i % STACKSLOTS_PER_LINE) == 0))
50-
printk("%s\n", loglvl);
50+
pr_cont("\n");
5151
pr_cont(" %08lx", *stack++);
5252
}
53-
printk("%s\n", loglvl);
5453

5554
printk("%sCall Trace:\n", loglvl);
5655
dump_trace(current, &stackops, (void *)loglvl);
57-
printk("%s\n", loglvl);
5856
}

arch/um/kernel/time.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,17 @@ static void time_travel_handle_message(struct um_timetravel_msg *msg,
7070
* read of the message and write of the ACK.
7171
*/
7272
if (mode != TTMH_READ) {
73+
bool disabled = irqs_disabled();
74+
75+
BUG_ON(mode == TTMH_IDLE && !disabled);
76+
77+
if (disabled)
78+
local_irq_enable();
7379
while (os_poll(1, &time_travel_ext_fd) != 0) {
74-
if (mode == TTMH_IDLE) {
75-
BUG_ON(!irqs_disabled());
76-
local_irq_enable();
77-
local_irq_disable();
78-
}
80+
/* nothing */
7981
}
82+
if (disabled)
83+
local_irq_disable();
8084
}
8185

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

109+
resp.seq = msg->seq;
105110
os_write_file(time_travel_ext_fd, &resp, sizeof(resp));
106111
}
107112

0 commit comments

Comments
 (0)