linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Bryan Donlan <bdonlan@gmail.com>
To: Tony Ibbs <tibs@tonyibbs.co.uk>
Cc: Pekka Enberg <penberg@kernel.org>,
	lkml <linux-kernel@vger.kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Jonathan Corbet <corbet@lwn.net>,
	Florian Fainelli <florian@openwrt.org>,
	Grant Likely <grant.likely@secretlab.ca>,
	Linux-embedded <linux-embedded@vger.kernel.org>,
	Tibs at Kynesim <tibs@kynesim.co.uk>,
	Richard Watts <rrw@kynesim.co.uk>
Subject: Re: RFC: [Restatement] KBUS messaging subsystem
Date: Sun, 21 Aug 2011 21:15:31 -0400	[thread overview]
Message-ID: <CAF_S4t-RV1SACnkwW9RsVWEXv-jHujvnLZh-NMfDZi4YzfJwdw@mail.gmail.com> (raw)
In-Reply-To: <1825A697-7D60-44D0-8150-BC0E9F0DEB67@tonyibbs.co.uk>

On Sun, Aug 21, 2011 at 09:28, Tony Ibbs <tibs@tonyibbs.co.uk> wrote:
>
> On 15 Aug 2011, at 12:46, Pekka Enberg wrote:
>
>> I simply don't see a convincing argument why existing IPC and other
>> kernel mechanisms are not sufficient to implement what you need. I'm
>> sure there is one but it's not apparent from your emails.
>
> Our major concern, strongly based on experience, is that given the
> existing kernel mechanisms, users do not build robust (or even
> sometimes working!) solutions for inter-process communication.
>
> This is in large part because they do not realise (at the start) how
> difficult this is to do. Especially if they want to keep it small.
>
> The only *sure* way of solving this is to provide a mechanism that is
> "always there", and that really means a solution provided by the
> kernel. This needs to be at a higher level than what is currently
> available, but obviously what exactly is provided is then a matter for
> discussion. We'd obviously argue that KBUS hits a "sweet spot" for the
> needs we perceive, given our application areas.
>
>> The whole thing feels more like "lets put a message broker into the
>> kernel" rather than set of kernel APIs that make sense. I suppose the
>> rather extensive ioctl() ABI is partly to blame here.
>
> I'm not sure what you mean by "message broker", except that it's
> plainly meant to be a bad thing - the wikipedia meaning doesn't seem
> terribly applicable to KBUS, as it covers an awful lot more territory
> (mind, the discussion page is amusing).
>
> I'll freely admit we started with the idea of what functionality we
> wanted and then chose a simple-to-implement API to make it happen.
>
> *If* KBUS were in the kernel, with its current functionality, what API
> would you expect? (not just "a sockety one", but what actual API?) If
> one recasts as a sockety API, how is many new socket options better
> than a set of ioctls? (or is that just one of those questions to which
> the answer is "well, it is"?)

I think this may well be the core problem here - is KBUS, as proposed,
a general API lots of people will find useful, or is it something that
will fit _your_ usecase well, but other usecases poorly?
Designing a good API, of course, is quite difficult, but it _must_ be
done before integrating anything with upstream Linux, as once
something is merged it has to be supported for decades, even if it
turns out to be useless for 99% of usecases.

Some good questions to ask might be:
* Does this system play nice with namespaces?
* What limits are in place to prevent resource exhaustion attacks?
* Can libdbus or other such existing message brokers swap out their
existing central-routing-process based communications with this new
system without applications being aware?

Keep in mind also that the kernel API need not match the
application-visible API, if you can add a userspace library to
translate to the API you want. So, for example, instead of numbering
kbuses, you could define them as a new AF_UNIX protocol, and place
them in the abstract socket namespace (ie, they'd have names like
"\0kbus-0"). Doing something like this avoids creating a new
namespace, and non-embedded devices could place these new primitives
in a tmpfs or other more visible location. It also makes it very cheap
(and a non-privileged operation!) to create kbuses.

So, let's look at your requirements:

* Message broadcast API with prefix filtering
* Deterministic ordering
* Possible to snoop on all messages being passed through
* Must not require any kind of central userspace daemon
* Needs a race-less way of 1) Advertising (and locking) as a replier
for a particular message type and 2) Detecting when the replier dies
(and synthesizing error replies in this event)

Now, to minimize this definition, why not remove prefix filtering from
the kernel? For low-volume buses, it doesn't hurt to do the filtering
in userspace (right?). If you want to reduce the volume of messages
received, do it on a per-bus granularity (and set up lots of buses
instead). After all, you can always connect to multiple buses if you
need to listen for multiple message types. For replier registration,
then, it would be done on a per-bus granularity, not a per-message
granularity.

So we now have an API that might (as an example) look like this:

* Creation of buses - socket(AF_UNIX, SOCK_DGRAM, PROTO_KBUS),
followed by bind() either to a file or in the abstract namespace
* Advertising as a replier on a socket - setsockopt(SOL_KBUS,
KBUS_REPLIER, &one); - returns -EEXIST if a replier is already present
* Sending/receiving messages - ordinary sendto/recvfrom. If a reply is
desired, use sendmsg with an ancillary data item indicating a reply is
desired
* Notification on replier death (or replier buffer overflow etc):
empty message with ancillary data attached informing of the error
condition
* 64-bit global counter on all messages (or messages where requested
by the client) to give a deterministic order between messages sent on
multiple buses (reported via ancillary data)
* Resource limitation based on memory cgroup or something? Not sure
what AF_UNIX uses already, but you could probably use the same system.
* Perhaps support SCM_RIGHTS/SCM_CREDENTIALS transfers as well?

This is a much simpler kernel API, don't you think? It's also easy to
see how dbus could use it as well - just add a method to filter
unicast messages from being seen by other uninterested clients, create
a kbus socket for each dbus connection (with appropriate symlinks for
any registered aliases), and have the owner of a connection socket
register itself as a replier. Now you can send dbus broadcast messages
across the KBUS socket as usual, and perhaps send replies to unicast
messages over a socket passed in over a SCM_CREDENTIALS transfer.
Alternately, you could assign connection IDs, and have a control
message to route unicast replies to their sender - in any case, these
details are something dbus people would need to comment on, if they're
interested, but you can see that it's a use case that shows promise
(I'm not familiar with the dbus security model, however, and so I'm
not sure if this'll play well with it).

In short, API minimalism is key to acceptance in the upstream kernel.
Try to pare down the core API to the bare minimum to get what you
need, rather than implementing your final use case directly into the
kernel using ioctls or whatnot.

Thanks,

Bryan

  reply	other threads:[~2011-08-22  1:16 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-18 17:21 [PATCH 00/11] RFC: KBUS messaging subsystem Tony Ibbs
2011-03-18 17:21 ` [PATCH 01/11] Documentation for KBUS Tony Ibbs
2011-03-18 17:21   ` [PATCH 02/11] KBUS external header file Tony Ibbs
2011-03-18 17:21     ` [PATCH 03/11] KBUS internal " Tony Ibbs
2011-03-18 17:21       ` [PATCH 04/11] KBUS main source file, basic device support only Tony Ibbs
2011-03-18 17:21         ` [PATCH 05/11] KBUS add support for messages Tony Ibbs
2011-03-18 17:21           ` [PATCH 06/11] KBUS add ability to receive messages only once Tony Ibbs
2011-03-18 17:21             ` [PATCH 07/11] KBUS add ability to add devices at runtime Tony Ibbs
2011-03-18 17:21               ` [PATCH 08/11] KBUS add Replier Bind Events Tony Ibbs
2011-03-18 17:21                 ` [PATCH 09/11] KBUS Replier Bind Event set-aside lists Tony Ibbs
2011-03-18 17:21                   ` [PATCH 10/11] KBUS report state to userspace Tony Ibbs
2011-03-18 17:21                     ` [PATCH 11/11] KBUS configuration and Makefile Tony Ibbs
2011-03-22 19:36 ` [PATCH 00/11] RFC: KBUS messaging subsystem Jonathan Corbet
2011-03-23 23:13   ` Tony Ibbs
2011-03-24 18:03     ` James Chapman
2011-03-27 19:07       ` Tony Ibbs
2011-04-15 21:34     ` [PATCH] extra/1 Allow setting the maximum KBUS message size Tony Ibbs
2011-04-15 22:46       ` Jonathan Corbet
2011-04-18 14:01         ` Mark Brown
2011-04-19 19:33           ` Tony Ibbs
2011-05-17  8:50   ` [PATCH 00/11] RFC: KBUS messaging subsystem Florian Fainelli
2011-05-22 19:58     ` Tony Ibbs
2011-07-06 16:15       ` Florian Fainelli
2011-07-28 21:48         ` RFC: [Restatement] " Tony Ibbs
2011-07-28 23:58           ` Colin Walters
2011-08-03 20:14             ` Tony Ibbs
2011-08-07 16:47               ` Tony Ibbs
2011-08-03 20:48           ` Pekka Enberg
2011-08-07 20:24             ` Tony Ibbs
2011-08-15 11:46               ` Pekka Enberg
2011-08-21 13:28                 ` Tony Ibbs
2011-08-22  1:15                   ` Bryan Donlan [this message]
2011-08-29  8:55                     ` Tony Ibbs
2011-08-03 20:23     ` [PATCH 00/11] RFC: " Tony Ibbs

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=CAF_S4t-RV1SACnkwW9RsVWEXv-jHujvnLZh-NMfDZi4YzfJwdw@mail.gmail.com \
    --to=bdonlan@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=corbet@lwn.net \
    --cc=florian@openwrt.org \
    --cc=grant.likely@secretlab.ca \
    --cc=linux-embedded@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=penberg@kernel.org \
    --cc=rrw@kynesim.co.uk \
    --cc=tibs@kynesim.co.uk \
    --cc=tibs@tonyibbs.co.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).