All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alex Williamson <alex.williamson@redhat.com>
To: Jan Kiszka <jan.kiszka@web.de>
Cc: Avi Kivity <avi@redhat.com>,
	Marcelo Tosatti <mtosatti@redhat.com>,
	kvm@vger.kernel.org, "Michael S. Tsirkin" <mst@redhat.com>,
	Jan Kiszka <jan.kiszka@siemens.com>
Subject: Re: [PATCH 5/5] pci-assign: Use PCI-2.3-based shared legacy interrupts
Date: Mon, 13 Dec 2010 17:16:00 -0700	[thread overview]
Message-ID: <1292285760.2857.143.camel@x201> (raw)
In-Reply-To: <3c2a95e127d06df4833c3093dd104b088c98de92.1292282738.git.jan.kiszka@web.de>

On Tue, 2010-12-14 at 00:25 +0100, Jan Kiszka wrote:
> From: Jan Kiszka <jan.kiszka@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.
> 
> Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
> ---
>  hw/device-assignment.c |   38 +++++++++++++++++++++++++++++++++-----
>  qemu-kvm.c             |    8 ++++++++
>  qemu-kvm.h             |    3 +++
>  3 files changed, 44 insertions(+), 5 deletions(-)
> 
> diff --git a/hw/device-assignment.c b/hw/device-assignment.c
> index 26d3bd7..cf75c52 100644
> --- a/hw/device-assignment.c
> +++ b/hw/device-assignment.c
> @@ -423,12 +423,21 @@ static uint8_t pci_find_cap_offset(PCIDevice *d, uint8_t cap, uint8_t start)
>      return 0;
>  }
>  
> +static uint32_t calc_assigned_dev_id(uint16_t seg, uint8_t bus, uint8_t devfn)
> +{
> +    return (uint32_t)seg << 16 | (uint32_t)bus << 8 | (uint32_t)devfn;
> +}
> +
>  static void assigned_dev_pci_write_config(PCIDevice *d, uint32_t address,
>                                            uint32_t val, int len)
>  {
>      int fd;
>      ssize_t ret;
>      AssignedDevice *pci_dev = container_of(d, AssignedDevice, dev);
> +    struct kvm_assigned_pci_dev assigned_dev_data;
> +#ifdef KVM_CAP_PCI_2_3
> +    bool intx_masked, update_intx_mask;
> +#endif /* KVM_CAP_PCI_2_3 */
>  
>      DEBUG("(%x.%x): address=%04x val=0x%08x len=%d\n",
>            ((d->devfn >> 3) & 0x1F), (d->devfn & 0x7),
> @@ -439,6 +448,26 @@ static void assigned_dev_pci_write_config(PCIDevice *d, uint32_t address,
>      }
>  
>      if (ranges_overlap(address, len, PCI_COMMAND, 2)) {
> +#ifdef KVM_CAP_PCI_2_3
> +        update_intx_mask = false;
> +        if (address == PCI_COMMAND+1) {
> +            intx_masked = val & (PCI_COMMAND_INTX_DISABLE >> 8);
> +            update_intx_mask = true;
> +        } else if (len >= 2) {
> +            intx_masked = val & PCI_COMMAND_INTX_DISABLE;
> +            update_intx_mask = true;
> +        }

I wonder if this might be a little cleaner as something like this.

    if (ranges_overlap(address, len, PCI_COMMAND + 1, 1) {
        update_intx_mask = true;
        intx_masked = (len == 1 ? val << 8 : val) & PCI_COMMAND_INTX_DISABLE;
    }

> +        if (update_intx_mask) {
> +            memset(&assigned_dev_data, 0, sizeof(assigned_dev_data));
> +            assigned_dev_data.assigned_dev_id  =
> +                calc_assigned_dev_id(pci_dev->h_segnr, pci_dev->h_busnr,
> +                                     pci_dev->h_devfn);
> +            if (intx_masked) {
> +                assigned_dev_data.flags = KVM_DEV_ASSIGN_MASK_INTX;
> +            }
> +            kvm_assign_set_intx_mask(kvm_context, &assigned_dev_data);
> +        }
> +#endif /* KVM_CAP_PCI_2_3 */
>          pci_default_write_config(d, address, val, len);
>          /* Continue to program the card */
>      }
> @@ -876,11 +905,6 @@ static void free_assigned_device(AssignedDevice *dev)
>      }
>  }
>  
> -static uint32_t calc_assigned_dev_id(uint16_t seg, uint8_t bus, uint8_t devfn)
> -{
> -    return (uint32_t)seg << 16 | (uint32_t)bus << 8 | (uint32_t)devfn;
> -}
> -
>  static void assign_failed_examine(AssignedDevice *dev)
>  {
>      char name[PATH_MAX], dir[PATH_MAX], driver[PATH_MAX] = {}, *ns;
> @@ -971,6 +995,10 @@ static int assign_device(AssignedDevice *dev)
>                  "cause host memory corruption if the device issues DMA write "
>                  "requests!\n");
>      }
> +#ifdef KVM_CAP_PCI_2_3
> +    assigned_dev_data.flags |= KVM_DEV_ASSIGN_PCI_2_3;
> +    dev->emulate_cmd_mask |= PCI_COMMAND_INTX_DISABLE;
> +#endif /* KVM_CAP_PCI_2_3 */
>  
>      r = kvm_assign_pci_device(kvm_context, &assigned_dev_data);
>      if (r < 0) {
> diff --git a/qemu-kvm.c b/qemu-kvm.c
> index 471306b..8157b4f 100644
> --- a/qemu-kvm.c
> +++ b/qemu-kvm.c
> @@ -740,6 +740,14 @@ int kvm_deassign_pci_device(kvm_context_t kvm,
>  }
>  #endif
>  
> +#ifdef KVM_CAP_PCI_2_3
> +int kvm_assign_set_intx_mask(kvm_context_t kvm,
> +                             struct kvm_assigned_pci_dev *assigned_dev)
> +{
> +    return kvm_vm_ioctl(kvm_state, KVM_ASSIGN_SET_INTX_MASK, assigned_dev);
> +}
> +#endif
> +
>  int kvm_reinject_control(kvm_context_t kvm, int pit_reinject)
>  {
>  #ifdef KVM_CAP_REINJECT_CONTROL
> diff --git a/qemu-kvm.h b/qemu-kvm.h
> index 7e6edfb..522b1b2 100644
> --- a/qemu-kvm.h
> +++ b/qemu-kvm.h
> @@ -602,6 +602,9 @@ int kvm_assign_set_msix_entry(kvm_context_t kvm,
>                                struct kvm_assigned_msix_entry *entry);
>  #endif
>  
> +int kvm_assign_set_intx_mask(kvm_context_t kvm,
> +                             struct kvm_assigned_pci_dev *assigned_dev);
> +
>  #else                           /* !CONFIG_KVM */
>  
>  typedef struct kvm_context *kvm_context_t;




  reply	other threads:[~2010-12-14  0:16 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-12-13 23:25 [PATCH 0/5] pci-assign: Host IRQ sharing suppport + some fixes and cleanups Jan Kiszka
2010-12-13 23:25 ` [PATCH 1/5] pci-assign: Clean up assigned_dev_pci_read/write_config Jan Kiszka
2010-12-13 23:53   ` Alex Williamson
2010-12-13 23:25 ` [PATCH 2/5] pci-assign: Fix dword read at PCI_COMMAND Jan Kiszka
2010-12-13 23:53   ` Alex Williamson
2010-12-13 23:25 ` [PATCH 3/5] pci-assign: Remove suspicious hunk from assigned_dev_pci_read_config Jan Kiszka
2010-12-13 23:54   ` Alex Williamson
2010-12-13 23:25 ` [PATCH 4/5] pci-assign: Convert need_emulate_cmd into a bitmask Jan Kiszka
2010-12-13 23:56   ` Alex Williamson
2010-12-15 10:36     ` Michael S. Tsirkin
2010-12-13 23:25 ` [PATCH 5/5] pci-assign: Use PCI-2.3-based shared legacy interrupts Jan Kiszka
2010-12-14  0:16   ` Alex Williamson [this message]
2010-12-14 23:23     ` Jan Kiszka

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=1292285760.2857.143.camel@x201 \
    --to=alex.williamson@redhat.com \
    --cc=avi@redhat.com \
    --cc=jan.kiszka@siemens.com \
    --cc=jan.kiszka@web.de \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.