Skip to content

Conversation

@M1cha
Copy link

@M1cha M1cha commented Sep 20, 2016

This change is Reviewable

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>
Copy link
Member

@tavip tavip left a 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

pdev = platform_device_alloc("virtio-mmio", PLATFORM_DEVID_AUTO);
if (!pdev) {
dev_err(&pdev->dev,
"%s: Unable to device alloc for virtio-mmio\n",
Copy link
Member

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

sysfs_path[strlen("/sysfs/block/vd")] += disk_id;
if ((uint32_t) disk_id >= virtio_get_num_bootdevs())
ret =
snprintf(sysfs_path, sizeof(sysfs_path),
Copy link
Member

@tavip tavip Sep 20, 2016

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.

return (long)opendir_ret;

ret =
snprintf(sysfs_path + sysfs_path_len,
Copy link
Member

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You missed this one :)

@M1cha
Copy link
Author

M1cha commented Sep 20, 2016

@tavip I updated the commit according to your comments.

Copy link
Member

@tavip tavip left a 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.


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());
Copy link
Member

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());

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);
Copy link
Member

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.

return (long)opendir_ret;

ret =
snprintf(sysfs_path + sysfs_path_len,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You missed this one :)

return -LKL_ENOMEM;
if (!lkl_is_running()) {
avail = sizeof(lkl_virtio_devs) - (devs - lkl_virtio_devs);
num_bytes =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here as well

return ret;

if (dev->virtio_mmio_id >= virtio_get_num_bootdevs())
ret =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here

snprintf(devname, sizeof(devname), "virtio-mmio.%d.auto",
dev->virtio_mmio_id - virtio_get_num_bootdevs());
else
ret =
Copy link
Member

@tavip tavip Sep 20, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here as well

@M1cha
Copy link
Author

M1cha commented Sep 20, 2016

@tavip no problem, upstreaming LKL would be really great :)

Copy link
Member

@tavip tavip left a 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.

@M1cha
Copy link
Author

M1cha commented Sep 20, 2016

btw 'drivers/virtio/virtio_mmio.c' throws warnings about a missing remove-function when removing a device.
This definitely looks like a upstream bug. I locally added an empty function to 'vm_dev->vdev.dev.release' to silence the warnings. I dunno if and what kind of cleanup this driver needs.

if (ret < 0)
return ret;

ret = lkl_sys_umount("/sysfs", 0);
Copy link
Member

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);
Copy link
Member

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 =
Copy link
Member

@liuyuan10 liuyuan10 Sep 20, 2016

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?

Copy link
Author

@M1cha M1cha Sep 21, 2016

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.

Copy link
Member

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.

@thehajime
Copy link
Member

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants