Skip to content

RFC TSM: Secure VFIO, TDISP, SEV TIO

Alexey Kardashevskiy kvm linux-arch linux-coco linux-crypto linux-iommu linux-pci 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 RFC Latest22 patches 73 repliesIn review
  2. v1 RFC21 patches 106 repliesSuperseded

Changes in v2 from the cover letter

* redid the whole thing pretty much
* RMPUPDATE API for QEMU
* switched to IOMMUFD
* mapping guest memory via IOMMUFD map-from-fd
* marking resouces as validated
* more modules
* moved tons to the userspace (QEMU), such as TDI bind and GHCB guest requests

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/22pci/doe: Define protocol types and make those publicdrivers/pci/doe.c include/linux/pci-doe.h+4 -21 reply
2/22PCI/IDE: Fixes to make it work on AMD SNP-SEVdrivers/pci/ide.c include/linux/pci-ide.h include/uapi/linux/pci_regs.h+78 -210 replies
3/22PCI/IDE: Init IDs on all IDE streams beforehanddrivers/pci/ide.c+26 -30 replies
4/22iommu/amd: Report SEV-TIO supportdrivers/iommu/amd/amd_iommu_types.h drivers/iommu/amd/init.c include/linux/amd-iommu.h+12 -00 replies
5/22crypto: ccp: Enable SEV-TIO feature in the PSP when supporteddrivers/crypto/ccp/sev-dev.c drivers/crypto/ccp/sev-dev.h include/linux/psp-sev.h +1 more+115 -62 replies
6/22KVM: X86: Define tsm_get_vmidarch/x86/include/asm/kvm-x86-ops.h arch/x86/include/asm/kvm_host.h arch/x86/kvm/svm/svm.c +2 more+23 -05 replies
7/22coco/tsm: Add tsm and tsm-host modulesDocumentation/virt/coco/tsm.rst drivers/virt/coco/Kconfig drivers/virt/coco/Makefile +5 more+1610 -03 replies
8/22pci/tsm: Add PCI driver for TSMdrivers/pci/Kconfig drivers/pci/Makefile drivers/pci/tsm.c +1 more+252 -01 reply
9/22crypto/ccp: Implement SEV TIO firmware interfacearch/x86/include/asm/sev.h drivers/crypto/ccp/Kconfig drivers/crypto/ccp/Makefile +8 more+2576 -41 reply
10/22KVM: SVM: Add uAPI to change RMP for MMIOarch/x86/include/asm/sev.h arch/x86/include/uapi/asm/kvm.h arch/x86/kvm/svm/sev.c +1 more+178 -42 replies
11/22KVM: SEV: Add TIO VMGEXITarch/x86/include/uapi/asm/svm.h arch/x86/kvm/svm/sev.c include/uapi/linux/kvm.h+96 -00 replies
12/22iommufd: Allow mapping from guest_memfddrivers/iommu/iommufd/pages.c+87 -112 replies
13/22iommufd: amd-iommu: Add vdevice supportdrivers/iommu/amd/amd_iommu_types.h drivers/iommu/amd/iommu.c include/uapi/linux/iommufd.h+61 -25 replies
14/22iommufd: Add TIO callsdrivers/iommu/iommufd/iommufd_private.h drivers/iommu/iommufd/main.c drivers/iommu/iommufd/viommu.c +1 more+146 -031 replies
15/22KVM: X86: Handle private MMIO as sharedarch/x86/kvm/mmu/mmu.c+5 -12 replies
16/22coco/tsm: Add tsm-guest moduleDocumentation/virt/coco/tsm.rst drivers/virt/coco/guest/Kconfig drivers/virt/coco/guest/Makefile +6 more+358 -01 reply
17/22resource: Mark encrypted MMIO resource on validationarch/x86/mm/ioremap.c include/linux/ioport.h kernel/resource.c+52 -01 reply
18/22coco/sev-guest: Implement the guest support for SEV TIOarch/x86/coco/sev/core.c arch/x86/include/asm/sev.h drivers/virt/coco/sev-guest/Makefile +3 more+815 -21 reply
19/22RFC: pci: Add BUS_NOTIFY_PCI_BUS_MASTER eventdrivers/pci/pci.c drivers/virt/coco/guest/tsm-guest.c include/linux/device/bus.h+41 -01 reply
20/22sev-guest: Stop changing encrypted page state for TDISP devicesarch/x86/mm/mem_encrypt.c include/linux/dma-direct.h include/linux/swiotlb.h+22 -01 reply
21/22pci: Allow encrypted MMIO mapping via sysfsdrivers/pci/mmap.c drivers/pci/pci-sysfs.c drivers/pci/proc.c +1 more+32 -101 reply
22/22pci: Define pci_iomap_range_encrypteddrivers/pci/iomap.c include/asm-generic/pci_iomap.h+28 -01 reply

