From: Andre Przywara <andre.przywara@arm.com>
To: Alexandru Elisei <alexandru.elisei@arm.com>
Cc: kvm@vger.kernel.org, will@kernel.org,
julien.thierry.kdev@gmail.com, sami.mujawar@arm.com,
lorenzo.pieralisi@arm.com, maz@kernel.org
Subject: Re: [PATCH v2 kvmtool 21/30] virtio/pci: Get emulated region address from BARs
Date: Wed, 5 Feb 2020 17:01:03 +0000 [thread overview]
Message-ID: <20200205170103.6411c606@donnerap.cambridge.arm.com> (raw)
In-Reply-To: <20200123134805.1993-22-alexandru.elisei@arm.com>
On Thu, 23 Jan 2020 13:47:56 +0000
Alexandru Elisei <alexandru.elisei@arm.com> wrote:
> The struct virtio_pci fields port_addr, mmio_addr and msix_io_block
> represent the same addresses that are written in the corresponding BARs.
> Remove this duplication of information and always use the address from the
> BAR. This will make our life a lot easier when we add support for
> reassignable BARs, because we won't have to update the fields on each BAR
> change.
>
> No functional changes.
>
> Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com>
Reviewed-by: Andre Przywara <andre.przywara@arm.com>
Cheers,
Andre
> ---
> include/kvm/virtio-pci.h | 3 --
> virtio/pci.c | 86 ++++++++++++++++++++++++++--------------
> 2 files changed, 56 insertions(+), 33 deletions(-)
>
> diff --git a/include/kvm/virtio-pci.h b/include/kvm/virtio-pci.h
> index 278a25950d8b..959b4b81c871 100644
> --- a/include/kvm/virtio-pci.h
> +++ b/include/kvm/virtio-pci.h
> @@ -24,8 +24,6 @@ struct virtio_pci {
> void *dev;
> struct kvm *kvm;
>
> - u16 port_addr;
> - u32 mmio_addr;
> u8 status;
> u8 isr;
> u32 features;
> @@ -43,7 +41,6 @@ struct virtio_pci {
> u32 config_gsi;
> u32 vq_vector[VIRTIO_PCI_MAX_VQ];
> u32 gsis[VIRTIO_PCI_MAX_VQ];
> - u32 msix_io_block;
> u64 msix_pba;
> struct msix_table msix_table[VIRTIO_PCI_MAX_VQ + VIRTIO_PCI_MAX_CONFIG];
>
> diff --git a/virtio/pci.c b/virtio/pci.c
> index 6723a1f3a84d..c4822514856c 100644
> --- a/virtio/pci.c
> +++ b/virtio/pci.c
> @@ -13,6 +13,21 @@
> #include <linux/byteorder.h>
> #include <string.h>
>
> +static u16 virtio_pci__port_addr(struct virtio_pci *vpci)
> +{
> + return pci__bar_address(&vpci->pci_hdr, 0);
> +}
> +
> +static u32 virtio_pci__mmio_addr(struct virtio_pci *vpci)
> +{
> + return pci__bar_address(&vpci->pci_hdr, 1);
> +}
> +
> +static u32 virtio_pci__msix_io_addr(struct virtio_pci *vpci)
> +{
> + return pci__bar_address(&vpci->pci_hdr, 2);
> +}
> +
> static void virtio_pci__ioevent_callback(struct kvm *kvm, void *param)
> {
> struct virtio_pci_ioevent_param *ioeventfd = param;
> @@ -25,6 +40,8 @@ static int virtio_pci__init_ioeventfd(struct kvm *kvm, struct virtio_device *vde
> {
> struct ioevent ioevent;
> struct virtio_pci *vpci = vdev->virtio;
> + u32 mmio_addr = virtio_pci__mmio_addr(vpci);
> + u16 port_addr = virtio_pci__port_addr(vpci);
> int r, flags = 0;
> int fd;
>
> @@ -48,7 +65,7 @@ static int virtio_pci__init_ioeventfd(struct kvm *kvm, struct virtio_device *vde
> flags |= IOEVENTFD_FLAG_USER_POLL;
>
> /* ioport */
> - ioevent.io_addr = vpci->port_addr + VIRTIO_PCI_QUEUE_NOTIFY;
> + ioevent.io_addr = port_addr + VIRTIO_PCI_QUEUE_NOTIFY;
> ioevent.io_len = sizeof(u16);
> ioevent.fd = fd = eventfd(0, 0);
> r = ioeventfd__add_event(&ioevent, flags | IOEVENTFD_FLAG_PIO);
> @@ -56,7 +73,7 @@ static int virtio_pci__init_ioeventfd(struct kvm *kvm, struct virtio_device *vde
> return r;
>
> /* mmio */
> - ioevent.io_addr = vpci->mmio_addr + VIRTIO_PCI_QUEUE_NOTIFY;
> + ioevent.io_addr = mmio_addr + VIRTIO_PCI_QUEUE_NOTIFY;
> ioevent.io_len = sizeof(u16);
> ioevent.fd = eventfd(0, 0);
> r = ioeventfd__add_event(&ioevent, flags);
> @@ -68,7 +85,7 @@ static int virtio_pci__init_ioeventfd(struct kvm *kvm, struct virtio_device *vde
> return 0;
>
> free_ioport_evt:
> - ioeventfd__del_event(vpci->port_addr + VIRTIO_PCI_QUEUE_NOTIFY, vq);
> + ioeventfd__del_event(port_addr + VIRTIO_PCI_QUEUE_NOTIFY, vq);
> return r;
> }
>
> @@ -76,9 +93,11 @@ static void virtio_pci_exit_vq(struct kvm *kvm, struct virtio_device *vdev,
> int vq)
> {
> struct virtio_pci *vpci = vdev->virtio;
> + u32 mmio_addr = virtio_pci__mmio_addr(vpci);
> + u16 port_addr = virtio_pci__port_addr(vpci);
>
> - ioeventfd__del_event(vpci->mmio_addr + VIRTIO_PCI_QUEUE_NOTIFY, vq);
> - ioeventfd__del_event(vpci->port_addr + VIRTIO_PCI_QUEUE_NOTIFY, vq);
> + ioeventfd__del_event(mmio_addr + VIRTIO_PCI_QUEUE_NOTIFY, vq);
> + ioeventfd__del_event(port_addr + VIRTIO_PCI_QUEUE_NOTIFY, vq);
> virtio_exit_vq(kvm, vdev, vpci->dev, vq);
> }
>
> @@ -163,10 +182,12 @@ static bool virtio_pci__io_in(struct ioport *ioport, struct kvm_cpu *vcpu, u16 p
> unsigned long offset;
> struct virtio_device *vdev;
> struct virtio_pci *vpci;
> + u16 port_addr;
>
> vdev = ioport->priv;
> vpci = vdev->virtio;
> - offset = port - vpci->port_addr;
> + port_addr = virtio_pci__port_addr(vpci);
> + offset = port - port_addr;
>
> return virtio_pci__data_in(vcpu, vdev, offset, data, size);
> }
> @@ -323,10 +344,12 @@ static bool virtio_pci__io_out(struct ioport *ioport, struct kvm_cpu *vcpu, u16
> unsigned long offset;
> struct virtio_device *vdev;
> struct virtio_pci *vpci;
> + u16 port_addr;
>
> vdev = ioport->priv;
> vpci = vdev->virtio;
> - offset = port - vpci->port_addr;
> + port_addr = virtio_pci__port_addr(vpci);
> + offset = port - port_addr;
>
> return virtio_pci__data_out(vcpu, vdev, offset, data, size);
> }
> @@ -343,17 +366,18 @@ static void virtio_pci__msix_mmio_callback(struct kvm_cpu *vcpu,
> struct virtio_device *vdev = ptr;
> struct virtio_pci *vpci = vdev->virtio;
> struct msix_table *table;
> + u32 msix_io_addr = virtio_pci__msix_io_addr(vpci);
> int vecnum;
> size_t offset;
>
> - if (addr > vpci->msix_io_block + PCI_IO_SIZE) {
> + if (addr > msix_io_addr + PCI_IO_SIZE) {
> if (is_write)
> return;
> table = (struct msix_table *)&vpci->msix_pba;
> - offset = addr - (vpci->msix_io_block + PCI_IO_SIZE);
> + offset = addr - (msix_io_addr + PCI_IO_SIZE);
> } else {
> table = vpci->msix_table;
> - offset = addr - vpci->msix_io_block;
> + offset = addr - msix_io_addr;
> }
> vecnum = offset / sizeof(struct msix_table);
> offset = offset % sizeof(struct msix_table);
> @@ -442,19 +466,20 @@ static void virtio_pci__io_mmio_callback(struct kvm_cpu *vcpu,
> {
> struct virtio_device *vdev = ptr;
> struct virtio_pci *vpci = vdev->virtio;
> + u32 mmio_addr = virtio_pci__mmio_addr(vpci);
>
> if (!is_write)
> - virtio_pci__data_in(vcpu, vdev, addr - vpci->mmio_addr,
> - data, len);
> + virtio_pci__data_in(vcpu, vdev, addr - mmio_addr, data, len);
> else
> - virtio_pci__data_out(vcpu, vdev, addr - vpci->mmio_addr,
> - data, len);
> + virtio_pci__data_out(vcpu, vdev, addr - mmio_addr, data, len);
> }
>
> int virtio_pci__init(struct kvm *kvm, void *dev, struct virtio_device *vdev,
> int device_id, int subsys_id, int class)
> {
> struct virtio_pci *vpci = vdev->virtio;
> + u32 mmio_addr, msix_io_block;
> + u16 port_addr;
> int r;
>
> vpci->kvm = kvm;
> @@ -462,20 +487,21 @@ int virtio_pci__init(struct kvm *kvm, void *dev, struct virtio_device *vdev,
>
> BUILD_BUG_ON(!is_power_of_two(PCI_IO_SIZE));
>
> - r = pci_get_io_port_block(PCI_IO_SIZE);
> - r = ioport__register(kvm, r, &virtio_pci__io_ops, PCI_IO_SIZE, vdev);
> + port_addr = pci_get_io_port_block(PCI_IO_SIZE);
> + r = ioport__register(kvm, port_addr, &virtio_pci__io_ops, PCI_IO_SIZE,
> + vdev);
> if (r < 0)
> return r;
> - vpci->port_addr = (u16)r;
> + port_addr = (u16)r;
>
> - vpci->mmio_addr = pci_get_mmio_block(PCI_IO_SIZE);
> - r = kvm__register_mmio(kvm, vpci->mmio_addr, PCI_IO_SIZE, false,
> + mmio_addr = pci_get_mmio_block(PCI_IO_SIZE);
> + r = kvm__register_mmio(kvm, mmio_addr, PCI_IO_SIZE, false,
> virtio_pci__io_mmio_callback, vdev);
> if (r < 0)
> goto free_ioport;
>
> - vpci->msix_io_block = pci_get_mmio_block(PCI_IO_SIZE * 2);
> - r = kvm__register_mmio(kvm, vpci->msix_io_block, PCI_IO_SIZE * 2, false,
> + msix_io_block = pci_get_mmio_block(PCI_IO_SIZE * 2);
> + r = kvm__register_mmio(kvm, msix_io_block, PCI_IO_SIZE * 2, false,
> virtio_pci__msix_mmio_callback, vdev);
> if (r < 0)
> goto free_mmio;
> @@ -491,11 +517,11 @@ int virtio_pci__init(struct kvm *kvm, void *dev, struct virtio_device *vdev,
> .class[2] = (class >> 16) & 0xff,
> .subsys_vendor_id = cpu_to_le16(PCI_SUBSYSTEM_VENDOR_ID_REDHAT_QUMRANET),
> .subsys_id = cpu_to_le16(subsys_id),
> - .bar[0] = cpu_to_le32(vpci->port_addr
> + .bar[0] = cpu_to_le32(port_addr
> | PCI_BASE_ADDRESS_SPACE_IO),
> - .bar[1] = cpu_to_le32(vpci->mmio_addr
> + .bar[1] = cpu_to_le32(mmio_addr
> | PCI_BASE_ADDRESS_SPACE_MEMORY),
> - .bar[2] = cpu_to_le32(vpci->msix_io_block
> + .bar[2] = cpu_to_le32(msix_io_block
> | PCI_BASE_ADDRESS_SPACE_MEMORY),
> .status = cpu_to_le16(PCI_STATUS_CAP_LIST),
> .capabilities = (void *)&vpci->pci_hdr.msix - (void *)&vpci->pci_hdr,
> @@ -542,11 +568,11 @@ int virtio_pci__init(struct kvm *kvm, void *dev, struct virtio_device *vdev,
> return 0;
>
> free_msix_mmio:
> - kvm__deregister_mmio(kvm, vpci->msix_io_block);
> + kvm__deregister_mmio(kvm, msix_io_block);
> free_mmio:
> - kvm__deregister_mmio(kvm, vpci->mmio_addr);
> + kvm__deregister_mmio(kvm, mmio_addr);
> free_ioport:
> - ioport__unregister(kvm, vpci->port_addr);
> + ioport__unregister(kvm, port_addr);
> return r;
> }
>
> @@ -566,9 +592,9 @@ int virtio_pci__exit(struct kvm *kvm, struct virtio_device *vdev)
> struct virtio_pci *vpci = vdev->virtio;
>
> virtio_pci__reset(kvm, vdev);
> - kvm__deregister_mmio(kvm, vpci->mmio_addr);
> - kvm__deregister_mmio(kvm, vpci->msix_io_block);
> - ioport__unregister(kvm, vpci->port_addr);
> + kvm__deregister_mmio(kvm, virtio_pci__mmio_addr(vpci));
> + kvm__deregister_mmio(kvm, virtio_pci__msix_io_addr(vpci));
> + ioport__unregister(kvm, virtio_pci__port_addr(vpci));
>
> return 0;
> }
next prev parent reply other threads:[~2020-02-05 17:01 UTC|newest]
Thread overview: 88+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-23 13:47 [PATCH v2 kvmtool 00/30] Add reassignable BARs and PCIE 1.1 support Alexandru Elisei
2020-01-23 13:47 ` [PATCH v2 kvmtool 01/30] Makefile: Use correct objcopy binary when cross-compiling for x86_64 Alexandru Elisei
2020-01-23 13:47 ` [PATCH v2 kvmtool 02/30] hw/i8042: Compile only for x86 Alexandru Elisei
2020-01-27 18:07 ` Andre Przywara
2020-01-23 13:47 ` [PATCH v2 kvmtool 03/30] pci: Fix BAR resource sizing arbitration Alexandru Elisei
2020-01-27 18:07 ` Andre Przywara
2020-01-23 13:47 ` [PATCH v2 kvmtool 04/30] Remove pci-shmem device Alexandru Elisei
2020-01-23 13:47 ` [PATCH v2 kvmtool 05/30] Check that a PCI device's memory size is power of two Alexandru Elisei
2020-01-27 18:07 ` Andre Przywara
2020-01-23 13:47 ` [PATCH v2 kvmtool 06/30] arm/pci: Advertise only PCI bus 0 in the DT Alexandru Elisei
2020-01-27 18:08 ` Andre Przywara
2020-01-23 13:47 ` [PATCH v2 kvmtool 07/30] ioport: pci: Move port allocations to PCI devices Alexandru Elisei
2020-02-07 17:02 ` Andre Przywara
2020-01-23 13:47 ` [PATCH v2 kvmtool 08/30] pci: Fix ioport allocation size Alexandru Elisei
2020-01-23 13:47 ` [PATCH v2 kvmtool 09/30] arm/pci: Fix PCI IO region Alexandru Elisei
2020-01-29 18:16 ` Andre Przywara
2020-03-04 16:20 ` Alexandru Elisei
2020-03-05 13:06 ` Alexandru Elisei
2020-01-23 13:47 ` [PATCH v2 kvmtool 10/30] virtio/pci: Make memory and IO BARs independent Alexandru Elisei
2020-01-29 18:16 ` Andre Przywara
2020-03-05 15:41 ` Alexandru Elisei
2020-01-23 13:47 ` [PATCH v2 kvmtool 11/30] vfio/pci: Allocate correct size for MSIX table and PBA BARs Alexandru Elisei
2020-01-29 18:16 ` Andre Przywara
2020-01-23 13:47 ` [PATCH v2 kvmtool 12/30] vfio/pci: Don't assume that only even numbered BARs are 64bit Alexandru Elisei
2020-01-30 14:50 ` Andre Przywara
2020-01-23 13:47 ` [PATCH v2 kvmtool 13/30] vfio/pci: Ignore expansion ROM BAR writes Alexandru Elisei
2020-01-30 14:50 ` Andre Przywara
2020-01-30 15:52 ` Alexandru Elisei
2020-01-23 13:47 ` [PATCH v2 kvmtool 14/30] vfio/pci: Don't access potentially unallocated regions Alexandru Elisei
2020-01-29 18:17 ` Andre Przywara
2020-03-06 10:54 ` Alexandru Elisei
2020-01-23 13:47 ` [PATCH v2 kvmtool 15/30] virtio: Don't ignore initialization failures Alexandru Elisei
2020-01-30 14:51 ` Andre Przywara
2020-03-06 11:20 ` Alexandru Elisei
2020-03-30 9:27 ` André Przywara
2020-01-23 13:47 ` [PATCH v2 kvmtool 16/30] Don't ignore errors registering a device, ioport or mmio emulation Alexandru Elisei
2020-01-30 14:51 ` Andre Przywara
2020-03-06 11:28 ` Alexandru Elisei
2020-01-23 13:47 ` [PATCH v2 kvmtool 17/30] hw/vesa: Don't ignore fatal errors Alexandru Elisei
2020-01-30 14:52 ` Andre Przywara
2020-03-06 12:33 ` Alexandru Elisei
2020-01-23 13:47 ` [PATCH v2 kvmtool 18/30] hw/vesa: Set the size for BAR 0 Alexandru Elisei
2020-02-03 12:20 ` Andre Przywara
2020-02-03 12:27 ` Alexandru Elisei
2020-02-05 17:00 ` Andre Przywara
2020-03-06 12:40 ` Alexandru Elisei
2020-01-23 13:47 ` [PATCH v2 kvmtool 19/30] Use independent read/write locks for ioport and mmio Alexandru Elisei
2020-02-03 12:23 ` Andre Przywara
2020-02-05 11:25 ` Alexandru Elisei
2020-01-23 13:47 ` [PATCH v2 kvmtool 20/30] pci: Add helpers for BAR values and memory/IO space access Alexandru Elisei
2020-02-05 17:00 ` Andre Przywara
2020-02-05 17:02 ` Alexandru Elisei
2020-01-23 13:47 ` [PATCH v2 kvmtool 21/30] virtio/pci: Get emulated region address from BARs Alexandru Elisei
2020-02-05 17:01 ` Andre Przywara [this message]
2020-01-23 13:47 ` [PATCH v2 kvmtool 22/30] vfio: Destroy memslot when unmapping the associated VAs Alexandru Elisei
2020-02-05 17:01 ` Andre Przywara
2020-03-09 12:38 ` Alexandru Elisei
2020-01-23 13:47 ` [PATCH v2 kvmtool 23/30] vfio: Reserve ioports when configuring the BAR Alexandru Elisei
2020-02-05 18:34 ` Andre Przywara
2020-01-23 13:47 ` [PATCH v2 kvmtool 24/30] vfio/pci: Don't write configuration value twice Alexandru Elisei
2020-02-05 18:35 ` Andre Przywara
2020-03-09 15:21 ` Alexandru Elisei
2020-01-23 13:48 ` [PATCH v2 kvmtool 25/30] pci: Implement callbacks for toggling BAR emulation Alexandru Elisei
2020-02-06 18:21 ` Andre Przywara
2020-02-07 10:12 ` Alexandru Elisei
2020-02-07 15:39 ` Alexandru Elisei
2020-01-23 13:48 ` [PATCH v2 kvmtool 26/30] pci: Toggle BAR I/O and memory space emulation Alexandru Elisei
2020-02-06 18:21 ` Andre Przywara
2020-02-07 11:08 ` Alexandru Elisei
2020-02-07 11:36 ` Andre Przywara
2020-02-07 11:44 ` Alexandru Elisei
2020-03-09 14:54 ` Alexandru Elisei
2020-01-23 13:48 ` [PATCH v2 kvmtool 27/30] pci: Implement reassignable BARs Alexandru Elisei
2020-02-07 16:50 ` Andre Przywara
2020-03-10 14:17 ` Alexandru Elisei
2020-01-23 13:48 ` [PATCH v2 kvmtool 28/30] arm/fdt: Remove 'linux,pci-probe-only' property Alexandru Elisei
2020-02-07 16:51 ` Andre Przywara
2020-02-07 17:38 ` Andre Przywara
2020-03-10 16:04 ` Alexandru Elisei
2020-01-23 13:48 ` [PATCH v2 kvmtool 29/30] vfio: Trap MMIO access to BAR addresses which aren't page aligned Alexandru Elisei
2020-02-07 16:51 ` Andre Przywara
2020-01-23 13:48 ` [PATCH v2 kvmtool 30/30] arm/arm64: Add PCI Express 1.1 support Alexandru Elisei
2020-02-07 16:51 ` Andre Przywara
2020-03-10 16:28 ` Alexandru Elisei
2020-02-07 17:02 ` [PATCH v2 kvmtool 00/30] Add reassignable BARs and PCIE " Andre Przywara
2020-05-13 14:56 ` Marc Zyngier
2020-05-13 15:15 ` Alexandru Elisei
2020-05-13 16:41 ` Alexandru Elisei
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=20200205170103.6411c606@donnerap.cambridge.arm.com \
--to=andre.przywara@arm.com \
--cc=alexandru.elisei@arm.com \
--cc=julien.thierry.kdev@gmail.com \
--cc=kvm@vger.kernel.org \
--cc=lorenzo.pieralisi@arm.com \
--cc=maz@kernel.org \
--cc=sami.mujawar@arm.com \
--cc=will@kernel.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).