BPF List
 help / color / mirror / Atom feed
From: "D. Wythe" <alibuda@linux.alibaba.com    >
To: Martin KaFai Lau <martin.lau@linux.dev>
Cc: "D. Wythe" <alibuda@linux.alibaba.com>,
	kgraul@linux.ibm.com, wenjia@linux.ibm.com, jaka@linux.ibm.com,
	ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org,
	pabeni@redhat.com, song@kernel.org, sdf@google.com,
	haoluo@google.com, yhs@fb.com, edumazet@google.com,
	john.fastabend@gmail.com, kpsingh@kernel.org, jolsa@kernel.org,
	guwen@linux.alibaba.com, kuba@kernel.org, davem@davemloft.net,
	netdev@vger.kernel.org, linux-s390@vger.kernel.org,
	linux-rdma@vger.kernel.org, bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v6 2/5] net/smc: Introduce generic hook smc_ops
Date: Wed, 22 Jan 2025 12:35:38 +0800	[thread overview]
Message-ID: <20250122043538.GC81479@j66a10360.sqa.eu95> (raw)
In-Reply-To: <86948347-529b-433a-991d-0b298776db63@linux.dev>

On Fri, Jan 17, 2025 at 03:50:48PM -0800, Martin KaFai Lau wrote:
> On 1/15/25 11:44 PM, D. Wythe wrote:
> >diff --git a/net/smc/smc_sysctl.c b/net/smc/smc_sysctl.c
> >index 2fab6456f765..2004241c3045 100644
> >--- a/net/smc/smc_sysctl.c
> >+++ b/net/smc/smc_sysctl.c
> >@@ -18,6 +18,7 @@
> >  #include "smc_core.h"
> >  #include "smc_llc.h"
> >  #include "smc_sysctl.h"
> >+#include "smc_ops.h"
> >  static int min_sndbuf = SMC_BUF_MIN_SIZE;
> >  static int min_rcvbuf = SMC_BUF_MIN_SIZE;
> >@@ -30,6 +31,69 @@ static int links_per_lgr_max = SMC_LINKS_ADD_LNK_MAX;
> >  static int conns_per_lgr_min = SMC_CONN_PER_LGR_MIN;
> >  static int conns_per_lgr_max = SMC_CONN_PER_LGR_MAX;
> >+#if IS_ENABLED(CONFIG_SMC_OPS)
> >+static int smc_net_replace_smc_ops(struct net *net, const char *name)
> >+{
> >+	struct smc_ops *ops = NULL;
> >+
> >+	rcu_read_lock();
> >+	/* null or empty name ask to clear current ops */
> >+	if (name && name[0]) {
> >+		ops = smc_ops_find_by_name(name);
> >+		if (!ops) {
> >+			rcu_read_unlock();
> >+			return -EINVAL;
> >+		}
> >+		/* no change, just return */
> >+		if (ops == rcu_dereference(net->smc.ops)) {
> >+			rcu_read_unlock();
> >+			return 0;
> >+		}
> >+	}
> >+	if (!ops || bpf_try_module_get(ops, ops->owner)) {
> >+		/* xhcg */
> 
> typo. I noticed it only because...
> 
> >+		ops = rcu_replace_pointer(net->smc.ops, ops, true);
> 
> ... rcu_replace_pointer() does not align with the above xchg
> comment. From looking into rcu_replace_pointer, it is not a xchg. It
> is also not obvious to me why it is safe to assume "true" here...
> 
> >+		/* release old ops */
> >+		if (ops)
> >+			bpf_module_put(ops, ops->owner);
> 
> ... together with a put here on the return value of the rcu_replace_pointer.
> 

Hi Martin,

This is indeed a very good catch. Initially, I used the xhcg()
for swapping, but later I thought there wouldn't be a situation where
smc_net_replace_smc_ops would be called simultaneously with the same net.

Therefore, I modified it to rcu_replace_pointer, which is also why I assumed
that it was true here, I thought the updates here was prevented. but now I
realize that sysctl might not be mutually exclusive. It seems that this should
be changed back to xhcg().

> >+	} else if (ops) {
> 
> nit. This looks redundant when looking at the "if (!ops || ..." test above
> Also a nit, I would move the bpf_try_module_get() immediately after
> the above "if (ops == rcu_dereference(net->smc.ops))" test. This
> should simplify the later cases.
> 

This is a very good suggestion. I tried it and the code became very
clean. I'll take it in next version.

> >+		rcu_read_unlock();
> >+		return -EBUSY;
> >+	}
> >+	rcu_read_unlock();
> >+	return 0;
> >+}
> >+
> >+static int proc_smc_ops(const struct ctl_table *ctl, int write,
> >+#if IS_ENABLED(CONFIG_SMC_OPS)
> >+		struct smc_ops *ops;
> >+
> >+		rcu_read_lock();
> >+		ops = rcu_dereference(init_net.smc.ops);
> >+		if (ops && ops->flags & SMC_OPS_FLAG_INHERITABLE) {
> >+			if (!bpf_try_module_get(ops, ops->owner)) {
> >+				rcu_read_unlock();
> >+				return -EBUSY;
> 
> Not sure if it should count as error when the ops is in the process
> of un-register-ing. The next smc_sysctl_net_init will have NULL ops
> and succeed. Something for you to consider.
>

It seems more reasonable that no need to prevent net initialization
just because ops is uninstalling... I plan to just skip that error.

> 
> Also, it needs an ack from the SMC maintainer for the SMC specific
> parts like the sysctl here.

Got it. I will communicate this matter with the SMC maintainers.

Best wishes,
D. Wythe

  reply	other threads:[~2025-01-22  4:35 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-16  7:44 [PATCH bpf-next v6 0/5] net/smc: Introduce smc_ops D. Wythe
2025-01-16  7:44 ` [PATCH bpf-next v6 1/5] bpf: export necessary sympols for modules with struct_ops D. Wythe
2025-01-16  7:44 ` [PATCH bpf-next v6 2/5] net/smc: Introduce generic hook smc_ops D. Wythe
2025-01-16 12:22   ` Dust Li
2025-01-17 23:50   ` Martin KaFai Lau
2025-01-22  4:35     ` D. Wythe [this message]
2025-01-16  7:44 ` [PATCH bpf-next v6 3/5] net/smc: bpf: register smc_ops info struct_ops D. Wythe
2025-01-16  7:44 ` [PATCH bpf-next v6 4/5] libbpf: fix error when st-prefix_ops and ops from differ btf D. Wythe
2025-01-17 18:36   ` Andrii Nakryiko
2025-01-22  2:43     ` D. Wythe
2025-01-22 17:16       ` Andrii Nakryiko
2025-01-16  7:44 ` [PATCH bpf-next v6 5/5] bpf/selftests: add selftest for bpf_smc_ops D. Wythe
2025-01-18  0:37   ` Martin KaFai Lau
2025-01-22  1:51     ` D. Wythe
2025-01-21  6:42   ` Saket Kumar Bhaskar
2025-01-22  2:46     ` D. Wythe
2025-01-22  4:39       ` Saket Kumar Bhaskar

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=20250122043538.GC81479@j66a10360.sqa.eu95 \
    --to=alibuda@linux.alibaba.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=guwen@linux.alibaba.com \
    --cc=haoluo@google.com \
    --cc=jaka@linux.ibm.com \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kgraul@linux.ibm.com \
    --cc=kpsingh@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=sdf@google.com \
    --cc=song@kernel.org \
    --cc=wenjia@linux.ibm.com \
    --cc=yhs@fb.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