linux-rdma.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jason Gunthorpe <jgg@nvidia.com>
To: Wenpeng Liang <liangwenpeng@huawei.com>
Cc: dledford@redhat.com, linux-rdma@vger.kernel.org, linuxarm@huawei.com
Subject: Re: [PATCH v2 for-next] RDMA/hns: Add a new mmap implementation
Date: Wed, 20 Oct 2021 20:15:00 -0300	[thread overview]
Message-ID: <20211020231500.GA27862@nvidia.com> (raw)
In-Reply-To: <20211012124155.12329-1-liangwenpeng@huawei.com>

On Tue, Oct 12, 2021 at 08:41:55PM +0800, Wenpeng Liang wrote:
> From: Chengchang Tang <tangchengchang@huawei.com>
> 
> Add a new implementation for mmap by using the new mmap entry API.
> 
> The new implementation prepares for subsequent features and is compatible
> with the old implementation. And the old implementation using hard-coded
> offset will not be extended in the future.
> 
> Signed-off-by: Chengchang Tang <tangchengchang@huawei.com>
> Signed-off-by: Wenpeng Liang <liangwenpeng@huawei.com>
>  drivers/infiniband/hw/hns/hns_roce_device.h |  23 +++
>  drivers/infiniband/hw/hns/hns_roce_main.c   | 208 +++++++++++++++++---
>  include/uapi/rdma/hns-abi.h                 |  21 +-
>  3 files changed, 225 insertions(+), 27 deletions(-)
> 
> diff --git a/drivers/infiniband/hw/hns/hns_roce_device.h b/drivers/infiniband/hw/hns/hns_roce_device.h
> index 9467c39e3d28..1d4cf3f083c2 100644
> +++ b/drivers/infiniband/hw/hns/hns_roce_device.h
> @@ -225,11 +225,25 @@ struct hns_roce_uar {
>  	unsigned long	logic_idx;
>  };
>  
> +struct hns_user_mmap_entry {
> +	struct rdma_user_mmap_entry rdma_entry;
> +	u64 address;
> +	u8 mmap_flag;

Call this mmap_type and use the enum:

 enum hns_roce_mmap_type mmap_type

> +struct hns_user_mmap_entry *hns_roce_user_mmap_entry_insert(
> +				struct ib_ucontext *ucontext, u64 address,
> +				size_t length, u8 mmap_flag)
> +{
> +#define HNS_ROCE_PGOFFSET_TPTR 1
> +#define HNS_ROCE_PGOFFSET_DB 0
> +	struct hns_roce_ucontext *context = to_hr_ucontext(ucontext);
> +	struct hns_user_mmap_entry *entry;
> +	int ret;
> +
> +	entry = kzalloc(sizeof(*entry), GFP_KERNEL);
> +	if (!entry)
> +		return NULL;
> +
> +	entry->address = address;
> +	entry->mmap_flag = mmap_flag;
> +
> +	if (context->mmap_key_support) {
> +		ret = rdma_user_mmap_entry_insert(ucontext, &entry->rdma_entry,
> +						  length);
> +	} else {
> +		switch (mmap_flag) {
> +		case HNS_ROCE_MMAP_TYPE_DB:
> +			ret = rdma_user_mmap_entry_insert_range(ucontext,
> +						&entry->rdma_entry, length,
> +						HNS_ROCE_PGOFFSET_DB,
> +						HNS_ROCE_PGOFFSET_DB);

Please add this to avoid the odd #defines:

static inline int
rdma_user_mmap_entry_insert_exact(struct ib_ucontext *ucontext,
                                  struct rdma_user_mmap_entry *entry,
                                  size_t length, u32 pgoff)
{
        return rdma_user_mmap_entry_insert_range(ucontext, entry, length, pgoff,
                                                 pgoff);
}

> -static int hns_roce_mmap(struct ib_ucontext *context,
> -			 struct vm_area_struct *vma)
> +static int hns_roce_mmap(struct ib_ucontext *uctx, struct vm_area_struct *vma)
>  {
> -	struct hns_roce_dev *hr_dev = to_hr_dev(context->device);
> -
> -	switch (vma->vm_pgoff) {
> -	case 0:
> -		return rdma_user_mmap_io(context, vma,
> -					 to_hr_ucontext(context)->uar.pfn,
> -					 PAGE_SIZE,
> -					 pgprot_noncached(vma->vm_page_prot),
> -					 NULL);
> -
> -	/* vm_pgoff: 1 -- TPTR */
> -	case 1:
> -		if (!hr_dev->tptr_dma_addr || !hr_dev->tptr_size)
> -			return -EINVAL;
> +	struct hns_roce_dev *hr_dev = to_hr_dev(uctx->device);
> +	struct ib_device *ibdev = &hr_dev->ib_dev;
> +	struct rdma_user_mmap_entry *rdma_entry;
> +	struct hns_user_mmap_entry *entry;
> +	phys_addr_t pfn;
> +	pgprot_t prot;
> +	int ret;
> +
> +	rdma_entry = rdma_user_mmap_entry_get_pgoff(uctx, vma->vm_pgoff);
> +	if (!rdma_entry) {
> +		ibdev_err(ibdev, "Invalid entry vm_pgoff %lu.\n",
> +			  vma->vm_pgoff);
> +		return -EINVAL;
> +	}
> +
> +	entry = to_hns_mmap(rdma_entry);
> +	pfn = entry->address >> PAGE_SHIFT;
> +	prot = vma->vm_page_prot;

Just write

 if (entry->mmap_type != HNS_ROCE_MMAP_TYPE_TPTR)
    prot = pgprot_noncached(prot);
 ret = rdma_user_mmap_io(uctx, vma, pfn,
			rdma_entry->npages * PAGE_SIZE,
			pgprot_noncached(prot), rdma_entry);

No need for the big case statement

> diff --git a/include/uapi/rdma/hns-abi.h b/include/uapi/rdma/hns-abi.h
> index 42b177655560..ce1e39f21d73 100644
> +++ b/include/uapi/rdma/hns-abi.h
> @@ -83,11 +83,30 @@ struct hns_roce_ib_create_qp_resp {
>  	__aligned_u64 cap_flags;
>  };
>  
> +enum hns_roce_alloc_uctx_comp_flag {
> +	HNS_ROCE_ALLOC_UCTX_COMP_CONFIG = 1 << 0,
> +};
> +
> +enum hns_roce_alloc_uctx_resp_config {
> +	HNS_ROCE_UCTX_RESP_MMAP_KEY_EN = 1 << 0,
> +};
> +
> +enum hns_roce_alloc_uctx_req_config {
> +	HNS_ROCE_UCTX_REQ_MMAP_KEY_EN = 1 << 0,
> +};
> +
> +struct hns_roce_ib_alloc_ucontext {
> +	__u32 comp;
> +	__u32 config;
> +};
> +
>  struct hns_roce_ib_alloc_ucontext_resp {
>  	__u32	qp_tab_size;
>  	__u32	cqe_size;
>  	__u32	srq_tab_size;
> -	__u32	reserved;
> +	__u8    config;
> +	__u8    rsv[3];
> +	__aligned_u64 db_mmap_key;

I'm confused, this doesn't change the uAPI, so why add this stuff?
This should go in a later patch?

Jason

  reply	other threads:[~2021-10-20 23:15 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-12 12:41 [PATCH v2 for-next] RDMA/hns: Add a new mmap implementation Wenpeng Liang
2021-10-20 23:15 ` Jason Gunthorpe [this message]
2021-10-22  8:56   ` Wenpeng Liang
2021-10-22  9:31     ` Wenpeng Liang
2021-10-22  9:46   ` Wenpeng Liang
2021-10-25 12:55     ` Jason Gunthorpe
2021-10-26 13:02       ` Wenpeng Liang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211020231500.GA27862@nvidia.com \
    --to=jgg@nvidia.com \
    --cc=dledford@redhat.com \
    --cc=liangwenpeng@huawei.com \
    --cc=linux-rdma@vger.kernel.org \
    --cc=linuxarm@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).