VMX: Properly handle pi descriptor and per-cpu blocking list
v7 cover VMX: Properly handle pi descriptor and per-cpu blocking list
The current VT-d PI related code may operate incorrectly in the following scenarios:
1. When the last assigned device is dettached from the domain, all the PI related hooks are removed then, however, the vCPU can be blocked, switched to another pCPU, etc, all without the aware of PI. After the next time we attach another device to the domain, which makes the PI realted hooks avaliable again, the status of the pi descriptor is not true. Beside that, the blocking vcpu may still remain in the per-cpu blocking in this case. Patch [1/6] and [2/6] handle this.
2. When IRTE is in posted mode, we don't need to set the irq affinity for it, since the destination of these interrupts is vCPU and the vCPU affinity is set during vCPU scheduling. Patch [4/6] handles this.
4. [5/6] is a cleanup patch
5. When a pCPU is unplugged, and there might be vCPUs on its list. Since the pCPU is offline, those vCPUs might not be woken up again. [6/6] addresses it.
Feng Wu (6):
VMX: Permanently assign PI hook vmx_pi_switch_to()
VMX: Properly handle pi when all the assigned devices are removed
VMX: Make sure PI is in proper state before install the hooks
VT-d: No need to set irq affinity for posted format IRTE
VT-d: Some cleanups
VMX: Fixup PI descriptor when cpu is offline
xen/arch/x86/hvm/vmx/vmcs.c | 14 ++-- xen/arch/x86/hvm/vmx/vmx.c | 132 +++++++++++++++++++++++++++++++-- xen/drivers/passthrough/pci.c | 14 ++++ xen/drivers/passthrough/vtd/intremap.c | 64 ++++++++-------- xen/include/asm-x86/hvm/vmx/vmx.h | 3 + 5 files changed, 184 insertions(+), 43 deletions(-)
Signature · 7 lines
2.1.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH v7 1/6 VMX: Permanently assign PI hook vmx_pi_switch_to()
PI hook vmx_pi_switch_to() is needed even when any previously assigned device is detached from the domain. Since 'SN' bit is also used to control the CPU side PI and we change the state of SN bit in these two functions, then evaluate this bit in vmx_deliver_posted_intr() when trying to deliver the interrupt in posted way via software. The problem is if we deassign the hooks while the vCPU is runnable in the runqueue with 'SN' set, all the furture notificaton event will be suppressed. This patch makes the hook permanently assigned.
---
v7:
- comments changes.
v6:
- Adjust the comments and wording.
v5:
- Zap "pi_switch_from" hook
v4:
- Don't zap vmx_pi_switch_from() and vmx_pi_switch_to() when any previously assigned device is detached from the domain.
- Comments changes.
xen/arch/x86/hvm/vmx/vmx.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
xen/arch/x86/hvm/vmx/vmx.c +6 -1
@@ -222,8 +222,13 @@ void vmx_pi_hooks_deassign(struct domain *d) d->arch.hvm_domain.vmx.vcpu_block =NULL ; d->arch.hvm_domain.vmx.pi_switch_from =NULL ; - d->arch.hvm_domain.vmx.pi_switch_to =NULL ; d->arch.hvm_domain.vmx.pi_do_resume =NULL ; + +/* +* In fact, we could remove 'vmx_pi_switch_to' inside itself if no new device +* is in the process of getting assigned and "from" hook is NULL. However, +* it is not straightforward to find a clear solution, so just leave it here. +*/ }static int vmx_domain_initialise (struct domain *d)
Signature · 7 lines
2.1.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH v7 1/6] VMX: Permanently assign PI hook vmx_pi_switch_to()
Quoted 34 lines · Feng Wu
PI hook
vmx_pi_switch_to()is needed even when any previously assigned device is detached from the domain. Since 'SN' bit is also used to control the CPU side PI and we change the state of SN bit in these two functions, then evaluate this bit invmx_deliver_posted_intr()when trying to deliver the interrupt in posted way via software. The problem is if we deassign the hooks while the vCPU is runnable in the runqueue with 'SN' set, all the furture notificaton event will be suppressed. This patch makes the hook permanently assigned.Signed-off-by Feng Wu <[email protected]>---
v7:
- comments changes.v6:
- Adjust the comments and wording.v5:
- Zap "pi_switch_from" hookv4:
- Don't zapvmx_pi_switch_from()andvmx_pi_switch_to()when any previously assigned device is detached from the domain.
- Comments changes.xen/arch/x86/hvm/vmx/vmx.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)xen/arch/x86/hvm/vmx/vmx.c +0
-0
xen/arch/x86/hvm/vmx/vmx.c void vmx_pi_hooks_deassign(struct domain *d) · line 228
Quoted 8 lines
xen/arch/x86/hvm/vmx/vmx.c +3
-1@@ -222,8 +222,13 @@ void vmx_pi_hooks_deassign(struct domain *d) d->arch.hvm_domain.vmx.vcpu_block =NULL ; d->arch.hvm_domain.vmx.pi_switch_from =NULL ; - d->arch.hvm_domain.vmx.pi_switch_to =NULL ; d->arch.hvm_domain.vmx.pi_do_resume =NULL ; + +/* +* In fact, we could remove 'vmx_pi_switch_to' inside itself if no new device
I am having a hard time parsing that. What is the 'inside itself'?
Otherwise,
Quoted 14 lines
xen/arch/x86/hvm/vmx/vmx.c +3
-0+* is in the process of getting assigned and "from" hook is NULL. However, +* it is not straightforward to find a clear solution, so just leave it here. +*/ }static int vmx_domain_initialise (struct domain *d)Signature · 7 lines
2.1.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v7 1/6] VMX: Permanently assign PI hook vmx_pi_switch_to()
Quoted 15 lines
xen/arch/x86/hvm/vmx/vmx.c void vmx_pi_hooks_deassign(struct domain *d) · line 228
Quoted 13 lines
xen/arch/x86/hvm/vmx/vmx.c +3
-1@@ -222,8 +222,13 @@ void vmx_pi_hooks_deassign(struct domain *d) d->arch.hvm_domain.vmx.vcpu_block =NULL ; d->arch.hvm_domain.vmx.pi_switch_from =NULL ; - d->arch.hvm_domain.vmx.pi_switch_to =NULL ; d->arch.hvm_domain.vmx.pi_do_resume =NULL ; + +/* +* In fact, we could remove 'vmx_pi_switch_to' inside itself if no new device
Quoted 1 line
I am having a hard time parsing that. What is the 'inside itself'?
Thanks for your review. It means we could set ' d->arch.hvm_domain.vmx.pi_switch_to' to NULL in vmx_pi_switch_to(). It would be good if you have any better description! :)
Thanks,
Feng
Quoted 17 lines
Otherwise,
Reviewed-by Konrad Rzeszutek Wilk <[email protected]>Quoted 14 lines
xen/arch/x86/hvm/vmx/vmx.c +3
-1+* is in the process of getting assigned and "from" hook is NULL. However, +* it is not straightforward to find a clear solution, so just leave it here. +*/ }static int vmx_domain_initialise (struct domain *d) --2.1.0
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v7 1/6] VMX: Permanently assign PI hook vmx_pi_switch_to()
Quoted 15 lines · Feng
Quoted 1 line
Review
Quoted 1 line
(quoted diff) +0
-0
b/xen/arch/x86/hvm/vmx/vmx.cQuoted 5 lines
Quoted 5 lines
index 3d330b6..10546af 100644
xen/arch/x86/hvm/vmx/vmx.c +0
-0@@ -222,8 +222,13 @@ void vmx_pi_hooks_deassign(struct domain *d)Quoted 7 lines
xen/arch/x86/hvm/vmx/vmx.c void vmx_pi_hooks_deassign(struct domain *d)
Quoted 7 lines
xen/arch/x86/hvm/vmx/vmx.c +3
-1d->arch.hvm_domain.vmx.vcpu_block =NULL ; d->arch.hvm_domain.vmx.pi_switch_from =NULL ; - d->arch.hvm_domain.vmx.pi_switch_to =NULL ; d->arch.hvm_domain.vmx.pi_do_resume =NULL ; + +/* +* In fact, we could remove 'vmx_pi_switch_to' inside itself if no new
Quoted 8 lines
Quoted 3 lines
device
I am having a hard time parsing that. What is the 'inside itself'?
Thanks for your review. It means we could set '
d->arch.hvm_domain.vmx.pi_switch_to'
to NULL invmx_pi_switch_to(). It would be good if you have any better description! :)
Your above description is perfect:
"We could set d-arch.hvm_domain.vmx.pi_switch_to to NULL in vmx_pi_switch_to() if no new device ..."
Thanks!
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH v7 2/6 VMX: Properly handle pi when all the assigned devices are removed
In reply to Feng WuThis patch handles some corner cases when the last assigned device is removed from the domain. In this case we should carefully handle pi descriptor and the per-cpu blocking list, to make sure:
- all the PI descriptor are in the right state when next time a devices is assigned to the domain again.
- No remaining vcpus of the domain in the per-cpu blocking list.
Here we call vmx_pi_unblock_vcpu() to remove the vCPU from the blocking list if it is on the list. However, this could happen when vmx_vcpu_block() is being called, hence we might incorrectly add the vCPU to the blocking list while the last devcie is detached from the domain. Consider that the situation can only occur when detaching the last device from the domain and it is not a frequent operation, so we use domain_pause before that, which is considered as an clean and maintainable solution for the situation.
---
v7:
- Prevent the domain from pausing itself.
v6:
- Comments changes
- Rename vmx_pi_list_remove() to vmx_pi_unblock_vcpu()
v5:
- Remove a no-op wrapper
v4:
- Rename some functions:
vmx_pi_remove_vcpu_from_blocking_list() -> vmx_pi_list_remove() vmx_pi_blocking_cleanup() -> vmx_pi_list_cleanup()
- Remove the check in vmx_pi_list_cleanup()
- Comments adjustment
xen/arch/x86/hvm/vmx/vmx.c | 28 ++++++++++++++++++++++++---- xen/drivers/passthrough/pci.c | 14 ++++++++++++++ 2 files changed, 38 insertions(+), 4 deletions(-)
xen/arch/x86/hvm/vmx/vmx.c +24 -4
@@ -158,14 +158,12 @@ static void vmx_pi_switch_to(struct vcpu *v)pi_clear_sn (pi_desc); } -static void vmx_pi_do_resume (struct vcpu *v) +static void vmx_pi_unblock_vcpu (struct vcpu *v) {unsigned long flags;spinlock_t *pi_blocking_list_lock;struct pi_desc *pi_desc = &v->arch.hvm_vmx.pi_desc; -ASSERT (!test_bit (_VPF_blocked, &v->pause_flags)); -/* * Set 'NV' field back to posted_intr_vector, so the * Posted-Interrupts can be delivered to the vCPU when
@@ -173,12 +171,12 @@ static void vmx_pi_do_resume(struct vcpu *v)*/ write_atomic (&pi_desc->nv, posted_intr_vector); -/* The vCPU is not on any blocking list. */ pi_blocking_list_lock = v->arch.hvm_vmx.pi_blocking.lock;/* Prevent the compiler from eliminating the local variable.*/ smp_rmb (); +/* The vCPU is not on any blocking list. */ if ( pi_blocking_list_lock ==NULL )return ;
@@ -198,6 +196,13 @@ static void vmx_pi_do_resume(struct vcpu *v)spin_unlock_irqrestore (pi_blocking_list_lock, flags); } +static void vmx_pi_do_resume (struct vcpu *v) +{ +ASSERT (!test_bit (_VPF_blocked, &v->pause_flags)); + +vmx_pi_unblock_vcpu (v); +} +/* This function is called when pcidevs_lock is held */ void vmx_pi_hooks_assign (struct domain *d) {
@@ -215,11 +220,21 @@ void vmx_pi_hooks_assign(struct domain *d)/* This function is called when pcidevs_lock is held */ void vmx_pi_hooks_deassign (struct domain *d) { +struct vcpu *v; +if ( !iommu_intpost || !has_hvm_container_domain (d) )return ;ASSERT (d->arch.hvm_domain.vmx.vcpu_block); +/* +* Pausing the domain can make sure the vCPU is not +* running and hence not calling the hooks simultaneously +* when deassigning the PI hooks and removing the vCPU +* from the blocking list. +*/ +domain_pause (d); + d->arch.hvm_domain.vmx.vcpu_block =NULL ; d->arch.hvm_domain.vmx.pi_switch_from =NULL ; d->arch.hvm_domain.vmx.pi_do_resume =NULL ;
@@ -229,6 +244,11 @@ void vmx_pi_hooks_deassign(struct domain *d)* is in the process of getting assigned and "from" hook is NULL. However, * it is not straightforward to find a clear solution, so just leave it here. */ + + for_each_vcpu ( d, v ) +vmx_pi_unblock_vcpu (v); + +domain_unpause (d); }static int vmx_domain_initialise (struct domain *d)
xen/drivers/passthrough/pci.c +14 -0
@@ -1602,6 +1602,13 @@ int iommu_do_pci_domctl(break ;case XEN_DOMCTL_assign_device: +/* no domain_pause() */ +if ( d == current->domain ) + { + ret = -EINVAL ; +break ; + } + ret = -ENODEV ;if ( domctl->u.assign_device.dev !=XEN_DOMCTL_DEV_PCI )break ;
@@ -1642,6 +1649,13 @@ int iommu_do_pci_domctl(break ;case XEN_DOMCTL_deassign_device: +/* no domain_pause() */ +if ( d == current->domain ) + { + ret = -EINVAL ; +break ; + } + ret = -ENODEV ;if ( domctl->u.assign_device.dev !=XEN_DOMCTL_DEV_PCI )break ;
Signature · 7 lines
2.1.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH v7 2/6] VMX: Properly handle pi when all the assigned devices are removed
Quoted 18 lines
Quoted 1 line
Quoted 1 line · On 07.11.16 at 09:07, <[email protected]> wrote:
This patch handles some corner cases when the last assigned device is removed from the domain. In this case we should carefully handle pi descriptor and the per-cpu blocking list, to make sure:
- all the PI descriptor are in the right state when next time a devices is assigned to the domain again.
- No remaining vcpus of the domain in the per-cpu blocking list.Here we call
vmx_pi_unblock_vcpu()to remove the vCPU from the blocking list if it is on the list. However, this could happen whenvmx_vcpu_block()is being called, hence we might incorrectly add the vCPU to the blocking list while the last devcie is detached from the domain. Consider that the situation
can only occur when detaching the last device from the domain and it is not a frequent operation, so we usedomain_pausebefore that, which is considered
as an clean and maintainable solution for the situation.
Quoted 1 line
Signed-off-by Feng Wu <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH v7 3/6 VMX: Make sure PI is in proper state before install the hooks
In reply to Feng WuWe may hit the last ASSERT() in vmx_vcpu_block in the current code, since vmx_vcpu_block() may get called before vmx_pi_switch_to() has been installed or executed. Here We use cmpxchg to update the NDST field, this can make sure we only update the NDST when vmx_pi_switch_to() has not been called. So the NDST is in a proper state in vmx_vcpu_block().
---
v6:
- Comments changes
- Define macro 'APIC_INVALID_DEST' for '0xffffffff'
v5:
- Use 0xffffffff as the invalid value for NDST field.
v4:
- This patch is previously called "Pause/Unpause the domain before/after assigning PI hooks"
- Remove the pause/unpause method
- Use cmpxchg to update NDST
xen/arch/x86/hvm/vmx/vmcs.c | 13 +++++-------- xen/arch/x86/hvm/vmx/vmx.c | 27 ++++++++++++++++++++++++++- xen/include/asm-x86/hvm/vmx/vmx.h | 2 ++ 3 files changed, 33 insertions(+), 9 deletions(-)
xen/arch/x86/hvm/vmx/vmcs.c +5 -8
@@ -956,16 +956,13 @@ void virtual_vmcs_vmwrite(const struct vcpu *v, u32 vmcs_encoding, u64 val)*/ static void pi_desc_init (struct vcpu *v) { -uint32_t dest; - v->arch.hvm_vmx.pi_desc.nv = posted_intr_vector; - dest =cpu_physical_id (v->processor); - -if ( x2apic_enabled ) - v->arch.hvm_vmx.pi_desc.ndst = dest; -else - v->arch.hvm_vmx.pi_desc.ndst =MASK_INSR (dest, PI_xAPIC_NDST_MASK); +/* +* Mark NDST as invalid, then we can use this invalid value as a +* marker to whether update NDST or not in vmx_pi_hooks_assign(). +*/ + v->arch.hvm_vmx.pi_desc.ndst =APIC_INVALID_DEST ; }static int construct_vmcs (struct vcpu *v)
xen/arch/x86/hvm/vmx/vmx.c +26 -1
@@ -206,14 +206,39 @@ static void vmx_pi_do_resume(struct vcpu *v)/* This function is called when pcidevs_lock is held */ void vmx_pi_hooks_assign (struct domain *d) { +struct vcpu *v; +if ( !iommu_intpost || !has_hvm_container_domain (d) )return ;ASSERT (!d->arch.hvm_domain.vmx.vcpu_block); - d->arch.hvm_domain.vmx.vcpu_block = vmx_vcpu_block; +/* +* We carefully handle the timing here: +* - Install the context switch first +* - Then set the NDST field +* - Install the block and resume hooks in the end +* +* This can make sure the PI (especially the NDST feild) is +* in proper state when we call vmx_vcpu_block(). +*/ d->arch.hvm_domain.vmx.pi_switch_from = vmx_pi_switch_from; d->arch.hvm_domain.vmx.pi_switch_to = vmx_pi_switch_to; + + for_each_vcpu ( d, v ) + { +unsigned int dest =cpu_physical_id (v->processor); +struct pi_desc *pi_desc = &v->arch.hvm_vmx.pi_desc; + +/* +* We don't need to update NDST if vmx_pi_switch_to() +* has already got called. +*/ + (void )cmpxchg (&pi_desc->ndst,APIC_INVALID_DEST , + x2apic_enabled ? dest :MASK_INSR (dest, PI_xAPIC_NDST_MASK)); + } + + d->arch.hvm_domain.vmx.vcpu_block = vmx_vcpu_block; d->arch.hvm_domain.vmx.pi_do_resume = vmx_pi_do_resume; }
xen/include/asm-x86/hvm/vmx/vmx.h +2 -0
@@ -573,6 +573,8 @@ void vmx_pi_per_cpu_init(unsigned int cpu);void vmx_pi_hooks_assign (struct domain *d);void vmx_pi_hooks_deassign (struct domain *d); +#define APIC_INVALID_DEST 0xffffffff +/* EPT violation qualifications definitions */ #define _EPT_READ_VIOLATION 0#define EPT_READ_VIOLATION (1UL<<_EPT_READ_VIOLATION)
Signature · 7 lines
2.1.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH v7 4/6 VT-d: No need to set irq affinity for posted format IRTE
In reply to Feng WuWe don't set the affinity for posted format IRTE, since the destination of these interrupts is vCPU and the vCPU affinity is set during vCPU scheduling.
---
v7:
- Compare all the field in IRTE to justify whether we can suppress the update
v6:
- Make pi_can_suppress_irte_update() a check-only function
- Introduce another function pi_get_new_irte() to update the 'new_ire' if needed
v5:
- Only suppress affinity related IRTE updates for PI
v4:
- Keep the construction of new_ire and only modify the hardware IRTE when it is not in posted mode.
xen/drivers/passthrough/vtd/intremap.c | 54 +++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 24 deletions(-)
xen/drivers/passthrough/vtd/intremap.c +30 -24
@@ -597,31 +597,34 @@ static int msi_msg_to_remap_entry(memcpy (&new_ire, iremap_entry,sizeof (struct iremap_entry )); -/* Set interrupt remapping table entry */ - new_ire.remap.fpd =0 ; - new_ire.remap.dm = (msg->address_lo >>MSI_ADDR_DESTMODE_SHIFT ) &0x1 ; - new_ire.remap.tm = (msg->data >>MSI_DATA_TRIGGER_SHIFT ) &0x1 ; - new_ire.remap.dlm = (msg->data >>MSI_DATA_DELIVERY_MODE_SHIFT ) &0x1 ; -/* Hardware require RH = 1 for LPR delivery mode */ - new_ire.remap.rh = (new_ire.remap.dlm == dest_LowestPrio); - new_ire.remap.avail =0 ; - new_ire.remap.res_1 =0 ; - new_ire.remap.vector = (msg->data >>MSI_DATA_VECTOR_SHIFT ) & -MSI_DATA_VECTOR_MASK ; - new_ire.remap.res_2 =0 ; -if ( x2apic_enabled ) - new_ire.remap.dst = msg->dest32; -else - new_ire.remap.dst = ((msg->address_lo >>MSI_ADDR_DEST_ID_SHIFT ) - &0xff ) <<8 ; -if ( pdev )set_msi_source_id (pdev, &new_ire);else set_hpet_source_id (msi_desc->hpet_id, &new_ire); - new_ire.remap.res_3 =0 ; - new_ire.remap.res_4 =0 ; - new_ire.remap.p =1 ;/* finally, set present bit */ + +if ( !new_ire.remap.p || !new_ire.remap.im ) + { +/* Set interrupt remapping table entry */ + new_ire.remap.fpd =0 ; + new_ire.remap.dm = (msg->address_lo >>MSI_ADDR_DESTMODE_SHIFT ) &0x1 ; + new_ire.remap.tm = (msg->data >>MSI_DATA_TRIGGER_SHIFT ) &0x1 ; + new_ire.remap.dlm = (msg->data >>MSI_DATA_DELIVERY_MODE_SHIFT ) &0x1 ; +/* Hardware require RH = 1 for LPR delivery mode */ + new_ire.remap.rh = (new_ire.remap.dlm == dest_LowestPrio); + new_ire.remap.avail =0 ; + new_ire.remap.res_1 =0 ; + new_ire.remap.vector = (msg->data >>MSI_DATA_VECTOR_SHIFT ) & +MSI_DATA_VECTOR_MASK ; + new_ire.remap.res_2 =0 ; +if ( x2apic_enabled ) + new_ire.remap.dst = msg->dest32; +else + new_ire.remap.dst = ((msg->address_lo >>MSI_ADDR_DEST_ID_SHIFT ) + &0xff ) <<8 ; + new_ire.remap.res_3 =0 ; + new_ire.remap.res_4 =0 ; + new_ire.remap.p =1 ;/* finally, set present bit */ + }/* now construct new MSI/MSI-X rte entry */ remap_rte = (struct msi_msg_remap_entry *)msg;
@@ -637,9 +640,12 @@ static int msi_msg_to_remap_entry( remap_rte->address_hi =0 ; remap_rte->data = index - i; -memcpy (iremap_entry, &new_ire,sizeof (struct iremap_entry )); -iommu_flush_cache_entry (iremap_entry,sizeof (struct iremap_entry )); -iommu_flush_iec_index (iommu,0 , index); +if ( iremap_entry->val != new_ire.val ) + { +memcpy (iremap_entry, &new_ire,sizeof (struct iremap_entry )); +iommu_flush_cache_entry (iremap_entry,sizeof (struct iremap_entry )); +iommu_flush_iec_index (iommu,0 , index); + }unmap_vtd_domain_page (iremap_entries);spin_unlock_irqrestore (&ir_ctrl->iremap_lock, flags);
Signature · 7 lines
2.1.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH v7 5/6 VT-d: Some cleanups
In reply to Feng WuUse type-safe structure assignment instead of memcpy() Use sizeof(*iremap_entry).
---
v7:
- Remove a useless cleanup
v6:
- More descripion about the patch
xen/drivers/passthrough/vtd/intremap.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
xen/drivers/passthrough/vtd/intremap.c +7 -7
@@ -183,8 +183,8 @@ static void free_remap_entry(struct iommu *iommu, int index)GET_IREMAP_ENTRY (ir_ctrl->iremap_maddr, index, iremap_entries, iremap_entry); -memset (iremap_entry,0 ,sizeof (struct iremap_entry )); -iommu_flush_cache_entry (iremap_entry,sizeof (struct iremap_entry )); +memset (iremap_entry,0 ,sizeof (*iremap_entry)); +iommu_flush_cache_entry (iremap_entry,sizeof (*iremap_entry));iommu_flush_iec_index (iommu,0 , index);unmap_vtd_domain_page (iremap_entries);
@@ -310,7 +310,7 @@ static int ioapic_rte_to_remap_entry(struct iommu *iommu,GET_IREMAP_ENTRY (ir_ctrl->iremap_maddr, index, iremap_entries, iremap_entry); -memcpy (&new_ire, iremap_entry,sizeof (struct iremap_entry )); + new_ire = *iremap_entry;if ( rte_upper ) {
@@ -353,8 +353,8 @@ static int ioapic_rte_to_remap_entry(struct iommu *iommu, remap_rte->format =1 ;/* indicate remap format */ } -memcpy (iremap_entry, &new_ire,sizeof (struct iremap_entry )); -iommu_flush_cache_entry (iremap_entry,sizeof (struct iremap_entry )); + *iremap_entry = new_ire; +iommu_flush_cache_entry (iremap_entry,sizeof (*iremap_entry));iommu_flush_iec_index (iommu,0 , index);unmap_vtd_domain_page (iremap_entries);
@@ -642,8 +642,8 @@ static int msi_msg_to_remap_entry(if ( iremap_entry->val != new_ire.val ) { -memcpy (iremap_entry, &new_ire,sizeof (struct iremap_entry )); -iommu_flush_cache_entry (iremap_entry,sizeof (struct iremap_entry )); + *iremap_entry = new_ire; +iommu_flush_cache_entry (iremap_entry,sizeof (*iremap_entry));iommu_flush_iec_index (iommu,0 , index); }
Signature · 7 lines
2.1.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH v7 5/6] VT-d: Some cleanups
Quoted 5 lines · Feng Wu
Use type-safe structure assignment instead of
memcpy()Usesizeof(*iremap_entry).Signed-off-by Feng Wu <[email protected]>
Quoted 64 lines
---
v7:
- Remove a useless cleanupv6:
- More descripion about the patchxen/drivers/passthrough/vtd/intremap.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)xen/drivers/passthrough/vtd/intremap.c +7
-7@@ -183,8 +183,8 @@ static void free_remap_entry(struct iommu *iommu, int index)GET_IREMAP_ENTRY (ir_ctrl->iremap_maddr, index, iremap_entries, iremap_entry); -memset (iremap_entry,0 ,sizeof (struct iremap_entry )); -iommu_flush_cache_entry (iremap_entry,sizeof (struct iremap_entry )); +memset (iremap_entry,0 ,sizeof (*iremap_entry)); +iommu_flush_cache_entry (iremap_entry,sizeof (*iremap_entry));iommu_flush_iec_index (iommu,0 , index);unmap_vtd_domain_page (iremap_entries);@@ -310,7 +310,7 @@ static int ioapic_rte_to_remap_entry(struct iommu *iommu,GET_IREMAP_ENTRY (ir_ctrl->iremap_maddr, index, iremap_entries, iremap_entry); -memcpy (&new_ire, iremap_entry,sizeof (struct iremap_entry )); + new_ire = *iremap_entry;if ( rte_upper ) {@@ -353,8 +353,8 @@ static int ioapic_rte_to_remap_entry(struct iommu *iommu, remap_rte->format =1 ;/* indicate remap format */ } -memcpy (iremap_entry, &new_ire,sizeof (struct iremap_entry )); -iommu_flush_cache_entry (iremap_entry,sizeof (struct iremap_entry )); + *iremap_entry = new_ire; +iommu_flush_cache_entry (iremap_entry,sizeof (*iremap_entry));iommu_flush_iec_index (iommu,0 , index);unmap_vtd_domain_page (iremap_entries);@@ -642,8 +642,8 @@ static int msi_msg_to_remap_entry(if ( iremap_entry->val != new_ire.val ) { -memcpy (iremap_entry, &new_ire,sizeof (struct iremap_entry )); -iommu_flush_cache_entry (iremap_entry,sizeof (struct iremap_entry )); + *iremap_entry = new_ire; +iommu_flush_cache_entry (iremap_entry,sizeof (*iremap_entry));iommu_flush_iec_index (iommu,0 , index); }Signature · 7 lines
2.1.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH v7 6/6 VMX: Fixup PI descriptor when cpu is offline
In reply to Feng WuWhen cpu is offline, we need to move all the vcpus in its blocking list to another online cpu, this patch handles it.
---
v7:
- Pass unsigned int to vmx_pi_desc_fixup()
v6:
- Carefully suppress 'SN' to avoid missing notification event during moving the vcpu to the new list
v5:
- Add some comments to explain why it doesn't cause deadlock for the ABBA deadlock scenario.
v4:
- Remove the pointless check since we are in machine stop context and no other cpus go down in parallel.
xen/arch/x86/hvm/vmx/vmcs.c | 1 + xen/arch/x86/hvm/vmx/vmx.c | 70 +++++++++++++++++++++++++++++++++++++++ xen/include/asm-x86/hvm/vmx/vmx.h | 1 + 3 files changed, 72 insertions(+)
xen/arch/x86/hvm/vmx/vmcs.c +1 -0
@@ -578,6 +578,7 @@ void vmx_cpu_dead(unsigned int cpu)vmx_free_vmcs (per_cpu (vmxon_region, cpu));per_cpu (vmxon_region, cpu) =0 ;nvmx_cpu_dead (cpu); +vmx_pi_desc_fixup (cpu); }int vmx_cpu_up (void )
xen/arch/x86/hvm/vmx/vmx.c +70 -0
76 lines not on this page · raw message
xen/include/asm-x86/hvm/vmx/vmx.h +1 -0
@@ -569,6 +569,7 @@ void free_p2m_hap_data(struct p2m_domain *p2m);void p2m_init_hap_data (struct p2m_domain *p2m);void vmx_pi_per_cpu_init (unsigned int cpu); +void vmx_pi_desc_fixup (unsigned int cpu);void vmx_pi_hooks_assign (struct domain *d);void vmx_pi_hooks_deassign (struct domain *d);
Signature · 7 lines
2.1.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel