From nobody Sat Feb 7 10:15:06 2026 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 26B1C49658 for ; Thu, 22 Aug 2024 05:52: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=1724305943; cv=none; b=cZT8kJsg4lWsAvXpD/00EwDZI2MRObpUjp8Edm/f+P1AY/wlBSZIZGN8/Z/4TqdtMVCJ8Avl0W44jwAQ8Tl0dYsHWTDX6QlhOgtTOa5Uym7+esOpGOWJ6o+uFBpeb54inBAoVP7E4A0vPAhGCe/HojbKxD3h497USkmgv7EnkQI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724305943; c=relaxed/simple; bh=ZDPRDTlLhRB8Ca5AowgVDx3jfAvGtbwAcPsMhXtWWrw=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=kKN39GVtXzEhKlEOgDgX08NW+zfff1++pz1tmrNwL23LQ6GRLLTPuEmhu5ma9K6kbrb7PBINgGRGgz/uHitF/MWQ+YzQ3jU4ojgYAELBEn+QBHKt7QoARvJIlfeD/5eW55XnCfjeKnxFUETUUfPAn2iSSVi9IANWH6jcU3XKBZ0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--almasrymina.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=U3pMlWgg; 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--almasrymina.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="U3pMlWgg" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e0be1808a36so770688276.1 for ; Wed, 21 Aug 2024 22:52:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1724305941; x=1724910741; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=04JaEmUuzFfbKL4CGnL5ZC4xtx6kxsSTreaHJ5A6DDg=; b=U3pMlWggtRE4AjLO2WvUhyfWMSX5BadmYCADPoZ+t9FX5BK8DN0xwd5sttY3g+qv3G MKTa+AtPxSELwZoNkLCHPXkyD5lWaCcxcfcGVKKBNXz9pSj8OsybUBSafOOPy+/YF4iR rJ7m3tUC2aSS0qsLJ3NckU1H8n1Fr07piNgysdxbQlP5al5vCvu+Uws6lCbn1OZvWmfz Gx3xLDI+2Mmlvb41JpiT/MAoH73tkNuv+LGxC0o3KYEVqFQJPIF+9U9M3P4gUWRl4lLs BvQ5Bjv7RHrROUh9MoF27RlsFdMp4voQCIkjQIG9D3Iv0E+asD9c1MwbAHsOLcyYpBqP IQ6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724305941; x=1724910741; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=04JaEmUuzFfbKL4CGnL5ZC4xtx6kxsSTreaHJ5A6DDg=; b=u5xwZ9upP+GbclWHzcyPt/rXb2fVJJ+ZRLirp4E7befkn0L95608OquKhvWlU6AbeI umJ1W2MuH7792AC3dFmJFbHJRYKwrxW3VBjHOhBH78NnVcx5GxZkynYiK9d0pCPIMACb ydS69PjvtD7kLvcxciExvrA3qvur+An5ssRRX3CmarBbj2EqCWrBENDUPiD+HHwBejni zZ+JOUNGu91cR+IYuYMPudqow9U4climSZxeMOD77I3NjiqHeghGgpX7wViElwsM0ET3 IkdgKlhgBKifP5GZ5lT/2J0u3VCUz6ATTABC2s5U3Zlwu8+astywD+M85jGi5Ibjmafw w+9g== X-Forwarded-Encrypted: i=1; AJvYcCXz/2cA5BCKzzzp9pa2faOAxmacQ+a8Qg1Uh7MZ58HehXqUcUlpvzs/L8iPQYlZhh2eddvPfKaivxGbUAQ=@vger.kernel.org X-Gm-Message-State: AOJu0Yz5qETnw9Sw2MefNIDfXV0F1Tphy4D4/HhDkxLVg+0Sfe0EX0v3 ZLXghNJjcxY1xN3z5GfKnCXkqKwN7zWbQ2e+Q2BDxb/F1+2nXtWwpIfNg+MOuR95Bkk6cHmOUbg yk8Ge3WYSQvLY+dqty5IGtA== X-Google-Smtp-Source: AGHT+IETrPBlj0Tv3ojSIAQFzaGbRbQ3B+XAZxSguR7Lp9ncSuSBoJfqKynKHzdekC+vdVaJRzY63BBhLOJMi+USHg== X-Received: from almasrymina.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:4bc5]) (user=almasrymina job=sendgmr) by 2002:a05:6902:1370:b0:e16:5303:7bcc with SMTP id 3f1490d57ef6-e166553ae90mr12157276.10.1724305940891; Wed, 21 Aug 2024 22:52:20 -0700 (PDT) Date: Thu, 22 Aug 2024 05:51:54 +0000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.46.0.295.g3b9ea8a38a-goog Message-ID: <20240822055154.4176338-1-almasrymina@google.com> Subject: [PATCH net-next v2] net: refactor ->ndo_bpf calls into dev_xdp_propagate From: Mina Almasry To: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, bpf@vger.kernel.org Cc: Mina Almasry , Jay Vosburgh , Andy Gospodarek , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When net devices propagate xdp configurations to slave devices, we will need to perform a memory provider check to ensure we're not binding xdp to a device using unreadable netmem. Currently the ->ndo_bpf calls in a few places. Adding checks to all these places would not be ideal. Refactor all the ->ndo_bpf calls into one place where we can add this check in the future. Suggested-by: Jakub Kicinski Signed-off-by: Mina Almasry --- v2: - Don't refactor the calls in net/xdp/xsk_buff_pool.c and kernel/bpf/offload.c (Jakub) --- drivers/net/bonding/bond_main.c | 8 ++++---- drivers/net/hyperv/netvsc_bpf.c | 2 +- include/linux/netdevice.h | 1 + net/core/dev.c | 9 +++++++++ 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_mai= n.c index f9633a6f8571..73f9416c6c1b 100644 --- a/drivers/net/bonding/bond_main.c +++ b/drivers/net/bonding/bond_main.c @@ -2258,7 +2258,7 @@ int bond_enslave(struct net_device *bond_dev, struct = net_device *slave_dev, goto err_sysfs_del; } =20 - res =3D slave_dev->netdev_ops->ndo_bpf(slave_dev, &xdp); + res =3D dev_xdp_propagate(slave_dev, &xdp); if (res < 0) { /* ndo_bpf() sets extack error message */ slave_dbg(bond_dev, slave_dev, "Error %d calling ndo_bpf\n", res); @@ -2394,7 +2394,7 @@ static int __bond_release_one(struct net_device *bond= _dev, .prog =3D NULL, .extack =3D NULL, }; - if (slave_dev->netdev_ops->ndo_bpf(slave_dev, &xdp)) + if (dev_xdp_propagate(slave_dev, &xdp)) slave_warn(bond_dev, slave_dev, "failed to unload XDP program\n"); } =20 @@ -5584,7 +5584,7 @@ static int bond_xdp_set(struct net_device *dev, struc= t bpf_prog *prog, goto err; } =20 - err =3D slave_dev->netdev_ops->ndo_bpf(slave_dev, &xdp); + err =3D dev_xdp_propagate(slave_dev, &xdp); if (err < 0) { /* ndo_bpf() sets extack error message */ slave_err(dev, slave_dev, "Error %d calling ndo_bpf\n", err); @@ -5616,7 +5616,7 @@ static int bond_xdp_set(struct net_device *dev, struc= t bpf_prog *prog, if (slave =3D=3D rollback_slave) break; =20 - err_unwind =3D slave_dev->netdev_ops->ndo_bpf(slave_dev, &xdp); + err_unwind =3D dev_xdp_propagate(slave_dev, &xdp); if (err_unwind < 0) slave_err(dev, slave_dev, "Error %d when unwinding XDP program change\n", err_unwind); diff --git a/drivers/net/hyperv/netvsc_bpf.c b/drivers/net/hyperv/netvsc_bp= f.c index 4a9522689fa4..e01c5997a551 100644 --- a/drivers/net/hyperv/netvsc_bpf.c +++ b/drivers/net/hyperv/netvsc_bpf.c @@ -183,7 +183,7 @@ int netvsc_vf_setxdp(struct net_device *vf_netdev, stru= ct bpf_prog *prog) xdp.command =3D XDP_SETUP_PROG; xdp.prog =3D prog; =20 - ret =3D vf_netdev->netdev_ops->ndo_bpf(vf_netdev, &xdp); + ret =3D dev_xdp_propagate(vf_netdev, &xdp); =20 if (ret && prog) bpf_prog_put(prog); diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 614ec5d3d75b..f0ff269ce262 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -3923,6 +3923,7 @@ struct sk_buff *dev_hard_start_xmit(struct sk_buff *s= kb, struct net_device *dev, =20 int bpf_xdp_link_attach(const union bpf_attr *attr, struct bpf_prog *prog); u8 dev_xdp_prog_count(struct net_device *dev); +int dev_xdp_propagate(struct net_device *dev, struct netdev_bpf *bpf); u32 dev_xdp_prog_id(struct net_device *dev, enum bpf_xdp_mode mode); =20 int __dev_forward_skb(struct net_device *dev, struct sk_buff *skb); diff --git a/net/core/dev.c b/net/core/dev.c index e7260889d4cb..165e9778d422 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -9369,6 +9369,15 @@ u8 dev_xdp_prog_count(struct net_device *dev) } EXPORT_SYMBOL_GPL(dev_xdp_prog_count); =20 +int dev_xdp_propagate(struct net_device *dev, struct netdev_bpf *bpf) +{ + if (!dev->netdev_ops->ndo_bpf) + return -EOPNOTSUPP; + + return dev->netdev_ops->ndo_bpf(dev, bpf); +} +EXPORT_SYMBOL_GPL(dev_xdp_propagate); + u32 dev_xdp_prog_id(struct net_device *dev, enum bpf_xdp_mode mode) { struct bpf_prog *prog =3D dev_xdp_prog(dev, mode); --=20 2.46.0.295.g3b9ea8a38a-goog