-
Notifications
You must be signed in to change notification settings - Fork 144
add support for adding/removing virtio devices during runtime #241
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Signed-off-by: Michael Zimmermann <sigmaepsilon92@gmail.com>
4096 is the value of 'COMMAND_LINE_SIZE' Signed-off-by: Michael Zimmermann <sigmaepsilon92@gmail.com>
Signed-off-by: Michael Zimmermann <sigmaepsilon92@gmail.com>
Signed-off-by: Michael Zimmermann <sigmaepsilon92@gmail.com>
tavip
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for a great patch, looks good to me, just a few coding style issues:
ret =
snprintf
is unusual for kernel code, can you please use
ret = snprintf
Also keep in mind that we don't have to split long strings, even though checkpatch.pl complains for lines over 80. We can manually override checkpatch.pl (see arch/lkl/script/checkpatch.sh) when it gets too pedantic
arch/lkl/kernel/syscalls.c
Outdated
| pdev = platform_device_alloc("virtio-mmio", PLATFORM_DEVID_AUTO); | ||
| if (!pdev) { | ||
| dev_err(&pdev->dev, | ||
| "%s: Unable to device alloc for virtio-mmio\n", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are allowed to have strings go over the 80 column limit, so we can keep compact this and the above line
tools/lkl/lib/fs.c
Outdated
| sysfs_path[strlen("/sysfs/block/vd")] += disk_id; | ||
| if ((uint32_t) disk_id >= virtio_get_num_bootdevs()) | ||
| ret = | ||
| snprintf(sysfs_path, sizeof(sysfs_path), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can merge ret and sprintf on the same line, even if the sysfs string goes beyond 80 chars limit.
tools/lkl/lib/fs.c
Outdated
| return (long)opendir_ret; | ||
|
|
||
| ret = | ||
| snprintf(sysfs_path + sysfs_path_len, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here as wel, we can merge ret and sprintf on the same line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You missed this one :)
|
@tavip I updated the commit according to your comments. |
tavip
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some more comments related to line splitting. Sorry to be pedantic, but it will help us when we get to try and upstream the code.
tools/lkl/lib/fs.c
Outdated
|
|
||
| sysfs_path[strlen("/sysfs/block/vd")] += disk_id; | ||
| if ((uint32_t) disk_id >= virtio_get_num_bootdevs()) | ||
| ret = snprintf(sysfs_path, sizeof(sysfs_path), "/sysfs/devices/platform/virtio-mmio.%d.auto", disk_id - virtio_get_num_bootdevs()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this line is very long (>100), you can split this one after the string, like:
ret = snprintf(sysfs_path, sizeof(sysfs_path), "/sysfs/devices/platform/virtio-mmio.%d.auto",
disk_id - virtio_get_num_bootdevs());
tools/lkl/lib/fs.c
Outdated
| if ((uint32_t) disk_id >= virtio_get_num_bootdevs()) | ||
| ret = snprintf(sysfs_path, sizeof(sysfs_path), "/sysfs/devices/platform/virtio-mmio.%d.auto", disk_id - virtio_get_num_bootdevs()); | ||
| else | ||
| ret = snprintf(sysfs_path, sizeof(sysfs_path), "/sysfs/devices/virtio-mmio-cmdline/virtio-mmio.%d", disk_id); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, you can split after the string.
tools/lkl/lib/fs.c
Outdated
| return (long)opendir_ret; | ||
|
|
||
| ret = | ||
| snprintf(sysfs_path + sysfs_path_len, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You missed this one :)
tools/lkl/lib/virtio.c
Outdated
| return -LKL_ENOMEM; | ||
| if (!lkl_is_running()) { | ||
| avail = sizeof(lkl_virtio_devs) - (devs - lkl_virtio_devs); | ||
| num_bytes = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here as well
tools/lkl/lib/virtio.c
Outdated
| return ret; | ||
|
|
||
| if (dev->virtio_mmio_id >= virtio_get_num_bootdevs()) | ||
| ret = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And here
tools/lkl/lib/virtio.c
Outdated
| snprintf(devname, sizeof(devname), "virtio-mmio.%d.auto", | ||
| dev->virtio_mmio_id - virtio_get_num_bootdevs()); | ||
| else | ||
| ret = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here as well
|
@tavip no problem, upstreaming LKL would be really great :) |
tavip
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All looks good now. I'll wait a day or so before merging to give people chance for more reviews.
And we don't have to rebuild with SKIP_CHECKPATCH, I just realized that failing checkpatch does not stop the test process and both the build and the testing seems fine.
|
btw 'drivers/virtio/virtio_mmio.c' throws warnings about a missing remove-function when removing a device. |
tools/lkl/lib/virtio.c
Outdated
| if (ret < 0) | ||
| return ret; | ||
|
|
||
| ret = lkl_sys_umount("/sysfs", 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If sysfs is already mounted before this function, it will umount it. Can you umount only when lkl_mount_fs returns 0?
|
|
||
| while ((dirent = lkl_readdir(dir))) { | ||
| if (startswith(dirent->d_name, prefix)) | ||
| result = strdup(dirent->d_name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
break early?
| devs += num_bytes; | ||
| dev->virtio_mmio_id = lkl_num_virtio_boot_devs++; | ||
| } else { | ||
| ret = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are several "Must be called before calling lkl_start_kernel" in lkl.h. Can you correct them?
Can I add virtio devs after lkl is running concurrently in multiple threads? At least seems register_iomem() is not thread safe. If not, can you make a comment somewhere to make it clear?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's not even thread safe before starting LKL. if that's right I think the comments should be updated in a different commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initially I thought this PR applies to all virtio devs but seems only disk is tested. It's fine then.
|
it is more like a general question but is it possible to adapt this patch to a netdev (dynamically added new virtio-net dev by a program) ? we may need to update tools/lkl/lib/net.c or else though. |
Signed-off-by: Michael Zimmermann <sigmaepsilon92@gmail.com>
This change is