From: Stewart Hildebrand <stewart.hildebrand@amd.com>
To: <xen-devel@lists.xenproject.org>
Cc: "Stewart Hildebrand" <stewart.hildebrand@amd.com>,
"Stefano Stabellini" <sstabellini@kernel.org>,
"Julien Grall" <julien@xen.org>,
"Bertrand Marquis" <bertrand.marquis@arm.com>,
"Michal Orzel" <michal.orzel@amd.com>,
"Volodymyr Babchuk" <Volodymyr_Babchuk@epam.com>,
"Andrew Cooper" <andrew.cooper3@citrix.com>,
"George Dunlap" <george.dunlap@citrix.com>,
"Jan Beulich" <jbeulich@suse.com>, "Wei Liu" <wl@xen.org>,
"Roger Pau Monné" <roger.pau@citrix.com>,
"Paul Durrant" <paul@xen.org>
Subject: [PATCH v6 4/5] [FUTURE] xen/arm: enable vPCI for domUs
Date: Mon, 13 Nov 2023 17:21:13 -0500 [thread overview]
Message-ID: <20231113222118.825758-5-stewart.hildebrand@amd.com> (raw)
In-Reply-To: <20231113222118.825758-1-stewart.hildebrand@amd.com>
Select HAS_VPCI_GUEST_SUPPORT in Kconfig for enabling vPCI support for
domUs.
Add checks to fail guest creation if the configuration is invalid.
Signed-off-by: Stewart Hildebrand <stewart.hildebrand@amd.com>
---
As the tag implies, this patch is not intended to be merged (yet).
Note that CONFIG_HAS_VPCI_GUEST_SUPPORT is not currently used in the
upstream code base. It will be used by the vPCI series [1]. This patch
is intended to be merged as part of the vPCI series. I'll coordinate
with Volodymyr to include this in the vPCI series or resend afterwards.
Meanwhile, I'll include it here until the Kconfig and
xen_domctl_createdomain prerequisites have been committed.
v5->v6:
* drop is_pvh_domain(), simply make arch_needs_vpci() return false on
x86 for now
* leave has_vpci() alone, instead, add HAS_VPCI_GUEST_SUPPORT check in
domain_create
v4->v5:
* replace is_system_domain() check with dom_io check
* return an error in XEN_DOMCTL_assign_device (thanks Jan!)
* remove CONFIG_ARM check
* add needs_vpci() and arch_needs_vpci()
* add HAS_VPCI_GUEST_SUPPORT check to has_vpci()
v3->v4:
* refuse to create domain if configuration is invalid
* split toolstack change into separate patch
v2->v3:
* set pci flags in toolstack
v1->v2:
* new patch
[1] https://lists.xenproject.org/archives/html/xen-devel/2023-10/msg00660.html
---
xen/arch/arm/Kconfig | 1 +
xen/arch/arm/include/asm/domain.h | 2 ++
xen/arch/arm/vpci.c | 8 ++++++++
xen/arch/x86/include/asm/domain.h | 2 ++
xen/common/domain.c | 5 +++++
xen/drivers/passthrough/pci.c | 20 ++++++++++++++++++++
6 files changed, 38 insertions(+)
diff --git a/xen/arch/arm/Kconfig b/xen/arch/arm/Kconfig
index 5ff68e5d5979..3845b238a33f 100644
--- a/xen/arch/arm/Kconfig
+++ b/xen/arch/arm/Kconfig
@@ -195,6 +195,7 @@ config PCI_PASSTHROUGH
depends on ARM_64
select HAS_PCI
select HAS_VPCI
+ select HAS_VPCI_GUEST_SUPPORT
default n
help
This option enables PCI device passthrough
diff --git a/xen/arch/arm/include/asm/domain.h b/xen/arch/arm/include/asm/domain.h
index 3614562eaefe..8e6d5fe9578c 100644
--- a/xen/arch/arm/include/asm/domain.h
+++ b/xen/arch/arm/include/asm/domain.h
@@ -31,6 +31,8 @@ enum domain_type {
#define is_domain_direct_mapped(d) ((d)->cdf & CDF_directmap)
+#define arch_needs_vpci(d) ({ (void)(d); true; })
+
/*
* Is the domain using the host memory layout?
*
diff --git a/xen/arch/arm/vpci.c b/xen/arch/arm/vpci.c
index 3bc4bb55082a..61e0edcedea9 100644
--- a/xen/arch/arm/vpci.c
+++ b/xen/arch/arm/vpci.c
@@ -2,6 +2,7 @@
/*
* xen/arch/arm/vpci.c
*/
+#include <xen/lib.h>
#include <xen/sched.h>
#include <xen/vpci.h>
@@ -90,8 +91,15 @@ int domain_vpci_init(struct domain *d)
return ret;
}
else
+ {
+ if ( !IS_ENABLED(CONFIG_HAS_VPCI_GUEST_SUPPORT) )
+ {
+ gdprintk(XENLOG_ERR, "vPCI requested but guest support not enabled\n");
+ return -EINVAL;
+ }
register_mmio_handler(d, &vpci_mmio_handler,
GUEST_VPCI_ECAM_BASE, GUEST_VPCI_ECAM_SIZE, NULL);
+ }
return 0;
}
diff --git a/xen/arch/x86/include/asm/domain.h b/xen/arch/x86/include/asm/domain.h
index cb02a4d1ebb2..d34015391eed 100644
--- a/xen/arch/x86/include/asm/domain.h
+++ b/xen/arch/x86/include/asm/domain.h
@@ -503,6 +503,8 @@ struct arch_domain
#define has_vpit(d) (!!((d)->arch.emulation_flags & X86_EMU_PIT))
#define has_pirq(d) (!!((d)->arch.emulation_flags & X86_EMU_USE_PIRQ))
+#define arch_needs_vpci(d) ({ (void)(d); false; })
+
#define gdt_ldt_pt_idx(v) \
((v)->vcpu_id >> (PAGETABLE_ORDER - GDT_LDT_VCPU_SHIFT))
#define pv_gdt_ptes(v) \
diff --git a/xen/common/domain.c b/xen/common/domain.c
index 12dc27428972..47d49c57bf83 100644
--- a/xen/common/domain.c
+++ b/xen/common/domain.c
@@ -692,6 +692,11 @@ struct domain *domain_create(domid_t domid,
if ( !is_idle_domain(d) )
{
+ err = -EINVAL;
+ if ( !is_hardware_domain(d) && (config->flags & XEN_DOMCTL_CDF_vpci) &&
+ !IS_ENABLED(CONFIG_HAS_VPCI_GUEST_SUPPORT) )
+ goto fail;
+
if ( !is_hardware_domain(d) )
d->nr_pirqs = nr_static_irqs + extra_domU_irqs;
else
diff --git a/xen/drivers/passthrough/pci.c b/xen/drivers/passthrough/pci.c
index 04d00c7c37df..2203725a2aa6 100644
--- a/xen/drivers/passthrough/pci.c
+++ b/xen/drivers/passthrough/pci.c
@@ -1542,6 +1542,18 @@ void iommu_dev_iotlb_flush_timeout(struct domain *d, struct pci_dev *pdev)
pcidevs_unlock();
}
+static bool needs_vpci(const struct domain *d)
+{
+ if ( is_hardware_domain(d) )
+ return false;
+
+ if ( d == dom_io )
+ /* xl pci-assignable-add assigns PCI devices to domIO */
+ return false;
+
+ return arch_needs_vpci(d);
+}
+
int iommu_do_pci_domctl(
struct xen_domctl *domctl, struct domain *d,
XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)
@@ -1618,6 +1630,14 @@ int iommu_do_pci_domctl(
bus = PCI_BUS(machine_sbdf);
devfn = PCI_DEVFN(machine_sbdf);
+ if ( needs_vpci(d) && !has_vpci(d) )
+ {
+ printk(XENLOG_G_WARNING "Cannot assign %pp to %pd: vPCI support not enabled\n",
+ &PCI_SBDF(seg, bus, devfn), d);
+ ret = -EPERM;
+ break;
+ }
+
pcidevs_lock();
ret = device_assigned(seg, bus, devfn);
if ( domctl->cmd == XEN_DOMCTL_test_assign_device )
--
2.42.0
next prev parent reply other threads:[~2023-11-13 22:22 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-13 22:21 [PATCH v6 0/5] Kconfig for PCI passthrough on ARM Stewart Hildebrand
2023-11-13 22:21 ` [PATCH v6 1/5] xen/arm: pci: introduce PCI_PASSTHROUGH Kconfig option Stewart Hildebrand
2023-11-13 22:21 ` [PATCH v6 2/5] xen/vpci: move xen_domctl_createdomain vPCI flag to common Stewart Hildebrand
2023-11-14 9:11 ` Jan Beulich
2023-11-29 21:25 ` Stewart Hildebrand
2023-12-15 9:36 ` Rahul Singh
2023-12-19 18:55 ` Stewart Hildebrand
2023-11-13 22:21 ` [PATCH v6 3/5] [FUTURE] xen/arm: enable vPCI for dom0 Stewart Hildebrand
2023-11-13 22:21 ` Stewart Hildebrand [this message]
2023-11-14 9:13 ` [PATCH v6 4/5] [FUTURE] xen/arm: enable vPCI for domUs Jan Beulich
2023-11-30 2:47 ` Stewart Hildebrand
2023-11-30 8:33 ` Jan Beulich
2023-11-30 17:06 ` Stewart Hildebrand
2023-12-01 6:57 ` Jan Beulich
2023-12-01 9:16 ` Roger Pau Monné
2023-12-02 2:56 ` Stefano Stabellini
2023-12-04 3:54 ` Stewart Hildebrand
2023-12-04 8:24 ` Jan Beulich
2023-12-04 10:58 ` Roger Pau Monné
2023-12-04 19:09 ` Stewart Hildebrand
2023-12-04 22:07 ` Stefano Stabellini
2023-12-05 11:08 ` Roger Pau Monné
2023-12-05 16:27 ` Stewart Hildebrand
2023-12-05 17:09 ` Roger Pau Monné
2023-12-05 17:36 ` Stewart Hildebrand
2023-12-05 23:25 ` Stefano Stabellini
2023-12-05 19:01 ` Stewart Hildebrand
2023-12-11 9:42 ` Roger Pau Monné
2023-12-06 2:34 ` Stefano Stabellini
2023-12-11 10:36 ` Roger Pau Monné
2023-12-12 1:34 ` Stefano Stabellini
2023-11-13 22:21 ` [PATCH v6 5/5] [FUTURE] tools/arm: " Stewart Hildebrand
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=20231113222118.825758-5-stewart.hildebrand@amd.com \
--to=stewart.hildebrand@amd.com \
--cc=Volodymyr_Babchuk@epam.com \
--cc=andrew.cooper3@citrix.com \
--cc=bertrand.marquis@arm.com \
--cc=george.dunlap@citrix.com \
--cc=jbeulich@suse.com \
--cc=julien@xen.org \
--cc=michal.orzel@amd.com \
--cc=paul@xen.org \
--cc=roger.pau@citrix.com \
--cc=sstabellini@kernel.org \
--cc=wl@xen.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 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.