forked from HW42/qubes-vmm-xen-stubdom-linux
/
0001-hw-xen-xen_pt-Save-back-data-only-for-declared-regis.patch
86 lines (75 loc) · 3.01 KB
/
0001-hw-xen-xen_pt-Save-back-data-only-for-declared-regis.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
From 172275923f0f0999187a0bba60066a5672f839dc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?=
<marmarek@invisiblethingslab.com>
Date: Mon, 14 Nov 2022 13:40:02 +0100
Subject: [PATCH 1/3] hw/xen/xen_pt: Save back data only for declared registers
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Call pci_default_write_config() in xen_pt_pci_write_config() only for
registers that have matching XenPTRegInfo structure, and do that only after
resolving any custom handlers. This is important for two reasons:
1. XenPTRegInfo has ro_mask which needs to be enforced - Xen-specific
hooks do that on their own (especially xen_pt_*_reg_write()).
2. Not setting value early allows the hooks to see the old value too.
If it would be only about the first point, setting PCIDevice.wmask would
probably be sufficient, but given the second point, restructure those
writes.
Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
---
v2:
- rewrite commit message, previous one was very misleading
- fix loop saving register values
---
hw/xen/xen_pt.c | 22 +++++++++++++++++++++-
1 file changed, 21 insertions(+), 1 deletion(-)
diff --git a/hw/xen/xen_pt.c b/hw/xen/xen_pt.c
index 2d33d178ad..3d6763dee7 100644
--- a/hw/xen/xen_pt.c
+++ b/hw/xen/xen_pt.c
@@ -256,6 +256,7 @@ static void xen_pt_pci_write_config(PCIDevice *d, uint32_t addr,
uint32_t find_addr = addr;
XenPTRegInfo *reg = NULL;
bool wp_flag = false;
+ uint32_t emul_mask = 0, write_val;
if (xen_pt_pci_config_access_check(d, addr, len)) {
return;
@@ -311,7 +312,6 @@ static void xen_pt_pci_write_config(PCIDevice *d, uint32_t addr,
}
memory_region_transaction_begin();
- pci_default_write_config(d, addr, val, len);
/* adjust the read and write value to appropriate CFC-CFF window */
read_val <<= (addr & 3) << 3;
@@ -371,6 +371,8 @@ static void xen_pt_pci_write_config(PCIDevice *d, uint32_t addr,
return;
}
+ emul_mask |= ( (1 << (reg->size * 8) ) - 1 ) << ((find_addr & 3) * 8);
+
/* calculate next address to find */
emul_len -= reg->size;
if (emul_len > 0) {
@@ -397,6 +399,24 @@ static void xen_pt_pci_write_config(PCIDevice *d, uint32_t addr,
/* need to shift back before passing them to xen_host_pci_set_block. */
val >>= (addr & 3) << 3;
+ /* store emulated registers after calling their handlers */
+ write_val = val;
+ for (index = 0; index < len; index += emul_len) {
+ emul_len = 0;
+ while (emul_mask & 0xff) {
+ emul_len++;
+ emul_mask >>= 8;
+ }
+ if (emul_len) {
+ uint32_t mask = ((1 << (emul_len * 8)) - 1);
+ pci_default_write_config(d, addr + index, write_val & mask, emul_len);
+ } else {
+ emul_mask >>= 8;
+ emul_len = 1;
+ }
+ write_val >>= emul_len * 8;
+ }
+
memory_region_transaction_commit();
out:
--
2.41.0