netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next] openvswitch: switch to per-action label counting in conntrack
@ 2024-07-18  2:10 Xin Long
  2024-07-18 13:23 ` Paolo Abeni
  2024-07-18 13:27 ` Jakub Kicinski
  0 siblings, 2 replies; 4+ messages in thread
From: Xin Long @ 2024-07-18  2:10 UTC (permalink / raw)
  To: network dev, dev, ovs-dev
  Cc: davem, kuba, Eric Dumazet, Paolo Abeni, Pravin B Shelar,
	Ilya Maximets, Aaron Conole, Florian Westphal

Similar to commit 70f06c115bcc ("sched: act_ct: switch to per-action
label counting"), we should also switch to per-action label counting
in openvswitch conntrack, as Florian suggested.

The difference is that nf_connlabels_get() is called unconditionally
when creating an ct action in ovs_ct_copy_action(). As with these
flows:

  table=0,ip,actions=ct(commit,table=1)
  table=1,ip,actions=ct(commit,exec(set_field:0xac->ct_label),table=2)

it needs to make sure the label ext is created in the 1st flow before
the ct is committed in ovs_ct_commit(). Otherwise, the warning in
nf_ct_ext_add() when creating the label ext in the 2nd flow will
be triggered:

   WARN_ON(nf_ct_is_confirmed(ct));

Signed-off-by: Xin Long <lucien.xin@gmail.com>
---
 net/openvswitch/conntrack.c | 28 +++++++++++-----------------
 net/openvswitch/datapath.h  |  3 ---
 2 files changed, 11 insertions(+), 20 deletions(-)

diff --git a/net/openvswitch/conntrack.c b/net/openvswitch/conntrack.c
index 8eb1d644b741..2cc38faab682 100644
--- a/net/openvswitch/conntrack.c
+++ b/net/openvswitch/conntrack.c
@@ -1368,11 +1368,8 @@ bool ovs_ct_verify(struct net *net, enum ovs_key_attr attr)
 	    attr == OVS_KEY_ATTR_CT_MARK)
 		return true;
 	if (IS_ENABLED(CONFIG_NF_CONNTRACK_LABELS) &&
-	    attr == OVS_KEY_ATTR_CT_LABELS) {
-		struct ovs_net *ovs_net = net_generic(net, ovs_net_id);
-
-		return ovs_net->xt_label;
-	}
+	    attr == OVS_KEY_ATTR_CT_LABELS)
+		return true;
 
 	return false;
 }
