bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Björn Töpel" <bjorn.topel@gmail.com>
To: ast@kernel.org, daniel@iogearbox.net, netdev@vger.kernel.org
Cc: "Björn Töpel" <bjorn.topel@intel.com>,
	magnus.karlsson@intel.com, toke@redhat.com, brouer@redhat.com,
	bpf@vger.kernel.org, jakub.kicinski@netronome.com,
	saeedm@mellanox.com
Subject: [PATCH bpf-next v3 4/5] net: xdp: refactor XDP flags checking
Date: Mon, 10 Jun 2019 18:02:33 +0200	[thread overview]
Message-ID: <20190610160234.4070-5-bjorn.topel@gmail.com> (raw)
In-Reply-To: <20190610160234.4070-1-bjorn.topel@gmail.com>

From: Björn Töpel <bjorn.topel@intel.com>

Similar to query a driver for a loaded XDP program, each driver need
to check the attachment flags when a program is loaded.

E.g., if an XDP program was loaded without explicit flags (fallback
mode), it must be reloaded/removed without explicit flags.

This commit moves that check to generic code as well.

Signed-off-by: Björn Töpel <bjorn.topel@intel.com>
---
 net/core/dev.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/net/core/dev.c b/net/core/dev.c
index 8e9f5693a7da..bb5fbb395596 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -8075,8 +8075,8 @@ int dev_change_xdp_fd(struct net_device *dev, struct netlink_ext_ack *extack,
 	const struct net_device_ops *ops = dev->netdev_ops;
 	xdp_query_prog_t query, check;
 	struct bpf_prog *prog = NULL;
+	bool offload, expl;
 	bpf_op_t bpf_op;
-	bool offload;
 	int err;
 
 	ASSERT_RTNL();
@@ -8124,6 +8124,14 @@ int dev_change_xdp_fd(struct net_device *dev, struct netlink_ext_ack *extack,
 		}
 	}
 
+	expl = dev->xdp.explicit_mode;
+	if (!offload && query(dev) && !!expl ^ !!(flags & XDP_FLAGS_MODES)) {
+		NL_SET_ERR_MSG(extack, "program loaded with different flags");
+		if (prog)
+			bpf_prog_put(prog);
+		return -EBUSY;
+	}
+
 	err = dev_xdp_install(dev, bpf_op, extack, flags, prog);
 	if (err < 0 && prog)
 		bpf_prog_put(prog);
-- 
2.20.1


  parent reply	other threads:[~2019-06-10 16:03 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-10 16:02 [PATCH bpf-next v3 0/5] net: xdp: refactor XDP program queries Björn Töpel
2019-06-10 16:02 ` [PATCH bpf-next v3 1/5] net: xdp: refactor XDP_QUERY_PROG{,_HW} to netdev Björn Töpel
2019-06-10 16:02 ` [PATCH bpf-next v3 2/5] nfp, netdevsim: use dev_xdp_support_offload() function Björn Töpel
2019-06-10 16:02 ` [PATCH bpf-next v3 3/5] net: xdp: remove XDP_QUERY_PROG{,_HW} Björn Töpel
2019-06-10 16:02 ` Björn Töpel [this message]
2019-06-10 16:02 ` [PATCH bpf-next v3 5/5] net: xdp: remove xdp_attachment_flags_ok() and flags member Björn Töpel
2019-06-10 22:24 ` [PATCH bpf-next v3 0/5] net: xdp: refactor XDP program queries Jakub Kicinski
2019-06-11  7:24   ` Björn Töpel
2019-06-11 12:17     ` Toke Høiland-Jørgensen
2019-06-11 17:22     ` Jakub Kicinski
2019-06-12  5:38       ` Björn Töpel
2019-06-12 14:31     ` Jonathan Lemon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190610160234.4070-5-bjorn.topel@gmail.com \
    --to=bjorn.topel@gmail.com \
    --cc=ast@kernel.org \
    --cc=bjorn.topel@intel.com \
    --cc=bpf@vger.kernel.org \
    --cc=brouer@redhat.com \
    --cc=daniel@iogearbox.net \
    --cc=jakub.kicinski@netronome.com \
    --cc=magnus.karlsson@intel.com \
    --cc=netdev@vger.kernel.org \
    --cc=saeedm@mellanox.com \
    --cc=toke@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).