diff mbox series

[net-next,v4,03/18] net/smc: extract v2 check helper from SMC-D device registration

Message ID 1695568613-125057-4-git-send-email-guwen@linux.alibaba.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series net/smc: implement virtual ISM extension and loopback-ism | expand

Checks

Context Check Description
netdev/series_format fail Series longer than 15 patches (and no cover letter)
netdev/tree_selection success Clearly marked for net-next
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: 1340 this patch: 1340
netdev/cc_maintainers success CCed 12 of 12 maintainers
netdev/build_clang success Errors and warnings before: 1363 this patch: 1363
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: 1363 this patch: 1363
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 57 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Wen Gu Sept. 24, 2023, 3:16 p.m. UTC
This patch extracts v2-capable logic from the process of registering the
ISM device as an SMC-D device, so that the registration process of other
underlying devices can reuse it.

Signed-off-by: Wen Gu <guwen@linux.alibaba.com>
---
 net/smc/smc_ism.c | 29 ++++++++++++++++++-----------
 net/smc/smc_ism.h |  1 +
 2 files changed, 19 insertions(+), 11 deletions(-)

Comments

Jan Karcher Sept. 28, 2023, 3:08 a.m. UTC | #1
On 24/09/2023 17:16, Wen Gu wrote:
> This patch extracts v2-capable logic from the process of registering the
> ISM device as an SMC-D device, so that the registration process of other
> underlying devices can reuse it.
> 
> Signed-off-by: Wen Gu <guwen@linux.alibaba.com>
> ---
>   net/smc/smc_ism.c | 29 ++++++++++++++++++-----------
>   net/smc/smc_ism.h |  1 +
>   2 files changed, 19 insertions(+), 11 deletions(-)
> 
> diff --git a/net/smc/smc_ism.c b/net/smc/smc_ism.c
> index 455ae0a..8f1ba74 100644
> --- a/net/smc/smc_ism.c
> +++ b/net/smc/smc_ism.c
> @@ -69,6 +69,22 @@ bool smc_ism_is_v2_capable(void)
>   	return smc_ism_v2_capable;
>   }
>   
> +/* must be called under smcd_dev_list.mutex lock */
> +void smc_ism_check_v2_capable(struct smcd_dev *smcd)
> +{
> +	u8 *system_eid = NULL;
> +
> +	if (smc_ism_v2_capable)
> +		return;
> +
> +	system_eid = smcd->ops->get_system_eid();
> +	if (smcd->ops->supports_v2()) {
> +		smc_ism_v2_capable = true;
> +		memcpy(smc_ism_v2_system_eid, system_eid,
> +		       SMC_MAX_EID_LEN);
> +	}
> +}
> +
>   /* Set a connection using this DMBE. */
>   void smc_ism_set_conn(struct smc_connection *conn)
>   {
> @@ -423,16 +439,7 @@ static void smcd_register_dev(struct ism_dev *ism)
>   		smc_pnetid_by_table_smcd(smcd);
>   
>   	mutex_lock(&smcd_dev_list.mutex);
> -	if (list_empty(&smcd_dev_list.list)) {
> -		u8 *system_eid = NULL;
> -
> -		system_eid = smcd->ops->get_system_eid();
> -		if (smcd->ops->supports_v2()) {
> -			smc_ism_v2_capable = true;
> -			memcpy(smc_ism_v2_system_eid, system_eid,
> -			       SMC_MAX_EID_LEN);
> -		}
> -	}
> +	smc_ism_check_v2_capable(smcd);

The list_empty check is omitted here which means the 
smc_ism_check_v2_capable does not touch the list.
So i think the call could be placed prior the mutex_lock.

>   	/* sort list: devices without pnetid before devices with pnetid */
>   	if (smcd->pnetid[0])
>   		list_add_tail(&smcd->list, &smcd_dev_list.list);
> @@ -535,10 +542,10 @@ int smc_ism_init(void)
>   {
>   	int rc = 0;
>   
> -#if IS_ENABLED(CONFIG_ISM)
>   	smc_ism_v2_capable = false;
>   	memset(smc_ism_v2_system_eid, 0, SMC_MAX_EID_LEN);
>   
> +#if IS_ENABLED(CONFIG_ISM)
>   	rc = ism_register_client(&smc_ism_client);
>   #endif
>   	return rc;
> diff --git a/net/smc/smc_ism.h b/net/smc/smc_ism.h
> index 832b2f4..14d2e77 100644
> --- a/net/smc/smc_ism.h
> +++ b/net/smc/smc_ism.h
> @@ -42,6 +42,7 @@ int smc_ism_register_dmb(struct smc_link_group *lgr, int buf_size,
>   void smc_ism_get_system_eid(u8 **eid);
>   u16 smc_ism_get_chid(struct smcd_dev *dev);
>   bool smc_ism_is_v2_capable(void);
> +void smc_ism_check_v2_capable(struct smcd_dev *dev);
>   int smc_ism_init(void);
>   void smc_ism_exit(void);
>   int smcd_nl_get_device(struct sk_buff *skb, struct netlink_callback *cb);
Wen Gu Sept. 30, 2023, 8:41 a.m. UTC | #2
On 2023/9/28 11:08, Jan Karcher wrote:
> 
> 
> On 24/09/2023 17:16, Wen Gu wrote:
>> This patch extracts v2-capable logic from the process of registering the
>> ISM device as an SMC-D device, so that the registration process of other
>> underlying devices can reuse it.
>>
>> Signed-off-by: Wen Gu <guwen@linux.alibaba.com>
>> ---
>>   net/smc/smc_ism.c | 29 ++++++++++++++++++-----------
>>   net/smc/smc_ism.h |  1 +
>>   2 files changed, 19 insertions(+), 11 deletions(-)
>>
>> diff --git a/net/smc/smc_ism.c b/net/smc/smc_ism.c
>> index 455ae0a..8f1ba74 100644
>> --- a/net/smc/smc_ism.c
>> +++ b/net/smc/smc_ism.c
>> @@ -69,6 +69,22 @@ bool smc_ism_is_v2_capable(void)
>>       return smc_ism_v2_capable;
>>   }
>> +/* must be called under smcd_dev_list.mutex lock */
>> +void smc_ism_check_v2_capable(struct smcd_dev *smcd)
>> +{
>> +    u8 *system_eid = NULL;
>> +
>> +    if (smc_ism_v2_capable)
>> +        return;
>> +
>> +    system_eid = smcd->ops->get_system_eid();
>> +    if (smcd->ops->supports_v2()) {
>> +        smc_ism_v2_capable = true;
>> +        memcpy(smc_ism_v2_system_eid, system_eid,
>> +               SMC_MAX_EID_LEN);
>> +    }
>> +}
>> +
>>   /* Set a connection using this DMBE. */
>>   void smc_ism_set_conn(struct smc_connection *conn)
>>   {
>> @@ -423,16 +439,7 @@ static void smcd_register_dev(struct ism_dev *ism)
>>           smc_pnetid_by_table_smcd(smcd);
>>       mutex_lock(&smcd_dev_list.mutex);
>> -    if (list_empty(&smcd_dev_list.list)) {
>> -        u8 *system_eid = NULL;
>> -
>> -        system_eid = smcd->ops->get_system_eid();
>> -        if (smcd->ops->supports_v2()) {
>> -            smc_ism_v2_capable = true;
>> -            memcpy(smc_ism_v2_system_eid, system_eid,
>> -                   SMC_MAX_EID_LEN);
>> -        }
>> -    }
>> +    smc_ism_check_v2_capable(smcd);
> 
> The list_empty check is omitted here which means the smc_ism_check_v2_capable does not touch the list.
> So i think the call could be placed prior the mutex_lock.
> 

Good catch. I omitted the list_empty check in this version but forget to remove 'the
lock comments' and place the helper prior to the mutex_lock. It will be fixed.

Thank you.

>>       /* sort list: devices without pnetid before devices with pnetid */
>>       if (smcd->pnetid[0])
>>           list_add_tail(&smcd->list, &smcd_dev_list.list);
>> @@ -535,10 +542,10 @@ int smc_ism_init(void)
>>   {
>>       int rc = 0;
>> -#if IS_ENABLED(CONFIG_ISM)
>>       smc_ism_v2_capable = false;
>>       memset(smc_ism_v2_system_eid, 0, SMC_MAX_EID_LEN);
>> +#if IS_ENABLED(CONFIG_ISM)
>>       rc = ism_register_client(&smc_ism_client);
>>   #endif
>>       return rc;
>> diff --git a/net/smc/smc_ism.h b/net/smc/smc_ism.h
>> index 832b2f4..14d2e77 100644
>> --- a/net/smc/smc_ism.h
>> +++ b/net/smc/smc_ism.h
>> @@ -42,6 +42,7 @@ int smc_ism_register_dmb(struct smc_link_group *lgr, int buf_size,
>>   void smc_ism_get_system_eid(u8 **eid);
>>   u16 smc_ism_get_chid(struct smcd_dev *dev);
>>   bool smc_ism_is_v2_capable(void);
>> +void smc_ism_check_v2_capable(struct smcd_dev *dev);
>>   int smc_ism_init(void);
>>   void smc_ism_exit(void);
>>   int smcd_nl_get_device(struct sk_buff *skb, struct netlink_callback *cb);
diff mbox series

Patch

diff --git a/net/smc/smc_ism.c b/net/smc/smc_ism.c
index 455ae0a..8f1ba74 100644
--- a/net/smc/smc_ism.c
+++ b/net/smc/smc_ism.c
@@ -69,6 +69,22 @@  bool smc_ism_is_v2_capable(void)
 	return smc_ism_v2_capable;
 }
 
+/* must be called under smcd_dev_list.mutex lock */
+void smc_ism_check_v2_capable(struct smcd_dev *smcd)
+{
+	u8 *system_eid = NULL;
+
+	if (smc_ism_v2_capable)
+		return;
+
+	system_eid = smcd->ops->get_system_eid();
+	if (smcd->ops->supports_v2()) {
+		smc_ism_v2_capable = true;
+		memcpy(smc_ism_v2_system_eid, system_eid,
+		       SMC_MAX_EID_LEN);
+	}
+}
+
 /* Set a connection using this DMBE. */
 void smc_ism_set_conn(struct smc_connection *conn)
 {
@@ -423,16 +439,7 @@  static void smcd_register_dev(struct ism_dev *ism)
 		smc_pnetid_by_table_smcd(smcd);
 
 	mutex_lock(&smcd_dev_list.mutex);
-	if (list_empty(&smcd_dev_list.list)) {
-		u8 *system_eid = NULL;
-
-		system_eid = smcd->ops->get_system_eid();
-		if (smcd->ops->supports_v2()) {
-			smc_ism_v2_capable = true;
-			memcpy(smc_ism_v2_system_eid, system_eid,
-			       SMC_MAX_EID_LEN);
-		}
-	}
+	smc_ism_check_v2_capable(smcd);
 	/* sort list: devices without pnetid before devices with pnetid */
 	if (smcd->pnetid[0])
 		list_add_tail(&smcd->list, &smcd_dev_list.list);
@@ -535,10 +542,10 @@  int smc_ism_init(void)
 {
 	int rc = 0;
 
-#if IS_ENABLED(CONFIG_ISM)
 	smc_ism_v2_capable = false;
 	memset(smc_ism_v2_system_eid, 0, SMC_MAX_EID_LEN);
 
+#if IS_ENABLED(CONFIG_ISM)
 	rc = ism_register_client(&smc_ism_client);
 #endif
 	return rc;
diff --git a/net/smc/smc_ism.h b/net/smc/smc_ism.h
index 832b2f4..14d2e77 100644
--- a/net/smc/smc_ism.h
+++ b/net/smc/smc_ism.h
@@ -42,6 +42,7 @@  int smc_ism_register_dmb(struct smc_link_group *lgr, int buf_size,
 void smc_ism_get_system_eid(u8 **eid);
 u16 smc_ism_get_chid(struct smcd_dev *dev);
 bool smc_ism_is_v2_capable(void);
+void smc_ism_check_v2_capable(struct smcd_dev *dev);
 int smc_ism_init(void);
 void smc_ism_exit(void);
 int smcd_nl_get_device(struct sk_buff *skb, struct netlink_callback *cb);