Commit 17071fe7 authored by Sheng Yang's avatar Sheng Yang Committed by Avi Kivity

KVM: Add support to disable MSI for assigned device

MSI is always enabled by default for msi2intx=1. But if msi2intx=0, we
have to disable MSI if guest require to do so.

The patch also discard unnecessary msi2intx judgment if guest want to update
MSI state.

Notice KVM_DEV_IRQ_ASSIGN_MSI_ACTION is a mask which should cover all MSI
related operations, though we only got one for now.
Signed-off-by: default avatarSheng Yang <sheng@linux.intel.com>
Signed-off-by: default avatarAvi Kivity <avi@redhat.com>
parent 67346440
...@@ -550,6 +550,7 @@ struct kvm_assigned_irq { ...@@ -550,6 +550,7 @@ struct kvm_assigned_irq {
#define KVM_DEV_ASSIGN_ENABLE_IOMMU (1 << 0) #define KVM_DEV_ASSIGN_ENABLE_IOMMU (1 << 0)
#define KVM_DEV_IRQ_ASSIGN_MSI_ACTION KVM_DEV_IRQ_ASSIGN_ENABLE_MSI
#define KVM_DEV_IRQ_ASSIGN_ENABLE_MSI (1 << 0) #define KVM_DEV_IRQ_ASSIGN_ENABLE_MSI (1 << 0)
#endif #endif
...@@ -343,6 +343,14 @@ static int assigned_device_update_msi(struct kvm *kvm, ...@@ -343,6 +343,14 @@ static int assigned_device_update_msi(struct kvm *kvm,
adev->irq_requested_type &= ~KVM_ASSIGNED_DEV_GUEST_MSI; adev->irq_requested_type &= ~KVM_ASSIGNED_DEV_GUEST_MSI;
adev->guest_irq = airq->guest_irq; adev->guest_irq = airq->guest_irq;
adev->ack_notifier.gsi = airq->guest_irq; adev->ack_notifier.gsi = airq->guest_irq;
} else {
/*
* Guest require to disable device MSI, we disable MSI and
* re-enable INTx by default again. Notice it's only for
* non-msi2intx.
*/
assigned_device_update_intx(kvm, adev, airq);
return 0;
} }
if (adev->irq_requested_type & KVM_ASSIGNED_DEV_HOST_MSI) if (adev->irq_requested_type & KVM_ASSIGNED_DEV_HOST_MSI)
...@@ -379,6 +387,7 @@ static int kvm_vm_ioctl_assign_irq(struct kvm *kvm, ...@@ -379,6 +387,7 @@ static int kvm_vm_ioctl_assign_irq(struct kvm *kvm,
{ {
int r = 0; int r = 0;
struct kvm_assigned_dev_kernel *match; struct kvm_assigned_dev_kernel *match;
u32 current_flags = 0, changed_flags;
mutex_lock(&kvm->lock); mutex_lock(&kvm->lock);
...@@ -416,8 +425,13 @@ static int kvm_vm_ioctl_assign_irq(struct kvm *kvm, ...@@ -416,8 +425,13 @@ static int kvm_vm_ioctl_assign_irq(struct kvm *kvm,
} }
} }
if ((!msi2intx && if ((match->irq_requested_type & KVM_ASSIGNED_DEV_HOST_MSI) &&
(assigned_irq->flags & KVM_DEV_IRQ_ASSIGN_ENABLE_MSI)) || (match->irq_requested_type & KVM_ASSIGNED_DEV_GUEST_MSI))
current_flags |= KVM_DEV_IRQ_ASSIGN_ENABLE_MSI;
changed_flags = assigned_irq->flags ^ current_flags;
if ((changed_flags & KVM_DEV_IRQ_ASSIGN_MSI_ACTION) ||
(msi2intx && match->dev->msi_enabled)) { (msi2intx && match->dev->msi_enabled)) {
#ifdef CONFIG_X86 #ifdef CONFIG_X86
r = assigned_device_update_msi(kvm, match, assigned_irq); r = assigned_device_update_msi(kvm, match, assigned_irq);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment