From patchwork Thu Jun 20 11:47:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13705283 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AE52C1ABCC7 for ; Thu, 20 Jun 2024 11:47:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718884037; cv=none; b=Wqrjkb2QCuoJArXaDYWM1PKbnlqkAjDN4WRk5PlMS3ewsN8ynZtlw4I1oy74upJciWBPoCyHVYtcuWeiHZTCqZEkR2aTQu4NcPliQgzq029EbPTxfc/Ftzb60GvoYnvHyMlekhGappaf0FJ5ndluXB5eSyMBO6usUwCpBJw7ajc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718884037; c=relaxed/simple; bh=6k1ACoQfcvcjSGAdPrceCftyFpOBfzhZGPY5Zf5rPpk=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=qZwTg4/76QP2MuaSrPNtfL3VGgEbTY6UePFu5jEV72Gacsm6/QpuNhPdoi8NTxHJJCAYU5Iko4bv78dbxmR7uXFrBlDsim05H6LhvlE8dYRBMyGLB5/ywD85dlvVlNFEiBsBSL/GxjDrtC74sxhmFBRAP/rt6jxNZypRXtayYRU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Nr0/yLCZ; arc=none smtp.client-ip=209.85.128.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Nr0/yLCZ" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-62f4a731ad4so17105487b3.1 for ; Thu, 20 Jun 2024 04:47:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1718884035; x=1719488835; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=GMfbVnUPhTujqT8L/s0KUahjgRHHdhMW+BGUKMdzCh0=; b=Nr0/yLCZkjN8ohaSqqnx/wupfwLgieKfZQ3gwYKfhjj3XELyKN6esp0jRUDFg41AJi Q33ypDmwsbo81sUPfqnhKWuMXGJwQPKfADhtg7pQL4bXyOGiH3bmcmmABskueV/WCFUS FLv13rGBPMHQpxDcC8+5T65XmuPyUT13Y47peUcOj4CUwasq3UETf2jXFfVr3UjTUBOP 5U0KvtC6rVS6b3BpBjz6YBdFCHqv9SqZ/jpcQlL/a10FL2XdCwSy6f9vOMiIowbq7Gto mc8Y3G89g+xaGL0noh2qRQy+JvAMX8fukxEcNgIiKv3FIVo68kMY0vaqjg++eTR88M86 6lYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718884035; x=1719488835; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=GMfbVnUPhTujqT8L/s0KUahjgRHHdhMW+BGUKMdzCh0=; b=BcvfGnXHN6etcOraav3v11QRFVthHsid+H+F3UiIFoK/Napw1S97twcivKkT6eVRLS mwa0S4FY0ZaZT1ZpyyxvA7em+yQdFlojx1tKH2e7hMha3sTHmo4JsijEymBK65CeEk0x kNC7ZhVGyTVI7tfrZcNuoezQ1IdeO+yt7Ei7m7rss+IM3MiwJXxogqJqeMWdoRwSD8nN v5di4kM/mGKUyWW4zEf1TV4Xymh9gfcNdFf9KVajNSzJB8p7qx37pwdgshksox8XAVi0 6+3Zev5CDdunOBJqdzjUaAPlSmaBYvu5QrnX36bKUoYDAJyus+13bHrAHDgLVZqRRtM6 HuaA== X-Forwarded-Encrypted: i=1; AJvYcCUu8l66bKgqJ0kOgVNFWjQoUzcvDro+TXAc0ly36Kbux7e/R7XLXoE3S4XyX4EeW/hyzG/31xxfuQiIlI6hj6VnftJ8HVpd X-Gm-Message-State: AOJu0Yxuw7jJvAKUeFs09Z5V7CGs2ZfJ7HwXjR2QG9xBuerwBxIQZdYF e05/wTThKWrqhaX+QDOX7NOAwTNjf8dVvF8U7xXekOKCc4+YtbGzB+s58M7bI4F/SBrHO1Z/zL2 J7Pp5OUD8KA== X-Google-Smtp-Source: AGHT+IGTV+ykH3VtY8k8oqlf+rgSp7qd6QCZ0qan5fe0sd3ZmUudVedGBjQ42A6dCyUy68KqGqO2aU+vjsUoEw== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a05:6902:c11:b0:e02:c478:c8b9 with SMTP id 3f1490d57ef6-e02c478c9d4mr379784276.12.1718884034734; Thu, 20 Jun 2024 04:47:14 -0700 (PDT) Date: Thu, 20 Jun 2024 11:47:06 +0000 In-Reply-To: <20240620114711.777046-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240620114711.777046-1-edumazet@google.com> X-Mailer: git-send-email 2.45.2.627.g7a2c4fd464-goog Message-ID: <20240620114711.777046-2-edumazet@google.com> Subject: [PATCH net-next 1/6] net: ethtool: grab a netdev reference in dev_ethtool() From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: Ziwei Xiao , Praveen Kaligineedi , Harshitha Ramamurthy , Willem de Bruijn , Jeroen de Borst , Shailend Chand , netdev@vger.kernel.org, eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org We would like to not always grab RTNL for some commands in the future, to decrease RTNL pressure. Grab a reference on the device to ensure it will not disappear while dev_ethtool() is running. Signed-off-by: Eric Dumazet --- net/ethtool/ioctl.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/net/ethtool/ioctl.c b/net/ethtool/ioctl.c index e645d751a5e8998064ef5fa239d465f66c044e6f..01c52159aef7a47165ef11aab2c599ffe4ad345d 100644 --- a/net/ethtool/ioctl.c +++ b/net/ethtool/ioctl.c @@ -2851,18 +2851,14 @@ static int ethtool_set_fecparam(struct net_device *dev, void __user *useraddr) /* The main entry point in this file. Called from net/core/dev_ioctl.c */ static int -__dev_ethtool(struct net *net, struct ifreq *ifr, void __user *useraddr, - u32 ethcmd, struct ethtool_devlink_compat *devlink_state) +__dev_ethtool(struct net *net, struct net_device *dev, struct ifreq *ifr, + void __user *useraddr, u32 ethcmd, + struct ethtool_devlink_compat *devlink_state) { - struct net_device *dev; u32 sub_cmd; int rc; netdev_features_t old_features; - dev = __dev_get_by_name(net, ifr->ifr_name); - if (!dev) - return -ENODEV; - if (ethcmd == ETHTOOL_PERQUEUE) { if (copy_from_user(&sub_cmd, useraddr + sizeof(ethcmd), sizeof(sub_cmd))) return -EFAULT; @@ -3153,6 +3149,8 @@ __dev_ethtool(struct net *net, struct ifreq *ifr, void __user *useraddr, int dev_ethtool(struct net *net, struct ifreq *ifr, void __user *useraddr) { struct ethtool_devlink_compat *state; + netdevice_tracker dev_tracker; + struct net_device *dev; u32 ethcmd; int rc; @@ -3173,9 +3171,16 @@ int dev_ethtool(struct net *net, struct ifreq *ifr, void __user *useraddr) break; } + rc = -ENODEV; + dev = netdev_get_by_name(net, ifr->ifr_name, &dev_tracker, GFP_KERNEL); + if (!dev) + goto exit_free; + rtnl_lock(); - rc = __dev_ethtool(net, ifr, useraddr, ethcmd, state); + rc = __dev_ethtool(net, dev, ifr, useraddr, ethcmd, state); rtnl_unlock(); + netdev_put(dev, &dev_tracker); + if (rc) goto exit_free; From patchwork Thu Jun 20 11:47:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13705284 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BD9A11AC233 for ; Thu, 20 Jun 2024 11:47:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718884039; cv=none; b=JmslSCrvxtDfXf/AWjfAmzpZh/uxP95n5sRCZrnlfkUZ+VVeLn5C7OKOR4+e9t85U/ZwBwtBKkYcil08moPdlvoNuzsNXc4SrxrISMPEFl5Xt1LTh05BSFBwVuApifDs3+nUwHV5Ju1qxJO8HrX9D7T1qh3YCR7oQR54MFCdEjI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718884039; c=relaxed/simple; bh=i5ek/H2xewLnWY0l8ZSHif2f2l/QR/ndrpNq2r/WBic=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=THVCeRaxxF3vqtolzAUhro+D4f7u+8LN5E/PJIz0H3qaVndBFDK4+ZuA32GSZL625TLJTjGrHG51iZkx0iBQsmEAIkgiK8mw/Ue0UyKfRK0r+c7BItTUBo1c+qr1TMFpfHEvDzz9DBPDqQQapBKNQNegbPRjqtBu1s12cn9JfCs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=aMD3tm9Z; arc=none smtp.client-ip=209.85.128.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="aMD3tm9Z" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-632e098ab42so16492697b3.3 for ; Thu, 20 Jun 2024 04:47:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1718884037; x=1719488837; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=1XoJ+LDaZQa6kQaJG3nZHbUf5IeIEJtBZ7kJKCerotM=; b=aMD3tm9Z/t3JZ13B86JffWcopac1XbQGdc2vrmbN5Ufhn9FelVRZhswTA9Hg4YWaq6 aD1Aaqhbuhfo1VojL6q+0Ly8puUvN5vk3sF69IF2Dj4E8DqDFkVCQJRvGEuelhzxlYxv 9A83Z5x96eP4uHdQFB/ZuB4kWbIpIR9rhFXhkjmOsGYMjiA8m1EXCj1AOhEm9oueGUPR A6/Qf7EUgo9HFsLpsYnMspHfJeUTabjvshC777C8iKvM3mePptdacBaYBNND8lCJoMSM dL6uLFE83WQXKNBDSJSUVrDqNB0ynYDcbbXS27rEadvWDEIsZp1IFnH4rNMQ7o9xt0Fj f2Iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718884037; x=1719488837; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=1XoJ+LDaZQa6kQaJG3nZHbUf5IeIEJtBZ7kJKCerotM=; b=Unzl3lWztEEO1sK4DUQsqWFnC5E/8ZcjeRldXbqcZnkTySU2kNMg4I0ximhdB7G73g xHQuS13eQ0zGMw7iUHxxJFAcPeL6X/RTzCIa9qSWgvQ54gvc81TiZ97LiE7mv8HuCO2X saJK2kmTVt0m/Gb0iYS89rvQxBR1LA6tKvKWXi8mdGvHXtP+tu7L6LGlEPFd9Z/7h8T3 6RSVXhdcBHBYe3yD2eh5DvUVsQoQjehRWoX1z/xl3UwLJ2d6idKHUezB64Xxr0c+z90o iNhiUJiCOAtZJ89BZDbo3GkJrSV3F9K8NOfW9tB2TIZd0usS4Ha9qWVpWk4rYdsJ241Y Zfew== X-Forwarded-Encrypted: i=1; AJvYcCW5P5r6Jlj5ed+ZTAUD41AdWlfh1UfJNr39AIkAj5w7ZROYJSHLvwQWLfC1l4GRYtoxBWpvfqRRi6BYGl4wwLJ40Ym3ESqw X-Gm-Message-State: AOJu0YzmRkRwWhLzICzfdp3hpFdjdXVIcHRf+4dI5KwUEFWZmEx+PngL qhZpi27+OwW18UJhmtiy2sF4wywWn9BQ0jlX8l76VhTaZ/d6jAob0yzd0XP0DvcFmI9PG3erMVJ 7sJZQj86ljg== X-Google-Smtp-Source: AGHT+IG6k0LxBp6qaDynyKp3aHZc/8Qonks9BOG1IhBCgd98LvgFiqJRtoz6r+5MdPQCd6CJcUT+CaNeEtKv3A== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a05:6902:729:b0:dfb:1147:cbaa with SMTP id 3f1490d57ef6-e02be1f5f37mr1383388276.10.1718884036815; Thu, 20 Jun 2024 04:47:16 -0700 (PDT) Date: Thu, 20 Jun 2024 11:47:07 +0000 In-Reply-To: <20240620114711.777046-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240620114711.777046-1-edumazet@google.com> X-Mailer: git-send-email 2.45.2.627.g7a2c4fd464-goog Message-ID: <20240620114711.777046-3-edumazet@google.com> Subject: [PATCH net-next 2/6] net: ethtool: add dev_ethtool_cap_check() From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: Ziwei Xiao , Praveen Kaligineedi , Harshitha Ramamurthy , Willem de Bruijn , Jeroen de Borst , Shailend Chand , netdev@vger.kernel.org, eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org Perform capability check in a dedicated helper, before grabbing RTNL. Signed-off-by: Eric Dumazet --- net/ethtool/ioctl.c | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/net/ethtool/ioctl.c b/net/ethtool/ioctl.c index 01c52159aef7a47165ef11aab2c599ffe4ad345d..45e7497839389bad9c6a6b238429b7534bfd6085 100644 --- a/net/ethtool/ioctl.c +++ b/net/ethtool/ioctl.c @@ -2850,21 +2850,8 @@ static int ethtool_set_fecparam(struct net_device *dev, void __user *useraddr) /* The main entry point in this file. Called from net/core/dev_ioctl.c */ -static int -__dev_ethtool(struct net *net, struct net_device *dev, struct ifreq *ifr, - void __user *useraddr, u32 ethcmd, - struct ethtool_devlink_compat *devlink_state) +static int dev_ethtool_cap_check(struct net *net, u32 sub_cmd) { - u32 sub_cmd; - int rc; - netdev_features_t old_features; - - if (ethcmd == ETHTOOL_PERQUEUE) { - if (copy_from_user(&sub_cmd, useraddr + sizeof(ethcmd), sizeof(sub_cmd))) - return -EFAULT; - } else { - sub_cmd = ethcmd; - } /* Allow some commands to be done by anyone */ switch (sub_cmd) { case ETHTOOL_GSET: @@ -2908,6 +2895,16 @@ __dev_ethtool(struct net *net, struct net_device *dev, struct ifreq *ifr, if (!ns_capable(net->user_ns, CAP_NET_ADMIN)) return -EPERM; } + return 0; +} + +static int +__dev_ethtool(struct net_device *dev, struct ifreq *ifr, + void __user *useraddr, u32 ethcmd, u32 sub_cmd, + struct ethtool_devlink_compat *devlink_state) +{ + netdev_features_t old_features; + int rc; if (dev->dev.parent) pm_runtime_get_sync(dev->dev.parent); @@ -3151,7 +3148,7 @@ int dev_ethtool(struct net *net, struct ifreq *ifr, void __user *useraddr) struct ethtool_devlink_compat *state; netdevice_tracker dev_tracker; struct net_device *dev; - u32 ethcmd; + u32 ethcmd, sub_cmd; int rc; if (copy_from_user(ðcmd, useraddr, sizeof(ethcmd))) @@ -3171,13 +3168,23 @@ int dev_ethtool(struct net *net, struct ifreq *ifr, void __user *useraddr) break; } + if (ethcmd == ETHTOOL_PERQUEUE) { + if (copy_from_user(&sub_cmd, useraddr + sizeof(ethcmd), sizeof(sub_cmd))) + return -EFAULT; + } else { + sub_cmd = ethcmd; + } + rc = dev_ethtool_cap_check(net, sub_cmd); + if (rc) + goto exit_free; + rc = -ENODEV; dev = netdev_get_by_name(net, ifr->ifr_name, &dev_tracker, GFP_KERNEL); if (!dev) goto exit_free; rtnl_lock(); - rc = __dev_ethtool(net, dev, ifr, useraddr, ethcmd, state); + rc = __dev_ethtool(dev, ifr, useraddr, ethcmd, sub_cmd, state); rtnl_unlock(); netdev_put(dev, &dev_tracker); From patchwork Thu Jun 20 11:47:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13705285 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D9B331AC241 for ; Thu, 20 Jun 2024 11:47:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718884041; cv=none; b=b3TrGxk/jMUYGZIXP64Ni+5KYDa1KsYLTdEIeU7Zv3PPKC6IB9Dg/mjXrkmRCLoD0VVWbHa7Ad9nUUNOleLTTZabIGxCULRJfN86TeYsYAd1t6FH6xFxU8PIVTFm9JWXTcXk9M+mS0Mg3rqnYb0/UW6KsVLUNm5LMjENL5mcLGw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718884041; c=relaxed/simple; bh=jXv1mhCP5jaX9+OWPN3NNX9k6EYeKPYnn+twk5/eQB4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Ge60KL478VnwVf+QME6uqLF2iWXD57dOvmUxtRCHJShoVjb4WIj9AsusGMyOJ7nrZUBZIQqRzmxkwZWEFjuGU+00+p5VPLiKQlno8O4+FlbEQ8ulkjCZnF3vDtfawE9+Vi7vSwF1NyQQQiL9WHwYl1giv6iUvODlco0eBqtgxiw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=TmtMOZ2f; arc=none smtp.client-ip=209.85.219.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="TmtMOZ2f" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dfeff072f65so1358444276.3 for ; Thu, 20 Jun 2024 04:47:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1718884039; x=1719488839; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=iVUU9/gt+Bb7CTynVPH1yn7xrC+qX9qd8pqIfpL1N8U=; b=TmtMOZ2fiYwaE+izbGoynjWmOpvU5E4pWJn0iUUzjkHo6HtNxUsEH05LoHkkVBVNaQ 6X6lwHGFIy2HzlRurdGukuSRRUPOasZrqTvaNKA5W3GqcL04odnNOYEONkBZUF1Qemud /cxLEcfrR5FPfMhKIUlB1BnjPRgLPu7TBymjSH1iWXoLJxmrslH5mS7eDJ5okaZdYtnt rh0W+/VyT/QKOzqm/MxO8jrV9rILMgjYYNi0vyP3WOv6rcSCTKMjGPmfb6ZVrH0dacaA r11+WReMLePeIEAzEk0k3t064xZsio2sJMv10bNUICiBry5k11qXFxYaap3yAyPujHW/ yLAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718884039; x=1719488839; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=iVUU9/gt+Bb7CTynVPH1yn7xrC+qX9qd8pqIfpL1N8U=; b=sU+aM/8nVaHCISeKHdOkeFwZJcUmmY+E0EhW8u8luTPZvXh10oKtg1whkgmLXI0+Ak Pd4wcdeJ4gbIvwYNuQsWpLthqRDBan4tj9+6II2J59HvzcHFbqHkkT1lWQxXQkFpYVp3 r406RkIpVEKpz5INQz4ud0u1mG0U8AnjbCVzhiiKmKPdrDhHRAla7vZhy2FDR8JqPQub INgVu2WLtTjqWBFq4GRFiRiLTgO61QmZ+Kg7P4wDFpoZaQg7nIMexnMjZ3C/qXPdRXch 5/lPu0ODlqcLTOhE1OMho5MVNeq+JCRVYxMa1MEAwRmKsOXcfAogwz25gWx2iPJW85xK SufQ== X-Forwarded-Encrypted: i=1; AJvYcCWq2S2+tO8z/YkrTRQX8sYhzV1OTyYuoK83i4hZqWMPJIwfbjEXJw8Zmnxv+r8xUEBgIcgljpIysFE+Yg53h60QXk9r8WC3 X-Gm-Message-State: AOJu0Yz6FQcwdkr38mXWcCWUOUn8IC6IE+YIdXw94sDtmn2q1cdvc8M0 CzoJSBNHLvB17DEty9tqWj3wyhshfgjtMt5Clsa0nfziinTeGJ4bo8NQrMlb6NlUn6DIO+/g0hR tT7fCLBy7eg== X-Google-Smtp-Source: AGHT+IH/wMEnI5lKIPL5RyTqW8+iMV3Qst6TygS7WixRd1oHtBL+ChD2KSsPhNmtHENDPN6nEQfrEedfk/kWAA== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a05:6902:1202:b0:dfb:168d:c02e with SMTP id 3f1490d57ef6-e02be0f4c01mr526817276.3.1718884038592; Thu, 20 Jun 2024 04:47:18 -0700 (PDT) Date: Thu, 20 Jun 2024 11:47:08 +0000 In-Reply-To: <20240620114711.777046-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240620114711.777046-1-edumazet@google.com> X-Mailer: git-send-email 2.45.2.627.g7a2c4fd464-goog Message-ID: <20240620114711.777046-4-edumazet@google.com> Subject: [PATCH net-next 3/6] net: ethtool: perform pm duties outside of rtnl lock From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: Ziwei Xiao , Praveen Kaligineedi , Harshitha Ramamurthy , Willem de Bruijn , Jeroen de Borst , Shailend Chand , netdev@vger.kernel.org, eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org Move pm_runtime_get_sync() and pm_runtime_put() out of __dev_ethtool to dev_ethtool() while RTNL is not yet held. These helpers do not depend on RTNL. Signed-off-by: Eric Dumazet --- net/ethtool/ioctl.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/net/ethtool/ioctl.c b/net/ethtool/ioctl.c index 45e7497839389bad9c6a6b238429b7534bfd6085..70bb0d2fa2ed416fdff3de71a4f752e4a1bba67a 100644 --- a/net/ethtool/ioctl.c +++ b/net/ethtool/ioctl.c @@ -2906,14 +2906,6 @@ __dev_ethtool(struct net_device *dev, struct ifreq *ifr, netdev_features_t old_features; int rc; - if (dev->dev.parent) - pm_runtime_get_sync(dev->dev.parent); - - if (!netif_device_present(dev)) { - rc = -ENODEV; - goto out; - } - if (dev->ethtool_ops->begin) { rc = dev->ethtool_ops->begin(dev); if (rc < 0) @@ -3137,9 +3129,6 @@ __dev_ethtool(struct net_device *dev, struct ifreq *ifr, if (old_features != dev->features) netdev_features_change(dev); out: - if (dev->dev.parent) - pm_runtime_put(dev->dev.parent); - return rc; } @@ -3183,9 +3172,19 @@ int dev_ethtool(struct net *net, struct ifreq *ifr, void __user *useraddr) if (!dev) goto exit_free; + if (dev->dev.parent) + pm_runtime_get_sync(dev->dev.parent); + + if (!netif_device_present(dev)) + goto out_pm; + rtnl_lock(); rc = __dev_ethtool(dev, ifr, useraddr, ethcmd, sub_cmd, state); rtnl_unlock(); + +out_pm: + if (dev->dev.parent) + pm_runtime_put(dev->dev.parent); netdev_put(dev, &dev_tracker); if (rc) From patchwork Thu Jun 20 11:47:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13705286 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 76F821AAE20 for ; Thu, 20 Jun 2024 11:47:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718884043; cv=none; b=TpXUw4tFWbjazJQ+VXG6W1wVsDhrZL03OXXzzDrklPiY8esmWkQYu/HJ2mM3E6dm8tG08s0Yyg9z/Dy5GaKSwsWvuLxtV+bE+ACKRBG2+1JwAGQ/LeK411aof3rnXlgFP4SUueoxIJvp9vpVrx4l9/UA34Rlz7EUMHEx9/VnfC4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718884043; c=relaxed/simple; bh=BH7c2k7bxyXt8QCS2LFtIOQ8YLAZtpWrEdG8OuqcR90=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=m+CmcB/z8z829kQqREXrEX3qeo+VtwncyUNbv9QlYIMnUa/yMTCodiOcsbDFkIbDTEadMQWs6s0nnG7+r/n8k+eaUsSLXac09hCExRZTzCzC7/PBjewIZCpqDPlTdip90UTX/t4PRKIwuwxJj7EbJBc2evRF16MEKtADzHmFHB4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=0UfFnqHk; arc=none smtp.client-ip=209.85.219.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="0UfFnqHk" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e02b58759c2so1484217276.3 for ; Thu, 20 Jun 2024 04:47:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1718884040; x=1719488840; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=201iyVUIyfZ0rht8gMaTvcbCQRn7se0kCnaq9C0QCtE=; b=0UfFnqHkZlcWlWq0DlEKaIi7R8bxjUhQqnyedH+zrLSZCkRrmB7pXPYnRUZcstXtBZ 8fLVipcgW3MWS8PrxQ9tJKh2fHQGFuQTZq5TFU4/EyesXQNbyIpDHid8FXDXRFxE7jOk 961M8I9R8GnRBEZdjzcMInLbZqwGvytmlLPnEDUBPJSn04ODXwFSabift1x9wbTsG4aP QB7GBZoYZNKhnQx2F7rnwgEp2mWAvoG3P5PUMgTRvZVV5bK4VBvIX9LU8041a+0w8kwa L0l4uZzJviDCPFAnMCl2lEX0sQi2bJ7uAS93OnpxlOoxRRDy/MBF6fGCSIPuvHIOmNQQ Np6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718884040; x=1719488840; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=201iyVUIyfZ0rht8gMaTvcbCQRn7se0kCnaq9C0QCtE=; b=uHBsgbSlAhr7f8TDGtGKUdyvabY/0q9wDsBiSdoZtP5p9EjGMUuGXu2Sgp2FPb9dMQ me2yIqt+fY1GXX/KDDxa5EIej1y87mkP0Gpag4HG88TQlzfjZoDYuZClAtP8gnOTtKYa baFmYUfEpTH7lgjFQhDFPQzpyv14+fjbIrN7HPsgs8bqa6D8+Yhg2lYzZdQiJfqOKSX6 E8QOu5ZlvkKy1WGD1qpmFsK6Tcq4rCOBNQ3qtCVEEP90h3JmVtUUaURgtNNbN/QSy4wp xaqD2em7WRWhaeCzJcet+rhUTMHystWfYa9fP46vgzpbirhPPmWG/ojoiUKHjEZom92W qEXg== X-Forwarded-Encrypted: i=1; AJvYcCVlx5E5W7xtl5FEFkieXFCzp7okS8mNMUfbCJOwBlXeOcg1udEFrDG+zoAznFf9YwAkBpIs8c3K4YgK2tjHGqO05M+tP9YK X-Gm-Message-State: AOJu0YzfJs1/mJt4sqxW9dVhxr6p3zCma9hbNvqRap1mA2ywEZrWpvg3 OgT4Tp9LBku4BJmiAWPnud9Gm4xTyN2G8DfyOeck1ja18b19snKiXGWo3SCRmAYr5QX8aZNFllG FtNkS5BDjwQ== X-Google-Smtp-Source: AGHT+IFsTqE6kxKtm02oUcRuQFFhIGsnWljMrB3WX00CcdtsaItRAyfMM0jjCODs4Ibpa5BWAJ8XIzVFMzbUaw== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a05:6902:1007:b0:e02:ce2f:cf07 with SMTP id 3f1490d57ef6-e02ce2fd313mr239560276.5.1718884040506; Thu, 20 Jun 2024 04:47:20 -0700 (PDT) Date: Thu, 20 Jun 2024 11:47:09 +0000 In-Reply-To: <20240620114711.777046-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240620114711.777046-1-edumazet@google.com> X-Mailer: git-send-email 2.45.2.627.g7a2c4fd464-goog Message-ID: <20240620114711.777046-5-edumazet@google.com> Subject: [PATCH net-next 4/6] net: ethtool: call ethtool_get_one_feature() without RTNL From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: Ziwei Xiao , Praveen Kaligineedi , Harshitha Ramamurthy , Willem de Bruijn , Jeroen de Borst , Shailend Chand , netdev@vger.kernel.org, eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org ethtool_get_one_feature() is used by ETHTOOL_GTXCSUM, ETHTOOL_GRXCSUM, ETHTOOL_GSG, ETHTOOL_GTSO, ETHTOOL_GGSO and ETHTOOL_GGRO. Add WRITE_ONCE() and READ_ONCE() annotations on dev->features. Note that many READ_ONCE() annotations are probably missing in many drivers, but this is orthogonal to this patch. Signed-off-by: Eric Dumazet --- net/core/dev.c | 10 +++++----- net/ethtool/ioctl.c | 30 ++++++++++++++++-------------- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/net/core/dev.c b/net/core/dev.c index 093d82bf0e2886d4948f4952353c71c92e3586c6..b18223ed269f24bedd02b7c435de0ce2f1f8edf3 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -3536,7 +3536,7 @@ static netdev_features_t gso_features_check(const struct sk_buff *skb, netdev_features_t netif_skb_features(struct sk_buff *skb) { struct net_device *dev = skb->dev; - netdev_features_t features = dev->features; + netdev_features_t features = READ_ONCE(dev->features); if (skb_is_gso(skb)) features = gso_features_check(skb, dev, features); @@ -10016,7 +10016,7 @@ int __netdev_update_features(struct net_device *dev) * but *after* calling udp_tunnel_drop_rx_info. */ if (features & NETIF_F_RX_UDP_TUNNEL_PORT) { - dev->features = features; + WRITE_ONCE(dev->features, features); udp_tunnel_get_rx_info(dev); } else { udp_tunnel_drop_rx_info(dev); @@ -10025,7 +10025,7 @@ int __netdev_update_features(struct net_device *dev) if (diff & NETIF_F_HW_VLAN_CTAG_FILTER) { if (features & NETIF_F_HW_VLAN_CTAG_FILTER) { - dev->features = features; + WRITE_ONCE(dev->features, features); err |= vlan_get_rx_ctag_filter_info(dev); } else { vlan_drop_rx_ctag_filter_info(dev); @@ -10034,14 +10034,14 @@ int __netdev_update_features(struct net_device *dev) if (diff & NETIF_F_HW_VLAN_STAG_FILTER) { if (features & NETIF_F_HW_VLAN_STAG_FILTER) { - dev->features = features; + WRITE_ONCE(dev->features, features); err |= vlan_get_rx_stag_filter_info(dev); } else { vlan_drop_rx_stag_filter_info(dev); } } - dev->features = features; + WRITE_ONCE(dev->features, features); } return err < 0 ? 0 : 1; diff --git a/net/ethtool/ioctl.c b/net/ethtool/ioctl.c index 70bb0d2fa2ed416fdff3de71a4f752e4a1bba67a..d0c9d2ad9c3d0acb1be00eb4970d3a1ef9da030a 100644 --- a/net/ethtool/ioctl.c +++ b/net/ethtool/ioctl.c @@ -245,13 +245,13 @@ static netdev_features_t ethtool_get_feature_mask(u32 eth_cmd) } } -static int ethtool_get_one_feature(struct net_device *dev, +static int ethtool_get_one_feature(const struct net_device *dev, char __user *useraddr, u32 ethcmd) { netdev_features_t mask = ethtool_get_feature_mask(ethcmd); struct ethtool_value edata = { .cmd = ethcmd, - .data = !!(dev->features & mask), + .data = !!(READ_ONCE(dev->features) & mask), }; if (copy_to_user(useraddr, &edata, sizeof(edata))) @@ -3049,14 +3049,6 @@ __dev_ethtool(struct net_device *dev, struct ifreq *ifr, case ETHTOOL_SFEATURES: rc = ethtool_set_features(dev, useraddr); break; - case ETHTOOL_GTXCSUM: - case ETHTOOL_GRXCSUM: - case ETHTOOL_GSG: - case ETHTOOL_GTSO: - case ETHTOOL_GGSO: - case ETHTOOL_GGRO: - rc = ethtool_get_one_feature(dev, useraddr, ethcmd); - break; case ETHTOOL_STXCSUM: case ETHTOOL_SRXCSUM: case ETHTOOL_SSG: @@ -3178,10 +3170,20 @@ int dev_ethtool(struct net *net, struct ifreq *ifr, void __user *useraddr) if (!netif_device_present(dev)) goto out_pm; - rtnl_lock(); - rc = __dev_ethtool(dev, ifr, useraddr, ethcmd, sub_cmd, state); - rtnl_unlock(); - + switch (ethcmd) { + case ETHTOOL_GTXCSUM: + case ETHTOOL_GRXCSUM: + case ETHTOOL_GSG: + case ETHTOOL_GTSO: + case ETHTOOL_GGSO: + case ETHTOOL_GGRO: + rc = ethtool_get_one_feature(dev, useraddr, ethcmd); + break; + default: + rtnl_lock(); + rc = __dev_ethtool(dev, ifr, useraddr, ethcmd, sub_cmd, state); + rtnl_unlock(); + } out_pm: if (dev->dev.parent) pm_runtime_put(dev->dev.parent); From patchwork Thu Jun 20 11:47:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13705287 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 67F621AB8F0 for ; Thu, 20 Jun 2024 11:47:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718884044; cv=none; b=O9kkzDyHfr5mbCULb8Nszm7DSPcLKI6Dj2aka0e7R0raFrRKZ+XYOvdgBE9n2aO0v2nARQXg0tzXBRLM+lMs47arpLxgKKirJjk7y5mepp2kbVhvRqE7uouJsgVNIsrpohCrIWUuhUdSqEJZzB9tThtQEp60JP5Ujy4OUSQoRmc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718884044; c=relaxed/simple; bh=0GGECpbjh3ycFYT6pu/CUetA0+l1IS1AkGwWCJN9biw=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=SwP9R0qrol6L0EbrzLXjsRtIvfUW3WXFZj7arMIwbPcr0Afb+LFCgjtx3lckVblyU28wAJScpaHjnNbjmPKLy2yAxi6T726GxILIw4qQYSZvUmnQYnO7sht4xX7L5v4DWIOZRlzf7s3gNRVSSizeYdufI8lAHcQZE1X5LY441/Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=X/Qhy9cZ; arc=none smtp.client-ip=209.85.219.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="X/Qhy9cZ" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e02c3d0f784so1351393276.0 for ; Thu, 20 Jun 2024 04:47:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1718884042; x=1719488842; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=+nNbInJfrL3GbMNQXNczNCVPth5SAn7I4SKHYQrALmw=; b=X/Qhy9cZP2re4qjW3xC2+OSbzSTKT/ecmj75bdPyyATZtduD5lACAqXQO+JHVX9diy 9nPZkiyy/AaN2/0dDhgzHfgk45vHflQNkQbJatZiBGegGlDWLNk33n+Uh928tKzma/Ub z68ognz1oWmhveC97zcKnxZvYvUiGd3HX5AFyah/CngG6Q6IZZHzERWZocN/6C+Azu5v XtfEz5xR18VF3uwijZ8dBy+eETsItF6VCI9OPL/zjiM1AYiDNJTTprKE++3NL5ISOjPz 32REVVj2o8B3IsNM5ZxZAMpxmx3a26/na37SLSB5/t4hdAQyMv9ZzmhFEGy2B1hmWV5z S6qQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718884042; x=1719488842; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=+nNbInJfrL3GbMNQXNczNCVPth5SAn7I4SKHYQrALmw=; b=MRIwEb7DOD6vEOPJO0BsZChisWGdtz4JJNNj2MJKBUxBEUqBeQH+mAcavCNtP8a8VH QeekTDA4+xqUzJK6hl29fiSEb1tEqnh06yQGXU69LgRNbj/xe1Sllrifv5Z7JbbTK/wX Qu7Tw2xkpYStQE0npZc20+UDHh5mCZo+eu9V5ImAKFPf2qFl5Z6S7ZDO9IRk2h+tXZE/ DtBFdrLEI+YTD2l4Q0LjF2td2yNsBNTmBLjcJmr4uFpSDkywypVsCbE7jEJLJridbnsi ykOxgaqbaLpxwFdkyQzK6bv+EjrXI8T084QIDDRHFTscB7OSs73+7woHF1TP8fPLuuFW uFbg== X-Forwarded-Encrypted: i=1; AJvYcCUtRBLW0QVBOXkMq2hIlvaGbVYQtu06cM7ta/oEhpAsZT3H9zfyzZE+ZsLzrrEgkQTsTOlxE63BscaHw+3gu/XUhn4OYKM2 X-Gm-Message-State: AOJu0YyGOUKTi2S8SUIeGizixOqi3ig+ZE7oH1ElE66DOuAZYc9tV9qA vXALJo6/+vQ++nzxUW8Z3rO5UHAcjQSbHvuodYCTxbhGUlzrfkaWjI2McTmlw3DCYMgbMJrqaAc bnEX2ABVEmw== X-Google-Smtp-Source: AGHT+IGkta7OKISp6IhsfAFYVw6fN3+Kkv2fVqNBrdn0XAyMYJBucblZTA1Hl026gTBRzXpakpfpMueAo+Bkmw== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a05:6902:18c8:b0:df4:8ecb:ae57 with SMTP id 3f1490d57ef6-e02be1dc849mr624130276.10.1718884042340; Thu, 20 Jun 2024 04:47:22 -0700 (PDT) Date: Thu, 20 Jun 2024 11:47:10 +0000 In-Reply-To: <20240620114711.777046-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240620114711.777046-1-edumazet@google.com> X-Mailer: git-send-email 2.45.2.627.g7a2c4fd464-goog Message-ID: <20240620114711.777046-6-edumazet@google.com> Subject: [PATCH net-next 5/6] net: ethtool: implement lockless ETHTOOL_GFLAGS From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: Ziwei Xiao , Praveen Kaligineedi , Harshitha Ramamurthy , Willem de Bruijn , Jeroen de Borst , Shailend Chand , netdev@vger.kernel.org, eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org ETHTOOL_GFLAGS only reads dev->features, there is no need for RTNL protection. Signed-off-by: Eric Dumazet --- net/ethtool/ioctl.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/net/ethtool/ioctl.c b/net/ethtool/ioctl.c index d0c9d2ad9c3d0acb1be00eb4970d3a1ef9da030a..56b959495698c7cd0dfda995be7232e7cbb314a2 100644 --- a/net/ethtool/ioctl.c +++ b/net/ethtool/ioctl.c @@ -291,17 +291,18 @@ static int ethtool_set_one_feature(struct net_device *dev, static u32 __ethtool_get_flags(struct net_device *dev) { + netdev_features_t features = READ_ONCE(dev->features); u32 flags = 0; - if (dev->features & NETIF_F_LRO) + if (features & NETIF_F_LRO) flags |= ETH_FLAG_LRO; - if (dev->features & NETIF_F_HW_VLAN_CTAG_RX) + if (features & NETIF_F_HW_VLAN_CTAG_RX) flags |= ETH_FLAG_RXVLAN; - if (dev->features & NETIF_F_HW_VLAN_CTAG_TX) + if (features & NETIF_F_HW_VLAN_CTAG_TX) flags |= ETH_FLAG_TXVLAN; - if (dev->features & NETIF_F_NTUPLE) + if (features & NETIF_F_NTUPLE) flags |= ETH_FLAG_NTUPLE; - if (dev->features & NETIF_F_RXHASH) + if (features & NETIF_F_RXHASH) flags |= ETH_FLAG_RXHASH; return flags; @@ -2993,10 +2994,6 @@ __dev_ethtool(struct net_device *dev, struct ifreq *ifr, case ETHTOOL_GPERMADDR: rc = ethtool_get_perm_addr(dev, useraddr); break; - case ETHTOOL_GFLAGS: - rc = ethtool_get_value(dev, useraddr, ethcmd, - __ethtool_get_flags); - break; case ETHTOOL_SFLAGS: rc = ethtool_set_value(dev, useraddr, __ethtool_set_flags); break; @@ -3179,6 +3176,10 @@ int dev_ethtool(struct net *net, struct ifreq *ifr, void __user *useraddr) case ETHTOOL_GGRO: rc = ethtool_get_one_feature(dev, useraddr, ethcmd); break; + case ETHTOOL_GFLAGS: + rc = ethtool_get_value(dev, useraddr, ethcmd, + __ethtool_get_flags); + break; default: rtnl_lock(); rc = __dev_ethtool(dev, ifr, useraddr, ethcmd, sub_cmd, state); From patchwork Thu Jun 20 11:47:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13705288 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3FFE41AC45F for ; Thu, 20 Jun 2024 11:47:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718884046; cv=none; b=GAaGeLzQJTb5puk3JLYX40b71izITeP61zt2qvsEvh+JcjAnWEhLpjMMJOktSPnVgumqNNKHWQorfUILMXScIWfC1ZAP7w4VUy4qNU2aZr7aOZjXYrT7Atj7xC4KS67ZARSvjl8ZzfQak5onm6EZRw0enjrlinpZe2nCSbRE9kU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718884046; c=relaxed/simple; bh=+T49OIRbKSaE+8+oJxEeRuCse4sjpV+WKYunARmT280=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Q34cPyudHE2iaH9I4rtn+vH2foM3gDEkJwlggQNkjZbLdBmkOVdibMWVR5di0yNSaB+dsdWTT9gVF11kI1NFcCEGNpdhCUeG/3/7LqMYHfULhKJ55yqqtpDXFS0wPEQAgRl4OZ99On56Asl3iYYA/5COOiYcfhrFYHNje7CY5jA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=fKJQ/NB9; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="fKJQ/NB9" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-62a08273919so12624357b3.1 for ; Thu, 20 Jun 2024 04:47:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1718884044; x=1719488844; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=JD3FBhuAf4qKqnoMJjK56b09cZCacV5PEgeQK14QU1Q=; b=fKJQ/NB9omNuuiqGgM6u7jTTUcaSmCHg/xaxBYKTba0u3BsPeu3bFw1qiBxRyHGb4/ sGFZ4vnRRtGZSPhqyiv0s++tKTJqKvY3wBjzWs8+uRoYmtaRDlRDilfs2ESQwqp0HcvE 2JLy6SYvktnWNwbEcWGGJj/rAJFjXro7/zSBDn9qd27Hcb93cM3kDyZIO+apmGPtnW9F HfGxq8DOU/HiRE7Z+zsrNxc2d/f1iag9BRyL4sFI25fQdV2wjw3jUe7MNeWLbBxDVKSS 4cbNEjh53dRfc7ygWwsI598FrTgeYbir22l1x9n7PN35JdJYrza0LOODayed4jG3ZAAQ 05ZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718884044; x=1719488844; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=JD3FBhuAf4qKqnoMJjK56b09cZCacV5PEgeQK14QU1Q=; b=Ji6us7IlEfWiV1ixpd5cZsODp2524QCeK32TzBAZwk8uHHqBA3IYRlPfRl7xHd9eBC yrAP7c5+e0rFwGXRSfbI2BSiGk8sqHf0lfG9nX45kQvlTPcUJORhaOqo0CErg6tRqJts qO7+erJPNKTuZYFLmaDaQ6QQOsMSKzHoVz/YfMr9alAXSZfF6wBNTStxDMRMLWcGkOfi ZuhGooKUv80GrxgSxF9yHrZ2qIkEYi7VvoERjz0I9W0zYHuqM6VvtBZ3P7paQgMc6Qmp Q5nUvi+fnoZmMK9AizzcGnbXZ6epxjqKEr4vBm0u+7QcHgDVS0qaZoCV1T8EaDHo8DVa mQ8g== X-Forwarded-Encrypted: i=1; AJvYcCUtNeAG1qC0sr8oYNQGtMI1n5fGhlpU9475OQvv8u/HaORoviqcN2slYIdbCbDTysmIRBoO7X33mndgo6W056hwfFx970vI X-Gm-Message-State: AOJu0Yyv81p3fIsj1E/zg/axzY+c4JS9K09cy0z+nmE6KfXcWgjknKWt ZENOzhHWUmH1zKP2999llM0tJyQ9pjkeWHq6zq/KtbTcteGzgeHi82fdaXERT1nwVdUpYTcMIC5 a41rLB07qZQ== X-Google-Smtp-Source: AGHT+IGaeYUovy1thNl52BFgtKzBRdwkBirvhnowiuw2TaDijojjzJMrBDptmJJUPNkEsV2cLjF7v+UXvPY+DQ== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a05:690c:25c7:b0:62c:de05:5a78 with SMTP id 00721157ae682-63a8f524cebmr11483177b3.6.1718884043947; Thu, 20 Jun 2024 04:47:23 -0700 (PDT) Date: Thu, 20 Jun 2024 11:47:11 +0000 In-Reply-To: <20240620114711.777046-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240620114711.777046-1-edumazet@google.com> X-Mailer: git-send-email 2.45.2.627.g7a2c4fd464-goog Message-ID: <20240620114711.777046-7-edumazet@google.com> Subject: [PATCH net-next 6/6] net: ethtool: add the ability to run ethtool_[gs]et_rxnfc() without RTNL From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: Ziwei Xiao , Praveen Kaligineedi , Harshitha Ramamurthy , Willem de Bruijn , Jeroen de Borst , Shailend Chand , netdev@vger.kernel.org, eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org For better scalability, drivers can prefer to implement their own locking schem (for instance one mutex per port or queue) instead of relying on RTNL. This patch adds a new boolean field in ethtool_ops : rxnfc_parallel Drivers can opt-in to this new behavior. Signed-off-by: Eric Dumazet --- include/linux/ethtool.h | 2 ++ net/ethtool/ioctl.c | 43 +++++++++++++++++++++++++++-------------- 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/include/linux/ethtool.h b/include/linux/ethtool.h index 6fd9107d3cc010dd2f1ecdb005c412145c461b6c..ee9b8054165361c9236186ff61f886e53cfa6b49 100644 --- a/include/linux/ethtool.h +++ b/include/linux/ethtool.h @@ -748,6 +748,7 @@ struct ethtool_rxfh_param { * error code or zero. * @set_rxnfc: Set RX flow classification rules. Returns a negative * error code or zero. + * @rxnfc_parallel: true if @set_rxnfc, @get_rxnfc and @get_rxfh do not need RTNL. * @flash_device: Write a firmware image to device's flash memory. * Returns a negative error code or zero. * @reset: Reset (part of) the device, as specified by a bitmask of @@ -907,6 +908,7 @@ struct ethtool_ops { int (*get_rxnfc)(struct net_device *, struct ethtool_rxnfc *, u32 *rule_locs); int (*set_rxnfc)(struct net_device *, struct ethtool_rxnfc *); + bool rxnfc_parallel; int (*flash_device)(struct net_device *, struct ethtool_flash *); int (*reset)(struct net_device *, u32 *); u32 (*get_rxfh_key_size)(struct net_device *); diff --git a/net/ethtool/ioctl.c b/net/ethtool/ioctl.c index 56b959495698c7cd0dfda995be7232e7cbb314a2..e65bd08412aeaf35d276ba48e1ebe71656e486fc 100644 --- a/net/ethtool/ioctl.c +++ b/net/ethtool/ioctl.c @@ -986,26 +986,34 @@ static noinline_for_stack int ethtool_set_rxnfc(struct net_device *dev, if (rc) return rc; + if (!ops->rxnfc_parallel) + rtnl_lock(); + if (ops->get_rxfh) { struct ethtool_rxfh_param rxfh = {}; rc = ops->get_rxfh(dev, &rxfh); if (rc) - return rc; + goto unlock; /* Sanity check: if symmetric-xor is set, then: * 1 - no other fields besides IP src/dst and/or L4 src/dst * 2 - If src is set, dst must also be set */ + rc = -EINVAL; if ((rxfh.input_xfrm & RXH_XFRM_SYM_XOR) && ((info.data & ~(RXH_IP_SRC | RXH_IP_DST | RXH_L4_B_0_1 | RXH_L4_B_2_3)) || (!!(info.data & RXH_IP_SRC) ^ !!(info.data & RXH_IP_DST)) || (!!(info.data & RXH_L4_B_0_1) ^ !!(info.data & RXH_L4_B_2_3)))) - return -EINVAL; + goto unlock; } rc = ops->set_rxnfc(dev, &info); + +unlock: + if (!ops->rxnfc_parallel) + rtnl_unlock(); if (rc) return rc; @@ -1042,7 +1050,14 @@ static noinline_for_stack int ethtool_get_rxnfc(struct net_device *dev, } } + if (!ops->rxnfc_parallel) + rtnl_lock(); + ret = ops->get_rxnfc(dev, &info, rule_buf); + + if (!ops->rxnfc_parallel) + rtnl_unlock(); + if (ret < 0) goto err_out; @@ -3007,18 +3022,6 @@ __dev_ethtool(struct net_device *dev, struct ifreq *ifr, rc = ethtool_set_value(dev, useraddr, dev->ethtool_ops->set_priv_flags); break; - case ETHTOOL_GRXFH: - case ETHTOOL_GRXRINGS: - case ETHTOOL_GRXCLSRLCNT: - case ETHTOOL_GRXCLSRULE: - case ETHTOOL_GRXCLSRLALL: - rc = ethtool_get_rxnfc(dev, ethcmd, useraddr); - break; - case ETHTOOL_SRXFH: - case ETHTOOL_SRXCLSRLDEL: - case ETHTOOL_SRXCLSRLINS: - rc = ethtool_set_rxnfc(dev, ethcmd, useraddr); - break; case ETHTOOL_FLASHDEV: rc = ethtool_flash_device(dev, devlink_state); break; @@ -3180,6 +3183,18 @@ int dev_ethtool(struct net *net, struct ifreq *ifr, void __user *useraddr) rc = ethtool_get_value(dev, useraddr, ethcmd, __ethtool_get_flags); break; + case ETHTOOL_GRXFH: + case ETHTOOL_GRXRINGS: + case ETHTOOL_GRXCLSRLCNT: + case ETHTOOL_GRXCLSRULE: + case ETHTOOL_GRXCLSRLALL: + rc = ethtool_get_rxnfc(dev, ethcmd, useraddr); + break; + case ETHTOOL_SRXFH: + case ETHTOOL_SRXCLSRLDEL: + case ETHTOOL_SRXCLSRLINS: + rc = ethtool_set_rxnfc(dev, ethcmd, useraddr); + break; default: rtnl_lock(); rc = __dev_ethtool(dev, ifr, useraddr, ethcmd, sub_cmd, state);