public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Alexandra Winter <wintera@linux.ibm.com>
To: Wen Gu <guwen@linux.alibaba.com>,
	wenjia@linux.ibm.com, hca@linux.ibm.com, gor@linux.ibm.com,
	agordeev@linux.ibm.com, davem@davemloft.net, edumazet@google.com,
	kuba@kernel.org, pabeni@redhat.com, kgraul@linux.ibm.com,
	jaka@linux.ibm.com
Cc: borntraeger@linux.ibm.com, svens@linux.ibm.com,
	alibuda@linux.alibaba.com, tonylu@linux.alibaba.com,
	raspl@linux.ibm.com, schnelle@linux.ibm.com,
	guangguan.wang@linux.alibaba.com, linux-s390@vger.kernel.org,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH net-next v5 2/9] net/smc: introduce sub-functions for smc_clc_send_confirm_accept()
Date: Mon, 11 Dec 2023 14:35:30 +0100	[thread overview]
Message-ID: <fb2365f6-1237-4f22-9897-5676757e5157@linux.ibm.com> (raw)
In-Reply-To: <9a6d57c0-f5b4-9b2c-dc5f-dc47d0518141@linux.alibaba.com>



On 11.12.23 13:15, Wen Gu wrote:
>>> +    clc = (struct smc_clc_msg_accept_confirm *)clc_v2;
>>
>> Why is this cast neccessary? (Here as well as in smcr_clc_prep_confirm_accept
>> and in smc_clc_send_confirm_accept)
>> smc_clc_msg_accept_confirm_v2 has hdr and d0 as well.
> 
> I think the cast is to imply that v2 is an expansion of v1, or v1 is the base of v2.
> So here using clc(v1) reperesents their common set.
> 
> If we use smc_clc_msg_accept_confirm_v2 for all, I think readers may be tempted to
> check whether the hdr and d0 in 'smc_clc_msg_accept_confirm_v2' are also applicable to v1.
> 
> And there are settings below that are specific for v1. It may be confusing if we
> change it like this:
> 
> if (version == SMC_V1) {
>     clc_v2->hdr.length = htons(SMCD_CLC_ACCEPT_CONFIRM_LEN);
> } else {
> 
> 
>>
>> IMO, it would be a nice seperate patch to get rid of the 2 type defs for
>> smc_clc_msg_accept_confirm and smc_clc_msg_accept_confirm_v2
>> and all the related casting anyhow.
>>
> 
> Do you mean to define only smc_clc_msg_accept_confirm_v2 or define with the name
> of smc_clc_msg_accept_confirm but the contents of smc_clc_msg_accept_confirm_v2?
> 
> I have a different opinion on this, since I think the smc_clc_msg_accept_confirm
> and smc_clc_msg_accept_confirm_v2 clearly shows the difference between v1 and
> v2 messages and remind people what is currently working on. So I perfer to keep them.
> Am I missing something?
> 


This is a discussion about coding style, readability and maintainability (avoid future errors).
And the code works today and the rest is opinions. That said, let me list some arguments why
I don't like the casts.

Casts in general break the type checking of the compiler.

In some places e.g. clc.d0 points to struct smc_clc_msg_accept_confirm in other
places it points to struct smc_clc_msg_accept_confirm_v2.
This makes it hard to find all places where e.g. d0 is altered. (e.g. with an IDE).

You say: "smc_clc_msg_accept_confirm
> and smc_clc_msg_accept_confirm_v2 clearly shows the difference between v1 and
> v2 messages"
But that is not even the case in the code that this patch changes:
In smcd_clc_prep_confirm_accept() you pass a struct smc_clc_msg_accept_confirm_v2
cast it to v1 (even in the v2 case) and then use the v1 layout for the common fields and
the v1-only fields. So I don't think that helps very much.

The v2 messages were explicitely defined for compatibility. i.e.
all v1 fields are still available. It would be good to see that in the code as well.
With 2 differnet structs you don't emphasize that.

With future changes somebody could easily make a mistake that the 2 structures don't 
have the same size anymore. And then the casting can lead to out-of-bound error that
are hard to find.

We want v2 to be the usual case and v1 to be the exception for backwards compatibility.
FOr historic reasons, the code looks as if v2 is the exception. I'd rather point out the 
remaining v1 cases.



I could envision something like:

struct smc_clc_msg_accept_confirm {	/* clc accept / confirm message */
	struct smc_clc_msg_hdr hdr;
	union {
		struct { /* SMC-R */
			struct smcr_clc_msg_accept_confirm r0;
			/* v2 only, reserved and ignored in v1: */
			u8 eid[SMC_MAX_EID_LEN];
			u8 reserved6[8];
		} r1;
		struct { /* SMC-D */
			struct smcd_clc_msg_accept_confirm_common d0;
			/* v2 only, reserved and ignored in v1: */
			__be16 chid;
			u8 eid[SMC_MAX_EID_LEN];
			__be64 gid_ext;
		} __packed d1;
	};
};

And then only use this one structure.









  reply	other threads:[~2023-12-11 13:35 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-08  7:40 [PATCH net-next v5 0/9] net/smc: implement SMCv2.1 virtual ISM device support Wen Gu
2023-12-08  7:40 ` [PATCH net-next v5 1/9] net/smc: rename some 'fce' to 'fce_v2x' for clarity Wen Gu
2023-12-08  7:40 ` [PATCH net-next v5 2/9] net/smc: introduce sub-functions for smc_clc_send_confirm_accept() Wen Gu
2023-12-09  2:50   ` Wen Gu
2023-12-11  9:47     ` Alexandra Winter
2023-12-11 10:57       ` Wen Gu
2023-12-11 10:43   ` Alexandra Winter
2023-12-11 12:15     ` Wen Gu
2023-12-11 13:35       ` Alexandra Winter [this message]
2023-12-11 15:23         ` Wen Gu
2023-12-08  7:40 ` [PATCH net-next v5 3/9] net/smc: support SMCv2.x supplemental features negotiation Wen Gu
2023-12-08  7:40 ` [PATCH net-next v5 4/9] net/smc: introduce virtual ISM device support feature Wen Gu
2023-12-08  7:40 ` [PATCH net-next v5 5/9] net/smc: define a reserved CHID range for virtual ISM devices Wen Gu
2023-12-11  8:24   ` Alexandra Winter
2023-12-11  8:41     ` Wen Gu
2023-12-08  7:40 ` [PATCH net-next v5 6/9] net/smc: compatible with 128-bits extended GID of virtual ISM device Wen Gu
2023-12-11 11:37   ` Alexandra Winter
2023-12-08  7:40 ` [PATCH net-next v5 7/9] net/smc: support extended GID in SMC-D lgr netlink attribute Wen Gu
2023-12-11  9:39   ` Alexandra Winter
2023-12-11 10:09     ` Wen Gu
2023-12-11 11:50       ` Alexandra Winter
2023-12-08  7:40 ` [PATCH net-next v5 8/9] net/smc: disable SEID on non-s390 archs where virtual ISM may be used Wen Gu
2023-12-08  7:40 ` [PATCH net-next v5 9/9] net/smc: manage system EID in SMC stack instead of ISM driver Wen Gu
2023-12-11  8:29   ` Alexandra Winter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=fb2365f6-1237-4f22-9897-5676757e5157@linux.ibm.com \
    --to=wintera@linux.ibm.com \
    --cc=agordeev@linux.ibm.com \
    --cc=alibuda@linux.alibaba.com \
    --cc=borntraeger@linux.ibm.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=gor@linux.ibm.com \
    --cc=guangguan.wang@linux.alibaba.com \
    --cc=guwen@linux.alibaba.com \
    --cc=hca@linux.ibm.com \
    --cc=jaka@linux.ibm.com \
    --cc=kgraul@linux.ibm.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=raspl@linux.ibm.com \
    --cc=schnelle@linux.ibm.com \
    --cc=svens@linux.ibm.com \
    --cc=tonylu@linux.alibaba.com \
    --cc=wenjia@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox