All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 1/3] x86/msi: passthrough all MSI-X vector ctrl writes to device model
@ 2023-03-25  2:49 Marek Marczykowski-Górecki
  2023-03-25  2:49 ` [PATCH v2 2/3] x86/hvm: Allow writes to registers on the same page as MSI-X table Marek Marczykowski-Górecki
                   ` (2 more replies)
  0 siblings, 3 replies; 37+ messages in thread
From: Marek Marczykowski-Górecki @ 2023-03-25  2:49 UTC (permalink / raw)
  To: xen-devel
  Cc: Jason Andryuk, Marek Marczykowski-Górecki, Jan Beulich,
	Andrew Cooper, Roger Pau Monné, Wei Liu

QEMU needs to know whether clearing maskbit of a vector is really
clearing, or was already cleared before. Currently Xen sends only
clearing that bit to the device model, but not setting it, so QEMU
cannot detect it. Because of that, QEMU is working this around by
checking via /dev/mem, but that isn't the proper approach.

Give all necessary information to QEMU by passing all ctrl writes,
including masking a vector. This does include forwarding also writes
that did not change the value, but as tested on both Linux (6.1.12) and
Windows (10 pro), they don't do excessive writes of unchanged values
(Windows seems to clear maskbit in some cases twice, but not more).

Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
---
v2:
 - passthrough quad writes to emulator too (Jan)
 - (ab)use len==0 for write len=4 completion (Jan), but add descriptive
   #define for this magic value

This behavior change needs to be surfaced to the device model somehow,
so it knows whether it can rely on it. I'm open for suggestions.
---
 xen/arch/x86/hvm/vmsi.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/xen/arch/x86/hvm/vmsi.c b/xen/arch/x86/hvm/vmsi.c
index 3cd4923060c8..9c82bf9b4ec2 100644
--- a/xen/arch/x86/hvm/vmsi.c
+++ b/xen/arch/x86/hvm/vmsi.c
@@ -272,6 +272,15 @@ out:
     return r;
 }
 
+/*
+ * This function returns X86EMUL_UNHANDLEABLE even if write is properly
+ * handled, to propagate it to the device model (so it can keep its internal
+ * state in sync).
+ * len==0 means really len==4, but as a write completion that will return
+ * X86EMUL_OKAY on successful processing. Use WRITE_LEN4_COMPLETION to make it
+ * less confusing.
+ */
+#define WRITE_LEN4_COMPLETION 0
 static int msixtbl_write(struct vcpu *v, unsigned long address,
                          unsigned int len, unsigned long val)
 {
@@ -283,9 +292,6 @@ static int msixtbl_write(struct vcpu *v, unsigned long address,
     unsigned long flags;
     struct irq_desc *desc;
 
-    if ( (len != 4 && len != 8) || (address & (len - 1)) )
-        return r;
-
     rcu_read_lock(&msixtbl_rcu_lock);
 
     entry = msixtbl_find_entry(v, address);
@@ -345,7 +351,7 @@ static int msixtbl_write(struct vcpu *v, unsigned long address,
 
 unlock:
     spin_unlock_irqrestore(&desc->lock, flags);
-    if ( len == 4 )
+    if ( len == WRITE_LEN4_COMPLETION )
         r = X86EMUL_OKAY;
 
 out:
@@ -357,6 +363,9 @@ static int cf_check _msixtbl_write(
     const struct hvm_io_handler *handler, uint64_t address, uint32_t len,
     uint64_t val)
 {
+    if ( (len != 4 && len != 8) || (address & (len - 1)) )
+        return X86EMUL_UNHANDLEABLE;
+
     return msixtbl_write(current, address, len, val);
 }
 
@@ -635,7 +644,7 @@ void msix_write_completion(struct vcpu *v)
         return;
 
     v->arch.hvm.hvm_io.msix_unmask_address = 0;
-    if ( msixtbl_write(v, ctrl_address, 4, 0) != X86EMUL_OKAY )
+    if ( msixtbl_write(v, ctrl_address, WRITE_LEN4_COMPLETION, 0) != X86EMUL_OKAY )
         gdprintk(XENLOG_WARNING, "MSI-X write completion failure\n");
 }
 
-- 
2.39.2



^ permalink raw reply related	[flat|nested] 37+ messages in thread

end of thread, other threads:[~2023-04-03 11:09 UTC | newest]

Thread overview: 37+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-03-25  2:49 [PATCH v2 1/3] x86/msi: passthrough all MSI-X vector ctrl writes to device model Marek Marczykowski-Górecki
2023-03-25  2:49 ` [PATCH v2 2/3] x86/hvm: Allow writes to registers on the same page as MSI-X table Marek Marczykowski-Górecki
2023-03-27 10:47   ` Andrew Cooper
2023-03-28 11:28   ` Roger Pau Monné
2023-03-28 12:05     ` Marek Marczykowski-Górecki
2023-03-28 12:34       ` Jan Beulich
2023-03-28 12:52         ` Marek Marczykowski-Górecki
2023-03-28 13:03           ` Jan Beulich
2023-03-28 13:22             ` Roger Pau Monné
2023-04-03  4:21             ` Marek Marczykowski-Górecki
2023-04-03 11:09               ` Jan Beulich
2023-03-28 12:52       ` Roger Pau Monné
2023-03-25  2:49 ` [PATCH v2 3/3] x86/msi: clear initial MSI-X state on boot Marek Marczykowski-Górecki
2023-03-28 11:37   ` Roger Pau Monné
2023-03-28 12:07     ` Marek Marczykowski-Górecki
2023-03-28 12:38       ` Jan Beulich
2023-03-28 12:54   ` Jan Beulich
2023-03-28 13:04     ` Marek Marczykowski-Górecki
2023-03-28 13:17       ` Jason Andryuk
2023-03-28 17:38         ` Jason Andryuk
2023-03-28 13:23       ` Jan Beulich
2023-03-28 13:27         ` Roger Pau Monné
2023-03-28 13:32           ` Jason Andryuk
2023-03-28 13:35             ` Jan Beulich
2023-03-28 13:43               ` Jason Andryuk
2023-03-28 13:54                 ` Jan Beulich
2023-03-28 15:08                   ` Jason Andryuk
2023-03-28 15:39                     ` Jan Beulich
2023-03-27 10:12 ` [PATCH v2 1/3] x86/msi: passthrough all MSI-X vector ctrl writes to device model Roger Pau Monné
2023-03-27 10:26   ` Marek Marczykowski-Górecki
2023-03-27 10:51     ` Roger Pau Monné
2023-03-27 11:34       ` Marek Marczykowski-Górecki
2023-03-27 13:29         ` Roger Pau Monné
2023-03-27 14:20           ` Marek Marczykowski-Górecki
2023-03-27 14:37             ` Roger Pau Monné
2023-03-27 15:32   ` Jan Beulich
2023-03-27 15:42     ` Roger Pau Monné

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.