Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp2689155ybp; Thu, 10 Oct 2019 11:04:52 -0700 (PDT) X-Google-Smtp-Source: APXvYqyzAJPO/L3pzaaOtCBAObe3FDXLosfG7Ae0xRGQR/wmK40NA/rVj1ABEEQZc7z/1xQ/2C3R X-Received: by 2002:a17:906:480a:: with SMTP id w10mr9405261ejq.212.1570730692669; Thu, 10 Oct 2019 11:04:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570730692; cv=none; d=google.com; s=arc-20160816; b=Hez9GNCPcRXb2R2/bMGjoZ7pChT2zf3N8zhg7QiMbXcZZfucF6c1hNWIz11EDRNYS9 bW6weGAnln8O15O99+1lnaeks5/ErISx0x6dUXPU/ae97gYAiD0zu36O7LjGXT9Hbwqf fBa5MbpWFMaNOw4bxJ60wJu1kpIb5S3fzC9HTK1h6MAIcBWnwgEQ79sG0fCR7WImJp8x 3pOn6TyX1ebd+MzpicsA+Gy0Kl3Vkaw+J7I2YX4j2UHnmU11jt66hiCWqOvkbFTtx1Dh ZT1YB5DGQlopB5fJOC9FG+UD3M1MJdKsKQHMdIkcSQRTBQtUi1G8l+djb+ycwkrHjezf AbzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=hM2AAkmQ8o/WzSbCEgibBUrX5IUt6x8t6qx7xMN4LIY=; b=Uz5DDIWszkLQgD4AwuY2exH4/RU+VqigQJzqdKlevqnKrXiRkviR1dtYKDfIGJYe/n LVmW+zZPInaRtTVO3Rxl0zIbtmr2d1BgMvZGMdAf4zbznn7lI2IWG75mBwmvUE7u+yAt t01Cj9TFgISmQZsawSDFJHQk5yDO0Ht1GcvILPaAaTbJ0LmC+lRXkKMJ0SrN3O/j1YPS Y9Tzo7c8VofSS7F2mnKaa4OFn6NE+VgQ7qPLAliOODsns+mQSOophs+UHEhDDYM49Rsh vcCU3LXOWiFwrnIpCAPN7f88wmV7F5hJ04/WNFewd29htLD2/SJSlWlIn9fdesHqLEep q7Bg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id op4si3609744ejb.77.2019.10.10.11.04.23; Thu, 10 Oct 2019 11:04:52 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726905AbfJJSEF (ORCPT + 99 others); Thu, 10 Oct 2019 14:04:05 -0400 Received: from mx2.suse.de ([195.135.220.15]:36686 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726323AbfJJSEF (ORCPT ); Thu, 10 Oct 2019 14:04:05 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 78D69AD69; Thu, 10 Oct 2019 18:04:02 +0000 (UTC) Received: by unicorn.suse.cz (Postfix, from userid 1000) id A6537E378C; Thu, 10 Oct 2019 20:04:01 +0200 (CEST) Date: Thu, 10 Oct 2019 20:04:01 +0200 From: Michal Kubecek To: netdev@vger.kernel.org Cc: Jiri Pirko , David Miller , Jakub Kicinski , Andrew Lunn , Florian Fainelli , John Linville , Stephen Hemminger , Johannes Berg , linux-kernel@vger.kernel.org Subject: Re: [PATCH net-next v7 09/17] ethtool: generic handlers for GET requests Message-ID: <20191010180401.GD22163@unicorn.suse.cz> References: <20191010135639.GJ2223@nanopsycho> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191010135639.GJ2223@nanopsycho> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Oct 10, 2019 at 03:56:39PM +0200, Jiri Pirko wrote: > Wed, Oct 09, 2019 at 10:59:27PM CEST, mkubecek@suse.cz wrote: > >+/** > >+ * ethnl_std_parse() - Parse request message > >+ * @req_info: pointer to structure to put data into > >+ * @nlhdr: pointer to request message header > >+ * @net: request netns > >+ * @request_ops: struct request_ops for request type > >+ * @extack: netlink extack for error reporting > >+ * @require_dev: fail if no device identified in header > >+ * > >+ * Parse universal request header and call request specific ->parse_request() > >+ * callback (if defined) to parse the rest of the message. > >+ * > >+ * Return: 0 on success or negative error code > >+ */ > >+static int ethnl_std_parse(struct ethnl_req_info *req_info, > > "std" sounds a bit odd. Perhaps "common"? It could be "common". The reason I used "standard" was that this parser is only used by (GET) request types which use the standard doit/dumpit handlers. Request types using their own (nonstandard) handlers will also do parsing on their own. > >+ const struct nlmsghdr *nlhdr, struct net *net, > >+ const struct get_request_ops *request_ops, > >+ struct netlink_ext_ack *extack, bool require_dev) > >+{ > >+ struct nlattr **tb; > >+ int ret; > >+ > >+ tb = kmalloc_array(request_ops->max_attr + 1, sizeof(tb[0]), > >+ GFP_KERNEL); > >+ if (!tb) > >+ return -ENOMEM; > >+ > >+ ret = nlmsg_parse(nlhdr, GENL_HDRLEN, tb, request_ops->max_attr, > >+ request_ops->request_policy, extack); > >+ if (ret < 0) > >+ goto out; > >+ ret = ethnl_parse_header(req_info, tb[request_ops->hdr_attr], net, > >+ extack, request_ops->header_policy, > >+ require_dev); > > This is odd. It's the other way around in compare what I would expect. > There is a request-specific header attr that contains common header > attributes parsed in ethnl_parse_header. > > Why don't you have the common header as a root then then have one nested > attr that would carry the request-specific attrs? > > Similar to how it is done in rtnl IFLA_INFO_KIND. To me, what you suggest feels much more odd. I thought about it last time, I thought about it now and the only reason for such layout I could come with would be to work around the unfortunate design flaw of the way validation and parsing is done in genetlink (see below). The situation with IFLA_INFO_KIND is a bit different, what you suggest would rather correspond to having only attributes common for all RTNL on top level and hiding all IFLA_* attributes into a nest (and the same with attributes specific to "ip addr", "ip route", "ip rule" etc.) > You can parse the common stuff in pre_doit/start genl ops and you > don't have to explicitly call ethnl_parse_header. > Also, that would allow you to benefit from the genl doit/dumpit initial > attr parsing and save basically this whole function (alloc,parse). > > Code would be much more simple to follow then. > > Still seems to me that you use the generic netlink but you don't like > the infra too much so you make it up yourself again in parallel - that is > my feeling reading the code. I get the argument about the similarities > of the individual requests and why you have this request_ops (alhough I > don't like it too much). The only thing I don't like about the genetlink infrastructure is the design decision that policy and corresponding maxattr is an attribute of the family rather than a command. This forces anyone who wants to use it to essentially have one common message format for all commands and if that is not possible, to do what you suggest above, hide the actual request into a nest. Whether you use one common attribute type for "command specific nest" or different attribute for each request type, you do not actually make things simpler, you just move the complexity one level lower. You will still have to do your own (per request) parsing of the actual request, the only difference is that you will do it in a different place and use nla_parse_nested() rather than nlmsg_parse(). Rather than bending the message layout to fit into the limitations of unified genetlink parsing, I prefer to keep the logical message structure and do the parsing on my own. > >+static void ethnl_init_reply_data(struct ethnl_reply_data *reply_data, > >+ const struct get_request_ops *ops, > >+ struct net_device *dev) > >+{ > >+ memset(reply_data, '\0', ops->reply_data_size); > > Just "0" would do too. OK > >+ > >+err_msg: > >+ WARN_ONCE(ret == -EMSGSIZE, > > No need to wrap here (and in other similar cases) OK > >+ "calculated message payload length (%d) not sufficient\n", > >+ reply_len); ... > >+ * @prepare_data: > >+ * Retrieve and prepare data needed to compose a reply message. Calls to > >+ * ethtool_ops handlers should be limited to this callback. Common reply > >+ * data (struct ethnl_reply_data) is filled on entry, type specific part > >+ * after it is zero initialized. This callback should only modify the > >+ * type specific part of reply data. Device identification from struct > >+ * ethnl_reply_data is to be used as for dump requests, it iterates > >+ * through network devices which common_req_info::dev points to the > > First time I see this notation. Is "::" something common in kernel code? It's sometimes used to denote a struct member but I don't know if it's common in kernel documentation. I'll write it explicitly. > >+struct get_request_ops { > > Could you please have "ethnl_" prefix for things like this. > "get_request_ops" sounds way to generic. OK Michal