@@ -1381,6 +1378,7 @@ int ovs_ct_copy_action(struct net *net, const struct nlattr *attr,
 		       const struct sw_flow_key *key,
 		       struct sw_flow_actions **sfa,  bool log)
 {
+	unsigned int n_bits = sizeof(struct ovs_key_ct_labels) * BITS_PER_BYTE;
 	struct ovs_conntrack_info ct_info;
 	const char *helper = NULL;
 	u16 family;
@@ -1409,6 +1407,12 @@ int ovs_ct_copy_action(struct net *net, const struct nlattr *attr,
 		return -ENOMEM;
 	}
 
+	if (nf_connlabels_get(net, n_bits - 1)) {
+		nf_ct_tmpl_free(ct_info.ct);
+		OVS_NLERR(log, "Failed to set connlabel length");
+		return -EOPNOTSUPP;
+	}
+
 	if (ct_info.timeout[0]) {
 		if (nf_ct_set_timeout(net, ct_info.ct, family, key->ip.proto,
 				      ct_info.timeout))
@@ -1577,6 +1581,7 @@ static void __ovs_ct_free_action(struct ovs_conntrack_info *ct_info)
 	if (ct_info->ct) {
 		if (ct_info->timeout[0])
 			nf_ct_destroy_timeout(ct_info->ct);
+		nf_connlabels_put(nf_ct_net(ct_info->ct));
 		nf_ct_tmpl_free(ct_info->ct);
 	}
 }
@@ -2002,17 +2007,9 @@ struct genl_family dp_ct_limit_genl_family __ro_after_init = {
 
 int ovs_ct_init(struct net *net)
 {
-	unsigned int n_bits = sizeof(struct ovs_key_ct_labels) * BITS_PER_BYTE;
+#if	IS_ENABLED(CONFIG_NETFILTER_CONNCOUNT)
 	struct ovs_net *ovs_net = net_generic(net, ovs_net_id);
 
-	if (nf_connlabels_get(net, n_bits - 1)) {
-		ovs_net->xt_label = false;
-		OVS_NLERR(true, "Failed to set connlabel length");
-	} else {
-		ovs_net->xt_label = true;
-	}
-
-#if	IS_ENABLED(CONFIG_NETFILTER_CONNCOUNT)
 	return ovs_ct_limit_init(net, ovs_net);
 #else
 	return 0;
@@ -2026,7 +2023,4 @@ void ovs_ct_exit(struct net *net)
 #if	IS_ENABLED(CONFIG_NETFILTER_CONNCOUNT)
 	ovs_ct_limit_exit(net, ovs_net);
 #endif
-
-	if (ovs_net->xt_label)
-		nf_connlabels_put(net);
 }
diff --git a/net/openvswitch/datapath.h b/net/openvswitch/datapath.h
index 9ca6231ea647..365b9bb7f546 100644
--- a/net/openvswitch/datapath.h
+++ b/net/openvswitch/datapath.h
@@ -160,9 +160,6 @@ struct ovs_net {
 #if	IS_ENABLED(CONFIG_NETFILTER_CONNCOUNT)
 	struct ovs_ct_limit_info *ct_limit_info;
 #endif
-
-	/* Module reference for configuring conntrack. */
-	bool xt_label;
 };
 
 /**
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH net-next] openvswitch: switch to per-action label counting in conntrack
  2024-07-18  2:10 [PATCH net-next] openvswitch: switch to per-action label counting in conntrack Xin Long
@ 2024-07-18 13:23 ` Paolo Abeni
  2024-07-18 13:27 ` Jakub Kicinski
  1 sibling, 0 replies; 4+ messages in thread
From: Paolo Abeni @ 2024-07-18 13:23 UTC (permalink / raw)
  To: Xin Long, network dev, dev, ovs-dev
  Cc: davem, kuba, Eric Dumazet, Pravin B Shelar, Ilya Maximets,
	Aaron Conole, Florian Westphal

On 7/18/24 04:10, Xin Long wrote:
> Similar to commit 70f06c115bcc ("sched: act_ct: switch to per-action
> label counting"), we should also switch to per-action label counting
> in openvswitch conntrack, as Florian suggested.
> 
> The difference is that nf_connlabels_get() is called unconditionally
> when creating an ct action in ovs_ct_copy_action(). As with these
> flows:
> 
>    table=0,ip,actions=ct(commit,table=1)
>    table=1,ip,actions=ct(commit,exec(set_field:0xac->ct_label),table=2)
> 
> it needs to make sure the label ext is created in the 1st flow before
> the ct is committed in ovs_ct_commit(). Otherwise, the warning in
> nf_ct_ext_add() when creating the label ext in the 2nd flow will
> be triggered:
> 
>     WARN_ON(nf_ct_is_confirmed(ct));
> 
> Signed-off-by: Xin Long <lucien.xin@gmail.com>

## Form letter - net-next-closed

The merge window for v6.11 and therefore net-next is closed for new
drivers, features, code refactoring and optimizations. We are currently
accepting bug fixes only.

Please repost when net-next reopens after July 29th.

RFC patches sent for review only are obviously welcome at any time.

See:
https://www.kernel.org/doc/html/next/process/maintainer-netdev.html#development-cycle
-- 
pw-bot: defer



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH net-next] openvswitch: switch to per-action label counting in conntrack
  2024-07-18  2:10 [PATCH net-next] openvswitch: switch to per-action label counting in conntrack Xin Long
  2024-07-18 13:23 ` Paolo Abeni
@ 2024-07-18 13:27 ` Jakub Kicinski
  2024-07-18 15:33   ` Xin Long
  1 sibling, 1 reply; 4+ messages in thread
From: Jakub Kicinski @ 2024-07-18 13:27 UTC (permalink / raw)
  To: Xin Long
  Cc: network dev, dev, ovs-dev, davem, Eric Dumazet, Paolo Abeni,
	Pravin B Shelar, Ilya Maximets, Aaron Conole, Florian Westphal

On Wed, 17 Jul 2024 22:10:15 -0400 Xin Long wrote:
> @@ -2026,7 +2023,4 @@ void ovs_ct_exit(struct net *net)
>  #if	IS_ENABLED(CONFIG_NETFILTER_CONNCOUNT)
>  	ovs_ct_limit_exit(net, ovs_net);
>  #endif
> -
> -	if (ovs_net->xt_label)
> -		nf_connlabels_put(net);
>  }

In addition to net-next being closed please note there is a warning
about ovs_net being unused if NETFILTER_CONNCOUNT=n.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH net-next] openvswitch: switch to per-action label counting in conntrack
  2024-07-18 13:27 ` Jakub Kicinski
@ 2024-07-18 15:33   ` Xin Long
  0 siblings, 0 replies; 4+ messages in thread
From: Xin Long @ 2024-07-18 15:33 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: network dev, dev, ovs-dev, davem, Eric Dumazet, Paolo Abeni,
	Pravin B Shelar, Ilya Maximets, Aaron Conole, Florian Westphal

On Thu, Jul 18, 2024 at 9:27 AM Jakub Kicinski <kuba@kernel.org> wrote:
>
> On Wed, 17 Jul 2024 22:10:15 -0400 Xin Long wrote:
> > @@ -2026,7 +2023,4 @@ void ovs_ct_exit(struct net *net)
> >  #if  IS_ENABLED(CONFIG_NETFILTER_CONNCOUNT)
> >       ovs_ct_limit_exit(net, ovs_net);
> >  #endif
> > -
> > -     if (ovs_net->xt_label)
> > -             nf_connlabels_put(net);
> >  }
>
> In addition to net-next being closed please note there is a warning
> about ovs_net being unused if NETFILTER_CONNCOUNT=n.
Copy, will move it into #if    IS_ENABLED(CONFIG_NETFILTER_CONNCOUNT).

Thanks!

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-07-18 15:33 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-18  2:10 [PATCH net-next] openvswitch: switch to per-action label counting in conntrack Xin Long
2024-07-18 13:23 ` Paolo Abeni
2024-07-18 13:27 ` Jakub Kicinski
2024-07-18 15:33   ` Xin Long

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).