linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Andre Przywara <andre.przywara@arm.com>
To: Alexandru Elisei <alexandru.elisei@arm.com>
Cc: kvm@vger.kernel.org, Marc Zyngier <maz@kernel.org>,
	Julien Thierry <julien.thierry.kdev@gmail.com>,
	Will Deacon <will@kernel.org>,
	kvmarm@lists.cs.columbia.edu,
	linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH kvmtool 17/21] virtio: Switch trap handling to use MMIO handler
Date: Thu, 18 Feb 2021 16:13:49 +0000	[thread overview]
Message-ID: <20210218161349.632897c9@slackpad.fritz.box> (raw)
In-Reply-To: <0c6e033e-4bc4-bc81-173f-c7c195ded78a@arm.com>

On Tue, 16 Feb 2021 17:03:04 +0000
Alexandru Elisei <alexandru.elisei@arm.com> wrote:

> Hi Andre,
> 
> Nitpick below, otherwise looks good.
> 
> On 12/10/20 2:29 PM, Andre Przywara wrote:
> > With the planned retirement of the special ioport emulation code, we
> > need to provide an emulation function compatible with the MMIO prototype.
> >
> > Adjust the existing MMIO callback routine to automatically determine
> > the region this trap came through, and call the existing I/O handlers.
> > Register the ioport region using the new registration function.
> >
> > Signed-off-by: Andre Przywara <andre.przywara@arm.com>
> > ---
> >  virtio/pci.c | 42 ++++++++++--------------------------------
> >  1 file changed, 10 insertions(+), 32 deletions(-)
> >
> > diff --git a/virtio/pci.c b/virtio/pci.c
> > index 6eea6c68..49d3f4d5 100644
> > --- a/virtio/pci.c
> > +++ b/virtio/pci.c
> > @@ -178,15 +178,6 @@ static bool virtio_pci__data_in(struct kvm_cpu *vcpu, struct virtio_device *vdev
> >  	return ret;
> >  }
> >  
> > -static bool virtio_pci__io_in(struct ioport *ioport, struct kvm_cpu *vcpu, u16 port, void *data, int size)
> > -{
> > -	struct virtio_device *vdev = ioport->priv;
> > -	struct virtio_pci *vpci = vdev->virtio;
> > -	unsigned long offset = port - virtio_pci__port_addr(vpci);
> > -
> > -	return virtio_pci__data_in(vcpu, vdev, offset, data, size);
> > -}
> > -
> >  static void update_msix_map(struct virtio_pci *vpci,
> >  			    struct msix_table *msix_entry, u32 vecnum)
> >  {
> > @@ -334,20 +325,6 @@ static bool virtio_pci__data_out(struct kvm_cpu *vcpu, struct virtio_device *vde
> >  	return ret;
> >  }
> >  
> > -static bool virtio_pci__io_out(struct ioport *ioport, struct kvm_cpu *vcpu, u16 port, void *data, int size)
> > -{
> > -	struct virtio_device *vdev = ioport->priv;
> > -	struct virtio_pci *vpci = vdev->virtio;
> > -	unsigned long offset = port - virtio_pci__port_addr(vpci);
> > -
> > -	return virtio_pci__data_out(vcpu, vdev, offset, data, size);
> > -}
> > -
> > -static struct ioport_operations virtio_pci__io_ops = {
> > -	.io_in	= virtio_pci__io_in,
> > -	.io_out	= virtio_pci__io_out,
> > -};
> > -
> >  static void virtio_pci__msix_mmio_callback(struct kvm_cpu *vcpu,
> >  					   u64 addr, u8 *data, u32 len,
> >  					   u8 is_write, void *ptr)
> > @@ -455,12 +432,15 @@ 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);
> > +	u32 base_addr = virtio_pci__mmio_addr(vpci);
> > +
> > +	if (addr < base_addr || addr >= base_addr + PCI_IO_SIZE)
> > +		base_addr = virtio_pci__port_addr(vpci);  
> 
> There are only two BARs that use this callback, the ioport BAR (BAR0) and the
> memory BAR (BAR1) (MSIX uses a different emulation callback). The condition above
> says that if addr is not inside the region described by the memory BAR, then it's
> an ioport BAR. How about checking explicitly that it is inside the ioport region
> like this (compile tested only), which looks a bit more intuitive for me:

Fair enough.

Cheers,
Andre

