From: "Michael S. Tsirkin" <mst@redhat.com>
To: Jan Kiszka <jan.kiszka@siemens.com>
Cc: Alex Williamson <alex.williamson@redhat.com>,
Marcelo Tosatti <mtosatti@redhat.com>,
Avi Kivity <avi@redhat.com>,
kvm@vger.kernel.org, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [RFC][PATCH 42/45] msix: Introduce msix_init_simple
Date: Mon, 17 Oct 2011 13:22:17 +0200 [thread overview]
Message-ID: <20111017112217.GC4537@redhat.com> (raw)
In-Reply-To: <c6418267e763286248166985b25b1dc0a357fc4c.1318843694.git.jan.kiszka@siemens.com>
On Mon, Oct 17, 2011 at 11:28:16AM +0200, Jan Kiszka wrote:
> Devices models are usually not interested in specifying MSI-X
> configuration details beyond the number of vectors to provide and the
> BAR number to use. Layout of an exclusively used BAR and its
> registration can also be handled centrally.
>
> This is the purpose of msix_init_simple. It provides handy services to
> the existing users. Future users like device assignment may require more
> detailed setup specification. For them we will (re-)introduce msix_init
> with the full list of configuration option (in contrast to the current
> code).
>
> Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Well, this seems a bit of a code churn then, doesn't it?
We are also discussing using memory BAR for virtio-pci for other
stuff besides MSI-X, so the last user of the _simple variant
will be ivshmem then?
> ---
> hw/ivshmem.c | 6 +-----
> hw/msix.c | 35 ++++++++++++++---------------------
> hw/msix.h | 7 +++----
> hw/virtio-pci.c | 15 +++++----------
> hw/virtio-pci.h | 1 -
> 5 files changed, 23 insertions(+), 41 deletions(-)
>
> diff --git a/hw/ivshmem.c b/hw/ivshmem.c
> index a402c98..d9dbd18 100644
> --- a/hw/ivshmem.c
> +++ b/hw/ivshmem.c
> @@ -65,7 +65,6 @@ typedef struct IVShmemState {
> */
> MemoryRegion bar;
> MemoryRegion ivshmem;
> - MemoryRegion msix_bar;
> uint64_t ivshmem_size; /* size of shared memory region */
> int shm_fd; /* shared memory file descriptor */
>
> @@ -539,10 +538,7 @@ static void ivshmem_setup_msi(IVShmemState *s)
> {
> /* allocate the MSI-X vectors */
>
> - memory_region_init(&s->msix_bar, "ivshmem-msix", 4096);
> - if (!msix_init(&s->dev, s->vectors, &s->msix_bar, 1, 0)) {
> - pci_register_bar(&s->dev, 1, PCI_BASE_ADDRESS_SPACE_MEMORY,
> - &s->msix_bar);
> + if (!msix_init_simple(&s->dev, s->vectors, 1)) {
> IVSHMEM_DPRINTF("msix initialized (%d vectors)\n", s->vectors);
> } else {
> IVSHMEM_DPRINTF("msix initialization failed\n");
> diff --git a/hw/msix.c b/hw/msix.c
> index bccd8b1..258b9c1 100644
> --- a/hw/msix.c
> +++ b/hw/msix.c
> @@ -244,17 +244,6 @@ static const MemoryRegionOps msix_mmio_ops = {
> },
> };
>
> -static void msix_mmio_setup(PCIDevice *d, MemoryRegion *bar)
> -{
> - uint8_t *config = d->config + d->msix_cap;
> - uint32_t table = pci_get_long(config + PCI_MSIX_TABLE);
> - uint32_t offset = table & ~(MSIX_PAGE_SIZE - 1);
> - /* TODO: for assigned devices, we'll want to make it possible to map
> - * pending bits separately in case they are in a separate bar. */
> -
> - memory_region_add_subregion(bar, offset, &d->msix_mmio);
> -}
> -
> static void msix_mask_all(struct PCIDevice *dev, unsigned nentries)
> {
> int vector;
> @@ -272,11 +261,9 @@ static void msix_mask_all(struct PCIDevice *dev, unsigned nentries)
> }
> }
>
> -/* Initialize the MSI-X structures. Note: if MSI-X is supported, BAR size is
> - * modified, it should be retrieved with msix_bar_size. */
> -int msix_init(struct PCIDevice *dev, unsigned short nentries,
> - MemoryRegion *bar,
> - unsigned bar_nr, unsigned bar_size)
> +/* Initialize the MSI-X structures in a single dedicated BAR
> + * and register it. */
> +int msix_init_simple(PCIDevice *dev, unsigned short nentries, unsigned bar_nr)
> {
> int ret;
>
> @@ -296,14 +283,16 @@ int msix_init(struct PCIDevice *dev, unsigned short nentries,
> "msix", MSIX_PAGE_SIZE);
>
> dev->msix_entries_nr = nentries;
> - ret = msix_add_config(dev, nentries, bar_nr, bar_size);
> + ret = msix_add_config(dev, nentries, bar_nr, 0);
> if (ret)
> goto err_config;
>
> dev->msix_cache = g_malloc0(nentries * sizeof *dev->msix_cache);
>
> dev->cap_present |= QEMU_PCI_CAP_MSIX;
> - msix_mmio_setup(dev, bar);
> +
> + pci_register_bar(dev, bar_nr, PCI_BASE_ADDRESS_SPACE_MEMORY,
> + &dev->msix_mmio);
> return 0;
>
> err_config:
> @@ -315,10 +304,10 @@ err_config:
> }
>
> /* Clean up resources for the device. */
> -int msix_uninit(PCIDevice *dev, MemoryRegion *bar)
> +void msix_uninit(PCIDevice *dev, MemoryRegion *bar)
> {
> if (!msix_present(dev)) {
> - return 0;
> + return;
> }
> pci_del_capability(dev, PCI_CAP_ID_MSIX, MSIX_CAP_LENGTH);
> dev->msix_cap = 0;
> @@ -332,7 +321,11 @@ int msix_uninit(PCIDevice *dev, MemoryRegion *bar)
> g_free(dev->msix_cache);
>
> dev->cap_present &= ~QEMU_PCI_CAP_MSIX;
> - return 0;
> +}
> +
> +void msix_uninit_simple(PCIDevice *dev)
> +{
> + msix_uninit(dev, &dev->msix_mmio);
> }
>
> void msix_save(PCIDevice *dev, QEMUFile *f)
> diff --git a/hw/msix.h b/hw/msix.h
> index dfc6087..56e7ba5 100644
> --- a/hw/msix.h
> +++ b/hw/msix.h
> @@ -4,14 +4,13 @@
> #include "qemu-common.h"
> #include "pci.h"
>
> -int msix_init(PCIDevice *pdev, unsigned short nentries,
> - MemoryRegion *bar,
> - unsigned bar_nr, unsigned bar_size);
> +int msix_init_simple(PCIDevice *dev, unsigned short nentries, unsigned bar_nr);
>
> void msix_write_config(PCIDevice *pci_dev, uint32_t address,
> uint32_t old_val, int len);
>
> -int msix_uninit(PCIDevice *d, MemoryRegion *bar);
> +void msix_uninit(PCIDevice *d, MemoryRegion *bar);
> +void msix_uninit_simple(PCIDevice *d);
>
> void msix_save(PCIDevice *dev, QEMUFile *f);
> void msix_load(PCIDevice *dev, QEMUFile *f);
> diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
> index 5004d7d..6fe2b5e 100644
> --- a/hw/virtio-pci.c
> +++ b/hw/virtio-pci.c
> @@ -713,13 +713,10 @@ void virtio_init_pci(VirtIOPCIProxy *proxy, VirtIODevice *vdev)
> pci_set_word(config + 0x2e, vdev->device_id);
> config[0x3d] = 1;
>
> - memory_region_init(&proxy->msix_bar, "virtio-msix", 4096);
> - if (vdev->nvectors && !msix_init(&proxy->pci_dev, vdev->nvectors,
> - &proxy->msix_bar, 1, 0)) {
> - pci_register_bar(&proxy->pci_dev, 1, PCI_BASE_ADDRESS_SPACE_MEMORY,
> - &proxy->msix_bar);
> - } else
> + if (vdev->nvectors &&
> + msix_init_simple(&proxy->pci_dev, vdev->nvectors, 1)) {
> vdev->nvectors = 0;
> + }
>
> proxy->pci_dev.config_write = virtio_write_config;
>
> @@ -766,12 +763,10 @@ static int virtio_blk_init_pci(PCIDevice *pci_dev)
> static int virtio_exit_pci(PCIDevice *pci_dev)
> {
> VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
> - int r;
>
> memory_region_destroy(&proxy->bar);
> - r = msix_uninit(pci_dev, &proxy->msix_bar);
> - memory_region_destroy(&proxy->msix_bar);
> - return r;
> + msix_uninit_simple(pci_dev);
> + return 0;
> }
>
> static int virtio_blk_exit_pci(PCIDevice *pci_dev)
> diff --git a/hw/virtio-pci.h b/hw/virtio-pci.h
> index 14c10f7..5af1c8c 100644
> --- a/hw/virtio-pci.h
> +++ b/hw/virtio-pci.h
> @@ -22,7 +22,6 @@ typedef struct {
> PCIDevice pci_dev;
> VirtIODevice *vdev;
> MemoryRegion bar;
> - MemoryRegion msix_bar;
> uint32_t flags;
> uint32_t class_code;
> uint32_t nvectors;
> --
> 1.7.3.4
next prev parent reply other threads:[~2011-10-17 11:21 UTC|newest]
Thread overview: 144+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-10-17 9:27 [Qemu-devel] [RFC][PATCH 00/45] qemu-kvm: MSI layer rework for in-kernel irqchip support Jan Kiszka
2011-10-17 9:27 ` [Qemu-devel] [RFC][PATCH 01/45] msi: Guard msi/msix_write_config with msi_present Jan Kiszka
2011-10-17 9:27 ` [Qemu-devel] [RFC][PATCH 02/45] msi: Guard msi_reset " Jan Kiszka
2011-10-17 9:27 ` [Qemu-devel] [RFC][PATCH 03/45] msi: Use msi/msix_present more consistently Jan Kiszka
2011-10-17 9:27 ` [Qemu-devel] [RFC][PATCH 04/45] msi: Invoke msi/msix_reset from PCI core Jan Kiszka
2011-10-17 9:27 ` [Qemu-devel] [RFC][PATCH 05/45] msi: Invoke msi/msix_write_config " Jan Kiszka
2011-10-17 9:27 ` [Qemu-devel] [RFC][PATCH 06/45] msix: Prevent bogus mask updates on MMIO accesses Jan Kiszka
2011-10-17 11:10 ` Michael S. Tsirkin
2011-10-17 11:23 ` Jan Kiszka
2011-10-17 11:57 ` Michael S. Tsirkin
2011-10-17 12:07 ` Jan Kiszka
2011-10-17 12:50 ` Michael S. Tsirkin
2011-10-17 19:11 ` Jan Kiszka
2011-10-17 19:43 ` Michael S. Tsirkin
2011-10-17 9:27 ` [Qemu-devel] [RFC][PATCH 07/45] msi: Generalize msix_supported to msi_supported Jan Kiszka
2011-10-17 9:27 ` [Qemu-devel] [RFC][PATCH 08/45] Introduce MSIMessage structure Jan Kiszka
2011-10-17 11:46 ` Michael S. Tsirkin
2011-10-17 11:51 ` Jan Kiszka
2011-10-17 12:04 ` Michael S. Tsirkin
2011-10-17 12:09 ` Jan Kiszka
2011-10-17 13:01 ` Michael S. Tsirkin
2011-10-17 19:14 ` Jan Kiszka
2011-10-17 9:27 ` [Qemu-devel] [RFC][PATCH 09/45] msi: Factor out msi_message_from_vector Jan Kiszka
2011-10-17 9:27 ` [Qemu-devel] [RFC][PATCH 10/45] msix: Factor out msix_message_from_vector Jan Kiszka
2011-10-17 9:27 ` [Qemu-devel] [RFC][PATCH 11/45] msi: Factor out delivery hook Jan Kiszka
2011-10-17 10:56 ` Avi Kivity
2011-10-17 11:15 ` Jan Kiszka
2011-10-17 11:22 ` Avi Kivity
2011-10-17 11:29 ` Jan Kiszka
2011-10-17 12:14 ` Avi Kivity
2011-10-17 18:59 ` Jan Kiszka
2011-10-17 13:41 ` Michael S. Tsirkin
2011-10-17 13:41 ` Avi Kivity
2011-10-17 13:48 ` Michael S. Tsirkin
2011-10-17 19:18 ` Jan Kiszka
2011-10-17 13:43 ` Michael S. Tsirkin
2011-10-17 19:15 ` Jan Kiszka
2011-10-18 12:05 ` Michael S. Tsirkin
2011-10-18 12:23 ` Jan Kiszka
2011-10-18 12:38 ` Michael S. Tsirkin
2011-10-18 12:41 ` Jan Kiszka
2011-10-18 12:44 ` malc
2011-10-18 12:49 ` Michael S. Tsirkin
2011-10-17 9:27 ` [Qemu-devel] [RFC][PATCH 12/45] msi: Introduce MSIRoutingCache Jan Kiszka
2011-10-17 11:06 ` Avi Kivity
2011-10-17 11:19 ` Jan Kiszka
2011-10-17 11:25 ` Avi Kivity
2011-10-17 11:31 ` Jan Kiszka
2011-10-17 12:17 ` Avi Kivity
2011-10-17 15:37 ` Michael S. Tsirkin
2011-10-17 19:19 ` Jan Kiszka
2011-10-18 12:17 ` Michael S. Tsirkin
2011-10-18 12:26 ` Jan Kiszka
2011-10-17 15:43 ` Michael S. Tsirkin
2011-10-17 19:23 ` Jan Kiszka
2011-10-17 9:27 ` [Qemu-devel] [RFC][PATCH 13/45] hpet: Use msi_deliver Jan Kiszka
2011-10-17 9:27 ` [Qemu-devel] [RFC][PATCH 14/45] qemu-kvm: Drop useless kvm_clear_gsi_routes Jan Kiszka
2011-10-17 9:27 ` [Qemu-devel] [RFC][PATCH 15/45] qemu-kvm: Drop unused kvm_del_irq_route Jan Kiszka
2011-10-17 9:27 ` [Qemu-devel] [RFC][PATCH 16/45] qemu-kvm: Use MSIMessage and MSIRoutingCache Jan Kiszka
2011-10-17 9:27 ` [Qemu-devel] [RFC][PATCH 17/45] qemu-kvm: Track MSIRoutingCache in KVM routing table Jan Kiszka
2011-10-17 11:13 ` Avi Kivity
2011-10-17 11:25 ` Jan Kiszka
2011-10-17 12:15 ` Avi Kivity
2011-10-17 9:27 ` [Qemu-devel] [RFC][PATCH 18/45] qemu-kvm: Hook into MSI delivery at APIC level Jan Kiszka
2011-10-17 9:27 ` [Qemu-devel] [RFC][PATCH 19/45] qemu-kvm: Factor out kvm_msi_irqfd_set Jan Kiszka
2011-10-17 9:27 ` [Qemu-devel] [RFC][PATCH 20/45] qemu-kvm: msix: Only invoke msix_handle_mask_update on changes Jan Kiszka
2011-10-17 9:27 ` [Qemu-devel] [RFC][PATCH 21/45] qemu-kvm: msix: Don't fire notifier spuriously on set/unset Jan Kiszka
2011-10-17 9:27 ` [Qemu-devel] [RFC][PATCH 22/45] qemu-kvm: msix: Fire mask notifier on global mask changes Jan Kiszka
2011-10-17 12:16 ` Michael S. Tsirkin
2011-10-17 19:00 ` Jan Kiszka
2011-10-18 12:40 ` Michael S. Tsirkin
2011-10-18 12:45 ` Jan Kiszka
2011-10-18 12:57 ` Michael S. Tsirkin
2011-10-17 9:27 ` [Qemu-devel] [RFC][PATCH 23/45] qemu-kvm: Rework MSI-X mask notifier to generic MSI config notifiers Jan Kiszka
2011-10-17 11:40 ` Michael S. Tsirkin
2011-10-17 11:45 ` Jan Kiszka
2011-10-17 12:39 ` Michael S. Tsirkin
2011-10-17 19:08 ` Jan Kiszka
2011-10-18 13:46 ` Michael S. Tsirkin
2011-10-18 13:49 ` Jan Kiszka
2011-10-17 9:27 ` [Qemu-devel] [RFC][PATCH 24/45] qemu-kvm: msix: Don't handle mask updated while disabled Jan Kiszka
2011-10-17 9:27 ` [Qemu-devel] [RFC][PATCH 25/45] qemu-kvm: Update MSI cache on kvm_msi_irqfd_set Jan Kiszka
2011-10-17 9:28 ` [Qemu-devel] [RFC][PATCH 26/45] qemu-kvm: Use g_realloc for irq_routes extension Jan Kiszka
2011-10-17 9:28 ` [Qemu-devel] [RFC][PATCH 27/45] qemu-kvm: Lazily update MSI caches Jan Kiszka
2011-10-17 9:28 ` [Qemu-devel] [RFC][PATCH 28/45] qemu-kvm: msix: Drop tracking of used vectors Jan Kiszka
2011-10-17 15:48 ` Michael S. Tsirkin
2011-10-17 19:28 ` Jan Kiszka
2011-10-18 11:58 ` Michael S. Tsirkin
2011-10-18 12:08 ` Jan Kiszka
2011-10-18 12:33 ` Michael S. Tsirkin
2011-10-18 12:38 ` Jan Kiszka
2011-10-18 12:48 ` Michael S. Tsirkin
2011-10-18 13:00 ` Jan Kiszka
2011-10-18 13:37 ` Michael S. Tsirkin
2011-10-18 13:46 ` Jan Kiszka
2011-10-18 14:01 ` Michael S. Tsirkin
2011-10-18 14:08 ` Jan Kiszka
2011-10-18 15:08 ` Michael S. Tsirkin
2011-10-18 15:22 ` Jan Kiszka
2011-10-18 15:55 ` Jan Kiszka
2011-10-18 17:06 ` Michael S. Tsirkin
2011-10-18 18:24 ` Jan Kiszka
2011-10-18 18:40 ` Michael S. Tsirkin
2011-10-18 19:37 ` Jan Kiszka
2011-10-18 21:40 ` Michael S. Tsirkin
2011-10-18 22:13 ` Jan Kiszka
2011-10-19 0:56 ` Michael S. Tsirkin
2011-10-19 6:41 ` Jan Kiszka
2011-10-19 9:03 ` Michael S. Tsirkin
2011-10-19 11:17 ` Jan Kiszka
2011-10-20 22:02 ` Michael S. Tsirkin
2011-10-21 7:09 ` Jan Kiszka
2011-10-21 7:54 ` Michael S. Tsirkin
2011-10-21 9:27 ` Jan Kiszka
2011-10-21 10:57 ` Michael S. Tsirkin
2011-10-18 18:26 ` Jan Kiszka
2011-10-18 15:56 ` Michael S. Tsirkin
2011-10-18 15:58 ` Jan Kiszka
2011-10-17 9:28 ` [Qemu-devel] [RFC][PATCH 29/45] pci-assign: Drop kvm_assigned_irq::host_irq initialization Jan Kiszka
2011-10-17 9:28 ` [Qemu-devel] [RFC][PATCH 30/45] pci-assign: Rename assign_irq to assign_intx Jan Kiszka
2011-10-17 9:28 ` [Qemu-devel] [RFC][PATCH 31/45] qemu-kvm: Refactor kvm_deassign_irq to kvm_device_irq_deassign Jan Kiszka
2011-10-17 9:28 ` [Qemu-devel] [RFC][PATCH 32/45] pci-assign: Factor out deassign_irq Jan Kiszka
2011-10-17 9:28 ` [Qemu-devel] [RFC][PATCH 33/45] qemu-kvm: Factor out kvm_device_intx_assign Jan Kiszka
2011-10-17 9:28 ` [Qemu-devel] [RFC][PATCH 34/45] qemu-kvm: Factor out kvm_device_msi_assign Jan Kiszka
2011-10-17 9:28 ` [Qemu-devel] [RFC][PATCH 35/45] pci-assign: Polish assigned_dev_update_msix_mmio Jan Kiszka
2011-10-17 9:28 ` [Qemu-devel] [RFC][PATCH 36/45] qemu-kvm: Factor out kvm_device_msix_* services Jan Kiszka
2011-10-17 9:28 ` [Qemu-devel] [RFC][PATCH 37/45] qemu-kvm: Clean up irqrouting API Jan Kiszka
2011-10-17 9:28 ` [Qemu-devel] [RFC][PATCH 38/45] msi: Implement config notifiers for legacy MSI Jan Kiszka
2011-10-17 9:28 ` [Qemu-devel] [RFC][PATCH 39/45] pci-assign: Use generic MSI support Jan Kiszka
2011-10-17 9:28 ` [Qemu-devel] [RFC][PATCH 40/45] qemu-kvm: msix: Drop check for preexisting cap from msix_add_config Jan Kiszka
2011-10-17 9:28 ` [Qemu-devel] [RFC][PATCH 41/45] msix: Drop unused msix_bar_size Jan Kiszka
2011-10-17 9:28 ` [Qemu-devel] [RFC][PATCH 42/45] msix: Introduce msix_init_simple Jan Kiszka
2011-10-17 11:22 ` Michael S. Tsirkin [this message]
2011-10-17 11:27 ` Jan Kiszka
2011-10-17 14:28 ` Michael S. Tsirkin
2011-10-17 19:21 ` Jan Kiszka
2011-10-18 10:52 ` Michael S. Tsirkin
2011-10-18 11:02 ` Jan Kiszka
2011-10-17 9:28 ` [Qemu-devel] [RFC][PATCH 43/45] msix: Allow to customize capability on init Jan Kiszka
2011-10-17 9:28 ` [Qemu-devel] [RFC][PATCH 44/45] pci-assign: Use generic MSI-X support Jan Kiszka
2011-10-17 9:28 ` [Qemu-devel] [RFC][PATCH 45/45] pci-assign: Fix coding style issues Jan Kiszka
2011-10-17 12:18 ` [Qemu-devel] [RFC][PATCH 00/45] qemu-kvm: MSI layer rework for in-kernel irqchip support Avi Kivity
2011-10-17 15:57 ` Michael S. Tsirkin
2011-10-17 19:35 ` 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=20111017112217.GC4537@redhat.com \
--to=mst@redhat.com \
--cc=alex.williamson@redhat.com \
--cc=avi@redhat.com \
--cc=jan.kiszka@siemens.com \
--cc=kvm@vger.kernel.org \
--cc=mtosatti@redhat.com \
--cc=qemu-devel@nongnu.org \
/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).