Skip to contentSkip to conversation

vt-d: use two 32-bit writes to update DMAR fault address registers

PATCH Superseded Haozhong Zhang 4 participants 13 messages Sep 11, 2017 – Oct 10, 2017

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vt-d: use two 32-bit writes to update DMAR fault address registers

The 64-bit DMAR fault address is composed of two 32 bits registers DMAR_FEADDR_REG and DMAR_FEUADDR_REG. According to VT-d spec:
"Software is expected to access 32-bit registers as aligned doublewords", a hypervisor should use two 32-bit writes to DMAR_FEADDR_REG and DMAR_FEUADDR_REG separately in order to update a 64-bit fault address, rather than a 64-bit write to DMAR_FEADDR_REG.

Though I haven't seen any errors caused by such one 64-bit write on real machines, it's still better to follow the specification.

---
 xen/drivers/passthrough/vtd/iommu.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
xen/drivers/passthrough/vtd/iommu.c +3 -1
index daaed0abbd..067c092214 100644
@@ -1105,7 +1105,9 @@ static void dma_msi_set_affinity(struct irq_desc *desc, const cpumask_t *mask)
 
     spin_lock_irqsave(&iommu->register_lock, flags);
     dmar_writel(iommu->reg, DMAR_FEDATA_REG, msg.data);
-    dmar_writeq(iommu->reg, DMAR_FEADDR_REG, msg.address);
+    dmar_writel(iommu->reg, DMAR_FEADDR_REG, msg.address_lo);
+    if (x2apic_enabled)
+        dmar_writel(iommu->reg, DMAR_FEUADDR_REG, msg.address_hi);
     spin_unlock_irqrestore(&iommu->register_lock, flags);
 }
 
Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#1 lore raw
Quoted 9 lines · Haozhong Zhang

The 64-bit DMAR fault address is composed of two 32 bits registers DMAR_FEADDR_REG and DMAR_FEUADDR_REG. According to VT-d spec:
"Software is expected to access 32-bit registers as aligned doublewords", a hypervisor should use two 32-bit writes to DMAR_FEADDR_REG and DMAR_FEUADDR_REG separately in order to update a 64-bit fault address, rather than a 64-bit write to DMAR_FEADDR_REG.

Though I haven't seen any errors caused by such one 64-bit write on real machines, it's still better to follow the specification.

Either the patch description is missing something or the patch is wrong. You should mention why is the write to the high part of the address now conditional on x2APIC being enabled, when it didn't use to be before.

[...]

xen/drivers/passthrough/vtd/iommu.c static void dma_msi_set_affinity(struct irq_desc *desc, const cpumask_t *mask) · line 1111

Quoted 5 lines
xen/drivers/passthrough/vtd/iommu.c +3 -1
-    dmar_writeq(iommu->reg, DMAR_FEADDR_REG, msg.address);
+    dmar_writel(iommu->reg, DMAR_FEADDR_REG, msg.address_lo);
+    if (x2apic_enabled)
+        dmar_writel(iommu->reg, DMAR_FEUADDR_REG, msg.address_hi);
     spin_unlock_irqrestore(&iommu->register_lock, flags);

Thanks, Roger.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#2 lore raw
Quoted 8 lines · Roger Pau Monné
Quoted 7 lines · Haozhong Zhang

The 64-bit DMAR fault address is composed of two 32 bits registers DMAR_FEADDR_REG and DMAR_FEUADDR_REG. According to VT-d spec:
"Software is expected to access 32-bit registers as aligned doublewords", a hypervisor should use two 32-bit writes to DMAR_FEADDR_REG and DMAR_FEUADDR_REG separately in order to update a 64-bit fault address, rather than a 64-bit write to DMAR_FEADDR_REG.

Quoted 8 lines
Quoted 2 lines

Though I haven't seen any errors caused by such one 64-bit write on real machines, it's still better to follow the specification.

