Intel-Wired-Lan Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [Intel-wired-lan] [PATCH v2 net] i40e: fix src IP mask checks and memcpy argument names in cloud filter
@ 2025-11-10 19:13 Alok Tiwari
       [not found] ` <PH0PR11MB50139E1973CFB73CFF221FCD9687A@PH0PR11MB5013.namprd11.prod.outlook.com>
  0 siblings, 1 reply; 4+ messages in thread
From: Alok Tiwari @ 2025-11-10 19:13 UTC (permalink / raw)
  To: pmenzel, przemyslaw.kitszel, aleksander.lobakin, anthony.l.nguyen,
	andrew+netdev, kuba, davem, edumazet, pabeni, horms,
	intel-wired-lan, netdev
  Cc: alok.a.tiwarilinux, alok.a.tiwari

Fix following issues in the IPv4 and IPv6 cloud filter handling logic in
both the add and delete paths:

- The source-IP mask check incorrectly compares mask.src_ip[0] against
  tcf.dst_ip[0]. Update it to compare against tcf.src_ip[0]. This likely
  goes unnoticed because the check is in an "else if" path that only
  executes when dst_ip is not set, most cloud filter use cases focus on
  destination-IP matching, and the buggy condition can accidentally
  evaluate true in some cases.

- memcpy() for the IPv4 source address incorrectly uses
  ARRAY_SIZE(tcf.dst_ip) instead of ARRAY_SIZE(tcf.src_ip), although
  both arrays are the same size.

- The IPv4 memcpy operations used ARRAY_SIZE(tcf.dst_ip) and ARRAY_SIZE
  (tcf.src_ip), Update these to use sizeof(cfilter->ip.v4.dst_ip) and
  sizeof(cfilter->ip.v4.src_ip) to ensure correct and explicit copy size.

- In the IPv6 delete path, memcmp() uses sizeof(src_ip6) when comparing
  dst_ip6 fields. Replace this with sizeof(dst_ip6) to make the intent
  explicit, even though both fields are struct in6_addr.

Fixes: e284fc280473 ("i40e: Add and delete cloud filter")
Signed-off-by: Alok Tiwari <alok.a.tiwari@oracle.com>
Reviewed-by: Aleksandr Loktionov <aleksandr.loktionov@intel.com>
Reviewed-by: Paul Menzel <pmenzel@molgen.mpg.de>
---
v1 -> v2
update patch subject line and replace ARRAY_SIZE with sizeof
as suggested by Alex and added Reviewed-by Alex and Paul.
---
 drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c b/drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c
index 081a4526a2f0..dd9fb170d98b 100644
--- a/drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c
+++ b/drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c
@@ -3818,10 +3818,10 @@ static int i40e_vc_del_cloud_filter(struct i40e_vf *vf, u8 *msg)
 		cfilter.n_proto = ETH_P_IP;
 		if (mask.dst_ip[0] & tcf.dst_ip[0])
 			memcpy(&cfilter.ip.v4.dst_ip, tcf.dst_ip,
-			       ARRAY_SIZE(tcf.dst_ip));
-		else if (mask.src_ip[0] & tcf.dst_ip[0])
+			       sizeof(cfilter.ip.v4.dst_ip));
+		else if (mask.src_ip[0] & tcf.src_ip[0])
 			memcpy(&cfilter.ip.v4.src_ip, tcf.src_ip,
-			       ARRAY_SIZE(tcf.dst_ip));
+			       sizeof(cfilter.ip.v4.src_ip));
 		break;
 	case VIRTCHNL_TCP_V6_FLOW:
 		cfilter.n_proto = ETH_P_IPV6;
@@ -3876,7 +3876,7 @@ static int i40e_vc_del_cloud_filter(struct i40e_vf *vf, u8 *msg)
 		/* for ipv6, mask is set for all sixteen bytes (4 words) */
 		if (cfilter.n_proto == ETH_P_IPV6 && mask.dst_ip[3])
 			if (memcmp(&cfilter.ip.v6.dst_ip6, &cf->ip.v6.dst_ip6,
-				   sizeof(cfilter.ip.v6.src_ip6)))
+				   sizeof(cfilter.ip.v6.dst_ip6)))
 				continue;
 		if (mask.vlan_id)
 			if (cfilter.vlan_id != cf->vlan_id)
@@ -3964,10 +3964,10 @@ static int i40e_vc_add_cloud_filter(struct i40e_vf *vf, u8 *msg)
 		cfilter->n_proto = ETH_P_IP;
 		if (mask.dst_ip[0] & tcf.dst_ip[0])
 			memcpy(&cfilter->ip.v4.dst_ip, tcf.dst_ip,
-			       ARRAY_SIZE(tcf.dst_ip));
-		else if (mask.src_ip[0] & tcf.dst_ip[0])
+			       sizeof(cfilter->ip.v4.dst_ip));
+		else if (mask.src_ip[0] & tcf.src_ip[0])
 			memcpy(&cfilter->ip.v4.src_ip, tcf.src_ip,
-			       ARRAY_SIZE(tcf.dst_ip));
+			       sizeof(cfilter->ip.v4.src_ip));
 		break;
 	case VIRTCHNL_TCP_V6_FLOW:
 		cfilter->n_proto = ETH_P_IPV6;
-- 
2.50.1


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

* [Intel-wired-lan] [PATCH v2 net] i40e: fix src IP mask checks and memcpy argument names in cloud filter
       [not found] ` <PH0PR11MB50139E1973CFB73CFF221FCD9687A@PH0PR11MB5013.namprd11.prod.outlook.com>
