Skip to contentSkip to conversation

AMD IOMMU

PATCH Superseded David Kiarie 5 participants 53 messages Feb 21, 2016 – Mar 13, 2016 1 message not in the archive Page 2 of 2

v6 of 19 Superseded Latest is v19 →

lore
Share & tools
lore
#48 lore raw
In reply to Michael S. Tsirkin
Quoted 5 lines · Michael S. Tsirkin
Quoted 4 lines · Jan Kiszka
Quoted 2 lines · Jan Kiszka

There is likely no way around write-protecting the IOMMU page tables (in KVM mode) once we evaluated and cached them somewhere.

Quoted 7 lines
Quoted 2 lines

I mean, when in kvm mode AND having something that caches enabled, of course.

Just write-protecting won't be enough either, since the moment you remove the protection, all bets are off, and if you don't, guest will start from the same point when you re-enter and fault again.

We would not remove protection as long as the entry is in use by the IOMMU. There should be no difference from shadow MMU logic here: trap and emulate the write.

Quoted 10 lines

What this seems to call for is a new kind of protection
where yes PTE is write protected, but instead of
making PTE writeable (or killing guest)
KVM handles it as an MMIO: emulates the write and then skips the instruction.

Emulation can be in kernel, just writing into guest memory on behalf of the guest - with some kind of notifier to flush the vfio cache - or instead it can exit to userspace and have QEMU handle it like MMIO and write into guest memory.

Exactly, but that's nothing new, is it? It's "just" slow, like other shadow MMUs.

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT RDA ITP SES-DE
Corporate Competence Center Embedded Linux
#49 lore raw
Quoted 9 lines · Jan Kiszka
Quoted 8 lines · Michael S. Tsirkin
Quoted 6 lines · Jan Kiszka
Quoted 2 lines · Jan Kiszka

There is likely no way around write-protecting the IOMMU page tables (in KVM mode) once we evaluated and cached them somewhere.

I mean, when in kvm mode AND having something that caches enabled, of course.

Quoted 8 lines
Quoted 4 lines

Just write-protecting won't be enough either, since the moment you remove the protection, all bets are off, and if you don't, guest will start from the same point when you re-enter and fault again.

We would not remove protection as long as the entry is in use by the IOMMU. There should be no difference from shadow MMU logic here: trap and emulate the write.

Oh that's a nice trick. So you only write-protect it when you detect that a range was invalidated. Unfortunately it has page granularity so a single invalid PTE causes faults for writes to all others sharing a page with it.

Quoted 11 lines
Quoted 10 lines

What this seems to call for is a new kind of protection
where yes PTE is write protected, but instead of
making PTE writeable (or killing guest)
KVM handles it as an MMIO: emulates the write and then skips the instruction.

Emulation can be in kernel, just writing into guest memory on behalf of the guest - with some kind of notifier to flush the vfio cache - or instead it can exit to userspace and have QEMU handle it like MMIO and write into guest memory.

Quoted 4 lines

Exactly, but that's nothing new, is it? It's "just" slow, like other shadow MMUs.

Jan

Well AFAIK KVM does not have such an option ATM: MMIO causes exits for reads and writes. We want MMIO exits for writes but not reads. I agree it should be easy to implement.

Quoted 3 lines
Signature · 2 lines
Siemens AG, Corporate Technology, CT RDA ITP SES-DE
Corporate Competence Center Embedded Linux
#50 lore raw
Quoted 13 lines · Michael S. Tsirkin
Quoted 12 lines · Jan Kiszka
Quoted 10 lines · Michael S. Tsirkin

What this seems to call for is a new kind of protection
where yes PTE is write protected, but instead of
making PTE writeable (or killing guest)
KVM handles it as an MMIO: emulates the write and then skips the instruction.

Emulation can be in kernel, just writing into guest memory on behalf of the guest - with some kind of notifier to flush the vfio cache - or instead it can exit to userspace and have QEMU handle it like MMIO and write into guest memory.

Quoted 8 lines
Quoted 4 lines

Exactly, but that's nothing new, is it? It's "just" slow, like other shadow MMUs.

Jan

Well AFAIK KVM does not have such an option ATM: MMIO causes exits for reads and writes. We want MMIO exits for writes but not reads. I agree it should be easy to implement.

We have read-only memory slot support for quite a while. It's used to support execute (and read) from emulated ROM devices.

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT RDA ITP SES-DE
Corporate Competence Center Embedded Linux
#51 lore raw
Quoted 19 lines · Jan Kiszka
Quoted 18 lines · Michael S. Tsirkin
Quoted 16 lines · Jan Kiszka
Quoted 10 lines · Michael S. Tsirkin

What this seems to call for is a new kind of protection
where yes PTE is write protected, but instead of
making PTE writeable (or killing guest)
KVM handles it as an MMIO: emulates the write and then skips the instruction.

