(mainly) IOMMU hook adjustments
cover (mainly) IOMMU hook adjustments
Besides the altcall conversion, some further adjustments appeared desirable to do while touching that area.
1: IOMMU/x86: switch to alternatives-call patching in further instances 2: VT-d / x86: re-arrange cache syncing
3: VT-d: replace flush_all_cache()
4: libxc: correct bounce direction in xc_get_device_group()
Jan
PATCH 1/4 IOMMU/x86: switch to alternatives-call patching in further instances
This is, once again, to limit the number of indirect calls as much as possible. The only hook invocation which isn't sensible to convert is setup(). And of course Arm-only use sites are left alone as well.
Note regarding the introduction / use of local variables in pci.c:
struct pci_dev's involved fields are const. This const propagates, via typeof(), to the local helper variables in the altcall macros. These helper variables are, however, used as outputs (and hence can't be const). In iommu_get_device_group() make use of the new local variables to also simplify some adjacent code.
xen/drivers/passthrough/iommu.c +4 -4
@@ -198,7 +198,7 @@ int iommu_domain_init(struct domain *d,return ret; hd->platform_ops =iommu_get_ops (); - ret = hd->platform_ops->init (d); + ret =iommu_call (hd->platform_ops, init, d);if ( ret ||is_system_domain (d) )return ret;
@@ -233,7 +233,7 @@ void __hwdom_init iommu_hwdom_init(strucregister_keyhandler ('o' , &iommu_dump_page_tables,"dump iommu page tables" ,0 ); - hd->platform_ops->hwdom_init (d); +iommu_vcall (hd->platform_ops, hwdom_init, d); }static void iommu_teardown (struct domain *d)
@@ -576,7 +576,7 @@ int iommu_get_reserved_device_memory(iomif ( !ops->get_reserved_device_memory )return 0 ; -return ops->get_reserved_device_memory (func, ctxt); +return iommu_call (ops, get_reserved_device_memory, func, ctxt); }bool_t iommu_has_feature (struct domain *d,enum iommu_feature feature)
@@ -603,7 +603,7 @@ static void iommu_dump_page_tables(unsigcontinue ; } -dom_iommu (d)->platform_ops->dump_page_tables (d); +iommu_vcall (dom_iommu (d)->platform_ops, dump_page_tables, d); }rcu_read_unlock (&domlist_read_lock);
xen/drivers/passthrough/pci.c +26 -21
123 lines not on this page · raw message
xen/drivers/passthrough/x86/iommu.c +2 -2
@@ -142,7 +142,7 @@ unsigned int iommu_read_apic_from_ire(unint __init iommu_setup_hpet_msi (struct msi_desc *msi) {const struct iommu_ops *ops =iommu_get_ops (); -return ops->setup_hpet_msi ? ops->setup_hpet_msi (msi) : -ENODEV ; +return ops->setup_hpet_msi ?iommu_call (ops, setup_hpet_msi, msi) : -ENODEV ; } void __hwdom_init arch_iommu_check_autotranslated_hwdom(struct domain *d)
@@ -403,7 +403,7 @@ int iommu_free_pgtables(struct domain *d* Pages will be moved to the free list below. So we want to * clear the root page-table to avoid any potential use after-free. */ - hd->platform_ops->clear_root_pgtable (d); +iommu_vcall (hd->platform_ops, clear_root_pgtable, d);while ( (pg =page_list_remove_head (&hd->arch.pgtables.list)) ) {
Re: [PATCH 1/4] IOMMU/x86: switch to alternatives-call patching in further instances
xen/drivers/passthrough/pci.c static int iommu_get_device_group( · line 1465
Quoted 8 lines · Jan Beulich
xen/drivers/passthrough/pci.c +1
-1@@ -1457,24 +1462,24 @@ static int iommu_get_device_group(if ( !is_iommu_enabled (d) || !ops->get_device_group_id )return 0 ; - group_id = ops->get_device_group_id (seg, bus, devfn); + group_id =iommu_call (ops, get_device_group_id, seg, bus, devfn);
So I was going to suggest adjusting this to use more pci_sbdf_t, but the Intel implementation can fail and return -1.
However, given the observations in patch 4, I'd instead recommend dropping all of this.
Everything unrelated to get_device_group() looks fine.
~Andrew
Re: [PATCH 1/4] IOMMU/x86: switch to alternatives-call patching in further instances
Quoted 7 lines · Andrew Cooper
Quoted 6 lines · Jan Beulich
xen/drivers/passthrough/pci.c +0
-0@@ -1457,24 +1462,24 @@ static int iommu_get_device_group(if ( !is_iommu_enabled (d) || !ops->get_device_group_id )return 0 ;
Quoted 5 lines
xen/drivers/passthrough/pci.c static int iommu_get_device_group( · line 1465
Quoted 2 lines
xen/drivers/passthrough/pci.c +1
-1- group_id = ops->get_device_group_id (seg, bus, devfn); + group_id =iommu_call (ops, get_device_group_id, seg, bus, devfn);So I was going to suggest adjusting this to use more
pci_sbdf_t, but the Intel implementation can fail and return -1.
How are the two aspects related? Wouldn't you mean the parameter of the function to become pci_sbdf_t? If so, I'd view this as an orthogonal change. I'll reply to the question of removal on the subthread of patch 4.
Jan
PATCH 2/4 VT-d / x86: re-arrange cache syncing
In reply to Jan BeulichThe actual function should always have lived in core x86 code; move it there, replacing get_cache_line_size() by readily available (except very early during boot; see the code comment) data.
Drop the respective IOMMU hook, (re)introducing a respective boolean instead. Replace a true and an almost open-coding instance of iommu_sync_cache().
---
Placing the function next to flush_area_local() exposes a curious asymmetry between the SFENCE placements: sync_cache() has it after the flush, while flush_area_local() has it before it. I think the latter one is misplaced.
xen/arch/x86/flushtlb.c +52 -0
@@ -11,6 +11,7 @@#include <xen/sched.h> #include <xen/smp.h> #include <xen/softirq.h> +#include <asm/cache.h> #include <asm/flushtlb.h> #include <asm/invpcid.h> #include <asm/nops.h>
@@ -265,6 +266,57 @@ unsigned int flush_area_local(const voidreturn flags; } +void sync_cache (const void *addr,unsigned int size) +{ +/* +* This function may be called before current_cpu_data is established. +* Hence a fallback is needed to prevent the loop below becoming infinite. +*/ +unsigned int clflush_size = current_cpu_data.x86_clflush_size ?:16 ; +const void *end = addr + size; + + addr -= (unsigned long )addr & (clflush_size -1 ); +for ( ; addr < end; addr += clflush_size ) + { +/* +* The arguments to a macro must not include preprocessor directives. Doing so +* results in undefined behavior, so we have to create some defines here in +* order to avoid it. +*/ +#if defined(HAVE_AS_CLWB ) +# define CLWB_ENCODING "clwb %[p]" +#elif defined(HAVE_AS_XSAVEOPT ) +# define CLWB_ENCODING "data16 xsaveopt %[p]"/* clwb */ +#else +# define CLWB_ENCODING ".byte 0x66, 0x0f, 0xae, 0x30"/* clwb (%%rax) */ +#endif + +#define BASE_INPUT (addr) [p] "m" (*(const char *)(addr)) +#if defined(HAVE_AS_CLWB ) || defined(HAVE_AS_XSAVEOPT ) +# define INPUT BASE_INPUT +#else +# define INPUT (addr) "a" (addr), BASE_INPUT(addr) +#endif +/* +* Note regarding the use of NOP_DS_PREFIX: it's faster to do a clflush +* + prefix than a clflush + nop, and hence the prefix is added instead +* of letting the alternative framework fill the gap by appending nops. +*/ + alternative_io_2(".byte " __stringify(NOP_DS_PREFIX) "; clflush %[p]", +"data16 clflush %[p]" ,/* clflushopt */ +X86_FEATURE_CLFLUSHOPT , +CLWB_ENCODING , + X86_FEATURE_CLWB, /* no outputs */, +INPUT (addr)); +#undef INPUT +#undef BASE_INPUT +#undef CLWB_ENCODING + } + +alternative_2 ("" ,"sfence" ,X86_FEATURE_CLFLUSHOPT , +"sfence" ,X86_FEATURE_CLWB ); +} +unsigned int guest_flush_tlb_flags (const struct domain *d) {bool shadow =paging_mode_shadow (d);
xen/drivers/passthrough/vtd/iommu.c +2 -51
71 lines not on this page · raw message
xen/drivers/passthrough/x86/iommu.c +2 -2
@@ -28,6 +28,7 @@const struct iommu_init_ops *__initdata iommu_init_ops;struct iommu_ops __read_mostly iommu_ops; +bool __read_mostly iommu_non_coherent;enum iommu_intremap __read_mostly iommu_intremap = iommu_intremap_full;
@@ -435,8 +436,7 @@ struct page_info *iommu_alloc_pgtable(st p =__map_domain_page (pg);clear_page (p); -if ( hd->platform_ops->sync_cache ) -iommu_vcall (hd->platform_ops, sync_cache, p,PAGE_SIZE ); +iommu_sync_cache (p,PAGE_SIZE );unmap_domain_page (p);
xen/include/asm-x86/cache.h +6 -0
@@ -11,4 +11,10 @@#define __read_mostly __section(".data.read_mostly") +#ifndef __ASSEMBLY__ + +void sync_cache (const void *addr,unsigned int size); + +#endif +#endif
xen/include/asm-x86/iommu.h +8 -6
@@ -19,6 +19,7 @@#include <xen/mem_access.h> #include <xen/spinlock.h> #include <asm/apicdef.h> +#include <asm/cache.h> #include <asm/processor.h> #include <asm/hvm/vmx/vmcs.h>
@@ -134,12 +135,13 @@ extern bool untrusted_msi;int pi_update_irte (const struct pi_desc *pi_desc,const struct pirq *pirq,const uint8_t gvec); -#define iommu_sync_cache (addr, size) ({ \ - const struct iommu_ops *ops = iommu_get_ops(); \ - \ - if ( ops->sync_cache ) \ - iommu_vcall(ops, sync_cache, addr, size); \ -}) +extern bool iommu_non_coherent; + +static inline void iommu_sync_cache (const void *addr,unsigned int size) +{ +if ( iommu_non_coherent ) +sync_cache (addr, size); +}int __must_check iommu_free_pgtables (struct domain *d);struct page_info *__must_check iommu_alloc_pgtable (struct domain *d);
xen/include/xen/iommu.h +0 -1
@@ -268,7 +268,6 @@ struct iommu_ops {int (*setup_hpet_msi)(struct msi_desc *);int (*adjust_irq_affinities)(void ); -void (*sync_cache)(const void *addr,unsigned int size);void (*clear_root_pgtable)(struct domain *d);int (*update_ire_from_msi)(struct msi_desc *msi_desc,struct msi_msg *msg);#endif /* CONFIG_X86 */
xen/drivers/passthrough/vtd/extern.h +0 -1
@@ -76,7 +76,6 @@ int __must_check qinval_device_iotlb_synstruct pci_dev *pdev, u16 did, u16 size, u64 addr); -unsigned int get_cache_line_size (void );void flush_all_cache (void );uint64_t alloc_pgtable_maddr (unsigned long npages,nodeid_t node);
xen/drivers/passthrough/vtd/x86/vtd.c +0 -5
@@ -47,11 +47,6 @@ void unmap_vtd_domain_page(const void *vunmap_domain_page (va); } -unsigned int get_cache_line_size (void ) -{ -return ((cpuid_ebx (1 ) >>8 ) &0xff ) *8 ; -} -void flush_all_cache () {wbinvd ();
Re: [PATCH 2/4] VT-d / x86: re-arrange cache syncing
Quoted 7 lines · Jan Beulich
The actual function should always have lived in core x86 code; move it there, replacing
get_cache_line_size()by readily available (except very early during boot; see the code comment) data.Drop the respective IOMMU hook, (re)introducing a respective boolean instead. Replace a true and an almost open-coding instance of
iommu_sync_cache().
Coherency (or not) is a per-IOMMU property, not a global platform property. iGPU IOMMUs are very different to those the uncore, and there's no reason to presume that IOMMUs in the PCH would have the same properties as those in the uncore.
Given how expensive sync_cache() is, we cannot afford to be using it for coherent IOMMUs in a mixed system.
This wants to be a boolean in arch_iommu.
Quoted 6 lines
Signed-off-by Jan Beulich <[email protected]>---
Placing the function next toflush_area_local()exposes a curious asymmetry between the SFENCE placements:sync_cache()has it after the flush, whileflush_area_local()has it before it. I think the latter one is misplaced.
Wow this is a mess.
First and foremost, AMD state that on pre-CLFLUSHOPT parts, CLFLUSH is unordered with ~anything (including SFENCE), and need bounding with MFENCE on both sides. We definitely aren't doing this correctly right now.
AMD explicitly states that SFENCE drains the store and WC buffers (i.e. make stuff instantaneously globally visible). Intel does not, and merely guarantees ordering.
A leading SFENCE would only make sense if there were WC concerns, but both manuals say that the memory type doesn't matter, so I can't see a justification for it.
What does matter, from the IOMMU's point of view, is that the line has been written back (or evicted on pre-CLWB parts) before the IOTLB invalidation occurs. The invalidation will be a write to a different address, which is why the trailing SFENCE is necessary, as CLFLUSHOPT isn't ordered with respect to unaliasing writes.
On a more minor note, both Intel and AMD say that CLFLUSH* are permitted to target an execute-only code segment, so we need a fix in hvmemul_cache_op()'s use of hvmemul_virtual_to_linear(..., hvm_access_read, ...) which will currently #GP in this case.
Quoted 12 lines
xen/arch/x86/flushtlb.c +1
-0@@ -11,6 +11,7 @@#include <xen/sched.h> #include <xen/smp.h> #include <xen/softirq.h> +#include <asm/cache.h> #include <asm/flushtlb.h> #include <asm/invpcid.h> #include <asm/nops.h>
xen/arch/x86/flushtlb.c unsigned int flush_area_local(const void · line 269
Quoted 4 lines
xen/arch/x86/flushtlb.c +1
-0@@ -265,6 +266,57 @@ unsigned int flush_area_local(const voidreturn flags; } +void sync_cache (const void *addr,unsigned int size)
Can we name this cache_writeback()? sync is very generic, and it really doesn't want confusing cache_flush().
~Andrew
Re: [PATCH 2/4] VT-d / x86: re-arrange cache syncing
Quoted 14 lines · Andrew Cooper
Quoted 7 lines · Jan Beulich
The actual function should always have lived in core x86 code; move it there, replacing
get_cache_line_size()by readily available (except very early during boot; see the code comment) data.Drop the respective IOMMU hook, (re)introducing a respective boolean instead. Replace a true and an almost open-coding instance of
iommu_sync_cache().Coherency (or not) is a per-IOMMU property, not a global platform property. iGPU IOMMUs are very different to those the uncore, and there's no reason to presume that IOMMUs in the PCH would have the same properties as those in the uncore.
Quoted 4 lines
Given how expensive
sync_cache()is, we cannot afford to be using it for coherent IOMMUs in a mixed system.This wants to be a boolean in
arch_iommu.
That's a valid consideration, but may not be as easy as it may seem on the surface. Certainly not something I could promise to find time for soon. And definitely separate from the specific change here.
Quoted 21 lines
Quoted 5 lines
---
Placing the function next toflush_area_local()exposes a curious asymmetry between the SFENCE placements:sync_cache()has it after the flush, whileflush_area_local()has it before it. I think the latter one is misplaced.Wow this is a mess.
First and foremost, AMD state that on pre-CLFLUSHOPT parts, CLFLUSH is unordered with ~anything (including SFENCE), and need bounding with MFENCE on both sides. We definitely aren't doing this correctly right now.
AMD explicitly states that SFENCE drains the store and WC buffers (i.e. make stuff instantaneously globally visible). Intel does not, and merely guarantees ordering.
A leading SFENCE would only make sense if there were WC concerns, but both manuals say that the memory type doesn't matter, so I can't see a justification for it.
Quoted 5 lines
What does matter, from the IOMMU's point of view, is that the line has been written back (or evicted on pre-CLWB parts) before the IOTLB invalidation occurs. The invalidation will be a write to a different address, which is why the trailing SFENCE is necessary, as CLFLUSHOPT isn't ordered with respect to unaliasing writes.
IOW for the purposes of this change all is correct, and everything else will require taking care of separately.
Quoted 4 lines
On a more minor note, both Intel and AMD say that CLFLUSH* are permitted to target an execute-only code segment, so we need a fix in hvmemul_cache_op()'s use of
hvmemul_virtual_to_linear(..., hvm_access_read, ...)which will currently #GP in this case.
Hmm, this specific case would seem to require to simply use hvm_access_none (like hvmemul_tlb_op() already does), except for CLWB.
But then hvm_vcpu_virtual_to_linear() also doesn't look to handle hvm_access_insn_fetch correctly for data segments. Changing of which would in turn require to first audit all use sites, to make sure we don't break anything.
I'll see about doing both.
Quoted 14 lines
Quoted 14 lines
xen/arch/x86/flushtlb.c +1
-0@@ -11,6 +11,7 @@#include <xen/sched.h> #include <xen/smp.h> #include <xen/softirq.h> +#include <asm/cache.h> #include <asm/flushtlb.h> #include <asm/invpcid.h> #include <asm/nops.h> @@ -265,6 +266,57 @@ unsigned int flush_area_local(const voidreturn flags; }
Quoted 4 lines
xen/arch/x86/flushtlb.c unsigned int flush_area_local(const void · line 269
Quoted 1 line
xen/arch/x86/flushtlb.c +1
-0+void sync_cache (const void *addr,unsigned int size)Can we name this cache_writeback()? sync is very generic, and it really doesn't want confusing
cache_flush().
Oh, sure, can do. As long as you don't insist on also changing iommu_sync_cache(): While purely mechanical, this would bloat the patch by quite a bit.
Bottom line: This last item is the only change to the actual patch; everything else will require further work yielding separate patches.
Jan
RE: [PATCH 2/4] VT-d / x86: re-arrange cache syncing
Quoted 19 lines
From: Jan Beulich <[email protected]>
Sent: Thursday, December 2, 2021 5:19 PMQuoted 5 lines · Andrew Cooper
Quoted 4 lines · Jan Beulich
The actual function should always have lived in core x86 code; move it there, replacing
get_cache_line_size()by readily available (except very early during boot; see the code comment) data.Quoted 7 lines
Quoted 3 lines
Drop the respective IOMMU hook, (re)introducing a respective boolean instead. Replace a true and an almost open-coding instance of
iommu_sync_cache().Coherency (or not) is a per-IOMMU property, not a global platform property. iGPU IOMMUs are very different to those the uncore, and there's no reason to presume that IOMMUs in the PCH would have the
same
Quoted 2 lines
properties as those in the uncore.
Quoted 8 lines
Quoted 4 lines
Given how expensive
sync_cache()is, we cannot afford to be using it for coherent IOMMUs in a mixed system.This wants to be a boolean in
arch_iommu.That's a valid consideration, but may not be as easy as it may seem on the surface. Certainly not something I could promise to find time for soon. And definitely separate from the specific change here.
I'm fine with this patch if you prefer to a staging approach to improve it. By any means this patch doesn't make things worse.
Quoted 22 lines
Quoted 22 lines
Quoted 6 lines
---
Placing the function next toflush_area_local()exposes a curious asymmetry between the SFENCE placements:sync_cache()has it after the flush, whileflush_area_local()has it before it. I think the latter one is misplaced.Wow this is a mess.
First and foremost, AMD state that on pre-CLFLUSHOPT parts, CLFLUSH is unordered with ~anything (including SFENCE), and need bounding with MFENCE on both sides. We definitely aren't doing this correctly right now.
AMD explicitly states that SFENCE drains the store and WC buffers (i.e. make stuff instantaneously globally visible). Intel does not, and merely guarantees ordering.
A leading SFENCE would only make sense if there were WC concerns, but both manuals say that the memory type doesn't matter, so I can't see a justification for it.
Quoted 9 lines
Quoted 5 lines
What does matter, from the IOMMU's point of view, is that the line has been written back (or evicted on pre-CLWB parts) before the IOTLB invalidation occurs. The invalidation will be a write to a different address, which is why the trailing SFENCE is necessary, as CLFLUSHOPT isn't ordered with respect to unaliasing writes.
IOW for the purposes of this change all is correct, and everything else will require taking care of separately.
Same for this part. btw Linux does mfence both before and after clflush.
Thanks
Kevin
PATCH 3/4 VT-d: replace flush_all_cache()
In reply to Jan BeulichLet's use infrastructure we have available instead of an open-coded wbinvd() invocation.
xen/drivers/passthrough/vtd/extern.h +0 -2
@@ -76,8 +76,6 @@ int __must_check qinval_device_iotlb_synstruct pci_dev *pdev, u16 did, u16 size, u64 addr); -void flush_all_cache (void ); -uint64_t alloc_pgtable_maddr (unsigned long npages,nodeid_t node);void free_pgtable_maddr (u64 maddr);void *map_vtd_domain_page (u64 maddr);
xen/drivers/passthrough/vtd/iommu.c +2 -1
@@ -591,7 +591,8 @@ static int __must_check iommu_flush_all(bool_t flush_dev_iotlb;int rc =0 ; -flush_all_cache (); +flush_local (FLUSH_CACHE ); +for_each_drhd_unit ( drhd ) {int context_rc, iotlb_rc;
xen/drivers/passthrough/vtd/x86/vtd.c +0 -5
@@ -46,8 +46,3 @@ void unmap_vtd_domain_page(const void *v {unmap_domain_page (va); } - -void flush_all_cache () -{ -wbinvd (); -}
Re: [PATCH 3/4] VT-d: replace flush_all_cache()
xen/drivers/passthrough/vtd/iommu.c static int __must_check iommu_flush_all( · line 594
Quoted 8 lines · Jan Beulich
xen/drivers/passthrough/vtd/iommu.c +1
-1@@ -591,7 +591,8 @@ static int __must_check iommu_flush_all(bool_t flush_dev_iotlb;int rc =0 ; -flush_all_cache (); +flush_local (FLUSH_CACHE );
While I agree that the conversion is an improvement, the logic still looks totally bogus.
I can believe that it might have been a stopgap to fix problems before we identified the need for sync_cache() for non-coherent IOMMUs, but there's no need I can spot for any WBINVDs on any of these paths.
I'm fairly sure this should just be dropped, and Xen will get faster as a result.
~Andrew
Re: [PATCH 3/4] VT-d: replace flush_all_cache()
Quoted 13 lines · Andrew Cooper
xen/drivers/passthrough/vtd/iommu.c static int __must_check iommu_flush_all( · line 594
Quoted 8 lines · Jan Beulich
xen/drivers/passthrough/vtd/iommu.c +1
-1@@ -591,7 +591,8 @@ static int __must_check iommu_flush_all(bool_t flush_dev_iotlb;int rc =0 ; -flush_all_cache (); +flush_local (FLUSH_CACHE );While I agree that the conversion is an improvement, the logic still looks totally bogus.
Quoted 6 lines
I can believe that it might have been a stopgap to fix problems before we identified the need for
sync_cache()for non-coherent IOMMUs, but there's no need I can spot for any WBINVDs on any of these paths.I'm fairly sure this should just be dropped, and Xen will get faster as a result.
Kevin, thoughts? I have to admit I'm hesitant to remove such code, when there's no clear indication why it's there. I'm also not sure how much of a win the dropping would be, considering the places where this function gets called from.
Jan
RE: [PATCH 3/4] VT-d: replace flush_all_cache()
Quoted 21 lines
From: Jan Beulich <[email protected]>
Sent: Thursday, December 2, 2021 4:48 PMQuoted 17 lines · Andrew Cooper
xen/drivers/passthrough/vtd/iommu.c static int __must_check iommu_flush_all( · line 594
Quoted 8 lines · Jan Beulich
xen/drivers/passthrough/vtd/iommu.c +1
-1@@ -591,7 +591,8 @@ static int __must_check iommu_flush_all(bool_t flush_dev_iotlb;int rc =0 ; -flush_all_cache (); +flush_local (FLUSH_CACHE );While I agree that the conversion is an improvement, the logic still looks totally bogus.
I can believe that it might have been a stopgap to fix problems before we identified the need for
sync_cache()for non-coherent IOMMUs, but there's no need I can spot for any WBINVDs on any of these paths.
Quoted 8 lines
Quoted 2 lines
I'm fairly sure this should just be dropped, and Xen will get faster as a result.
Kevin, thoughts? I have to admit I'm hesitant to remove such code, when there's no clear indication why it's there. I'm also not sure how much of a win the dropping would be, considering the places where this function gets called from.
me too. Could Andrew elaborate further on "fairly sure" part?
Thanks
Kevin
PATCH 4/4 libxc: correct bounce direction in xc_get_device_group()
In reply to Jan BeulichThe array of IDs is an output.
---
Clearly the function, including its Python wrapper, cannot have been used by anything for many years. I wonder whether that isn't good enough a reason to sanitize the layout of the array elements: Right now they have BDF in bits 8...23, when conventionally this would be bits 0...15.
tools/libs/ctrl/xc_domain.c +2 -1
@@ -1546,7 +1546,8 @@ int xc_get_device_group( {int rc;DECLARE_DOMCTL ; -DECLARE_HYPERCALL_BOUNCE (sdev_array, max_sdevs *sizeof (*sdev_array),XC_HYPERCALL_BUFFER_BOUNCE_IN ); +DECLARE_HYPERCALL_BOUNCE (sdev_array, max_sdevs *sizeof (*sdev_array), +XC_HYPERCALL_BUFFER_BOUNCE_OUT );if (xc_hypercall_bounce_pre (xch, sdev_array) ) {
Re: [PATCH 4/4] libxc: correct bounce direction in xc_get_device_group()
Quoted 4 lines · Jan Beulich
The array of IDs is an output.
Fixes 79647c5bc9c6 ("libxc: convert domctl interfaces over to hypercall buffers")Signed-off-by Jan Beulich <[email protected]>
Juergen
Re: [PATCH 4/4] libxc: correct bounce direction in xc_get_device_group()
In reply to Jan BeulichQuoted 9 lines · Jan Beulich
The array of IDs is an output.
Fixes 79647c5bc9c6 ("libxc: convert domctl interfaces over to hypercall buffers")Signed-off-by Jan Beulich <[email protected]>---
Clearly the function, including its Python wrapper, cannot have been used by anything for many years. I wonder whether that isn't good enough a reason to sanitize the layout of the array elements: Right now they have BDF in bits 8...23, when conventionally this would be bits 0...15.
There is a lot of WTF with this hypercall. It's obviously an attempt to do the thing that Linux calls IOMMU groups now, except that the correct way to do this would be for the group ID to be the unit of assignment/deassignment. (We need to do this anyway for other reasons.)
The last user was deleted with Xend (2013), which suggests that it was broken for 3 years due to the incorrect bounce direction (2010).
Furthermore, it will arbitrarily fail if targetting domains without an IOMMU configured, but everything else seems to be invariant of the passed domain. This should clearly be sysctl, not a domctl.
I suggest ripping all of this infrastructure out. It's clearly unused (and broken in Xen too - see patch 1), and not something which should be used in this form in the future.
~Andrew
Re: [PATCH 4/4] libxc: correct bounce direction in xc_get_device_group()
Quoted 19 lines · Andrew Cooper
Quoted 9 lines · Jan Beulich
The array of IDs is an output.
Fixes 79647c5bc9c6 ("libxc: convert domctl interfaces over to hypercall buffers")Signed-off-by Jan Beulich <[email protected]>---
Clearly the function, including its Python wrapper, cannot have been used by anything for many years. I wonder whether that isn't good enough a reason to sanitize the layout of the array elements: Right now they have BDF in bits 8...23, when conventionally this would be bits 0...15.There is a lot of WTF with this hypercall. It's obviously an attempt to do the thing that Linux calls IOMMU groups now, except that the correct way to do this would be for the group ID to be the unit of assignment/deassignment. (We need to do this anyway for other reasons.)
The last user was deleted with Xend (2013), which suggests that it was broken for 3 years due to the incorrect bounce direction (2010).
Quoted 7 lines
Furthermore, it will arbitrarily fail if targetting domains without an IOMMU configured, but everything else seems to be invariant of the passed domain. This should clearly be sysctl, not a domctl.
I suggest ripping all of this infrastructure out. It's clearly unused (and broken in Xen too - see patch 1),
I've not seen you point out any breakage in reply to patch 1, unless you mean VT-d's returning of -1 (which you didn't point out as broken, but which I can see would lead to misbehavior).
Quoted 1 line
and not something which should be used in this form in the future.
I didn't think the concept here was wrong. What's missing is the tool stack actually making use of this plus a way to do assignment in groups. Iirc the latter was something Paul had started work on before leaving Citrix? (That's leaving aside the bug you mention plus potential further ones.)
Paul, Ian, Wei - what are your thoughts towards Andrew's proposal?
Jan