Commit bc1dde56 authored by Wen Gu's avatar Wen Gu Committed by Zhengchao Shao
Browse files

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

mainline inclusion
from mainline-v6.8-rc3
commit c3dfcdb65ec1a4813ec1e0871c52c671ba9c71ac
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/IACM52

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=c3dfcdb65ec1a4813ec1e0871c52c671ba9c71ac



--------------------------------

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: default avatarMatthew 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: default avatarWen Gu <guwen@linux.alibaba.com>
Reviewed-by: default avatarAlexandra Winter <wintera@linux.ibm.com>
Link: https://lore.kernel.org/r/20240125123916.77928-1-guwen@linux.alibaba.com


Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
Signed-off-by: default avatarZhengchao Shao <shaozhengchao@huawei.com>
parent 18cc1ccb
Loading
Loading
Loading
Loading
+9 −3
Original line number Diff line number Diff line
@@ -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) */