> 
> diff --git a/virtio/pci.c b/virtio/pci.c
> index 49d3f4d524b2..4024bcd709cd 100644
> --- a/virtio/pci.c
> +++ b/virtio/pci.c
> @@ -432,10 +432,15 @@ static void virtio_pci__io_mmio_callback(struct kvm_cpu *vcpu,
>  {
>         struct virtio_device *vdev = ptr;
>         struct virtio_pci *vpci = vdev->virtio;
> -       u32 base_addr = virtio_pci__mmio_addr(vpci);
> +       u32 mmio_addr = virtio_pci__mmio_addr(vpci);
> +       u32 ioport_addr = virtio_pci__port_addr(vpci);
> +       u32 base_addr;
>  
> -       if (addr < base_addr || addr >= base_addr + PCI_IO_SIZE)
> -               base_addr = virtio_pci__port_addr(vpci);
> +       if (addr >= ioport_addr &&
> +           addr < ioport_addr + pci__bar_size(&vpci->pci_hdr, 0))
> +               base_addr = ioport_addr;
> +       else
> +               base_addr = mmio_addr;
>  
>         if (!is_write)
>                 virtio_pci__data_in(vcpu, vdev, addr - base_addr, data, len);
> 
> Thanks,
> 
> Alex
> 
> >  
> >  	if (!is_write)
> > -		virtio_pci__data_in(vcpu, vdev, addr - mmio_addr, data, len);
> > +		virtio_pci__data_in(vcpu, vdev, addr - base_addr, data, len);
> >  	else
> > -		virtio_pci__data_out(vcpu, vdev, addr - mmio_addr, data, len);
> > +		virtio_pci__data_out(vcpu, vdev, addr - base_addr, data, len);
> >  }
> >  
> >  static int virtio_pci__bar_activate(struct kvm *kvm,
> > @@ -478,10 +458,8 @@ static int virtio_pci__bar_activate(struct kvm *kvm,
> >  
> >  	switch (bar_num) {
> >  	case 0:
> > -		r = ioport__register(kvm, bar_addr, &virtio_pci__io_ops,
> > -				     bar_size, vdev);
> > -		if (r > 0)
> > -			r = 0;
> > +		r = kvm__register_pio(kvm, bar_addr, bar_size,
> > +				      virtio_pci__io_mmio_callback, vdev);
> >  		break;
> >  	case 1:
> >  		r =  kvm__register_mmio(kvm, bar_addr, bar_size, false,
> > @@ -510,7 +488,7 @@ static int virtio_pci__bar_deactivate(struct kvm *kvm,
> >  
> >  	switch (bar_num) {
> >  	case 0:
> > -		r = ioport__unregister(kvm, bar_addr);
> > +		r = kvm__deregister_pio(kvm, bar_addr);
> >  		break;
> >  	case 1:
> >  	case 2:
> > @@ -625,7 +603,7 @@ int virtio_pci__exit(struct kvm *kvm, struct virtio_device *vdev)
> >  	virtio_pci__reset(kvm, vdev);
> >  	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));
> > +	kvm__deregister_pio(kvm, virtio_pci__port_addr(vpci));
> >  
> >  	return 0;
> >  }  


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2021-02-18 16:17 UTC|newest]

Thread overview: 72+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-10 14:28 [PATCH kvmtool 00/21] Unify I/O port and MMIO trap handling Andre Przywara
2020-12-10 14:28 ` [PATCH kvmtool 01/21] ioport: Remove ioport__setup_arch() Andre Przywara
2021-02-10 17:44   ` Alexandru Elisei
2021-02-11 17:16     ` Andre Przywara
2021-02-11 17:32       ` Alexandru Elisei
2021-02-17 16:46         ` Andre Przywara
2021-02-22 10:23           ` Andre Przywara
2021-02-22 15:01             ` Alexandru Elisei
2020-12-10 14:28 ` [PATCH kvmtool 02/21] hw/serial: Use device abstraction for FDT generator function Andre Przywara
2021-02-11 12:05   ` Alexandru Elisei
2021-02-11 17:45     ` Andre Przywara
2020-12-10 14:28 ` [PATCH kvmtool 03/21] ioport: Retire .generate_fdt_node functionality Andre Przywara
2021-02-11 14:05   ` Alexandru Elisei
2021-02-17 15:54     ` Andre Przywara
2021-02-17 16:06       ` Alexandru Elisei
2020-12-10 14:28 ` [PATCH kvmtool 04/21] mmio: Extend handling to include ioport emulation Andre Przywara
2021-02-11 16:10   ` Alexandru Elisei
2021-02-17 17:43     ` Andre Przywara
2021-02-22 15:50       ` Alexandru Elisei
2020-12-10 14:28 ` [PATCH kvmtool 05/21] hw/i8042: Clean up data types Andre Przywara
2021-02-11 16:55   ` Alexandru Elisei
2021-02-17 17:46     ` Andre Przywara
2020-12-10 14:28 ` [PATCH kvmtool 06/21] hw/i8042: Refactor trap handler Andre Przywara
2021-02-11 17:23   ` Alexandru Elisei
2021-02-18 10:34     ` Andre Przywara
2021-02-18 11:17       ` Alexandru Elisei
2021-02-18 11:48         ` Andre Przywara
2021-02-22 16:03           ` Alexandru Elisei
2020-12-10 14:28 ` [PATCH kvmtool 07/21] hw/i8042: Switch to new trap handlers Andre Przywara
2021-02-12 10:41   ` Alexandru Elisei
2021-02-18 12:09     ` Andre Przywara
2021-02-22 16:19       ` Alexandru Elisei
2020-12-10 14:28 ` [PATCH kvmtool 08/21] x86/ioport: Refactor " Andre Przywara
2021-02-12 11:14   ` Alexandru Elisei
2020-12-10 14:28 ` [PATCH kvmtool 09/21] x86/ioport: Switch to new " Andre Przywara
2021-02-12 11:27   ` Alexandru Elisei
2021-02-18 14:05     ` Andre Przywara
2020-12-10 14:28 ` [PATCH kvmtool 10/21] hw/rtc: Refactor " Andre Przywara
2021-02-12 11:56   ` Alexandru Elisei
2020-12-10 14:28 ` [PATCH kvmtool 11/21] hw/rtc: Switch to new trap handler Andre Przywara
2021-02-12 12:02   ` Alexandru Elisei
2020-12-10 14:28 ` [PATCH kvmtool 12/21] hw/vesa: Switch trap handling to use MMIO handler Andre Przywara
2021-02-12 17:50   ` Alexandru Elisei
2020-12-10 14:29 ` [PATCH kvmtool 13/21] hw/serial: Refactor trap handler Andre Przywara
2021-02-16 14:22   ` Alexandru Elisei
2021-02-18 14:41     ` Andre Przywara
2021-02-22 17:40       ` Alexandru Elisei
2021-02-24 14:54         ` Andre Przywara
2020-12-10 14:29 ` [PATCH kvmtool 14/21] hw/serial: Switch to new trap handlers Andre Przywara
2021-02-16 14:31   ` Alexandru Elisei
2020-12-10 14:29 ` [PATCH kvmtool 15/21] vfio: Refactor ioport trap handler Andre Przywara
2021-02-16 14:47   ` Alexandru Elisei
2021-02-18 15:51     ` Andre Przywara
2020-12-10 14:29 ` [PATCH kvmtool 16/21] vfio: Switch to new ioport trap handlers Andre Przywara
2021-02-16 14:52   ` Alexandru Elisei
2020-12-10 14:29 ` [PATCH kvmtool 17/21] virtio: Switch trap handling to use MMIO handler Andre Przywara
2021-02-16 17:03   ` Alexandru Elisei
2021-02-18 16:13     ` Andre Przywara [this message]
2020-12-10 14:29 ` [PATCH kvmtool 18/21] pci: " Andre Przywara
2021-02-17 15:14   ` Alexandru Elisei
2020-12-10 14:29 ` [PATCH kvmtool 19/21] Remove ioport specific routines Andre Przywara
2021-02-17 15:49   ` Alexandru Elisei
2021-02-17 16:11     ` Alexandru Elisei
2021-02-18 16:34       ` Andre Przywara
2020-12-10 14:29 ` [PATCH kvmtool 20/21] hw/serial: ARM/arm64: Use MMIO at higher addresses Andre Przywara
2021-02-17 16:48   ` Alexandru Elisei
2021-02-18 12:18     ` Alexandru Elisei
2021-02-18 16:38       ` Andre Przywara
2020-12-10 14:29 ` [PATCH kvmtool 21/21] hw/rtc: " Andre Przywara
2021-02-18 13:33   ` Alexandru Elisei
2021-02-18 16:41     ` Andre Przywara
2021-02-10 17:44 ` [PATCH kvmtool 00/21] Unify I/O port and MMIO trap handling 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=20210218161349.632897c9@slackpad.fritz.box \
    --to=andre.przywara@arm.com \
    --cc=alexandru.elisei@arm.com \
    --cc=julien.thierry.kdev@gmail.com \
    --cc=kvm@vger.kernel.org \
    --cc=kvmarm@lists.cs.columbia.edu \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=maz@kernel.org \
    --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).