Message ID | 1607078436-26455-6-git-send-email-liweihang@huawei.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | RDMA/hns: Updates for 5.11 | expand |
On Fri, Dec 04, 2020 at 06:40:30PM +0800, Weihang Li wrote: > According to the RoCE v1 specification, the sl (service level) 0-7 are > mapped directly to priorities 0-7 respectively, sl 8-15 are reserved. The > driver should verify whether the value of sl is larger than 7, if so, an > exception should be returned. > > Fixes: 172505cfa3a8 ("RDMA/hns: Add check for the validity of sl configuration") > Fixes: d6a3627e311c ("RDMA/hns: Optimize wqe buffer set flow for post send") > Signed-off-by: Weihang Li <liweihang@huawei.com> > --- > drivers/infiniband/hw/hns/hns_roce_hw_v2.c | 10 +++++----- > 1 file changed, 5 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 7a0c1ab..15e1313 100644 > --- a/drivers/infiniband/hw/hns/hns_roce_hw_v2.c > +++ b/drivers/infiniband/hw/hns/hns_roce_hw_v2.c > @@ -433,6 +433,10 @@ static int fill_ud_av(struct hns_roce_v2_ud_send_wqe *ud_sq_wqe, > V2_UD_SEND_WQE_BYTE_36_TCLASS_S, ah->av.tclass); > roce_set_field(ud_sq_wqe->byte_40, V2_UD_SEND_WQE_BYTE_40_FLOW_LABEL_M, > V2_UD_SEND_WQE_BYTE_40_FLOW_LABEL_S, ah->av.flowlabel); > + > + if (WARN_ON(ah->av.sl > MAX_SERVICE_LEVEL)) > + return -EINVAL; > + > roce_set_field(ud_sq_wqe->byte_40, V2_UD_SEND_WQE_BYTE_40_SL_M, > V2_UD_SEND_WQE_BYTE_40_SL_S, ah->av.sl); > > @@ -4609,12 +4613,8 @@ static int hns_roce_v2_set_path(struct ib_qp *ibqp, > memset(qpc_mask->dgid, 0, sizeof(grh->dgid.raw)); > > hr_qp->sl = rdma_ah_get_sl(&attr->ah_attr); > - if (unlikely(hr_qp->sl > MAX_SERVICE_LEVEL)) { > - ibdev_err(ibdev, > - "failed to fill QPC, sl (%d) shouldn't be larger than %d.\n", > - hr_qp->sl, MAX_SERVICE_LEVEL); > + if (WARN_ON(hr_qp->sl > MAX_SERVICE_LEVEL)) > return -EINVAL; > - } > > roce_set_field(context->byte_28_at_fl, V2_QPC_BYTE_28_SL_M, > V2_QPC_BYTE_28_SL_S, hr_qp->sl); Can any of these warn_on's be triggered by user space? That would not be OK Jason
On 2020/12/10 5:09, Jason Gunthorpe wrote: > On Fri, Dec 04, 2020 at 06:40:30PM +0800, Weihang Li wrote: >> According to the RoCE v1 specification, the sl (service level) 0-7 are >> mapped directly to priorities 0-7 respectively, sl 8-15 are reserved. The >> driver should verify whether the value of sl is larger than 7, if so, an >> exception should be returned. >> >> Fixes: 172505cfa3a8 ("RDMA/hns: Add check for the validity of sl configuration") >> Fixes: d6a3627e311c ("RDMA/hns: Optimize wqe buffer set flow for post send") >> Signed-off-by: Weihang Li <liweihang@huawei.com> >> --- >> drivers/infiniband/hw/hns/hns_roce_hw_v2.c | 10 +++++----- >> 1 file changed, 5 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 7a0c1ab..15e1313 100644 >> --- a/drivers/infiniband/hw/hns/hns_roce_hw_v2.c >> +++ b/drivers/infiniband/hw/hns/hns_roce_hw_v2.c >> @@ -433,6 +433,10 @@ static int fill_ud_av(struct hns_roce_v2_ud_send_wqe *ud_sq_wqe, >> V2_UD_SEND_WQE_BYTE_36_TCLASS_S, ah->av.tclass); >> roce_set_field(ud_sq_wqe->byte_40, V2_UD_SEND_WQE_BYTE_40_FLOW_LABEL_M, >> V2_UD_SEND_WQE_BYTE_40_FLOW_LABEL_S, ah->av.flowlabel); >> + >> + if (WARN_ON(ah->av.sl > MAX_SERVICE_LEVEL)) >> + return -EINVAL; >> + >> roce_set_field(ud_sq_wqe->byte_40, V2_UD_SEND_WQE_BYTE_40_SL_M, >> V2_UD_SEND_WQE_BYTE_40_SL_S, ah->av.sl); >> >> @@ -4609,12 +4613,8 @@ static int hns_roce_v2_set_path(struct ib_qp *ibqp, >> memset(qpc_mask->dgid, 0, sizeof(grh->dgid.raw)); >> >> hr_qp->sl = rdma_ah_get_sl(&attr->ah_attr); >> - if (unlikely(hr_qp->sl > MAX_SERVICE_LEVEL)) { >> - ibdev_err(ibdev, >> - "failed to fill QPC, sl (%d) shouldn't be larger than %d.\n", >> - hr_qp->sl, MAX_SERVICE_LEVEL); >> + if (WARN_ON(hr_qp->sl > MAX_SERVICE_LEVEL)) >> return -EINVAL; >> - } >> >> roce_set_field(context->byte_28_at_fl, V2_QPC_BYTE_28_SL_M, >> V2_QPC_BYTE_28_SL_S, hr_qp->sl); > > Can any of these warn_on's be triggered by user space? That would not > be OK > > Jason > Hi Jason, Thanks for your comments, I understand that error that can be triggered by userspace shouldn't use WARN_ON(). So I shouldn't use WARN_ON() in hns_roce_v2_set_path(). As for the error in process of post_send, you suggested me to warn_on if a kernel user try to pass in an illegal opcode. So I guess I should use WARN_ON() too in sl's check when filling a UD WQE. Am I right? Weihang
On Thu, Dec 10, 2020 at 04:00:16AM +0000, liweihang wrote: > On 2020/12/10 5:09, Jason Gunthorpe wrote: > > On Fri, Dec 04, 2020 at 06:40:30PM +0800, Weihang Li wrote: > >> According to the RoCE v1 specification, the sl (service level) 0-7 are > >> mapped directly to priorities 0-7 respectively, sl 8-15 are reserved. The > >> driver should verify whether the value of sl is larger than 7, if so, an > >> exception should be returned. > >> > >> Fixes: 172505cfa3a8 ("RDMA/hns: Add check for the validity of sl configuration") > >> Fixes: d6a3627e311c ("RDMA/hns: Optimize wqe buffer set flow for post send") > >> Signed-off-by: Weihang Li <liweihang@huawei.com> > >> drivers/infiniband/hw/hns/hns_roce_hw_v2.c | 10 +++++----- > >> 1 file changed, 5 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 7a0c1ab..15e1313 100644 > >> +++ b/drivers/infiniband/hw/hns/hns_roce_hw_v2.c > >> @@ -433,6 +433,10 @@ static int fill_ud_av(struct hns_roce_v2_ud_send_wqe *ud_sq_wqe, > >> V2_UD_SEND_WQE_BYTE_36_TCLASS_S, ah->av.tclass); > >> roce_set_field(ud_sq_wqe->byte_40, V2_UD_SEND_WQE_BYTE_40_FLOW_LABEL_M, > >> V2_UD_SEND_WQE_BYTE_40_FLOW_LABEL_S, ah->av.flowlabel); > >> + > >> + if (WARN_ON(ah->av.sl > MAX_SERVICE_LEVEL)) > >> + return -EINVAL; > >> + > >> roce_set_field(ud_sq_wqe->byte_40, V2_UD_SEND_WQE_BYTE_40_SL_M, > >> V2_UD_SEND_WQE_BYTE_40_SL_S, ah->av.sl); > >> > >> @@ -4609,12 +4613,8 @@ static int hns_roce_v2_set_path(struct ib_qp *ibqp, > >> memset(qpc_mask->dgid, 0, sizeof(grh->dgid.raw)); > >> > >> hr_qp->sl = rdma_ah_get_sl(&attr->ah_attr); > >> - if (unlikely(hr_qp->sl > MAX_SERVICE_LEVEL)) { > >> - ibdev_err(ibdev, > >> - "failed to fill QPC, sl (%d) shouldn't be larger than %d.\n", > >> - hr_qp->sl, MAX_SERVICE_LEVEL); > >> + if (WARN_ON(hr_qp->sl > MAX_SERVICE_LEVEL)) > >> return -EINVAL; > >> - } > >> > >> roce_set_field(context->byte_28_at_fl, V2_QPC_BYTE_28_SL_M, > >> V2_QPC_BYTE_28_SL_S, hr_qp->sl); > > > > Can any of these warn_on's be triggered by user space? That would not > > be OK > > > > Jason > > > > Hi Jason, > > Thanks for your comments, I understand that error that can be triggered by > userspace shouldn't use WARN_ON(). So I shouldn't use WARN_ON() in > hns_roce_v2_set_path(). > > As for the error in process of post_send, you suggested me to warn_on if > a kernel user try to pass in an illegal opcode. So I guess I should use > WARN_ON() too in sl's check when filling a UD WQE. Am I right? Userspace should not be able to trigger warn_on Bad kernel ULPs are OK to trigger warn_on Jason
On 2020/12/10 21:45, Jason Gunthorpe wrote: > On Thu, Dec 10, 2020 at 04:00:16AM +0000, liweihang wrote: >> On 2020/12/10 5:09, Jason Gunthorpe wrote: >>> On Fri, Dec 04, 2020 at 06:40:30PM +0800, Weihang Li wrote: >>>> According to the RoCE v1 specification, the sl (service level) 0-7 are >>>> mapped directly to priorities 0-7 respectively, sl 8-15 are reserved. The >>>> driver should verify whether the value of sl is larger than 7, if so, an >>>> exception should be returned. >>>> >>>> Fixes: 172505cfa3a8 ("RDMA/hns: Add check for the validity of sl configuration") >>>> Fixes: d6a3627e311c ("RDMA/hns: Optimize wqe buffer set flow for post send") >>>> Signed-off-by: Weihang Li <liweihang@huawei.com> >>>> drivers/infiniband/hw/hns/hns_roce_hw_v2.c | 10 +++++----- >>>> 1 file changed, 5 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 7a0c1ab..15e1313 100644 >>>> +++ b/drivers/infiniband/hw/hns/hns_roce_hw_v2.c >>>> @@ -433,6 +433,10 @@ static int fill_ud_av(struct hns_roce_v2_ud_send_wqe *ud_sq_wqe, >>>> V2_UD_SEND_WQE_BYTE_36_TCLASS_S, ah->av.tclass); >>>> roce_set_field(ud_sq_wqe->byte_40, V2_UD_SEND_WQE_BYTE_40_FLOW_LABEL_M, >>>> V2_UD_SEND_WQE_BYTE_40_FLOW_LABEL_S, ah->av.flowlabel); >>>> + >>>> + if (WARN_ON(ah->av.sl > MAX_SERVICE_LEVEL)) >>>> + return -EINVAL; >>>> + >>>> roce_set_field(ud_sq_wqe->byte_40, V2_UD_SEND_WQE_BYTE_40_SL_M, >>>> V2_UD_SEND_WQE_BYTE_40_SL_S, ah->av.sl); >>>> >>>> @@ -4609,12 +4613,8 @@ static int hns_roce_v2_set_path(struct ib_qp *ibqp, >>>> memset(qpc_mask->dgid, 0, sizeof(grh->dgid.raw)); >>>> >>>> hr_qp->sl = rdma_ah_get_sl(&attr->ah_attr); >>>> - if (unlikely(hr_qp->sl > MAX_SERVICE_LEVEL)) { >>>> - ibdev_err(ibdev, >>>> - "failed to fill QPC, sl (%d) shouldn't be larger than %d.\n", >>>> - hr_qp->sl, MAX_SERVICE_LEVEL); >>>> + if (WARN_ON(hr_qp->sl > MAX_SERVICE_LEVEL)) >>>> return -EINVAL; >>>> - } >>>> >>>> roce_set_field(context->byte_28_at_fl, V2_QPC_BYTE_28_SL_M, >>>> V2_QPC_BYTE_28_SL_S, hr_qp->sl); >>> >>> Can any of these warn_on's be triggered by user space? That would not >>> be OK >>> >>> Jason >>> >> >> Hi Jason, >> >> Thanks for your comments, I understand that error that can be triggered by >> userspace shouldn't use WARN_ON(). So I shouldn't use WARN_ON() in >> hns_roce_v2_set_path(). >> >> As for the error in process of post_send, you suggested me to warn_on if >> a kernel user try to pass in an illegal opcode. So I guess I should use >> WARN_ON() too in sl's check when filling a UD WQE. Am I right? > > Userspace should not be able to trigger warn_on > > Bad kernel ULPs are OK to trigger warn_on > > Jason > I see, Thank you. Weihang
diff --git a/drivers/infiniband/hw/hns/hns_roce_hw_v2.c b/drivers/infiniband/hw/hns/hns_roce_hw_v2.c index 7a0c1ab..15e1313 100644 --- a/drivers/infiniband/hw/hns/hns_roce_hw_v2.c +++ b/drivers/infiniband/hw/hns/hns_roce_hw_v2.c @@ -433,6 +433,10 @@ static int fill_ud_av(struct hns_roce_v2_ud_send_wqe *ud_sq_wqe, V2_UD_SEND_WQE_BYTE_36_TCLASS_S, ah->av.tclass); roce_set_field(ud_sq_wqe->byte_40, V2_UD_SEND_WQE_BYTE_40_FLOW_LABEL_M, V2_UD_SEND_WQE_BYTE_40_FLOW_LABEL_S, ah->av.flowlabel); + + if (WARN_ON(ah->av.sl > MAX_SERVICE_LEVEL)) + return -EINVAL; + roce_set_field(ud_sq_wqe->byte_40, V2_UD_SEND_WQE_BYTE_40_SL_M, V2_UD_SEND_WQE_BYTE_40_SL_S, ah->av.sl); @@ -4609,12 +4613,8 @@ static int hns_roce_v2_set_path(struct ib_qp *ibqp, memset(qpc_mask->dgid, 0, sizeof(grh->dgid.raw)); hr_qp->sl = rdma_ah_get_sl(&attr->ah_attr); - if (unlikely(hr_qp->sl > MAX_SERVICE_LEVEL)) { - ibdev_err(ibdev, - "failed to fill QPC, sl (%d) shouldn't be larger than %d.\n", - hr_qp->sl, MAX_SERVICE_LEVEL); + if (WARN_ON(hr_qp->sl > MAX_SERVICE_LEVEL)) return -EINVAL; - } roce_set_field(context->byte_28_at_fl, V2_QPC_BYTE_28_SL_M, V2_QPC_BYTE_28_SL_S, hr_qp->sl);
According to the RoCE v1 specification, the sl (service level) 0-7 are mapped directly to priorities 0-7 respectively, sl 8-15 are reserved. The driver should verify whether the value of sl is larger than 7, if so, an exception should be returned. Fixes: 172505cfa3a8 ("RDMA/hns: Add check for the validity of sl configuration") Fixes: d6a3627e311c ("RDMA/hns: Optimize wqe buffer set flow for post send") Signed-off-by: Weihang Li <liweihang@huawei.com> --- drivers/infiniband/hw/hns/hns_roce_hw_v2.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)