@ 2026-01-06 14:41   ` Kamakshi, NelloreX
  2026-01-07  5:59     ` Kamakshi, NelloreX
  0 siblings, 1 reply; 4+ messages in thread
From: Kamakshi, NelloreX @ 2026-01-06 14:41 UTC (permalink / raw)
  To: intel-wired-lan-bounces@osuosl.org
  Cc: pmenzel@molgen.mpg.de, Kitszel, Przemyslaw, Lobakin, Aleksander,
	Nguyen, Anthony L, andrew+netdev@lunn.ch, kuba@kernel.org,
	davem@davemloft.net, edumazet@google.com, pabeni@redhat.com,
	horms@kernel.org, intel-wired-lan@lists.osuosl.org,
	netdev@vger.kernel.org, alok.a.tiwarilinux@gmail.com,
	alok.a.tiwari@oracle.com

-----Original Message-----
From: Intel-wired-lan <intel-wired-lan-bounces@osuosl.org> On Behalf Of Alok Tiwari
Sent: Tuesday, November 11, 2025 12:44 AM
To: pmenzel@molgen.mpg.de; Kitszel, Przemyslaw <przemyslaw.kitszel@intel.com>; Lobakin, Aleksander <aleksander.lobakin@intel.com>; Nguyen, Anthony L <anthony.l.nguyen@intel.com>; andrew+netdev@lunn.ch; kuba@kernel.org; davem@davemloft.net; edumazet@google.com; pabeni@redhat.com; horms@kernel.org; intel-wired-lan@lists.osuosl.org; netdev@vger.kernel.org
Cc: alok.a.tiwarilinux@gmail.com; alok.a.tiwari@oracle.com
Subject: [Intel-wired-lan] [PATCH v2 net] i40e: fix src IP mask checks and memcpy argument names in cloud filter

Fix following issues in the IPv4 and IPv6 cloud filter handling logic in both the add and delete paths:

- The source-IP mask check incorrectly compares mask.src_ip[0] against
  tcf.dst_ip[0]. Update it to compare against tcf.src_ip[0]. This likely
  goes unnoticed because the check is in an "else if" path that only
  executes when dst_ip is not set, most cloud filter use cases focus on
  destination-IP matching, and the buggy condition can accidentally
  evaluate true in some cases.

- memcpy() for the IPv4 source address incorrectly uses
  ARRAY_SIZE(tcf.dst_ip) instead of ARRAY_SIZE(tcf.src_ip), although
  both arrays are the same size.

- The IPv4 memcpy operations used ARRAY_SIZE(tcf.dst_ip) and ARRAY_SIZE
  (tcf.src_ip), Update these to use sizeof(cfilter->ip.v4.dst_ip) and
  sizeof(cfilter->ip.v4.src_ip) to ensure correct and explicit copy size.

- In the IPv6 delete path, memcmp() uses sizeof(src_ip6) when comparing
  dst_ip6 fields. Replace this with sizeof(dst_ip6) to make the intent
  explicit, even though both fields are struct in6_addr.

Fixes: e284fc280473 ("i40e: Add and delete cloud filter")
Signed-off-by: Alok Tiwari <alok.a.tiwari@oracle.com>
Reviewed-by: Aleksandr Loktionov <aleksandr.loktionov@intel.com>
Reviewed-by: Paul Menzel <pmenzel@molgen.mpg.de>
---
v1 -> v2
update patch subject line and replace ARRAY_SIZE with sizeof as suggested by Alex and added Reviewed-by Alex and Paul.
---
 drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