Either the patch description is missing something or the patch is wrong. You should mention why is the write to the high part of the address now conditional on x2APIC being enabled, when it didn't use to be before.

When x2APIC is disabled, DMAR_FEUADDR_REG is reserved and it's not necessary to update it. The original code always writes zero to it in that case, which is also correct.

Haozhong

Quoted 8 lines

[...]

xen/drivers/passthrough/vtd/iommu.c static void dma_msi_set_affinity(struct irq_desc *desc, const cpumask_t *mask) · line 1111

Quoted 5 lines
xen/drivers/passthrough/vtd/iommu.c +3 -1
-    dmar_writeq(iommu->reg, DMAR_FEADDR_REG, msg.address);
+    dmar_writel(iommu->reg, DMAR_FEADDR_REG, msg.address_lo);
+    if (x2apic_enabled)
+        dmar_writel(iommu->reg, DMAR_FEUADDR_REG, msg.address_hi);
     spin_unlock_irqrestore(&iommu->register_lock, flags);

Thanks, Roger.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#3 lore raw
Quoted 23 lines

From: Zhang, Haozhong
Sent: Monday, September 11, 2017 8:13 PM

Quoted 3 lines · Roger Pau Monné
Quoted 2 lines · Haozhong Zhang

The 64-bit DMAR fault address is composed of two 32 bits registers DMAR_FEADDR_REG and DMAR_FEUADDR_REG. According to VT-d

spec:

Quoted 3 lines
Quoted 3 lines

"Software is expected to access 32-bit registers as aligned doublewords", a hypervisor should use two 32-bit writes to DMAR_FEADDR_REG and DMAR_FEUADDR_REG separately in order to update a 64-bit fault

address,

Quoted 10 lines
Quoted 4 lines

rather than a 64-bit write to DMAR_FEADDR_REG.

Though I haven't seen any errors caused by such one 64-bit write on real machines, it's still better to follow the specification.

Either the patch description is missing something or the patch is wrong. You should mention why is the write to the high part of the address now conditional on x2APIC being enabled, when it didn't use to be before.

Quoted 6 lines

When x2APIC is disabled, DMAR_FEUADDR_REG is reserved and it's not necessary to update it. The original code always writes zero to it in that case, which is also correct.

Haozhong

Please add a brief comment in the code to make it clear.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#4 lore raw
In reply to Haozhong Zhang
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 11.09.17 at 08:00, <[email protected]> wrote:

The 64-bit DMAR fault address is composed of two 32 bits registers DMAR_FEADDR_REG and DMAR_FEUADDR_REG. According to VT-d spec:
"Software is expected to access 32-bit registers as aligned doublewords", a hypervisor should use two 32-bit writes to DMAR_FEADDR_REG and DMAR_FEUADDR_REG separately in order to update a 64-bit fault address, rather than a 64-bit write to DMAR_FEADDR_REG.

Though I haven't seen any errors caused by such one 64-bit write on real machines, it's still better to follow the specification.

Any sane chipset should split qword accesses into dword ones if they can't be handled at some layer. Also if you undo something explicitly done by an earlier commit, please quote that commit and say what was wrong. After all Kevin as the VT-d maintainer agreed with the change back then.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#5 lore raw
Quoted 15 lines

From: Jan Beulich [mailto:[email protected]]
Sent: Monday, September 11, 2017 6:03 PM

Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 11.09.17 at 08:00, <[email protected]> wrote:

The 64-bit DMAR fault address is composed of two 32 bits registers DMAR_FEADDR_REG and DMAR_FEUADDR_REG. According to VT-d spec:
"Software is expected to access 32-bit registers as aligned doublewords", a hypervisor should use two 32-bit writes to DMAR_FEADDR_REG and DMAR_FEUADDR_REG separately in order to update a 64-bit fault

address,

Quoted 4 lines

rather than a 64-bit write to DMAR_FEADDR_REG.

Though I haven't seen any errors caused by such one 64-bit write on real machines, it's still better to follow the specification.

Quoted 7 lines

Any sane chipset should split qword accesses into dword ones if they can't be handled at some layer. Also if you undo something explicitly done by an earlier commit, please quote that commit and say what was wrong. After all Kevin as the VT-d maintainer agreed with the change back then.

Jan

I'm OK with this change. As Jan pointed out, please quote earlier comment in next version.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#6 lore raw
Quoted 16 lines
Quoted 16 lines
Quoted 1 line · On 18.09.17 at 10:18, <[email protected]> wrote:

From: Jan Beulich [mailto:[email protected]]
Sent: Monday, September 11, 2017 6:03 PM

Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 11.09.17 at 08:00, <[email protected]> wrote:

The 64-bit DMAR fault address is composed of two 32 bits registers DMAR_FEADDR_REG and DMAR_FEUADDR_REG. According to VT-d spec:
"Software is expected to access 32-bit registers as aligned doublewords", a hypervisor should use two 32-bit writes to DMAR_FEADDR_REG and DMAR_FEUADDR_REG separately in order to update a 64-bit fault

address,

Quoted 4 lines

rather than a 64-bit write to DMAR_FEADDR_REG.

Though I haven't seen any errors caused by such one 64-bit write on real machines, it's still better to follow the specification.

Quoted 7 lines
Quoted 5 lines

Any sane chipset should split qword accesses into dword ones if they can't be handled at some layer. Also if you undo something explicitly done by an earlier commit, please quote that commit and say what was wrong. After all Kevin as the VT-d maintainer agreed with the change back then.

I'm OK with this change.

Hmm, would you mind explaining? You were also okay with the change in the opposite direction back then, and we've had no reports of problems.

Jan

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#7 lore raw
Quoted 22 lines · Jan Beulich
Quoted 22 lines
Quoted 21 lines
Quoted 1 line · On 18.09.17 at 10:18, <[email protected]> wrote:

From: Jan Beulich [mailto:[email protected]]
Sent: Monday, September 11, 2017 6:03 PM

Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 11.09.17 at 08:00, <[email protected]> wrote:

The 64-bit DMAR fault address is composed of two 32 bits registers DMAR_FEADDR_REG and DMAR_FEUADDR_REG. According to VT-d spec:
"Software is expected to access 32-bit registers as aligned doublewords", a hypervisor should use two 32-bit writes to DMAR_FEADDR_REG and DMAR_FEUADDR_REG separately in order to update a 64-bit fault

address,

Quoted 4 lines

rather than a 64-bit write to DMAR_FEADDR_REG.

Though I haven't seen any errors caused by such one 64-bit write on real machines, it's still better to follow the specification.

Any sane chipset should split qword accesses into dword ones if they can't be handled at some layer. Also if you undo something explicitly done by an earlier commit, please quote that commit and say what was wrong. After all Kevin as the VT-d maintainer agreed with the change back then.

Quoted 6 lines
Quoted 1 line

I'm OK with this change.

Hmm, would you mind explaining? You were also okay with the change in the opposite direction back then, and we've had no reports of problems.

I haven't seen any issues of the current 64-bit write on recent Intel Haswell, Broadwell and Skylake Xeon platforms, so I guess the hardware can properly handle the 64-bits write to contiguous 32-bit registers.

I actually encountered errors when running Xen on KVM/QEMU with QEMU vIOMMU enabled, which (QEMU) disallows 64-bit writes to 32-bit registers and aborts if such writes happen.

If this patch is considered senseless (as it does not fix any errors on real hardware), I'm fine to fix the above abort on QEMU side (i.e., let vIOMMU in QEMU follow the behavior of real hardware).

Haozhong

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#8 lore raw
Quoted 34 lines · Haozhong Zhang
Quoted 22 lines · Jan Beulich
Quoted 22 lines
Quoted 21 lines
Quoted 1 line · On 18.09.17 at 10:18, <[email protected]> wrote:

From: Jan Beulich [mailto:[email protected]]
Sent: Monday, September 11, 2017 6:03 PM

Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 11.09.17 at 08:00, <[email protected]> wrote:

The 64-bit DMAR fault address is composed of two 32 bits registers DMAR_FEADDR_REG and DMAR_FEUADDR_REG. According to VT-d spec:
"Software is expected to access 32-bit registers as aligned doublewords", a hypervisor should use two 32-bit writes to DMAR_FEADDR_REG and DMAR_FEUADDR_REG separately in order to update a 64-bit fault

address,

Quoted 4 lines

rather than a 64-bit write to DMAR_FEADDR_REG.

Though I haven't seen any errors caused by such one 64-bit write on real machines, it's still better to follow the specification.

Any sane chipset should split qword accesses into dword ones if they can't be handled at some layer. Also if you undo something explicitly done by an earlier commit, please quote that commit and say what was wrong. After all Kevin as the VT-d maintainer agreed with the change back then.

Quoted 6 lines
Quoted 1 line

I'm OK with this change.

Hmm, would you mind explaining? You were also okay with the change in the opposite direction back then, and we've had no reports of problems.

I haven't seen any issues of the current 64-bit write on recent Intel Haswell, Broadwell and Skylake Xeon platforms, so I guess the hardware can properly handle the 64-bits write to contiguous 32-bit registers.

Quoted 7 lines

I actually encountered errors when running Xen on KVM/QEMU with QEMU vIOMMU enabled, which (QEMU) disallows 64-bit writes to 32-bit registers and aborts if such writes happen.

If this patch is considered senseless (as it does not fix any errors on real hardware), I'm fine to fix the above abort on QEMU side (i.e., let vIOMMU in QEMU follow the behavior of real hardware).

I think that either the spec is changed to mention that quad-word accesses are allowed, or this patch is applied.

There's nothing wrong with the QEMU implementation, it adheres to the spec. So unless the spec is changed, we might see issues with other emulated DMAR units.

Roger.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#9 lore raw
Quoted 51 lines

From: Roger Pau Monné [mailto:[email protected]]
Sent: Monday, September 18, 2017 5:10 PM

Quoted 8 lines · Haozhong Zhang
Quoted 7 lines · Jan Beulich
Quoted 7 lines
Quoted 7 lines
Quoted 1 line · On 18.09.17 at 10:18, <[email protected]> wrote:

From: Jan Beulich [mailto:[email protected]]
Sent: Monday, September 11, 2017 6:03 PM

Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 11.09.17 at 08:00, <[email protected]> wrote:

The 64-bit DMAR fault address is composed of two 32 bits registers DMAR_FEADDR_REG and DMAR_FEUADDR_REG. According to VT-d

spec:

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Software is expected to access 32-bit registers as aligned

doublewords",

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

a hypervisor should use two 32-bit writes to DMAR_FEADDR_REG

and

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 1 line

DMAR_FEUADDR_REG separately in order to update a 64-bit fault

address,

Quoted 3 lines

rather than a 64-bit write to DMAR_FEADDR_REG.

Though I haven't seen any errors caused by such one 64-bit write

on

Quoted 15 lines
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 1 line

real machines, it's still better to follow the specification.

Any sane chipset should split qword accesses into dword ones if they can't be handled at some layer. Also if you undo something explicitly done by an earlier commit, please quote that commit and say what was wrong. After all Kevin as the VT-d maintainer agreed with the change back then.

Quoted 6 lines
Quoted 1 line

I'm OK with this change.

Hmm, would you mind explaining? You were also okay with the change in the opposite direction back then, and we've had no reports of problems.

Quoted 5 lines

I haven't seen any issues of the current 64-bit write on recent Intel Haswell, Broadwell and Skylake Xeon platforms, so I guess the hardware can properly handle the 64-bits write to contiguous 32-bit registers.

I actually encountered errors when running Xen on KVM/QEMU with

