Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp794932pxb; Thu, 19 Nov 2020 14:06:25 -0800 (PST) X-Google-Smtp-Source: ABdhPJyMQGg9RFRllQMUS2/otFqGohc425wlkodGxPu/nxWzHhp+4vnEWdLV9TKQOSm+8QdY5P7G X-Received: by 2002:a17:906:2818:: with SMTP id r24mr31608737ejc.100.1605823585400; Thu, 19 Nov 2020 14:06:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605823585; cv=none; d=google.com; s=arc-20160816; b=h2KFr+1QWOIvlTov0jrN6sOPuDAr5TxZdP6to0HV0HgAXVYAZ6Xi9O3uIyIaudNUO/ /RKPYoizqJc8slXZqMTGeNrOZ7RnQCDRO/3q0P0zQM8hktcYK9qLKOxJmmqiez4e1KeK OagtvJeBlAUl6U42v1KNpY1N3q/3nIZoeo2o75CbkEoNixGIe5X+tYNlAzDykcz6LDQF okKxdV0SwVQ18IWej58jtUU5pe0Uc801UH5lYEvRIFLiX+T2KUbQYrgO8d+AhvMVQQo7 c/EAl7Koj7djqLII5888qBVx5pCiqLUToITIGqa2AHTu0tzFOEbjdcN/9s3v2+enrsNw HXrA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=N8xDL+pXcz5RyFPQFhn4cTV896t+f/6RxJ7Fo+k4zNI=; b=HT0uFU6XKumLH/3WKqeBd7AIz3r2AfhAhR0UdrHM9HgKM9dSJfj4Mv/vRbRI/qKfsM 35I3x9tJ+vqOVGo+5uHUcFf12zB4O1hMM4tT1chmAi1Zbe+I3vRupz97UeEReBSlaszG brZBClCZrZAZNI0MpZO91yB2WdrYpgEQGe0s0AML/9lkmfNLLswOUKD5KY37rRN1vcR+ CH7xh+1u4isrGZW3M5aj2VzW1IfeDgGHlqF7vDaHTqPEcdm2eeUeXaC7u6Rb7ocOHWT8 E+KhE54HgXlhuOxkWZfzWmRnPx3bJfhZfwOdGlALoN9gF63LedDvJmqIVrf0qPkBDxHr tZfg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t2si577251ejs.475.2020.11.19.14.06.01; Thu, 19 Nov 2020 14:06:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726799AbgKSWCG (ORCPT + 99 others); Thu, 19 Nov 2020 17:02:06 -0500 Received: from mx2.suse.de ([195.135.220.15]:34968 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725877AbgKSWCF (ORCPT ); Thu, 19 Nov 2020 17:02:05 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 6FFBAAC41; Thu, 19 Nov 2020 22:02:03 +0000 (UTC) Received: by lion.mk-sys.cz (Postfix, from userid 1000) id 13A59603F9; Thu, 19 Nov 2020 23:02:03 +0100 (CET) Date: Thu, 19 Nov 2020 23:02:03 +0100 From: Michal Kubecek To: tanhuazhong Cc: Andrew Lunn , davem@davemloft.net, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linuxarm@huawei.com, kuba@kernel.org Subject: Re: [RFC net-next 1/2] ethtool: add support for controling the type of adaptive coalescing Message-ID: <20201119220203.fv2uluoeekyoyxrv@lion.mk-sys.cz> References: <1605758050-21061-1-git-send-email-tanhuazhong@huawei.com> <1605758050-21061-2-git-send-email-tanhuazhong@huawei.com> <20201119041557.GR1804098@lunn.ch> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Nov 19, 2020 at 04:56:42PM +0800, tanhuazhong wrote: > On 2020/11/19 12:15, Andrew Lunn wrote: > > > diff --git a/include/uapi/linux/ethtool.h b/include/uapi/linux/ethtool.h > > > index 9ca87bc..afd8de2 100644 > > > --- a/include/uapi/linux/ethtool.h > > > +++ b/include/uapi/linux/ethtool.h > > > @@ -433,6 +433,7 @@ struct ethtool_modinfo { > > > * a TX interrupt, when the packet rate is above @pkt_rate_high. > > > * @rate_sample_interval: How often to do adaptive coalescing packet rate > > > * sampling, measured in seconds. Must not be zero. > > > + * @use_dim: Use DIM for IRQ coalescing, if adaptive coalescing is enabled. > > > * > > > * Each pair of (usecs, max_frames) fields specifies that interrupts > > > * should be coalesced until > > > @@ -483,6 +484,7 @@ struct ethtool_coalesce { > > > __u32 tx_coalesce_usecs_high; > > > __u32 tx_max_coalesced_frames_high; > > > __u32 rate_sample_interval; > > > + __u32 use_dim; > > > }; > > > > You cannot do this. > > > > static noinline_for_stack int ethtool_set_coalesce(struct net_device *dev, > > void __user *useraddr) > > { > > struct ethtool_coalesce coalesce; > > int ret; > > > > if (!dev->ethtool_ops->set_coalesce) > > return -EOPNOTSUPP; > > > > if (copy_from_user(&coalesce, useraddr, sizeof(coalesce))) > > return -EFAULT; > > > > An old ethtool binary is not going to set this extra last byte to > > anything meaningful. You cannot tell if you have an old or new user > > space, so you have no idea if it put anything into use_dim, or if it > > is random junk. Even worse, as there is no indication of data length, ETHTOOL_GCOALESCE ioctl request from old ethtool on new kernel would result in kernel writing past the end of userspace buffer. > > You have to leave the IOCTL interface unchanged, and limit this new > > feature to the netlink API. > > > > Hi, Andrew. > thanks for pointing out this problem, i will fix it. > without callling set_coalesce/set_coalesce of ethtool_ops, do you have any > suggestion for writing/reading this new attribute to/from the driver? add a > new field in net_device or a new callback function in ethtool_ops seems not > good. We could use a similar approach as struct ethtool_link_ksettings, e.g. struct kernel_ethtool_coalesce { struct ethtool_coalesce base; /* new members which are not part of UAPI */ } get_coalesce() and set_coalesce() would get pointer to struct kernel_ethtool_coalesce and ioctl code would be modified to only touch the base (legacy?) part. While already changing the ops arguments, we could also add extack pointer, either as a separate argument or as struct member (I slightly prefer the former). BtW, please don't forget to update the message descriptions in Documentation/networking/ethtool-netlink.rst Michal