Reviews trailers per patch

1 of 22 patches has a Reviewed-by or Acked-by.

PatchVasant Hegde
1/22
2/22
3/22
4/22
5/22
6/22
7/22
8/22
9/22
10/22
11/22
12/22R-b
13/22
14/22
15/22
16/22
17/22
18/22
19/22
20/22
21/22
22/22

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v2 thread

Cover letter [RFC PATCH v2 00/22] TSM: Secure VFIO, TDISP, SEV TIO

Here are some patches to enable SEV-TIO on AMD Turin. It's been a while and got quiet and I kept fixing my tree and wondering if I am going in the right direction.

SEV-TIO allow a guest to establish trust in a device that supports TEE Device Interface Security Protocol (TDISP, defined in PCIe r6.0+) and then interact with the device via private memory.

These include both guest and host support. QEMU also requires changes. This is more to show what it takes on AMD EPYC to pass through TDISP devices, hence "RFC".

Components affected:
KVM
IOMMUFD
CCP (AMD)
SEV-GUEST (AMD)

New components:
PCI IDE
PCI TSM
VIRT CoCo TSM
VIRT CoCo TSM-HOST
VIRT CoCo TSM-GUEST

This is based on a merge of Lukas'es CMA and 1 week old upstream + some of Dan's patches:

https://github.com/aik/linux/tree/tsm
https://github.com/aik/qemu/tree/tsm

Not using "[PATCH 03/11] coco/tsm: Introduce a class device for TEE Security Managers" yet as may be (may be) my approach makes sense too. Tried to stick to the terminology. I have done some changes on top of that, these are on github, not posting here as I expect those to be addressed in that thread:
https://lore.kernel.org/linux-coco/173343739517.1074769.13134786548545925484.stgit@dwillia2-xfh.jf.intel.com/T/

SEV TIO spec:
https://www.amd.com/content/dam/amd/en/documents/epyc-technical-docs/specifications/58271_0_70.pdf
Whitepaper:
https://www.amd.com/content/dam/amd/en/documents/epyc-business-docs/white-papers/sev-tio-whitepaper.pdf

Acronyms:

TEE - Trusted Execution Environments, a concept of managing trust between the host
and devices
TSM - TEE Security Manager (TSM), an entity which ensures security on the host PSP - AMD platform secure processor (also "ASP", "AMD-SP"), acts as TSM on AMD. SEV TIO - the TIO protocol implemented by the PSP and used by the host GHCB - guest/host communication block - a protocol for guest-to-host communication
via a shared page
TDISP - TEE Device Interface Security Protocol (PCIe).

Flow:

- Boot host OS, load CCP and PCI TSM (they will load TSM-HOST too)
- PCI TSM creates sysfs nodes in "coco/tsm: Add tsm and tsm-host modules" for all TDISP-capable devices
- Enable IDE via "echo 0 > /sys/bus/pci/devices/0000:e1:00.0/tsm-dev/tdev:0000:e1:00.0/tsm_dev_connect"
- Examine certificates/measurements/status via sysfs

- run an SNP VM _without_ VFIO PCI device, wait till it is booted
- hotplug a TDISP-capable PCI function, IOMMUFD must be used (not a VFIO container)
- QEMU pins all guest memory via IOMMUFD map-from-fd ioctl()
- the VM detects a TDISP-capable device, creates sysfs nodes in "coco/tsm: Add tsm-guest module"
- the VM loads the device driver which goes as usual till enabling bus master (for convinience)
- TSM-GUEST modules listens for bus master event (hacked in "pci: Add BUS_NOTIFY_PCI_BUS_MASTER event")
- TSM-GUEST requests TDI ("trusted PCI VF") info, traps into QEMU
- QEMU binds the VF to the Coco VM in the secure fw (AMD PSP) via IOMMUFD ioctl
- QEMU reads certificates/measurements/interface report from the hosts sysfs and writes to the guest memory
- the guest receives all the data, examines it (not in this series though)
- the guest enables secure DMA and MMIO by calling GHCB which traps into QEMU
- QEMU calls IOMMUFD ioctl to enable secure DMA and MMIO
- the guest can now stop sharing memory for DMA (and expect DMA to encrypted memory to work) and start accessing validated MMIO with Cbit set.

Assumptions

This requires hotpligging into the VM vs passing the device via the command line as VFIO maps all guest memory as the device init step which is too soon as SNP LAUNCH UPDATE happens later and will fail if VFIO maps private memory before that.

This requires the BME hack as MMIO and BusMaster enable bits cannot be 0 after MMIO validation is done and there are moments in the guest OS booting process when this appens.

SVSM could help addressing these (not implemented).

QEMU advertises TEE-IO capability to the VM. An additional x-tio flag is added to vfio-pci.

Trying to avoid the device driver modification as much as possible at the moment as my test devices already exist in non-TDISP form and need to work without modification. Arguably this may not be always the case.

TODOs

Deal with PCI reset. Hot unplug+plug? Power states too. Actually collaborate with CMA.
Other tons of things.

The previous conversation is here:
https://lore.kernel.org/r/[email protected]

Changes:
v2:
* redid the whole thing pretty much
* RMPUPDATE API for QEMU
* switched to IOMMUFD
* mapping guest memory via IOMMUFD map-from-fd
* marking resouces as validated
* more modules
* moved tons to the userspace (QEMU), such as TDI bind and GHCB guest requests

Sean, get_maintainer.pl produced more than 100 emails for the entire patchset, should I have posted them all anyway?

Please comment. Thanks.

