From: Inaky Perez-Gonzalez <inaky@linux.intel.com>
To: Thomas Graf <tgraf@suug.ch>
Cc: netdev@vger.kernel.org, wimax@linuxwimax.org
Subject: Re: [PATCH 10/39] wimax: Generic messaging interface between user space and driver/device
Date: Tue, 2 Dec 2008 18:02:34 -0800 [thread overview]
Message-ID: <200812021802.34863.inaky@linux.intel.com> (raw)
In-Reply-To: <20081127123511.GP20815@postel.suug.ch>
On Thursday 27 November 2008, Thomas Graf wrote:
> * Inaky Perez-Gonzalez <inaky@linux.intel.com> 2008-11-26 14:40
>
> > + * By default, all devices get one default pipe ("the messaging
> > + * pipe").
>
> I think this is fundamentally wrong by design. There should be one
> WiMAX genetlink family with a set of commands taking the interface
> index as attribute. The number of genetlink families is critical
> to its performance.
The number should not be a problem; the strange case is going to be the
system that has more than one WiMAX interface.
So if the general case is going to be 1 interface, instead of making one
lookup for the family name and then another lookup for the attribute
indicating the interface, making it one single lookup reduces the overhead.
> > + * GENERIC NETLINK ENCODING AND CAPACITY
> > + *
> > + * Messages are encoded as a binary netlink attribute using nla_put()
> > + * using type NLA_UNSPEC (as some versions of libnl still in
> > + * deployment don't yet understand NLA_BINARY).
>
> Not sure what you mean by that, the attribute policies are not shared
> between kernel and userspace. The attribute policy defines the semantics
> on what you receive, not what or how you send it.
the libnls I've seen don't define type NLA_BINARY -- I don't really know
how they map onto each other, but using NLA_UNSPEC on both sides (kernel
and userspace) seems to work for transferring a buffer.
> > + * The maximum capacity of this transport is undetermined. Sending of
> > + * messages up to 4k has been tested with success. Bigger buffers
> > + * beware.
>
> All netlink messages are limited to the PAGESIZE.
Note taken, thanks
> > +struct sk_buff *wimax_pipe_msg_alloc(struct wimax_dev *wimax_dev,
> > + const void *msg, size_t size,
> > + gfp_t gfp_flags)
> > +{
> > + int result;
> > + struct device *dev = wimax_dev->net_dev->dev.parent;
> > + void *genl_msg;
> > + struct sk_buff *skb;
> > +
> > + skb = genlmsg_new(nla_total_size(size), gfp_flags);
>
> This dosen't look right, genlmsg_new() expects the size of the
> family specific payload.
So I am going to create a message, with no family specific payload
but just an attribute with a buffer sized 'size'. What should
I pass to it so it preallocates correctly?
That construct (at least now) seems to work.
> > + result = nla_put(skb, WIMAX_GNL_MSG_DATA, size, msg);
> > + if (result == -1) {
>
> nla_put() returns -EMSGSIZE so this check is useless, check against < 0.
Fixed
> > +const void *wimax_msg_data(struct sk_buff *msg)
> > +{
> > + struct nlmsghdr *nlh = (void *) msg->head;
>
> You shouldn't access the netlink header via skb->head or skb->data as it
> is done in numerous places. The genetlink layer passes a struct
> genl_info to the doit() callback which conains a pointer to the netlink
> header genl_info->nlhdr.
This is mostly used before sending a message to user space, so genl_info
doesn't apply. By default all notifications from the device are sent over
generic netlink to user space.
But some times we need to consume that information inside the kernel, so
instead of creating two separate formats, we just use the same. So we need
to extract, from an SKB that is packaged to be sent as generic netlink,
the header. And at his point there is no genl_info :(
I've missed a couple that can get it from genl_info (in rfkill and msg), plus
reset doesn't really needed. Updated them; the rest are contained in
wimax_msg_data() and wimax_msg_len().
> > +/**
> > + * wimax_msg_len - Return a message's payload length
> > + *
> > + * @msg: Pointer to a message created with wimax_pipe_msg_alloc()
> > + */
> > +ssize_t wimax_msg_len(struct sk_buff *msg)
> > +{
> > + struct nlmsghdr *nlh = (void *) msg->head;
> > + struct nlattr *nla;
> > +
> > + nla = nlmsg_find_attr(nlh, sizeof(struct genlmsghdr),
> > + WIMAX_GNL_MSG_DATA);
> > + if (nla == NULL) {
> > + printk(KERN_ERR "Cannot find attribute WIMAX_GNL_MSG_DATA\n");
> > + return -EINVAL;
> > + }
> > + return nla_len(nla);
> > +}
>
> So users have to call both wimax_msg_data() and wimax_msg_len() which
> both walk through all attributes to find the attribute in question.
> You could simply return the nlattr and rely on users to call nla_data()
> respectively nla_len() to access data/length.
Good point; actually in most cases it either needs the pointer data
or both, so probably a wimax_msg_get_data_len() helper makes more sense.
> > +
> > +static
> > +struct nla_policy wimax_gnl_msg_policy[WIMAX_GNL_ATTR_MAX + 1] = {
> > + [WIMAX_GNL_MSG_DATA] = {
> > + .type = NLA_UNSPEC, /* libnl doesn't grok BINARY yet */
> > + },
> > +};
>
> This policy is completely pointless :-)
Why? Should I just use NLA_BINARY then? What do I use in user space to compose
it if libnl still doesn't know about NLA_BINARY?
I just need it to verify that there is an attribute with a buffer. That's it.
> > + struct nlattr *tb[WIMAX_GNL_ATTR_MAX+1];
> > + void *msg_buf;
> > + size_t msg_len;
> > +
> > + /* Parse the message to extract arguments */
> > + result = nlmsg_parse(nlh, sizeof(struct genlmsghdr),
> > + tb, ARRAY_SIZE(tb),
> > + wimax_gnl_msg_policy);
>
> It's not wrong to parse the attributes yourself but it's a lot easier to
> define them as one sequence and have the genetlink layer parse and
> validate them for you. Simply assign the highest attribute number and
> policy to the family and they will be made available in the info
> structure.
So the policy is already set up like that, it has a pointer to the policy.
Are you saying it should be possible for me to just access genl_info->attrs[]?
[I didn't know that existed, just found out after your comment made me look
at it].
/me tries...
sweet, it works -- well, this cuts more code out, thanks.
--
Inaky
next prev parent reply other threads:[~2008-12-03 2:11 UTC|newest]
Thread overview: 97+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-11-26 22:40 [PATCH 00/39] merge request for WiMAX kernel stack and i2400m driver v2 Inaky Perez-Gonzalez
2008-11-26 22:40 ` [PATCH 01/39] wimax: documentation for the stack Inaky Perez-Gonzalez
2008-11-27 9:29 ` Johannes Berg
2008-12-03 2:07 ` Inaky Perez-Gonzalez
2008-11-26 22:40 ` [PATCH 02/39] wimax: declarations for the in-kernel WiMAX API Inaky Perez-Gonzalez
2008-11-27 9:32 ` Johannes Berg
2008-12-03 2:07 ` Inaky Perez-Gonzalez
2008-12-04 9:04 ` Johannes Berg
2008-12-04 20:11 ` Inaky Perez-Gonzalez
2008-11-26 22:40 ` [PATCH 03/39] wimax: constants and definitions to interact with user space Inaky Perez-Gonzalez
2008-11-27 9:41 ` Johannes Berg
2008-12-03 2:06 ` Inaky Perez-Gonzalez
2008-11-26 22:40 ` [PATCH 04/39] wimax: internal API for the kernel space WiMAX stack Inaky Perez-Gonzalez
2008-11-27 9:43 ` Johannes Berg
2008-12-03 2:07 ` Inaky Perez-Gonzalez
2008-12-04 9:02 ` Johannes Berg
2008-12-04 19:22 ` Inaky Perez-Gonzalez
2008-11-26 22:40 ` [PATCH 05/39] wimax: debug macros and debug settings for the " Inaky Perez-Gonzalez
2008-11-27 9:28 ` Johannes Berg
2008-12-03 2:07 ` Inaky Perez-Gonzalez
2008-11-26 22:40 ` [PATCH 06/39] genetlink: export genl_unregister_mc_group() Inaky Perez-Gonzalez
2008-11-26 23:07 ` Johannes Berg
2008-11-26 22:40 ` [PATCH 07/39] wimax: generic WiMAX device management (registration, deregistration, etc) Inaky Perez-Gonzalez
2008-11-27 10:40 ` Patrick McHardy
2008-12-03 2:06 ` Inaky Perez-Gonzalez
2008-12-04 13:02 ` Patrick McHardy
2008-11-26 22:40 ` [PATCH 08/39] wimax: Mappping of generic netlink family IDs to net devices Inaky Perez-Gonzalez
2008-11-27 9:47 ` Johannes Berg
2008-12-03 2:06 ` Inaky Perez-Gonzalez
2008-11-26 22:40 ` [PATCH 09/39] wimax: provides user space with information needed when opening a WiMAX device Inaky Perez-Gonzalez
2008-11-27 9:53 ` Johannes Berg
2008-11-27 12:20 ` Johannes Berg
2008-12-03 2:06 ` Inaky Perez-Gonzalez
2008-11-27 10:44 ` Patrick McHardy
2008-11-26 22:40 ` [PATCH 10/39] wimax: Generic messaging interface between user space and driver/device Inaky Perez-Gonzalez
2008-11-27 9:55 ` Johannes Berg
2008-11-27 12:35 ` Thomas Graf
2008-12-03 2:02 ` Inaky Perez-Gonzalez [this message]
2008-11-26 22:40 ` [PATCH 11/39] wimax: RF-kill framework integration Inaky Perez-Gonzalez
2008-11-27 9:56 ` Johannes Berg
2008-12-03 2:03 ` Inaky Perez-Gonzalez
2008-11-26 22:40 ` [PATCH 12/39] wimax: API call to reset a WiMAX device Inaky Perez-Gonzalez
2008-11-27 9:58 ` Johannes Berg
2008-12-03 2:05 ` Inaky Perez-Gonzalez
2008-11-26 22:40 ` [PATCH 13/39] wimax: Makefile, Kconfig and docbook linkage for the stack Inaky Perez-Gonzalez
2008-11-26 22:40 ` [PATCH 14/39] i2400m: documentation and instructions for usage Inaky Perez-Gonzalez
2008-11-27 10:01 ` Johannes Berg
2008-12-03 2:06 ` Inaky Perez-Gonzalez
2008-11-26 22:40 ` [PATCH 15/39] i2400m: host-to-device protocol definitions Inaky Perez-Gonzalez
2008-11-27 10:04 ` Johannes Berg
2008-12-03 2:06 ` Inaky Perez-Gonzalez
2008-11-26 22:40 ` [PATCH 16/39] i2400m: core driver definitions and API Inaky Perez-Gonzalez
2008-11-26 22:40 ` [PATCH 17/39] i2400m: Generic probe/disconnect, reset and message passing Inaky Perez-Gonzalez
2008-11-26 22:40 ` [PATCH 18/39] i2400m: linkage to the networking stack Inaky Perez-Gonzalez
2008-11-26 22:40 ` [PATCH 19/39] i2400m: sysfs controls Inaky Perez-Gonzalez
2008-11-27 9:23 ` Johannes Berg
2008-11-26 22:40 ` [PATCH 20/39] i2400m: rfkill integration with the WiMAX stack Inaky Perez-Gonzalez
2008-11-26 22:40 ` [PATCH 21/39] i2400m: firmware loading and bootrom initialization Inaky Perez-Gonzalez
2008-11-26 22:40 ` [PATCH 22/39] i2400m: handling of the data/control reception path Inaky Perez-Gonzalez
2008-11-26 22:40 ` [PATCH 23/39] i2400m: handling of the data/control transmission path Inaky Perez-Gonzalez
2008-11-26 22:40 ` [PATCH 24/39] i2400m: various functions for device management Inaky Perez-Gonzalez
2008-11-26 22:40 ` [PATCH 25/39] i2400m/USB: header for the USB bus driver Inaky Perez-Gonzalez
2008-11-26 22:40 ` [PATCH 26/39] i2400m/USB: error density tracking Inaky Perez-Gonzalez
2008-11-26 22:40 ` [PATCH 27/39] i2400m/USB: main probe/disconnect and backend routines Inaky Perez-Gonzalez
2008-11-26 22:40 ` [PATCH 28/39] i2400m/USB: firmware upload backend Inaky Perez-Gonzalez
2008-11-26 22:40 ` [PATCH 29/39] i2400m/USB: handling of notifications from the device Inaky Perez-Gonzalez
2008-11-26 22:40 ` [PATCH 30/39] i2400m/USB: read transactions from the USB device Inaky Perez-Gonzalez
2008-11-26 22:40 ` [PATCH 31/39] i2400m/USB: write transactions to " Inaky Perez-Gonzalez
2008-11-26 22:40 ` [PATCH 32/39] i2400m/SDIO: header for the SDIO subdriver Inaky Perez-Gonzalez
2008-11-26 22:40 ` [PATCH 33/39] i2400m/SDIO: main probe/disconnect and backend routines Inaky Perez-Gonzalez
2008-11-26 22:40 ` [PATCH 34/39] i2400m/SDIO: firmware upload backend Inaky Perez-Gonzalez
2008-11-26 22:40 ` [PATCH 35/39] i2400m/SDIO: read transactions from the SDIO device Inaky Perez-Gonzalez
2008-11-26 22:40 ` [PATCH 36/39] i2400m/SDIO: write transactions to " Inaky Perez-Gonzalez
2008-11-26 22:40 ` [PATCH 37/39] i2400m: Makefile and Kconfig Inaky Perez-Gonzalez
2008-11-26 22:40 ` [PATCH 38/39] wimax: export linux/wimax.h and linux/wimax/i2400m.h with headers_install Inaky Perez-Gonzalez
2008-11-26 22:40 ` [PATCH 39/39] wimax/i2400m: add CREDITS and MAINTAINERS entries Inaky Perez-Gonzalez
2008-11-27 8:17 ` [PATCH 00/39] merge request for WiMAX kernel stack and i2400m driver v2 David Miller
2008-11-27 9:24 ` Inaky Perez-Gonzalez
2008-11-27 10:18 ` Arkadiusz Miskiewicz
2008-11-27 10:41 ` Marcel Holtmann
2008-11-27 10:54 ` Johannes Berg
2008-11-27 11:14 ` Marcel Holtmann
2008-11-27 11:23 ` Johannes Berg
2008-11-30 4:05 ` Dan Williams
2008-11-27 11:47 ` Andi Kleen
2008-11-27 11:50 ` Johannes Berg
2008-11-27 16:51 ` Inaky Perez-Gonzalez
2008-12-03 2:07 ` Inaky Perez-Gonzalez
2008-12-03 23:03 ` Dan Williams
2008-12-04 9:00 ` Johannes Berg
2008-12-04 19:21 ` Inaky Perez-Gonzalez
2008-12-04 23:09 ` Johannes Berg
2008-12-03 2:10 ` Inaky Perez-Gonzalez
2008-12-04 9:01 ` Johannes Berg
2008-12-04 13:37 ` Marcel Holtmann
-- strict thread matches above, loose matches on Subject: below --
2008-11-26 7:38 Inaky Perez-Gonzalez
2008-11-26 7:39 ` [PATCH 10/39] wimax: Generic messaging interface between user space and driver/device Inaky Perez-Gonzalez
2008-11-24 21:50 [PATCH 00/39] merge request for WiMAX kernel stack and i2400m driver Inaky Perez-Gonzalez
2008-11-24 21:50 ` [PATCH 10/39] wimax: Generic messaging interface between user space and driver/device Inaky Perez-Gonzalez
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=200812021802.34863.inaky@linux.intel.com \
--to=inaky@linux.intel.com \
--cc=netdev@vger.kernel.org \
--cc=tgraf@suug.ch \
--cc=wimax@linuxwimax.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 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).