QEMU

Quoted 6 lines

vIOMMU enabled, which (QEMU) disallows 64-bit writes to 32-bit registers and aborts if such writes happen.

If this patch is considered senseless (as it does not fix any errors on real hardware), I'm fine to fix the above abort on QEMU side (i.e., let vIOMMU in QEMU follow the behavior of real hardware).

Quoted 7 lines

I think that either the spec is changed to mention that quad-word accesses are allowed, or this patch is applied.

There's nothing wrong with the QEMU implementation, it adheres to the spec. So unless the spec is changed, we might see issues with other emulated DMAR units.

I checked with our hardware guy. It' recommended to strictly follow what spec says. there is no hardware-level guarantee that a 64b write will touch both FEADDR and FEUADDR. So we should fix Xen side.

Thanks
Kevin

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

Reviewed-by on v1 1/1
#10 lore raw
In reply to Haozhong Zhang
Quoted 6 lines · Haozhong Zhang

The 64-bit DMAR fault address is composed of two 32 bits registers DMAR_FEADDR_REG and DMAR_FEUADDR_REG. According to VT-d spec:
"Software is expected to access 32-bit registers as aligned doublewords", a hypervisor should use two 32-bit writes to DMAR_FEADDR_REG and DMAR_FEUADDR_REG separately in order to update a 64-bit fault address, rather than a 64-bit write to DMAR_FEADDR_REG.

I would add:

"Note that when x2APIC is disabled DMAR_FEUADDR_REG is reserved and it's not necessary to update it."

Quoted 4 lines

Though I haven't seen any errors caused by such one 64-bit write on real machines, it's still better to follow the specification.

Given the reply from Kevin:

Thanks, Roger.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#11 lore raw
Quoted 18 lines

From: Roger Pau Monné [mailto:[email protected]]
Sent: Wednesday, September 20, 2017 4:31 PM

Quoted 5 lines · Haozhong Zhang

The 64-bit DMAR fault address is composed of two 32 bits registers DMAR_FEADDR_REG and DMAR_FEUADDR_REG. According to VT-d spec:
"Software is expected to access 32-bit registers as aligned doublewords", a hypervisor should use two 32-bit writes to DMAR_FEADDR_REG and DMAR_FEUADDR_REG separately in order to update a 64-bit fault

address,

Quoted 1 line

rather than a 64-bit write to DMAR_FEADDR_REG.

I would add:

"Note that when x2APIC is disabled DMAR_FEUADDR_REG is reserved and it's not
necessary to update it."

Quoted 9 lines
Quoted 4 lines

Though I haven't seen any errors caused by such one 64-bit write on real machines, it's still better to follow the specification.

Given the reply from Kevin:

Haozhong, can you resend a new version with patch description updated?

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#12 lore raw
Quoted 23 lines · Kevin
Quoted 23 lines

From: Roger Pau Monné [mailto:[email protected]]
Sent: Wednesday, September 20, 2017 4:31 PM

Quoted 5 lines · Haozhong Zhang

The 64-bit DMAR fault address is composed of two 32 bits registers DMAR_FEADDR_REG and DMAR_FEUADDR_REG. According to VT-d spec:
"Software is expected to access 32-bit registers as aligned doublewords", a hypervisor should use two 32-bit writes to DMAR_FEADDR_REG and DMAR_FEUADDR_REG separately in order to update a 64-bit fault

address,

Quoted 1 line

rather than a 64-bit write to DMAR_FEADDR_REG.

I would add:

"Note that when x2APIC is disabled DMAR_FEUADDR_REG is reserved and it's not
necessary to update it."

Quoted 4 lines

Though I haven't seen any errors caused by such one 64-bit write on real machines, it's still better to follow the specification.

Quoted 7 lines
Quoted 4 lines

Given the reply from Kevin:

Haozhong, can you resend a new version with patch description updated?

Sorry, I forgot it and will send.

Thanks,
Haozhong

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel