Patch "RDMA/hns: Work around broken constant propagation in gcc 8" has been added to the 5.14-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    RDMA/hns: Work around broken constant propagation in gcc 8

to the 5.14-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     rdma-hns-work-around-broken-constant-propagation-in-.patch
and it can be found in the queue-5.14 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit b6e015e5f621c8736dd9f2f163242d614eef85ff
Author: Jason Gunthorpe <jgg@xxxxxxxxxx>
Date:   Thu Sep 16 12:05:28 2021 -0300

    RDMA/hns: Work around broken constant propagation in gcc 8
    
    [ Upstream commit 14351f08ed5c8b888cdd95651152db7e096ee27f ]
    
    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")
    Link: https://lore.kernel.org/r/0-v1-c773ecb137bc+11f-hns_gcc8_jgg@xxxxxxxxxx
    Reported-by: Geert Uytterhoeven <geert@xxxxxxxxxxxxxx>
    Signed-off-by: Jason Gunthorpe <jgg@xxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/drivers/infiniband/hw/hns/hns_roce_hw_v2.c b/drivers/infiniband/hw/hns/hns_roce_hw_v2.c
index c320891c8763..6cb4a4e10837 100644
--- a/drivers/infiniband/hw/hns/hns_roce_hw_v2.c
+++ b/drivers/infiniband/hw/hns/hns_roce_hw_v2.c
@@ -4411,7 +4411,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) {
@@ -4419,10 +4424,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);
 



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux