All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michael Tokarev <mjt@tls.msk.ru>
To: Damien Millescamps <damien.millescamps@6wind.com>
Cc: qemu-trivial@nongnu.org, qemu-devel@nongnu.org
Subject: Re: [Qemu-trivial] [PATCH] ivshmem: allow the sharing of hugepages
Date: Sat, 14 Sep 2013 13:36:14 +0400	[thread overview]
Message-ID: <52342E0E.3010700@msgid.tls.msk.ru> (raw)
In-Reply-To: <1379010228-15324-1-git-send-email-damien.millescamps@6wind.com>

12.09.2013 22:23, Damien Millescamps wrote:
> According to shm_open specifications:
>
>   A shared memory object should be identified by a name of the form /somename;
>   that is, a null-terminated string of up to NAME_MAX (i.e., 255) characters
>   consisting of an initial slash, followed by one or more characters, none of
>   which are slashes.
>
> This patch permits to share memory areas that do not specifically belong to
> /dev/shmem.
>
> A use case for this patch is sharing huge pages available through a
> hugetlbfs mountpoint.
>
> Signed-off-by: Damien Millescamps <damien.millescamps@6wind.com>
> ---
>   hw/misc/ivshmem.c |   16 +++++++++++++++-
>   1 files changed, 15 insertions(+), 1 deletions(-)
>
> diff --git a/hw/misc/ivshmem.c b/hw/misc/ivshmem.c
> index 2838866..9020bb2 100644
> --- a/hw/misc/ivshmem.c
> +++ b/hw/misc/ivshmem.c
> @@ -751,9 +751,23 @@ static int pci_ivshmem_init(PCIDevice *dev)
>
>           IVSHMEM_DPRINTF("using shm_open (shm object = %s)\n", s->shmobj);
>
> +        /*
> +         * A shared memory object should be identified by a name of the form /somename;
> +         * that is, a null-terminated string of up to NAME_MAX (i.e., 255) characters
> +         * consisting of an initial slash, followed by one or more characters, none of
> +         * which are slashes.

It'd be nice to give a hint about where this definition comes from.

And once you look at shm_open(3), you'll notice that this paragraph
is prefixed with "For portable use", and reads:

  For portable use, a shared memory object should be identified by a name of the
  form  /somename; that is, a null-terminated string of up to NAME_MAX (i.e., 255)
  characters consisting of an initial slash, followed by one or more characters,
  none of which are slashes.

That to say, this is not a _definition_ of a shared memory object, it is just
a suggested name syntax, suggested purely for portability.  In other words,
there may be other acceptable syntaxes for it.

So as the result, I'm not sure this approach is valid.  Maybe we should
always try shared first and create-new second?  I dunno.

Note that whole thing - using shared memory object like this - may lead
to surprizes at least, -- users who previously expected one behavour now
see different behavour.  Most likely the old behavour wasn't correct.

At least this should be documented somewhere in user-visible part of
ivshmem, so users will have an ides when objects will be shared and
when truncated.

> +         */
> +        if (s->shmobj && s->shmobj[0] == '/' && strstr(&s->shmobj[1], "/")) {

Here you're testing for s->shmobj, but before, the code were referencing
it directly as an argument for shm_open().  Can it be NULL in this place?

It is a somewhat minor nitpick, but it'd be not nice to spread such tests
(for NULLness) where the object can't be NULL and to confuse readers.

> +            /* This can't be a shared memory object. */
> +            fd = open(s->shmobj, O_RDWR);
> +            if (fd < 0) {
> +                perror("ivshmem - open");
> +                exit(-1);
> +            }
> +        }
>           /* try opening with O_EXCL and if it succeeds zero the memory
>            * by truncating to 0 */
> -        if ((fd = shm_open(s->shmobj, O_CREAT|O_RDWR|O_EXCL,
> +        else if ((fd = shm_open(s->shmobj, O_CREAT|O_RDWR|O_EXCL,
>                           S_IRWXU|S_IRWXG|S_IRWXO)) > 0) {
>              /* truncate file to length PCI device's memory */
>               if (ftruncate(fd, s->ivshmem_size) != 0) {
>

Thanks,

/mjt


WARNING: multiple messages have this Message-ID (diff)
From: Michael Tokarev <mjt@tls.msk.ru>
To: Damien Millescamps <damien.millescamps@6wind.com>
Cc: qemu-trivial@nongnu.org, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [Qemu-trivial] [PATCH] ivshmem: allow the sharing of hugepages
Date: Sat, 14 Sep 2013 13:36:14 +0400	[thread overview]
Message-ID: <52342E0E.3010700@msgid.tls.msk.ru> (raw)
In-Reply-To: <1379010228-15324-1-git-send-email-damien.millescamps@6wind.com>

12.09.2013 22:23, Damien Millescamps wrote:
> According to shm_open specifications:
>
>   A shared memory object should be identified by a name of the form /somename;
>   that is, a null-terminated string of up to NAME_MAX (i.e., 255) characters
>   consisting of an initial slash, followed by one or more characters, none of
>   which are slashes.
>
> This patch permits to share memory areas that do not specifically belong to
> /dev/shmem.
>
> A use case for this patch is sharing huge pages available through a
> hugetlbfs mountpoint.
>
> Signed-off-by: Damien Millescamps <damien.millescamps@6wind.com>
> ---
>   hw/misc/ivshmem.c |   16 +++++++++++++++-
>   1 files changed, 15 insertions(+), 1 deletions(-)
>
> diff --git a/hw/misc/ivshmem.c b/hw/misc/ivshmem.c
> index 2838866..9020bb2 100644
> --- a/hw/misc/ivshmem.c
> +++ b/hw/misc/ivshmem.c
> @@ -751,9 +751,23 @@ static int pci_ivshmem_init(PCIDevice *dev)
>
>           IVSHMEM_DPRINTF("using shm_open (shm object = %s)\n", s->shmobj);
>
> +        /*
> +         * A shared memory object should be identified by a name of the form /somename;
> +         * that is, a null-terminated string of up to NAME_MAX (i.e., 255) characters
> +         * consisting of an initial slash, followed by one or more characters, none of
> +         * which are slashes.

It'd be nice to give a hint about where this definition comes from.

And once you look at shm_open(3), you'll notice that this paragraph
is prefixed with "For portable use", and reads:

  For portable use, a shared memory object should be identified by a name of the
  form  /somename; that is, a null-terminated string of up to NAME_MAX (i.e., 255)
  characters consisting of an initial slash, followed by one or more characters,
  none of which are slashes.

That to say, this is not a _definition_ of a shared memory object, it is just
a suggested name syntax, suggested purely for portability.  In other words,
there may be other acceptable syntaxes for it.

So as the result, I'm not sure this approach is valid.  Maybe we should
always try shared first and create-new second?  I dunno.

Note that whole thing - using shared memory object like this - may lead
to surprizes at least, -- users who previously expected one behavour now
see different behavour.  Most likely the old behavour wasn't correct.

At least this should be documented somewhere in user-visible part of
ivshmem, so users will have an ides when objects will be shared and
when truncated.

> +         */
> +        if (s->shmobj && s->shmobj[0] == '/' && strstr(&s->shmobj[1], "/")) {

Here you're testing for s->shmobj, but before, the code were referencing
it directly as an argument for shm_open().  Can it be NULL in this place?

It is a somewhat minor nitpick, but it'd be not nice to spread such tests
(for NULLness) where the object can't be NULL and to confuse readers.

> +            /* This can't be a shared memory object. */
> +            fd = open(s->shmobj, O_RDWR);
> +            if (fd < 0) {
> +                perror("ivshmem - open");
> +                exit(-1);
> +            }
> +        }
>           /* try opening with O_EXCL and if it succeeds zero the memory
>            * by truncating to 0 */
> -        if ((fd = shm_open(s->shmobj, O_CREAT|O_RDWR|O_EXCL,
> +        else if ((fd = shm_open(s->shmobj, O_CREAT|O_RDWR|O_EXCL,
>                           S_IRWXU|S_IRWXG|S_IRWXO)) > 0) {
>              /* truncate file to length PCI device's memory */
>               if (ftruncate(fd, s->ivshmem_size) != 0) {
>

Thanks,

/mjt

  reply	other threads:[~2013-09-14  9:36 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-12 18:23 [Qemu-trivial] [PATCH] ivshmem: allow the sharing of hugepages Damien Millescamps
2013-09-12 18:23 ` [Qemu-devel] " Damien Millescamps
2013-09-14  9:36 ` Michael Tokarev [this message]
2013-09-14  9:36   ` [Qemu-devel] [Qemu-trivial] " Michael Tokarev
2013-09-14 10:51   ` Damien Millescamps
2013-09-14 10:51     ` [Qemu-devel] " Damien Millescamps
  -- strict thread matches above, loose matches on Subject: below --
2013-09-10 15:23 Damien Millescamps

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=52342E0E.3010700@msgid.tls.msk.ru \
    --to=mjt@tls.msk.ru \
    --cc=damien.millescamps@6wind.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-trivial@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.