From: Zhu Yanjun <yanjun.zhu@linux.dev>
To: Linus Walleij <linus.walleij@linaro.org>,
Jason Gunthorpe <jgg@nvidia.com>,
Leon Romanovsky <leonro@nvidia.com>
Cc: linux-rdma@vger.kernel.org, Bob Pearson <rpearsonhpe@gmail.com>
Subject: Re: [PATCH v2 1/2] RDMA/rxe: Treat physical addresses right
Date: Sun, 2 Apr 2023 21:51:43 +0800 [thread overview]
Message-ID: <020c55e0-0b6d-9807-b021-b0b99fa5dd92@linux.dev> (raw)
In-Reply-To: <20230329142341.863175-1-linus.walleij@linaro.org>
在 2023/3/29 22:23, Linus Walleij 写道:
> Whenever the IB_MR_TYPE_DMA flag is set in imbr.type, the "iova"
> (I/O virtual address) is not really a virtual address but a physical
> address.
>
> This means that the use of virt_to_page() on these addresses is also
> incorrect, this needs to be treated and converted to a page using
> the page frame number and pfn_to_page().
>
> Fix up all users in this file.
It is better to have a summary to these 2 commits.
Anyway, thanks.
Acked-by: Zhu Yanjun <zyjzyj2000@gmail.com>
Zhu Yanjun
>
> Fixes: 592627ccbdff ("RDMA/rxe: Replace rxe_map and rxe_phys_buf by xarray")
> Cc: Bob Pearson <rpearsonhpe@gmail.com>
> Reported-by: Jason Gunthorpe <jgg@nvidia.com>
> Link: https://lore.kernel.org/linux-rdma/ZB2s3GeaN%2FFBpR5K@nvidia.com/
> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
> ---
> ChangeLog v1->v2:
> - New patch prepended to patch set.
> ---
> drivers/infiniband/sw/rxe/rxe_mr.c | 26 ++++++++++++++++++--------
> 1 file changed, 18 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/infiniband/sw/rxe/rxe_mr.c b/drivers/infiniband/sw/rxe/rxe_mr.c
> index b10aa1580a64..8e8250652f9d 100644
> --- a/drivers/infiniband/sw/rxe/rxe_mr.c
> +++ b/drivers/infiniband/sw/rxe/rxe_mr.c
> @@ -279,16 +279,20 @@ static int rxe_mr_copy_xarray(struct rxe_mr *mr, u64 iova, void *addr,
> return 0;
> }
>
> -static void rxe_mr_copy_dma(struct rxe_mr *mr, u64 iova, void *addr,
> +/*
> + * This function is always called with a physical address as parameter,
> + * since DMA only operates on physical addresses.
> + */
> +static void rxe_mr_copy_dma(struct rxe_mr *mr, u64 phys, void *addr,
> unsigned int length, enum rxe_mr_copy_dir dir)
> {
> - unsigned int page_offset = iova & (PAGE_SIZE - 1);
> + unsigned int page_offset = phys & (PAGE_SIZE - 1);
> unsigned int bytes;
> struct page *page;
> u8 *va;
>
> while (length) {
> - page = virt_to_page(iova & mr->page_mask);
> + page = pfn_to_page(phys >> PAGE_SHIFT);
> bytes = min_t(unsigned int, length,
> PAGE_SIZE - page_offset);
> va = kmap_local_page(page);
> @@ -300,7 +304,7 @@ static void rxe_mr_copy_dma(struct rxe_mr *mr, u64 iova, void *addr,
>
> kunmap_local(va);
> page_offset = 0;
> - iova += bytes;
> + phys += bytes;
> addr += bytes;
> length -= bytes;
> }
> @@ -487,8 +491,11 @@ int rxe_mr_do_atomic_op(struct rxe_mr *mr, u64 iova, int opcode,
> }
>
> if (mr->ibmr.type == IB_MR_TYPE_DMA) {
> - page_offset = iova & (PAGE_SIZE - 1);
> - page = virt_to_page(iova & PAGE_MASK);
> + /* In this case iova is a physical address */
> + u64 phys = iova;
> +
> + page_offset = phys & (PAGE_SIZE - 1);
> + page = pfn_to_page(phys >> PAGE_SHIFT);
> } else {
> unsigned long index;
> int err;
> @@ -544,8 +551,11 @@ int rxe_mr_do_atomic_write(struct rxe_mr *mr, u64 iova, u64 value)
> }
>
> if (mr->ibmr.type == IB_MR_TYPE_DMA) {
> - page_offset = iova & (PAGE_SIZE - 1);
> - page = virt_to_page(iova & PAGE_MASK);
> + /* In this case iova is a physical address */
> + u64 phys = iova;
> +
> + page_offset = phys & (PAGE_SIZE - 1);
> + page = pfn_to_page(phys >> PAGE_SHIFT);
> } else {
> unsigned long index;
> int err;
prev parent reply other threads:[~2023-04-02 13:52 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-29 14:23 [PATCH v2 1/2] RDMA/rxe: Treat physical addresses right Linus Walleij
2023-03-29 14:23 ` [PATCH v2 2/2] RDMA/rxe: Pass a pointer to virt_to_page() Linus Walleij
2023-03-29 20:14 ` Bob Pearson
2023-04-02 13:51 ` Zhu Yanjun [this message]
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=020c55e0-0b6d-9807-b021-b0b99fa5dd92@linux.dev \
--to=yanjun.zhu@linux.dev \
--cc=jgg@nvidia.com \
--cc=leonro@nvidia.com \
--cc=linus.walleij@linaro.org \
--cc=linux-rdma@vger.kernel.org \
--cc=rpearsonhpe@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.