From: Xenia Ragiadakou <burzalodowa@gmail.com>
To: Oleksandr Tyshchenko <olekstysh@gmail.com>,
xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org
Cc: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>,
Stefano Stabellini <sstabellini@kernel.org>,
Juergen Gross <jgross@suse.com>
Subject: Re: [PATCH V2 1/2] xen/virtio: Handle cases when page offset > PAGE_SIZE properly
Date: Fri, 14 Oct 2022 10:35:24 +0300 [thread overview]
Message-ID: <ae26a54b-ece5-f8a3-2331-f7e495ecceea@gmail.com> (raw)
In-Reply-To: <20221008151013.2537826-2-olekstysh@gmail.com>
On 10/8/22 18:10, Oleksandr Tyshchenko wrote:
> From: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>
>
> Passed to xen_grant_dma_map_page() offset in the page
> can be > PAGE_SIZE even if the guest uses the same page granularity
> as Xen (4KB).
>
> Before current patch, if such case happened we ended up providing
> grants for the whole region in xen_grant_dma_map_page() which
> was really unnecessary. The more, we ended up not releasing all
> grants which represented that region in xen_grant_dma_unmap_page().
>
> Current patch updates the code to be able to deal with such cases.
>
> Signed-off-by: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>
Reviewed-by: Xenia Ragiadakou <burzalodowa@gmail.com>
> ---
> Cc: Juergen Gross <jgross@suse.com>
> Cc: Xenia Ragiadakou <burzalodowa@gmail.com>
>
> Changes V1 -> V2:
> - s/gfn_offset/pfn_offset
> - clarify gfn calculation when granting a page
>
> Previous discussion is at:
> https://lore.kernel.org/lkml/20221007132736.2275574-1-olekstysh@gmail.com/
> ---
> drivers/xen/grant-dma-ops.c | 9 ++++++---
> 1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/xen/grant-dma-ops.c b/drivers/xen/grant-dma-ops.c
> index c66f56d24013..1d018e3a68a0 100644
> --- a/drivers/xen/grant-dma-ops.c
> +++ b/drivers/xen/grant-dma-ops.c
> @@ -168,7 +168,9 @@ static dma_addr_t xen_grant_dma_map_page(struct device *dev, struct page *page,
> unsigned long attrs)
> {
> struct xen_grant_dma_data *data;
> - unsigned int i, n_pages = PFN_UP(offset + size);
> + unsigned long dma_offset = offset_in_page(offset),
> + pfn_offset = PFN_DOWN(offset);
> + unsigned int i, n_pages = PFN_UP(dma_offset + size);
> grant_ref_t grant;
> dma_addr_t dma_handle;
>
> @@ -187,10 +189,11 @@ static dma_addr_t xen_grant_dma_map_page(struct device *dev, struct page *page,
>
> for (i = 0; i < n_pages; i++) {
> gnttab_grant_foreign_access_ref(grant + i, data->backend_domid,
> - xen_page_to_gfn(page) + i, dir == DMA_TO_DEVICE);
> + pfn_to_gfn(page_to_xen_pfn(page) + i + pfn_offset),
> + dir == DMA_TO_DEVICE);
> }
>
> - dma_handle = grant_to_dma(grant) + offset;
> + dma_handle = grant_to_dma(grant) + dma_offset;
>
> return dma_handle;
> }
--
Xenia
next prev parent reply other threads:[~2022-10-14 7:35 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-08 15:10 [PATCH V2 0/2] Other misc fixes for Xen grant DMA-mapping layer Oleksandr Tyshchenko
2022-10-08 15:10 ` [PATCH V2 1/2] xen/virtio: Handle cases when page offset > PAGE_SIZE properly Oleksandr Tyshchenko
2022-10-14 0:22 ` Stefano Stabellini
2022-10-14 7:35 ` Xenia Ragiadakou [this message]
2022-10-08 15:10 ` [PATCH V2 2/2] xen/virtio: Convert PAGE_SIZE/PAGE_SHIFT/PFN_UP to Xen counterparts Oleksandr Tyshchenko
2022-10-14 0:24 ` Stefano Stabellini
2022-10-14 7:35 ` Xenia Ragiadakou
2022-10-15 14:03 ` [PATCH V2 0/2] Other misc fixes for Xen grant DMA-mapping layer Juergen Gross
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=ae26a54b-ece5-f8a3-2331-f7e495ecceea@gmail.com \
--to=burzalodowa@gmail.com \
--cc=jgross@suse.com \
--cc=linux-kernel@vger.kernel.org \
--cc=oleksandr_tyshchenko@epam.com \
--cc=olekstysh@gmail.com \
--cc=sstabellini@kernel.org \
--cc=xen-devel@lists.xenproject.org \
/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
all inboxes | Powered by JetHome®