>


Unable able to create  Ipv4 and Ipv6 filter with src_ip.

Below are the commands I used to create the filters for IPV4 and IPV6.

tc filter add dev eth0 protocol ipv6 parent ffff: prio 1 flower  src_ip 2001:db8:0:f101::12 skip_sw hw_tc 1

Error:
RTNETLINK answers: Invalid argument
We have an error talking to the kernel

tc filter add dev eth0 protocol ip parent ffff: prio 1 flower src_ip 1.2.1.1 skip_sw hw_tc 1

Error:
RTNETLINK answers: Invalid argument
We have an error talking to the kernel




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

* [Intel-wired-lan] [PATCH v2 net] i40e: fix src IP mask checks and memcpy argument names in cloud filter
  2026-01-06 14:41   ` Kamakshi, NelloreX
@ 2026-01-07  5:59     ` Kamakshi, NelloreX
  2026-01-14 15:27       ` ALOK TIWARI via Intel-wired-lan
  0 siblings, 1 reply; 4+ messages in thread
From: Kamakshi, NelloreX @ 2026-01-07  5:59 UTC (permalink / raw)
  To: intel-wired-lan-bounces@osuosl.org
  Cc: pmenzel@molgen.mpg.de, Kitszel, Przemyslaw, Lobakin, Aleksander,
	Nguyen, Anthony L, andrew+netdev@lunn.ch, kuba@kernel.org,
	davem@davemloft.net, edumazet@google.com, pabeni@redhat.com,
	horms@kernel.org, intel-wired-lan@lists.osuosl.org,
	netdev@vger.kernel.org, alok.a.tiwarilinux@gmail.com,
	alok.a.tiwari@oracle.com

-----Original Message-----
From: Intel-wired-lan <intel-wired-lan-bounces@osuosl.org> On Behalf Of Alok Tiwari
Sent: Tuesday, November 11, 2025 12:44 AM
To: pmenzel@molgen.mpg.de; Kitszel, Przemyslaw <przemyslaw.kitszel@intel.com>; Lobakin, Aleksander <aleksander.lobakin@intel.com>; Nguyen, Anthony L <anthony.l.nguyen@intel.com>; andrew+netdev@lunn.ch; kuba@kernel.org; davem@davemloft.net; edumazet@google.com; pabeni@redhat.com; horms@kernel.org; intel-wired-lan@lists.osuosl.org; netdev@vger.kernel.org
Cc: alok.a.tiwarilinux@gmail.com; alok.a.tiwari@oracle.com
Subject: [Intel-wired-lan] [PATCH v2 net] i40e: fix src IP mask checks and memcpy argument names in cloud filter

Fix following issues in the IPv4 and IPv6 cloud filter handling logic in both the add and delete paths:

- The source-IP mask check incorrectly compares mask.src_ip[0] against
  tcf.dst_ip[0]. Update it to compare against tcf.src_ip[0]. This likely
  goes unnoticed because the check is in an "else if" path that only
  executes when dst_ip is not set, most cloud filter use cases focus on
  destination-IP matching, and the buggy condition can accidentally
  evaluate true in some cases.

- memcpy() for the IPv4 source address incorrectly uses
  ARRAY_SIZE(tcf.dst_ip) instead of ARRAY_SIZE(tcf.src_ip), although
  both arrays are the same size.

- The IPv4 memcpy operations used ARRAY_SIZE(tcf.dst_ip) and ARRAY_SIZE
  (tcf.src_ip), Update these to use sizeof(cfilter->ip.v4.dst_ip) and
  sizeof(cfilter->ip.v4.src_ip) to ensure correct and explicit copy size.

- In the IPv6 delete path, memcmp() uses sizeof(src_ip6) when comparing
  dst_ip6 fields. Replace this with sizeof(dst_ip6) to make the intent
  explicit, even though both fields are struct in6_addr.

Fixes: e284fc280473 ("i40e: Add and delete cloud filter")
Signed-off-by: Alok Tiwari <alok.a.tiwari@oracle.com>
Reviewed-by: Aleksandr Loktionov <aleksandr.loktionov@intel.com>
Reviewed-by: Paul Menzel <pmenzel@molgen.mpg.de>
---
v1 -> v2
update patch subject line and replace ARRAY_SIZE with sizeof as suggested by Alex and added Reviewed-by Alex and Paul.
---
 drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
>

Unable able to create  Ipv4 and Ipv6 filter with src_ip as a match parameter. However filters are getting created with dst_ip.

Below are the commands I used to create the filters for IPV4 and IPV6.

tc filter add dev eth0 protocol ip parent ffff:  prio 1 flower dst_ip 1.1.1.1  ip_proto tcp dst_port 5000  skip_sw  hw_tc 2

tc filter add dev eth0 protocol ip parent ffff:  prio 1 flower src_ip 2.1.1.1  ip_proto tcp dst_port 5000  skip_sw  hw_tc 2
RTNETLINK answers: Operation not supported
We have an error talking to the kernel

tc filter add dev eth0 protocol ipv6 parent ffff: prio 1 flower dst_ip 2001:0db8:0:f101::11 ip_proto tcp dst_port 5200 skip_sw hw_tc 1

tc filter add dev eth0 protocol ipv6 parent ffff: prio 1 flower src_ip 2001:0db8:0:f101::12 ip_proto tcp dst_port 5200 skip_sw hw_tc 1
RTNETLINK answers: Operation not supported
We have an error talking to the kernel

Dmesg:
i40e 0000:5e:00.0: Failed to add cloud filter, err -95
i40e 0000:5e:00.0: Failed to add cloud filter, err -95




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

* Re: [Intel-wired-lan] [PATCH v2 net] i40e: fix src IP mask checks and memcpy argument names in cloud filter
  2026-01-07  5:59     ` Kamakshi, NelloreX
