diff mbox series

[net] net/smc: correct the reason code in smc_listen_find_device when fallback

Message ID 20231016061153.40057-1-guangguan.wang@linux.alibaba.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series [net] net/smc: correct the reason code in smc_listen_find_device when fallback | 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/fixes_present fail Series targets non-next tree, but doesn't contain any Fixes tags
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 1362 this patch: 1362
netdev/cc_maintainers success CCed 12 of 12 maintainers
netdev/build_clang success Errors and warnings before: 1386 this patch: 1386
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 success Errors and warnings before: 1386 this patch: 1386
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 76 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Guangguan Wang Oct. 16, 2023, 6:11 a.m. UTC
The function smc_find_ism_store_rc is not only used for ism, so it is
reasonable to change the function name to smc_find_device_store_rc.

The ini->rc is used to store the last error happened when finding usable
ism or rdma device in smc_listen_find_device, and is set by calling smc_
find_device_store_rc. Once the ini->rc is assigned to an none-zero value,
the value can not be overwritten anymore. So the ini-rc should be set to
the error reason only when an error actually occurs.

When finding ISM/RDMA devices, device not found is not a real error, as
not all machine have ISM/RDMA devices. Failures after device found, when
initializing device or when initializing connection, is real errors, and
should be store in ini->rc.

SMC_CLC_DECL_DIFFPREFIX also is not a real error, as for SMC-RV2, it is
not require same prefix.

Signed-off-by: Guangguan Wang <guangguan.wang@linux.alibaba.com>
---
 net/smc/af_smc.c | 23 +++++++++--------------
 1 file changed, 9 insertions(+), 14 deletions(-)

Comments

Dust Li Oct. 17, 2023, 7:37 a.m. UTC | #1
On Mon, Oct 16, 2023 at 02:11:53PM +0800, Guangguan Wang wrote:

Hi guangguan,

This patch doesn't apply clearly on net because it conflict with my
previous patch 4abbd2e3c1db(net/smc: return the right falback reason
when prefix checks fail), pls rebase.

>The function smc_find_ism_store_rc is not only used for ism, so it is
>reasonable to change the function name to smc_find_device_store_rc.
>
>The ini->rc is used to store the last error happened when finding usable
>ism or rdma device in smc_listen_find_device, and is set by calling smc_
>find_device_store_rc. Once the ini->rc is assigned to an none-zero value,
>the value can not be overwritten anymore. So the ini-rc should be set to
>the error reason only when an error actually occurs.
>
>When finding ISM/RDMA devices, device not found is not a real error, as
>not all machine have ISM/RDMA devices. Failures after device found, when
>initializing device or when initializing connection, is real errors, and
>should be store in ini->rc.
>
>SMC_CLC_DECL_DIFFPREFIX also is not a real error, as for SMC-RV2, it is
>not require same prefix.

I think it's better to seperate this patch into 2:
- one for changing the name from smc_find_ism_store_rc to smc_find_device_store_rc.
- one for fixing the return reason.

More comments below.

