diff mbox series

[net] net/smc: fix incorrect SMC-D link group matching logic

Message ID 20240125123916.77928-1-guwen@linux.alibaba.com (mailing list archive)
State Accepted
Commit c3dfcdb65ec1a4813ec1e0871c52c671ba9c71ac
Delegated to: Netdev Maintainers
Headers show
Series [net] net/smc: fix incorrect SMC-D link group matching logic | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net
netdev/ynl success SINGLE THREAD; Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag present in non-next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 1064 this patch: 1064
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 0 of 0 maintainers
netdev/build_clang success Errors and warnings before: 1081 this patch: 1081
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 Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 1081 this patch: 1081
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 18 lines checked
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
netdev/contest success net-next-2024-01-26--21-00 (tests: 610)

Commit Message

Wen Gu Jan. 25, 2024, 12:39 p.m. UTC
The logic to determine if SMC-D link group matches is incorrect. The
correct logic should be that it only returns true when the GID is the
same, and the SMC-D device is the same and the extended GID is the same
(in the case of virtual ISM).

It can be fixed by adding brackets around the conditional (or ternary)
operator expression. But for better readability and maintainability, it
has been changed to an if-else statement.

Reported-by: Matthew Rosato <mjrosato@linux.ibm.com>
Closes: https://lore.kernel.org/r/13579588-eb9d-4626-a063-c0b77ed80f11@linux.ibm.com
Fixes: b40584d14570 ("net/smc: compatible with 128-bits extended GID of virtual ISM device")
Link: https://lore.kernel.org/r/13579588-eb9d-4626-a063-c0b77ed80f11@linux.ibm.com
Signed-off-by: Wen Gu <guwen@linux.alibaba.com>
---
 net/smc/smc_core.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

Comments

Alexandra Winter Jan. 25, 2024, 3:26 p.m. UTC | #1
On 25.01.24 13:39, Wen Gu wrote:
> The logic to determine if SMC-D link group matches is incorrect. The
> correct logic should be that it only returns true when the GID is the
> same, and the SMC-D device is the same and the extended GID is the same
> (in the case of virtual ISM).
> 
> It can be fixed by adding brackets around the conditional (or ternary)
> operator expression. But for better readability and maintainability, it
> has been changed to an if-else statement.
> 
> Reported-by: Matthew Rosato <mjrosato@linux.ibm.com>
> Closes: https://lore.kernel.org/r/13579588-eb9d-4626-a063-c0b77ed80f11@linux.ibm.com
> Fixes: b40584d14570 ("net/smc: compatible with 128-bits extended GID of virtual ISM device")
> Link: https://lore.kernel.org/r/13579588-eb9d-4626-a063-c0b77ed80f11@linux.ibm.com
> Signed-off-by: Wen Gu <guwen@linux.alibaba.com>
> ---
>  net/smc/smc_core.c | 12 +++++++++---
>  1 file changed, 9 insertions(+), 3 deletions(-)
> 
> diff --git a/net/smc/smc_core.c b/net/smc/smc_core.c
> index 95cc95458e2d..e4c858411207 100644
> --- a/net/smc/smc_core.c
> +++ b/net/smc/smc_core.c
> @@ -1877,9 +1877,15 @@ static bool smcd_lgr_match(struct smc_link_group *lgr,
>  			   struct smcd_dev *smcismdev,
>  			   struct smcd_gid *peer_gid)
>  {
> -	return lgr->peer_gid.gid == peer_gid->gid && lgr->smcd == smcismdev &&
> -		smc_ism_is_virtual(smcismdev) ?
> -		(lgr->peer_gid.gid_ext == peer_gid->gid_ext) : 1;
> +	if (lgr->peer_gid.gid != peer_gid->gid ||
> +	    lgr->smcd != smcismdev)
> +		return false;
> +
> +	if (smc_ism_is_virtual(smcismdev) &&
> +	    lgr->peer_gid.gid_ext != peer_gid->gid_ext)
> +		return false;
> +
> +	return true;
>  }
>  
>  /* create a new SMC connection (and a new link group if necessary) */

Thank you Wen Gu

