This patch changes the type of cqn from u32 to u64 to keep userspace and kernel consistent, initializes resp both for cq and qp to zeros, and also changes the condition judgment of outlen considering future caps extension.
Unified · Split
| @@ -315,7 +315,7 @@ struct ib_cq *hns_roce_ib_create_cq(struct ib_device *ib_dev, · 314 unmodified lines | ||
| 315 | 315 | struct hns_roce_dev *hr_dev = to_hr_dev(ib_dev); |
| 316 | 316 | struct device *dev = hr_dev->dev; |
| 317 | 317 | struct hns_roce_ib_create_cq ucmd; |
| 318 | − struct hns_roce_ib_create_cq_resp resp; | |
| 318 | + struct hns_roce_ib_create_cq_resp resp = {}; | |
| 319 | 319 | struct hns_roce_cq *hr_cq = NULL; |
| 320 | 320 | struct hns_roce_uar *uar = NULL; |
| 321 | 321 | int vector = attr->comp_vector; |
| @@ -389,7 +389,7 @@ struct ib_cq *hns_roce_ib_create_cq(struct ib_device *ib_dev, · 67 unmodified lines | ||
| 389 | 389 | } |
| 390 | 390 | |
| 391 | 391 | if (context && (hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_RECORD_DB) && |
| 392 | − (udata->outlen == sizeof(resp))) { | |
| 392 | + (udata->outlen >= sizeof(resp))) { | |
| 393 | 393 | ret = hns_roce_db_map_user(to_hr_ucontext(context), |
| 394 | 394 | ucmd.db_addr, &hr_cq->db); |
| 395 | 395 | if (ret) { |
| @@ -413,15 +413,14 @@ struct ib_cq *hns_roce_ib_create_cq(struct ib_device *ib_dev, · 17 unmodified lines | ||
| 413 | 413 | hr_cq->cq_depth = cq_entries; |
| 414 | 414 | |
| 415 | 415 | if (context) { |
| 416 | + resp.cqn = hr_cq->cqn; | |
| 416 | 417 | if ((hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_RECORD_DB) && |
| 417 | − (udata->outlen == sizeof(resp))) { | |
| 418 | + (udata->outlen >= sizeof(resp))) { | |
| 418 | 419 | hr_cq->db_en = 1; |
| 419 | − resp.cqn = hr_cq->cqn; | |
| 420 | 420 | resp.cap_flags |= HNS_ROCE_SUPPORT_CQ_RECORD_DB; |
| 421 | − ret = ib_copy_to_udata(udata, &resp, sizeof(resp)); | |
| 422 | − } else | |
| 423 | − ret = ib_copy_to_udata(udata, &hr_cq->cqn, sizeof(u64)); | |
| 421 | + } | |
| 424 | 422 | |
| 423 | + ret = ib_copy_to_udata(udata, &resp, sizeof(resp)); | |
| 425 | 424 | if (ret) |
| 426 | 425 | goto err_dbmap; |
| 427 | 426 | } |
| @@ -430,7 +429,7 @@ struct ib_cq *hns_roce_ib_create_cq(struct ib_device *ib_dev, · 2 unmodified lines | ||
| 430 | 429 | |
| 431 | 430 | err_dbmap: |
| 432 | 431 | if (context && (hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_RECORD_DB) && |
| 433 | − (udata->outlen == sizeof(resp))) | |
| 432 | + (udata->outlen >= sizeof(resp))) | |
| 434 | 433 | hns_roce_db_unmap_user(to_hr_ucontext(context), |
| 435 | 434 | &hr_cq->db); |
| 436 | 435 | |
| @@ -506,7 +506,7 @@ static int hns_roce_create_qp_common(struct hns_roce_dev *hr_dev, · 505 unmodified lines | ||
| 506 | 506 | { |
| 507 | 507 | struct device *dev = hr_dev->dev; |
| 508 | 508 | struct hns_roce_ib_create_qp ucmd; |
| 509 | − struct hns_roce_ib_create_qp_resp resp; | |
| 509 | + struct hns_roce_ib_create_qp_resp resp = {}; | |
| 510 | 510 | unsigned long qpn = 0; |
| 511 | 511 | int ret = 0; |
| 512 | 512 | u32 page_shift; |
| @@ -614,7 +614,7 @@ static int hns_roce_create_qp_common(struct hns_roce_dev *hr_dev, · 101 unmodified lines | ||
| 614 | 614 | } |
| 615 | 615 | |
| 616 | 616 | if ((hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_RECORD_DB) && |
| 617 | − (udata->outlen == sizeof(resp)) && | |
| 617 | + (udata->outlen >= sizeof(resp)) && | |
| 618 | 618 | hns_roce_qp_has_rq(init_attr)) { |
| 619 | 619 | ret = hns_roce_db_map_user( |
| 620 | 620 | to_hr_ucontext(ib_pd->uobject->context), |
| @@ -730,7 +730,7 @@ static int hns_roce_create_qp_common(struct hns_roce_dev *hr_dev, · 109 unmodified lines | ||
| 730 | 730 | else |
| 731 | 731 | hr_qp->doorbell_qpn = cpu_to_le64(hr_qp->qpn); |
| 732 | 732 | |
| 733 | − if (ib_pd->uobject && (udata->outlen == sizeof(resp)) && | |
| 733 | + if (ib_pd->uobject && (udata->outlen >= sizeof(resp)) && | |
| 734 | 734 | (hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_RECORD_DB)) { |
| 735 | 735 | |
| 736 | 736 | /* indicate kernel supports record db */ |
| @@ -759,7 +759,7 @@ err_qpn: · 22 unmodified lines | ||
| 759 | 759 | err_wrid: |
| 760 | 760 | if (ib_pd->uobject) { |
| 761 | 761 | if ((hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_RECORD_DB) && |
| 762 | − (udata->outlen == sizeof(resp)) && | |
| 762 | + (udata->outlen >= sizeof(resp)) && | |
| 763 | 763 | hns_roce_qp_has_rq(init_attr)) |
| 764 | 764 | hns_roce_db_unmap_user( |
| 765 | 765 | to_hr_ucontext(ib_pd->uobject->context), |
| @@ -42,8 +42,7 @@ struct hns_roce_ib_create_cq { · 41 unmodified lines | ||
| 42 | 42 | }; |
| 43 | 43 | |
| 44 | 44 | struct hns_roce_ib_create_cq_resp { |
| 45 | − __u32 cqn; | |
| 46 | − __u32 reserved; | |
| 45 | + __u64 cqn; /* Only 32 bits used, 64 for compat */ | |
| 47 | 46 | __u64 cap_flags; |
| 48 | 47 | }; |
| 49 | 48 | |