From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: David Howells <dhowells@redhat.com>
Cc: viro@zeniv.linux.org.uk, Casey Schaufler <casey@schaufler-ca.com>,
Stephen Smalley <sds@tycho.nsa.gov>,
nicolas.dichtel@6wind.com, raven@themaw.net,
Christian Brauner <christian@brauner.io>,
keyrings@vger.kernel.org, linux-usb@vger.kernel.org,
linux-security-module@vger.kernel.org,
linux-fsdevel@vger.kernel.org, linux-api@vger.kernel.org,
linux-block@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 4/9] General notification queue with user mmap()'able ring buffer [ver #5]
Date: Wed, 03 Jul 2019 17:11:55 +0000 [thread overview]
Message-ID: <20190703171155.GC24672@kroah.com> (raw)
In-Reply-To: <156173695061.15137.17196611619288074120.stgit@warthog.procyon.org.uk>
On Fri, Jun 28, 2019 at 04:49:10PM +0100, David Howells wrote:
> Implement a misc device that implements a general notification queue as a
> ring buffer that can be mmap()'d from userspace.
>
> The way this is done is:
>
> (1) An application opens the device and indicates the size of the ring
> buffer that it wants to reserve in pages (this can only be set once):
>
> fd = open("/dev/watch_queue", O_RDWR);
> ioctl(fd, IOC_WATCH_QUEUE_NR_PAGES, nr_of_pages);
>
> (2) The application should then map the pages that the device has
> reserved. Each instance of the device created by open() allocates
> separate pages so that maps of different fds don't interfere with one
> another. Multiple mmap() calls on the same fd, however, will all work
> together.
>
> page_size = sysconf(_SC_PAGESIZE);
> mapping_size = nr_of_pages * page_size;
> char *buf = mmap(NULL, mapping_size, PROT_READ|PROT_WRITE,
> MAP_SHARED, fd, 0);
>
> The ring is divided into 8-byte slots. Entries written into the ring are
> variable size and can use between 1 and 63 slots. A special entry is
> maintained in the first two slots of the ring that contains the head and
> tail pointers. This is skipped when the ring wraps round. Note that
> multislot entries, therefore, aren't allowed to be broken over the end of
> the ring, but instead "skip" entries are inserted to pad out the buffer.
>
> Each entry has a 1-slot header that describes it:
>
> struct watch_notification {
> __u32 type:24;
> __u32 subtype:8;
> __u32 info;
> };
>
> The type indicates the source (eg. mount tree changes, superblock events,
> keyring changes, block layer events) and the subtype indicates the event
> type (eg. mount, unmount; EIO, EDQUOT; link, unlink). The info field
> indicates a number of things, including the entry length, an ID assigned to
> a watchpoint contributing to this buffer, type-specific flags and meta
> flags, such as an overrun indicator.
>
> Supplementary data, such as the key ID that generated an event, are
> attached in additional slots.
>
> Signed-off-by: David Howells <dhowells@redhat.com>
I don't know if I mentioned this before, but your naming seems a bit
"backwards" from other subsystems. Should "watch_queue" always be the
prefix, instead of a mix of prefix/suffix usage?
Anyway, your call, it's your code :)
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
WARNING: multiple messages have this Message-ID (diff)
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: David Howells <dhowells@redhat.com>
Cc: viro@zeniv.linux.org.uk, Casey Schaufler <casey@schaufler-ca.com>,
Stephen Smalley <sds@tycho.nsa.gov>,
nicolas.dichtel@6wind.com, raven@themaw.net,
Christian Brauner <christian@brauner.io>,
keyrings@vger.kernel.org, linux-usb@vger.kernel.org,
linux-security-module@vger.kernel.org,
linux-fsdevel@vger.kernel.org, linux-api@vger.kernel.org,
linux-block@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 4/9] General notification queue with user mmap()'able ring buffer [ver #5]
Date: Wed, 3 Jul 2019 19:11:55 +0200 [thread overview]
Message-ID: <20190703171155.GC24672@kroah.com> (raw)
In-Reply-To: <156173695061.15137.17196611619288074120.stgit@warthog.procyon.org.uk>
On Fri, Jun 28, 2019 at 04:49:10PM +0100, David Howells wrote:
> Implement a misc device that implements a general notification queue as a
> ring buffer that can be mmap()'d from userspace.
>
> The way this is done is:
>
> (1) An application opens the device and indicates the size of the ring
> buffer that it wants to reserve in pages (this can only be set once):
>
> fd = open("/dev/watch_queue", O_RDWR);
> ioctl(fd, IOC_WATCH_QUEUE_NR_PAGES, nr_of_pages);
>
> (2) The application should then map the pages that the device has
> reserved. Each instance of the device created by open() allocates
> separate pages so that maps of different fds don't interfere with one
> another. Multiple mmap() calls on the same fd, however, will all work
> together.
>
> page_size = sysconf(_SC_PAGESIZE);
> mapping_size = nr_of_pages * page_size;
> char *buf = mmap(NULL, mapping_size, PROT_READ|PROT_WRITE,
> MAP_SHARED, fd, 0);
>
> The ring is divided into 8-byte slots. Entries written into the ring are
> variable size and can use between 1 and 63 slots. A special entry is
> maintained in the first two slots of the ring that contains the head and
> tail pointers. This is skipped when the ring wraps round. Note that
> multislot entries, therefore, aren't allowed to be broken over the end of
> the ring, but instead "skip" entries are inserted to pad out the buffer.
>
> Each entry has a 1-slot header that describes it:
>
> struct watch_notification {
> __u32 type:24;
> __u32 subtype:8;
> __u32 info;
> };
>
> The type indicates the source (eg. mount tree changes, superblock events,
> keyring changes, block layer events) and the subtype indicates the event
> type (eg. mount, unmount; EIO, EDQUOT; link, unlink). The info field
> indicates a number of things, including the entry length, an ID assigned to
> a watchpoint contributing to this buffer, type-specific flags and meta
> flags, such as an overrun indicator.
>
> Supplementary data, such as the key ID that generated an event, are
> attached in additional slots.
>
> Signed-off-by: David Howells <dhowells@redhat.com>
I don't know if I mentioned this before, but your naming seems a bit
"backwards" from other subsystems. Should "watch_queue" always be the
prefix, instead of a mix of prefix/suffix usage?
Anyway, your call, it's your code :)
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
next prev parent reply other threads:[~2019-07-03 17:11 UTC|newest]
Thread overview: 55+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-28 15:48 [PATCH 0/9] Keyrings, Block and USB notifications [ver #5] David Howells
2019-06-28 15:48 ` David Howells
2019-06-28 15:48 ` David Howells
2019-06-28 15:48 ` [PATCH 1/9] uapi: General notification ring definitions " David Howells
2019-06-28 15:48 ` David Howells
2019-06-28 15:48 ` David Howells
2019-07-03 17:08 ` Greg Kroah-Hartman
2019-07-03 17:08 ` Greg Kroah-Hartman
2019-06-28 15:48 ` [PATCH 2/9] security: Add hooks to rule on setting a watch " David Howells
2019-06-28 15:48 ` David Howells
2019-06-28 15:48 ` David Howells
2019-07-08 18:46 ` Stephen Smalley
2019-07-08 18:46 ` Stephen Smalley
2019-06-28 15:49 ` [PATCH 3/9] security: Add a hook for the point of notification insertion " David Howells
2019-06-28 15:49 ` David Howells
2019-06-28 15:49 ` David Howells
2019-07-08 19:13 ` Stephen Smalley
2019-07-08 19:13 ` Stephen Smalley
2019-06-28 15:49 ` [PATCH 4/9] General notification queue with user mmap()'able ring buffer " David Howells
2019-06-28 15:49 ` David Howells
2019-06-28 15:49 ` David Howells
2019-07-03 17:11 ` Greg Kroah-Hartman [this message]
2019-07-03 17:11 ` Greg Kroah-Hartman
2019-06-28 15:49 ` [PATCH 5/9] keys: Add a notification facility " David Howells
2019-06-28 15:49 ` David Howells
2019-06-28 15:49 ` David Howells
2019-06-28 15:49 ` [PATCH 6/9] Add a general, global device notification watch list " David Howells
2019-06-28 15:49 ` David Howells
2019-06-28 15:49 ` David Howells
2019-07-03 17:16 ` Greg Kroah-Hartman
2019-07-03 17:16 ` Greg Kroah-Hartman
2019-07-03 19:08 ` Greg Kroah-Hartman
2019-07-03 19:08 ` Greg Kroah-Hartman
2019-07-04 16:04 ` David Howells
2019-07-04 16:04 ` David Howells
2019-07-05 5:17 ` Greg Kroah-Hartman
2019-07-05 5:17 ` Greg Kroah-Hartman
2019-07-05 8:04 ` David Howells
2019-07-05 8:04 ` David Howells
2019-07-05 8:44 ` Greg Kroah-Hartman
2019-07-05 8:44 ` Greg Kroah-Hartman
2019-07-05 14:40 ` Alan Stern
2019-07-05 14:40 ` Alan Stern
2019-07-05 14:40 ` Alan Stern
2019-06-28 15:49 ` [PATCH 7/9] block: Add block layer notifications " David Howells
2019-06-28 15:49 ` David Howells
2019-06-28 15:49 ` David Howells
2019-06-28 15:49 ` [PATCH 8/9] usb: Add USB subsystem " David Howells
2019-06-28 15:49 ` David Howells
2019-06-28 15:49 ` David Howells
2019-07-03 17:07 ` Greg Kroah-Hartman
2019-07-03 17:07 ` Greg Kroah-Hartman
2019-06-28 15:49 ` [PATCH 9/9] Add sample notification program " David Howells
2019-06-28 15:49 ` David Howells
2019-06-28 15:49 ` David Howells
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=20190703171155.GC24672@kroah.com \
--to=gregkh@linuxfoundation.org \
--cc=casey@schaufler-ca.com \
--cc=christian@brauner.io \
--cc=dhowells@redhat.com \
--cc=keyrings@vger.kernel.org \
--cc=linux-api@vger.kernel.org \
--cc=linux-block@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=nicolas.dichtel@6wind.com \
--cc=raven@themaw.net \
--cc=sds@tycho.nsa.gov \
--cc=viro@zeniv.linux.org.uk \
/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.