Reviewed-by: Alexandra Winter <wintera@linux.ibm.com>
Matthew Rosato Jan. 25, 2024, 3:29 p.m. UTC | #2
On 1/25/24 7:39 AM, Wen Gu wrote:
> The logic to determine if SMC-D link group matches is incorrect. The
> correct logic should be that it only returns true when the GID is the
> same, and the SMC-D device is the same and the extended GID is the same
> (in the case of virtual ISM).
> 
> It can be fixed by adding brackets around the conditional (or ternary)
> operator expression. But for better readability and maintainability, it
> has been changed to an if-else statement.
> 
> Reported-by: Matthew Rosato <mjrosato@linux.ibm.com>
> Closes: https://lore.kernel.org/r/13579588-eb9d-4626-a063-c0b77ed80f11@linux.ibm.com
> Fixes: b40584d14570 ("net/smc: compatible with 128-bits extended GID of virtual ISM device")
> Link: https://lore.kernel.org/r/13579588-eb9d-4626-a063-c0b77ed80f11@linux.ibm.com
> Signed-off-by: Wen Gu <guwen@linux.alibaba.com>

Hi Wen Gu,

I just ran the same series of tests with this patch applied and it resolves the issue for me.  Thanks for the quick fix!

Thanks,
Matt


> ---
>  net/smc/smc_core.c | 12 +++++++++---
>  1 file changed, 9 insertions(+), 3 deletions(-)
> 
> diff --git a/net/smc/smc_core.c b/net/smc/smc_core.c
> index 95cc95458e2d..e4c858411207 100644
> --- a/net/smc/smc_core.c
> +++ b/net/smc/smc_core.c
> @@ -1877,9 +1877,15 @@ static bool smcd_lgr_match(struct smc_link_group *lgr,
>  			   struct smcd_dev *smcismdev,
>  			   struct smcd_gid *peer_gid)
>  {
> -	return lgr->peer_gid.gid == peer_gid->gid && lgr->smcd == smcismdev &&
> -		smc_ism_is_virtual(smcismdev) ?
> -		(lgr->peer_gid.gid_ext == peer_gid->gid_ext) : 1;
> +	if (lgr->peer_gid.gid != peer_gid->gid ||
> +	    lgr->smcd != smcismdev)
> +		return false;
> +
> +	if (smc_ism_is_virtual(smcismdev) &&
> +	    lgr->peer_gid.gid_ext != peer_gid->gid_ext)
> +		return false;
> +
> +	return true;
>  }
>  
>  /* create a new SMC connection (and a new link group if necessary) */
patchwork-bot+netdevbpf@kernel.org Jan. 26, 2024, 10:10 p.m. UTC | #3
Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Thu, 25 Jan 2024 20:39:16 +0800 you wrote:
> The logic to determine if SMC-D link group matches is incorrect. The
> correct logic should be that it only returns true when the GID is the
> same, and the SMC-D device is the same and the extended GID is the same
> (in the case of virtual ISM).
> 
> It can be fixed by adding brackets around the conditional (or ternary)
> operator expression. But for better readability and maintainability, it
> has been changed to an if-else statement.
> 
> [...]

Here is the summary with links:
  - [net] net/smc: fix incorrect SMC-D link group matching logic
    https://git.kernel.org/netdev/net/c/c3dfcdb65ec1

You are awesome, thank you!
diff mbox series

Patch

diff --git a/net/smc/smc_core.c b/net/smc/smc_core.c
index 95cc95458e2d..e4c858411207 100644
--- a/net/smc/smc_core.c
+++ b/net/smc/smc_core.c
@@ -1877,9 +1877,15 @@  static bool smcd_lgr_match(struct smc_link_group *lgr,
 			   struct smcd_dev *smcismdev,
 			   struct smcd_gid *peer_gid)
 {
-	return lgr->peer_gid.gid == peer_gid->gid && lgr->smcd == smcismdev &&
-		smc_ism_is_virtual(smcismdev) ?
-		(lgr->peer_gid.gid_ext == peer_gid->gid_ext) : 1;
+	if (lgr->peer_gid.gid != peer_gid->gid ||
+	    lgr->smcd != smcismdev)
+		return false;
+
+	if (smc_ism_is_virtual(smcismdev) &&
+	    lgr->peer_gid.gid_ext != peer_gid->gid_ext)
+		return false;
+
+	return true;
 }
 
 /* create a new SMC connection (and a new link group if necessary) */