Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp610380rwb; Wed, 16 Nov 2022 05:29:54 -0800 (PST) X-Google-Smtp-Source: AA0mqf71CKrSYLj1f165xi3NAmtuB8UYFIpUA99GxJ22XAvRH7+aUuTJBqoddl3TihQHmAtVmOT4 X-Received: by 2002:a17:906:344f:b0:79f:e0b3:3b99 with SMTP id d15-20020a170906344f00b0079fe0b33b99mr17524076ejb.381.1668605394609; Wed, 16 Nov 2022 05:29:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668605394; cv=none; d=google.com; s=arc-20160816; b=hE4RYQpzHzr6uup+56IJLszxGaydq8Jjk/6Q0MFL7Y00sr5bUJHg46leutkWV1y5BI AyyPXirY4MEW2A+dTO9wdzfp3c62rUxns8OCFN7oyqm/c/QUkYGiLMP71u05QwbALdyS oD1F2fNWDoWq7jNVxGEduccrBtxyITaT75ameOBa9/tAz2sk+czKOzoDOy8WBZ4EFIYI NLB8NbEl57LKIVFxPccLbMBvTVzKb08R5fr40fzHr9txcZb8aD/i9dndiWWe9z13rLGl 1O9FjW17HEgD1XaMldEe2nSfR4LvE5drOi+oMzUn38U+eWakRXfwjWjrkFmBzs6TyFr2 QzLQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=eT/6csOSu7SFpZHBsgunlrQMZeMZnaIM2b4OlHql6Ps=; b=Mxg2VCZJQEG0MHDWrIUZXb+Zz2RmQa9ehGHrg+Kojrbu+iHfsZndm4X61MmFdA2v0t JmkNE3dKlhjkoPId+ogEoSbS8bBvAI5EjXJSpgoFlsTkYIBr2CGInZuQseUJ76/ieiYQ PAdtC7xMID7kGJuHWkNyjxBGpCxRp8XKRfvvxMrlpEWHJLtT6Qz4B1yYpNWvT5hTwyOX nVeBZS3P7FAuT6uUHD6EywkFT+139ZnTtwnxF8tqYqxL0YNFaX4hynqL6KHTLmS9ic/7 ybjHZCXmUXit6RakI5LoXjwHAYc7PEtXGGRFfQl+lGTObShOcEMGzNl+RfKfF+FUZ9h0 Z9kg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Z3k0EOmS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k9-20020a17090646c900b00781b6ce15e1si9814518ejs.101.2022.11.16.05.29.32; Wed, 16 Nov 2022 05:29:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Z3k0EOmS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238998AbiKPMi3 (ORCPT + 91 others); Wed, 16 Nov 2022 07:38:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53136 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239015AbiKPMiC (ORCPT ); Wed, 16 Nov 2022 07:38:02 -0500 Received: from mail-lj1-x232.google.com (mail-lj1-x232.google.com [IPv6:2a00:1450:4864:20::232]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2C631248D6; Wed, 16 Nov 2022 04:37:33 -0800 (PST) Received: by mail-lj1-x232.google.com with SMTP id h12so21649920ljg.9; Wed, 16 Nov 2022 04:37:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=eT/6csOSu7SFpZHBsgunlrQMZeMZnaIM2b4OlHql6Ps=; b=Z3k0EOmSnjchLvQlVuICpdEqdcJERXsU2Nptii3E8Rl2oNGnJt5nYBROlwreVEg/dn qsnUjbn5HjrL2YMW+lOK0F4uKVBhtD0o8L76GWy6gHRt1Vkrx/UfKHt6E2OYv7Ll4F6L lFfpARGnAs8YDxHS0zg+oUk73FwEUH+cTDScmNu6DpKtYMS/efv+iKkeyeuuHbY5/gCX GOGJ4BvmZLsvpVKDoSGNBvaMuaZazd7aEoS38dl2mPffw/atTYDuKI4dQN/+iIj98f0W ESvaA+MBlU1QYMi/owdMJJ7VlSat2EIjFnPJ74eH5zL+5esnYROLAIg61vvJ/fx7zaU/ vyNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=eT/6csOSu7SFpZHBsgunlrQMZeMZnaIM2b4OlHql6Ps=; b=sx9gkNSemzqV2LK+jsMJLiQtfX3EDgsGCkXNPRO4N7DNDc4ZtFdrJQ7CiK6jht06I0 mXcz9GIIVwUuR+0T2fkUBvwl1sH90ENbP+eTNfyVvNC9tbzQcwBc1B3qppiGJUS+efj8 TEqh/XgpR/iGIbYbQHhezlw69s+jynp8frdth6tdK4nCqiFc+zpi1vCqDFNXonaZ8Gmi p41n7TV0W1eignNJEY6+a09GksD3S6IIYG0ZR3tEnZHN6GCPu41p37KzGFdk+v8U6EqK uPr+ROurDQwxSatJYaPUTfaaNm7dycZytZWKK3Ox5NUT3iWXIg7dwmWr1B/n3MBONxkn pVSA== X-Gm-Message-State: ANoB5plwOKNBoz98eMQlY1KWbWR5R0KYGAZ5cPmniMVL3fih0ujLsLQL zfl7CIPzWf7XLyKXeE2rnqcids8iRgwnDdmOJfd6+lEF X-Received: by 2002:a2e:b0ef:0:b0:26d:ee99:93b4 with SMTP id h15-20020a2eb0ef000000b0026dee9993b4mr7987691ljl.329.1668602251220; Wed, 16 Nov 2022 04:37:31 -0800 (PST) MIME-Version: 1.0 References: <1668141030-2-1-git-send-email-lizhijian@fujitsu.com> <1668141030-2-5-git-send-email-lizhijian@fujitsu.com> In-Reply-To: <1668141030-2-5-git-send-email-lizhijian@fujitsu.com> From: "Fabio M. De Francesco" Date: Wed, 16 Nov 2022 13:37:14 +0100 Message-ID: Subject: Re: [for-next PATCH 4/5] RDMA/rxe: refactor iova_to_vaddr To: Li Zhijian Cc: Zhu Yanjun , Jason Gunthorpe , Leon Romanovsky , linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org, Ira Weiny Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On venerd=C3=AC 11 novembre 2022 05:30:29 CET Li Zhijian wrote: > For IB_MR_TYPE_USER MR, iova_to_vaddr() will call kmap_local_page() to > map page. > > Signed-off-by: Li Zhijian > --- > drivers/infiniband/sw/rxe/rxe_loc.h | 1 + > drivers/infiniband/sw/rxe/rxe_mr.c | 38 +++++++++++++++------------ > drivers/infiniband/sw/rxe/rxe_resp.c | 1 + > drivers/infiniband/sw/rxe/rxe_verbs.h | 5 +++- > 4 files changed, 27 insertions(+), 18 deletions(-) > > diff --git a/drivers/infiniband/sw/rxe/rxe_loc.h > b/drivers/infiniband/sw/rxe/rxe_loc.h index c2a5c8814a48..22a8c44d39c8 100644 > --- a/drivers/infiniband/sw/rxe/rxe_loc.h > +++ b/drivers/infiniband/sw/rxe/rxe_loc.h > @@ -73,6 +73,7 @@ int rxe_mr_copy(struct rxe_mr *mr, u64 iova, void *addr= , int > length, int copy_data(struct rxe_pd *pd, int access, struct rxe_dma_info > *dma, void *addr, int length, enum rxe_mr_copy_dir dir); > void *iova_to_vaddr(struct rxe_mr *mr, u64 iova, int length); > +void rxe_unmap_vaddr(struct rxe_mr *mr, void *vaddr); > struct rxe_mr *lookup_mr(struct rxe_pd *pd, int access, u32 key, > enum rxe_mr_lookup_type type); > int mr_check_range(struct rxe_mr *mr, u64 iova, size_t length); > diff --git a/drivers/infiniband/sw/rxe/rxe_mr.c > b/drivers/infiniband/sw/rxe/rxe_mr.c index a4e786b657b7..d26a4a33119c 100= 644 > --- a/drivers/infiniband/sw/rxe/rxe_mr.c > +++ b/drivers/infiniband/sw/rxe/rxe_mr.c > @@ -120,9 +120,7 @@ int rxe_mr_init_user(struct rxe_dev *rxe, u64 start, = u64 > length, u64 iova, struct ib_umem *umem; > struct sg_page_iter sg_iter; > int num_buf; > - void *vaddr; > int err; > - int i; > > umem =3D ib_umem_get(&rxe->ib_dev, start, length, access); > if (IS_ERR(umem)) { > @@ -159,18 +157,9 @@ int rxe_mr_init_user(struct rxe_dev *rxe, u64 start, u64 > length, u64 iova, num_buf =3D 0; > } > > - vaddr =3D page_address(sg_page_iter_page(&sg_iter)); > - if (!vaddr) { > - pr_warn("%s: Unable to get virtual address\n", > - __func__); > - err =3D -ENOMEM; > - goto err_cleanup_map; > - } > - > - buf->addr =3D (uintptr_t)vaddr; > + buf->page =3D sg_page_iter_page(&sg_iter); > num_buf++; > buf++; > - > } > } > > @@ -182,10 +171,6 @@ int rxe_mr_init_user(struct rxe_dev *rxe, u64 start, u64 > length, u64 iova, > > return 0; > > -err_cleanup_map: > - for (i =3D 0; i < mr->num_map; i++) > - kfree(mr->map[i]); > - kfree(mr->map); > err_release_umem: > ib_umem_release(umem); > err_out: > @@ -246,6 +231,12 @@ static void lookup_iova(struct rxe_mr *mr, u64 iova, int > *m_out, int *n_out, } > } > > +void rxe_unmap_vaddr(struct rxe_mr *mr, void *vaddr) > +{ > + if (mr->ibmr.type =3D=3D IB_MR_TYPE_USER) > + kunmap_local(vaddr); > +} > + > static void *__iova_to_vaddr(struct rxe_mr *mr, u64 iova, int length) > { > size_t offset; > @@ -258,9 +249,21 @@ static void *__iova_to_vaddr(struct rxe_mr *mr, u64 iova, > int length) return NULL; > } > > - return (void *)(uintptr_t)mr->map[m]->buf[n].addr + offset; > + if (mr->ibmr.type =3D=3D IB_MR_TYPE_USER) { > + char *paddr; > + struct page *pg =3D mr->map[m]->buf[n].page; > + > + paddr =3D kmap_local_page(pg); > + if (paddr =3D=3D NULL) { > + pr_warn("Failed to map page"); > + return NULL; > + } I know nothing about this code but I am here as a result of regular checks = for changes to HIGHMEM mappings across the entire kernel. So please forgive me = if I'm objecting to the correct changes. 1) It looks like this code had a call to page_address() and you converted i= t to mapping with kmap_local_page(). If page_address() is related and it used to work properly, the page you are mapping cannot come from ZONE_HIGHMEM. Therefore, kmap_local_page() looks l= ike an overkill. I'm probably missing something... > + return paddr + offset; > + } else > + return (void *)(uintptr_t)mr->map[m]->buf[n].addr + offset; > } > > +/* must call rxe_unmap_vaddr to unmap vaddr */ > void *iova_to_vaddr(struct rxe_mr *mr, u64 iova, int length) > { > if (mr->state !=3D RXE_MR_STATE_VALID) { > @@ -326,6 +329,7 @@ int rxe_mr_copy(struct rxe_mr *mr, u64 iova, void *ad= dr, > int length, dest =3D (dir =3D=3D RXE_TO_MR_OBJ) ? va : addr; > > memcpy(dest, src, bytes); > + rxe_unmap_vaddr(mr, va); > > length -=3D bytes; > addr +=3D bytes; > diff --git a/drivers/infiniband/sw/rxe/rxe_resp.c > b/drivers/infiniband/sw/rxe/rxe_resp.c index 483043dc4e89..765cb9f8538a > 100644 > --- a/drivers/infiniband/sw/rxe/rxe_resp.c > +++ b/drivers/infiniband/sw/rxe/rxe_resp.c > @@ -636,6 +636,7 @@ static enum resp_states atomic_reply(struct rxe_qp *q= p, > > *vaddr =3D value; > spin_unlock_bh(&atomic_ops_lock); > + rxe_unmap_vaddr(mr, vaddr); > > qp->resp.msn++; > > diff --git a/drivers/infiniband/sw/rxe/rxe_verbs.h > b/drivers/infiniband/sw/rxe/rxe_verbs.h index acab785ba7e2..6080a4b32f09 > 100644 > --- a/drivers/infiniband/sw/rxe/rxe_verbs.h > +++ b/drivers/infiniband/sw/rxe/rxe_verbs.h > @@ -280,7 +280,10 @@ enum rxe_mr_lookup_type { > #define RXE_BUF_PER_MAP (PAGE_SIZE / sizeof(struct rxe_phys_buf)) > > struct rxe_phys_buf { > - u64 addr; > + union { > + u64 addr; /* IB_MR_TYPE_MEM_REG */ > + struct page *page; /* IB_MR_TYPE_USER */ > + }; > }; > > struct rxe_map { > -- > 2.31.1