lkml.org 
[lkml]   [2022]   [Apr]   [23]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
SubjectRe: [PATCH V1 3/6] xen/virtio: Add option to restrict memory access under Xen
From
Date

On 23.04.22 02:00, Stefano Stabellini wrote:

Hello Stefano


> On Fri, 22 Apr 2022, Oleksandr Tyshchenko wrote:
>> From: Juergen Gross <jgross@suse.com>
>>
>> Introduce Xen grant DMA-mapping layer which contains special DMA-mapping
>> routines for providing grant references as DMA addresses to be used by
>> frontends (e.g. virtio) in Xen guests.
>>
>> In order to support virtio in Xen guests add a config option XEN_VIRTIO
>> enabling the user to specify whether in all Xen guests virtio should
>> be able to access memory via Xen grant mappings only on the host side.
>>
>> As this also requires providing arch_has_restricted_virtio_memory_access
>> implementation, switch from a pure stub to a real function on Arm
>> and combine with existing implementation for the SEV guests on x86.
>>
>> Add the needed functionality by providing a special set of DMA ops
>> handling the needed grant operations for the I/O pages.
>>
>> Signed-off-by: Juergen Gross <jgross@suse.com>
>> Signed-off-by: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>
> There are a couple of minor things that checkpatch.pl reports,

Thank you for pointing this out, my fault.


> but aside
> from those the patch looks fine to me.

good


The attached diff to be squashed for the new version. One thing remains:

checkpatch.pl says regarding drivers/xen/grant-dma-ops.c:

WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
#151:
new file mode 100644


Which, I assume, this is not an issue as new file falls under XEN
HYPERVISOR INTERFACE maintainership?

scripts/get_maintainer.pl -f drivers/xen/grant-dma-ops.c
Boris Ostrovsky <boris.ostrovsky@oracle.com> (supporter:XEN HYPERVISOR
INTERFACE)
Juergen Gross <jgross@suse.com> (supporter:XEN HYPERVISOR INTERFACE)
Stefano Stabellini <sstabellini@kernel.org> (reviewer:XEN HYPERVISOR
INTERFACE)
xen-devel@lists.xenproject.org (moderated list:XEN HYPERVISOR INTERFACE)
linux-kernel@vger.kernel.org (open list)

[snip]

--
Regards,

Oleksandr Tyshchenko

From 8d36fc5a3604a69848c300a42f1a78f8ace41829 Mon Sep 17 00:00:00 2001
From: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>
Date: Sat, 23 Apr 2022 09:23:04 +0300
Subject: [PATCH] fixup

Signed-off-by: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>
---
drivers/xen/Kconfig | 2 ++
drivers/xen/grant-dma-ops.c | 21 ++++++++++++---------
2 files changed, 14 insertions(+), 9 deletions(-)

diff --git a/drivers/xen/Kconfig b/drivers/xen/Kconfig
index b95581f..1727337 100644
--- a/drivers/xen/Kconfig
+++ b/drivers/xen/Kconfig
@@ -350,4 +350,6 @@ config XEN_VIRTIO
guest type this will require special support on the backend side
(qemu or kernel, depending on the virtio device types used).

+ If in doubt, say n.
+
endmenu
diff --git a/drivers/xen/grant-dma-ops.c b/drivers/xen/grant-dma-ops.c
index 70d5d77..b9d93d7 100644
--- a/drivers/xen/grant-dma-ops.c
+++ b/drivers/xen/grant-dma-ops.c
@@ -139,7 +139,7 @@ static struct page *xen_grant_dma_alloc_pages(struct device *dev, size_t size,
enum dma_data_direction dir,
gfp_t gfp)
{
- WARN_ONCE(1, "xen_grant_dma_alloc_pages size %zu\n", size);
+ WARN_ONCE(1, "%s: size %zu\n", __func__, size);
return NULL;
}

@@ -147,7 +147,7 @@ static void xen_grant_dma_free_pages(struct device *dev, size_t size,
struct page *vaddr, dma_addr_t dma_handle,
enum dma_data_direction dir)
{
- WARN_ONCE(1, "xen_grant_dma_free_pages size %zu\n", size);
+ WARN_ONCE(1, "%s: size %zu\n", __func__, size);
}

static dma_addr_t xen_grant_dma_map_page(struct device *dev, struct page *page,
@@ -160,7 +160,8 @@ static dma_addr_t xen_grant_dma_map_page(struct device *dev, struct page *page,
grant_ref_t grant;
dma_addr_t dma_handle;

- BUG_ON(dir == DMA_NONE);
+ if (WARN_ON(dir == DMA_NONE))
+ return DMA_MAPPING_ERROR;

data = find_xen_grant_dma_data(dev);
if (!data)
@@ -190,7 +191,8 @@ static void xen_grant_dma_unmap_page(struct device *dev, dma_addr_t dma_handle,
unsigned int i, n_pages = PFN_UP(size);
grant_ref_t grant;

- BUG_ON(dir == DMA_NONE);
+ if (WARN_ON(dir == DMA_NONE))
+ return;

data = find_xen_grant_dma_data(dev);
if (!data)
@@ -219,7 +221,8 @@ static void xen_grant_dma_unmap_sg(struct device *dev, struct scatterlist *sg,
struct scatterlist *s;
unsigned int i;

- BUG_ON(dir == DMA_NONE);
+ if (WARN_ON(dir == DMA_NONE))
+ return;

for_each_sg(sg, s, nents, i)
xen_grant_dma_unmap_page(dev, s->dma_address, sg_dma_len(s), dir,
@@ -233,7 +236,8 @@ static int xen_grant_dma_map_sg(struct device *dev, struct scatterlist *sg,
struct scatterlist *s;
unsigned int i;

- BUG_ON(dir == DMA_NONE);
+ if (WARN_ON(dir == DMA_NONE))
+ return -EINVAL;

for_each_sg(sg, s, nents, i) {
s->dma_address = xen_grant_dma_map_page(dev, sg_page(s), s->offset,
@@ -303,10 +307,9 @@ void xen_grant_setup_dma_ops(struct device *dev)
}

data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
- if (!data) {
- dev_err(dev, "Сannot allocate Xen grant DMA data\n");
+ if (!data)
goto err;
- }
+
data->dev_domid = dev_domid;
data->dev = dev;

--
2.7.4
\
 
 \ /
  Last update: 2022-04-23 09:07    [W:0.251 / U:0.048 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site