From: Jan Kiszka <jan.kiszka@siemens.com>
To: Avi Kivity <avi@redhat.com>, Marcelo Tosatti <mtosatti@redhat.com>
Cc: Alex Williamson <alex.williamson@redhat.com>,
"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
"Michael S. Tsirkin" <mst@redhat.com>
Subject: [PATCH v5 3/4] pci-assign: Use PCI-2.3-based shared legacy interrupts
Date: Thu, 08 Mar 2012 19:04:01 +0100 [thread overview]
Message-ID: <4F58F491.1000601@siemens.com> (raw)
In-Reply-To: <4F58E7A1.5010708@siemens.com>
Enable the new KVM feature that allows legacy interrupt sharing for
PCI-2.3-compliant devices. This requires to synchronize any guest
change of the INTx mask bit to the kernel.
The feature is controlled by the property 'share_intx' and is off by
default for now.
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
Changes in v5:
- Only emulate INTx disable bit if there is kernel support
hw/device-assignment.c | 26 ++++++++++++++++++++++++++
hw/device-assignment.h | 10 ++++++----
qemu-kvm.c | 9 +++++++++
qemu-kvm.h | 2 ++
4 files changed, 43 insertions(+), 4 deletions(-)
diff --git a/hw/device-assignment.c b/hw/device-assignment.c
index a5f1abb..ad3406c 100644
--- a/hw/device-assignment.c
+++ b/hw/device-assignment.c
@@ -782,6 +782,14 @@ static int assign_device(AssignedDevice *dev)
"cause host memory corruption if the device issues DMA write "
"requests!\n");
}
+ if (dev->features & ASSIGNED_DEVICE_SHARE_INTX_MASK &&
+ kvm_has_intx_set_mask()) {
+ assigned_dev_data.flags |= KVM_DEV_ASSIGN_PCI_2_3;
+
+ /* hide host-side INTx masking from the guest */
+ dev->emulate_config_read[PCI_COMMAND + 1] |=
+ PCI_COMMAND_INTX_DISABLE >> 8;
+ }
r = kvm_assign_pci_device(kvm_state, &assigned_dev_data);
if (r < 0) {
@@ -1121,10 +1129,26 @@ static void assigned_dev_pci_write_config(PCIDevice *pci_dev, uint32_t address,
uint32_t val, int len)
{
AssignedDevice *assigned_dev = DO_UPCAST(AssignedDevice, dev, pci_dev);
+ uint16_t old_cmd = pci_get_word(pci_dev->config + PCI_COMMAND);
uint32_t emulate_mask, full_emulation_mask;
+ int ret;
pci_default_write_config(pci_dev, address, val, len);
+ if (kvm_has_intx_set_mask() &&
+ range_covers_byte(address, len, PCI_COMMAND + 1)) {
+ bool intx_masked = (pci_get_word(pci_dev->config + PCI_COMMAND) &
+ PCI_COMMAND_INTX_DISABLE);
+
+ if (intx_masked != !!(old_cmd & PCI_COMMAND_INTX_DISABLE)) {
+ ret = kvm_device_intx_set_mask(kvm_state,
+ calc_assigned_dev_id(assigned_dev),
+ intx_masked);
+ if (ret) {
+ perror("assigned_dev_pci_write_config: set intx mask");
+ }
+ }
+ }
if (assigned_dev->cap.available & ASSIGNED_DEVICE_CAP_MSI) {
if (range_covers_byte(address, len,
pci_dev->msi_cap + PCI_MSI_FLAGS)) {
@@ -1748,6 +1772,8 @@ static Property da_properties[] =
ASSIGNED_DEVICE_USE_IOMMU_BIT, true),
DEFINE_PROP_BIT("prefer_msi", AssignedDevice, features,
ASSIGNED_DEVICE_PREFER_MSI_BIT, true),
+ DEFINE_PROP_BIT("share_intx", AssignedDevice, features,
+ ASSIGNED_DEVICE_SHARE_INTX_BIT, false),
DEFINE_PROP_INT32("bootindex", AssignedDevice, bootindex, -1),
DEFINE_PROP_STRING("configfd", AssignedDevice, configfd_name),
DEFINE_PROP_END_OF_LIST(),
diff --git a/hw/device-assignment.h b/hw/device-assignment.h
index b4bcfa6..5d271d5 100644
--- a/hw/device-assignment.h
+++ b/hw/device-assignment.h
@@ -74,11 +74,13 @@ typedef struct {
PCIRegion *region;
} AssignedDevRegion;
-#define ASSIGNED_DEVICE_USE_IOMMU_BIT 0
-#define ASSIGNED_DEVICE_PREFER_MSI_BIT 1
+#define ASSIGNED_DEVICE_USE_IOMMU_BIT 0
+#define ASSIGNED_DEVICE_PREFER_MSI_BIT 1
+#define ASSIGNED_DEVICE_SHARE_INTX_BIT 2
-#define ASSIGNED_DEVICE_USE_IOMMU_MASK (1 << ASSIGNED_DEVICE_USE_IOMMU_BIT)
-#define ASSIGNED_DEVICE_PREFER_MSI_MASK (1 << ASSIGNED_DEVICE_PREFER_MSI_BIT)
+#define ASSIGNED_DEVICE_USE_IOMMU_MASK (1 << ASSIGNED_DEVICE_USE_IOMMU_BIT)
+#define ASSIGNED_DEVICE_PREFER_MSI_MASK (1 << ASSIGNED_DEVICE_PREFER_MSI_BIT)
+#define ASSIGNED_DEVICE_SHARE_INTX_MASK (1 << ASSIGNED_DEVICE_SHARE_INTX_BIT)
typedef struct {
uint32_t addr_lo;
diff --git a/qemu-kvm.c b/qemu-kvm.c
index 09a35f0..2047ebb 100644
--- a/qemu-kvm.c
+++ b/qemu-kvm.c
@@ -54,6 +54,15 @@ static int kvm_old_assign_irq(KVMState *s,
return kvm_vm_ioctl(s, KVM_ASSIGN_IRQ, assigned_irq);
}
+int kvm_device_intx_set_mask(KVMState *s, uint32_t dev_id, bool masked)
+{
+ struct kvm_assigned_pci_dev assigned_dev;
+
+ assigned_dev.assigned_dev_id = dev_id;
+ assigned_dev.flags = masked ? KVM_DEV_ASSIGN_MASK_INTX : 0;
+ return kvm_vm_ioctl(s, KVM_ASSIGN_SET_INTX_MASK, &assigned_dev);
+}
+
#ifdef KVM_CAP_ASSIGN_DEV_IRQ
int kvm_assign_irq(KVMState *s, struct kvm_assigned_irq *assigned_irq)
{
diff --git a/qemu-kvm.h b/qemu-kvm.h
index 3c4f023..2b23daf 100644
--- a/qemu-kvm.h
+++ b/qemu-kvm.h
@@ -114,6 +114,8 @@ int kvm_assign_irq(KVMState *s, struct kvm_assigned_irq *assigned_irq);
*/
int kvm_deassign_irq(KVMState *s, struct kvm_assigned_irq *assigned_irq);
+int kvm_device_intx_set_mask(KVMState *s, uint32_t dev_id, bool masked);
+
/*!
* \brief Notifies host kernel about a PCI device to be deassigned from a guest
*
--
1.7.3.4
next prev parent reply other threads:[~2012-03-08 18:04 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-03-08 10:10 [PATCH v4 0/4] qemu-kvm: pci-assign: Host IRQ sharing suppport Jan Kiszka
2012-03-08 10:10 ` [PATCH v4 1/4] kvm: Update kernel headers against kvm.git Jan Kiszka
2012-04-05 9:44 ` Michael S. Tsirkin
2012-03-08 10:10 ` [PATCH v4 2/4] kvm: Introduce kvm_has_intx_set_mask Jan Kiszka
2012-04-05 9:44 ` Michael S. Tsirkin
2012-03-08 10:10 ` [PATCH v4 3/4] pci-assign: Use PCI-2.3-based shared legacy interrupts Jan Kiszka
2012-03-08 17:00 ` Alex Williamson
2012-03-08 17:08 ` Jan Kiszka
2012-03-08 18:04 ` Jan Kiszka [this message]
2012-04-05 9:44 ` Michael S. Tsirkin
2012-03-08 10:10 ` [PATCH v4 4/4] pci_assign: Flip defaults of prefer_msi and share_intx Jan Kiszka
2012-04-05 9:46 ` Michael S. Tsirkin
2012-03-09 22:38 ` [PATCH v4 0/4] qemu-kvm: pci-assign: Host IRQ sharing suppport Alex Williamson
2012-03-09 22:49 ` Marcelo Tosatti
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=4F58F491.1000601@siemens.com \
--to=jan.kiszka@siemens.com \
--cc=alex.williamson@redhat.com \
--cc=avi@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=mst@redhat.com \
--cc=mtosatti@redhat.com \
/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 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).