Emulation can be in kernel, just writing into guest memory on behalf of the guest - with some kind of notifier to flush the vfio cache - or instead it can exit to userspace and have QEMU handle it like MMIO and write into guest memory.

Exactly, but that's nothing new, is it? It's "just" slow, like other shadow MMUs.

Jan

Quoted 8 lines
Quoted 3 lines

Well AFAIK KVM does not have such an option ATM: MMIO causes exits for reads and writes. We want MMIO exits for writes but not reads. I agree it should be easy to implement.

We have read-only memory slot support for quite a while. It's used to support execute (and read) from emulated ROM devices.

Jan

I didn't realize this causes an mmio exit.

Quoted 3 lines
Signature · 2 lines
Siemens AG, Corporate Technology, CT RDA ITP SES-DE
Corporate Competence Center Embedded Linux
#52 lore raw
In reply to Jan Kiszka
Quoted 44 lines · Jan Kiszka
Quoted 20 lines · Michael S. Tsirkin
Quoted 10 lines · David Kiarie

Hello there,

Repost, AMD IOMMU patches version 6.

Changes since version 5
-Fixed macro formating issues
-changed occurences of IO MMU to IOMMU for consistency -Fixed capability registers duplication -Rebased to current master

Quoted 5 lines

David Kiarie (4):
hw/i386: Introduce AMD IOMMU
hw/core: Add AMD IOMMU to machine properties
hw/i386: ACPI table for AMD IOMMU
hw/pci-host: Emulate AMD IOMMU

I went over AMD IOMMU spec.
I'm concerned that it appears that there's no chance for it to work correctly if host caches invalid PTE entries.

Quoted 5 lines

The spec vaguely discusses write-protecting such PTEs but that would be very complex if it can be made to work at all.

This means that this can't work with e.g. VFIO.
It can only work with emulated devices.

You mean it can't work if we program a real IOMMU (for VFIO) with translated data from the emulated one but cannot track any updates of the related page tables because the guest is not required to issue traceable flush requests? Hmm, too bad.

Quoted 1 line

OTOH VTD can easily support PTE shadowing by setting a flag.

Do you mean RWBF=1 in the CAP register? Given that "Newer hardware implementations are expected to NOT require explicit software flushing of write buffers and report RWBF=0 in the Capability register", we may eventually run into guests that no longer check that flag if we expose something that looks like a "newer" implementation.

However, this flag is not set right now in our VT-d model.

Quoted 4 lines

I'd like us to find some way to avoid possibility of user error creating a configuration mixing e.g. vfio with the amd iommu.

Quoted 6 lines
Quoted 3 lines

I'm not sure how to do this.

Any idea?

There is likely no way around write-protecting the IOMMU page tables (in KVM mode) once we evaluated and cached them somewhere. For now, I would simply deny vfio while an IOMMU is active on x86.

Should I implement this, in the meantime ?

Quoted 3 lines

Jan

#53 lore raw
Quoted 47 lines · David Kiarie
Quoted 44 lines · Jan Kiszka
Quoted 20 lines · Michael S. Tsirkin
Quoted 10 lines · David Kiarie

Hello there,

Repost, AMD IOMMU patches version 6.

Changes since version 5
-Fixed macro formating issues
-changed occurences of IO MMU to IOMMU for consistency -Fixed capability registers duplication -Rebased to current master

Quoted 5 lines

David Kiarie (4):
hw/i386: Introduce AMD IOMMU
hw/core: Add AMD IOMMU to machine properties
hw/i386: ACPI table for AMD IOMMU
hw/pci-host: Emulate AMD IOMMU

I went over AMD IOMMU spec.
I'm concerned that it appears that there's no chance for it to work correctly if host caches invalid PTE entries.

Quoted 5 lines

The spec vaguely discusses write-protecting such PTEs but that would be very complex if it can be made to work at all.

This means that this can't work with e.g. VFIO.
It can only work with emulated devices.

You mean it can't work if we program a real IOMMU (for VFIO) with translated data from the emulated one but cannot track any updates of the related page tables because the guest is not required to issue traceable flush requests? Hmm, too bad.

Quoted 1 line

OTOH VTD can easily support PTE shadowing by setting a flag.

Do you mean RWBF=1 in the CAP register? Given that "Newer hardware implementations are expected to NOT require explicit software flushing of write buffers and report RWBF=0 in the Capability register", we may eventually run into guests that no longer check that flag if we expose something that looks like a "newer" implementation.

However, this flag is not set right now in our VT-d model.

Quoted 4 lines

I'd like us to find some way to avoid possibility of user error creating a configuration mixing e.g. vfio with the amd iommu.

Quoted 7 lines
Quoted 6 lines
Quoted 3 lines

I'm not sure how to do this.

Any idea?

There is likely no way around write-protecting the IOMMU page tables (in KVM mode) once we evaluated and cached them somewhere. For now, I would simply deny vfio while an IOMMU is active on x86.

Should I implement this, in the meantime ?

Why not :)

Quoted 3 lines
Quoted 3 lines

Jan