Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp1045033ybh; Wed, 11 Mar 2020 16:24:04 -0700 (PDT) X-Google-Smtp-Source: ADFU+vvcp+WnD5MUkdKZUEXC9IiXlSMMSe/rZ3yFqhCzTJgizdYauDUA+DjAbgcqPYsVmyZV11F5 X-Received: by 2002:a05:6830:2105:: with SMTP id i5mr4026222otc.141.1583969044194; Wed, 11 Mar 2020 16:24:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1583969044; cv=none; d=google.com; s=arc-20160816; b=Mejc3xlxxiq8RBBs4jNGQ3AQhv9DvjKaz1SqDRbkbL6fS/PDZcDPiEWkBk7OYTl3Fx wn2gTewrEMsJl+vVDoMoZJnbXkGmfCQCchavwm+F00wtAUaC/XhQsB3ERx8Ppik1hCaJ WcAhI3abm0zBs0M8RnZeXTAD+4ZsQ6z+L3KGuRY+sd+BSX4pcLKyTzWQ+o5Aws8ooY3L DkfeJaUhmo+I2EDqctkTd9HEySMhKZSrk0iypr0qkr1lJoefXlQj5APHIZ2LXVI8ldkX JoWXWfYGPfFTUt4hH50IE4v+t7KxKTomKXd+MRcnG+aF5oXSxrnf2axb6T24yqGt8y9V SYUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=C8yqtqvC/Lqo4Di4W4tAXxDUD3zulwvbVxRCgobZmAI=; b=tjdpCjDUuyWzlJLWV5pryA9854T7OaOFnyf7yUxmvoJnLAjWv5tRQ9V7zPphkFe1qU E/fl4At/r3Mo9nEGy7aGDCHzpqjp6MeYMWWZVvNannYM4/+XTx7nmXAEIT6sAwBx8pgR m0lr2T36aGr2flVHbMf9gNQtCdS51BuM0BOdLNQPXbtbYPqphj+vouUJrYTSG52mw2i5 MPMZKgx04Nb0c/cETpnjYY+19735U8FPWbhbrVwm25s8SIXRZOW89espjNvMo7YQ0vPF ImBnxj769geoT+dtKgdbheP7z6UzIsFsz271j7X4WemO6MPCPATJawSPJ9Xlv0C3AIQW NQPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="PsZ4/Vis"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b13si799653oob.40.2020.03.11.16.23.52; Wed, 11 Mar 2020 16:24:04 -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; dkim=pass header.i=@kernel.org header.s=default header.b="PsZ4/Vis"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387492AbgCKXWx (ORCPT + 99 others); Wed, 11 Mar 2020 19:22:53 -0400 Received: from mail.kernel.org ([198.145.29.99]:38210 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387410AbgCKXWx (ORCPT ); Wed, 11 Mar 2020 19:22:53 -0400 Received: from kicinski-fedora-PC1C0HJN (unknown [163.114.132.128]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D4A6020751; Wed, 11 Mar 2020 23:22:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583968973; bh=3tRF0qODHgRc2/92DC4wS65TgSACth1Nm0FyprTE08s=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=PsZ4/Visf0exp0IIyIOP6r25c9a9N236F1EPIAj5bZAzsXYMCS+fk+fH/u892aVXU seqoxETfxP9p1RA5qXVL31xcrEWgC7Gcyr3iIJQYNOpircxQVaoZWsHTwJFcbFv0OG gmLdxAVmakAR451XxESw/tc+94llxrE8na4mSknw= Date: Wed, 11 Mar 2020 16:22:51 -0700 From: Jakub Kicinski To: Michal Kubecek Cc: David Miller , netdev@vger.kernel.org, Jiri Pirko , Andrew Lunn , Florian Fainelli , John Linville , Johannes Berg , linux-kernel@vger.kernel.org Subject: Re: [PATCH net-next 11/15] ethtool: set device ring sizes with RINGS_SET request Message-ID: <20200311162251.0317e09a@kicinski-fedora-PC1C0HJN> In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 11 Mar 2020 22:40:58 +0100 (CET) Michal Kubecek wrote: > +int ethnl_set_rings(struct sk_buff *skb, struct genl_info *info) > +{ > + struct nlattr *tb[ETHTOOL_A_RINGS_MAX + 1]; > + struct ethtool_ringparam ringparam = {}; > + struct ethnl_req_info req_info = {}; > + const struct nlattr *err_attr; > + const struct ethtool_ops *ops; > + struct net_device *dev; > + bool mod = false; > + int ret; > + > + ret = nlmsg_parse(info->nlhdr, GENL_HDRLEN, tb, > + ETHTOOL_A_RINGS_MAX, rings_set_policy, > + info->extack); > + if (ret < 0) > + return ret; > + ret = ethnl_parse_header_dev_get(&req_info, > + tb[ETHTOOL_A_RINGS_HEADER], > + genl_info_net(info), info->extack, > + true); > + if (ret < 0) > + return ret; > + dev = req_info.dev; > + ops = dev->ethtool_ops; > + if (!ops->get_ringparam || !ops->set_ringparam) > + return -EOPNOTSUPP; Leaking the dev reference here? > + > + rtnl_lock(); > + ret = ethnl_ops_begin(dev); > + if (ret < 0) > + goto out_rtnl; > + ops->get_ringparam(dev, &ringparam); > + > + ethnl_update_u32(&ringparam.rx_pending, tb[ETHTOOL_A_RINGS_RX], &mod); > + ethnl_update_u32(&ringparam.rx_mini_pending, > + tb[ETHTOOL_A_RINGS_RX_MINI], &mod); > + ethnl_update_u32(&ringparam.rx_jumbo_pending, > + tb[ETHTOOL_A_RINGS_RX_JUMBO], &mod); > + ethnl_update_u32(&ringparam.tx_pending, tb[ETHTOOL_A_RINGS_TX], &mod); > + ret = 0; > + if (!mod) > + goto out_ops; > + > + /* ensure new ring parameters are within limits */ > + if (ringparam.rx_pending > ringparam.rx_max_pending) > + err_attr = tb[ETHTOOL_A_RINGS_RX]; > + else if (ringparam.rx_mini_pending > ringparam.rx_mini_max_pending) > + err_attr = tb[ETHTOOL_A_RINGS_RX_MINI]; > + else if (ringparam.rx_jumbo_pending > ringparam.rx_jumbo_max_pending) > + err_attr = tb[ETHTOOL_A_RINGS_RX_JUMBO]; > + else if (ringparam.tx_pending > ringparam.tx_max_pending) > + err_attr = tb[ETHTOOL_A_RINGS_TX]; > + else > + err_attr = NULL; > + if (err_attr) { > + ret = -EINVAL; > + NL_SET_ERR_MSG_ATTR(info->extack, err_attr, > + "requested ring size exceeeds maximum"); > + goto out_ops; > + } > + > + ret = dev->ethtool_ops->set_ringparam(dev, &ringparam); > + > +out_ops: > + ethnl_ops_complete(dev); > +out_rtnl: > + rtnl_unlock(); > + dev_put(dev); > + return ret; > +}