>
>Signed-off-by: Guangguan Wang <guangguan.wang@linux.alibaba.com>
>---
> net/smc/af_smc.c | 23 +++++++++--------------
> 1 file changed, 9 insertions(+), 14 deletions(-)
>
>diff --git a/net/smc/af_smc.c b/net/smc/af_smc.c
>index bacdd971615e..15d8ad7af75d 100644
>--- a/net/smc/af_smc.c
>+++ b/net/smc/af_smc.c
>@@ -2121,7 +2121,7 @@ static void smc_check_ism_v2_match(struct smc_init_info *ini,
> 	}
> }
> 
>-static void smc_find_ism_store_rc(u32 rc, struct smc_init_info *ini)
>+static void smc_find_device_store_rc(u32 rc, struct smc_init_info *ini)
> {
> 	if (!ini->rc)
> 		ini->rc = rc;
>@@ -2162,10 +2162,8 @@ static void smc_find_ism_v2_device_serv(struct smc_sock *new_smc,
> 	}
> 	mutex_unlock(&smcd_dev_list.mutex);
> 
>-	if (!ini->ism_dev[0]) {
>-		smc_find_ism_store_rc(SMC_CLC_DECL_NOSMCD2DEV, ini);
>+	if (!ini->ism_dev[0])
> 		goto not_found;
>-	}
> 
> 	smc_ism_get_system_eid(&eid);
> 	if (!smc_clc_match_eid(ini->negotiated_eid, smc_v2_ext,
>@@ -2180,7 +2178,7 @@ static void smc_find_ism_v2_device_serv(struct smc_sock *new_smc,
> 		ini->ism_selected = i;
> 		rc = smc_listen_ism_init(new_smc, ini);
> 		if (rc) {
>-			smc_find_ism_store_rc(rc, ini);
>+			smc_find_device_store_rc(rc, ini);
> 			/* try next active ISM device */
> 			continue;
> 		}
>@@ -2213,11 +2211,12 @@ static void smc_find_ism_v1_device_serv(struct smc_sock *new_smc,
> 		goto not_found;
> 	ini->ism_selected = 0;
> 	rc = smc_listen_ism_init(new_smc, ini);
>-	if (!rc)
>+	if (!rc) {
>+		smc_find_device_store_rc(rc, ini);

This smc_find_device_store_rc() seems useless when rc == 0 here ?

> 		return;		/* V1 ISM device found */
>+	}
> 
> not_found:
>-	smc_find_ism_store_rc(rc, ini);
> 	ini->smcd_version &= ~SMC_V1;
> 	ini->ism_dev[0] = NULL;
> 	ini->is_smcd = false;
>@@ -2266,10 +2265,8 @@ static void smc_find_rdma_v2_device_serv(struct smc_sock *new_smc,
> 	ini->smcrv2.saddr = new_smc->clcsock->sk->sk_rcv_saddr;
> 	ini->smcrv2.daddr = smc_ib_gid_to_ipv4(smc_v2_ext->roce);
> 	rc = smc_find_rdma_device(new_smc, ini);
>-	if (rc) {
>-		smc_find_ism_store_rc(rc, ini);
>+	if (rc)
> 		goto not_found;
>-	}
> 	if (!ini->smcrv2.uses_gateway)
> 		memcpy(ini->smcrv2.nexthop_mac, pclc->lcl.mac, ETH_ALEN);
> 
>@@ -2284,7 +2281,7 @@ static void smc_find_rdma_v2_device_serv(struct smc_sock *new_smc,
> 	if (!rc)
> 		return;
> 	ini->smcr_version = smcr_version;
>-	smc_find_ism_store_rc(rc, ini);
>+	smc_find_device_store_rc(rc, ini);
> 
> not_found:
> 	ini->smcr_version &= ~SMC_V2;
>@@ -2330,8 +2327,6 @@ static int smc_listen_find_device(struct smc_sock *new_smc,
> 
> 	/* check for matching IP prefix and subnet length (V1) */
> 	prfx_rc = smc_listen_prfx_check(new_smc, pclc);
>-	if (prfx_rc)
>-		smc_find_ism_store_rc(prfx_rc, ini);
> 
> 	/* get vlan id from IP device */
> 	if (smc_vlan_by_tcpsk(new_smc->clcsock, ini))
>@@ -2358,7 +2353,7 @@ static int smc_listen_find_device(struct smc_sock *new_smc,
> 		int rc;
> 
> 		rc = smc_find_rdma_v1_device_serv(new_smc, pclc, ini);
>-		smc_find_ism_store_rc(rc, ini);
>+		smc_find_device_store_rc(rc, ini);
> 		return (!rc) ? 0 : ini->rc;
> 	}
> 	return SMC_CLC_DECL_NOSMCDEV;
>-- 
>2.24.3 (Apple Git-128)
Guangguan Wang Oct. 17, 2023, 8:52 a.m. UTC | #2
On 2023/10/17 15:37, Dust Li wrote:
> On Mon, Oct 16, 2023 at 02:11:53PM +0800, Guangguan Wang wrote:
> 
> Hi guangguan,
> 
> This patch doesn't apply clearly on net because it conflict with my
> previous patch 4abbd2e3c1db(net/smc: return the right falback reason
> when prefix checks fail), pls rebase.
>

This patch sent before the patch 4abbd2e3c1db applied. I will rebase it
in the next version.
 
>> The function smc_find_ism_store_rc is not only used for ism, so it is
>> reasonable to change the function name to smc_find_device_store_rc.
>>
>> The ini->rc is used to store the last error happened when finding usable
>> ism or rdma device in smc_listen_find_device, and is set by calling smc_
>> find_device_store_rc. Once the ini->rc is assigned to an none-zero value,
>> the value can not be overwritten anymore. So the ini-rc should be set to
>> the error reason only when an error actually occurs.
>>
>> When finding ISM/RDMA devices, device not found is not a real error, as
>> not all machine have ISM/RDMA devices. Failures after device found, when
>> initializing device or when initializing connection, is real errors, and
>> should be store in ini->rc.
>>
>> SMC_CLC_DECL_DIFFPREFIX also is not a real error, as for SMC-RV2, it is
>> not require same prefix.
> 
> I think it's better to seperate this patch into 2:
> - one for changing the name from smc_find_ism_store_rc to smc_find_device_store_rc.
> - one for fixing the return reason.
> 
> More comments below.
> 
OK, I will seperate it.
>>
>> Signed-off-by: Guangguan Wang <guangguan.wang@linux.alibaba.com>

>> @@ -2213,11 +2211,12 @@ static void smc_find_ism_v1_device_serv(struct smc_sock *new_smc,
>> 		goto not_found;
>> 	ini->ism_selected = 0;
>> 	rc = smc_listen_ism_init(new_smc, ini);
>> -	if (!rc)
>> +	if (!rc) {
>> +		smc_find_device_store_rc(rc, ini);
> 
> This smc_find_device_store_rc() seems useless when rc == 0 here ?

Oh, I see. The code here should be:

rc = smc_listen_ism_init(new_smc, ini);
if (!rc)
    return;
smc_find_device_store_rc(rc, ini);

not_found:
    ini->smcd_version &= ~SMC_V1;
    ini->ism_dev[0] = NULL;
    ini->is_smcd = false;


Thanks,
Guangguan Wang.
> 
>> 		return;		/* V1 ISM device found */
>> +	}
>>
>> not_found:
>> -	smc_find_ism_store_rc(rc, ini);
>> 	ini->smcd_version &= ~SMC_V1;
>> 	ini->ism_dev[0] = NULL;
>> 	ini->is_smcd = false;
diff mbox series

Patch

diff --git a/net/smc/af_smc.c b/net/smc/af_smc.c
index bacdd971615e..15d8ad7af75d 100644
--- a/net/smc/af_smc.c
+++ b/net/smc/af_smc.c
@@ -2121,7 +2121,7 @@  static void smc_check_ism_v2_match(struct smc_init_info *ini,
 	}
 }
 
-static void smc_find_ism_store_rc(u32 rc, struct smc_init_info *ini)
+static void smc_find_device_store_rc(u32 rc, struct smc_init_info *ini)
 {
 	if (!ini->rc)
 		ini->rc = rc;
@@ -2162,10 +2162,8 @@  static void smc_find_ism_v2_device_serv(struct smc_sock *new_smc,
 	}
 	mutex_unlock(&smcd_dev_list.mutex);
 
-	if (!ini->ism_dev[0]) {
-		smc_find_ism_store_rc(SMC_CLC_DECL_NOSMCD2DEV, ini);
+	if (!ini->ism_dev[0])
 		goto not_found;
-	}
 
 	smc_ism_get_system_eid(&eid);
 	if (!smc_clc_match_eid(ini->negotiated_eid, smc_v2_ext,
@@ -2180,7 +2178,7 @@  static void smc_find_ism_v2_device_serv(struct smc_sock *new_smc,
 		ini->ism_selected = i;
 		rc = smc_listen_ism_init(new_smc, ini);
 		if (rc) {
-			smc_find_ism_store_rc(rc, ini);
+			smc_find_device_store_rc(rc, ini);
 			/* try next active ISM device */
 			continue;
 		}
@@ -2213,11 +2211,12 @@  static void smc_find_ism_v1_device_serv(struct smc_sock *new_smc,
 		goto not_found;
 	ini->ism_selected = 0;
 	rc = smc_listen_ism_init(new_smc, ini);
-	if (!rc)
+	if (!rc) {
+		smc_find_device_store_rc(rc, ini);
 		return;		/* V1 ISM device found */
+	}
 
 not_found:
-	smc_find_ism_store_rc(rc, ini);
 	ini->smcd_version &= ~SMC_V1;
 	ini->ism_dev[0] = NULL;
 	ini->is_smcd = false;
@@ -2266,10 +2265,8 @@  static void smc_find_rdma_v2_device_serv(struct smc_sock *new_smc,
 	ini->smcrv2.saddr = new_smc->clcsock->sk->sk_rcv_saddr;
 	ini->smcrv2.daddr = smc_ib_gid_to_ipv4(smc_v2_ext->roce);
 	rc = smc_find_rdma_device(new_smc, ini);
-	if (rc) {
-		smc_find_ism_store_rc(rc, ini);
+	if (rc)
 		goto not_found;
-	}
 	if (!ini->smcrv2.uses_gateway)
 		memcpy(ini->smcrv2.nexthop_mac, pclc->lcl.mac, ETH_ALEN);
 
@@ -2284,7 +2281,7 @@  static void smc_find_rdma_v2_device_serv(struct smc_sock *new_smc,
 	if (!rc)
 		return;
 	ini->smcr_version = smcr_version;
-	smc_find_ism_store_rc(rc, ini);
+	smc_find_device_store_rc(rc, ini);
 
 not_found:
 	ini->smcr_version &= ~SMC_V2;
@@ -2330,8 +2327,6 @@  static int smc_listen_find_device(struct smc_sock *new_smc,
 
 	/* check for matching IP prefix and subnet length (V1) */
 	prfx_rc = smc_listen_prfx_check(new_smc, pclc);
-	if (prfx_rc)
-		smc_find_ism_store_rc(prfx_rc, ini);
 
 	/* get vlan id from IP device */
 	if (smc_vlan_by_tcpsk(new_smc->clcsock, ini))
@@ -2358,7 +2353,7 @@  static int smc_listen_find_device(struct smc_sock *new_smc,
 		int rc;
 
 		rc = smc_find_rdma_v1_device_serv(new_smc, pclc, ini);
-		smc_find_ism_store_rc(rc, ini);
+		smc_find_device_store_rc(rc, ini);
 		return (!rc) ? 0 : ini->rc;
 	}
 	return SMC_CLC_DECL_NOSMCDEV;