diff mbox series

[v2,kvmtool,23/30] vfio: Reserve ioports when configuring the BAR

Message ID 20200123134805.1993-24-alexandru.elisei@arm.com (mailing list archive)
State New, archived
Headers show
Series Add reassignable BARs and PCIE 1.1 support | expand

Commit Message

Alexandru Elisei Jan. 23, 2020, 1:47 p.m. UTC
Let's be consistent and reserve ioports when we are configuring the BAR,
not when we map it, just like we do with mmio regions.

Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com>
---
 vfio/core.c | 9 +++------
 vfio/pci.c  | 4 +++-
 2 files changed, 6 insertions(+), 7 deletions(-)

Comments

Andre Przywara Feb. 5, 2020, 6:34 p.m. UTC | #1
On Thu, 23 Jan 2020 13:47:58 +0000
Alexandru Elisei <alexandru.elisei@arm.com> wrote:

Hi,

> Let's be consistent and reserve ioports when we are configuring the BAR,
> not when we map it, just like we do with mmio regions.
> 
> Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com>

Reviewed-by: Andre Przywara <andre.przywara@arm.com>

Thanks,
Andre

> ---
>  vfio/core.c | 9 +++------
>  vfio/pci.c  | 4 +++-
>  2 files changed, 6 insertions(+), 7 deletions(-)
> 
> diff --git a/vfio/core.c b/vfio/core.c
> index 73fdac8be675..6b9b58ea8d2f 100644
> --- a/vfio/core.c
> +++ b/vfio/core.c
> @@ -202,14 +202,11 @@ static int vfio_setup_trap_region(struct kvm *kvm, struct vfio_device *vdev,
>  				  struct vfio_region *region)
>  {
>  	if (region->is_ioport) {
> -		int port = pci_get_io_port_block(region->info.size);
> -
> -		port = ioport__register(kvm, port, &vfio_ioport_ops,
> -					region->info.size, region);
> +		int port = ioport__register(kvm, region->port_base,
> +					   &vfio_ioport_ops, region->info.size,
> +					   region);
>  		if (port < 0)
>  			return port;
> -
> -		region->port_base = port;
>  		return 0;
>  	}
>  
> diff --git a/vfio/pci.c b/vfio/pci.c
> index f86a7d9b7032..abde16dc8693 100644
> --- a/vfio/pci.c
> +++ b/vfio/pci.c
> @@ -885,7 +885,9 @@ static int vfio_pci_configure_bar(struct kvm *kvm, struct vfio_device *vdev,
>  		}
>  	}
>  
> -	if (!region->is_ioport) {
> +	if (region->is_ioport) {
> +		region->port_base = pci_get_io_port_block(region->info.size);
> +	} else {
>  		/* Grab some MMIO space in the guest */
>  		map_size = ALIGN(region->info.size, PAGE_SIZE);
>  		region->guest_phys_addr = pci_get_mmio_block(map_size);
diff mbox series

Patch

diff --git a/vfio/core.c b/vfio/core.c
index 73fdac8be675..6b9b58ea8d2f 100644
--- a/vfio/core.c
+++ b/vfio/core.c
@@ -202,14 +202,11 @@  static int vfio_setup_trap_region(struct kvm *kvm, struct vfio_device *vdev,
 				  struct vfio_region *region)
 {
 	if (region->is_ioport) {
-		int port = pci_get_io_port_block(region->info.size);
-
-		port = ioport__register(kvm, port, &vfio_ioport_ops,
-					region->info.size, region);
+		int port = ioport__register(kvm, region->port_base,
+					   &vfio_ioport_ops, region->info.size,
+					   region);
 		if (port < 0)
 			return port;
-
-		region->port_base = port;
 		return 0;
 	}
 
diff --git a/vfio/pci.c b/vfio/pci.c
index f86a7d9b7032..abde16dc8693 100644
--- a/vfio/pci.c
+++ b/vfio/pci.c
@@ -885,7 +885,9 @@  static int vfio_pci_configure_bar(struct kvm *kvm, struct vfio_device *vdev,
 		}
 	}
 
-	if (!region->is_ioport) {
+	if (region->is_ioport) {
+		region->port_base = pci_get_io_port_block(region->info.size);
+	} else {
 		/* Grab some MMIO space in the guest */
 		map_size = ALIGN(region->info.size, PAGE_SIZE);
 		region->guest_phys_addr = pci_get_mmio_block(map_size);