Alexey Kardashevskiy (22):
pci/doe: Define protocol types and make those public PCI/IDE: Fixes to make it work on AMD SNP-SEV PCI/IDE: Init IDs on all IDE streams beforehand iommu/amd: Report SEV-TIO support
crypto: ccp: Enable SEV-TIO feature in the PSP when supported
KVM: X86: Define tsm_get_vmid
coco/tsm: Add tsm and tsm-host modules
pci/tsm: Add PCI driver for TSM
crypto/ccp: Implement SEV TIO firmware interface
KVM: SVM: Add uAPI to change RMP for MMIO
KVM: SEV: Add TIO VMGEXIT
iommufd: Allow mapping from guest_memfd
iommufd: amd-iommu: Add vdevice support
iommufd: Add TIO calls
KVM: X86: Handle private MMIO as shared
coco/tsm: Add tsm-guest module
resource: Mark encrypted MMIO resource on validation coco/sev-guest: Implement the guest support for SEV TIO
RFC: pci: Add BUS_NOTIFY_PCI_BUS_MASTER event
sev-guest: Stop changing encrypted page state for TDISP devices
pci: Allow encrypted MMIO mapping via sysfs
pci: Define pci_iomap_range_encrypted

 drivers/crypto/ccp/Makefile                 |   13 +
 drivers/pci/Makefile                        |    3 +
 drivers/virt/coco/Makefile                  |    2 +
 drivers/virt/coco/guest/Makefile            |    3 +
 drivers/virt/coco/host/Makefile             |    6 +
 drivers/virt/coco/sev-guest/Makefile        |    2 +-
 arch/x86/include/asm/kvm-x86-ops.h          |    1 +
 arch/x86/include/asm/kvm_host.h             |    2 +
 arch/x86/include/asm/sev.h                  |   31 +
 arch/x86/include/uapi/asm/kvm.h             |   11 +
 arch/x86/include/uapi/asm/svm.h             |    2 +
 drivers/crypto/ccp/sev-dev-tio.h            |  111 ++
 drivers/crypto/ccp/sev-dev.h                |   19 +
 drivers/iommu/amd/amd_iommu_types.h         |    3 +
 drivers/iommu/iommufd/iommufd_private.h     |    3 +
 include/asm-generic/pci_iomap.h             |    4 +
 include/linux/amd-iommu.h                   |    2 +
 include/linux/device.h                      |    4 +
 include/linux/device/bus.h                  |    3 +
 include/linux/dma-direct.h                  |    8 +
 include/linux/ioport.h                      |    2 +
 include/linux/kvm_host.h                    |    2 +
 include/linux/pci-doe.h                     |    4 +
 include/linux/pci-ide.h                     |   19 +-
 include/linux/pci.h                         |    2 +-
 include/linux/psp-sev.h                     |   61 +-
 include/linux/swiotlb.h                     |    8 +
 include/linux/tsm.h                         |  315 ++++
 include/uapi/linux/iommufd.h                |   26 +
 include/uapi/linux/kvm.h                    |   24 +
 include/uapi/linux/pci_regs.h               |    5 +-
 include/uapi/linux/psp-sev.h                |    6 +-
 include/uapi/linux/sev-guest.h              |   39 +
 arch/x86/coco/sev/core.c                    |   19 +-
 arch/x86/kvm/mmu/mmu.c                      |    6 +-
 arch/x86/kvm/svm/sev.c                      |  205 +++
 arch/x86/kvm/svm/svm.c                      |   12 +
 arch/x86/mm/ioremap.c                       |    2 +
 arch/x86/mm/mem_encrypt.c                   |    6 +
 arch/x86/virt/svm/sev.c                     |   34 +-
 drivers/crypto/ccp/sev-dev-tio.c            | 1664 ++++++++++++++++++++
 drivers/crypto/ccp/sev-dev-tsm.c            |  709 +++++++++
 drivers/crypto/ccp/sev-dev.c                |   94 +-
 drivers/iommu/amd/init.c                    |    9 +
 drivers/iommu/amd/iommu.c                   |   60 +-
 drivers/iommu/iommufd/main.c                |    6 +
 drivers/iommu/iommufd/pages.c               |   88 +-
 drivers/iommu/iommufd/viommu.c              |  112 ++
 drivers/pci/doe.c                           |    2 -
 drivers/pci/ide.c                           |  103 +-
 drivers/pci/iomap.c                         |   24 +
 drivers/pci/mmap.c                          |   11 +-
 drivers/pci/pci-sysfs.c                     |   27 +-
 drivers/pci/pci.c                           |    3 +
 drivers/pci/proc.c                          |    2 +-
 drivers/pci/tsm.c                           |  233 +++
 drivers/virt/coco/guest/tsm-guest.c         |  326 ++++
 drivers/virt/coco/host/tsm-host.c           |  551 +++++++
 drivers/virt/coco/sev-guest/sev_guest.c     |   10 +
 drivers/virt/coco/sev-guest/sev_guest_tio.c |  738 +++++++++
 drivers/virt/coco/tsm.c                     |  638 ++++++++
 kernel/resource.c                           |   48 +
 virt/kvm/kvm_main.c                         |    6 +
 Documentation/virt/coco/tsm.rst             |  132 ++
 drivers/crypto/ccp/Kconfig                  |    2 +
 drivers/pci/Kconfig                         |   15 +
 drivers/virt/coco/Kconfig                   |   14 +
 drivers/virt/coco/guest/Kconfig             |    3 +
 drivers/virt/coco/host/Kconfig              |    6 +
 drivers/virt/coco/sev-guest/Kconfig         |    1 +
 70 files changed, 6614 insertions(+), 53 deletions(-)
 create mode 100644 drivers/virt/coco/host/Makefile
 create mode 100644 drivers/crypto/ccp/sev-dev-tio.h
 create mode 100644 drivers/crypto/ccp/sev-dev-tio.c
 create mode 100644 drivers/crypto/ccp/sev-dev-tsm.c
 create mode 100644 drivers/pci/tsm.c
 create mode 100644 drivers/virt/coco/guest/tsm-guest.c
 create mode 100644 drivers/virt/coco/host/tsm-host.c
 create mode 100644 drivers/virt/coco/sev-guest/sev_guest_tio.c
 create mode 100644 drivers/virt/coco/tsm.c
 create mode 100644 Documentation/virt/coco/tsm.rst
 create mode 100644 drivers/virt/coco/host/Kconfig
Signature · 1 line
2.47.1