linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/4] swiotlb-xen: remaining fixes and adjustments
@ 2021-09-17 10:43 Jan Beulich
  2021-09-17 10:45 ` [PATCH v2 1/4] swiotlb-xen: ensure to issue well-formed XENMEM_exchange requests Jan Beulich
                   ` (4 more replies)
  0 siblings, 5 replies; 8+ messages in thread
From: Jan Beulich @ 2021-09-17 10:43 UTC (permalink / raw)
  To: Juergen Gross, Boris Ostrovsky
  Cc: Stefano Stabellini, lkml, xen-devel, hch, Konrad Wilk, iommu

The primary intention really was the last patch, there you go (on top
of what is already in xen/tip.git for-linus-5.15) ...

1: swiotlb-xen: ensure to issue well-formed XENMEM_exchange requests
2: PCI: only build xen-pcifront in PV-enabled environments
3: xen/pci-swiotlb: reduce visibility of symbols
4: swiotlb-xen: this is PV-only on x86

Jan


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v2 1/4] swiotlb-xen: ensure to issue well-formed XENMEM_exchange requests
  2021-09-17 10:43 [PATCH v2 0/4] swiotlb-xen: remaining fixes and adjustments Jan Beulich
@ 2021-09-17 10:45 ` Jan Beulich
  2021-09-17 20:04   ` Stefano Stabellini
  2021-09-17 10:48 ` [PATCH v2 2/4] PCI: only build xen-pcifront in PV-enabled environments Jan Beulich
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 8+ messages in thread
From: Jan Beulich @ 2021-09-17 10:45 UTC (permalink / raw)
  To: Juergen Gross, Boris Ostrovsky
  Cc: Stefano Stabellini, lkml, xen-devel, hch, Konrad Wilk, iommu

While the hypervisor hasn't been enforcing this, we would still better
avoid issuing requests with GFNs not aligned to the requested order.
Instead of altering the value also in the call to panic(), drop it
there for being static and hence easy to determine without being part
of the panic message.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
---
I question how useful it is to wrap "bytes" in PAGE_ALIGN(), when it is
a multiple of a segment's size anyway (or at least was supposed to be,
prior to "swiotlb-xen: maintain slab count properly"). But that's
perhaps yet another separate patch.
---
v2: Drop logging of alignment. Wrap lines.

--- a/drivers/xen/swiotlb-xen.c
+++ b/drivers/xen/swiotlb-xen.c
@@ -230,10 +230,11 @@ retry:
 	/*
 	 * Get IO TLB memory from any location.
 	 */
-	start = memblock_alloc(PAGE_ALIGN(bytes), PAGE_SIZE);
+	start = memblock_alloc(PAGE_ALIGN(bytes),
+			       IO_TLB_SEGSIZE << IO_TLB_SHIFT);
 	if (!start)
-		panic("%s: Failed to allocate %lu bytes align=0x%lx\n",
-		      __func__, PAGE_ALIGN(bytes), PAGE_SIZE);
+		panic("%s: Failed to allocate %lu bytes\n",
+		      __func__, PAGE_ALIGN(bytes));
 
 	/*
 	 * And replace that memory with pages under 4GB.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v2 2/4] PCI: only build xen-pcifront in PV-enabled environments
  2021-09-17 10:43 [PATCH v2 0/4] swiotlb-xen: remaining fixes and adjustments Jan Beulich
  2021-09-17 10:45 ` [PATCH v2 1/4] swiotlb-xen: ensure to issue well-formed XENMEM_exchange requests Jan Beulich
@ 2021-09-17 10:48 ` Jan Beulich
  2021-09-17 16:28   ` Bjorn Helgaas
  2021-09-17 10:49 ` [PATCH v2 3/4] xen/pci-swiotlb: reduce visibility of symbols Jan Beulich
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 8+ messages in thread
From: Jan Beulich @ 2021-09-17 10:48 UTC (permalink / raw)
  To: bhelgaas
  Cc: Stefano Stabellini, lkml, xen-devel, hch, Konrad Wilk, iommu,
	Boris Ostrovsky, Juergen Gross, linux-pci

The driver's module init function, pcifront_init(), invokes
xen_pv_domain() first thing. That construct produces constant "false"
when !CONFIG_XEN_PV. Hence there's no point building the driver in
non-PV configurations.

Drop the (now implicit and generally wrong) X86 dependency: At present,
XEN_PV con only be set when X86 is also enabled. In general an
architecture supporting Xen PV (and PCI) would want to have this driver
built.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
---
v2: Title and description redone.

--- a/drivers/pci/Kconfig
+++ b/drivers/pci/Kconfig
@@ -110,7 +110,7 @@ config PCI_PF_STUB
 
 config XEN_PCIDEV_FRONTEND
 	tristate "Xen PCI Frontend"
-	depends on X86 && XEN
+	depends on XEN_PV
 	select PCI_XEN
 	select XEN_XENBUS_FRONTEND
 	default y


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v2 3/4] xen/pci-swiotlb: reduce visibility of symbols
  2021-09-17 10:43 [PATCH v2 0/4] swiotlb-xen: remaining fixes and adjustments Jan Beulich
  2021-09-17 10:45 ` [PATCH v2 1/4] swiotlb-xen: ensure to issue well-formed XENMEM_exchange requests Jan Beulich
  2021-09-17 10:48 ` [PATCH v2 2/4] PCI: only build xen-pcifront in PV-enabled environments Jan Beulich
@ 2021-09-17 10:49 ` Jan Beulich
  2021-09-17 10:50 ` [PATCH v2 4/4] swiotlb-xen: this is PV-only on x86 Jan Beulich
  2021-09-20 15:19 ` [PATCH v2 0/4] swiotlb-xen: remaining fixes and adjustments Juergen Gross
  4 siblings, 0 replies; 8+ messages in thread
From: Jan Beulich @ 2021-09-17 10:49 UTC (permalink / raw)
  To: Juergen Gross, Boris Ostrovsky
  Cc: Stefano Stabellini, lkml, xen-devel, hch, Konrad Wilk, iommu

xen_swiotlb and pci_xen_swiotlb_init() are only used within the file
defining them, so make them static and remove the stubs. Otoh
pci_xen_swiotlb_detect() has a use (as function pointer) from the main
pci-swiotlb.c file - convert its stub to a #define to NULL.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>

--- a/arch/x86/include/asm/xen/swiotlb-xen.h
+++ b/arch/x86/include/asm/xen/swiotlb-xen.h
@@ -3,14 +3,10 @@
 #define _ASM_X86_SWIOTLB_XEN_H
 
 #ifdef CONFIG_SWIOTLB_XEN
-extern int xen_swiotlb;
 extern int __init pci_xen_swiotlb_detect(void);
-extern void __init pci_xen_swiotlb_init(void);
 extern int pci_xen_swiotlb_init_late(void);
 #else
-#define xen_swiotlb (0)
-static inline int __init pci_xen_swiotlb_detect(void) { return 0; }
-static inline void __init pci_xen_swiotlb_init(void) { }
+#define pci_xen_swiotlb_detect NULL
 static inline int pci_xen_swiotlb_init_late(void) { return -ENXIO; }
 #endif
 
--- a/arch/x86/xen/pci-swiotlb-xen.c
+++ b/arch/x86/xen/pci-swiotlb-xen.c
@@ -18,7 +18,7 @@
 #endif
 #include <linux/export.h>
 
-int xen_swiotlb __read_mostly;
+static int xen_swiotlb __read_mostly;
 
 /*
  * pci_xen_swiotlb_detect - set xen_swiotlb to 1 if necessary
@@ -56,7 +56,7 @@ int __init pci_xen_swiotlb_detect(void)
 	return xen_swiotlb;
 }
 
-void __init pci_xen_swiotlb_init(void)
+static void __init pci_xen_swiotlb_init(void)
 {
 	if (xen_swiotlb) {
 		xen_swiotlb_init_early();


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v2 4/4] swiotlb-xen: this is PV-only on x86
  2021-09-17 10:43 [PATCH v2 0/4] swiotlb-xen: remaining fixes and adjustments Jan Beulich
                   ` (2 preceding siblings ...)
  2021-09-17 10:49 ` [PATCH v2 3/4] xen/pci-swiotlb: reduce visibility of symbols Jan Beulich
@ 2021-09-17 10:50 ` Jan Beulich
  2021-09-20 15:19 ` [PATCH v2 0/4] swiotlb-xen: remaining fixes and adjustments Juergen Gross
  4 siblings, 0 replies; 8+ messages in thread
From: Jan Beulich @ 2021-09-17 10:50 UTC (permalink / raw)
  To: Juergen Gross, Boris Ostrovsky
  Cc: Stefano Stabellini, lkml, xen-devel, hch, Konrad Wilk, iommu,
	the arch/x86 maintainers, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov

The code is unreachable for HVM or PVH, and it also makes little sense
in auto-translated environments. On Arm, with
xen_{create,destroy}_contiguous_region() both being stubs, I have a hard
time seeing what good the Xen specific variant does - the generic one
ought to be fine for all purposes there. Still Arm code explicitly
references symbols here, so the code will continue to be included there.

Instead of making PCI_XEN's "select" conditional, simply drop it -
SWIOTLB_XEN will be available unconditionally in the PV case anyway, and
is - as explained above - dead code in non-PV environments.

This in turn allows dropping the stubs for
xen_{create,destroy}_contiguous_region(), the former of which was broken
anyway - it failed to set the DMA handle output.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>

--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -2605,7 +2605,6 @@ config PCI_OLPC
 config PCI_XEN
 	def_bool y
 	depends on PCI && XEN
-	select SWIOTLB_XEN
 
 config MMCONF_FAM10H
 	def_bool y
--- a/drivers/xen/Kconfig
+++ b/drivers/xen/Kconfig
@@ -177,6 +177,7 @@ config XEN_GRANT_DMA_ALLOC
 
 config SWIOTLB_XEN
 	def_bool y
+	depends on XEN_PV || ARM || ARM64
 	select DMA_OPS
 	select SWIOTLB
 
--- a/include/xen/xen-ops.h
+++ b/include/xen/xen-ops.h
@@ -46,19 +46,7 @@ extern unsigned long *xen_contiguous_bit
 int xen_create_contiguous_region(phys_addr_t pstart, unsigned int order,
 				unsigned int address_bits,
 				dma_addr_t *dma_handle);
-
 void xen_destroy_contiguous_region(phys_addr_t pstart, unsigned int order);
-#else
-static inline int xen_create_contiguous_region(phys_addr_t pstart,
-					       unsigned int order,
-					       unsigned int address_bits,
-					       dma_addr_t *dma_handle)
-{
-	return 0;
-}
-
-static inline void xen_destroy_contiguous_region(phys_addr_t pstart,
-						 unsigned int order) { }
 #endif
 
 #if defined(CONFIG_XEN_PV)


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2 2/4] PCI: only build xen-pcifront in PV-enabled environments
  2021-09-17 10:48 ` [PATCH v2 2/4] PCI: only build xen-pcifront in PV-enabled environments Jan Beulich
@ 2021-09-17 16:28   ` Bjorn Helgaas
  0 siblings, 0 replies; 8+ messages in thread
From: Bjorn Helgaas @ 2021-09-17 16:28 UTC (permalink / raw)
  To: Jan Beulich
  Cc: bhelgaas, Stefano Stabellini, lkml, xen-devel, hch, Konrad Wilk,
	iommu, Boris Ostrovsky, Juergen Gross, linux-pci

s/only/Only/ in subject

On Fri, Sep 17, 2021 at 12:48:03PM +0200, Jan Beulich wrote:
> The driver's module init function, pcifront_init(), invokes
> xen_pv_domain() first thing. That construct produces constant "false"
> when !CONFIG_XEN_PV. Hence there's no point building the driver in
> non-PV configurations.

Thanks for these bread crumbs.  xen_domain_type is set to
XEN_PV_DOMAIN only by xen_start_kernel() in enlighten_pv.c, which is
only built when CONFIG_XEN_PV=y, so even I can verify this :)

> Drop the (now implicit and generally wrong) X86 dependency: At present,
> XEN_PV con only be set when X86 is also enabled. In general an
> architecture supporting Xen PV (and PCI) would want to have this driver
> built.

s/con only/can only/

> Signed-off-by: Jan Beulich <jbeulich@suse.com>
> Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>

Acked-by: Bjorn Helgaas <bhelgaas@google.com>

> ---
> v2: Title and description redone.
> 
> --- a/drivers/pci/Kconfig
> +++ b/drivers/pci/Kconfig
> @@ -110,7 +110,7 @@ config PCI_PF_STUB
>  
>  config XEN_PCIDEV_FRONTEND
>  	tristate "Xen PCI Frontend"
> -	depends on X86 && XEN
> +	depends on XEN_PV
>  	select PCI_XEN
>  	select XEN_XENBUS_FRONTEND
>  	default y
> 

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2 1/4] swiotlb-xen: ensure to issue well-formed XENMEM_exchange requests
  2021-09-17 10:45 ` [PATCH v2 1/4] swiotlb-xen: ensure to issue well-formed XENMEM_exchange requests Jan Beulich
@ 2021-09-17 20:04   ` Stefano Stabellini
  0 siblings, 0 replies; 8+ messages in thread
From: Stefano Stabellini @ 2021-09-17 20:04 UTC (permalink / raw)
  To: Jan Beulich
  Cc: Juergen Gross, Boris Ostrovsky, Stefano Stabellini, lkml,
	xen-devel, hch, Konrad Wilk, iommu

On Fri, 17 Sep 2021, Jan Beulich wrote:
> While the hypervisor hasn't been enforcing this, we would still better
> avoid issuing requests with GFNs not aligned to the requested order.
> Instead of altering the value also in the call to panic(), drop it
> there for being static and hence easy to determine without being part
> of the panic message.
> 
> Signed-off-by: Jan Beulich <jbeulich@suse.com>

Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>


> ---
> I question how useful it is to wrap "bytes" in PAGE_ALIGN(), when it is
> a multiple of a segment's size anyway (or at least was supposed to be,
> prior to "swiotlb-xen: maintain slab count properly"). But that's
> perhaps yet another separate patch.
> ---
> v2: Drop logging of alignment. Wrap lines.
> 
> --- a/drivers/xen/swiotlb-xen.c
> +++ b/drivers/xen/swiotlb-xen.c
> @@ -230,10 +230,11 @@ retry:
>  	/*
>  	 * Get IO TLB memory from any location.
>  	 */
> -	start = memblock_alloc(PAGE_ALIGN(bytes), PAGE_SIZE);
> +	start = memblock_alloc(PAGE_ALIGN(bytes),
> +			       IO_TLB_SEGSIZE << IO_TLB_SHIFT);
>  	if (!start)
> -		panic("%s: Failed to allocate %lu bytes align=0x%lx\n",
> -		      __func__, PAGE_ALIGN(bytes), PAGE_SIZE);
> +		panic("%s: Failed to allocate %lu bytes\n",
> +		      __func__, PAGE_ALIGN(bytes));
>  
>  	/*
>  	 * And replace that memory with pages under 4GB.
> 

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2 0/4] swiotlb-xen: remaining fixes and adjustments
  2021-09-17 10:43 [PATCH v2 0/4] swiotlb-xen: remaining fixes and adjustments Jan Beulich
                   ` (3 preceding siblings ...)
  2021-09-17 10:50 ` [PATCH v2 4/4] swiotlb-xen: this is PV-only on x86 Jan Beulich
@ 2021-09-20 15:19 ` Juergen Gross
  4 siblings, 0 replies; 8+ messages in thread
From: Juergen Gross @ 2021-09-20 15:19 UTC (permalink / raw)
  To: Jan Beulich, Boris Ostrovsky
  Cc: Stefano Stabellini, lkml, xen-devel, hch, Konrad Wilk, iommu


[-- Attachment #1.1.1: Type: text/plain, Size: 469 bytes --]

On 17.09.21 12:43, Jan Beulich wrote:
> The primary intention really was the last patch, there you go (on top
> of what is already in xen/tip.git for-linus-5.15) ...
> 
> 1: swiotlb-xen: ensure to issue well-formed XENMEM_exchange requests
> 2: PCI: only build xen-pcifront in PV-enabled environments
> 3: xen/pci-swiotlb: reduce visibility of symbols
> 4: swiotlb-xen: this is PV-only on x86

All 4 patches pushed to xen/tip.git for-linus-5.15b


Juergen

[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 3135 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 495 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-09-20 15:19 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-17 10:43 [PATCH v2 0/4] swiotlb-xen: remaining fixes and adjustments Jan Beulich
2021-09-17 10:45 ` [PATCH v2 1/4] swiotlb-xen: ensure to issue well-formed XENMEM_exchange requests Jan Beulich
2021-09-17 20:04   ` Stefano Stabellini
2021-09-17 10:48 ` [PATCH v2 2/4] PCI: only build xen-pcifront in PV-enabled environments Jan Beulich
2021-09-17 16:28   ` Bjorn Helgaas
2021-09-17 10:49 ` [PATCH v2 3/4] xen/pci-swiotlb: reduce visibility of symbols Jan Beulich
2021-09-17 10:50 ` [PATCH v2 4/4] swiotlb-xen: this is PV-only on x86 Jan Beulich
2021-09-20 15:19 ` [PATCH v2 0/4] swiotlb-xen: remaining fixes and adjustments Juergen Gross

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).