From: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
To: xen-devel@lists.xensource.com
Cc: julien.grall@citrix.com, Ian.Campbell@citrix.com,
JBeulich@suse.com,
Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Subject: [PATCH v6 3/3] xen/arm: introduce XENFEAT_grant_map_identity
Date: Fri, 1 Aug 2014 15:45:25 +0100 [thread overview]
Message-ID: <1406904325-15722-3-git-send-email-stefano.stabellini@eu.citrix.com> (raw)
In-Reply-To: <alpine.DEB.2.02.1408011539110.2293@kaball.uk.xensource.com>
The flag specifies that the hypervisor maps a grant page to guest
physical address == machine address of the page in addition to the
normal grant mapping address.
Frontends are allowed to map the same page multiple times using multiple
grant references. On the backend side it can be difficult to find out
the physical address corresponding to a particular machine address,
especially at the completion of a dma operation. To simplify address
translations, we introduce a second mapping of the grant at physical
address == machine address so that dom0 can issue cache maintenance
operations without having to find the pfn.
Call arch_grant_map_page_identity and arch_grant_unmap_page_identity
from __gnttab_map_grant_ref and __gnttab_unmap_common to introduce the
second mapping if the domain is directly mapped. To do so we also need
to change gnttab_need_iommu_mapping to just be defined as
is_domain_direct_mapped on arm.
Remove arm_smmu_map_page and arm_smmu_unmap_page as they have become
unused.
Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Julien Grall <julien.grall@linaro.org>
---
Changes in v5:
- fix coding style;
- remove arm_smmu_map_page and arm_smmu_unmap_page.
Changes in v4:
- add XENFEAT_grant_map_identity if is_domain_direct_mapped;
- remove gnttab_need_identity_mapping, check is_domain_direct_mapped
instead;
- define gnttab_need_iommu_mapping as is_domain_direct_mapped on arm.
Changes in v3:
- introduce gnttab_need_identity_mapping;
- check gnttab_need_identity_mapping in __gnttab_map_grant_ref and
__gnttab_unmap_common.
Changes in v2:
- rename XENFEAT_grant_map_11 to XENFEAT_grant_map_identity;
- remove superfluous ifdef CONFIG_ARM in xen/common/kernel.c;
- don't modify gnttab_need_iommu_mapping;
- call arch_grant_map_page_identity and arch_grant_unmap_page_identity
from grant_table functions.
---
xen/common/grant_table.c | 30 +++++++++++++++++++++++++-----
xen/common/kernel.c | 2 ++
xen/drivers/passthrough/arm/smmu.c | 33 ---------------------------------
xen/include/asm-arm/grant_table.h | 3 +--
xen/include/public/features.h | 3 +++
5 files changed, 31 insertions(+), 40 deletions(-)
diff --git a/xen/common/grant_table.c b/xen/common/grant_table.c
index 464007e..23266c3 100644
--- a/xen/common/grant_table.c
+++ b/xen/common/grant_table.c
@@ -738,13 +738,23 @@ __gnttab_map_grant_ref(
!(old_pin & (GNTPIN_hstw_mask|GNTPIN_devw_mask)) )
{
if ( wrc == 0 )
- err = iommu_map_page(ld, frame, frame,
- IOMMUF_readable|IOMMUF_writable);
+ {
+ if ( is_domain_direct_mapped(ld) )
+ err = arch_grant_map_page_identity(ld, frame, 1);
+ else
+ err = iommu_map_page(ld, frame, frame,
+ IOMMUF_readable|IOMMUF_writable);
+ }
}
else if ( act_pin && !old_pin )
{
if ( (wrc + rdc) == 0 )
- err = iommu_map_page(ld, frame, frame, IOMMUF_readable);
+ {
+ if ( is_domain_direct_mapped(ld) )
+ err = arch_grant_map_page_identity(ld, frame, 0);
+ else
+ err = iommu_map_page(ld, frame, frame, IOMMUF_readable);
+ }
}
if ( err )
{
@@ -941,9 +951,19 @@ __gnttab_unmap_common(
int err = 0;
mapcount(lgt, rd, op->frame, &wrc, &rdc);
if ( (wrc + rdc) == 0 )
- err = iommu_unmap_page(ld, op->frame);
+ {
+ if ( is_domain_direct_mapped(ld) )
+ err = arch_grant_unmap_page_identity(ld, op->frame);
+ else
+ err = iommu_unmap_page(ld, op->frame);
+ }
else if ( wrc == 0 )
- err = iommu_map_page(ld, op->frame, op->frame, IOMMUF_readable);
+ {
+ if ( is_domain_direct_mapped(ld) )
+ err = arch_grant_map_page_identity(ld, op->frame, 0);
+ else
+ err = iommu_map_page(ld, op->frame, op->frame, IOMMUF_readable);
+ }
if ( err )
{
rc = GNTST_general_error;
diff --git a/xen/common/kernel.c b/xen/common/kernel.c
index 7e83353..fa40a36 100644
--- a/xen/common/kernel.c
+++ b/xen/common/kernel.c
@@ -325,6 +325,8 @@ DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
break;
}
#endif
+ if ( is_domain_direct_mapped(d) )
+ fi.submap |= 1U << XENFEAT_grant_map_identity;
break;
default:
return -EINVAL;
diff --git a/xen/drivers/passthrough/arm/smmu.c b/xen/drivers/passthrough/arm/smmu.c
index fb0c694..21b4572 100644
--- a/xen/drivers/passthrough/arm/smmu.c
+++ b/xen/drivers/passthrough/arm/smmu.c
@@ -1536,37 +1536,6 @@ static void arm_smmu_iommu_domain_teardown(struct domain *d)
xfree(smmu_domain);
}
-static int arm_smmu_map_page(struct domain *d, unsigned long gfn,
- unsigned long mfn, unsigned int flags)
-{
- /* Grant mappings can be used for DMA requests. The dev_bus_addr returned by
- * the hypercall is the MFN (not the IPA). For device protected by
- * an IOMMU, Xen needs to add a 1:1 mapping in the domain p2m to
- * allow DMA request to work.
- * This is only valid when the domain is directed mapped. Hence this
- * function should only be used by gnttab code with gfn == mfn.
- */
- BUG_ON(!is_domain_direct_mapped(d));
- BUG_ON(mfn != gfn);
-
- /* We only support readable and writable flags */
- if ( !(flags & (IOMMUF_readable | IOMMUF_writable)) )
- return -EINVAL;
-
- return arch_grant_map_page_identity(d, mfn, flags & IOMMUF_writable);
-}
-
-static int arm_smmu_unmap_page(struct domain *d, unsigned long gfn)
-{
- /* This function should only be used by gnttab code when the domain
- * is direct mapped
- */
- if ( !is_domain_direct_mapped(d) )
- return -EINVAL;
-
- return arch_grant_unmap_page_identity(d, gfn);
-}
-
static const struct iommu_ops arm_smmu_iommu_ops = {
.init = arm_smmu_iommu_domain_init,
.hwdom_init = arm_smmu_iommu_hwdom_init,
@@ -1575,8 +1544,6 @@ static const struct iommu_ops arm_smmu_iommu_ops = {
.iotlb_flush_all = arm_smmu_iotlb_flush_all,
.assign_dt_device = arm_smmu_attach_dev,
.reassign_dt_device = arm_smmu_reassign_dt_dev,
- .map_page = arm_smmu_map_page,
- .unmap_page = arm_smmu_unmap_page,
};
static int __init smmu_init(struct dt_device_node *dev,
diff --git a/xen/include/asm-arm/grant_table.h b/xen/include/asm-arm/grant_table.h
index eac8a70..47147ce 100644
--- a/xen/include/asm-arm/grant_table.h
+++ b/xen/include/asm-arm/grant_table.h
@@ -33,8 +33,7 @@ static inline int replace_grant_supported(void)
( ((i >= nr_grant_frames(d->grant_table)) && \
(i < max_nr_grant_frames)) ? 0 : (d->arch.grant_table_gpfn[i]))
-#define gnttab_need_iommu_mapping(d) \
- (is_domain_direct_mapped(d) && need_iommu(d))
+#define gnttab_need_iommu_mapping(d) (is_domain_direct_mapped(d))
#endif /* __ASM_GRANT_TABLE_H__ */
/*
diff --git a/xen/include/public/features.h b/xen/include/public/features.h
index a149aa6..b7bf83f 100644
--- a/xen/include/public/features.h
+++ b/xen/include/public/features.h
@@ -94,6 +94,9 @@
/* operation as Dom0 is supported */
#define XENFEAT_dom0 11
+/* Xen also maps grant references at pfn = mfn */
+#define XENFEAT_grant_map_identity 12
+
#define XENFEAT_NR_SUBMAPS 1
#endif /* __XEN_PUBLIC_FEATURES_H__ */
--
1.7.10.4
next prev parent reply other threads:[~2014-08-01 14:45 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-08-01 14:43 [PATCH v6 0/3] map grant refs at pfn = mfn Stefano Stabellini
2014-08-01 14:45 ` [PATCH v6 1/3] xen/x86: introduce is_domain_direct_mapped(d) as ((void)(d), 0) on x86 Stefano Stabellini
2014-08-01 14:45 ` [PATCH v6 2/3] xen: introduce arch_grant_(un)map_page_identity Stefano Stabellini
2014-08-01 14:45 ` Stefano Stabellini [this message]
2014-09-09 11:06 ` [PATCH v6 0/3] map grant refs at pfn = mfn Ian Campbell
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=1406904325-15722-3-git-send-email-stefano.stabellini@eu.citrix.com \
--to=stefano.stabellini@eu.citrix.com \
--cc=Ian.Campbell@citrix.com \
--cc=JBeulich@suse.com \
--cc=julien.grall@citrix.com \
--cc=xen-devel@lists.xensource.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).