diff mbox series

[net-next,v2,07/12] selftests: ncdevmem: Properly reset flow steering

Message ID 20240930171753.2572922-8-sdf@fomichev.me (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series selftests: ncdevmem: Add ncdevmem to ksft | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 9 this patch: 9
netdev/build_tools success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers warning 2 maintainers not CCed: shuah@kernel.org linux-kselftest@vger.kernel.org
netdev/build_clang success Errors and warnings before: 9 this patch: 9
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn fail Errors and warnings before: 12 this patch: 12
netdev/checkpatch warning CHECK: Lines should not end with a '('
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Stanislav Fomichev Sept. 30, 2024, 5:17 p.m. UTC
ntuple off/on might be not enough to do it on all NICs.
Add a bunch of shell crap to explicitly remove the rules.

Cc: Mina Almasry <almasrymina@google.com>
Signed-off-by: Stanislav Fomichev <sdf@fomichev.me>
---
 tools/testing/selftests/net/ncdevmem.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

Comments

Mina Almasry Oct. 3, 2024, 7:02 a.m. UTC | #1
On Mon, Sep 30, 2024 at 10:18 AM Stanislav Fomichev <sdf@fomichev.me> wrote:
>
> ntuple off/on might be not enough to do it on all NICs.
> Add a bunch of shell crap to explicitly remove the rules.
>
> Cc: Mina Almasry <almasrymina@google.com>
> Signed-off-by: Stanislav Fomichev <sdf@fomichev.me>
> ---
>  tools/testing/selftests/net/ncdevmem.c | 13 ++++++-------
>  1 file changed, 6 insertions(+), 7 deletions(-)
>
> diff --git a/tools/testing/selftests/net/ncdevmem.c b/tools/testing/selftests/net/ncdevmem.c
> index 47458a13eff5..48cbf057fde7 100644
> --- a/tools/testing/selftests/net/ncdevmem.c
> +++ b/tools/testing/selftests/net/ncdevmem.c
> @@ -207,13 +207,12 @@ void validate_buffer(void *line, size_t size)
>
>  static int reset_flow_steering(void)
>  {
> -       int ret = 0;
> -
> -       ret = run_command("sudo ethtool -K %s ntuple off >&2", ifname);
> -       if (ret)
> -               return ret;
> -
> -       return run_command("sudo ethtool -K %s ntuple on >&2", ifname);
> +       run_command("sudo ethtool -K %s ntuple off >&2", ifname);
> +       run_command("sudo ethtool -K %s ntuple on >&2", ifname);
> +       run_command(
> +               "sudo ethtool -n %s | grep 'Filter:' | awk '{print $2}' | xargs -n1 ethtool -N %s delete >&2",
> +               ifname, ifname);
> +       return 0;

Any reason to remove the checking of the return codes? Silent failures
can waste time if the test fails and someone has to spend time finding
out its the flow steering reset that failed (it may not be very
obvious without the checking of the return code.
Stanislav Fomichev Oct. 3, 2024, 4:42 p.m. UTC | #2
On 10/03, Mina Almasry wrote:
> On Mon, Sep 30, 2024 at 10:18 AM Stanislav Fomichev <sdf@fomichev.me> wrote:
> >
> > ntuple off/on might be not enough to do it on all NICs.
> > Add a bunch of shell crap to explicitly remove the rules.
> >
> > Cc: Mina Almasry <almasrymina@google.com>
> > Signed-off-by: Stanislav Fomichev <sdf@fomichev.me>
> > ---
> >  tools/testing/selftests/net/ncdevmem.c | 13 ++++++-------
> >  1 file changed, 6 insertions(+), 7 deletions(-)
> >
> > diff --git a/tools/testing/selftests/net/ncdevmem.c b/tools/testing/selftests/net/ncdevmem.c
> > index 47458a13eff5..48cbf057fde7 100644
> > --- a/tools/testing/selftests/net/ncdevmem.c
> > +++ b/tools/testing/selftests/net/ncdevmem.c
> > @@ -207,13 +207,12 @@ void validate_buffer(void *line, size_t size)
> >
> >  static int reset_flow_steering(void)
> >  {
> > -       int ret = 0;
> > -
> > -       ret = run_command("sudo ethtool -K %s ntuple off >&2", ifname);
> > -       if (ret)
> > -               return ret;
> > -
> > -       return run_command("sudo ethtool -K %s ntuple on >&2", ifname);
> > +       run_command("sudo ethtool -K %s ntuple off >&2", ifname);
> > +       run_command("sudo ethtool -K %s ntuple on >&2", ifname);
> > +       run_command(
> > +               "sudo ethtool -n %s | grep 'Filter:' | awk '{print $2}' | xargs -n1 ethtool -N %s delete >&2",
> > +               ifname, ifname);
> > +       return 0;
> 
> Any reason to remove the checking of the return codes? Silent failures
> can waste time if the test fails and someone has to spend time finding
> out its the flow steering reset that failed (it may not be very
> obvious without the checking of the return code.

IIRC, for me the 'ntuple off' part fails because the NIC doesn't let me
turn it of. And the new "ethtool .. | grep 'Filter: ' | ..." also fails
when there are no existing filters. 

I will add a comment to clarify..
Mina Almasry Oct. 3, 2024, 6:54 p.m. UTC | #3
On Thu, Oct 3, 2024 at 9:42 AM Stanislav Fomichev <stfomichev@gmail.com> wrote:
>
> On 10/03, Mina Almasry wrote:
> > On Mon, Sep 30, 2024 at 10:18 AM Stanislav Fomichev <sdf@fomichev.me> wrote:
> > >
> > > ntuple off/on might be not enough to do it on all NICs.
> > > Add a bunch of shell crap to explicitly remove the rules.
> > >
> > > Cc: Mina Almasry <almasrymina@google.com>
> > > Signed-off-by: Stanislav Fomichev <sdf@fomichev.me>
> > > ---
> > >  tools/testing/selftests/net/ncdevmem.c | 13 ++++++-------
> > >  1 file changed, 6 insertions(+), 7 deletions(-)
> > >
> > > diff --git a/tools/testing/selftests/net/ncdevmem.c b/tools/testing/selftests/net/ncdevmem.c
> > > index 47458a13eff5..48cbf057fde7 100644
> > > --- a/tools/testing/selftests/net/ncdevmem.c
> > > +++ b/tools/testing/selftests/net/ncdevmem.c
> > > @@ -207,13 +207,12 @@ void validate_buffer(void *line, size_t size)
> > >
> > >  static int reset_flow_steering(void)
> > >  {
> > > -       int ret = 0;
> > > -
> > > -       ret = run_command("sudo ethtool -K %s ntuple off >&2", ifname);
> > > -       if (ret)
> > > -               return ret;
> > > -
> > > -       return run_command("sudo ethtool -K %s ntuple on >&2", ifname);
> > > +       run_command("sudo ethtool -K %s ntuple off >&2", ifname);
> > > +       run_command("sudo ethtool -K %s ntuple on >&2", ifname);
> > > +       run_command(
> > > +               "sudo ethtool -n %s | grep 'Filter:' | awk '{print $2}' | xargs -n1 ethtool -N %s delete >&2",
> > > +               ifname, ifname);
> > > +       return 0;
> >
> > Any reason to remove the checking of the return codes? Silent failures
> > can waste time if the test fails and someone has to spend time finding
> > out its the flow steering reset that failed (it may not be very
> > obvious without the checking of the return code.
>
> IIRC, for me the 'ntuple off' part fails because the NIC doesn't let me
> turn it of. And the new "ethtool .. | grep 'Filter: ' | ..." also fails
> when there are no existing filters.
>
> I will add a comment to clarify..

Ah, understood. Seems this area is fraught with subtleties.

If you have time, maybe to counter these subtleties we can do a get of
ntuple filters and confirm they're 0 somehow at the end of the
function. That would offset not checking the return code.

But, I don't think it's extremely likely to run into errors here? So,
this is probably good and can easily be improved later if we run into
issues:

Reviewed-by: Mina Almasry <almasrymina@google.com>
Stanislav Fomichev Oct. 3, 2024, 10:12 p.m. UTC | #4
On 10/03, Mina Almasry wrote:
> On Thu, Oct 3, 2024 at 9:42 AM Stanislav Fomichev <stfomichev@gmail.com> wrote:
> >
> > On 10/03, Mina Almasry wrote:
> > > On Mon, Sep 30, 2024 at 10:18 AM Stanislav Fomichev <sdf@fomichev.me> wrote:
> > > >
> > > > ntuple off/on might be not enough to do it on all NICs.
> > > > Add a bunch of shell crap to explicitly remove the rules.
> > > >
> > > > Cc: Mina Almasry <almasrymina@google.com>
> > > > Signed-off-by: Stanislav Fomichev <sdf@fomichev.me>
> > > > ---
> > > >  tools/testing/selftests/net/ncdevmem.c | 13 ++++++-------
> > > >  1 file changed, 6 insertions(+), 7 deletions(-)
> > > >
> > > > diff --git a/tools/testing/selftests/net/ncdevmem.c b/tools/testing/selftests/net/ncdevmem.c
> > > > index 47458a13eff5..48cbf057fde7 100644
> > > > --- a/tools/testing/selftests/net/ncdevmem.c
> > > > +++ b/tools/testing/selftests/net/ncdevmem.c
> > > > @@ -207,13 +207,12 @@ void validate_buffer(void *line, size_t size)
> > > >
> > > >  static int reset_flow_steering(void)
> > > >  {
> > > > -       int ret = 0;
> > > > -
> > > > -       ret = run_command("sudo ethtool -K %s ntuple off >&2", ifname);
> > > > -       if (ret)
> > > > -               return ret;
> > > > -
> > > > -       return run_command("sudo ethtool -K %s ntuple on >&2", ifname);
> > > > +       run_command("sudo ethtool -K %s ntuple off >&2", ifname);
> > > > +       run_command("sudo ethtool -K %s ntuple on >&2", ifname);
> > > > +       run_command(
> > > > +               "sudo ethtool -n %s | grep 'Filter:' | awk '{print $2}' | xargs -n1 ethtool -N %s delete >&2",
> > > > +               ifname, ifname);
> > > > +       return 0;
> > >
> > > Any reason to remove the checking of the return codes? Silent failures
> > > can waste time if the test fails and someone has to spend time finding
> > > out its the flow steering reset that failed (it may not be very
> > > obvious without the checking of the return code.
> >
> > IIRC, for me the 'ntuple off' part fails because the NIC doesn't let me
> > turn it of. And the new "ethtool .. | grep 'Filter: ' | ..." also fails
> > when there are no existing filters.
> >
> > I will add a comment to clarify..
> 
> Ah, understood. Seems this area is fraught with subtleties.
> 
> If you have time, maybe to counter these subtleties we can do a get of
> ntuple filters and confirm they're 0 somehow at the end of the
> function. That would offset not checking the return code.
> 
> But, I don't think it's extremely likely to run into errors here? So,
> this is probably good and can easily be improved later if we run into
> issues:
> 
> Reviewed-by: Mina Almasry <almasrymina@google.com>

Ack, I'll keep it as is with a comment. Ideally we should do proper
ethtool netlink/ioctl instead of shelling out, but I don' think
ntuple API is exposed to netlink and I'm too lazy to dive into how
the old ioctl-based ntuple API works :-D
diff mbox series

Patch

diff --git a/tools/testing/selftests/net/ncdevmem.c b/tools/testing/selftests/net/ncdevmem.c
index 47458a13eff5..48cbf057fde7 100644
--- a/tools/testing/selftests/net/ncdevmem.c
+++ b/tools/testing/selftests/net/ncdevmem.c
@@ -207,13 +207,12 @@  void validate_buffer(void *line, size_t size)
 
 static int reset_flow_steering(void)
 {
-	int ret = 0;
-
-	ret = run_command("sudo ethtool -K %s ntuple off >&2", ifname);
-	if (ret)
-		return ret;
-
-	return run_command("sudo ethtool -K %s ntuple on >&2", ifname);
+	run_command("sudo ethtool -K %s ntuple off >&2", ifname);
+	run_command("sudo ethtool -K %s ntuple on >&2", ifname);
+	run_command(
+		"sudo ethtool -n %s | grep 'Filter:' | awk '{print $2}' | xargs -n1 ethtool -N %s delete >&2",
+		ifname, ifname);
+	return 0;
 }
 
 static int configure_headersplit(bool on)