linux-rdma.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] RDMA/hns: Work around broken constant propogation in gcc 8
@ 2021-09-16 15:05 Jason Gunthorpe
  2021-09-24  8:39 ` Wenpeng Liang
  2021-09-24 12:28 ` Jason Gunthorpe
  0 siblings, 2 replies; 3+ messages in thread
From: Jason Gunthorpe @ 2021-09-16 15:05 UTC (permalink / raw)
  To: Wenpeng Liang, linux-rdma; +Cc: Lang Cheng, Geert Uytterhoeven, Weihang Li

gcc 8.3 and 5.4 throw this:

In function 'modify_qp_init_to_rtr',
././include/linux/compiler_types.h:322:38: error: call to '__compiletime_assert_1859' declared with attribute error: FIELD_PREP: value too large for the field
  _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
[..]
drivers/infiniband/hw/hns/hns_roce_common.h:91:52: note: in expansion of macro 'FIELD_PREP'
   *((__le32 *)ptr + (field_h) / 32) |= cpu_to_le32(FIELD_PREP(   \
                                                    ^~~~~~~~~~
drivers/infiniband/hw/hns/hns_roce_common.h:95:39: note: in expansion of macro '_hr_reg_write'
 #define hr_reg_write(ptr, field, val) _hr_reg_write(ptr, field, val)
                                       ^~~~~~~~~~~~~
drivers/infiniband/hw/hns/hns_roce_hw_v2.c:4412:2: note: in expansion of macro 'hr_reg_write'
  hr_reg_write(context, QPC_LP_PKTN_INI, lp_pktn_ini);

Because gcc has miscalculated the constantness of lp_pktn_ini:

	mtu = ib_mtu_enum_to_int(ib_mtu);
	if (WARN_ON(mtu < 0)) [..]
	lp_pktn_ini = ilog2(MAX_LP_MSG_LEN / mtu);

Since mtu is limited to {256,512,1024,2048,4096} lp_pktn_ini is between 4
and 8 which is compatible with the 4 bit field in the FIELD_PREP.

Work around this broken compiler by adding a 'can never be true'
constraint on lp_pktn_ini's value which clears out the problem.

Fixes: f0cb411aad23 ("RDMA/hns: Use new interface to modify QP context")
Reported-by: Geert Uytterhoeven <geert@linux-m68k.org>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
 drivers/infiniband/hw/hns/hns_roce_hw_v2.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/infiniband/hw/hns/hns_roce_hw_v2.c b/drivers/infiniband/hw/hns/hns_roce_hw_v2.c
index 5b9953105752c3..a9c00a2e8ebdbb 100644
--- a/drivers/infiniband/hw/hns/hns_roce_hw_v2.c
+++ b/drivers/infiniband/hw/hns/hns_roce_hw_v2.c
@@ -4397,7 +4397,12 @@ static int modify_qp_init_to_rtr(struct ib_qp *ibqp,
 	hr_qp->path_mtu = ib_mtu;
 
 	mtu = ib_mtu_enum_to_int(ib_mtu);
-	if (WARN_ON(mtu < 0))
+	if (WARN_ON(mtu <= 0))
+		return -EINVAL;
+#define MAX_LP_MSG_LEN 65536
+	/* MTU * (2 ^ LP_PKTN_INI) shouldn't be bigger than 64KB */
+	lp_pktn_ini = ilog2(MAX_LP_MSG_LEN / mtu);
+	if (WARN_ON(lp_pktn_ini >= 0xF))
 		return -EINVAL;
 
 	if (attr_mask & IB_QP_PATH_MTU) {
@@ -4405,10 +4410,6 @@ static int modify_qp_init_to_rtr(struct ib_qp *ibqp,
 		hr_reg_clear(qpc_mask, QPC_MTU);
 	}
 
-#define MAX_LP_MSG_LEN 65536
-	/* MTU * (2 ^ LP_PKTN_INI) shouldn't be bigger than 64KB */
-	lp_pktn_ini = ilog2(MAX_LP_MSG_LEN / mtu);
-
 	hr_reg_write(context, QPC_LP_PKTN_INI, lp_pktn_ini);
 	hr_reg_clear(qpc_mask, QPC_LP_PKTN_INI);
 

base-commit: ad17bbef3dd573da937816edc0ab84fed6a17fa6
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] RDMA/hns: Work around broken constant propogation in gcc 8
  2021-09-16 15:05 [PATCH] RDMA/hns: Work around broken constant propogation in gcc 8 Jason Gunthorpe
@ 2021-09-24  8:39 ` Wenpeng Liang
  2021-09-24 12:28 ` Jason Gunthorpe
  1 sibling, 0 replies; 3+ messages in thread
From: Wenpeng Liang @ 2021-09-24  8:39 UTC (permalink / raw)
  To: Jason Gunthorpe, linux-rdma; +Cc: Lang Cheng, Geert Uytterhoeven, Weihang Li

On 2021/9/16 23:05, Jason Gunthorpe wrote:
> gcc 8.3 and 5.4 throw this:
> 
> In function 'modify_qp_init_to_rtr',
> ././include/linux/compiler_types.h:322:38: error: call to '__compiletime_assert_1859' declared with attribute error: FIELD_PREP: value too large for the field
>   _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
> [..]
> drivers/infiniband/hw/hns/hns_roce_common.h:91:52: note: in expansion of macro 'FIELD_PREP'
>    *((__le32 *)ptr + (field_h) / 32) |= cpu_to_le32(FIELD_PREP(   \
>                                                     ^~~~~~~~~~
> drivers/infiniband/hw/hns/hns_roce_common.h:95:39: note: in expansion of macro '_hr_reg_write'
>  #define hr_reg_write(ptr, field, val) _hr_reg_write(ptr, field, val)
>                                        ^~~~~~~~~~~~~
> drivers/infiniband/hw/hns/hns_roce_hw_v2.c:4412:2: note: in expansion of macro 'hr_reg_write'
>   hr_reg_write(context, QPC_LP_PKTN_INI, lp_pktn_ini);
> 
> Because gcc has miscalculated the constantness of lp_pktn_ini:
> 
> 	mtu = ib_mtu_enum_to_int(ib_mtu);
> 	if (WARN_ON(mtu < 0)) [..]
> 	lp_pktn_ini = ilog2(MAX_LP_MSG_LEN / mtu);
> 
> Since mtu is limited to {256,512,1024,2048,4096} lp_pktn_ini is between 4
> and 8 which is compatible with the 4 bit field in the FIELD_PREP.
> 
> Work around this broken compiler by adding a 'can never be true'
> constraint on lp_pktn_ini's value which clears out the problem.
> 
> Fixes: f0cb411aad23 ("RDMA/hns: Use new interface to modify QP context")
> Reported-by: Geert Uytterhoeven <geert@linux-m68k.org>
> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
> ---
>  drivers/infiniband/hw/hns/hns_roce_hw_v2.c | 11 ++++++-----
>  1 file changed, 6 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/infiniband/hw/hns/hns_roce_hw_v2.c b/drivers/infiniband/hw/hns/hns_roce_hw_v2.c
> index 5b9953105752c3..a9c00a2e8ebdbb 100644
> --- a/drivers/infiniband/hw/hns/hns_roce_hw_v2.c
> +++ b/drivers/infiniband/hw/hns/hns_roce_hw_v2.c
> @@ -4397,7 +4397,12 @@ static int modify_qp_init_to_rtr(struct ib_qp *ibqp,
>  	hr_qp->path_mtu = ib_mtu;
>  
>  	mtu = ib_mtu_enum_to_int(ib_mtu);
> -	if (WARN_ON(mtu < 0))
> +	if (WARN_ON(mtu <= 0))
> +		return -EINVAL;
> +#define MAX_LP_MSG_LEN 65536
> +	/* MTU * (2 ^ LP_PKTN_INI) shouldn't be bigger than 64KB */
> +	lp_pktn_ini = ilog2(MAX_LP_MSG_LEN / mtu);
> +	if (WARN_ON(lp_pktn_ini >= 0xF))
>  		return -EINVAL;
>  
>  	if (attr_mask & IB_QP_PATH_MTU) {
> @@ -4405,10 +4410,6 @@ static int modify_qp_init_to_rtr(struct ib_qp *ibqp,
>  		hr_reg_clear(qpc_mask, QPC_MTU);
>  	}
>  
> -#define MAX_LP_MSG_LEN 65536
> -	/* MTU * (2 ^ LP_PKTN_INI) shouldn't be bigger than 64KB */
> -	lp_pktn_ini = ilog2(MAX_LP_MSG_LEN / mtu);
> -
>  	hr_reg_write(context, QPC_LP_PKTN_INI, lp_pktn_ini);
>  	hr_reg_clear(qpc_mask, QPC_LP_PKTN_INI);
>  
> 
> base-commit: ad17bbef3dd573da937816edc0ab84fed6a17fa6
> 
Hi, Jason,

Sorry for the late reply,
It seems okay to me, thanks!

Wengpeng


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] RDMA/hns: Work around broken constant propogation in gcc 8
  2021-09-16 15:05 [PATCH] RDMA/hns: Work around broken constant propogation in gcc 8 Jason Gunthorpe
  2021-09-24  8:39 ` Wenpeng Liang
@ 2021-09-24 12:28 ` Jason Gunthorpe
  1 sibling, 0 replies; 3+ messages in thread
From: Jason Gunthorpe @ 2021-09-24 12:28 UTC (permalink / raw)
  To: Wenpeng Liang, linux-rdma; +Cc: Lang Cheng, Geert Uytterhoeven, Weihang Li

On Thu, Sep 16, 2021 at 12:05:28PM -0300, Jason Gunthorpe wrote:
> gcc 8.3 and 5.4 throw this:
> 
> In function 'modify_qp_init_to_rtr',
> ././include/linux/compiler_types.h:322:38: error: call to '__compiletime_assert_1859' declared with attribute error: FIELD_PREP: value too large for the field
>   _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
> [..]
> drivers/infiniband/hw/hns/hns_roce_common.h:91:52: note: in expansion of macro 'FIELD_PREP'
>    *((__le32 *)ptr + (field_h) / 32) |= cpu_to_le32(FIELD_PREP(   \
>                                                     ^~~~~~~~~~
> drivers/infiniband/hw/hns/hns_roce_common.h:95:39: note: in expansion of macro '_hr_reg_write'
>  #define hr_reg_write(ptr, field, val) _hr_reg_write(ptr, field, val)
>                                        ^~~~~~~~~~~~~
> drivers/infiniband/hw/hns/hns_roce_hw_v2.c:4412:2: note: in expansion of macro 'hr_reg_write'
>   hr_reg_write(context, QPC_LP_PKTN_INI, lp_pktn_ini);
> 
> Because gcc has miscalculated the constantness of lp_pktn_ini:
> 
> 	mtu = ib_mtu_enum_to_int(ib_mtu);
> 	if (WARN_ON(mtu < 0)) [..]
> 	lp_pktn_ini = ilog2(MAX_LP_MSG_LEN / mtu);
> 
> Since mtu is limited to {256,512,1024,2048,4096} lp_pktn_ini is between 4
> and 8 which is compatible with the 4 bit field in the FIELD_PREP.
> 
> Work around this broken compiler by adding a 'can never be true'
> constraint on lp_pktn_ini's value which clears out the problem.
> 
> Fixes: f0cb411aad23 ("RDMA/hns: Use new interface to modify QP context")
> Reported-by: Geert Uytterhoeven <geert@linux-m68k.org>
> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
> ---
>  drivers/infiniband/hw/hns/hns_roce_hw_v2.c | 11 ++++++-----
>  1 file changed, 6 insertions(+), 5 deletions(-)

Applied to for-rc

Jason

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-09-24 12:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-16 15:05 [PATCH] RDMA/hns: Work around broken constant propogation in gcc 8 Jason Gunthorpe
2021-09-24  8:39 ` Wenpeng Liang
2021-09-24 12:28 ` Jason Gunthorpe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).