Introduce Microsoft Azure Network Adapter (MANA) RDMA driver
Subsystems (5)
cover Introduce Microsoft Azure Network Adapter (MANA) RDMA driver
From: Long Li <[email protected]>
This patchset implements a RDMA driver for Microsoft Azure Network Adapter (MANA). In MANA, the RDMA device is modeled as an auxiliary device to the Ethernet device.
The first 11 patches modify the MANA Ethernet driver to support RDMA driver. The last patch implementes the RDMA driver.
Long Li (12):
net: mana: Add support for auxiliary device
net: mana: Record the physical address for doorbell page region
net: mana: Handle vport sharing between devices
net: mana: Add functions for allocating doorbell page from GDMA
net: mana: Set the DMA device max page size
net: mana: Define data structures for protection domain and memory
registration
net: mana: Export Work Queue functions for use by RDMA driver
net: mana: Record port number in netdev
net: mana: Move header files to a common location
net: mana: Define max values for SGL entries
net: mana: Define and process GDMA response code
GDMA_STATUS_MORE_ENTRIES
RDMA/mana_ib: Add a driver for Microsoft Azure Network Adapter
MAINTAINERS | 4 +
drivers/infiniband/Kconfig | 1 +
drivers/infiniband/hw/Makefile | 1 +
drivers/infiniband/hw/mana/Kconfig | 7 +
drivers/infiniband/hw/mana/Makefile | 4 +
drivers/infiniband/hw/mana/cq.c | 74 ++
drivers/infiniband/hw/mana/main.c | 679 ++++++++++++++++++
drivers/infiniband/hw/mana/mana_ib.h | 145 ++++
drivers/infiniband/hw/mana/mr.c | 133 ++++
drivers/infiniband/hw/mana/qp.c | 466 ++++++++++++
drivers/infiniband/hw/mana/wq.c | 111 +++
.../net/ethernet/microsoft/mana/gdma_main.c | 94 ++-
.../net/ethernet/microsoft/mana/hw_channel.c | 6 +-
.../net/ethernet/microsoft/mana/mana_bpf.c | 2 +-
drivers/net/ethernet/microsoft/mana/mana_en.c | 139 +++-
.../ethernet/microsoft/mana/mana_ethtool.c | 2 +-
.../net/ethernet/microsoft/mana/shm_channel.c | 2 +-
.../microsoft => include/linux}/mana/gdma.h | 191 ++++-
.../linux}/mana/hw_channel.h | 0
.../microsoft => include/linux}/mana/mana.h | 26 +-
.../linux}/mana/shm_channel.h | 0
include/uapi/rdma/ib_user_ioctl_verbs.h | 1 +
include/uapi/rdma/mana-abi.h | 68 ++
23 files changed, 2111 insertions(+), 45 deletions(-)
create mode 100644 drivers/infiniband/hw/mana/Kconfig
create mode 100644 drivers/infiniband/hw/mana/Makefile
create mode 100644 drivers/infiniband/hw/mana/cq.c
create mode 100644 drivers/infiniband/hw/mana/main.c
create mode 100644 drivers/infiniband/hw/mana/mana_ib.h
create mode 100644 drivers/infiniband/hw/mana/mr.c
create mode 100644 drivers/infiniband/hw/mana/qp.c
create mode 100644 drivers/infiniband/hw/mana/wq.c
rename {drivers/net/ethernet/microsoft => include/linux}/mana/gdma.h (77%)
rename {drivers/net/ethernet/microsoft => include/linux}/mana/hw_channel.h (100%)
rename {drivers/net/ethernet/microsoft => include/linux}/mana/mana.h (94%)
rename {drivers/net/ethernet/microsoft => include/linux}/mana/shm_channel.h (100%)
create mode 100644 include/uapi/rdma/mana-abi.hSignature · 1 line
2.17.1
PATCH 7/12 net: mana: Export Work Queue functions for use by RDMA driver
From: Long Li <[email protected]>
RDMA device may need to create Ethernet device queues for use by Queue Pair type RAW. This allows a user-mode context accesses Ethernet hardware queues. Export the supporting functions for use by the RDMA driver.
--- drivers/net/ethernet/microsoft/mana/gdma_main.c | 1 + drivers/net/ethernet/microsoft/mana/mana.h | 9 +++++++++ drivers/net/ethernet/microsoft/mana/mana_en.c | 16 +++++++++------- 3 files changed, 19 insertions(+), 7 deletions(-)
drivers/net/ethernet/microsoft/mana/gdma_main.c +1 -0
@@ -125,6 +125,7 @@ int mana_gd_send_request(struct gdma_context *gc, u32 req_len, const void *req,return mana_hwc_send_request (hwc, req_len, req, resp_len, resp); } +EXPORT_SYMBOL (mana_gd_send_request);int mana_gd_alloc_memory (struct gdma_context *gc,unsigned int length,struct gdma_mem_info *gmi)
drivers/net/ethernet/microsoft/mana/mana.h +9 -0
@@ -568,6 +568,15 @@ struct mana_adev {struct gdma_dev *mdev; }; +int mana_create_wq_obj (struct mana_port_context *apc, +mana_handle_t vport, +u32 wq_type,struct mana_obj_spec *wq_spec, +struct mana_obj_spec *cq_spec, +mana_handle_t *wq_obj); + +void mana_destroy_wq_obj (struct mana_port_context *apc,u32 wq_type, +mana_handle_t wq_obj); +int mana_cfg_vport (struct mana_port_context *apc,u32 protection_dom_id,u32 doorbell_pg_id);void mana_uncfg_vport (struct mana_port_context *apc);
drivers/net/ethernet/microsoft/mana/mana_en.c +9 -7
@@ -644,11 +644,11 @@ static int mana_cfg_vport_steering(struct mana_port_context *apc,return err; } -static int mana_create_wq_obj (struct mana_port_context *apc, -mana_handle_t vport, -u32 wq_type,struct mana_obj_spec *wq_spec, -struct mana_obj_spec *cq_spec, -mana_handle_t *wq_obj) +int mana_create_wq_obj (struct mana_port_context *apc, +mana_handle_t vport, +u32 wq_type,struct mana_obj_spec *wq_spec, +struct mana_obj_spec *cq_spec, +mana_handle_t *wq_obj) {struct mana_create_wqobj_resp resp = {};struct mana_create_wqobj_req req = {};
@@ -697,9 +697,10 @@ static int mana_create_wq_obj(struct mana_port_context *apc, out:return err; } +EXPORT_SYMBOL_GPL (mana_create_wq_obj); -static void mana_destroy_wq_obj (struct mana_port_context *apc,u32 wq_type, -mana_handle_t wq_obj) +void mana_destroy_wq_obj (struct mana_port_context *apc,u32 wq_type, +mana_handle_t wq_obj) {struct mana_destroy_wqobj_resp resp = {};struct mana_destroy_wqobj_req req = {};
@@ -724,6 +725,7 @@ static void mana_destroy_wq_obj(struct mana_port_context *apc, u32 wq_type,netdev_err (ndev,"Failed to destroy WQ object: %d, 0x%x\n" , err, resp.hdr.status); } +EXPORT_SYMBOL_GPL (mana_destroy_wq_obj);static void mana_destroy_eq (struct mana_context *ac) {
Signature · 1 line
2.17.1
PATCH 6/12 net: mana: Define data structures for protection domain and memory registration
In reply to [email protected]From: Long Li <[email protected]>
The MANA hardware support protection domain and memory registration for use in RDMA environment. Add those definitions and expose them for use by the RDMA driver.
--- drivers/net/ethernet/microsoft/mana/gdma.h | 149 +++++++++++++++++- .../net/ethernet/microsoft/mana/gdma_main.c | 26 +-- drivers/net/ethernet/microsoft/mana/mana_en.c | 16 +- 3 files changed, 168 insertions(+), 23 deletions(-)
drivers/net/ethernet/microsoft/mana/gdma.h +144 -5
@@ -27,6 +27,10 @@ enum gdma_request_type {GDMA_CREATE_DMA_REGION =25 ,GDMA_DMA_REGION_ADD_PAGES =26 ,GDMA_DESTROY_DMA_REGION =27 , +GDMA_CREATE_PD =29 , +GDMA_DESTROY_PD =30 , +GDMA_CREATE_MR =31 , + GDMA_DESTROY_MR = 32, };#define GDMA_RESOURCE_DOORBELL_PAGE 27
@@ -59,6 +63,8 @@ enum { GDMA_DEVICE_MANA = 2, }; +typedef u64 gdma_obj_handle_t ; +struct gdma_resource {/* Protect the bitmap */ spinlock_t lock;
@@ -192,7 +198,7 @@ struct gdma_mem_info {u64 length;/* Allocated by the PF driver */ -u64 gdma_region; +gdma_obj_handle_t dma_region_handle; };#define REGISTER_ATB_MST_MKEY_LOWER_SIZE 8
@@ -599,7 +605,7 @@ struct gdma_create_queue_req {u32 reserved1;u32 pdid;u32 doolbell_id; -u64 gdma_region; +gdma_obj_handle_t gdma_region;u32 reserved2;u32 queue_size;u32 log2_throttle_limit;
@@ -626,6 +632,28 @@ struct gdma_disable_queue_req {u32 alloc_res_id_on_creation; };/* HW DATA */ +enum atb_page_size { +ATB_PAGE_SIZE_4K , +ATB_PAGE_SIZE_8K , +ATB_PAGE_SIZE_16K , +ATB_PAGE_SIZE_32K , +ATB_PAGE_SIZE_64K , +ATB_PAGE_SIZE_128K , +ATB_PAGE_SIZE_256K , +ATB_PAGE_SIZE_512K , +ATB_PAGE_SIZE_1M , +ATB_PAGE_SIZE_2M , +ATB_PAGE_SIZE_MAX , +}; + +enum gdma_mr_access_flags { +GDMA_ACCESS_FLAG_LOCAL_READ = (1 <<0 ), +GDMA_ACCESS_FLAG_LOCAL_WRITE = (1 <<1 ), +GDMA_ACCESS_FLAG_REMOTE_READ = (1 <<2 ), +GDMA_ACCESS_FLAG_REMOTE_WRITE = (1 <<3 ), +GDMA_ACCESS_FLAG_REMOTE_ATOMIC = (1 <<4 ), +}; +/* GDMA_CREATE_DMA_REGION */ struct gdma_create_dma_region_req {struct gdma_req_hdr hdr;
@@ -652,14 +680,14 @@ struct gdma_create_dma_region_req {struct gdma_create_dma_region_resp {struct gdma_resp_hdr hdr; -u64 gdma_region; +gdma_obj_handle_t dma_region_handle; };/* HW DATA */ /* GDMA_DMA_REGION_ADD_PAGES */ struct gdma_dma_region_add_pages_req {struct gdma_req_hdr hdr; -u64 gdma_region; +gdma_obj_handle_t dma_region_handle;u32 page_addr_list_len;u32 reserved3;
@@ -671,9 +699,117 @@ struct gdma_dma_region_add_pages_req {struct gdma_destroy_dma_region_req {struct gdma_req_hdr hdr; -u64 gdma_region; +gdma_obj_handle_t dma_region_handle; };/* HW DATA */ +enum gdma_pd_flags { +GDMA_PD_FLAG_ALLOW_GPA_MR = (1 <<0 ), +GDMA_PD_FLAG_ALLOW_FMR_MR = (1 <<1 ), +}; + +struct gdma_create_pd_req { +struct gdma_req_hdr hdr; +enum gdma_pd_flags flags; +u32 reserved; +}; + +struct gdma_create_pd_resp { +struct gdma_resp_hdr hdr; +gdma_obj_handle_t pd_handle; +u32 pd_id; +u32 reserved; +}; + +struct gdma_destroy_pd_req { +struct gdma_req_hdr hdr; +gdma_obj_handle_t pd_handle; +}; + +struct gdma_destory_pd_resp { +struct gdma_resp_hdr hdr; +}; + +enum gdma_mr_type { +// +// Guest Physical Address - MRs of this type allow access +// to any DMA-mapped memory using bus-logical address +// +GDMA_MR_TYPE_GPA =1 , + +// +// Guest Virtual Address - MRs of this type allow access +// to memory mapped by PTEs associated with this MR using a virtual +// address that is set up in the MST +// +GDMA_MR_TYPE_GVA , + +// +// Fast Memory Register - Like GVA but the MR is initially put in the +// FREE state (as opposed to Valid), and the specified number of +// PTEs are reserved for future fast memory reservations. +// +GDMA_MR_TYPE_FMR , +}; + +struct gdma_create_mr_params { +gdma_obj_handle_t pd_handle; +enum gdma_mr_type mr_type; +union { +struct { +gdma_obj_handle_t dma_region_handle; +u64 virtual_address; +enum gdma_mr_access_flags access_flags; + } gva; +struct { +enum gdma_mr_access_flags access_flags; + } gpa; +struct { +enum atb_page_size page_size; +u32 reserved_pte_count; + } fmr; + }; +}; + +struct gdma_create_mr_request { +struct gdma_req_hdr hdr; +gdma_obj_handle_t pd_handle; +enum gdma_mr_type mr_type; +u32 reserved; + +union { +struct { +enum gdma_mr_access_flags access_flags; + } gpa; + +struct { +gdma_obj_handle_t dma_region_handle; +u64 virtual_address; +enum gdma_mr_access_flags access_flags; + } gva; + +struct { +enum atb_page_size page_size; +u32 reserved_pte_count; + } fmr; + }; +}; + +struct gdma_create_mr_response { +struct gdma_resp_hdr hdr; +gdma_obj_handle_t mr_handle; +u32 lkey; +u32 rkey; +}; + +struct gdma_destroy_mr_request { +struct gdma_req_hdr hdr; +gdma_obj_handle_t mr_handle; +}; + +struct gdma_destroy_mr_response { +struct gdma_resp_hdr hdr; +}; +int mana_gd_verify_vf_version (struct pci_dev *pdev);int mana_gd_register_device (struct gdma_dev *gd);
@@ -705,4 +841,7 @@ int mana_gd_allocate_doorbell_page(struct gdma_context *gc, int *doorbell_page);int mana_gd_destroy_doorbell_page (struct gdma_context *gc,int doorbell_page); +int mana_gd_destroy_dma_region (struct gdma_context *gc, +gdma_obj_handle_t dma_region_handle); +#endif /* _GDMA_H */
drivers/net/ethernet/microsoft/mana/gdma_main.c +16 -10
@@ -224,7 +224,7 @@ static int mana_gd_create_hw_eq(struct gdma_context *gc, req.type = queue->type; req.pdid = queue->gdma_dev->pdid; req.doolbell_id = queue->gdma_dev->doorbell; - req.gdma_region = queue->mem_info.gdma_region; + req.gdma_region = queue->mem_info.dma_region_handle; req.queue_size = queue->queue_size; req.log2_throttle_limit = queue->eq.log2_throttle_limit; req.eq_pci_msix_index = queue->eq.msix_index;
@@ -238,7 +238,7 @@ static int mana_gd_create_hw_eq(struct gdma_context *gc, queue->id = resp.queue_index; queue->eq.disable_needed = true; - queue->mem_info.gdma_region =GDMA_INVALID_DMA_REGION ; + queue->mem_info.dma_region_handle =GDMA_INVALID_DMA_REGION ;return 0 ; }
@@ -692,24 +692,30 @@ int mana_gd_create_hwc_queue(struct gdma_dev *gd,return err; } -static void mana_gd_destroy_dma_region (struct gdma_context *gc,u64 gdma_region) +int mana_gd_destroy_dma_region (struct gdma_context *gc, +gdma_obj_handle_t dma_region_handle) {struct gdma_destroy_dma_region_req req = {};struct gdma_general_resp resp = {};int err; -if (gdma_region ==GDMA_INVALID_DMA_REGION ) -return ; +if (dma_region_handle ==GDMA_INVALID_DMA_REGION ) +return 0 ;mana_gd_init_req_hdr (&req.hdr,GDMA_DESTROY_DMA_REGION ,sizeof (req),sizeof (resp)); - req.gdma_region = gdma_region; + req.dma_region_handle = dma_region_handle; err =mana_gd_send_request (gc,sizeof (req), &req,sizeof (resp), &resp); -if (err || resp.hdr.status) +if (err || resp.hdr.status) {dev_err (gc->dev,"Failed to destroy DMA region: %d, 0x%x\n" , err, resp.hdr.status); +return -EPROTO ; + } + +return 0 ; } +EXPORT_SYMBOL (mana_gd_destroy_dma_region);static int mana_gd_create_dma_region (struct gdma_dev *gd,struct gdma_mem_info *gmi)
@@ -754,14 +760,14 @@ static int mana_gd_create_dma_region(struct gdma_dev *gd,if (err) goto out; -if (resp.hdr.status || resp.gdma_region ==GDMA_INVALID_DMA_REGION ) { +if (resp.hdr.status || resp.dma_region_handle ==GDMA_INVALID_DMA_REGION ) {dev_err (gc->dev,"Failed to create DMA region: 0x%x\n" , resp.hdr.status); err = -EPROTO ; goto out; } - gmi->gdma_region = resp.gdma_region; + gmi->dma_region_handle = resp.dma_region_handle; out:kfree (req);return err;
@@ -884,7 +890,7 @@ void mana_gd_destroy_queue(struct gdma_context *gc, struct gdma_queue *queue)return ; } -mana_gd_destroy_dma_region (gc, gmi->gdma_region); +mana_gd_destroy_dma_region (gc, gmi->dma_region_handle);mana_gd_free_memory (gmi);kfree (queue); }
drivers/net/ethernet/microsoft/mana/mana_en.c +8 -8
@@ -1364,10 +1364,10 @@ static int mana_create_txq(struct mana_port_context *apc,memset (&wq_spec,0 ,sizeof (wq_spec));memset (&cq_spec,0 ,sizeof (cq_spec)); - wq_spec.gdma_region = txq->gdma_sq->mem_info.gdma_region; + wq_spec.gdma_region = txq->gdma_sq->mem_info.dma_region_handle; wq_spec.queue_size = txq->gdma_sq->queue_size; - cq_spec.gdma_region = cq->gdma_cq->mem_info.gdma_region; + cq_spec.gdma_region = cq->gdma_cq->mem_info.dma_region_handle; cq_spec.queue_size = cq->gdma_cq->queue_size; cq_spec.modr_ctx_id =0 ; cq_spec.attached_eq = cq->gdma_cq->cq.parent->id;
@@ -1382,8 +1382,8 @@ static int mana_create_txq(struct mana_port_context *apc, txq->gdma_sq->id = wq_spec.queue_index; cq->gdma_cq->id = cq_spec.queue_index; - txq->gdma_sq->mem_info.gdma_region =GDMA_INVALID_DMA_REGION ; - cq->gdma_cq->mem_info.gdma_region =GDMA_INVALID_DMA_REGION ; + txq->gdma_sq->mem_info.dma_region_handle =GDMA_INVALID_DMA_REGION ; + cq->gdma_cq->mem_info.dma_region_handle =GDMA_INVALID_DMA_REGION ; txq->gdma_txq_id = txq->gdma_sq->id;
@@ -1594,10 +1594,10 @@ static struct mana_rxq *mana_create_rxq(struct mana_port_context *apc,memset (&wq_spec,0 ,sizeof (wq_spec));memset (&cq_spec,0 ,sizeof (cq_spec)); - wq_spec.gdma_region = rxq->gdma_rq->mem_info.gdma_region; + wq_spec.gdma_region = rxq->gdma_rq->mem_info.dma_region_handle; wq_spec.queue_size = rxq->gdma_rq->queue_size; - cq_spec.gdma_region = cq->gdma_cq->mem_info.gdma_region; + cq_spec.gdma_region = cq->gdma_cq->mem_info.dma_region_handle; cq_spec.queue_size = cq->gdma_cq->queue_size; cq_spec.modr_ctx_id =0 ; cq_spec.attached_eq = cq->gdma_cq->cq.parent->id;
@@ -1610,8 +1610,8 @@ static struct mana_rxq *mana_create_rxq(struct mana_port_context *apc, rxq->gdma_rq->id = wq_spec.queue_index; cq->gdma_cq->id = cq_spec.queue_index; - rxq->gdma_rq->mem_info.gdma_region =GDMA_INVALID_DMA_REGION ; - cq->gdma_cq->mem_info.gdma_region =GDMA_INVALID_DMA_REGION ; + rxq->gdma_rq->mem_info.dma_region_handle =GDMA_INVALID_DMA_REGION ; + cq->gdma_cq->mem_info.dma_region_handle =GDMA_INVALID_DMA_REGION ; rxq->gdma_id = rxq->gdma_rq->id; cq->gdma_id = cq->gdma_cq->id;
Signature · 1 line
2.17.1
PATCH 8/12 net: mana: Record port number in netdev
In reply to [email protected]From: Long Li <[email protected]>
The port number is useful for user-mode application to identify this net device based on port index. Set to the correct value in ndev.
--- drivers/net/ethernet/microsoft/mana/mana_en.c | 1 + 1 file changed, 1 insertion(+)
drivers/net/ethernet/microsoft/mana/mana_en.c +1 -0
@@ -1952,6 +1952,7 @@ static int mana_probe_port(struct mana_context *ac, int port_idx, ndev->max_mtu = ndev->mtu; ndev->min_mtu = ndev->mtu; ndev->needed_headroom =MANA_HEADROOM ; + ndev->dev_port = port_idx;SET_NETDEV_DEV (ndev, gc->dev);netif_carrier_off (ndev);
Signature · 1 line
2.17.1
PATCH 5/12 net: mana: Set the DMA device max page size
In reply to [email protected]From: Long Li <[email protected]>
The system chooses default 64K page size if the device does not specify the max page size the device can handle for DMA. This do not work well when device is registering large chunk of memory in that a large page size is more efficient.
Set it to the maximum hardware supported page size.
--- drivers/net/ethernet/microsoft/mana/gdma_main.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/net/ethernet/microsoft/mana/gdma_main.c +7 -0
@@ -1385,6 +1385,13 @@ static int mana_gd_probe(struct pci_dev *pdev, const struct pci_device_id *ent)if (err) goto release_region; +// The max GDMA HW supported page size is 2M + err =dma_set_max_seg_size (&pdev->dev,SZ_2M ); +if (err) { +dev_err (&pdev->dev,"Failed to set dma device segment size\n" ); + goto release_region; + } + err = -ENOMEM ; gc =vzalloc (sizeof (*gc));if (!gc)
Signature · 1 line
2.17.1
PATCH 9/12 net: mana: Move header files to a common location
In reply to [email protected]From: Long Li <[email protected]>
In preparation to add MANA RDMA driver, move all the required header files to a common location for use by both Ethernet and RDMA drivers.
---
MAINTAINERS | 1 +
drivers/net/ethernet/microsoft/mana/gdma_main.c | 2 +-
drivers/net/ethernet/microsoft/mana/hw_channel.c | 4 ++--
drivers/net/ethernet/microsoft/mana/mana_bpf.c | 2 +-
drivers/net/ethernet/microsoft/mana/mana_en.c | 2 +-
drivers/net/ethernet/microsoft/mana/mana_ethtool.c | 2 +-
drivers/net/ethernet/microsoft/mana/shm_channel.c | 2 +-
{drivers/net/ethernet/microsoft => include/linux}/mana/gdma.h | 0
.../ethernet/microsoft => include/linux}/mana/hw_channel.h | 0
{drivers/net/ethernet/microsoft => include/linux}/mana/mana.h | 0
.../ethernet/microsoft => include/linux}/mana/shm_channel.h | 0
11 files changed, 8 insertions(+), 7 deletions(-)
rename {drivers/net/ethernet/microsoft => include/linux}/mana/gdma.h (100%)
rename {drivers/net/ethernet/microsoft => include/linux}/mana/hw_channel.h (100%)
rename {drivers/net/ethernet/microsoft => include/linux}/mana/mana.h (100%)
rename {drivers/net/ethernet/microsoft => include/linux}/mana/shm_channel.h (100%)MAINTAINERS +1 -0
@@ -9108,6 +9108,7 @@ F: include/asm-generic/hyperv-tlfs.h F: include/asm-generic/mshyperv.h F: include/clocksource/hyperv_timer.h F: include/linux/hyperv.h +F: include/mana/ F: include/uapi/linux/hyperv.h F: net/vmw_vsock/hyperv_transport.c F: tools/hv/
drivers/net/ethernet/microsoft/mana/gdma_main.c +1 -1
@@ -6,7 +6,7 @@#include <linux/utsname.h> #include <linux/version.h> -#include "mana.h" +#include <linux/mana/mana.h> static u32 mana_gd_r32 (struct gdma_context *g,u64 offset) {
drivers/net/ethernet/microsoft/mana/hw_channel.c +2 -2
@@ -1,8 +1,8 @@// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause /* Copyright (c) 2021, Microsoft Corporation. */ -#include "gdma.h" -#include "hw_channel.h" +#include <linux/mana/gdma.h> +#include <linux/mana/hw_channel.h> static int mana_hwc_get_msg_index (struct hw_channel_context *hwc,u16 *msg_id) {
drivers/net/ethernet/microsoft/mana/mana_bpf.c +1 -1
@@ -8,7 +8,7 @@#include <linux/bpf_trace.h> #include <net/xdp.h> -#include "mana.h" +#include <linux/mana/mana.h> void mana_xdp_tx (struct sk_buff *skb,struct net_device *ndev) {
drivers/net/ethernet/microsoft/mana/mana_en.c +1 -1
@@ -11,7 +11,7 @@#include <net/checksum.h> #include <net/ip6_checksum.h> -#include "mana.h" +#include <linux/mana/mana.h> static DEFINE_IDA (mana_adev_ida);
drivers/net/ethernet/microsoft/mana/mana_ethtool.c +1 -1
@@ -5,7 +5,7 @@#include <linux/etherdevice.h> #include <linux/ethtool.h> -#include "mana.h" +#include <linux/mana/mana.h> static const struct { char name[ETH_GSTRING_LEN];
drivers/net/ethernet/microsoft/mana/shm_channel.c +1 -1
@@ -6,7 +6,7 @@#include <linux/io.h> #include <linux/mm.h> -#include "shm_channel.h" +#include <linux/mana/shm_channel.h> #define PAGE_FRAME_L48_WIDTH_BYTES 6#define PAGE_FRAME_L48_WIDTH_BITS (PAGE_FRAME_L48_WIDTH_BYTES * 8)
include/linux/mana/gdma.h renamed from drivers/net/ethernet/microsoft/mana/gdma.h +0 -0
include/linux/mana/hw_channel.h renamed from drivers/net/ethernet/microsoft/mana/hw_channel.h +0 -0
include/linux/mana/mana.h renamed from drivers/net/ethernet/microsoft/mana/mana.h +0 -0
include/linux/mana/shm_channel.h renamed from drivers/net/ethernet/microsoft/mana/shm_channel.h +0 -0
Signature · 1 line
2.17.1
PATCH 12/12 RDMA/mana_ib: Add a driver for Microsoft Azure Network Adapter
In reply to [email protected]From: Long Li <[email protected]>
Add a RDMA VF driver for Microsoft Azure Network Adapter (MANA).
--- MAINTAINERS | 3 + drivers/infiniband/Kconfig | 1 + drivers/infiniband/hw/Makefile | 1 + drivers/infiniband/hw/mana/Kconfig | 7 + drivers/infiniband/hw/mana/Makefile | 4 + drivers/infiniband/hw/mana/cq.c | 74 +++ drivers/infiniband/hw/mana/main.c | 679 ++++++++++++++++++++++++ drivers/infiniband/hw/mana/mana_ib.h | 145 +++++ drivers/infiniband/hw/mana/mr.c | 133 +++++ drivers/infiniband/hw/mana/qp.c | 466 ++++++++++++++++ drivers/infiniband/hw/mana/wq.c | 111 ++++ include/linux/mana/mana.h | 3 + include/uapi/rdma/ib_user_ioctl_verbs.h | 1 + include/uapi/rdma/mana-abi.h | 68 +++ 14 files changed, 1696 insertions(+) create mode 100644 drivers/infiniband/hw/mana/Kconfig create mode 100644 drivers/infiniband/hw/mana/Makefile create mode 100644 drivers/infiniband/hw/mana/cq.c create mode 100644 drivers/infiniband/hw/mana/main.c create mode 100644 drivers/infiniband/hw/mana/mana_ib.h create mode 100644 drivers/infiniband/hw/mana/mr.c create mode 100644 drivers/infiniband/hw/mana/qp.c create mode 100644 drivers/infiniband/hw/mana/wq.c create mode 100644 include/uapi/rdma/mana-abi.h
MAINTAINERS +3 -0
@@ -9078,6 +9078,7 @@ M: Haiyang Zhang <[email protected]> M: Stephen Hemminger <[email protected]> M: Wei Liu <[email protected]> M: Dexuan Cui <[email protected]> +M: Long Li <[email protected]> L: [email protected] S: Supported T: git git://git.kernel.org/pub/scm/linux/kernel/git/hyperv/linux.git
@@ -9095,6 +9096,7 @@ F: arch/x86/kernel/cpu/mshyperv.c F: drivers/clocksource/hyperv_timer.c F: drivers/hid/hid-hyperv.c F: drivers/hv/ +F: drivers/infiniband/hw/mana/ F: drivers/input/serio/hyperv-keyboard.c F: drivers/iommu/hyperv-iommu.c F: drivers/net/ethernet/microsoft/
@@ -9110,6 +9112,7 @@ F: include/clocksource/hyperv_timer.h F: include/linux/hyperv.h F: include/mana/ F: include/uapi/linux/hyperv.h +F: include/uapi/rdma/mana-abi.h F: net/vmw_vsock/hyperv_transport.c F: tools/hv/
drivers/infiniband/Kconfig +1 -0
@@ -83,6 +83,7 @@ source "drivers/infiniband/hw/qib/Kconfig" source "drivers/infiniband/hw/cxgb4/Kconfig" source "drivers/infiniband/hw/efa/Kconfig" source "drivers/infiniband/hw/irdma/Kconfig" +source "drivers/infiniband/hw/mana/Kconfig" source "drivers/infiniband/hw/mlx4/Kconfig" source "drivers/infiniband/hw/mlx5/Kconfig" source "drivers/infiniband/hw/ocrdma/Kconfig"
drivers/infiniband/hw/Makefile +1 -0
@@ -4,6 +4,7 @@ obj-$(CONFIG_INFINIBAND_QIB) += qib/ obj-$(CONFIG_INFINIBAND_CXGB4) += cxgb4/ obj-$(CONFIG_INFINIBAND_EFA) += efa/ obj-$(CONFIG_INFINIBAND_IRDMA) += irdma/ +obj-$(CONFIG_MANA_INFINIBAND) += mana/ obj-$(CONFIG_MLX4_INFINIBAND) += mlx4/ obj-$(CONFIG_MLX5_INFINIBAND) += mlx5/ obj-$(CONFIG_INFINIBAND_OCRDMA) += ocrdma/
drivers/infiniband/hw/mana/Kconfig new file +7 -0
@@ -0,0 +1,7 @@ +# SPDX-License-Identifier: GPL-2.0-only +config MANA_INFINIBAND + tristate "Microsoft Azure Network Adapter support" + depends on NETDEVICES && ETHERNET && PCI && MICROSOFT_MANA + help + This driver provides low-level RDMA support for + Microsoft Azure Network Adapter (MANA).
drivers/infiniband/hw/mana/Makefile new file +4 -0
@@ -0,0 +1,4 @@ +# SPDX-License-Identifier: GPL-2.0-only +obj-$(CONFIG_MANA_INFINIBAND) += mana_ib.o + +mana_ib-y := main.o wq.o qp.o cq.o mr.o
drivers/infiniband/hw/mana/cq.c new file +74 -0
74 lines not on this page · raw message
drivers/infiniband/hw/mana/main.c new file +679 -0
679 lines not on this page · raw message
drivers/infiniband/hw/mana/mana_ib.h new file +145 -0
145 lines not on this page · raw message
drivers/infiniband/hw/mana/mr.c new file +133 -0
133 lines not on this page · raw message
drivers/infiniband/hw/mana/qp.c new file +466 -0
466 lines not on this page · raw message
drivers/infiniband/hw/mana/wq.c new file +111 -0
111 lines not on this page · raw message
include/linux/mana/mana.h +3 -0
@@ -403,6 +403,9 @@ int mana_bpf(struct net_device *ndev, struct netdev_bpf *bpf);extern const struct ethtool_ops mana_ethtool_ops; +/* A CQ can be created not associated with any EQ */ +#define GDMA_CQ_NO_EQ 0xffff +struct mana_obj_spec {u32 queue_index;u64 gdma_region;
include/uapi/rdma/ib_user_ioctl_verbs.h +1 -0
@@ -250,6 +250,7 @@ enum rdma_driver_id {RDMA_DRIVER_QIB ,RDMA_DRIVER_EFA ,RDMA_DRIVER_SIW , + RDMA_DRIVER_MANA, }; enum ib_uverbs_gid_type {
include/uapi/rdma/mana-abi.h new file +68 -0
68 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH 11/12 net: mana: Define and process GDMA response code GDMA_STATUS_MORE_ENTRIES
In reply to [email protected]From: Long Li <[email protected]>
When doing memory registration, the PF may respond with GDMA_STATUS_MORE_ENTRIES to indicate a follow request is needed. This is not an error and should be processed as expected.
--- drivers/net/ethernet/microsoft/mana/hw_channel.c | 2 +- include/linux/mana/gdma.h | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-)
drivers/net/ethernet/microsoft/mana/hw_channel.c +1 -1
@@ -820,7 +820,7 @@ int mana_hwc_send_request(struct hw_channel_context *hwc, u32 req_len, goto out; } -if (ctx->status_code) { +if (ctx->status_code && ctx->status_code !=GDMA_STATUS_MORE_ENTRIES ) {dev_err (hwc->dev,"HWC: Failed hw_channel req: 0x%x\n" , ctx->status_code); err = -EPROTO ;
include/linux/mana/gdma.h +2 -0
@@ -9,6 +9,8 @@#include "shm_channel.h" +#define GDMA_STATUS_MORE_ENTRIES ((u32)0x00000105L) +/* Structures labeled with "HW DATA" are exchanged with the hardware. All of * them are naturally aligned and hence don't need __packed. */
Signature · 1 line
2.17.1
PATCH 10/12 net: mana: Define max values for SGL entries
In reply to [email protected]From: Long Li <[email protected]>
The number of maximum SGl entries should be computed from the maximum WQE size for the intended queue type, witj the corresponding OOB data size. This guarantees the hardware queue can successfully queue requests up to the queue depth exposed to the upper layer.
--- drivers/net/ethernet/microsoft/mana/mana_en.c | 2 +- include/linux/mana/gdma.h | 7 +++++++ include/linux/mana/mana.h | 4 +--- 3 files changed, 9 insertions(+), 4 deletions(-)
drivers/net/ethernet/microsoft/mana/mana_en.c +1 -1
@@ -187,7 +187,7 @@ int mana_start_xmit(struct sk_buff *skb, struct net_device *ndev) pkg.wqe_req.client_data_unit =0 ; pkg.wqe_req.num_sge =1 +skb_shinfo (skb)->nr_frags; -WARN_ON_ONCE (pkg.wqe_req.num_sge >30 ); +WARN_ON_ONCE (pkg.wqe_req.num_sge >MAX_TX_WQE_SGL_ENTRIES );if (pkg.wqe_req.num_sge <=ARRAY_SIZE (pkg.sgl_array)) { pkg.wqe_req.sgl = pkg.sgl_array;
include/linux/mana/gdma.h +7 -0
@@ -436,6 +436,13 @@ struct gdma_wqe {#define MAX_TX_WQE_SIZE 512#define MAX_RX_WQE_SIZE 256 +#define MAX_TX_WQE_SGL_ENTRIES ((GDMA_MAX_SQE_SIZE - \ + sizeof(struct gdma_sge) - INLINE_OOB_SMALL_SIZE) / \ + sizeof(struct gdma_sge)) + +#define MAX_RX_WQE_SGL_ENTRIES ((GDMA_MAX_RQE_SIZE - \ + sizeof(struct gdma_sge)) / sizeof(struct gdma_sge)) +struct gdma_cqe {u32 cqe_data[GDMA_COMP_DATA_SIZE /4 ];
include/linux/mana/mana.h +1 -3
@@ -264,8 +264,6 @@ struct mana_cq {int budget; }; -#define GDMA_MAX_RQE_SGES 15 -struct mana_recv_buf_oob {/* A valid GDMA work request representing the data buffer. */ struct gdma_wqe_request wqe_req;
@@ -275,7 +273,7 @@ struct mana_recv_buf_oob {/* SGL of the buffer going to be sent has part of the work request. */ u32 num_sge; -struct gdma_sge sgl[GDMA_MAX_RQE_SGES ]; +struct gdma_sge sgl[MAX_RX_WQE_SGL_ENTRIES ];/* Required to store the result of mana_gd_post_work_request. * gdma_posted_wqe_info.wqe_size_in_bu is required for progressing the
Signature · 1 line
2.17.1
PATCH 4/12 net: mana: Add functions for allocating doorbell page from GDMA
In reply to [email protected]From: Long Li <[email protected]>
The RDMA device needs to allocate doorbell pages for each user context. Implement those functions and expose them for use by the RDMA driver.
--- drivers/net/ethernet/microsoft/mana/gdma.h | 29 ++++++++++ .../net/ethernet/microsoft/mana/gdma_main.c | 54 +++++++++++++++++++ 2 files changed, 83 insertions(+)
drivers/net/ethernet/microsoft/mana/gdma.h +29 -0
@@ -22,11 +22,15 @@ enum gdma_request_type {GDMA_GENERATE_TEST_EQE =10 ,GDMA_CREATE_QUEUE =12 ,GDMA_DISABLE_QUEUE =13 , +GDMA_ALLOCATE_RESOURCE_RANGE =22 , +GDMA_DESTROY_RESOURCE_RANGE =24 ,GDMA_CREATE_DMA_REGION =25 ,GDMA_DMA_REGION_ADD_PAGES =26 , GDMA_DESTROY_DMA_REGION = 27, }; +#define GDMA_RESOURCE_DOORBELL_PAGE 27 +enum gdma_queue_type {GDMA_INVALID_QUEUE , GDMA_SQ,
@@ -568,6 +572,26 @@ struct gdma_register_device_resp {u32 db_id; };/* HW DATA */ +struct gdma_allocate_resource_range_req { +struct gdma_req_hdr hdr; +u32 resource_type; +u32 num_resources; +u32 alignment; +u32 allocated_resources; +}; + +struct gdma_allocate_resource_range_resp { +struct gdma_resp_hdr hdr; +u32 allocated_resources; +}; + +struct gdma_destroy_resource_range_req { +struct gdma_req_hdr hdr; +u32 resource_type; +u32 num_resources; +u32 allocated_resources; +}; +/* GDMA_CREATE_QUEUE */ struct gdma_create_queue_req {struct gdma_req_hdr hdr;
@@ -676,4 +700,9 @@ void mana_gd_free_memory(struct gdma_mem_info *gmi);int mana_gd_send_request (struct gdma_context *gc,u32 req_len,const void *req,u32 resp_len,void *resp); + +int mana_gd_allocate_doorbell_page (struct gdma_context *gc,int *doorbell_page); + +int mana_gd_destroy_doorbell_page (struct gdma_context *gc,int doorbell_page); +#endif /* _GDMA_H */
drivers/net/ethernet/microsoft/mana/gdma_main.c +54 -0
60 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH 3/12 net: mana: Handle vport sharing between devices
In reply to [email protected]From: Long Li <[email protected]>
For outgoing packets, the PF requires the VF to configure the vport with corresponding protection domain and doorbell ID for the kernel or user context. The vport can't be shared between different contexts.
Implement the logic to exclusively take over the vport by either the Ethernet device or RDMA device.
--- drivers/net/ethernet/microsoft/mana/mana.h | 4 ++++ drivers/net/ethernet/microsoft/mana/mana_en.c | 19 +++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-)
drivers/net/ethernet/microsoft/mana/mana.h +4 -0
@@ -375,6 +375,7 @@ struct mana_port_context {unsigned int num_queues;mana_handle_t port_handle; +atomic_t port_use_count;u16 port_idx;
@@ -567,4 +568,7 @@ struct mana_adev { struct gdma_dev *mdev; }; +int mana_cfg_vport (struct mana_port_context *apc,u32 protection_dom_id, +u32 doorbell_pg_id); +void mana_uncfg_vport (struct mana_port_context *apc);#endif /* _MANA_H */
drivers/net/ethernet/microsoft/mana/mana_en.c +17 -2
@@ -530,13 +530,25 @@ static int mana_query_vport_cfg(struct mana_port_context *apc, u32 vport_index,return 0 ; } -static int mana_cfg_vport (struct mana_port_context *apc,u32 protection_dom_id, -u32 doorbell_pg_id) +void mana_uncfg_vport (struct mana_port_context *apc) +{ +atomic_dec (&apc->port_use_count); +} +EXPORT_SYMBOL_GPL (mana_uncfg_vport); + +int mana_cfg_vport (struct mana_port_context *apc,u32 protection_dom_id, +u32 doorbell_pg_id) {struct mana_config_vport_resp resp = {};struct mana_config_vport_req req = {};int err; +/* Ethernet driver and IB driver can't take the port at the same time */ +if (atomic_inc_return (&apc->port_use_count) !=1 ) { +atomic_dec (&apc->port_use_count); +return -ENODEV ; + } +mana_gd_init_req_hdr (&req.hdr,MANA_CONFIG_VPORT_TX ,sizeof (req),sizeof (resp)); req.vport = apc->port_handle;
@@ -566,6 +578,7 @@ static int mana_cfg_vport(struct mana_port_context *apc, u32 protection_dom_id, out:return err; } +EXPORT_SYMBOL_GPL (mana_cfg_vport); static int mana_cfg_vport_steering(struct mana_port_context *apc, enum TRI_STATE rx,
@@ -1678,6 +1691,8 @@ static void mana_destroy_vport(struct mana_port_context *apc) }mana_destroy_txq (apc); + +mana_uncfg_vport (apc); } static int mana_create_vport(struct mana_port_context *apc,
Signature · 1 line
2.17.1
PATCH 2/12 net: mana: Record the physical address for doorbell page region
In reply to [email protected]From: Long Li <[email protected]>
For supporting RDMA device with multiple user contexts with their individual doorbell pages, record the start address of doorbell page region for use by the RDMA driver to allocate user context doorbell IDs.
--- drivers/net/ethernet/microsoft/mana/gdma.h | 2 ++ drivers/net/ethernet/microsoft/mana/gdma_main.c | 4 ++++ 2 files changed, 6 insertions(+)
drivers/net/ethernet/microsoft/mana/gdma.h +2 -0
@@ -350,9 +350,11 @@ struct gdma_context {struct completion eq_test_event;u32 test_event_eq_id; +phys_addr_t bar0_pa;void __iomem *bar0_va;void __iomem *shm_base;void __iomem *db_page_base; +phys_addr_t phys_db_page_base;u32 db_page_size;/* Shared memory chanenl (used to bootstrap HWC) */
drivers/net/ethernet/microsoft/mana/gdma_main.c +4 -0
@@ -27,6 +27,9 @@ static void mana_gd_init_registers(struct pci_dev *pdev) gc->db_page_base = gc->bar0_va +mana_gd_r64 (gc,GDMA_REG_DB_PAGE_OFFSET ); + gc->phys_db_page_base = gc->bar0_pa + +mana_gd_r64 (gc,GDMA_REG_DB_PAGE_OFFSET ); + gc->shm_base = gc->bar0_va +mana_gd_r64 (gc,GDMA_REG_SHM_OFFSET ); }
@@ -1335,6 +1338,7 @@ static int mana_gd_probe(struct pci_dev *pdev, const struct pci_device_id *ent)mutex_init (&gc->eq_test_event_mutex);pci_set_drvdata (pdev, gc); + gc->bar0_pa =pci_resource_start (pdev,0 ); bar0_va =pci_iomap (pdev, bar,0 );if (!bar0_va)
Signature · 1 line
2.17.1
PATCH 1/12 net: mana: Add support for auxiliary device
In reply to [email protected]From: Long Li <[email protected]>
In preparation for supporting MANA RDMA driver, add support for auxiliary device in the Ethernet driver. The RDMA device is modeled as an auxiliary device to the Ethernet device.
--- drivers/net/ethernet/microsoft/mana/gdma.h | 2 + drivers/net/ethernet/microsoft/mana/mana.h | 6 ++ drivers/net/ethernet/microsoft/mana/mana_en.c | 83 ++++++++++++++++++- 3 files changed, 90 insertions(+), 1 deletion(-)
drivers/net/ethernet/microsoft/mana/gdma.h +2 -0
@@ -204,6 +204,8 @@ struct gdma_dev {/* GDMA driver specific pointer */ void *driver_data; + +struct auxiliary_device *adev; };#define MINIMUM_SUPPORTED_PAGE_SIZE PAGE_SIZE
drivers/net/ethernet/microsoft/mana/mana.h +6 -0
@@ -6,6 +6,7 @@#include "gdma.h" #include "hw_channel.h" +#include <linux/auxiliary_bus.h> /* Microsoft Azure Network Adapter (MANA)'s definitions *
@@ -561,4 +562,9 @@ struct mana_tx_package { struct gdma_posted_wqe_info wqe_info; }; +struct mana_adev { +struct auxiliary_device adev; +struct gdma_dev *mdev; +}; +#endif /* _MANA_H */
drivers/net/ethernet/microsoft/mana/mana_en.c +82 -1
113 lines not on this page · raw message
Signature · 1 line
2.17.1
Re: [PATCH 05/12] net: mana: Set the DMA device max page size
In reply to [email protected]Quoted 8 lines · On Tue, May 17, 2022 at 02:04:29AM -0700, [email protected] wrote:
From: Long Li <[email protected]>
The system chooses default 64K page size if the device does not specify the max page size the device can handle for DMA. This do not work well when device is registering large chunk of memory in that a large page size is more efficient.
Set it to the maximum hardware supported page size.
For RDMA devices this should be set to the largest segment size an ib_sge can take in when posting work. It should not be the page size of MR. 2M is a weird number for that, are you sure it is right?
Jason
Re: [PATCH 09/12] net: mana: Move header files to a common location
In reply to [email protected]Quoted 15 lines · On Tue, May 17, 2022 at 02:04:33AM -0700, [email protected] wrote:
From: Long Li <[email protected]>
In preparation to add MANA RDMA driver, move all the required header files to a common location for use by both Ethernet and RDMA drivers.
Signed-off-by Long Li <[email protected]>--- MAINTAINERS | 1 + drivers/net/ethernet/microsoft/mana/gdma_main.c | 2 +- drivers/net/ethernet/microsoft/mana/hw_channel.c | 4 ++-- drivers/net/ethernet/microsoft/mana/mana_bpf.c | 2 +- drivers/net/ethernet/microsoft/mana/mana_en.c | 2 +- drivers/net/ethernet/microsoft/mana/mana_ethtool.c | 2 +- drivers/net/ethernet/microsoft/mana/shm_channel.c | 2 +- {drivers/net/ethernet/microsoft => include/linux}/mana/gdma.h | 0
Quoted 8 lines
.../ethernet/microsoft => include/linux}/mana/hw_channel.h | 0
{drivers/net/ethernet/microsoft => include/linux}/mana/mana.h | 0
.../ethernet/microsoft => include/linux}/mana/shm_channel.h | 0
11 files changed, 8 insertions(+), 7 deletions(-)
rename {drivers/net/ethernet/microsoft => include/linux}/mana/gdma.h (100%)
rename {drivers/net/ethernet/microsoft => include/linux}/mana/hw_channel.h (100%)
rename {drivers/net/ethernet/microsoft => include/linux}/mana/mana.h (100%)
rename {drivers/net/ethernet/microsoft => include/linux}/mana/shm_channel.h (100%)I know mlx5 did it like this, but I wonder if include/net is more appropriate?
Or maybe include/aux/?
Jason
Re: [PATCH 03/12] net: mana: Handle vport sharing between devices
In reply to [email protected]drivers/net/ethernet/microsoft/mana/mana.h struct mana_port_context { · line 378
Quoted 9 lines · On Tue, 17 May 2022 02:04:27 -0700 [email protected] wrote:
drivers/net/ethernet/microsoft/mana/mana.h +1
-0@@ -375,6 +375,7 @@ struct mana_port_context {unsigned int num_queues;mana_handle_t port_handle; +atomic_t port_use_count;
Could this be a refcount_t instead?
The refcount_t has protections against under/overflow.
Re: [PATCH 12/12] RDMA/mana_ib: Add a driver for Microsoft Azure Network Adapter
In reply to [email protected]Quoted 3 lines · On Tue, May 17, 2022 at 02:04:36AM -0700, [email protected] wrote:
From: Long Li <[email protected]>
Add a RDMA VF driver for Microsoft Azure Network Adapter (MANA).
To set exepecation, we are currently rc7, so this will not make this merge window. You will need to repost on the next rc1 in three weeks.
Quoted 11 lines
new file mode 100644
index 000000000000..0eac77c97658drivers/infiniband/hw/mana/cq.c new file +6
-0@@ -0,0 +1,74 @@ +// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB +/* +* Copyright (c) 2022, Microsoft Corporation. All rights reserved. +*/ + +#include "mana_ib.h"
drivers/infiniband/hw/mana/cq.c line 16
Quoted 10 lines
drivers/infiniband/hw/mana/cq.c new file +10
-0+ +int mana_ib_create_cq (struct ib_cq *ibcq,const struct ib_cq_init_attr *attr, +struct ib_udata *udata) +{ +struct mana_ib_create_cq ucmd = {}; +struct ib_device *ibdev = ibcq->device; +struct mana_ib_dev *mdev = + container_of(ibdev, struct mana_ib_dev, ib_dev); + struct mana_ib_cq *cq = container_of(ibcq, struct mana_ib_cq, ibcq); +int err;
We do try to follow the netdev formatting, christmas trees and all that.
drivers/infiniband/hw/mana/cq.c line 18
Quoted 2 lines
drivers/infiniband/hw/mana/cq.c new file +2
-0+ + err =ib_copy_from_udata (&ucmd, udata,min (sizeof (ucmd), udata->inlen));
Skeptical this min is correct, many other drivers get this wrong.
drivers/infiniband/hw/mana/cq.c line 20
Quoted 2 lines
drivers/infiniband/hw/mana/cq.c new file +2
-0+if (err) { +pr_err ("Failed to copy from udata for create cq, %d\n" , err);
Do not use pr_* - you should use one of the dev specific varients inside a device driver. In this case ibdev_dbg
Also, do not ever print to the console on a user triggerable event such as this. _dbg would be OK.
Scrub the driver for all occurances.
drivers/infiniband/hw/mana/cq.c line 30
Quoted 1 line
drivers/infiniband/hw/mana/cq.c new file +1
-0+pr_debug ("ucmd buf_addr 0x%llx\n" , ucmd.buf_addr);
I'm not keen on left over debugging please, in fact there are way too many prints..
drivers/infiniband/hw/mana/cq.c line 34
Quoted 3 lines
drivers/infiniband/hw/mana/cq.c new file +3
-0+ cq->umem =ib_umem_get (ibdev, ucmd.buf_addr, + cq->cqe *COMP_ENTRY_SIZE , +IB_ACCESS_LOCAL_WRITE );
Please touch the file with clang-format and take all the things that look good to you
Quoted 10 lines
drivers/infiniband/hw/mana/main.c new file +4
-0@@ -0,0 +1,679 @@ +// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB +/* +* Copyright (c) 2022, Microsoft Corporation. All rights reserved. +*/
drivers/infiniband/hw/mana/main.c line 14
Quoted 10 lines
drivers/infiniband/hw/mana/main.c new file +10
-0+ +#include "mana_ib.h" + +MODULE_DESCRIPTION ("Microsoft Azure Network Adapter IB driver" ); +MODULE_LICENSE ("Dual BSD/GPL" ); + +static const struct auxiliary_device_id mana_id_table[] = { + { .name ="mana.rdma" , }, + {}, +};
stylistically this stuff is usually at the bottom of the file, right before its first use
drivers/infiniband/hw/mana/main.c line 150
Quoted 12 lines
drivers/infiniband/hw/mana/main.c new file +12
-0+static inline enum atb_page_size mana_ib_get_atb_page_size (u64 page_sz) +{ +int pos =0 ; + + page_sz = (page_sz >>12 );//start with 4k + +while (page_sz) { + pos++; + page_sz = (page_sz >>1 ); + } +return (enum atb_page_size )(pos -1 ); +}
Isn't this ffs, log, or something that isn't a while loop?
Quoted 11 lines
drivers/infiniband/hw/mana/main.c new file +11
-0+static int _mana_ib_gd_create_dma_region (struct mana_ib_dev *dev, +const dma_addr_t *page_addr_array, +size_t num_pages_total, +u64 address,u64 length, +mana_handle_t *gdma_region, +u64 page_sz) +{ +struct gdma_dev *mdev = dev->gdma_dev; +struct gdma_context *gc = mdev->gdma_context; +struct hw_channel_context *hwc = gc->hwc.driver_data; +size_t num_pages_cur, num_pages_to_handle;
drivers/infiniband/hw/mana/main.c line 172
Quoted 10 lines
drivers/infiniband/hw/mana/main.c new file +10
-0+unsigned int create_req_msg_size; +unsigned int i; +struct gdma_dma_region_add_pages_req *add_req =NULL ; +int err; + +struct gdma_create_dma_region_req *create_req; +struct gdma_create_dma_region_resp create_resp = {}; + +size_t max_pgs_create_cmd = (hwc->max_req_msg_size - +sizeof (*create_req)) /sizeof (u64);
These extra blank lines are not kernel style, please check everything.
Quoted 22 lines
drivers/infiniband/hw/mana/main.c new file +22
-0+ num_pages_to_handle =min_t (size_t, num_pages_total, + max_pgs_create_cmd); + create_req_msg_size =struct_size (create_req, page_addr_list, + num_pages_to_handle); + + create_req =kzalloc (create_req_msg_size,GFP_KERNEL ); +if (!create_req) +return -ENOMEM ; + +mana_gd_init_req_hdr (&create_req->hdr,GDMA_CREATE_DMA_REGION , + create_req_msg_size,sizeof (create_resp)); + + create_req->length = length; + create_req->offset_in_page = address & (page_sz -1 ); + create_req->gdma_page_type =mana_ib_get_atb_page_size (page_sz); + create_req->page_count = num_pages_total; + create_req->page_addr_list_len = num_pages_to_handle; + +pr_debug ("size_dma_region %llu num_pages_total %lu, " +"page_sz 0x%llx offset_in_page %u\n" , + length, num_pages_total, page_sz, create_req->offset_in_page); +
drivers/infiniband/hw/mana/main.c line 205
Quoted 10 lines
drivers/infiniband/hw/mana/main.c new file +10
-0+pr_debug ("num_pages_to_handle %lu, gdma_page_type %u" , + num_pages_to_handle, create_req->gdma_page_type); + +for (i =0 ; i < num_pages_to_handle; ++i) { +dma_addr_t cur_addr = page_addr_array[i]; + + create_req->page_addr_list[i] = cur_addr; + +pr_debug ("page num %u cur_addr 0x%llx\n" , i, cur_addr); + }
Er, so we allocated memory and wrote the DMA addresses now you copy them to another memory?
Quoted 53 lines
drivers/infiniband/hw/mana/main.c new file +53
-0+ + err =mana_gd_send_request (gc, create_req_msg_size, create_req, +sizeof (create_resp), &create_resp); +kfree (create_req); + +if (err || create_resp.hdr.status) { +dev_err (gc->dev,"Failed to create DMA region: %d, 0x%x\n" , + err, create_resp.hdr.status); + goto error; + } + + *gdma_region = create_resp.dma_region_handle; +pr_debug ("Created DMA region with handle 0x%llx\n" , *gdma_region); + + num_pages_cur = num_pages_to_handle; + +if (num_pages_cur < num_pages_total) { + +unsigned int add_req_msg_size; +size_t max_pgs_add_cmd = (hwc->max_req_msg_size - +sizeof (*add_req)) /sizeof (u64); + + num_pages_to_handle =min_t (size_t, + num_pages_total - num_pages_cur, + max_pgs_add_cmd); + +// Calculate the max num of pages that will be handled + add_req_msg_size =struct_size (add_req, page_addr_list, + num_pages_to_handle); + + add_req =kmalloc (add_req_msg_size,GFP_KERNEL ); +if (!add_req) { + err = -ENOMEM ; + goto error; + } + +while (num_pages_cur < num_pages_total) { +struct gdma_general_resp add_resp = {}; +u32 expected_status; +int expected_ret; + +if (num_pages_cur + num_pages_to_handle < + num_pages_total) { +// This value means that more pages are needed + expected_status =GDMA_STATUS_MORE_ENTRIES ; + expected_ret =0x0 ; + }else { + expected_status =0x0 ; + expected_ret =0x0 ; + } + +memset (add_req,0 , add_req_msg_size); +
drivers/infiniband/hw/mana/main.c line 268
Quoted 10 lines
drivers/infiniband/hw/mana/main.c new file +10
-0+mana_gd_init_req_hdr (&add_req->hdr, +GDMA_DMA_REGION_ADD_PAGES , + add_req_msg_size, +sizeof (add_resp)); + add_req->dma_region_handle = *gdma_region; + add_req->page_addr_list_len = num_pages_to_handle; + +for (i =0 ; i < num_pages_to_handle; ++i) { +dma_addr_t cur_addr = + page_addr_array[num_pages_cur + i];
And then again?
That isn't how this is supposed to work, you should iterate over the umem in one pass and split up the output as you go. Allocating potentially giant temporary arrays should be avoided.
Quoted 27 lines
drivers/infiniband/hw/mana/main.c new file +27
-0+ add_req->page_addr_list[i] = cur_addr; + +pr_debug ("page_addr_list %lu addr 0x%llx\n" , + num_pages_cur + i, cur_addr); + } + + err =mana_gd_send_request (gc, add_req_msg_size, + add_req,sizeof (add_resp), + &add_resp); +if (err != expected_ret || + add_resp.hdr.status != expected_status) { +dev_err (gc->dev, +"Failed to put DMA pages %u: %d,0x%x\n" , + i, err, add_resp.hdr.status); + err = -EPROTO ; + goto free_req; + } + + num_pages_cur += num_pages_to_handle; + num_pages_to_handle =min_t (size_t, + num_pages_total - + num_pages_cur, + max_pgs_add_cmd); + add_req_msg_size =sizeof (*add_req) + + num_pages_to_handle *sizeof (u64); + } +free_req:
drivers/infiniband/hw/mana/main.c line 306
Quoted 10 lines
drivers/infiniband/hw/mana/main.c new file +10
-0+kfree (add_req); + } + +error: +return err; +} + + +int mana_ib_gd_create_dma_region (struct mana_ib_dev *dev,struct ib_umem *umem, +mana_handle_t *dma_region_handle,u64 page_sz)
Since this takes in a umem it should also compute the page_sz for that umem.
I see this driver seems to have various limitations, so the input argument here should be the pgsz bitmask that is compatible with the object being created.
Quoted 4 lines
drivers/infiniband/hw/mana/main.c new file +4
-0+{ +size_t num_pages =ib_umem_num_dma_blocks (umem, page_sz); +struct ib_block_iter biter; +dma_addr_t *page_addr_array;
drivers/infiniband/hw/mana/main.c line 320
Quoted 10 lines
drivers/infiniband/hw/mana/main.c new file +10
-0+unsigned int i =0 ; +int err; + +pr_debug ("num pages %lu umem->address 0x%lx\n" , + num_pages, umem->address); + + page_addr_array =kmalloc_array (num_pages, +sizeof (*page_addr_array),GFP_KERNEL ); +if (!page_addr_array) +return -ENOMEM ;
This will OOM easily, num_pages is user controlled.
Quoted 22 lines
drivers/infiniband/hw/mana/main.c new file +22
-0+ +rdma_umem_for_each_dma_block (umem, &biter, page_sz) + page_addr_array[i++] =rdma_block_iter_dma_address (&biter); + + err =_mana_ib_gd_create_dma_region (dev, page_addr_array, num_pages, + umem->address, umem->length, + dma_region_handle, page_sz); + +kfree (page_addr_array); + +return err; +} +int mana_ib_gd_create_pd (struct mana_ib_dev *dev,u64 *pd_handle,u32 *pd_id, +enum gdma_pd_flags flags) +{ +struct gdma_dev *mdev = dev->gdma_dev; +struct gdma_context *gc = mdev->gdma_context; +int err; + +struct gdma_create_pd_req req = {}; +struct gdma_create_pd_resp resp = {}; +
drivers/infiniband/hw/mana/main.c line 363
Quoted 10 lines
drivers/infiniband/hw/mana/main.c new file +10
-0+mana_gd_init_req_hdr (&req.hdr,GDMA_CREATE_PD , +sizeof (req),sizeof (resp)); + + req.flags = flags; + err =mana_gd_send_request (gc,sizeof (req), &req,sizeof (resp), &resp); + +if (!err && !resp.hdr.status) { + *pd_handle = resp.pd_handle; + *pd_id = resp.pd_id; +pr_debug ("pd_handle 0x%llx pd_id %d\n" , *pd_handle, *pd_id);
Kernel style is 'success oriented flow':
if (err) {
return err; }
// success
return 0;
Audit everything
drivers/infiniband/hw/mana/main.c line 492
Quoted 11 lines
drivers/infiniband/hw/mana/main.c new file +11
-0+static int mana_ib_mmap (struct ib_ucontext *ibcontext,struct vm_area_struct *vma) +{ +struct mana_ib_ucontext *mana_ucontext = + container_of(ibcontext, struct mana_ib_ucontext, ibucontext); +struct ib_device *ibdev = ibcontext->device; +struct mana_ib_dev *mdev = + container_of(ibdev, struct mana_ib_dev, ib_dev); +struct gdma_context *gc = mdev->gdma_dev->gdma_context; +pgprot_t prot; +phys_addr_t pfn; +int ret;
This needs to validate vma->pgoff
drivers/infiniband/hw/mana/main.c line 494
Quoted 1 line
drivers/infiniband/hw/mana/main.c new file +1
-0+// map to the page indexed by ucontext->doorbell
Not kernel style, be sure to run checkpatch and fix the egregious things.
drivers/infiniband/hw/mana/main.c line 560
Quoted 3 lines
drivers/infiniband/hw/mana/main.c new file +3
-0+static void mana_ib_disassociate_ucontext (struct ib_ucontext *ibcontext) +{ +}
Does this driver actually support disassociate? Don't define this function if it doesn't.
I didn't see any mmap zapping so I guess it doesn't.
Quoted 26 lines
drivers/infiniband/hw/mana/main.c new file +26
-0+static const struct ib_device_ops mana_ib_dev_ops = { + .owner =THIS_MODULE , + .driver_id =RDMA_DRIVER_MANA , + .uverbs_abi_ver =MANA_IB_UVERBS_ABI_VERSION , + + .alloc_pd = mana_ib_alloc_pd, + .dealloc_pd = mana_ib_dealloc_pd, + + .alloc_ucontext = mana_ib_alloc_ucontext, + .dealloc_ucontext = mana_ib_dealloc_ucontext, + + .create_cq = mana_ib_create_cq, + .destroy_cq = mana_ib_destroy_cq, + + .create_qp = mana_ib_create_qp, + .modify_qp = mana_ib_modify_qp, + .destroy_qp = mana_ib_destroy_qp, + + .disassociate_ucontext = mana_ib_disassociate_ucontext, + + .mmap = mana_ib_mmap, + + .reg_user_mr = mana_ib_reg_user_mr, + .dereg_mr = mana_ib_dereg_mr, + + .create_wq = mana_ib_create_wq,
drivers/infiniband/hw/mana/main.c line 597
Quoted 10 lines
drivers/infiniband/hw/mana/main.c new file +10
-0+ .modify_wq = mana_ib_modify_wq, + .destroy_wq = mana_ib_destroy_wq, + + .create_rwq_ind_table = mana_ib_create_rwq_ind_table, + .destroy_rwq_ind_table = mana_ib_destroy_rwq_ind_table, + + .get_port_immutable = mana_ib_get_port_immutable, + .query_device = mana_ib_query_device, + .query_port = mana_ib_query_port, + .query_gid = mana_ib_query_gid,
Usually drivers are just sorting this list
drivers/infiniband/hw/mana/main.c line 281
Quoted 5 lines
drivers/infiniband/hw/mana/main.c new file +5
-0+#define PAGE_SZ_BM (SZ_4K | SZ_8K | SZ_16K | SZ_32K | SZ_64K | SZ_128K \ + | SZ_256K | SZ_512K | SZ_1M | SZ_2M) + +// Maximum size of a memory registration is 1G bytes +#define MANA_IB_MAX_MR_SIZE (1024 * 1024 * 1024)
Even with large pages? Weird limit..
You also need to open a PR to the rdma-core github with the userspace for this and pyverbs test suite support
Thanks,
Jason
RE: [PATCH 05/12] net: mana: Set the DMA device max page size
In reply to Jason GunthorpeQuoted 10 lines
Subject: Re: [PATCH 05/12] net: mana: Set the DMA device max page size
Quoted 7 lines · On Tue, May 17, 2022 at 02:04:29AM -0700, [email protected] wrote:
From: Long Li <[email protected]>
The system chooses default 64K page size if the device does not specify the max page size the device can handle for DMA. This do not work well when device is registering large chunk of memory in that a large page size is more efficient.
Quoted 5 lines
Quoted 1 line
Set it to the maximum hardware supported page size.
For RDMA devices this should be set to the largest segment size an
ib_sgecan take in when posting work. It should not be the page size of MR. 2M is a weird number for that, are you sure it is right?
Yes, this is the maximum page size used in hardware page tables.
Long
Quoted 2 lines
Jason
Re: [PATCH 05/12] net: mana: Set the DMA device max page size
Quoted 10 lines · Long Li
Quoted 10 lines
Subject: Re: [PATCH 05/12] net: mana: Set the DMA device max page size
Quoted 7 lines · On Tue, May 17, 2022 at 02:04:29AM -0700, [email protected] wrote:
From: Long Li <[email protected]>
The system chooses default 64K page size if the device does not specify the max page size the device can handle for DMA. This do not work well when device is registering large chunk of memory in that a large page size is more efficient.
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
Set it to the maximum hardware supported page size.
For RDMA devices this should be set to the largest segment size an
ib_sgecan take in when posting work. It should not be the page size of MR. 2M is a weird number for that, are you sure it is right?Yes, this is the maximum page size used in hardware page tables.
As I said, it should be the size of the sge in the WQE, not the "hardware page tables"
Jason
RE: [PATCH 09/12] net: mana: Move header files to a common location
In reply to Jason GunthorpeQuoted 29 lines
Subject: Re: [PATCH 09/12] net: mana: Move header files to a common location
Quoted 19 lines · On Tue, May 17, 2022 at 02:04:33AM -0700, [email protected] wrote:
From: Long Li <[email protected]>
In preparation to add MANA RDMA driver, move all the required header files to a common location for use by both Ethernet and RDMA drivers.
Signed-off-by Long Li <[email protected]>--- MAINTAINERS | 1 + drivers/net/ethernet/microsoft/mana/gdma_main.c | 2 +- drivers/net/ethernet/microsoft/mana/hw_channel.c | 4 ++-- drivers/net/ethernet/microsoft/mana/mana_bpf.c | 2 +- drivers/net/ethernet/microsoft/mana/mana_en.c | 2 +- drivers/net/ethernet/microsoft/mana/mana_ethtool.c | 2 +- drivers/net/ethernet/microsoft/mana/shm_channel.c | 2 +- {drivers/net/ethernet/microsoft => include/linux}/mana/gdma.h | 0 .../ethernet/microsoft => include/linux}/mana/hw_channel.h | 0 {drivers/net/ethernet/microsoft => include/linux}/mana/mana.h | 0 .../ethernet/microsoft => include/linux}/mana/shm_channel.h | 0 11 files changed, 8 insertions(+), 7 deletions(-) renameQuoted 6 lines
{
drivers/net/ethernet/microsoft=>include/linux}/mana/gdma.h(100%) rename {drivers/net/ethernet/microsoft=>include/linux}/mana/hw_channel.h(100%) rename {drivers/net/ethernet/microsoft=>include/linux}/mana/mana.h(100%) rename {drivers/net/ethernet/microsoft=>include/linux}/mana/shm_channel.h(100%)
Quoted 3 lines
I know mlx5 did it like this, but I wonder if
include/netis more appropriate?Or maybe
include/aux/?
I can move the header files to include/net/mana, if that sounds okay and no objection to doing that.
Long
Quoted 2 lines
Jason
RE: [PATCH 05/12] net: mana: Set the DMA device max page size
In reply to Jason GunthorpeQuoted 17 lines
Subject: Re: [PATCH 05/12] net: mana: Set the DMA device max page size
Quoted 4 lines · Long Li
Quoted 4 lines
Subject: Re: [PATCH 05/12] net: mana: Set the DMA device max page size
On Tue, May 17, 2022 at 02:04:29AM -0700, [email protected]
Quoted 9 lines · wrote:
Quoted 9 lines
Quoted 8 lines
From: Long Li <[email protected]>
The system chooses default 64K page size if the device does not specify the max page size the device can handle for DMA. This do not work well when device is registering large chunk of memory in that a large page size is more efficient.
Set it to the maximum hardware supported page size.
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
For RDMA devices this should be set to the largest segment size an
ib_sgecan take in when posting work. It should not be the page size of MR. 2M is a weird number for that, are you sure it is right?Yes, this is the maximum page size used in hardware page tables.
As I said, it should be the size of the sge in the WQE, not the "hardware page tables"
This driver uses the following code to figure out the largest page size for memory registration with hardware:
page_sz = ib_umem_find_best_pgsz(mr->umem, PAGE_SZ_BM, iova);
In this function, mr->umem is created with ib_dma_max_seg_size() as its max segment size when creating its sgtable.
The purpose of setting DMA page size to 2M is to make sure this function returns the largest possible MR size that the hardware can take. Otherwise, this function will return 64k: the default DMA size.
Long
Quoted 2 lines
Jason
RE: [PATCH 03/12] net: mana: Handle vport sharing between devices
In reply to Stephen HemmingerQuoted 13 lines
Subject: Re: [PATCH 03/12] net: mana: Handle vport sharing between devices
Review
Quoted 1 line · On Tue, 17 May 2022 02:04:27 -0700 [email protected] wrote:
(quoted diff) +0
-0
b/drivers/net/ethernet/microsoft/mana/mana.hQuoted 6 lines
index
51bff91b63ee..26f14fcb6a61100644drivers/net/ethernet/microsoft/mana/mana.h +0
-0@@ -375,6 +375,7 @@ struct mana_port_context {unsigned int num_queues;
Quoted 5 lines
drivers/net/ethernet/microsoft/mana/mana.h struct mana_port_context { · line 378
Quoted 2 lines
drivers/net/ethernet/microsoft/mana/mana.h +1
-0mana_handle_t port_handle; +atomic_t port_use_count;Could this be a
refcount_tinstead?
Therefcount_thas protections against under/overflow.
Thanks for pointing this out. I will use refcount_t for v2.
Long
kernel test robot
build botRe: [PATCH 12/12] RDMA/mana_ib: Add a driver for Microsoft Azure Network Adapter
In reply to [email protected]I love your patch! Yet something to improve:
Hi,
I love your patch! Yet something to improve:
[auto build test ERROR on linus/master]
[also build test ERROR on v5.18-rc7 next-20220517]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/intel-lab-lkp/linux/commits/longli-linuxonhyperv-com/Introduce-Microsoft-Azure-Network-Adapter-MANA-RDMA-driver/20220517-170632 base: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 42226c989789d8da4af1de0c31070c96726d990c config: x86_64-randconfig-a011-20220516 (https://download.01.org/0day-ci/archive/20220518/[email protected]/config) compiler: gcc-11 (Debian 11.2.0-20) 11.2.0 reproduce (this is a W=1 build): # https://github.com/intel-lab-lkp/linux/commit/f082dc68ab65c498c978d574e62413d50286b4f9 git remote add linux-review https://github.com/intel-lab-lkp/linux git fetch --no-tags linux-review longli-linuxonhyperv-com/Introduce-Microsoft-Azure-Network-Adapter-MANA-RDMA-driver/20220517-170632 git checkout f082dc68ab65c498c978d574e62413d50286b4f9 # save the config file mkdir build_dir && cp config build_dir/.config make W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
In file included from <command-line>:
>> ./usr/include/rdma/mana-abi.h:12:10: fatal error: linux/mana/mana.h: No such file or directory
12 | #include <linux/mana/mana.h>
| ^~~~~~~~~~~~~~~~~~~compilation terminated.
Signature · 2 lines
0-DAY CI Kernel Test Service https://01.org/lkp
Re: [PATCH 05/12] net: mana: Set the DMA device max page size
In reply to Long LiQuoted 31 lines · Long Li
Quoted 17 lines
Subject: Re: [PATCH 05/12] net: mana: Set the DMA device max page size
Quoted 4 lines · Long Li
Quoted 4 lines
Subject: Re: [PATCH 05/12] net: mana: Set the DMA device max page size
On Tue, May 17, 2022 at 02:04:29AM -0700, [email protected]
Quoted 9 lines · wrote:
Quoted 9 lines
Quoted 8 lines
From: Long Li <[email protected]>
The system chooses default 64K page size if the device does not specify the max page size the device can handle for DMA. This do not work well when device is registering large chunk of memory in that a large page size is more efficient.
Set it to the maximum hardware supported page size.
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
For RDMA devices this should be set to the largest segment size an
ib_sgecan take in when posting work. It should not be the page size of MR. 2M is a weird number for that, are you sure it is right?Yes, this is the maximum page size used in hardware page tables.
As I said, it should be the size of the sge in the WQE, not the "hardware page tables"
This driver uses the following code to figure out the largest page size for memory registration with hardware:
page_sz=ib_umem_find_best_pgsz(mr->umem, PAGE_SZ_BM, iova);
Quoted 7 lines
In this function,
mr->umemis created withib_dma_max_seg_size()as its max segment size when creating its sgtable.The purpose of setting DMA page size to 2M is to make sure this function returns the largest possible MR size that the hardware can take. Otherwise, this function will return 64k: the default DMA size.
As I've already said, you are supposed to set the value that limits to ib_sge and *NOT* the value that is related to ib_umem_find_best_pgsz. It is usually 2G because the ib_sge's typically work on a 32 bit length.
Jason
kernel test robot
build botRe: [PATCH 12/12] RDMA/mana_ib: Add a driver for Microsoft Azure Network Adapter
In reply to [email protected]I love your patch! Yet something to improve:
Hi,
I love your patch! Yet something to improve:
[auto build test ERROR on linus/master]
[also build test ERROR on v5.18-rc7 next-20220517]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/intel-lab-lkp/linux/commits/longli-linuxonhyperv-com/Introduce-Microsoft-Azure-Network-Adapter-MANA-RDMA-driver/20220517-170632 base: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 42226c989789d8da4af1de0c31070c96726d990c config: x86_64-randconfig-a002-20220516 (https://download.01.org/0day-ci/archive/20220518/[email protected]/config) compiler: clang version 15.0.0 (https://github.com/llvm/llvm-project 853fa8ee225edf2d0de94b0dcbd31bea916e825e)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/f082dc68ab65c498c978d574e62413d50286b4f9
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review longli-linuxonhyperv-com/Introduce-Microsoft-Azure-Network-Adapter-MANA-RDMA-driver/20220517-170632 git checkout f082dc68ab65c498c978d574e62413d50286b4f9
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
In file included from <built-in>:1:
>> ./usr/include/rdma/mana-abi.h:12:10: fatal error: 'linux/mana/mana.h' file not found
#include <linux/mana/mana.h>
^~~~~~~~~~~~~~~~~~~1 error generated.
Signature · 2 lines
0-DAY CI Kernel Test Service https://01.org/lkp
RE: [EXTERNAL] Re: [PATCH 05/12] net: mana: Set the DMA device max page size
In reply to Jason GunthorpeThanks Long.
Hello Jason,
I am the author of the patch.
To your comment below :
" As I've already said, you are supposed to set the value that limits to ib_sge and *NOT* the value that is related to ib_umem_find_best_pgsz. It is usually 2G because the ib_sge's typically work on a 32 bit length."
The ib_sge is limited by the __sg_alloc_table_from_pages() which uses ib_dma_max_seg_size() which is what is set by the eth driver using dma_set_max_seg_size() . Currently our hw does not support PTEs larger than 2M.
So ib_umem_find_best_pgsz() takes as an input PG_SZ_BITMAP . The bitmap has all the bits set for the page sizes supported by the HW.
#define PAGE_SZ_BM (SZ_4K | SZ_8K | SZ_16K | SZ_32K | SZ_64K | SZ_128K \ | SZ_256K | SZ_512K | SZ_1M | SZ_2M)
Are you suggesting we are too restrictive in the bitmap we are passing ? or that we should not set this bitmap let the function choose default ?
Regards,
Ajay
-----Original Message-----
From: Jason Gunthorpe <[email protected]>
Sent: Tuesday, May 17, 2022 5:04 PM
To: Long Li <[email protected]>
Cc: Ajay Sharma <[email protected]>; KY Srinivasan <[email protected]>; Haiyang Zhang <[email protected]>; Stephen Hemminger <[email protected]>; Wei Liu <[email protected]>; Dexuan Cui <[email protected]>; David S. Miller <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>; Leon Romanovsky <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Subject: [EXTERNAL] Re: [PATCH 05/12] net: mana: Set the DMA device max page size
[You don't often get email from [email protected]. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification.]
Quoted 31 lines · Long Li
Quoted 19 lines
Subject: Re: [PATCH 05/12] net: mana: Set the DMA device max page size
Quoted 5 lines · Long Li
Quoted 5 lines
Subject: Re: [PATCH 05/12] net: mana: Set the DMA device max page size
On Tue, May 17, 2022 at 02:04:29AM -0700,
[email protected]Quoted 9 lines · wrote:
Quoted 9 lines
Quoted 8 lines
From: Long Li <[email protected]>
The system chooses default 64K page size if the device does not specify the max page size the device can handle for DMA. This do not work well when device is registering large chunk of memory in that a large page size is more efficient.
Set it to the maximum hardware supported page size.
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
For RDMA devices this should be set to the largest segment size an
ib_sgecan take in when posting work. It should not be the page size of MR. 2M is a weird number for that, are you sure it is right?Yes, this is the maximum page size used in hardware page tables.
As I said, it should be the size of the sge in the WQE, not the "hardware page tables"
This driver uses the following code to figure out the largest page size for memory registration with hardware:
Quoted 8 lines
page_sz=ib_umem_find_best_pgsz(mr->umem, PAGE_SZ_BM, iova);In this function,
mr->umemis created withib_dma_max_seg_size()as its max segment size when creating its sgtable.The purpose of setting DMA page size to 2M is to make sure this function returns the largest possible MR size that the hardware can take. Otherwise, this function will return 64k: the default DMA size.
As I've already said, you are supposed to set the value that limits to ib_sge and *NOT* the value that is related to ib_umem_find_best_pgsz. It is usually 2G because the ib_sge's typically work on a 32 bit length.
Jason
Re: [EXTERNAL] Re: [PATCH 05/12] net: mana: Set the DMA device max page size
Quoted 10 lines · Ajay Sharma
Thanks Long.
Hello Jason,
I am the author of the patch.
To your comment below :
" As I've already said, you are supposed to set the value that limits toib_sgeand *NOT* the value that is related toib_umem_find_best_pgsz. It is usually 2G because the ib_sge's typically work on a 32 bit length."The
ib_sgeis limited by the__sg_alloc_table_from_pages()which usesib_dma_max_seg_size()which is what is set by the eth driver usingdma_set_max_seg_size(). Currently our hw does not support PTEs larger than 2M.
*sigh* again it has nothing to do with *PTEs* in the HW.
Jason
RE: [EXTERNAL] Re: [PATCH 05/12] net: mana: Set the DMA device max page size
Sorry , I am not able to follow. Below is the reference efa driver implementation :
static int efa_device_init(struct efa_com_dev *edev, struct pci_dev *pdev)
{
int dma_width;
int err;
err = efa_com_dev_reset(edev, EFA_REGS_RESET_NORMAL);
if (err)
return err;
err = efa_com_validate_version(edev);
if (err)
return err;
dma_width = efa_com_get_dma_width(edev);
if (dma_width < 0) {
err = dma_width;
return err;
}
err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(dma_width));
if (err) {
dev_err(&pdev->dev, "dma_set_mask_and_coherent failed %d\n", err);
return err;
}
dma_set_max_seg_size(&pdev->dev, UINT_MAX);
return 0;
}static int efa_register_mr(struct ib_pd *ibpd, struct efa_mr *mr, u64 start,
u64 length, u64 virt_addr, int access_flags)
{
struct efa_dev *dev = to_edev(ibpd->device);
struct efa_com_reg_mr_params params = {};
struct efa_com_reg_mr_result result = {};
struct pbl_context pbl;
unsigned int pg_sz;
int inline_size;
int err;
params.pd = to_epd(ibpd)->pdn;
params.iova = virt_addr;
params.mr_length_in_bytes = length;
params.permissions = access_flags;
pg_sz = ib_umem_find_best_pgsz(mr->umem,
dev->dev_attr.page_size_cap,
virt_addr);....
}
Ideally we would like to read it from HW, but currently we are hardcoding the bitmap. I can change the commit message if you feel that is misleading . Something along the lines :
RDMA/mana: Use API to get contiguous memory blocks aligned to device supported page size
Use the ib_umem_find_best_pgsz() and rdma_for_each_block() API when registering an MR instead of coding it in the driver.
ib_umem_find_best_pgsz() is used to find the best suitable page size which replaces the existing efa_cont_pages() implementation. rdma_for_each_block() is used to iterate the umem in aligned contiguous memory blocks.
Ajay
-----Original Message-----
From: Jason Gunthorpe <[email protected]>
Sent: Wednesday, May 18, 2022 9:05 AM
To: Ajay Sharma <[email protected]>
Cc: Long Li <[email protected]>; KY Srinivasan <[email protected]>; Haiyang Zhang <[email protected]>; Stephen Hemminger <[email protected]>; Wei Liu <[email protected]>; Dexuan Cui <[email protected]>; David S. Miller <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>; Leon Romanovsky <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [EXTERNAL] Re: [PATCH 05/12] net: mana: Set the DMA device max page size
[You don't often get email from [email protected]. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification.]
Quoted 10 lines · Ajay Sharma
Thanks Long.
Hello Jason,
I am the author of the patch.
To your comment below :
" As I've already said, you are supposed to set the value that limits toib_sgeand *NOT* the value that is related toib_umem_find_best_pgsz. It is usually 2G because the ib_sge's typically work on a 32 bit length."The
ib_sgeis limited by the__sg_alloc_table_from_pages()which usesib_dma_max_seg_size()which is what is set by the eth driver usingdma_set_max_seg_size(). Currently our hw does not support PTEs larger than 2M.
*sigh* again it has nothing to do with *PTEs* in the HW.
Jason
Re: [EXTERNAL] Re: [PATCH 05/12] net: mana: Set the DMA device max page size
Quoted 2 lines · Ajay Sharma
Use the
ib_umem_find_best_pgsz()andrdma_for_each_block()API when registering an MR instead of coding it in the driver.
The dma_set_max_seg_size() has *nothing* to do with ib_umem_find_best_pgsz() other than its value should be larger than the largest set bit.
Again, it is supposed to be the maximum value the HW can support in a ib_sge length field, which is usually 2G.
Jason
RE: [EXTERNAL] Re: [PATCH 05/12] net: mana: Set the DMA device max page size
Quoted 8 lines
Subject: Re: [EXTERNAL] Re: [PATCH 05/12] net: mana: Set the DMA device max page size
Quoted 2 lines · Ajay Sharma
Use the
ib_umem_find_best_pgsz()andrdma_for_each_block()API when registering an MR instead of coding it in the driver.
Quoted 6 lines
The
dma_set_max_seg_size()has *nothing* to do withib_umem_find_best_pgsz()other than its value should be larger than the largest set bit.Again, it is supposed to be the maximum value the HW can support in a
ib_sgelength field, which is usually 2G.
Will fix this in v2.
Long
RE: [PATCH 12/12] RDMA/mana_ib: Add a driver for Microsoft Azure Network Adapter
In reply to Jason GunthorpeQuoted 36 lines
Subject: Re: [PATCH 12/12] RDMA/mana_ib: Add a driver for Microsoft Azure Network Adapter
Quoted 3 lines · On Tue, May 17, 2022 at 02:04:36AM -0700, [email protected] wrote:
From: Long Li <[email protected]>
Add a RDMA VF driver for Microsoft Azure Network Adapter (MANA).
To set exepecation, we are currently rc7, so this will not make this merge window. You will need to repost on the next rc1 in three weeks.
Quoted 11 lines
new file mode 100644
index 000000000000..0eac77c97658drivers/infiniband/hw/mana/cq.c new file +6
-0@@ -0,0 +1,74 @@ +// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB +/* +* Copyright (c) 2022, Microsoft Corporation. All rights reserved. +*/ + +#include "mana_ib.h" drivers/infiniband/hw/mana/cq.c line 16
Quoted 10 lines
drivers/infiniband/hw/mana/cq.c new file +10
-0+ +int mana_ib_create_cq (struct ib_cq *ibcq,const struct ib_cq_init_attr *attr, +struct ib_udata *udata) +{ +struct mana_ib_create_cq ucmd = {}; +struct ib_device *ibdev = ibcq->device; +struct mana_ib_dev *mdev = + container_of(ibdev, struct mana_ib_dev, ib_dev); + struct mana_ib_cq *cq = container_of(ibcq, struct mana_ib_cq, ibcq); +int err;We do try to follow the netdev formatting, christmas trees and all that.
Quoted 5 lines
drivers/infiniband/hw/mana/cq.c line 19
Quoted 3 lines
drivers/infiniband/hw/mana/cq.c new file +3
-0+ + err =ib_copy_from_udata (&ucmd, udata,min (sizeof (ucmd), +udata->inlen));Skeptical this min is correct, many other drivers get this wrong.
I think this is correct. This is to prevent user-mode passing more data that may overrun the kernel buffer.
Quoted 10 lines
drivers/infiniband/hw/mana/cq.c line 20
Quoted 3 lines
drivers/infiniband/hw/mana/cq.c new file +2
-0+if (err) { +pr_err ("Failed to copy from udata for create cq, %d\n" , err);Do not use pr_* - you should use one of the dev specific varients inside a device driver. In this case
ibdev_dbgAlso, do not ever print to the console on a user triggerable event such as this.
_dbgwould be OK.
Quoted 6 lines
Scrub the driver for all occurances.
drivers/infiniband/hw/mana/cq.c line 30
Quoted 1 line
drivers/infiniband/hw/mana/cq.c new file +1
-0+pr_debug ("ucmd buf_addr 0x%llx\n" , ucmd.buf_addr);I'm not keen on left over debugging please, in fact there are way too many prints..
I will clean up all the occurrence on pr_*.
Quoted 23 lines
drivers/infiniband/hw/mana/cq.c line 34
Quoted 4 lines
drivers/infiniband/hw/mana/cq.c new file +3
-0+ cq->umem =ib_umem_get (ibdev, ucmd.buf_addr, + cq->cqe *COMP_ENTRY_SIZE , +IB_ACCESS_LOCAL_WRITE );Please touch the file with clang-format and take all the things that look good to you
Quoted 15 lines
drivers/infiniband/hw/mana/main.c new file +8
-0@@ -0,0 +1,679 @@ +// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB +/* +* Copyright (c) 2022, Microsoft Corporation. All rights reserved. +*/ + +#include "mana_ib.h" + +MODULE_DESCRIPTION ("Microsoft Azure Network Adapter IB driver" );
Quoted 8 lines
drivers/infiniband/hw/mana/main.c line 14
Quoted 6 lines
drivers/infiniband/hw/mana/main.c new file +6
-0+MODULE_LICENSE ("Dual BSD/GPL" ); + +static const struct auxiliary_device_id mana_id_table[] = { + { .name ="mana.rdma" , }, + {}, +};stylistically this stuff is usually at the bottom of the file, right before its first use
Will move it.
Quoted 14 lines
drivers/infiniband/hw/mana/main.c
Quoted 12 lines
drivers/infiniband/hw/mana/main.c new file +11
-0+static inline enum atb_page_size mana_ib_get_atb_page_size (u64 +page_sz) { +int pos =0 ; + + page_sz = (page_sz >>12 );//start with 4k + +while (page_sz) { + pos++; + page_sz = (page_sz >>1 ); + } +return (enum atb_page_size )(pos -1 ); }Isn't this ffs, log, or something that isn't a while loop?
Will fix this.
Quoted 131 lines
Quoted 12 lines
drivers/infiniband/hw/mana/main.c new file +11
-0+static int _mana_ib_gd_create_dma_region (struct mana_ib_dev *dev, +const dma_addr_t *page_addr_array, +size_t num_pages_total, +u64 address,u64 length, +mana_handle_t *gdma_region, +u64 page_sz) +{ +struct gdma_dev *mdev = dev->gdma_dev; +struct gdma_context *gc = mdev->gdma_context; +struct hw_channel_context *hwc = gc->hwc.driver_data; +size_t num_pages_cur, num_pages_to_handle;drivers/infiniband/hw/mana/main.c line 172
Quoted 10 lines
drivers/infiniband/hw/mana/main.c new file +10
-0+unsigned int create_req_msg_size; +unsigned int i; +struct gdma_dma_region_add_pages_req *add_req =NULL ; +int err; + +struct gdma_create_dma_region_req *create_req; +struct gdma_create_dma_region_resp create_resp = {}; + +size_t max_pgs_create_cmd = (hwc->max_req_msg_size - +sizeof (*create_req)) /sizeof (u64);These extra blank lines are not kernel style, please check everything.
drivers/infiniband/hw/mana/main.c
Quoted 10 lines
drivers/infiniband/hw/mana/main.c new file +10
-0+ num_pages_to_handle =min_t (size_t, num_pages_total, + max_pgs_create_cmd); + create_req_msg_size =struct_size (create_req, page_addr_list, + num_pages_to_handle); + + create_req =kzalloc (create_req_msg_size,GFP_KERNEL ); +if (!create_req) +return -ENOMEM ; + + mana_gd_init_req_hdr(&create_req->hdr,
GDMA_CREATE_DMA_REGION,Quoted 13 lines
drivers/infiniband/hw/mana/main.c new file +11
-0+ create_req_msg_size, sizeof(create_resp)); + + create_req->length = length; + create_req->offset_in_page = address & (page_sz -1 ); + create_req->gdma_page_type =mana_ib_get_atb_page_size (page_sz); + create_req->page_count = num_pages_total; + create_req->page_addr_list_len = num_pages_to_handle; + + pr_debug("size_dma_region %llu num_pages_total %lu, " + "page_sz 0x%llx offset_in_page %u\n", + length, num_pages_total, page_sz, create_req-
offset_in_page);drivers/infiniband/hw/mana/main.c new file +1
-0+drivers/infiniband/hw/mana/main.c line 205
Quoted 10 lines
drivers/infiniband/hw/mana/main.c new file +10
-0+pr_debug ("num_pages_to_handle %lu, gdma_page_type %u" , + num_pages_to_handle, create_req->gdma_page_type); + +for (i =0 ; i < num_pages_to_handle; ++i) { +dma_addr_t cur_addr = page_addr_array[i]; + + create_req->page_addr_list[i] = cur_addr; + +pr_debug ("page num %u cur_addr 0x%llx\n" , i, cur_addr); + }Er, so we allocated memory and wrote the DMA addresses now you copy them to another memory?
Quoted 34 lines
drivers/infiniband/hw/mana/main.c new file +34
-0+ + err =mana_gd_send_request (gc, create_req_msg_size, create_req, +sizeof (create_resp), &create_resp); +kfree (create_req); + +if (err || create_resp.hdr.status) { +dev_err (gc->dev,"Failed to create DMA region: %d, 0x%x\n" , + err, create_resp.hdr.status); + goto error; + } + + *gdma_region = create_resp.dma_region_handle; +pr_debug ("Created DMA region with handle 0x%llx\n" , *gdma_region); + + num_pages_cur = num_pages_to_handle; + +if (num_pages_cur < num_pages_total) { + +unsigned int add_req_msg_size; +size_t max_pgs_add_cmd = (hwc->max_req_msg_size - +sizeof (*add_req)) /sizeof (u64); + + num_pages_to_handle =min_t (size_t, + num_pages_total - num_pages_cur, + max_pgs_add_cmd); + +// Calculate the max num of pages that will be handled + add_req_msg_size =struct_size (add_req, page_addr_list, + num_pages_to_handle); + + add_req =kmalloc (add_req_msg_size,GFP_KERNEL ); +if (!add_req) { + err = -ENOMEM ; + goto error;drivers/infiniband/hw/mana/main.c
Quoted 10 lines
drivers/infiniband/hw/mana/main.c new file +10
-0+ } + +while (num_pages_cur < num_pages_total) { +struct gdma_general_resp add_resp = {}; +u32 expected_status; +int expected_ret; + +if (num_pages_cur + num_pages_to_handle < + num_pages_total) { +// This value means that more pages are needed
drivers/infiniband/hw/mana/main.c
Quoted 1 line
drivers/infiniband/hw/mana/main.c new file +1
-0+ expected_status =
GDMA_STATUS_MORE_ENTRIES;Quoted 8 lines
drivers/infiniband/hw/mana/main.c new file +8
-0+ expected_ret =0x0 ; + }else { + expected_status =0x0 ; + expected_ret =0x0 ; + } + +memset (add_req,0 , add_req_msg_size); +drivers/infiniband/hw/mana/main.c line 268
Quoted 10 lines
drivers/infiniband/hw/mana/main.c new file +10
-0+mana_gd_init_req_hdr (&add_req->hdr, +GDMA_DMA_REGION_ADD_PAGES , + add_req_msg_size, +sizeof (add_resp)); + add_req->dma_region_handle = *gdma_region; + add_req->page_addr_list_len = num_pages_to_handle; + +for (i =0 ; i < num_pages_to_handle; ++i) { +dma_addr_t cur_addr = + page_addr_array[num_pages_cur + i];And then again?
Quoted 3 lines
That isn't how this is supposed to work, you should iterate over the umem in one pass and split up the output as you go. Allocating potentially giant temporary arrays should be avoided.
Will address this in V2.
Quoted 61 lines
Quoted 5 lines
drivers/infiniband/hw/mana/main.c new file +3
-0+ add_req->page_addr_list[i] = cur_addr; + + pr_debug("page_addr_list %lu addr 0x%llx\n",drivers/infiniband/hw/mana/main.c
Quoted 10 lines
drivers/infiniband/hw/mana/main.c new file +10
-0+ num_pages_cur + i, cur_addr); + } + + err =mana_gd_send_request (gc, add_req_msg_size, + add_req,sizeof (add_resp), + &add_resp); +if (err != expected_ret || + add_resp.hdr.status != expected_status) { + dev_err(gc->dev, + "Failed to put DMApages %u: %d,0x%x\n",
Quoted 13 lines
drivers/infiniband/hw/mana/main.c new file +13
-0+ i, err, add_resp.hdr.status); + err = -EPROTO ; + goto free_req; + } + + num_pages_cur += num_pages_to_handle; + num_pages_to_handle =min_t (size_t, + num_pages_total - + num_pages_cur, + max_pgs_add_cmd); + add_req_msg_size =sizeof (*add_req) + + num_pages_to_handle *sizeof (u64); + }drivers/infiniband/hw/mana/main.c
Quoted 10 lines
drivers/infiniband/hw/mana/main.c new file +10
-0+free_req: +kfree (add_req); + } + +error: +return err; +} + + +int mana_ib_gd_create_dma_region(struct mana_ib_dev *dev, struct
ib_umem*umem,drivers/infiniband/hw/mana/main.c
Quoted 1 line
drivers/infiniband/hw/mana/main.c new file +1
-0+mana_handle_t *dma_region_handle, u64
page_sz)Since this takes in a umem it should also compute the
page_szfor that umem.I see this driver seems to have various limitations, so the input argument here should be the pgsz bitmask that is compatible with the object being created.
drivers/infiniband/hw/mana/main.c
Quoted 12 lines
drivers/infiniband/hw/mana/main.c new file +12
-0+{ +size_t num_pages =ib_umem_num_dma_blocks (umem, page_sz); +struct ib_block_iter biter; +dma_addr_t *page_addr_array; +unsigned int i =0 ; +int err; + +pr_debug ("num pages %lu umem->address 0x%lx\n" , + num_pages, umem->address); + + page_addr_array = kmalloc_array(num_pages, + sizeof(*page_addr_array),
GFP_KERNEL);
Quoted 4 lines
drivers/infiniband/hw/mana/main.c line 320
Quoted 2 lines
drivers/infiniband/hw/mana/main.c new file +2
-0+if (!page_addr_array) +return -ENOMEM ;This will OOM easily,
num_pagesis user controlled.
I'm adding a check for length before calling into this.
Quoted 30 lines
drivers/infiniband/hw/mana/main.c
Quoted 6 lines
drivers/infiniband/hw/mana/main.c new file +5
-0+ +rdma_umem_for_each_dma_block (umem, &biter, page_sz) + page_addr_array[i++] =rdma_block_iter_dma_address (&biter); + + err = _mana_ib_gd_create_dma_region(dev, page_addr_array,
num_pages,drivers/infiniband/hw/mana/main.c
Quoted 8 lines
drivers/infiniband/hw/mana/main.c new file +8
-0+ umem->address, umem->length, + dma_region_handle, page_sz); + +kfree (page_addr_array); + +return err; +} +int mana_ib_gd_create_pd(struct mana_ib_dev *dev, u64 *pd_handle, u32
*pd_id,Quoted 14 lines
drivers/infiniband/hw/mana/main.c new file +14
-0+ enum gdma_pd_flags flags) +{ +struct gdma_dev *mdev = dev->gdma_dev; +struct gdma_context *gc = mdev->gdma_context; +int err; + +struct gdma_create_pd_req req = {}; +struct gdma_create_pd_resp resp = {}; + +mana_gd_init_req_hdr (&req.hdr,GDMA_CREATE_PD , +sizeof (req),sizeof (resp)); + + req.flags = flags; + err = mana_gd_send_request(gc, sizeof(req), &req, sizeof(resp),
Quoted 8 lines
drivers/infiniband/hw/mana/main.c line 363
Quoted 6 lines
+&resp);
drivers/infiniband/hw/mana/main.c new file +5
-0+ +if (!err && !resp.hdr.status) { + *pd_handle = resp.pd_handle; + *pd_id = resp.pd_id; +pr_debug ("pd_handle 0x%llx pd_id %d\n" , *pd_handle, *pd_id);Kernel style is 'success oriented flow':
Will fix this.
Quoted 9 lines
if (err) { return err;}
// success
return 0;Audit everything
Quoted 13 lines
drivers/infiniband/hw/mana/main.c line 492
Quoted 11 lines
drivers/infiniband/hw/mana/main.c new file +11
-0+static int mana_ib_mmap (struct ib_ucontext *ibcontext,struct +vm_area_struct *vma) { +struct mana_ib_ucontext *mana_ucontext = + container_of(ibcontext, struct mana_ib_ucontext, ibucontext); +struct ib_device *ibdev = ibcontext->device; +struct mana_ib_dev *mdev = + container_of(ibdev, struct mana_ib_dev, ib_dev); +struct gdma_context *gc = mdev->gdma_dev->gdma_context; +pgprot_t prot; +phys_addr_t pfn; +int ret;This needs to validate
vma->pgoff
Will validate this.
Quoted 5 lines
drivers/infiniband/hw/mana/main.c line 494
Quoted 2 lines
drivers/infiniband/hw/mana/main.c new file +1
-0+// map to the page indexed by ucontext->doorbell Not kernel style, be sure to run checkpatch and fix the egregious things.
Quoted 7 lines
drivers/infiniband/hw/mana/main.c
Quoted 2 lines
drivers/infiniband/hw/mana/main.c new file +2
-0+static void mana_ib_disassociate_ucontext (struct ib_ucontext +*ibcontext) { }Does this driver actually support disassociate? Don't define this function if it doesn't.
I didn't see any mmap zapping so I guess it doesn't.
The user-mode deals with zapping.
I see the following comments on rdma_umap_priv_init():
/* RDMA drivers supporting disassociation must have their user space designed
* to cope in some way with their IO pages going to the zero page. */
Is there any other additional work for the kernel driver to support disassociate? It seems uverbs_user_mmap_disassociate() has done all the zapping when destroying a ucontext.
Quoted 31 lines
Quoted 31 lines
drivers/infiniband/hw/mana/main.c new file +30
-0+static const struct ib_device_ops mana_ib_dev_ops = { + .owner =THIS_MODULE , + .driver_id =RDMA_DRIVER_MANA , + .uverbs_abi_ver =MANA_IB_UVERBS_ABI_VERSION , + + .alloc_pd = mana_ib_alloc_pd, + .dealloc_pd = mana_ib_dealloc_pd, + + .alloc_ucontext = mana_ib_alloc_ucontext, + .dealloc_ucontext = mana_ib_dealloc_ucontext, + + .create_cq = mana_ib_create_cq, + .destroy_cq = mana_ib_destroy_cq, + + .create_qp = mana_ib_create_qp, + .modify_qp = mana_ib_modify_qp, + .destroy_qp = mana_ib_destroy_qp, + + .disassociate_ucontext = mana_ib_disassociate_ucontext, + + .mmap = mana_ib_mmap, + + .reg_user_mr = mana_ib_reg_user_mr, + .dereg_mr = mana_ib_dereg_mr, + + .create_wq = mana_ib_create_wq, + .modify_wq = mana_ib_modify_wq, + .destroy_wq = mana_ib_destroy_wq, + + .create_rwq_ind_table = mana_ib_create_rwq_ind_table,
Quoted 8 lines
drivers/infiniband/hw/mana/main.c line 597
Quoted 6 lines
drivers/infiniband/hw/mana/main.c new file +6
-0+ .destroy_rwq_ind_table = mana_ib_destroy_rwq_ind_table, + + .get_port_immutable = mana_ib_get_port_immutable, + .query_device = mana_ib_query_device, + .query_port = mana_ib_query_port, + .query_gid = mana_ib_query_gid,Usually drivers are just sorting this list
Will sort the list.
Quoted 11 lines
drivers/infiniband/hw/mana/main.c
Quoted 6 lines
drivers/infiniband/hw/mana/main.c new file +5
-0+#define PAGE_SZ_BM (SZ_4K | SZ_8K | SZ_16K | SZ_32K | SZ_64K | SZ_128K \ + | SZ_256K | SZ_512K | SZ_1M | SZ_2M) + +// Maximum size of a memory registration is 1G bytes +#define MANA_IB_MAX_MR_SIZE (1024 * 1024 * 1024)Even with large pages? Weird limit..
You also need to open a PR to the rdma-core github with the userspace for this and pyverbs test suite support
I will open PR to rdma-core. The current version of the driver supports queue pair type IB_QPT_RAW_PACKET. The test case will be limited to querying device and load/unload. Running traffic tests will require DPDK (or other user-mode program making use of IB_QPT_RAW_PACKET).
Is it acceptable to develop test cases for this driver without traffic/data tests?
Long
Quoted 3 lines
Thanks,
Jason
Re: [PATCH 12/12] RDMA/mana_ib: Add a driver for Microsoft Azure Network Adapter
Quoted 7 lines · Long Li
Quoted 5 lines
Review
Quoted 3 lines
(quoted diff) +3
-0+ + err = ib_copy_from_udata(&ucmd, udata, min(sizeof(ucmd), +udata->inlen));Skeptical this min is correct, many other drivers get this wrong.
I think this is correct. This is to prevent user-mode passing more data that may overrun the kernel buffer.
And what happens when udata->inlen is, say, 0?
Quoted 15 lines
Quoted 11 lines
drivers/infiniband/hw/mana/main.c line 494
Quoted 1 line
drivers/infiniband/hw/mana/main.c new file +1
-0+// map to the page indexed by ucontext->doorbell Not kernel style, be sure to run checkpatch and fix the egregious things.
Review
Quoted 2 lines
(quoted diff) +2
-0+static void mana_ib_disassociate_ucontext(struct ib_ucontext +*ibcontext) { }Does this driver actually support disassociate? Don't define this function if it doesn't.
I didn't see any mmap zapping so I guess it doesn't.
The user-mode deals with zapping.
I see the following comments onrdma_umap_priv_init():
Quoted 6 lines
/* RDMA drivers supporting disassociation must have their user space designed
* to cope in some way with their IO pages going to the zero page. */Is there any other additional work for the kernel driver to support disassociate? It seems
uverbs_user_mmap_disassociate()has done all the zapping when destroying a ucontext.
Nope, that looks OK then
Quoted 8 lines
I will open PR to rdma-core. The current version of the driver supports queue pair type
IB_QPT_RAW_PACKET. The test case will be limited to querying device and load/unload. Running traffic tests will require DPDK (or other user-mode program making use ofIB_QPT_RAW_PACKET).Is it acceptable to develop test cases for this driver without traffic/data tests?
I'm not keen on that, even EFA was able to do simple traffic.
Even with RAW_PACKET I would expect the driver to be able to send/recv using standard verbs as RAW_PACKET is a common feature.
Jason
RE: [PATCH 12/12] RDMA/mana_ib: Add a driver for Microsoft Azure Network Adapter
Quoted 11 lines
Subject: Re: [PATCH 12/12] RDMA/mana_ib: Add a driver for Microsoft Azure Network Adapter
Quoted 6 lines · Long Li
Quoted 5 lines
Review
Quoted 3 lines
(quoted diff) +3
-0+ + err = ib_copy_from_udata(&ucmd, udata, min(sizeof(ucmd), +udata->inlen));Skeptical this min is correct, many other drivers get this wrong.
Quoted 4 lines
Quoted 1 line
I think this is correct. This is to prevent user-mode passing more data that may
overrun the kernel buffer.
And what happens when
udata->inlenis, say, 0?
Thanks. I'll add check before calling ib_copy_from_udata().
Long
kernel test robot
build botRe: [PATCH 01/12] net: mana: Add support for auxiliary device
In reply to [email protected]Thank you for the patch! Perhaps something to improve:
Hi,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on linus/master]
[also build test WARNING on v5.18-rc7]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/intel-lab-lkp/linux/commits/longli-linuxonhyperv-com/Introduce-Microsoft-Azure-Network-Adapter-MANA-RDMA-driver/20220517-170632 base: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 42226c989789d8da4af1de0c31070c96726d990c config: x86_64-allyesconfig (https://download.01.org/0day-ci/archive/20220520/[email protected]/config) compiler: gcc-11 (Debian 11.2.0-20) 11.2.0 reproduce (this is a W=1 build): # https://github.com/intel-lab-lkp/linux/commit/5c9b22b8d4038fba4019bb1e5bcda9a101d285b7 git remote add linux-review https://github.com/intel-lab-lkp/linux git fetch --no-tags linux-review longli-linuxonhyperv-com/Introduce-Microsoft-Azure-Network-Adapter-MANA-RDMA-driver/20220517-170632 git checkout 5c9b22b8d4038fba4019bb1e5bcda9a101d285b7 # save the config file mkdir build_dir && cp config build_dir/.config make W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash drivers/infiniband/hw/ drivers/net/ethernet/microsoft/mana/
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
>> drivers/net/ethernet/microsoft/mana/mana_en.c:18:5: warning: no previous prototype for 'mana_adev_idx_alloc' [-Wmissing-prototypes]
18 | int mana_adev_idx_alloc(void)
| ^~~~~~~~~~~~~~~~~~~
>> drivers/net/ethernet/microsoft/mana/mana_en.c:23:6: warning: no previous prototype for 'mana_adev_idx_free' [-Wmissing-prototypes] 23 | void mana_adev_idx_free(int idx)
| ^~~~~~~~~~~~~~~~~~
vim +/mana_adev_idx_alloc +18 drivers/net/ethernet/microsoft/mana/mana_en.c
17
> 18 int mana_adev_idx_alloc(void)
19 {
20 return ida_alloc(&mana_adev_ida, GFP_KERNEL);
21 }
22
> 23 void mana_adev_idx_free(int idx)
24 {
25 ida_free(&mana_adev_ida, idx);
26 }
27 Signature · 2 lines
0-DAY CI Kernel Test Service https://01.org/lkp
kernel test robot
build botRe: [PATCH 12/12] RDMA/mana_ib: Add a driver for Microsoft Azure Network Adapter
In reply to [email protected]I love your patch! Perhaps something to improve:
Hi,
I love your patch! Perhaps something to improve:
[auto build test WARNING on linus/master]
[also build test WARNING on v5.18-rc7]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/intel-lab-lkp/linux/commits/longli-linuxonhyperv-com/Introduce-Microsoft-Azure-Network-Adapter-MANA-RDMA-driver/20220517-170632 base: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 42226c989789d8da4af1de0c31070c96726d990c config: x86_64-allyesconfig (https://download.01.org/0day-ci/archive/20220520/[email protected]/config) compiler: gcc-11 (Debian 11.2.0-20) 11.2.0 reproduce (this is a W=1 build): # https://github.com/intel-lab-lkp/linux/commit/f082dc68ab65c498c978d574e62413d50286b4f9 git remote add linux-review https://github.com/intel-lab-lkp/linux git fetch --no-tags linux-review longli-linuxonhyperv-com/Introduce-Microsoft-Azure-Network-Adapter-MANA-RDMA-driver/20220517-170632 git checkout f082dc68ab65c498c978d574e62413d50286b4f9 # save the config file mkdir build_dir && cp config build_dir/.config make W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash drivers/infiniband/hw/mana/
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
>> drivers/infiniband/hw/mana/main.c:544:5: warning: no previous prototype for 'mana_ib_query_port' [-Wmissing-prototypes]
544 | int mana_ib_query_port(struct ib_device *ibdev, u32 port,
| ^~~~~~~~~~~~~~~~~~
--
>> drivers/infiniband/hw/mana/qp.c:8:5: warning: no previous prototype for 'mana_ib_cfg_vport_steering' [-Wmissing-prototypes]
8 | int mana_ib_cfg_vport_steering(struct mana_ib_dev *dev, struct net_device *ndev,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
>> drivers/infiniband/hw/mana/qp.c:227:5: warning: no previous prototype for 'mana_ib_create_qp_raw' [-Wmissing-prototypes]
227 | int mana_ib_create_qp_raw(struct ib_qp *ibqp, struct ib_pd *ibpd,
| ^~~~~~~~~~~~~~~~~~~~~
>> drivers/infiniband/hw/mana/qp.c:421:5: warning: no previous prototype for 'mana_ib_destroy_qp_raw' [-Wmissing-prototypes] 421 | int mana_ib_destroy_qp_raw(struct mana_ib_qp *qp, struct ib_udata *udata)
| ^~~~~~~~~~~~~~~~~~~~~~
vim +/mana_ib_query_port +544 drivers/infiniband/hw/mana/main.c
543
> 544 int mana_ib_query_port(struct ib_device *ibdev, u32 port,
545 struct ib_port_attr *props)
546 {
547 /* This version doesn't return port properties */
548 return 0;
549 }
550
Signature · 2 lines
0-DAY CI Kernel Test Service https://01.org/lkp