Skip to contentSkip to conversation

Is ivshmem's test for unix domain client socket valid?

Qemu-devel Markus Armbruster 2 participants 5 messages Nov 20, 2015 – Nov 24, 2015

lore
Share & tools
lore
#0 lore raw

Looks rather fishy:

        if (strncmp(s->server_chr->filename, "unix:", 5)) {
            error_setg(errp, "chardev is not a unix client socket");
            return;
        }

Paolo, is this reliable? Is it the proper way to check?

#1 lore raw
Quoted 8 lines · Markus Armbruster

Looks rather fishy:

        if (strncmp(s->server_chr->filename, "unix:", 5)) {
            error_setg(errp, "chardev is not a unix client socket");
            return;
        }

Paolo, is this reliable?

Yes, though by total chance (which is already a curious definition of reliability). If you create "-chardev file,path=unix:foo", chr->filename ends up with "file" because only pty and socket chardevs set chr->filename. Everything else does not set it, and the field is thus set to the default---the backend name.

Quoted 1 line

Is it the proper way to check?

It's the only one, which makes it the most proper too. Sarcasm is intentional.

Paolo

#2 lore raw

[Qemu-devel] Is ivshmem's use of qemu_chr_open_eventfd() kosher? (was: Is ivshmem's test for unix domain client socket valid?)

Quoted 16 lines · Paolo Bonzini
Quoted 8 lines · Markus Armbruster

Looks rather fishy:

        if (strncmp(s->server_chr->filename, "unix:", 5)) {
            error_setg(errp, "chardev is not a unix client socket");
            return;
        }

Paolo, is this reliable?

Yes, though by total chance (which is already a curious definition of reliability). If you create "-chardev file,path=unix:foo", chr->filename ends up with "file" because only pty and socket chardevs set chr->filename. Everything else does not set it, and the field is thus set to the default---the backend name.

Quoted 4 lines
Quoted 1 line

Is it the proper way to check?

It's the only one, which makes it the most proper too. Sarcasm is intentional.

FIXME added in my local ivshmem for-2.5 branch.

Next question: ivshmem creates a character backend in create_eventfd_chr_device() like this

        chr = qemu_chr_open_eventfd(eventfd);

on behalf of setup_interrupt()

    static void setup_interrupt(IVShmemState *s, int vector)
    {
        EventNotifier *n = &s->peers[s->vm_id].eventfds[vector];
        bool with_irqfd = kvm_msi_via_irqfd_enabled() &&
            ivshmem_has_feature(s, IVSHMEM_MSI);
    [...]
        if (!with_irqfd) {
            IVSHMEM_DPRINTF("with eventfd");
            s->eventfd_chr[vector] = create_eventfd_chr_device(s, n, vector);
        } else [...]

Device models (a.k.a. frontends) are normally not supposed to create backends by themselves, because it blurs the separation between frontend and backend, and commonly denies the user the opportunity to fully configure the backend.

Most other devices that do, as far as I can see, create null chardevs when the user didn't specify one. That's fine. Exceptions:

* xen_console.c's con_init()

Part of Xen's bigger "get configuration from XenStore" exception.

* dev-serial.c's usb_serial_init() and usb_braille_init()

Legacy -usbdevice.

None of them qualifies as precedence.

Is ivshmem's implicit creation of a backend appropriate?

I wish I had an easy way to find device models doing something no other does.

#3 lore raw

Re: [Qemu-devel] Is ivshmem's use of qemu_chr_open_eventfd() kosher?

Quoted 4 lines · Markus Armbruster

Device models (a.k.a. frontends) are normally not supposed to create backends by themselves, because it blurs the separation between frontend and backend, and commonly denies the user the opportunity to fully configure the backend.

Right, but here the fd comes from the ivshmem server. It's just using the chardev API internally. It could be changed with little effort to use a GSource or qemu_set_fd_handler.

Paolo

#4 lore raw

Re: [Qemu-devel] Is ivshmem's use of qemu_chr_open_eventfd() kosher?

Quoted 9 lines · Paolo Bonzini
Quoted 4 lines · Markus Armbruster

Device models (a.k.a. frontends) are normally not supposed to create backends by themselves, because it blurs the separation between frontend and backend, and commonly denies the user the opportunity to fully configure the backend.

Right, but here the fd comes from the ivshmem server. It's just using the chardev API internally. It could be changed with little effort to use a GSource or qemu_set_fd_handler.

Thanks!