@ 2026-01-14 15:27       ` ALOK TIWARI via Intel-wired-lan
  0 siblings, 0 replies; 4+ messages in thread
From: ALOK TIWARI via Intel-wired-lan @ 2026-01-14 15:27 UTC (permalink / raw)
  To: Kamakshi, NelloreX, intel-wired-lan-bounces@osuosl.org,
	Nguyen, Anthony L, Lobakin, Aleksander
  Cc: pmenzel@molgen.mpg.de, Kitszel, Przemyslaw, andrew+netdev@lunn.ch,
	kuba@kernel.org, davem@davemloft.net, edumazet@google.com,
	pabeni@redhat.com, horms@kernel.org,
	intel-wired-lan@lists.osuosl.org, netdev@vger.kernel.org,
	alok.a.tiwarilinux@gmail.com



On 1/7/2026 11:29 AM, Kamakshi, NelloreX wrote:
> -----Original Message-----
> From: Intel-wired-lan<intel-wired-lan-bounces@osuosl.org> On Behalf Of Alok Tiwari
> Sent: Tuesday, November 11, 2025 12:44 AM
> To:pmenzel@molgen.mpg.de; Kitszel, Przemyslaw<przemyslaw.kitszel@intel.com>; Lobakin, Aleksander<aleksander.lobakin@intel.com>; Nguyen, Anthony L<anthony.l.nguyen@intel.com>;andrew+netdev@lunn.ch;kuba@kernel.org;davem@davemloft.net;edumazet@google.com;pabeni@redhat.com;horms@kernel.org;intel-wired-lan@lists.osuosl.org;netdev@vger.kernel.org
> Cc:alok.a.tiwarilinux@gmail.com;alok.a.tiwari@oracle.com
> Subject: [Intel-wired-lan] [PATCH v2 net] i40e: fix src IP mask checks and memcpy argument names in cloud filter
> 
> Fix following issues in the IPv4 and IPv6 cloud filter handling logic in both the add and delete paths:
> 
> - The source-IP mask check incorrectly compares mask.src_ip[0] against
>    tcf.dst_ip[0]. Update it to compare against tcf.src_ip[0]. This likely
>    goes unnoticed because the check is in an "else if" path that only
>    executes when dst_ip is not set, most cloud filter use cases focus on
>    destination-IP matching, and the buggy condition can accidentally
>    evaluate true in some cases.
> 
> - memcpy() for the IPv4 source address incorrectly uses
>    ARRAY_SIZE(tcf.dst_ip) instead of ARRAY_SIZE(tcf.src_ip), although
>    both arrays are the same size.
> 
> - The IPv4 memcpy operations used ARRAY_SIZE(tcf.dst_ip) and ARRAY_SIZE
>    (tcf.src_ip), Update these to use sizeof(cfilter->ip.v4.dst_ip) and
>    sizeof(cfilter->ip.v4.src_ip) to ensure correct and explicit copy size.
> 
> - In the IPv6 delete path, memcmp() uses sizeof(src_ip6) when comparing
>    dst_ip6 fields. Replace this with sizeof(dst_ip6) to make the intent
>    explicit, even though both fields are struct in6_addr.
> 
> Fixes: e284fc280473 ("i40e: Add and delete cloud filter")
> Signed-off-by: Alok Tiwari<alok.a.tiwari@oracle.com>
> Reviewed-by: Aleksandr Loktionov<aleksandr.loktionov@intel.com>
> Reviewed-by: Paul Menzel<pmenzel@molgen.mpg.de>
> ---
> v1 -> v2
> update patch subject line and replace ARRAY_SIZE with sizeof as suggested by Alex and added Reviewed-by Alex and Paul.
> ---
>   drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c | 14 +++++++-------
>   1 file changed, 7 insertions(+), 7 deletions(-)
> Unable able to create  Ipv4 and Ipv6 filter with src_ip as a match parameter. However filters are getting created with dst_ip.
> 
> Below are the commands I used to create the filters for IPV4 and IPV6.
> 
> tc filter add dev eth0 protocol ip parent ffff:  prio 1 flower dst_ip 1.1.1.1  ip_proto tcp dst_port 5000  skip_sw  hw_tc 2
> 
> tc filter add dev eth0 protocol ip parent ffff:  prio 1 flower src_ip 2.1.1.1  ip_proto tcp dst_port 5000  skip_sw  hw_tc 2
> RTNETLINK answers: Operation not supported
> We have an error talking to the kernel
> 
> tc filter add dev eth0 protocol ipv6 parent ffff: prio 1 flower dst_ip 2001:0db8:0:f101::11 ip_proto tcp dst_port 5200 skip_sw hw_tc 1
> 
> tc filter add dev eth0 protocol ipv6 parent ffff: prio 1 flower src_ip 2001:0db8:0:f101::12 ip_proto tcp dst_port 5200 skip_sw hw_tc 1
> RTNETLINK answers: Operation not supported
> We have an error talking to the kernel
> 
> Dmesg:
> i40e 0000:5e:00.0: Failed to add cloud filter, err -95
> i40e 0000:5e:00.0: Failed to add cloud filter, err -95


as src_ip cloud filter creating fails for ipv4 and ipv6.

While testing cloud filter offload via tc flower, it is observed that
filters using only src_ip fail with -EINVAL, while dst_ip filters
work as expected.

Looking at the add/delete paths, this seems to be related to how IPv4
and IPv6 handle source and destination IP fields.

In the IPv4 path, an if / else if construct is used:

if (mask.dst_ip[0] & tcf.dst_ip[0])
         memcopy dst_ip;
else if (mask.src_ip[0] & tcf.dst_ip[0])
         memcopy src_ip;


This makes the source-IP handling dependent on the destination-IP check,
so valid src_ip-only filters (and combinations of src/dst IPs) don’t
seem to work as expected.

In contrast, the IPv6 path already treats source and destination IPs
independently using separate if statements:

if (mask.dst_ip[3] & tcf.dst_ip[3])
         memcopy dst_ip6;
if (mask.src_ip[3] & tcf.src_ip[3])
         memcopy src_ip6;


Aligning the IPv4 logic with the existing IPv6 approach fixes the IPv4
failures we are seeing and also keeps the behavior consistent across IP
versions.

It looks like cloud filter usage with src_ip might have been broken
for some time. Even though the current change only updates the IPv4
logic and IPv6 already has independent checks, src_ip filters are
still seen failing for both IPv4 and IPv6 during testing.

Also, using sizeof() for the memcpy lengths makes the copy size more
explicit and avoids relying on array dimensions.

Thanks,
Alok


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

end of thread, other threads:[~2026-01-14 15:27 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-10 19:13 [Intel-wired-lan] [PATCH v2 net] i40e: fix src IP mask checks and memcpy argument names in cloud filter Alok Tiwari
     [not found] ` <PH0PR11MB50139E1973CFB73CFF221FCD9687A@PH0PR11MB5013.namprd11.prod.outlook.com>
2026-01-06 14:41   ` Kamakshi, NelloreX
2026-01-07  5:59     ` Kamakshi, NelloreX
2026-01-14 15:27       ` ALOK TIWARI via Intel-wired-lan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox