[PATCH 1/2] hw/pci/msix: Warn on PBA writes

Nicholas Piggin posted 2 patches 2 weeks, 4 days ago
[PATCH 1/2] hw/pci/msix: Warn on PBA writes
Posted by Nicholas Piggin 2 weeks, 4 days ago
Of the MSI-X PBA pending bits, the PCI Local Bus Specification says:

  Software should never write, and should only read
  Pending Bits. If software writes to Pending Bits, the
  result is undefined.

Log a GUEST_ERROR message if the PBA is written to by software.

Cc: Michael S. Tsirkin <mst@redhat.com>
Cc: Marcel Apfelbaum <marcel.apfelbaum@gmail.com>
Cc: Dmitry Fleytman <dmitry.fleytman@gmail.com>
Cc: Akihiko Odaki <akihiko.odaki@daynix.com>
Cc: Sriram Yagnaraman <sriram.yagnaraman@ericsson.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
 hw/pci/msix.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/hw/pci/msix.c b/hw/pci/msix.c
index 57ec7084a47..66f27b9d712 100644
--- a/hw/pci/msix.c
+++ b/hw/pci/msix.c
@@ -15,6 +15,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/log.h"
 #include "hw/pci/msi.h"
 #include "hw/pci/msix.h"
 #include "hw/pci/pci.h"
@@ -260,6 +261,14 @@ static uint64_t msix_pba_mmio_read(void *opaque, hwaddr addr,
 static void msix_pba_mmio_write(void *opaque, hwaddr addr,
                                 uint64_t val, unsigned size)
 {
+    PCIDevice *dev = opaque;
+
+    qemu_log_mask(LOG_GUEST_ERROR,
+                  "PCI [%s:%02x:%02x.%x] attempt to write to MSI-X "
+                  "PBA at 0x%" FMT_PCIBUS ", ignoring.\n",
+                  pci_root_bus_path(dev), pci_dev_bus_num(dev),
+                  PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn),
+                  addr);
 }
 
 static const MemoryRegionOps msix_pba_mmio_ops = {
-- 
2.45.2
Re: [PATCH 1/2] hw/pci/msix: Warn on PBA writes
Posted by Philippe Mathieu-Daudé 2 weeks ago
On 17/1/25 18:28, Nicholas Piggin wrote:
> Of the MSI-X PBA pending bits, the PCI Local Bus Specification says:
> 
>    Software should never write, and should only read
>    Pending Bits. If software writes to Pending Bits, the
>    result is undefined.
> 
> Log a GUEST_ERROR message if the PBA is written to by software.
> 
> Cc: Michael S. Tsirkin <mst@redhat.com>
> Cc: Marcel Apfelbaum <marcel.apfelbaum@gmail.com>
> Cc: Dmitry Fleytman <dmitry.fleytman@gmail.com>
> Cc: Akihiko Odaki <akihiko.odaki@daynix.com>
> Cc: Sriram Yagnaraman <sriram.yagnaraman@ericsson.com>
> Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
> ---
>   hw/pci/msix.c | 9 +++++++++
>   1 file changed, 9 insertions(+)

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>


Re: [PATCH 1/2] hw/pci/msix: Warn on PBA writes
Posted by Phil Dennis-Jordan 2 weeks, 3 days ago
On Fri, 17 Jan 2025 at 18:29, Nicholas Piggin <npiggin@gmail.com> wrote:

> Of the MSI-X PBA pending bits, the PCI Local Bus Specification says:
>
>   Software should never write, and should only read
>   Pending Bits. If software writes to Pending Bits, the
>   result is undefined.
>
> Log a GUEST_ERROR message if the PBA is written to by software.
>
> Cc: Michael S. Tsirkin <mst@redhat.com>
> Cc: Marcel Apfelbaum <marcel.apfelbaum@gmail.com>
> Cc: Dmitry Fleytman <dmitry.fleytman@gmail.com>
> Cc: Akihiko Odaki <akihiko.odaki@daynix.com>
> Cc: Sriram Yagnaraman <sriram.yagnaraman@ericsson.com>
> Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
>

Reviewed-by: Phil Dennis-Jordan <phil@philjordan.eu>


> ---
>  hw/pci/msix.c | 9 +++++++++
>  1 file changed, 9 insertions(+)
>
> diff --git a/hw/pci/msix.c b/hw/pci/msix.c
> index 57ec7084a47..66f27b9d712 100644
> --- a/hw/pci/msix.c
> +++ b/hw/pci/msix.c
> @@ -15,6 +15,7 @@
>   */
>
>  #include "qemu/osdep.h"
> +#include "qemu/log.h"
>  #include "hw/pci/msi.h"
>  #include "hw/pci/msix.h"
>  #include "hw/pci/pci.h"
> @@ -260,6 +261,14 @@ static uint64_t msix_pba_mmio_read(void *opaque,
> hwaddr addr,
>  static void msix_pba_mmio_write(void *opaque, hwaddr addr,
>                                  uint64_t val, unsigned size)
>  {
> +    PCIDevice *dev = opaque;
> +
> +    qemu_log_mask(LOG_GUEST_ERROR,
> +                  "PCI [%s:%02x:%02x.%x] attempt to write to MSI-X "
> +                  "PBA at 0x%" FMT_PCIBUS ", ignoring.\n",
> +                  pci_root_bus_path(dev), pci_dev_bus_num(dev),
> +                  PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn),
> +                  addr);
>  }
>
>  static const MemoryRegionOps msix_pba_mmio_ops = {
> --
> 2.45.2
>
>
>
Re: [PATCH 1/2] hw/pci/msix: Warn on PBA writes
Posted by Akihiko Odaki 2 weeks, 4 days ago
On 2025/01/18 2:28, Nicholas Piggin wrote:
> Of the MSI-X PBA pending bits, the PCI Local Bus Specification says:
> 
>    Software should never write, and should only read
>    Pending Bits. If software writes to Pending Bits, the
>    result is undefined.
> 
> Log a GUEST_ERROR message if the PBA is written to by software.
> 
> Cc: Michael S. Tsirkin <mst@redhat.com>
> Cc: Marcel Apfelbaum <marcel.apfelbaum@gmail.com>
> Cc: Dmitry Fleytman <dmitry.fleytman@gmail.com>
> Cc: Akihiko Odaki <akihiko.odaki@daynix.com>
> Cc: Sriram Yagnaraman <sriram.yagnaraman@ericsson.com>
> Signed-off-by: Nicholas Piggin <npiggin@gmail.com>

Reviewed-by: Akihiko Odaki <akihiko.odaki@daynix.com>