From a38ac5e03faddbe9bcb90f9a0ab7e118285dbd4f Mon Sep 17 00:00:00 2001 From: Cheng Xu Date: Mon, 20 Feb 2023 15:38:40 +0800 Subject: [PATCH 1/2] Update kernel headers To commit ?? ("RDMA/erdma: Support larger page size with doorbell allocation"). Signed-off-by: Cheng Xu --- kernel-headers/rdma/erdma-abi.h | 5 ++++- kernel-headers/rdma/hns-abi.h | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/kernel-headers/rdma/erdma-abi.h b/kernel-headers/rdma/erdma-abi.h index b7a0222f9..57f8942a3 100644 --- a/kernel-headers/rdma/erdma-abi.h +++ b/kernel-headers/rdma/erdma-abi.h @@ -40,10 +40,13 @@ struct erdma_uresp_alloc_ctx { __u32 dev_id; __u32 pad; __u32 sdb_type; - __u32 sdb_offset; + __u32 sdb_entid; __aligned_u64 sdb; __aligned_u64 rdb; __aligned_u64 cdb; + __u32 sdb_off; + __u32 rdb_off; + __u32 cdb_off; }; #endif diff --git a/kernel-headers/rdma/hns-abi.h b/kernel-headers/rdma/hns-abi.h index 745790ce3..2e68a8b0c 100644 --- a/kernel-headers/rdma/hns-abi.h +++ b/kernel-headers/rdma/hns-abi.h @@ -87,10 +87,14 @@ struct hns_roce_ib_create_qp_resp { enum { HNS_ROCE_EXSGE_FLAGS = 1 << 0, + HNS_ROCE_RQ_INLINE_FLAGS = 1 << 1, + HNS_ROCE_CQE_INLINE_FLAGS = 1 << 2, }; enum { HNS_ROCE_RSP_EXSGE_FLAGS = 1 << 0, + HNS_ROCE_RSP_RQ_INLINE_FLAGS = 1 << 1, + HNS_ROCE_RSP_CQE_INLINE_FLAGS = 1 << 2, }; struct hns_roce_ib_alloc_ucontext_resp { From 174272dab6f4edeb59f75c18177f48adfe915b2c Mon Sep 17 00:00:00 2001 From: Cheng Xu Date: Mon, 20 Feb 2023 16:24:48 +0800 Subject: [PATCH 2/2] providers/erdma: Add non-4K page size support Default page size of some aarch64 distributions is not 4K, in these OSs, erdma will not work correctly. Currently, erdma always maps the doorbell spaces with size of 4096, it's not always right if OS's page size is not 4096. Fix this in this commit. Signed-off-by: Cheng Xu --- providers/erdma/erdma.c | 22 +++++++++++++++------- providers/erdma/erdma.h | 8 +++++++- providers/erdma/erdma_verbs.c | 11 +++++++---- 3 files changed, 29 insertions(+), 12 deletions(-) diff --git a/providers/erdma/erdma.c b/providers/erdma/erdma.c index 3a49490a3..42b57f122 100644 --- a/providers/erdma/erdma.c +++ b/providers/erdma/erdma.c @@ -60,36 +60,42 @@ static struct verbs_context *erdma_alloc_context(struct ibv_device *device, goto err_out; verbs_set_ops(&ctx->ibv_ctx, &erdma_context_ops); + ctx->page_size = to_edev(device)->page_size; ctx->dev_id = resp.dev_id; ctx->sdb_type = resp.sdb_type; - ctx->sdb_offset = resp.sdb_offset; + ctx->sdb_entid = resp.sdb_entid; - ctx->sdb = mmap(NULL, ERDMA_PAGE_SIZE, PROT_WRITE, MAP_SHARED, cmd_fd, + ctx->sdb = mmap(NULL, ctx->page_size, PROT_WRITE, MAP_SHARED, cmd_fd, resp.sdb); if (ctx->sdb == MAP_FAILED) goto err_out; - ctx->rdb = mmap(NULL, ERDMA_PAGE_SIZE, PROT_WRITE, MAP_SHARED, cmd_fd, + ctx->rdb = mmap(NULL, ctx->page_size, PROT_WRITE, MAP_SHARED, cmd_fd, resp.rdb); if (ctx->rdb == MAP_FAILED) goto err_rdb_map; - ctx->cdb = mmap(NULL, ERDMA_PAGE_SIZE, PROT_WRITE, MAP_SHARED, cmd_fd, + ctx->cdb = mmap(NULL, ctx->page_size, PROT_WRITE, MAP_SHARED, cmd_fd, resp.cdb); if (ctx->cdb == MAP_FAILED) goto err_cdb_map; - ctx->page_size = ERDMA_PAGE_SIZE; + ctx->sdb += resp.sdb_off; + ctx->rdb += resp.rdb_off; + ctx->cdb += resp.cdb_off; + list_head_init(&ctx->dbrecord_pages_list); pthread_mutex_init(&ctx->dbrecord_pages_mutex, NULL); return &ctx->ibv_ctx; err_cdb_map: - munmap(ctx->rdb, ERDMA_PAGE_SIZE); + munmap((void *)align_down((uintptr_t)ctx->rdb, ctx->page_size), + ctx->page_size); err_rdb_map: - munmap(ctx->sdb, ERDMA_PAGE_SIZE); + munmap((void *)align_down((uintptr_t)ctx->sdb, ctx->page_size), + ctx->page_size); err_out: verbs_uninit_context(&ctx->ibv_ctx); free(ctx); @@ -106,6 +112,8 @@ erdma_device_alloc(struct verbs_sysfs_dev *sysfs_dev) if (!dev) return NULL; + dev->page_size = sysconf(_SC_PAGESIZE); + return &dev->ibv_dev; } diff --git a/providers/erdma/erdma.h b/providers/erdma/erdma.h index ce13a8b7a..0883e8576 100644 --- a/providers/erdma/erdma.h +++ b/providers/erdma/erdma.h @@ -23,6 +23,7 @@ struct erdma_device { struct verbs_device ibv_dev; + uint32_t page_size; }; #define ERDMA_QP_TABLE_SIZE 4096 @@ -40,7 +41,7 @@ struct erdma_context { pthread_mutex_t qp_table_mutex; uint8_t sdb_type; - uint32_t sdb_offset; + uint32_t sdb_entid; void *sdb; void *rdb; @@ -56,4 +57,9 @@ static inline struct erdma_context *to_ectx(struct ibv_context *base) return container_of(base, struct erdma_context, ibv_ctx.context); } +static inline struct erdma_device *to_edev(struct ibv_device *ibv_dev) +{ + return container_of(ibv_dev, struct erdma_device, ibv_dev.device); +} + #endif diff --git a/providers/erdma/erdma_verbs.c b/providers/erdma/erdma_verbs.c index 2d33d455d..80c5246f6 100644 --- a/providers/erdma/erdma_verbs.c +++ b/providers/erdma/erdma_verbs.c @@ -277,7 +277,7 @@ static void __erdma_alloc_dbs(struct erdma_qp *qp, struct erdma_context *ctx) uint32_t db_offset; if (ctx->sdb_type == ERDMA_SDB_ENTRY) - db_offset = ctx->sdb_offset * ERDMA_NSDB_PER_ENTRY * + db_offset = ctx->sdb_entid * ERDMA_NSDB_PER_ENTRY * ERDMA_SQDB_SIZE; else db_offset = (qpn & ERDMA_SDB_ALLOC_QPN_MASK) * ERDMA_SQDB_SIZE; @@ -1018,9 +1018,12 @@ void erdma_free_context(struct ibv_context *ibv_ctx) struct erdma_context *ctx = to_ectx(ibv_ctx); int i; - munmap(ctx->sdb, ERDMA_PAGE_SIZE); - munmap(ctx->rdb, ERDMA_PAGE_SIZE); - munmap(ctx->cdb, ERDMA_PAGE_SIZE); + munmap((void *)align_down((uintptr_t)ctx->sdb, ctx->page_size), + ctx->page_size); + munmap((void *)align_down((uintptr_t)ctx->rdb, ctx->page_size), + ctx->page_size); + munmap((void *)align_down((uintptr_t)ctx->cdb, ctx->page_size), + ctx->page_size); pthread_mutex_lock(&ctx->qp_table_mutex); for (i = 0; i < ERDMA_QP_TABLE_SIZE; ++i) {