PCI/TSM: coco/sev-guest: Implement SEV-TIO PCIe TDISP (phase2)
Alexey Kardashevskiy
maintainercover PCI/TSM: coco/sev-guest: Implement SEV-TIO PCIe TDISP (phase2)
Here are some patches to continue enabling SEV-TIO on AMD.
SEV-TIO allows guests 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.
In order to streamline upstreaming process, a common TSM infrastructure is being developed in collaboration with Intel+ARM+RiscV. There is Documentation/driver-api/pci/tsm.rst with proposed phases:
1. IDE: encrypt PCI, host only
2. TDISP: lock + accept flow, host and guest, interface report
3. Enable secure MMIO + DMA: IOMMUFD, KVM changes
4. Device attestation: certificates, measurements
This is phase2 == basic guest support allowing TDISP CONFIG_LOCKED and RUN states, and unlocking as well.
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, extension to SEV-SNP 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 guest OS, load sev-guest.ko which registers itself as a TSM
- PCI TSM creates sysfs nodes under "tsm" subdirectory in for all TDISP-capable devices
- lock the device via:
echo tsm0 > "/sys/bus/pci/devices/0000:01:00.0/tsm/lock"
- accept the device via:
echo 1 > "/sys/bus/pci/devices/0000:01:00.0/tsm/accept"
- load the device driver:
- DMA to encrypted memory should work right away
- MMIO regions reported in TDISP interface report will be mapped as encrypted
Since one of my test devices does not use private MMIO for the main function, there is 9/9 which allows https://github.com/billfarrow/pcimem.git mapping MMIO as private.
The previous conversation is here:
https://lore.kernel.org/r/[email protected]
This is based on sha14fe8662d1a9c Dan Williams PCI/TSM: Documentation: Add Maturity Map from
https://git.kernel.org/pub/scm/linux/kernel/git/devsec/tsm.git/log/?h=staging
and 3 cherrypicks on top, please find the exact tree at:
https://github.com/AMDESE/linux-kvm/commits/tsm-staging
The host support is pushed here:
https://github.com/AMDESE/linux-kvm/commits/tsm
The SEV TIO spec:
https://www.amd.com/content/dam/amd/en/documents/epyc-technical-docs/specifications/58271.pdf
Individual patches have extra "---" comments (could have been "RFC"?)
Please comment. Thanks.
ps: quite a cc list from get_maintainers.pl.
Alexey Kardashevskiy (9):
pci/tsm: Add TDISP report blob and helpers to parse it pci/tsm: Add tsm_tdi_status
coco/sev-guest: Allow multiple source files in the driver dma/swiotlb: Stop forcing SWIOTLB for TDISP devices x86/mm: Stop forcing decrypted page state for TDISP devices x86/dma-direct: Stop changing encrypted page state for TDISP devices coco/sev-guest: Implement the guest support for SEV TIO (phase2)
RFC: PCI: Avoid needless touching of Command register
pci: Allow encrypted MMIO mapping via sysfs
arch/x86/Kconfig | 1 + drivers/virt/coco/sev-guest/Kconfig | 1 + drivers/virt/coco/sev-guest/Makefile | 6 +- arch/x86/include/asm/dma-direct.h | 39 ++ arch/x86/include/asm/sev-common.h | 1 + arch/x86/include/asm/sev.h | 13 + arch/x86/include/uapi/asm/svm.h | 13 + drivers/virt/coco/sev-guest/sev-guest.h | 20 + include/linux/pci-tsm.h | 110 +++ include/linux/pci.h | 2 +- include/linux/psp-sev.h | 31 + include/linux/swiotlb.h | 9 + include/uapi/linux/sev-guest.h | 43 ++ arch/x86/coco/sev/core.c | 53 ++ arch/x86/mm/mem_encrypt.c | 5 +- drivers/pci/mmap.c | 11 +- drivers/pci/pci-sysfs.c | 27 +- drivers/pci/probe.c | 5 + drivers/pci/proc.c | 2 +- drivers/pci/quirks.c | 9 + drivers/virt/coco/sev-guest/sev-guest.c | 23 +- drivers/virt/coco/sev-guest/tio.c | 707 ++++++++++++++++++++ drivers/virt/coco/tsm-core.c | 19 + 23 files changed, 1129 insertions(+), 21 deletions(-) create mode 100644 arch/x86/include/asm/dma-direct.h create mode 100644 drivers/virt/coco/sev-guest/sev-guest.h create mode 100644 drivers/virt/coco/sev-guest/tio.c
Signature · 1 line
2.52.0
Alexey Kardashevskiy
maintainerPATCH 1/9 pci/tsm: Add TDISP report blob and helpers to parse it
The TDI interface report is defined in PCIe r7.0, chapter "11.3.11 DEVICE_INTERFACE_REPORT". The report enumerates MMIO resources and their properties which will take effect upon transitioning to the RUN state.
Store the report in pci_tsm.
Define macros and helpers to parse the binary blob.
---
Probably pci_tsm::report could be struct tdi_report_header*?
--- include/linux/pci-tsm.h | 84 ++++++++++++++++++++ drivers/virt/coco/tsm-core.c | 19 +++++ 2 files changed, 103 insertions(+)
include/linux/pci-tsm.h +84 -0
@@ -10,6 +10,18 @@ struct tsm_dev;struct kvm ;enum pci_tsm_req_scope ; +/* Data object for measurements/certificates/attestationreport */ +struct tsm_blob { +void *data; +size_t len; +}; + +struct tsm_blob *tsm_blob_new (void *data,size_t len); +static inline void tsm_blob_free (struct tsm_blob *b) +{ +kfree (b); +} +/* * struct pci_tsm_ops - manage confidential links and security state * @link_ops: Coordinate PCIe SPDM and IDE establishment via a platform TSM.
@@ -123,6 +135,7 @@ struct pci_tsm {struct pci_dev *dsm_dev;struct tsm_dev *tsm_dev;struct pci_tdi *tdi; +struct tsm_blob *report; };/**
@@ -271,4 +284,75 @@ static inline ssize_t pci_tsm_guest_req(struct pci_dev *pdev,return -ENXIO ; }#endif + +/* +* struct tdisp_interface_id - TDISP INTERFACE_ID Definition +* +* @function_id: Identifies the function of the device hosting the TDI +* 15:0: @rid: Requester ID +* 23:16: @rseg: Requester Segment (Reserved if Requester Segment Valid is Clear) +* 24: @rseg_valid: Requester Segment Valid +* 31:25 – Reserved +* 8B - Reserved +*/ +#define TSM_TDISP_IID_REQUESTER_ID GENMASK(15, 0) +#define TSM_TDISP_IID_RSEG GENMASK(23, 16) +#define TSM_TDISP_IID_RSEG_VALID BIT(24) + +struct tdisp_interface_id { +__u32 function_id;/* TSM_TDISP_IID_xxxx */ +__u8 reserved[8 ]; +} __packed; + +#define SPDM_MEASUREMENTS_NONCE_LEN 32 +typedef __u8 spdm_measurements_nonce_t [SPDM_MEASUREMENTS_NONCE_LEN ]; + +/* +* TDI Report Structure as defined in TDISP. +*/ +#define _BITSH (x) (1 << (x)) +#define TSM_TDI_REPORT_NO_FW_UPDATE _BITSH(0)/* not updates in CONFIG_LOCKED or RUN */ +#define TSM_TDI_REPORT_DMA_NO_PASID _BITSH(1)/* TDI generates DMA requests without PASID */ +#define TSM_TDI_REPORT_DMA_PASID _BITSH(2)/* TDI generates DMA requests with PASID */ +#define TSM_TDI_REPORT_ATS _BITSH(3)/* ATS supported and enabled for the TDI */ +#define TSM_TDI_REPORT_PRS _BITSH(4)/* PRS supported and enabled for the TDI */ + +struct tdi_report_header { +__u16 interface_info;/* TSM_TDI_REPORT_xxx */ +__u16 reserved2; +__u16 msi_x_message_control; +__u16 lnr_control; +__u32 tph_control; +__u32 mmio_range_count; +} __packed; + +/* +* Each MMIO Range of the TDI is reported with the MMIO reporting offset added. +* Base and size in units of 4K pages +*/ +#define TSM_TDI_REPORT_MMIO_MSIX_TABLE BIT(0) +#define TSM_TDI_REPORT_MMIO_PBA BIT(1) +#define TSM_TDI_REPORT_MMIO_IS_NON_TEE BIT(2) +#define TSM_TDI_REPORT_MMIO_IS_UPDATABLE BIT(3) +#define TSM_TDI_REPORT_MMIO_RESERVED GENMASK(15, 4) +#define TSM_TDI_REPORT_MMIO_RANGE_ID GENMASK(31, 16) + +struct tdi_report_mmio_range { +__u64 first_page;/* First 4K page with offset added */ +__u32 num;/* Number of 4K pages in this range */ +__u32 range_attributes;/* TSM_TDI_REPORT_MMIO_xxx */ +} __packed; + +struct tdi_report_footer { +__u32 device_specific_info_len; +__u8 device_specific_info[]; +} __packed; + +#define TDI_REPORT_HDR (rep) ((struct tdi_report_header *) ((rep)->data)) +#define TDI_REPORT_MR_NUM (rep) (TDI_REPORT_HDR(rep)->mmio_range_count) +#define TDI_REPORT_MR_OFF (rep) ((struct tdi_report_mmio_range *) (TDI_REPORT_HDR(rep) + 1)) +#define TDI_REPORT_MR (rep, rangeid) TDI_REPORT_MR_OFF(rep)[rangeid] +#define TDI_REPORT_FTR (rep) ((struct tdi_report_footer *) &TDI_REPORT_MR((rep), \ + TDI_REPORT_MR_NUM(rep))) +#endif /*__PCI_TSM_H */
drivers/virt/coco/tsm-core.c +19 -0
@@ -16,6 +16,25 @@ static struct class *tsm_class;static DECLARE_RWSEM (tsm_rwsem);static DEFINE_IDA (tsm_ida); +struct tsm_blob *tsm_blob_new (void *data,size_t len) +{ +struct tsm_blob *b; + +if (!len || !data) +return NULL ; + + b =kzalloc (sizeof (*b) + len,GFP_KERNEL ); +if (!b) +return NULL ; + + b->data = (void *)b +sizeof (*b); + b->len = len; +memcpy (b->data, data, len); + +return b; +} +EXPORT_SYMBOL_GPL (tsm_blob_new); +static int match_id (struct device *dev,const void *data) { struct tsm_dev *tsm_dev = container_of(dev, struct tsm_dev, dev);
Signature · 1 line
2.52.0
Alexey Kardashevskiy
maintainerPATCH 2/9 pci/tsm: Add tsm_tdi_status
In reply to Alexey KardashevskiyDefine a structure with all info about a TDI such as TDISP status, bind state, used START_INTERFACE options and the report digest.
This will be extended and shared to the userspace.
---
Make it uapi? We might want a sysfs node per a field so probably not. For now its only user is AMD SEV TIO with a plan to expose this struct as a whole via sysfs.
--- include/linux/pci-tsm.h | 26 ++++++++++++++++++++ 1 file changed, 26 insertions(+)
include/linux/pci-tsm.h +26 -0
@@ -355,4 +355,30 @@ struct tdi_report_footer {#define TDI_REPORT_FTR (rep) ((struct tdi_report_footer *) &TDI_REPORT_MR((rep), \ TDI_REPORT_MR_NUM(rep))) +enum tsm_tdisp_state { +TDISP_STATE_CONFIG_UNLOCKED =0 , +TDISP_STATE_CONFIG_LOCKED =1 , +TDISP_STATE_RUN =2 , +TDISP_STATE_ERROR =3 , +}; + +enum tsm_tdisp_status { +TDISP_STATE_BOUND =0 , +TDISP_STATE_INVALID =1 , +TDISP_STATE_UNBOUND =2 , +}; + +struct tsm_tdi_status { +__u8 status;/* enum tsm_tdisp_status */ +__u8 state;/* enum tsm_tdisp_state */ +__u8 all_request_redirect; +__u8 bind_p2p; +__u8 lock_msix; +__u8 no_fw_update; +__u16 cache_line_size; +__u8 interface_report_digest[48 ]; +__u64 intf_report_counter; +struct tdisp_interface_id id; +} __packed; +#endif /*__PCI_TSM_H */
Signature · 1 line
2.52.0
Alexey Kardashevskiy
maintainerPATCH 3/9 coco/sev-guest: Allow multiple source files in the driver
In reply to Alexey KardashevskiyPrepare for SEV-TIO support as it is going to equal or bigger than the existing sev_guest.c which is already 700 lines and keeps growing.
No behavioural change expected.
--- drivers/virt/coco/sev-guest/Makefile | 3 ++- drivers/virt/coco/sev-guest/sev-guest.h | 16 ++++++++++++++++ drivers/virt/coco/sev-guest/sev-guest.c | 10 ++-------- 3 files changed, 20 insertions(+), 9 deletions(-)
drivers/virt/coco/sev-guest/Makefile +2 -1
@@ -1,2 +1,3 @@ # SPDX-License-Identifier: GPL-2.0-only -obj-$(CONFIG_SEV_GUEST) += sev-guest.o +obj-$(CONFIG_SEV_GUEST) += sev_guest.o +sev_guest-y += sev-guest.o
drivers/virt/coco/sev-guest/sev-guest.h new file +16 -0
@@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef __SEV_GUEST_H__ +#define __SEV_GUEST_H__ + +#include <linux/miscdevice.h> +#include <asm/sev.h> + +struct snp_guest_dev { +struct device *dev; +struct miscdevice misc; + +struct snp_msg_desc *msg_desc; +}; + +#endif /* __SEV_GUEST_H__ */
drivers/virt/coco/sev-guest/sev-guest.c +2 -8
@@ -28,19 +28,13 @@#include <uapi/linux/psp-sev.h> #include <asm/svm.h> -#include <asm/sev.h> + +#include "sev-guest.h" #define DEVICE_NAME "sev-guest"#define SVSM_MAX_RETRIES 3 -struct snp_guest_dev { -struct device *dev; -struct miscdevice misc; - -struct snp_msg_desc *msg_desc; -}; -/* * The VMPCK ID represents the key used by the SNP guest to communicate with the * SEV firmware in the AMD Secure Processor (ASP, aka PSP). By default, the key
Signature · 1 line
2.52.0
Alexey Kardashevskiy
maintainerPATCH 4/9 dma/swiotlb: Stop forcing SWIOTLB for TDISP devices
In reply to Alexey KardashevskiySWIOTLB is enforced when encrypted guest memory is detected in pci_swiotlb_detect() which is required for legacy devices.
Skip SWIOTLB for TDISP devices.
--- include/linux/swiotlb.h | 9 +++++++++ 1 file changed, 9 insertions(+)
include/linux/swiotlb.h +9 -0
@@ -173,6 +173,15 @@ static inline bool is_swiotlb_force_bounce(struct device *dev) {struct io_tlb_mem *mem = dev->dma_io_tlb_mem; +/* +* CC_ATTR_GUEST_MEM_ENCRYPT enforces SWIOTLB_FORCE in +* swiotlb_init_remap() to allow legacy devices access arbitrary +* VM encrypted memory. +* Skip it for TDISP devices capable of DMA-ing the encrypted memory. +*/ +if (device_cc_accepted (dev)) +return false; +return mem && mem->force_bounce; }
Signature · 1 line
2.52.0
Alexey Kardashevskiy
maintainerPATCH 5/9 x86/mm: Stop forcing decrypted page state for TDISP devices
In reply to Alexey KardashevskiyThe DMA subsystem does is forcing private-to-shared page conversion in force_dma_unencrypted().
Return false from force_dma_unencrypted() for TDISP devices.
--- arch/x86/mm/mem_encrypt.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
arch/x86/mm/mem_encrypt.c +3 -2
@@ -20,10 +20,11 @@bool force_dma_unencrypted (struct device *dev) {/* -* For SEV, all DMA must be to unencrypted addresses. +* dma_direct_alloc() forces page state change if private memory is +* allocated for DMA. Skip conversion if the TDISP device is accepted. */ if (cc_platform_has (CC_ATTR_GUEST_MEM_ENCRYPT )) -return true; +return !device_cc_accepted (dev);/* * For SME, all DMA must be to unencrypted addresses if the
Signature · 1 line
2.52.0
Alexey Kardashevskiy
maintainerPATCH 6/9 x86/dma-direct: Stop changing encrypted page state for TDISP devices
In reply to Alexey KardashevskiyTDISP devices operate in CoCo VMs only and capable of accessing encrypted guest memory.
Currently when SME is on, the DMA subsystem forces the SME mask in DMA handles in phys_to_dma() which assumes IOMMU pass through which is never the case with CoCoVM running with a TDISP device.
Define X86's version of phys_to_dma() to skip leaking SME mask to the device.
---
Doing this in the generic version breaks ARM which uses the SME mask in DMA handles, hence ARCH_HAS_PHYS_TO_DMA.
pci_device_add() enforces the FFFF_FFFF coherent DMA mask so dma_alloc_coherent() fails when SME=on, this is how I ended up fixing phys_to_dma() and not quite sure it is the right fix.
--- arch/x86/Kconfig | 1 + arch/x86/include/asm/dma-direct.h | 39 ++++++++++++++++++++ 2 files changed, 40 insertions(+)
arch/x86/Kconfig +1 -0
@@ -112,6 +112,7 @@ config X86 select ARCH_HAS_UBSAN select ARCH_HAS_DEBUG_WX select ARCH_HAS_ZONE_DMA_SET if EXPERT + select ARCH_HAS_PHYS_TO_DMA select ARCH_HAVE_NMI_SAFE_CMPXCHG select ARCH_HAVE_EXTRA_ELF_NOTES select ARCH_MHP_MEMMAP_ON_MEMORY_ENABLE
arch/x86/include/asm/dma-direct.h new file +39 -0
@@ -0,0 +1,39 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef ASM_X86_DMA_DIRECT_H +#define ASM_X86_DMA_DIRECT_H 1 + +static inline dma_addr_t __phys_to_dma (struct device *dev,phys_addr_t paddr) +{ +if (dev->dma_range_map) +return translate_phys_to_dma (dev, paddr); +return paddr; +} + +static inline dma_addr_t phys_to_dma (struct device *dev,phys_addr_t paddr) +{ +/* +* TDISP devices only work in CoCoVMs and rely on IOMMU to +* decide on the memory encryption. +* Stop leaking the SME mask in DMA handles and return +* the real address. +*/ +if (device_cc_accepted (dev)) +return dma_addr_unencrypted (__phys_to_dma (dev, paddr)); + +return dma_addr_encrypted (__phys_to_dma (dev, paddr)); +} + +static inline phys_addr_t dma_to_phys (struct device *dev,dma_addr_t daddr) +{ +return daddr; +} + +static inline dma_addr_t phys_to_dma_unencrypted (struct device *dev, +phys_addr_t paddr) +{ +return dma_addr_unencrypted (__phys_to_dma (dev, paddr)); +} + +#define phys_to_dma_unencrypted phys_to_dma_unencrypted + +#endif /* ASM_X86_DMA_DIRECT_H */
Signature · 1 line
2.52.0
Alexey Kardashevskiy
maintainerPATCH 7/9 coco/sev-guest: Implement the guest support for SEV TIO (phase2)
In reply to Alexey KardashevskiyImplement the SEV-TIO (Trusted I/O) support in for AMD SEV-SNP guests.
The implementation includes Device Security Manager (DSM) operations for:
- binding a PCI function (GHCB extension) to a VM and locking the device configuration;
- receiving TDI report and configuring MMIO and DMA/sDTE;
- accepting the device into the guest TCB.
Detect the SEV-TIO support (reported via GHCB HV features) and install the SEV-TIO TSM ops.
Implement lock/accept/unlock TSM ops.
Define 2 new VMGEXIT codes for GHCB:
- TIO Guest Request to provide secure communication between a VM and the FW (for configuring MMIO and DMA);
- TIO Op for requesting the HV to bind a TDI to the VM and for starting/stopping a TDI.
--- drivers/virt/coco/sev-guest/Kconfig | 1 + drivers/virt/coco/sev-guest/Makefile | 3 + arch/x86/include/asm/sev-common.h | 1 + arch/x86/include/asm/sev.h | 13 + arch/x86/include/uapi/asm/svm.h | 13 + drivers/virt/coco/sev-guest/sev-guest.h | 4 + include/linux/psp-sev.h | 31 + include/uapi/linux/sev-guest.h | 43 ++ arch/x86/coco/sev/core.c | 53 ++ drivers/virt/coco/sev-guest/sev-guest.c | 13 + drivers/virt/coco/sev-guest/tio.c | 707 ++++++++++++++++++++ 11 files changed, 882 insertions(+)
drivers/virt/coco/sev-guest/Kconfig +1 -0
@@ -3,6 +3,7 @@ config SEV_GUEST default m depends on AMD_MEM_ENCRYPT select TSM_REPORTS + select PCI_TSM if PCI help SEV-SNP firmware provides the guest a mechanism to communicate with the PSP without risk from a malicious hypervisor who wishes to read,
drivers/virt/coco/sev-guest/Makefile +3 -0
@@ -1,3 +1,6 @@ # SPDX-License-Identifier: GPL-2.0-only obj-$(CONFIG_SEV_GUEST) += sev_guest.o sev_guest-y += sev-guest.o +ifeq ($(CONFIG_PCI_TSM),y) +sev_guest-y += tio.o +endif
arch/x86/include/asm/sev-common.h +1 -0
@@ -137,6 +137,7 @@ enum psc_op {#define GHCB_HV_FT_SNP BIT_ULL(0)#define GHCB_HV_FT_SNP_AP_CREATION BIT_ULL(1)#define GHCB_HV_FT_SNP_MULTI_VMPL BIT_ULL(5) +#define GHCB_HV_FT_SNP_SEV_TIO BIT_ULL(7)/* * SNP Page State Change NAE event
arch/x86/include/asm/sev.h +13 -0
@@ -149,6 +149,8 @@ struct snp_req_data {unsigned long resp_gpa;unsigned long data_gpa;unsigned int data_npages; +unsigned int guest_rid; +unsigned long param; };#define MAX_AUTHTAG_LEN 32
@@ -179,6 +181,14 @@ enum msg_type {SNP_MSG_TSC_INFO_REQ =17 ,SNP_MSG_TSC_INFO_RSP , +TIO_MSG_TDI_INFO_REQ =19 , +TIO_MSG_TDI_INFO_RSP =20 , +TIO_MSG_MMIO_VALIDATE_REQ =21 , +TIO_MSG_MMIO_VALIDATE_RSP =22 , +TIO_MSG_MMIO_CONFIG_REQ =23 , +TIO_MSG_MMIO_CONFIG_RSP =24 , +TIO_MSG_SDTE_WRITE_REQ =25 , +TIO_MSG_SDTE_WRITE_RSP =26 ,SNP_MSG_TYPE_MAX };
@@ -597,6 +607,9 @@ static inline void sev_evict_cache(void *va, int npages) } } +bool sev_tio_ghcb_supported (void ); +int sev_tio_op (u32 guest_rid,unsigned int op,u64 *fw_err,u64 *tdi_id); +#else /* !CONFIG_AMD_MEM_ENCRYPT */ #define snp_vmpl 0
arch/x86/include/uapi/asm/svm.h +13 -0
@@ -122,6 +122,17 @@#define SVM_VMGEXIT_SAVIC_REGISTER_GPA 0#define SVM_VMGEXIT_SAVIC_UNREGISTER_GPA 1#define SVM_VMGEXIT_SAVIC_SELF_GPA ~0ULL +#define SVM_VMGEXIT_SEV_TIO_GUEST_REQUEST 0x80000020 +#define SVM_VMGEXIT_SEV_TIO_GUEST_REQUEST_PARAM_STATE BIT(0) +#define SVM_VMGEXIT_SEV_TIO_GUEST_REQUEST_PARAM_REPORT BIT(3) +#define SVM_VMGEXIT_SEV_TIO_OP 0x80000021 +#define SVM_VMGEXIT_SEV_TIO_OP_PARAM (guest_id, action) ((u64)(action)<<32|(guest_id)) +#define SVM_VMGEXIT_SEV_TIO_OP_ACTION (exitinfo1) ((exitinfo1)>>32) +#define SVM_VMGEXIT_SEV_TIO_OP_GUEST_ID (exitinfo1) ((exitinfo1) & 0xFFFFFFFF) +#define SVM_VMGEXIT_SEV_TIO_OP_BIND 0 +#define SVM_VMGEXIT_SEV_TIO_OP_UNBIND 1 +#define SVM_VMGEXIT_SEV_TIO_OP_RUN 2 +#define SVM_VMGEXIT_SEV_TIO_OP_STOP 3#define SVM_VMGEXIT_HV_FEATURES 0x8000fffd#define SVM_VMGEXIT_TERM_REQUEST 0x8000fffe#define SVM_VMGEXIT_TERM_REASON (reason_set, reason_code) \
@@ -245,6 +256,8 @@ { SVM_VMGEXIT_GUEST_REQUEST, "vmgexit_guest_request" }, \ { SVM_VMGEXIT_EXT_GUEST_REQUEST, "vmgexit_ext_guest_request" }, \ { SVM_VMGEXIT_AP_CREATION, "vmgexit_ap_creation" }, \ + { SVM_VMGEXIT_SEV_TIO_GUEST_REQUEST, "vmgexit_sev_tio_guest_request" }, \ + { SVM_VMGEXIT_SEV_TIO_OP, "vmgexit_sev_tio_op" }, \ { SVM_VMGEXIT_HV_FEATURES, "vmgexit_hypervisor_feature" }, \ { SVM_EXIT_ERR, "invalid_guest_state" }
drivers/virt/coco/sev-guest/sev-guest.h +4 -0
@@ -11,6 +11,10 @@ struct snp_guest_dev {struct miscdevice misc;struct snp_msg_desc *msg_desc; + + struct tsm_dev *tsmdev; }; +void sev_guest_tsm_set_ops (bool set,struct snp_guest_dev *snp_dev); +#endif /* __SEV_GUEST_H__ */
include/linux/psp-sev.h +31 -0
@@ -1050,4 +1050,35 @@ static inline bool sev_is_snp_ciphertext_hiding_supported(void) { return false;#endif /* CONFIG_CRYPTO_DEV_SP_PSP */ +/* +* Status codes from TIO_MSG_MMIO_VALIDATE_REQ +*/ +enum mmio_validate_status { +MMIO_VALIDATE_SUCCESS =0 , +MMIO_VALIDATE_INVALID_TDI =1 , +MMIO_VALIDATE_TDI_UNBOUND =2 , +MMIO_VALIDATE_NOT_ASSIGNED =3 , +MMIO_VALIDATE_NOT_IO =4 , +MMIO_VALIDATE_NOT_UNIFORM =5 ,/* The Validated bit is not uniformly set for +the MMIO subrange */ +MMIO_VALIDATE_NOT_IMMUTABLE =6 ,/* At least one page does not have immutable bit set +when validated bit is clear */ +MMIO_VALIDATE_NOT_MAPPED =7 ,/* At least one page is not mapped to the expected GPA */ +MMIO_VALIDATE_NOT_REPORTED =8 ,/* The provided MMIO range ID is not reported in +the interface report */ +MMIO_VALIDATE_OUT_OF_RANGE =9 ,/* The subrange is out the MMIO range in +the interface report */ +MMIO_VALIDATE_NOT_4K =10 ,/* At least one page is not 4K page size */ +}; + +/* +* Status codes from TIO_MSG_SDTE_WRITE_REQ +*/ +enum sdte_write_status { +SDTE_WRITE_SUCCESS =0 , +SDTE_WRITE_INVALID_TDI =1 , +SDTE_WRITE_TDI_NOT_BOUND =2 , +SDTE_WRITE_RESERVED =3 , +}; +#endif /* __PSP_SEV_H__ */
include/uapi/linux/sev-guest.h +43 -0
53 lines not on this page · raw message
arch/x86/coco/sev/core.c +53 -0
83 lines not on this page · raw message
drivers/virt/coco/sev-guest/sev-guest.c +13 -0
@@ -46,6 +46,10 @@ static int vmpck_id = -1;module_param (vmpck_id, int,0444 );MODULE_PARM_DESC (vmpck_id,"The VMPCK ID to use when communicating with the PSP." ); +static bool tsm_enable = true; +module_param (tsm_enable, bool,0644 ); +MODULE_PARM_DESC (tsm_enable,"Enable SEV TIO" ); +static inline struct snp_guest_dev *to_snp_dev (struct file *file) {struct miscdevice *dev = file->private_data;
@@ -667,6 +671,13 @@ static int __init sev_guest_probe(struct platform_device *pdev) snp_dev->msg_desc = mdesc;dev_info (dev,"Initialized SEV guest driver (using VMPCK%d communication key)\n" , mdesc->vmpck_id); + +if (!sev_tio_ghcb_supported ()) + tsm_enable = false; + +if (tsm_enable) +sev_guest_tsm_set_ops (true, snp_dev); +return 0 ; e_msg_init:
@@ -680,6 +691,8 @@ static void __exit sev_guest_remove(struct platform_device *pdev)struct snp_guest_dev *snp_dev =platform_get_drvdata (pdev);snp_msg_free (snp_dev->msg_desc); +if (tsm_enable) +sev_guest_tsm_set_ops (false, snp_dev);misc_deregister (&snp_dev->misc); }
drivers/virt/coco/sev-guest/tio.c new file +707 -0
707 lines not on this page · raw message
Signature · 1 line
2.52.0
Alexey Kardashevskiy
maintainerPATCH 8/9 RFC: PCI: Avoid needless touching of Command register
In reply to Alexey KardashevskiyOnce locked, a TDI's MSE and BME are not allowed to be cleared.
Skip INTx test as TEE-capable PCI functions are most likely IOV VFs anyway and those do not support INTx at all.
Add a quirk preventing the probing code from disabling MSE when updating 64bit BAR (which cannot be done atomically).
Note that normally this happens too early and likely not really needed for the device attestation happening long after PCI probing.
---
This is also handled in QEMU - it will block clearing BME and MSE (normally happening on modprobe/rmmod) as long as the TDI is CONFIG_LOCKED or RUN.
This only patch is not enough but reduces the number of unwanted writes to MSE/BME.
Also, SRIOV cannot have INTx so pci_intx_mask_broken() could skip VFs too, should it?
--- drivers/pci/probe.c | 5 +++++ drivers/pci/quirks.c | 9 +++++++++ 2 files changed, 14 insertions(+)
drivers/pci/probe.c +5 -0
@@ -1930,6 +1930,11 @@ static int pci_intx_mask_broken(struct pci_dev *dev) {u16 orig, toggle, new; +if (dev->devcap &PCI_EXP_DEVCAP_TEE ) { +pci_warn_once (dev,"(TIO) Disable check for broken INTX" ); +return 1 ; + } +pci_read_config_word (dev,PCI_COMMAND , &orig); toggle = orig ^PCI_COMMAND_INTX_DISABLE ;pci_write_config_word (dev,PCI_COMMAND , toggle);
drivers/pci/quirks.c +9 -0
@@ -316,6 +316,15 @@ static void quirk_mmio_always_on(struct pci_dev *dev)DECLARE_PCI_FIXUP_CLASS_EARLY (PCI_ANY_ID ,PCI_ANY_ID ,PCI_CLASS_BRIDGE_HOST ,8 , quirk_mmio_always_on); +static void quirk_mmio_tio_always_on (struct pci_dev *dev) +{ +if (dev->devcap &PCI_EXP_DEVCAP_TEE ) { +pci_info (dev,"(TIO) quirk: MMIO always On" ); + dev->mmio_always_on =1 ; + } +} +DECLARE_PCI_FIXUP_EARLY (PCI_ANY_ID ,PCI_ANY_ID , quirk_mmio_tio_always_on); +/* * The Mellanox Tavor device gives false positive parity errors. Disable * parity error reporting.
Signature · 1 line
2.52.0
Alexey Kardashevskiy
maintainerPATCH 9/9 pci: Allow encrypted MMIO mapping via sysfs
In reply to Alexey KardashevskiyAdd another resource#d_enc to allow mapping MMIO as an encrypted/private region.
Unlike resourceN_wc, the node is added always as ability to map MMIO as private depends on negotiation with the TSM which happens quite late.
--- include/linux/pci.h | 2 +- drivers/pci/mmap.c | 11 +++++++- drivers/pci/pci-sysfs.c | 27 +++++++++++++++----- drivers/pci/proc.c | 2 +- 4 files changed, 32 insertions(+), 10 deletions(-)
include/linux/pci.h +1 -1
@@ -2217,7 +2217,7 @@ pci_alloc_irq_vectors(struct pci_dev *dev, unsigned int min_vecs,*/ int pci_mmap_resource_range (struct pci_dev *dev,int bar,struct vm_area_struct *vma, -enum pci_mmap_state mmap_state,int write_combine); +enum pci_mmap_state mmap_state,int write_combine,int enc);#ifndef arch_can_pci_mmap_wc#define arch_can_pci_mmap_wc () 0
drivers/pci/mmap.c +10 -1
@@ -23,7 +23,7 @@ static const struct vm_operations_struct pci_phys_vm_ops = {int pci_mmap_resource_range (struct pci_dev *pdev,int bar,struct vm_area_struct *vma, -enum pci_mmap_state mmap_state,int write_combine) +enum pci_mmap_state mmap_state,int write_combine,int enc) {unsigned long size;int ret;
@@ -46,6 +46,15 @@ int pci_mmap_resource_range(struct pci_dev *pdev, int bar, vma->vm_ops = &pci_phys_vm_ops; +/* +* Calling remap_pfn_range() directly as io_remap_pfn_range() +* enforces shared mapping. +*/ +if (enc) +return remap_pfn_range (vma, vma->vm_start, vma->vm_pgoff, + vma->vm_end - vma->vm_start, +pgprot_encrypted (vma->vm_page_prot)); +return io_remap_pfn_range (vma, vma->vm_start, vma->vm_pgoff, vma->vm_end - vma->vm_start, vma->vm_page_prot);
drivers/pci/pci-sysfs.c +20 -7
@@ -1104,7 +1104,7 @@ void pci_remove_legacy_files(struct pci_bus *b)* Use the regular PCI mapping routines to map a PCI resource into userspace. */ static int pci_mmap_resource (struct kobject *kobj,const struct bin_attribute *attr, -struct vm_area_struct *vma,int write_combine) +struct vm_area_struct *vma,int write_combine,int enc) {struct pci_dev *pdev =to_pci_dev (kobj_to_dev (kobj));int bar = (unsigned long )attr->private;
@@ -1124,21 +1124,28 @@ static int pci_mmap_resource(struct kobject *kobj, const struct bin_attribute *a mmap_type = res->flags &IORESOURCE_MEM ? pci_mmap_mem : pci_mmap_io; -return pci_mmap_resource_range (pdev, bar, vma, mmap_type, write_combine); +return pci_mmap_resource_range (pdev, bar, vma, mmap_type, write_combine, enc); }static int pci_mmap_resource_uc (struct file *filp,struct kobject *kobj,const struct bin_attribute *attr,struct vm_area_struct *vma) { -return pci_mmap_resource (kobj, attr, vma,0 ); +return pci_mmap_resource (kobj, attr, vma,0 ,0 ); }static int pci_mmap_resource_wc (struct file *filp,struct kobject *kobj,const struct bin_attribute *attr,struct vm_area_struct *vma) { -return pci_mmap_resource (kobj, attr, vma,1 ); +return pci_mmap_resource (kobj, attr, vma,1 ,0 ); +} + +static int pci_mmap_resource_enc (struct file *filp,struct kobject *kobj, +const struct bin_attribute *attr, +struct vm_area_struct *vma) +{ +return pci_mmap_resource (kobj, attr, vma,0 ,1 ); } static ssize_t pci_resource_io(struct file *filp, struct kobject *kobj,
@@ -1232,7 +1239,7 @@ static void pci_remove_resource_files(struct pci_dev *pdev) } } -static int pci_create_attr (struct pci_dev *pdev,int num,int write_combine) +static int pci_create_attr (struct pci_dev *pdev,int num,int write_combine,int enc) {/* allocate attribute structure, piggyback attribute name */ int name_len = write_combine ?13 :10 ;
@@ -1250,6 +1257,9 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)if (write_combine) {sprintf (res_attr_name,"resource%d_wc" , num); res_attr->mmap = pci_mmap_resource_wc; + }else if (enc) { +sprintf (res_attr_name,"resource%d_enc" , num); + res_attr->mmap = pci_mmap_resource_enc; }else {sprintf (res_attr_name,"resource%d" , num);if (pci_resource_flags (pdev, num) &IORESOURCE_IO ) {
@@ -1310,11 +1320,14 @@ static int pci_create_resource_files(struct pci_dev *pdev)if (!pci_resource_len (pdev, i))continue ; - retval =pci_create_attr (pdev, i,0 ); + retval =pci_create_attr (pdev, i,0 ,0 );/* for prefetchable resources, create a WC mappable file */ if (!retval &&arch_can_pci_mmap_wc () && pdev->resource[i].flags &IORESOURCE_PREFETCH ) - retval =pci_create_attr (pdev, i,1 ); + retval =pci_create_attr (pdev, i,1 ,0 ); +/* Add node for private MMIO mapping */ +if (!retval) + retval =pci_create_attr (pdev, i,0 ,1 );if (retval) {pci_remove_resource_files (pdev);return retval;
drivers/pci/proc.c +1 -1
@@ -288,7 +288,7 @@ static int proc_bus_pci_mmap(struct file *file, struct vm_area_struct *vma)/* Adjust vm_pgoff to be the offset within the resource */ vma->vm_pgoff -= start >>PAGE_SHIFT ; ret =pci_mmap_resource_range (dev, i, vma, - fpriv->mmap_state, write_combine); + fpriv->mmap_state, write_combine,0 );if (ret <0 )return ret;
Signature · 1 line
2.52.0
Borislav Petkov
maintainerRe: [PATCH kernel 7/9] coco/sev-guest: Implement the guest support for SEV TIO (phase2)
In reply to Alexey KardashevskiyQuoted 12 lines · Alexey Kardashevskiy
Implement the SEV-TIO (Trusted I/O) support in for AMD SEV-SNP guests.
The implementation includes Device Security Manager (DSM) operations for:
- binding a PCI function (GHCB extension) to a VM and locking the device configuration;
- receiving TDI report and configuring MMIO and DMA/sDTE;
- accepting the device into the guest TCB.Detect the SEV-TIO support (reported via GHCB HV features) and install the SEV-TIO TSM ops.
Quoted 7 lines
Implement lock/accept/unlock TSM ops.
Define 2 new VMGEXIT codes for GHCB:
- TIO Guest Request to provide secure communication between a VM and the FW (for configuring MMIO and DMA);
- TIO Op for requesting the HV to bind a TDI to the VM and for starting/stopping a TDI.
Just from staring at that huuuge diff, those bullets and things above are basically begging to be separate patches...
Signature · 1 line
Small device. Typos and formatting crap
Re: [PATCH kernel 1/9] pci/tsm: Add TDISP report blob and helpers to parse it
In reply to Alexey KardashevskiyQuoted 13 lines · Alexey Kardashevskiy
The TDI interface report is defined in PCIe r7.0, chapter "11.3.11
DEVICE_INTERFACE_REPORT". The report enumerates MMIO resources and their properties which will take effect upon transitioning to the RUN state.Store the report in
pci_tsm.Define macros and helpers to parse the binary blob.
Signed-off-by Alexey Kardashevskiy <[email protected]>---
Probably
pci_tsm::reportcould be struct tdi_report_header*?
[..]
Quoted 14 lines
include/linux/pci-tsm.h +14
-0+struct tdi_report_header { +__u16 interface_info;/* TSM_TDI_REPORT_xxx */ +__u16 reserved2; +__u16 msi_x_message_control; +__u16 lnr_control; +__u32 tph_control; +__u32 mmio_range_count; +} __packed; + +/* +* Each MMIO Range of the TDI is reported with the MMIO reporting offset added. +* Base and size in units of 4K pages +*/ +#define TSM_TDI_REPORT_MMIO_MSIX_TABLE BIT(0)
include/linux/pci-tsm.h static inline ssize_t pci_tsm_guest_req(struct pci_dev *pdev, · line 343
Quoted 10 lines
include/linux/pci-tsm.h +10
-0+#define TSM_TDI_REPORT_MMIO_PBA BIT(1) +#define TSM_TDI_REPORT_MMIO_IS_NON_TEE BIT(2) +#define TSM_TDI_REPORT_MMIO_IS_UPDATABLE BIT(3) +#define TSM_TDI_REPORT_MMIO_RESERVED GENMASK(15, 4) +#define TSM_TDI_REPORT_MMIO_RANGE_ID GENMASK(31, 16) + +struct tdi_report_mmio_range { +__u64 first_page;/* First 4K page with offset added */ +__u32 num;/* Number of 4K pages in this range */ +__u32 range_attributes;/* TSM_TDI_REPORT_MMIO_xxx */
Those should be __le64 and le32, right? But see below for another option...
Quoted 4 lines
include/linux/pci-tsm.h +4
-0+} __packed; + +struct tdi_report_footer { +__u32 device_specific_info_len;
include/linux/pci-tsm.h static inline ssize_t pci_tsm_guest_req(struct pci_dev *pdev, · line 357
Quoted 10 lines
include/linux/pci-tsm.h +10
-0+__u8 device_specific_info[]; +} __packed; + +#define TDI_REPORT_HDR (rep) ((struct tdi_report_header *) ((rep)->data)) +#define TDI_REPORT_MR_NUM (rep) (TDI_REPORT_HDR(rep)->mmio_range_count) +#define TDI_REPORT_MR_OFF (rep) ((struct tdi_report_mmio_range *) (TDI_REPORT_HDR(rep) + 1)) +#define TDI_REPORT_MR (rep, rangeid) TDI_REPORT_MR_OFF(rep)[rangeid] +#define TDI_REPORT_FTR (rep) ((struct tdi_report_footer *) &TDI_REPORT_MR((rep), \ + TDI_REPORT_MR_NUM(rep))) +
So we all have a version of a patch like this and the general style suggestion I have is to just parse this layout with typical offsets+bitfield definitions.
This follows the precedent, admittedly tiny, of the DOE definitions in pci_regs.h. See:
/* DOE Data Object - note not actually registers */
I have a patch that parses the TDISP report with these defines:
/*
* PCIe ECN TEE Device Interface Security Protocol (TDISP)
*
* Device Interface Report data object layout as defined by PCIe r7.0 section
* 11.3.11
*/
#define PCI_TSM_DEVIF_REPORT_INFO 0
#define PCI_TSM_DEVIF_REPORT_MSIX 4
#define PCI_TSM_DEVIF_REPORT_LNR 6
#define PCI_TSM_DEVIF_REPORT_TPH 8
#define PCI_TSM_DEVIF_REPORT_MMIO_COUNT 12
#define PCI_TSM_DEVIF_REPORT_MMIO_PFN 0 /* An interface report 'pfn' is 4K in size */ #define PCI_TSM_DEVIF_REPORT_MMIO_NR_PFNS 8 #define PCI_TSM_DEVIF_REPORT_MMIO_ATTR 12 #define PCI_TSM_DEVIF_REPORT_MMIO_ATTR_MSIX_TABLE BIT(0) #define PCI_TSM_DEVIF_REPORT_MMIO_ATTR_MSIX_PBA BIT(1) #define PCI_TSM_DEVIF_REPORT_MMIO_ATTR_IS_NON_TEE BIT(2) #define PCI_TSM_DEVIF_REPORT_MMIO_ATTR_IS_UPDATABLE BIT(3) #define PCI_TSM_DEVIF_REPORT_MMIO_ATTR_RANGE_ID GENMASK(31, 16) #define PCI_TSM_DEVIF_REPORT_MMIO_SIZE (16)
#define PCI_TSM_DEVIF_REPORT_BASE_SIZE(nr_mmio) (16 + nr_mmio * PCI_TSM_DEVIF_REPORT_MMIO_SIZE)
Any strong feelings one way or the other? I have a mild preference for this offset+bitfields approach.
Re: [PATCH kernel 2/9] pci/tsm: Add tsm_tdi_status
In reply to Alexey KardashevskiyQuoted 11 lines · Alexey Kardashevskiy
Define a structure with all info about a TDI such as TDISP status, bind state, used
START_INTERFACEoptions and the report digest.This will be extended and shared to the userspace.
Signed-off-by Alexey Kardashevskiy <[email protected]>---
Make it uapi? We might want a sysfs node per a field so probably not. For now its only user is AMD SEV TIO with a plan to expose this struct as a whole via sysfs.
Say more about what this uapi when sysfs already has lock+accept indications?
Or are you just talking about exporting the TDISP report as a binary blob?
I think the kernel probably wants a generic abstraction for asserting that the tsm layer believes the report remains valid between fetch and run. In other words I am not sure arch features like intf_report_counter ever show up anywhere in uapi outside of debugfs.
Re: [PATCH kernel 1/9] pci/tsm: Add TDISP report blob and helpers to parse it
In reply to [email protected]Quoted 21 lines · On Wed, Feb 25, 2026, at 07:16, [email protected] wrote:
Alexey Kardashevskiy wrote:
[..]Quoted 19 lines
include/linux/pci-tsm.h +19
-0+struct tdi_report_header { +__u16 interface_info;/* TSM_TDI_REPORT_xxx */ +__u16 reserved2; +__u16 msi_x_message_control; +__u16 lnr_control; +__u32 tph_control; +__u32 mmio_range_count; +} __packed; + +/* +* Each MMIO Range of the TDI is reported with the MMIO reporting offset added. +* Base and size in units of 4K pages +*/ +#define TSM_TDI_REPORT_MMIO_MSIX_TABLE BIT(0) +#define TSM_TDI_REPORT_MMIO_PBA BIT(1) +#define TSM_TDI_REPORT_MMIO_IS_NON_TEE BIT(2) +#define TSM_TDI_REPORT_MMIO_IS_UPDATABLE BIT(3) +#define TSM_TDI_REPORT_MMIO_RESERVED GENMASK(15, 4) +#define TSM_TDI_REPORT_MMIO_RANGE_ID GENMASK(31, 16)
Quoted 8 lines
include/linux/pci-tsm.h static inline ssize_t pci_tsm_guest_req(struct pci_dev *pdev, · line 343
Quoted 5 lines
include/linux/pci-tsm.h +5
-0+ +struct tdi_report_mmio_range { +__u64 first_page;/* First 4K page with offset added */ +__u32 num;/* Number of 4K pages in this range */ +__u32 range_attributes;/* TSM_TDI_REPORT_MMIO_xxx */ Those should be
__le64and le32, right? But see below for another option...
If these come from DMA transfers from a device, yes.
Quoted 1 line
Quoted 1 line
+}
__packed;
The structure appears to be allocated with kzalloc, so it is always aligned to __alignof__(u64) or higher, and it's better to drop the __packed annotation.
Quoted 23 lines
/*
* PCIe ECN TEE Device Interface Security Protocol (TDISP) *
* Device Interface Report data object layout as defined by PCIe r7.0
section
* 11.3.11
*/
#definePCI_TSM_DEVIF_REPORT_INFO0
#definePCI_TSM_DEVIF_REPORT_MSIX4
#definePCI_TSM_DEVIF_REPORT_LNR6
#definePCI_TSM_DEVIF_REPORT_TPH8
#definePCI_TSM_DEVIF_REPORT_MMIO_COUNT12
#definePCI_TSM_DEVIF_REPORT_MMIO_PFN0 /* An interface report 'pfn' is 4K in size */#define PCI_TSM_DEVIF_REPORT_MMIO_NR_PFNS 8 #define PCI_TSM_DEVIF_REPORT_MMIO_ATTR 12 #define PCI_TSM_DEVIF_REPORT_MMIO_ATTR_MSIX_TABLE BIT(0) #define PCI_TSM_DEVIF_REPORT_MMIO_ATTR_MSIX_PBA BIT(1) #define PCI_TSM_DEVIF_REPORT_MMIO_ATTR_IS_NON_TEE BIT(2) #define PCI_TSM_DEVIF_REPORT_MMIO_ATTR_IS_UPDATABLE BIT(3) #define PCI_TSM_DEVIF_REPORT_MMIO_ATTR_RANGE_ID GENMASK(31, 16) #define PCI_TSM_DEVIF_REPORT_MMIO_SIZE (16)
Quoted 5 lines
#define
PCI_TSM_DEVIF_REPORT_BASE_SIZE(nr_mmio)(16 +nr_mmio*PCI_TSM_DEVIF_REPORT_MMIO_SIZE)Any strong feelings one way or the other? I have a mild preference for this offset+bitfields approach.
I assume by bitfield you mean the macros above, not the C structure syntax with ':', right? The macros seem fine to me, while C bitfields again would make the code nonportable due to architecture specific bitfield positioning.
Arnd
Re: [PATCH kernel 4/9] dma/swiotlb: Stop forcing SWIOTLB for TDISP devices
In reply to Alexey KardashevskiyQuoted 16 lines · Alexey Kardashevskiy
SWIOTLB is enforced when encrypted guest memory is detected in
pci_swiotlb_detect()which is required for legacy devices.Skip SWIOTLB for TDISP devices.
Signed-off-by Alexey Kardashevskiy <[email protected]>--- include/linux/swiotlb.h | 9 +++++++++ 1 file changed, 9 insertions(+)include/linux/swiotlb.h +0
-0@@ -173,6 +173,15 @@ static inline bool is_swiotlb_force_bounce(struct device *dev) {
include/linux/swiotlb.h static inline bool is_swiotlb_force_bounce(struct device *dev) · line 183
Quoted 10 lines
include/linux/swiotlb.h +8
-0struct io_tlb_mem *mem = dev->dma_io_tlb_mem; +/* +* CC_ATTR_GUEST_MEM_ENCRYPT enforces SWIOTLB_FORCE in +* swiotlb_init_remap() to allow legacy devices access arbitrary +* VM encrypted memory. +* Skip it for TDISP devices capable of DMA-ing the encrypted memory. +*/ +if (device_cc_accepted (dev)) +return false;
I worry this further muddies the meaning of the swiotlb force option. What if you want to force swiotlb operation on accepted devices?
For example:
@@ -173,7 +176,13 @@ static inline bool is_swiotlb_force_bounce(struct device *dev)
{
struct io_tlb_mem *mem = dev->dma_io_tlb_mem;- return mem && mem->force_bounce;
+ if (!mem)
+ return false;
+ if (mem->force_bounce)
+ return true;
+ if (mem->bounce_unaccepted && !device_cc_accepted(dev))
+ return true;
+ return false;
}
void swiotlb_init(bool addressing_limited, unsigned int flags);
Robin Murphy
reviewerRe: [PATCH kernel 4/9] dma/swiotlb: Stop forcing SWIOTLB for TDISP devices
In reply to Alexey KardashevskiyQuoted 16 lines · Alexey Kardashevskiy
SWIOTLB is enforced when encrypted guest memory is detected in
pci_swiotlb_detect()which is required for legacy devices.Skip SWIOTLB for TDISP devices.
Signed-off-by Alexey Kardashevskiy <[email protected]>--- include/linux/swiotlb.h | 9 +++++++++ 1 file changed, 9 insertions(+)include/linux/swiotlb.h +0
-0@@ -173,6 +173,15 @@ static inline bool is_swiotlb_force_bounce(struct device *dev) {
include/linux/swiotlb.h static inline bool is_swiotlb_force_bounce(struct device *dev) · line 183
Quoted 10 lines
include/linux/swiotlb.h +8
-0struct io_tlb_mem *mem = dev->dma_io_tlb_mem; +/* +* CC_ATTR_GUEST_MEM_ENCRYPT enforces SWIOTLB_FORCE in +* swiotlb_init_remap() to allow legacy devices access arbitrary +* VM encrypted memory. +* Skip it for TDISP devices capable of DMA-ing the encrypted memory. +*/ +if (device_cc_accepted (dev)) +return false;
This seems backwards - how does it make sense for arch code to force SWIOTLB globally on the grounds that all DMA must be to shared memory, but then generic code override that because it claims to know better?
I'd expect to see something more like:
if (is_cc_platform && !device_cc_accepted) return true;
here, and then get rid of the rest of the (ab)use of SWIOTLB_FORCE for this purpose entirely.
However there is the fiddly aspect that it's not necessarily strictly enough to just un-force SWIOTLB; we really want to actively ensure that no private memory can *ever* end up getting bounced through a shared SWIOTLB buffer. The private/shared state is really a property of the individual DMA mappings, though, rather than an overall property of the device itself (since a device that's trusted to access private memory isn't necessarily prohibited from still also accessing shared memory as well), hmmm...
Thanks,
Robin.
Quoted 4 lines
include/linux/swiotlb.h +1
-0+return mem && mem->force_bounce; }
Re: [PATCH kernel 5/9] x86/mm: Stop forcing decrypted page state for TDISP devices
In reply to Alexey KardashevskiyQuoted 15 lines · Alexey Kardashevskiy
The DMA subsystem does is forcing private-to-shared page conversion in
force_dma_unencrypted().Return false from
force_dma_unencrypted()for TDISP devices.Signed-off-by Alexey Kardashevskiy <[email protected]>--- arch/x86/mm/mem_encrypt.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)arch/x86/mm/mem_encrypt.c +0
-0
arch/x86/mm/mem_encrypt.c line 24
Quoted 6 lines
arch/x86/mm/mem_encrypt.c +2
-1@@ -20,10 +20,11 @@bool force_dma_unencrypted (struct device *dev) {/* -* For SEV, all DMA must be to unencrypted addresses. +* dma_direct_alloc() forces page state change if private memory is +* allocated for DMA. Skip conversion if the TDISP device is accepted.
Looks ok, but I would not reference "TDISP" here. TDISP is the PCI "accept" protocol. Other buses might accept devices via other bus-specific protocols.
Robin Murphy
reviewerRe: [PATCH kernel 6/9] x86/dma-direct: Stop changing encrypted page state for TDISP devices
In reply to Alexey KardashevskiyQuoted 7 lines · Alexey Kardashevskiy
TDISP devices operate in CoCo VMs only and capable of accessing encrypted guest memory.
Currently when SME is on, the DMA subsystem forces the SME mask in DMA handles in
phys_to_dma()which assumes IOMMU pass through which is never the case with CoCoVM running with a TDISP device.
Quoted 8 lines
Define X86's version of
phys_to_dma()to skip leaking SME mask to the device.Signed-off-by Alexey Kardashevskiy <[email protected]>---
Doing this in the generic version breaks ARM which uses the SME mask in DMA handles, hence
ARCH_HAS_PHYS_TO_DMA.
That smells a bit off... In CCA we should be in the same boat, wherein a trusted device can access memory at a DMA address based on its "normal" (private) GPA, rather than having to be redirected to the shared alias (it's really not an "SME mask" in that sense at all).
I guess this comes back to the point I just raised on the previous patch - the current assumption is that devices cannot access private memory at all, and thus phys_to_dma() is implicitly only dealing with the mechanics of how the given device accesses shared memory. Once that no longer holds, I don't see how we can find the right answer without also consulting the relevant state of paddr itself, and that really *should* be able to be commonly abstracted across CoCo environments. And if in the process of that we could untangle the "implicit vs. explicit SME mask for shared memory or non-CoCo SME" case from common code and punt *that* into an x86-specific special case, all the better :)
Thanks,
Robin.
Quoted 65 lines
pci_device_add()enforces theFFFF_FFFFcoherent DMA mask sodma_alloc_coherent()fails when SME=on, this is how I ended up fixingphys_to_dma()and not quite sure it is the right fix.--- arch/x86/Kconfig | 1 + arch/x86/include/asm/dma-direct.h | 39 ++++++++++++++++++++ 2 files changed, 40 insertions(+)arch/x86/Kconfig +1
-0@@ -112,6 +112,7 @@ config X86 select ARCH_HAS_UBSAN select ARCH_HAS_DEBUG_WX select ARCH_HAS_ZONE_DMA_SET if EXPERT + select ARCH_HAS_PHYS_TO_DMA select ARCH_HAVE_NMI_SAFE_CMPXCHG select ARCH_HAVE_EXTRA_ELF_NOTES select ARCH_MHP_MEMMAP_ON_MEMORY_ENABLEarch/x86/include/asm/dma-direct.h new file +39
-0@@ -0,0 +1,39 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef ASM_X86_DMA_DIRECT_H +#define ASM_X86_DMA_DIRECT_H 1 + +static inline dma_addr_t __phys_to_dma (struct device *dev,phys_addr_t paddr) +{ +if (dev->dma_range_map) +return translate_phys_to_dma (dev, paddr); +return paddr; +} + +static inline dma_addr_t phys_to_dma (struct device *dev,phys_addr_t paddr) +{ +/* +* TDISP devices only work in CoCoVMs and rely on IOMMU to +* decide on the memory encryption. +* Stop leaking the SME mask in DMA handles and return +* the real address. +*/ +if (device_cc_accepted (dev)) +return dma_addr_unencrypted (__phys_to_dma (dev, paddr)); + +return dma_addr_encrypted (__phys_to_dma (dev, paddr)); +} + +static inline phys_addr_t dma_to_phys (struct device *dev,dma_addr_t daddr) +{ +return daddr; +} + +static inline dma_addr_t phys_to_dma_unencrypted (struct device *dev, +phys_addr_t paddr) +{ +return dma_addr_unencrypted (__phys_to_dma (dev, paddr)); +} + +#define phys_to_dma_unencrypted phys_to_dma_unencrypted + +#endif /* ASM_X86_DMA_DIRECT_H */
Robin Murphy
reviewerRe: [PATCH kernel 4/9] dma/swiotlb: Stop forcing SWIOTLB for TDISP devices
In reply to [email protected]Quoted 19 lines · On 2026-02-25 4:30 pm, [email protected] wrote:
Quoted 18 lines · Alexey Kardashevskiy
SWIOTLB is enforced when encrypted guest memory is detected in
pci_swiotlb_detect()which is required for legacy devices.Skip SWIOTLB for TDISP devices.
Signed-off-by Alexey Kardashevskiy <[email protected]>--- include/linux/swiotlb.h | 9 +++++++++ 1 file changed, 9 insertions(+)include/linux/swiotlb.h +0
-0@@ -173,6 +173,15 @@ static inline bool is_swiotlb_force_bounce(struct device *dev) {struct io_tlb_mem *mem = dev->dma_io_tlb_mem;
Quoted 11 lines
include/linux/swiotlb.h static inline bool is_swiotlb_force_bounce(struct device *dev) · line 183
Quoted 8 lines
include/linux/swiotlb.h +8
-0+/* +* CC_ATTR_GUEST_MEM_ENCRYPT enforces SWIOTLB_FORCE in +* swiotlb_init_remap() to allow legacy devices access arbitrary +* VM encrypted memory. +* Skip it for TDISP devices capable of DMA-ing the encrypted memory. +*/ +if (device_cc_accepted (dev)) +return false;I worry this further muddies the meaning of the swiotlb force option. What if you want to force swiotlb operation on accepted devices?
For that we'd need a whole other private SWIOTLB plus the logic to decide which one to use in the first place. And if you really wanted an option to forcibly expose all DMA through shared memory regardless of TDISP and friends, that would logically want to be a higher-level CoCo option rather than belonging to SWIOTLB itself ;)
Thanks,
Robin.
Quoted 17 lines
For example:
(quoted diff) +7
-1@@ -173,7 +176,13 @@ static inline bool is_swiotlb_force_bounce(struct device *dev) { struct io_tlb_mem *mem = dev->dma_io_tlb_mem; - return mem && mem->force_bounce; + if (!mem) + return false; + if (mem->force_bounce) + return true; + if (mem->bounce_unaccepted && !device_cc_accepted(dev)) + return true; + return false; } void swiotlb_init(bool addressing_limited, unsigned int flags);
Re: [PATCH kernel 4/9] dma/swiotlb: Stop forcing SWIOTLB for TDISP devices
Quoted 32 lines · Robin Murphy
Quoted 19 lines · On 2026-02-25 4:30 pm, [email protected] wrote:
Quoted 18 lines · Alexey Kardashevskiy
SWIOTLB is enforced when encrypted guest memory is detected in
pci_swiotlb_detect()which is required for legacy devices.Skip SWIOTLB for TDISP devices.
Signed-off-by Alexey Kardashevskiy <[email protected]>--- include/linux/swiotlb.h | 9 +++++++++ 1 file changed, 9 insertions(+)include/linux/swiotlb.h +0
-0@@ -173,6 +173,15 @@ static inline bool is_swiotlb_force_bounce(struct device *dev) {struct io_tlb_mem *mem = dev->dma_io_tlb_mem;Quoted 11 lines
include/linux/swiotlb.h static inline bool is_swiotlb_force_bounce(struct device *dev) · line 183
Quoted 8 lines
include/linux/swiotlb.h +8
-0+/* +* CC_ATTR_GUEST_MEM_ENCRYPT enforces SWIOTLB_FORCE in +* swiotlb_init_remap() to allow legacy devices access arbitrary +* VM encrypted memory. +* Skip it for TDISP devices capable of DMA-ing the encrypted memory. +*/ +if (device_cc_accepted (dev)) +return false;I worry this further muddies the meaning of the swiotlb force option. What if you want to force swiotlb operation on accepted devices?
Quoted 2 lines
For that we'd need a whole other private SWIOTLB plus the logic to decide which one to use in the first place.
In this case I was still considering that swiotlb is still implicitly only shared address bouncining. Indeed, a whole other "private_swiotlb" mechanism would be needed for private bouncing. Not clear there is a need for that at present.
Even for this swiotlb=force for "accepted" devices I only see a potential kernel development use case, not a deployment use case.
Quoted 3 lines
option to forcibly expose all DMA through shared memory regardless of TDISP and friends, that would logically want to be a higher-level CoCo option rather than belonging to SWIOTLB itself ;)
As I have it below, yes, CoCo opts into this bounce_unaccepted mechanism.
As to your other question:
Quoted 3 lines
(since a device that's trusted to access private memory isn't necessarily prohibited from still also accessing shared memory as well), hmmm...
The specification allows it, but Linux DMA mapping core is not yet ready for it. So the expectation to start is that the device loses access to its original shared IOMMU mappings when converted to private operation.
So on ARM where shared addresses are high, it is future work to figure out how an accepted device might also access shared mappings outside the device's dma_mask.
Quoted 17 lines
Quoted 17 lines
For example:
(quoted diff) +7
-1@@ -173,7 +176,13 @@ static inline bool is_swiotlb_force_bounce(struct device *dev) { struct io_tlb_mem *mem = dev->dma_io_tlb_mem; - return mem && mem->force_bounce; + if (!mem) + return false; + if (mem->force_bounce) + return true; + if (mem->bounce_unaccepted && !device_cc_accepted(dev)) + return true; + return false; } void swiotlb_init(bool addressing_limited, unsigned int flags);
Re: [PATCH kernel 6/9] x86/dma-direct: Stop changing encrypted page state for TDISP devices
In reply to Robin MurphyQuoted 14 lines · Robin Murphy
Quoted 13 lines · Alexey Kardashevskiy
TDISP devices operate in CoCo VMs only and capable of accessing encrypted guest memory.
Currently when SME is on, the DMA subsystem forces the SME mask in DMA handles in
phys_to_dma()which assumes IOMMU pass through which is never the case with CoCoVM running with a TDISP device.Define X86's version of
phys_to_dma()to skip leaking SME mask to the device.Signed-off-by Alexey Kardashevskiy <[email protected]>---
Quoted 7 lines
Quoted 2 lines
Doing this in the generic version breaks ARM which uses the SME mask in DMA handles, hence
ARCH_HAS_PHYS_TO_DMA.That smells a bit off... In CCA we should be in the same boat, wherein a trusted device can access memory at a DMA address based on its "normal" (private) GPA, rather than having to be redirected to the shared alias (it's really not an "SME mask" in that sense at all).
Not quite, no, CCA *is* in the same boat as TDX, not SEV-SNP. Only SEV-SNP has this concept that the DMA handle for private memory is the dma_addr_unencrypted() conversion (C-bit masked) of the CPU physical address. For CCA and TDX the typical expectation of dma_addr_encrypted() for accepted devices holds. It just so happens that dma_addr_encrypted() does not munge the address on is a nop conversion for CCA and TDX.
Alexey Kardashevskiy
maintainerRe: [PATCH kernel 2/9] pci/tsm: Add tsm_tdi_status
In reply to [email protected]Quoted 13 lines · On 25/2/26 17:33, [email protected] wrote:
Quoted 11 lines · Alexey Kardashevskiy
Define a structure with all info about a TDI such as TDISP status, bind state, used
START_INTERFACEoptions and the report digest.This will be extended and shared to the userspace.
Signed-off-by Alexey Kardashevskiy <[email protected]>---
Make it uapi? We might want a sysfs node per a field so probably not. For now its only user is AMD SEV TIO with a plan to expose this struct as a whole via sysfs.
Quoted 5 lines
Say more about what this uapi when sysfs already has lock+accept indications?
Or are you just talking about exporting the TDISP report as a binary blob?
I mean that between lock and accept the guest userspace wants to read certs/measurements/report to do the attestation. And it will want to know these blobs digests. And probably the TDI state. Although successful write to lock() is an indication of CONFIG_LOCKED, and accept == RUN.
We do not do real attestation in phase2 but the report is required anyway to enable private MMIO so I started shuffling with this structure.
Quoted 4 lines
I think the kernel probably wants a generic abstraction for asserting that the tsm layer believes the report remains valid between fetch and run. In other words I am not sure arch features like
intf_report_counterever show up anywhere in uapi outside of debugfs.
True, this is a shorter (not shorter enough :) ) version of SEV-TIO's TDI_INFO. Thanks,
Signature · 1 line
Alexey
Alexey Kardashevskiy
maintainerRe: [PATCH kernel 1/9] pci/tsm: Add TDISP report blob and helpers to parse it
In reply to [email protected]Quoted 33 lines · On 25/2/26 17:16, [email protected] wrote:
Quoted 13 lines · Alexey Kardashevskiy
The TDI interface report is defined in PCIe r7.0, chapter "11.3.11
DEVICE_INTERFACE_REPORT". The report enumerates MMIO resources and their properties which will take effect upon transitioning to the RUN state.Store the report in
pci_tsm.Define macros and helpers to parse the binary blob.
Signed-off-by Alexey Kardashevskiy <[email protected]>---
Probably
pci_tsm::reportcould be struct tdi_report_header*?[..]
Quoted 18 lines
include/linux/pci-tsm.h +18
-0+struct tdi_report_header { +__u16 interface_info;/* TSM_TDI_REPORT_xxx */ +__u16 reserved2; +__u16 msi_x_message_control; +__u16 lnr_control; +__u32 tph_control; +__u32 mmio_range_count; +} __packed; + +/* +* Each MMIO Range of the TDI is reported with the MMIO reporting offset added. +* Base and size in units of 4K pages +*/ +#define TSM_TDI_REPORT_MMIO_MSIX_TABLE BIT(0) +#define TSM_TDI_REPORT_MMIO_PBA BIT(1) +#define TSM_TDI_REPORT_MMIO_IS_NON_TEE BIT(2) +#define TSM_TDI_REPORT_MMIO_IS_UPDATABLE BIT(3) +#define TSM_TDI_REPORT_MMIO_RESERVED GENMASK(15, 4)
Quoted 8 lines
include/linux/pci-tsm.h static inline ssize_t pci_tsm_guest_req(struct pci_dev *pdev, · line 343
Quoted 6 lines
include/linux/pci-tsm.h +6
-0+#define TSM_TDI_REPORT_MMIO_RANGE_ID GENMASK(31, 16) + +struct tdi_report_mmio_range { +__u64 first_page;/* First 4K page with offset added */ +__u32 num;/* Number of 4K pages in this range */ +__u32 range_attributes;/* TSM_TDI_REPORT_MMIO_xxx */ Those should be
__le64and le32, right?
Oh yes.
Quoted 40 lines
But see below for another
option...Quoted 4 lines
include/linux/pci-tsm.h +4
-0+} __packed; + +struct tdi_report_footer { +__u32 device_specific_info_len;include/linux/pci-tsm.h static inline ssize_t pci_tsm_guest_req(struct pci_dev *pdev, · line 357
Quoted 10 lines
include/linux/pci-tsm.h +10
-0+__u8 device_specific_info[]; +} __packed; + +#define TDI_REPORT_HDR (rep) ((struct tdi_report_header *) ((rep)->data)) +#define TDI_REPORT_MR_NUM (rep) (TDI_REPORT_HDR(rep)->mmio_range_count) +#define TDI_REPORT_MR_OFF (rep) ((struct tdi_report_mmio_range *) (TDI_REPORT_HDR(rep) + 1)) +#define TDI_REPORT_MR (rep, rangeid) TDI_REPORT_MR_OFF(rep)[rangeid] +#define TDI_REPORT_FTR (rep) ((struct tdi_report_footer *) &TDI_REPORT_MR((rep), \ + TDI_REPORT_MR_NUM(rep))) +So we all have a version of a patch like this and the general style suggestion I have is to just parse this layout with typical offsets+bitfield definitions.
This follows the precedent, admittedly tiny, of the DOE definitions in
pci_regs.h. See:/* DOE Data Object - note not actually registers */I have a patch that parses the TDISP report with these defines:
/*
* PCIe ECN TEE Device Interface Security Protocol (TDISP)
*
* Device Interface Report data object layout as defined by PCIe r7.0 section
* 11.3.11
*/
#definePCI_TSM_DEVIF_REPORT_INFO0
#definePCI_TSM_DEVIF_REPORT_MSIX4
#definePCI_TSM_DEVIF_REPORT_LNR6
#definePCI_TSM_DEVIF_REPORT_TPH8
#definePCI_TSM_DEVIF_REPORT_MMIO_COUNT12
Quoted 3 lines
#define PCI_TSM_DEVIF_REPORT_MMIO_PFN 0 /* An interface report 'pfn' is 4K in size */ #define PCI_TSM_DEVIF_REPORT_MMIO_NR_PFNS 8 #define PCI_TSM_DEVIF_REPORT_MMIO_ATTR 12
I cannot easily see from these what the sizes are. And how many of each.
Quoted 10 lines
#define PCI_TSM_DEVIF_REPORT_MMIO_ATTR_MSIX_TABLE BIT(0) #define PCI_TSM_DEVIF_REPORT_MMIO_ATTR_MSIX_PBA BIT(1) #define PCI_TSM_DEVIF_REPORT_MMIO_ATTR_IS_NON_TEE BIT(2) #define PCI_TSM_DEVIF_REPORT_MMIO_ATTR_IS_UPDATABLE BIT(3) #define PCI_TSM_DEVIF_REPORT_MMIO_ATTR_RANGE_ID GENMASK(31, 16) #define PCI_TSM_DEVIF_REPORT_MMIO_SIZE (16)#define
PCI_TSM_DEVIF_REPORT_BASE_SIZE(nr_mmio)(16 +nr_mmio*PCI_TSM_DEVIF_REPORT_MMIO_SIZE)Any strong feelings one way or the other? I have a mild preference for this offset+bitfields approach.
My variant is just like this (may be need to put it in the comment):
tdi_report_header
tdi_report_mmio_range[]tdi_report_footer
imho easier on eyes. I can live with either if the majority votes for it. Thanks.
Signature · 1 line
Alexey
Alexey Kardashevskiy
maintainerRe: [PATCH kernel 4/9] dma/swiotlb: Stop forcing SWIOTLB for TDISP devices
In reply to Robin MurphyQuoted 20 lines · Robin Murphy
Quoted 19 lines · Alexey Kardashevskiy
SWIOTLB is enforced when encrypted guest memory is detected in
pci_swiotlb_detect()which is required for legacy devices.Skip SWIOTLB for TDISP devices.
Signed-off-by Alexey Kardashevskiy <[email protected]>---
include/linux/swiotlb.h| 9 +++++++++1 file changed, 9 insertions(+)include/linux/swiotlb.h +2
-0@@ -173,6 +173,15 @@ static inline bool is_swiotlb_force_bounce(struct device *dev) { struct io_tlb_mem *mem = dev->dma_io_tlb_mem; + /* +* CC_ATTR_GUEST_MEM_ENCRYPT enforces SWIOTLB_FORCE in
Quoted 8 lines
include/linux/swiotlb.h static inline bool is_swiotlb_force_bounce(struct device *dev) · line 183
Quoted 6 lines
include/linux/swiotlb.h +6
-0+* swiotlb_init_remap() to allow legacy devices access arbitrary +* VM encrypted memory. +* Skip it for TDISP devices capable of DMA-ing the encrypted memory. +*/ + if (device_cc_accepted(dev)) + return false;This seems backwards - how does it make sense for arch code to force SWIOTLB globally on the grounds that all DMA must be to shared memory, but then generic code override that because it claims to know better?
True. I have the itch to remove SWIOTLB_FORCE from pci_swiotlb_detect(), this may be the other way to go.
Quoted 3 lines
I'd expect to see something more like:
if (
is_cc_platform&& !device_cc_accepted)
device_cc_accepted() implies is_cc_platform.
Quoted 5 lines
return true;
here, and then get rid of the rest of the (ab)use of
SWIOTLB_FORCEfor this purpose entirely.However there is the fiddly aspect that it's not necessarily strictly enough to just un-force SWIOTLB; we really want to actively ensure that no private memory can *ever* end up getting bounced through a shared SWIOTLB buffer. The private/shared state is really a property of the individual DMA mappings, though, rather than an overall property of the device itself
At the moment it is a property of the device though, for AMD, at least.
Quoted 1 line
(since a device that's trusted to access private memory isn't necessarily prohibited from still also accessing shared memory as well), hmmm...
True. With vTOM ("everything above TopOfMemory is shared", not using it now) or secure vIOMMU all sorts of accesses is possible. Thanks,
Quoted 8 lines
Thanks,
Robin.Quoted 3 lines
include/linux/swiotlb.h +1
-0+ return mem && mem->force_bounce; }
Signature · 1 line
Alexey
Re: [PATCH kernel 8/9] RFC: PCI: Avoid needless touching of Command register
In reply to Alexey KardashevskiyQuoted 1 line · Alexey Kardashevskiy
Once locked, a TDI's MSE and BME are not allowed to be cleared.
Disallowed by hardware, by spec, by convention? Spec reference would be helpful.
Quoted 2 lines
Skip INTx test as TEE-capable PCI functions are most likely IOV VFs anyway and those do not support INTx at all.
"Most likely" doesn't sound like a convincing argument for skipping something.
Quoted 2 lines
Add a quirk preventing the probing code from disabling MSE when updating 64bit BAR (which cannot be done atomically).
Say more about this please. If there's something special about this device, I'd like to know exactly what that is.
Quoted 2 lines
Note that normally this happens too early and likely not really needed for the device attestation happening long after PCI probing.
I don't follow this either. Please make it meaningful for non-TEE/TDI/whatever experts. And mention that context in the subject line.
drivers/pci/probe.c static int pci_intx_mask_broken(struct pci_dev *dev) · line 1935
Quoted 7 lines
drivers/pci/probe.c +3
-0@@ -1930,6 +1930,11 @@ static int pci_intx_mask_broken(struct pci_dev *dev) {u16 orig, toggle, new; +if (dev->devcap &PCI_EXP_DEVCAP_TEE ) { +pci_warn_once (dev,"(TIO) Disable check for broken INTX" ); +return 1 ;
s/INTX/INTx/
Why do users need to know this? Why as a warning? What can they do about it? "TIO"?
Re: [PATCH kernel 8/9] RFC: PCI: Avoid needless touching of Command register
In reply to Alexey KardashevskiyQuoted 18 lines · Alexey Kardashevskiy
Once locked, a TDI's MSE and BME are not allowed to be cleared.
Skip INTx test as TEE-capable PCI functions are most likely IOV VFs anyway and those do not support INTx at all.
Add a quirk preventing the probing code from disabling MSE when updating 64bit BAR (which cannot be done atomically).
Note that normally this happens too early and likely not really needed for the device attestation happening long after PCI probing.
Signed-off-by Alexey Kardashevskiy <[email protected]>---
This is also handled in QEMU - it will block clearing BME and MSE (normally happening on modprobe/rmmod) as long as the TDI is
CONFIG_LOCKEDor RUN.
Quoted 5 lines
This only patch is not enough but reduces the number of unwanted writes to MSE/BME.
Also, SRIOV cannot have INTx so
pci_intx_mask_broken()could skip VFs too, should it?
Locked command register management is handled by QEMU. This patch needs quite a bit more explanation about what use case it is trying to solve.
Re: [PATCH kernel 1/9] pci/tsm: Add TDISP report blob and helpers to parse it
In reply to Alexey KardashevskiyAlexey Kardashevskiy wrote:
[..]
Quoted 1 line
I cannot easily see from these what the sizes are. And how many of each.
Same as any other offset+bitmask code, the size is encoded in the accessor.
Arnd caught that I misspoke when I said offset+bitfield.
Quoted 12 lines
Quoted 10 lines
#define PCI_TSM_DEVIF_REPORT_MMIO_ATTR_MSIX_TABLE BIT(0) #define PCI_TSM_DEVIF_REPORT_MMIO_ATTR_MSIX_PBA BIT(1) #define PCI_TSM_DEVIF_REPORT_MMIO_ATTR_IS_NON_TEE BIT(2) #define PCI_TSM_DEVIF_REPORT_MMIO_ATTR_IS_UPDATABLE BIT(3) #define PCI_TSM_DEVIF_REPORT_MMIO_ATTR_RANGE_ID GENMASK(31, 16) #define PCI_TSM_DEVIF_REPORT_MMIO_SIZE (16)#define
PCI_TSM_DEVIF_REPORT_BASE_SIZE(nr_mmio)(16 +nr_mmio*PCI_TSM_DEVIF_REPORT_MMIO_SIZE)Any strong feelings one way or the other? I have a mild preference for this offset+bitfields approach.
Quoted 5 lines
My variant is just like this (may be need to put it in the comment):
tdi_report_header
tdi_report_mmio_range[]tdi_report_footer
Does the kernel have any use for the footer besides conveying it to userspace?
Quoted 1 line
imho easier on eyes. I can live with either if the majority votes for it. Thanks.
Aneesh also already has 'structs+bitmask', I will switch to that.
Alexey Kardashevskiy
maintainerRe: [PATCH kernel 7/9] coco/sev-guest: Implement the guest support for SEV TIO (phase2)
In reply to Borislav PetkovQuoted 15 lines · Borislav Petkov
Quoted 14 lines · Alexey Kardashevskiy
Implement the SEV-TIO (Trusted I/O) support in for AMD SEV-SNP guests.
The implementation includes Device Security Manager (DSM) operations for:
- binding a PCI function (GHCB extension) to a VM and locking the device configuration;
- receiving TDI report and configuring MMIO and DMA/sDTE;
- accepting the device into the guest TCB.Detect the SEV-TIO support (reported via GHCB HV features) and install the SEV-TIO TSM ops.
Implement lock/accept/unlock TSM ops.
Quoted 7 lines
Quoted 5 lines
Define 2 new VMGEXIT codes for GHCB:
- TIO Guest Request to provide secure communication between a VM and the FW (for configuring MMIO and DMA);
- TIO Op for requesting the HV to bind a TDI to the VM and for starting/stopping a TDI.Just from staring at that huuuge diff, those bullets and things above are basically begging to be separate patches...
I struggle to separate these more without making individual patches useless for any purpose, even splitting between maintainership area. People often define things in separate patches and then use them and I dislike such approach for reviewing purposes - hard to follow. I can ditch more stuff (like TIO_GUID_CERTIFICATES - just noticed) but it is not much :-/
Signature · 1 line
Alexey
Alexey Kardashevskiy
maintainerRe: [PATCH kernel 1/9] pci/tsm: Add TDISP report blob and helpers to parse it
In reply to [email protected]Quoted 19 lines · On 26/2/26 13:34, [email protected] wrote:
Alexey Kardashevskiy wrote:
[..]Quoted 1 line
I cannot easily see from these what the sizes are. And how many of each.
Same as any other offset+bitmask code, the size is encoded in the accessor.
Arnd caught that I misspoke when I said offset+bitfield.
Quoted 12 lines
Quoted 10 lines
Quoted 1 line
#define
PCI_TSM_DEVIF_REPORT_MMIO_ATTR_MSIX_TABLEBIT(0)#define PCI_TSM_DEVIF_REPORT_MMIO_ATTR_MSIX_PBA BIT(1) #define PCI_TSM_DEVIF_REPORT_MMIO_ATTR_IS_NON_TEE BIT(2) #define PCI_TSM_DEVIF_REPORT_MMIO_ATTR_IS_UPDATABLE BIT(3) #define PCI_TSM_DEVIF_REPORT_MMIO_ATTR_RANGE_ID GENMASK(31, 16) #define PCI_TSM_DEVIF_REPORT_MMIO_SIZE (16)#define
PCI_TSM_DEVIF_REPORT_BASE_SIZE(nr_mmio)(16 +nr_mmio*PCI_TSM_DEVIF_REPORT_MMIO_SIZE)Any strong feelings one way or the other? I have a mild preference for this offset+bitfields approach.
Quoted 8 lines
Quoted 5 lines
My variant is just like this (may be need to put it in the comment):
tdi_report_header
tdi_report_mmio_range[]tdi_report_footerDoes the kernel have any use for the footer besides conveying it to userspace?
PCIe says:
Example of such device specific information include:
• A network device may include receive-side scaling (RSS) related information such as the RSS hash and mappings to the virtual station interface (VSI) queues, etc.
• A NVMe device may include information about the associated name spaces, mapping of name space to command queue-pair mappings, etc.
• Accelerators may report capabilities such as algorithms supported, queue depths, etc
Sounds to me like something the device driver would be interested in.
Quoted 4 lines
Quoted 2 lines
imho easier on eyes. I can live with either if the majority votes for it. Thanks.
Aneesh also already has 'structs+bitmask', I will switch to that.
oh I just found it, more or less my version :) I can add pci_tdisp_ prefixes, should I? Thanks,
Signature · 1 line
Alexey
Alexey Kardashevskiy
maintainerRe: [PATCH kernel 8/9] RFC: PCI: Avoid needless touching of Command register
In reply to Bjorn HelgaasQuoted 5 lines · Bjorn Helgaas
Quoted 1 line · Alexey Kardashevskiy
Once locked, a TDI's MSE and BME are not allowed to be cleared.
Disallowed by hardware, by spec, by convention? Spec reference would be helpful.
By the PCIe spec, the TDISP part. Once the device in CONFIG_LOCKED or RUN, clearing MSE or BME will destroy this state == will go to the ERROR state. PCIe r7, "Figure 11-5 TDISP State Machine".
Then, if it was CONFIG_LOCKED - the device won't be able to go to the RUN state which allows DMA to/from encrypted memory and encrypted MMIO. If it was RUN - the device will lose those encrypted DMA/MMIO abilities.
Quoted 12 lines
Quoted 2 lines
Skip INTx test as TEE-capable PCI functions are most likely IOV VFs anyway and those do not support INTx at all.
"Most likely" doesn't sound like a convincing argument for skipping something.
Quoted 2 lines
Add a quirk preventing the probing code from disabling MSE when updating 64bit BAR (which cannot be done atomically).
Say more about this please. If there's something special about this device, I'd like to know exactly what that is.
Quoted 6 lines
Quoted 2 lines
Note that normally this happens too early and likely not really needed for the device attestation happening long after PCI probing.
I don't follow this either. Please make it meaningful for non-TEE/TDI/whatever experts. And mention that context in the subject line.
Well, frankly, I have this patch for ages and originally QEMU did not intercept zeroing of BME/MSE and just by having this patch, I could get my prototype working without that QEMU hack.
Then, even though the QEMU hack works, it is kind of muddy as when a device driver wants to clear BME to, say, stop DMA - and in reality it won't stop. So I suspect the QEMU hack won't always be enough and we will have to teach the PCI subsystem to not clear BME/MSE in some cases.
Hence the patch, to highlight rather unexpected writes to the PCI command register which are not that harmless anymore.
I'll drop it if it is no use to anyone even with the above.
Quoted 4 lines
Quoted 4 lines
drivers/pci/probe.c +0
-0@@ -1930,6 +1930,11 @@ static int pci_intx_mask_broken(struct pci_dev *dev) {u16 orig, toggle, new;
Quoted 8 lines
drivers/pci/probe.c static int pci_intx_mask_broken(struct pci_dev *dev) · line 1935
Quoted 3 lines
drivers/pci/probe.c +3
-0+if (dev->devcap &PCI_EXP_DEVCAP_TEE ) { +pci_warn_once (dev,"(TIO) Disable check for broken INTX" ); +return 1 ;s/INTX/INTx/
Why do users need to know this? Why as a warning? What can they do about it? "TIO"?
ah, sorry, a leftover. Thanks,
Signature · 1 line
Alexey
Alexey Kardashevskiy
maintainerRe: [PATCH kernel 6/9] x86/dma-direct: Stop changing encrypted page state for TDISP devices
In reply to [email protected]Quoted 23 lines · On 26/2/26 08:35, [email protected] wrote:
Quoted 14 lines · Robin Murphy
Quoted 13 lines · Alexey Kardashevskiy
TDISP devices operate in CoCo VMs only and capable of accessing encrypted guest memory.
Currently when SME is on, the DMA subsystem forces the SME mask in DMA handles in
phys_to_dma()which assumes IOMMU pass through which is never the case with CoCoVM running with a TDISP device.Define X86's version of
phys_to_dma()to skip leaking SME mask to the device.Signed-off-by Alexey Kardashevskiy <[email protected]>---
Quoted 7 lines
Quoted 2 lines
Doing this in the generic version breaks ARM which uses the SME mask in DMA handles, hence
ARCH_HAS_PHYS_TO_DMA.That smells a bit off... In CCA we should be in the same boat, wherein a trusted device can access memory at a DMA address based on its "normal" (private) GPA, rather than having to be redirected to the shared alias (it's really not an "SME mask" in that sense at all).
Quoted 6 lines
Not quite, no, CCA *is* in the same boat as TDX, not SEV-SNP. Only SEV-SNP has this concept that the DMA handle for private memory is the
dma_addr_unencrypted()conversion (C-bit masked) of the CPU physical address. For CCA and TDX the typical expectation ofdma_addr_encrypted()for accepted devices holds. It just so happens thatdma_addr_encrypted()does not munge the address on is a nop conversion for CCA and TDX.
OTOH TDX and SNP do not leak SME mask to DMA handles, and ARM does.
Sounds like what, we need sme_dma_me_mask in addition to sme_me_mask? Scary.
Signature · 1 line
Alexey
Borislav Petkov
maintainerRe: [PATCH kernel 7/9] coco/sev-guest: Implement the guest support for SEV TIO (phase2)
In reply to Alexey KardashevskiyQuoted 1 line · Alexey Kardashevskiy
I struggle to separate these more without making individual patches useless for any purpose
You sound like someone who hasn't been reviewing patches and scratching his head how to approach such a conglomerate as yours which does many things at once...
The rule is very simple actually: a patch should do one logical thing only. And no more. It doesn't matter whether the patch is "useless" by itself. It matters only whether it is reviewable and one can to a certain degree see that the transformation it contains is relatively bugfree.
And I'm very sure that when you start reviewing patches, you'll be pretty much asking people sending conglomerates like yours, to split them.
Thx.
Signature · 1 line
Small device. Typos and formatting crap
Re: [PATCH kernel 1/9] pci/tsm: Add TDISP report blob and helpers to parse it
In reply to Alexey KardashevskiyAlexey Kardashevskiy wrote:
[..]
Quoted 13 lines
Quoted 2 lines
Does the kernel have any use for the footer besides conveying it to userspace?
PCIe says:
Example of such device specific information include:
• A network device may include receive-side scaling (RSS) related information such as the RSS hash and mappings to the virtual station interface (VSI) queues, etc.
• A NVMe device may include information about the associated name spaces, mapping of name space to command queue-pair mappings, etc.
• Accelerators may report capabilities such as algorithms supported, queue depths, etc
Quoted 1 line
Sounds to me like something the device driver would be interested in.
That is not the concern. The concern is how does Linux maintain a convention around these use case so that common semantics converge on a common implementation expectations.
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
imho easier on eyes. I can live with either if the majority votes for it. Thanks.
Aneesh also already has 'structs+bitmask', I will switch to that.
oh I just found it, more or less my version :) I can add
pci_tdisp_prefixes, should I? Thanks,
I have a patch brewing that moves interface report consumption into encrypted resource population for ioremap() to consider. I will send that out shortly.
Re: [PATCH kernel 6/9] x86/dma-direct: Stop changing encrypted page state for TDISP devices
In reply to Robin MurphyQuoted 7 lines · Robin Murphy
I guess this comes back to the point I just raised on the previous patch - the current assumption is that devices cannot access private memory at all, and thus
phys_to_dma()is implicitly only dealing with the mechanics of how the given device accesses shared memory. Once that no longer holds, I don't see how we can find the right answer without also consulting the relevant state of paddr itself, and that really *should* be able to be commonly abstracted across CoCo environments.
Definately, I think building on this is a good place to start
https://lore.kernel.org/all/[email protected]/
Probably this series needs to take DMA_ATTR_CC_DECRYPTED and push it down into the phys_to_dma() and make the swiotlb shared allocation code force set it.
But what value is stored in the phys_addr_t for shared pages on the three arches? Does ARM and Intel set the high GPA/IPA bit in the phys_addr or do they set it through the pgprot? What does AMD do?
ie can we test a bit in the phys_addr_t to reliably determine if it is shared or private?
Quoted 3 lines
Quoted 3 lines
pci_device_add()enforces theFFFF_FFFFcoherent DMA mask sodma_alloc_coherent()fails when SME=on, this is how I ended up fixingphys_to_dma()and not quite sure it is the right fix.
Does AMD have the shared/private GPA split like ARM and Intel do? Ie shared is always at a high GPA? What is the SME mask?
Jason
Re: [PATCH kernel 4/9] dma/swiotlb: Stop forcing SWIOTLB for TDISP devices
In reply to [email protected]Quoted 7 lines · On Wed, Feb 25, 2026 at 12:57:01PM -0800, [email protected] wrote:
Quoted 3 lines
(since a device that's trusted to access private memory isn't necessarily prohibited from still also accessing shared memory as well), hmmm...
The specification allows it, but Linux DMA mapping core is not yet ready for it. So the expectation to start is that the device loses access to its original shared IOMMU mappings when converted to private operation.
Yes, the underlying translation changes, but no, it doesn't loose DMA access to any shared pages, it just goes through the T=1 IOMMU now.
The T=1 IOMMU will still have them mapped on all three platforms AFAIK. On TDX/CCA the CPU and IOMMU S2 tables are identical, so of course the shared pages are mapped. On AMD there is only one IOMMU so the page must also be mapped or non-TDISP is broken.
When this TDISP awareness is put in the DMA API it needs to be done in a way that allows DMA_ATTR_CC_DECRYPTED to keep working for TDISP devices.
This is important because we are expecting these sorts of things to work as part of integrating non-TDISP RDMA devices into CC guests. We can't loose access to the shared pages that are shared with the non-TDISP devices...
Quoted 3 lines
So on ARM where shared addresses are high, it is future work to figure out how an accepted device might also access shared mappings outside the device's
dma_mask.
ARM has a "solution" right now. The location of the high bit is controlled by the VMM and the VMM cannot create a CC VM where the IPA space exceeds the dma_mask of any assigned device.
Thus the VMM must limit the total available DRAM to fit within the HW restrictions.
Hopefully TDX can do the same.
Jason
Alexey Kardashevskiy
maintainerRe: [PATCH kernel 6/9] x86/dma-direct: Stop changing encrypted page state for TDISP devices
In reply to Jason GunthorpeQuoted 10 lines · Jason Gunthorpe
Quoted 7 lines · Robin Murphy
I guess this comes back to the point I just raised on the previous patch - the current assumption is that devices cannot access private memory at all, and thus
phys_to_dma()is implicitly only dealing with the mechanics of how the given device accesses shared memory. Once that no longer holds, I don't see how we can find the right answer without also consulting the relevant state of paddr itself, and that really *should* be able to be commonly abstracted across CoCo environments.
Quoted 3 lines
Definately, I think building on this is a good place to start
cool, thanks for the pointer.
Quoted 9 lines
Probably this series needs to take
DMA_ATTR_CC_DECRYPTEDand push it down into thephys_to_dma()and make the swiotlb shared allocation code force set it.But what value is stored in the
phys_addr_tfor shared pages on the three arches? Does ARM and Intel set the high GPA/IPA bit in thephys_addror do they set it through the pgprot? What does AMD do? ie can we test a bit in thephys_addr_tto reliably determine if it is shared or private?
Without secure vIOMMU, no Cbit in the S2 table (==host) for any VM. SDTE (==IOMMU) decides on shared/private for the device, i.e. (device_cc_accepted()?private:shared).
With secure vIOMMU, PTEs in VM will or won't have the SME mask.
Quoted 6 lines
Quoted 3 lines
Quoted 3 lines
pci_device_add()enforces theFFFF_FFFFcoherent DMA mask sodma_alloc_coherent()fails when SME=on, this is how I ended up fixingphys_to_dma()and not quite sure it is the right fix.Does AMD have the shared/private GPA split like ARM and Intel do? Ie shared is always at a high GPA? What is the SME mask?
sorry but I do not follow this entirely.
In general, GPA != DMA handle. Cbit (bit51) is not an address bit in a GPA but it is a DMA handle so I mask it there.
With one exception - 1) host 2) mem_encrypt=on 3) iommu=pt, but we default to IOMMU in the case of host+mem_encrypt=on and don't have Cbit in host's DMA handles.
For CoCoVM, I could map everything again at the 1<<51 offset in the same S2 table to leak Cbit to the bus (useless though).
There is vTOM in SDTE which is "every phys_addr_t above vTOM is no Cbit, below - with Cbit" (and there is the same thing for the CPU side in SEV) but this not it, right?
AMD's SME mask for shared is 0, for private - 1<<51.
Thanks,
Signature · 1 line
Alexey
Re: [PATCH kernel 6/9] x86/dma-direct: Stop changing encrypted page state for TDISP devices
Quoted 29 lines · Alexey Kardashevskiy
Quoted 10 lines · Jason Gunthorpe
Quoted 7 lines · Robin Murphy
I guess this comes back to the point I just raised on the previous patch - the current assumption is that devices cannot access private memory at all, and thus
phys_to_dma()is implicitly only dealing with the mechanics of how the given device accesses shared memory. Once that no longer holds, I don't see how we can find the right answer without also consulting the relevant state of paddr itself, and that really *should* be able to be commonly abstracted across CoCo environments.Quoted 3 lines
Definately, I think building on this is a good place to start
cool, thanks for the pointer.
Quoted 9 lines
Probably this series needs to take
DMA_ATTR_CC_DECRYPTEDand push it down into thephys_to_dma()and make the swiotlb shared allocation code force set it.But what value is stored in the
phys_addr_tfor shared pages on the three arches? Does ARM and Intel set the high GPA/IPA bit in thephys_addror do they set it through the pgprot? What does AMD do? ie can we test a bit in thephys_addr_tto reliably determine if it is shared or private?
Quoted 3 lines
Without secure vIOMMU, no Cbit in the S2 table (==host) for any VM. SDTE (==IOMMU) decides on shared/private for the device, i.e. (device_cc_accepted()?private:shared).
Is this "Cbit" part of the CPU S2 page table address space or is it actually some PTE bit that says it is "encrypted" ?
It is confusing when you say it would start working with a vIOMMU.
If 1<<51 is a valid IOPTE, and it is an actually address, then it should be mapped into the IOMMU S2, shouldn't it? If it is in the IOMMU S2 then shouldn't it work as a dma_addr_t?
If the HW is treating 1<<51 special in some way and not reflecting it into a S2 lookup then it isn't an address bit but an IOPTE flag. IMHO is really dangerous to intermix PTE flags into phys_addr_t, I hope that is not what is happening.
Quoted 10 lines
Quoted 2 lines
Does AMD have the shared/private GPA split like ARM and Intel do? Ie shared is always at a high GPA? What is the SME mask?
sorry but I do not follow this entirely.
In general, GPA != DMA handle. Cbit (bit51) is not an address bit in a GPA but it is a DMA handle so I mask it there.
With one exception - 1) host 2) mem_encrypt=on 3) iommu=pt, but we default to IOMMU in the case of host+mem_encrypt=on and don't have Cbit in host's DMA handles.
For CoCoVM, I could map everything again at the 1<<51 offset in the same S2 table to leak Cbit to the bus (useless though).
Double map is what ARM does at least. I don't know it is a good choice, but it means that phys_addr_t can have a shared/private bit (eg your Cbit at 51) and both the CPU and IOMMU S2 have legitimate mappings. ie it is a *true* address bit.
Given AMD has only a single IOMMO for T=0 and 1 it would make sense to me if AMD always remove the C bit and there is always a uniform IOVA mapping from 0 -> vTOM.
But in this case I would expect the vIOMMU to also use the same GPA space starting from 0 and also remove the C bit, as the S2 shouldn't have mappings starting at 1<<51.
Quoted 3 lines
There is vTOM in SDTE which is "every
phys_addr_tabove vTOM is no Cbit, below - with Cbit" (and there is the same thing for the CPU side in SEV) but this not it, right?
That seems like the IOMMU HW is specially handling the address bits in some way? At least ARM doesn't have anything like that, address bits are address bits, they don't get overloaded with secondary mechanisms.
Quoted 1 line
AMD's SME mask for shared is 0, for private - 1<<51.
ARM is the inverse of this (private is at 0), but the same idea.
Jason
Alexey Kardashevskiy
maintainerRe: [PATCH kernel 6/9] x86/dma-direct: Stop changing encrypted page state for TDISP devices
Quoted 30 lines · Jason Gunthorpe
Quoted 29 lines · Alexey Kardashevskiy
Quoted 10 lines · Jason Gunthorpe
Quoted 7 lines · Robin Murphy
I guess this comes back to the point I just raised on the previous patch - the current assumption is that devices cannot access private memory at all, and thus
phys_to_dma()is implicitly only dealing with the mechanics of how the given device accesses shared memory. Once that no longer holds, I don't see how we can find the right answer without also consulting the relevant state of paddr itself, and that really *should* be able to be commonly abstracted across CoCo environments.Quoted 3 lines
Definately, I think building on this is a good place to start
cool, thanks for the pointer.
Quoted 9 lines
Probably this series needs to take
DMA_ATTR_CC_DECRYPTEDand push it down into thephys_to_dma()and make the swiotlb shared allocation code force set it.But what value is stored in the
phys_addr_tfor shared pages on the three arches? Does ARM and Intel set the high GPA/IPA bit in thephys_addror do they set it through the pgprot? What does AMD do? ie can we test a bit in thephys_addr_tto reliably determine if it is shared or private?
Quoted 8 lines
Quoted 3 lines
Without secure vIOMMU, no Cbit in the S2 table (==host) for any VM. SDTE (==IOMMU) decides on shared/private for the device, i.e. (device_cc_accepted()?private:shared).
Is this "Cbit" part of the CPU S2 page table address space or is it actually some PTE bit that says it is "encrypted" ?
It is confusing when you say it would start working with a vIOMMU.
When I mention vIOMMU, I mean the S1 table which is guest owned and which has Cbit in PTEs.
Quoted 3 lines
If 1<<51 is a valid IOPTE, and it is an actually address, then it should be mapped into the IOMMU S2, shouldn't it? If it is in the IOMMU S2 then shouldn't it work as a
dma_addr_t?
It should (and checked with the HW folks), I just have not tried it as, like, whyyy.
Quoted 4 lines
If the HW is treating 1<<51 special in some way and not reflecting it into a S2 lookup then it isn't an address bit but an IOPTE flag. IMHO is really dangerous to intermix PTE flags into
phys_addr_t, I hope that is not what is happening.
Sounds like what you hope for is how it works now.
Quoted 16 lines
Quoted 10 lines
Quoted 2 lines
Does AMD have the shared/private GPA split like ARM and Intel do? Ie shared is always at a high GPA? What is the SME mask?
sorry but I do not follow this entirely.
In general, GPA != DMA handle. Cbit (bit51) is not an address bit in a GPA but it is a DMA handle so I mask it there.
With one exception - 1) host 2) mem_encrypt=on 3) iommu=pt, but we default to IOMMU in the case of host+mem_encrypt=on and don't have Cbit in host's DMA handles.
For CoCoVM, I could map everything again at the 1<<51 offset in the same S2 table to leak Cbit to the bus (useless though).
Double map is what ARM does at least. I don't know it is a good choice, but it means that
phys_addr_tcan have a shared/private bit (eg your Cbit at 51) and both the CPU and IOMMU S2 have legitimate mappings. ie it is a *true* address bit.
Quoted 7 lines
Given AMD has only a single IOMMO for T=0 and 1 it would make sense to me if AMD always remove the C bit and there is always a uniform IOVA mapping from 0 -> vTOM.
But in this case I would expect the vIOMMU to also use the same GPA space starting from 0 and also remove the C bit, as the S2 shouldn't have mappings starting at 1<<51.
How would then IOMMU know if DMA targets private or shared memory? The Cbit does not participate in the S2 translation as an address bit but IOMMU still knows what it is.
Quoted 6 lines
Quoted 3 lines
There is vTOM in SDTE which is "every
phys_addr_tabove vTOM is no Cbit, below - with Cbit" (and there is the same thing for the CPU side in SEV) but this not it, right?That seems like the IOMMU HW is specially handling the address bits in some way?
Yeah there is this capability. Except everything below vTOM is private and every above is shared so SME mask for it would be reverse than the CPU SME mask :) Not using this thing though (not sure why we have it). Thanks,
Quoted 7 lines
At least ARM doesn't have anything like that, address bits are address bits, they don't get overloaded with secondary mechanisms.
Quoted 1 line
Quoted 1 line
AMD's SME mask for shared is 0, for private - 1<<51.
ARM is the inverse of this (private is at 0), but the same idea.
Jason
Signature · 1 line
Alexey
Aneesh Kumar K.V
maintainerRe: [PATCH kernel 2/9] pci/tsm: Add tsm_tdi_status
In reply to [email protected]Quoted 16 lines · <[email protected]> writes:
Quoted 11 lines · Alexey Kardashevskiy
Define a structure with all info about a TDI such as TDISP status, bind state, used
START_INTERFACEoptions and the report digest.This will be extended and shared to the userspace.
Signed-off-by Alexey Kardashevskiy <[email protected]>---
Make it uapi? We might want a sysfs node per a field so probably not. For now its only user is AMD SEV TIO with a plan to expose this struct as a whole via sysfs.
Say more about what this uapi when sysfs already has lock+accept indications?
Quoted 8 lines
Or are you just talking about exporting the TDISP report as a binary blob?
I think the kernel probably wants a generic abstraction for asserting that the tsm layer believes the report remains valid between fetch and run. In other words I am not sure arch features like
intf_report_counterever show up anywhere in uapi outside of debugfs.
Agreed. For CCA, we use rsi_vdev_info, but we need a generic mechanism to associate this with the report that the guest has attested.
In CCA, we call rsi_vdev_get_info(vdev_id, dev_info) and later use that information in rsi_vdev_enable_dma(vdev_id, dev_info).
Perhaps we could add a generation number (or meas_nonce) to the TSM netlink response and use it when accepting the device, so we can reliably bind the device measurement to the attested one?
-aneesh
Aneesh Kumar K.V
maintainerRe: [PATCH kernel 4/9] dma/swiotlb: Stop forcing SWIOTLB for TDISP devices
In reply to Alexey KardashevskiyQuoted 20 lines · Alexey Kardashevskiy
SWIOTLB is enforced when encrypted guest memory is detected in
pci_swiotlb_detect()which is required for legacy devices.Skip SWIOTLB for TDISP devices.
Signed-off-by Alexey Kardashevskiy <[email protected]>--- include/linux/swiotlb.h | 9 +++++++++ 1 file changed, 9 insertions(+)include/linux/swiotlb.h +2
-0@@ -173,6 +173,15 @@ static inline bool is_swiotlb_force_bounce(struct device *dev) {struct io_tlb_mem *mem = dev->dma_io_tlb_mem; +/* +* CC_ATTR_GUEST_MEM_ENCRYPT enforces SWIOTLB_FORCE in
include/linux/swiotlb.h static inline bool is_swiotlb_force_bounce(struct device *dev) · line 187
Quoted 10 lines
include/linux/swiotlb.h +7
-0+* swiotlb_init_remap() to allow legacy devices access arbitrary +* VM encrypted memory. +* Skip it for TDISP devices capable of DMA-ing the encrypted memory. +*/ +if (device_cc_accepted (dev)) +return false; +return mem && mem->force_bounce; }
I’m wondering whether we need more than that. Perhaps we could start with a simpler assumption: a TDISP-capable device will never require SWIOTLB bouncing. That would significantly simplify the DMA allocation path for T=1.
Without this assumption, we might need to implement a private io_tlb_mem.
We should also avoid supporting TDISP mode on devices that require things like restricted-memory SWIOTLB pool.
Something like:
modified arch/arm64/mm/mem_encrypt.c
@@ -18,6 +18,7 @@
#include <linux/err.h>
#include <linux/mm.h>
#include <linux/mem_encrypt.h>
+#include <linux/device.h>
static const struct arm64_mem_crypt_ops *crypt_ops;
@@ -53,3 +54,12 @@ int set_memory_decrypted(unsigned long addr, int numpages)
return crypt_ops->decrypt(addr, numpages);
}
EXPORT_SYMBOL_GPL(set_memory_decrypted);
+
+bool force_dma_unencrypted(struct device *dev)
+{
+ if (device_cc_accepted(dev))
+ return false;
+
+ return is_realm_world();
+}
+EXPORT_SYMBOL_GPL(force_dma_unencrypted);
modified include/linux/swiotlb.h
@@ -173,6 +173,11 @@ static inline bool is_swiotlb_force_bounce(struct device *dev)
{
struct io_tlb_mem *mem = dev->dma_io_tlb_mem;
+ if (device_cc_accepted(dev)) {
+ dev_warn_once(dev, "(TIO) Disable SWIOTLB");
+ return false;
+ }
+
return mem && mem->force_bounce;
}
@@ -287,6 +292,9 @@ bool swiotlb_free(struct device *dev, struct page *page, size_t size);
static inline bool is_swiotlb_for_alloc(struct device *dev)
{
+ if (device_cc_accepted(dev))
+ return false;
+
return dev->dma_io_tlb_mem->for_alloc;
}
#else
modified kernel/dma/direct.c
@@ -159,6 +159,14 @@ static struct page *__dma_direct_alloc_pages(struct device *dev, size_t size,
*/
static bool dma_direct_use_pool(struct device *dev, gfp_t gfp)
{
+ /*
+ * Atomic pools are marked decrypted and are used if we require require
+ * updation of pfn mem encryption attributes or for DMA non-coherent
+ * device allocation. Both is not true for trusted device.
+ */
+ if (device_cc_accepted(dev))
+ return false;
+
return !gfpflags_allow_blocking(gfp) && !is_swiotlb_for_alloc(dev);
}
modified kernel/dma/swiotlb.c
@@ -1643,6 +1643,9 @@ bool is_swiotlb_active(struct device *dev)
{
struct io_tlb_mem *mem = dev->dma_io_tlb_mem;
+ if (device_cc_accepted(dev))
+ return false;
+
return mem && mem->nslabs;
}
Aneesh Kumar K.V
maintainerRe: [PATCH kernel 9/9] pci: Allow encrypted MMIO mapping via sysfs
In reply to Alexey KardashevskiyQuoted 6 lines · Alexey Kardashevskiy
Add another resource#d_enc to allow mapping MMIO as an encrypted/private region.
Unlike
resourceN_wc, the node is added always as ability to map MMIO as private depends on negotiation with the TSM which happens quite late.
Why is this needed? Is this for a specific tool?
-aneesh
Alexey Kardashevskiy
maintainerRe: [PATCH kernel 9/9] pci: Allow encrypted MMIO mapping via sysfs
Quoted 10 lines · Aneesh Kumar K.V
Quoted 6 lines · Alexey Kardashevskiy
Add another resource#d_enc to allow mapping MMIO as an encrypted/private region.
Unlike
resourceN_wc, the node is added always as ability to map MMIO as private depends on negotiation with the TSM which happens quite late.Why is this needed? Is this for a specific tool?
It is not _needed_ but (as the cover letter says) since one of my test devices does not use private MMIO for the main function, here it is to allow https://github.com/billfarrow/pcimem.git to map MMIO as private and do simple reads/writes. Useful for validation, can stop in gdb and inspect tables and whatever. Thanks,
Quoted 2 lines
-aneesh
Signature · 1 line
Alexey
Re: [PATCH kernel 6/9] x86/dma-direct: Stop changing encrypted page state for TDISP devices
In reply to Alexey KardashevskiyQuoted 11 lines · Alexey Kardashevskiy
Quoted 8 lines
Quoted 3 lines
Without secure vIOMMU, no Cbit in the S2 table (==host) for any VM. SDTE (==IOMMU) decides on shared/private for the device, i.e. (device_cc_accepted()?private:shared).
Is this "Cbit" part of the CPU S2 page table address space or is it actually some PTE bit that says it is "encrypted" ?
It is confusing when you say it would start working with a vIOMMU.
When I mention vIOMMU, I mean the S1 table which is guest owned and which has Cbit in PTEs.
Yes, I understand this.
It seems from your email that the CPU S2 has the Cbit as part of the address and the S1 feeds it through to the S2, so it is genuinely has two addres spaces?
While the IOMMU S1 does not and instead needs a PTE bit which is emphatically not an address bit because it does not feed through the S2?
Quoted 5 lines
Quoted 3 lines
If 1<<51 is a valid IOPTE, and it is an actually address, then it should be mapped into the IOMMU S2, shouldn't it? If it is in the IOMMU S2 then shouldn't it work as a
dma_addr_t?It should (and checked with the HW folks), I just have not tried it as, like, whyyy.
Well, I think things work more sensibly if you don't have to mangle the address..
Quoted 7 lines
Quoted 3 lines
But in this case I would expect the vIOMMU to also use the same GPA space starting from 0 and also remove the C bit, as the S2 shouldn't have mappings starting at 1<<51.
How would then IOMMU know if DMA targets private or shared memory? The Cbit does not participate in the S2 translation as an address bit but IOMMU still knows what it is.
Same way it knows if there is no S1? Why does the S1 change anything?
Quoted 11 lines
Quoted 6 lines
Quoted 3 lines
There is vTOM in SDTE which is "every
phys_addr_tabove vTOM is no Cbit, below - with Cbit" (and there is the same thing for the CPU side in SEV) but this not it, right?That seems like the IOMMU HW is specially handling the address bits in some way?
Yeah there is this capability. Except everything below vTOM is private and every above is shared so SME mask for it would be reverse than the CPU SME mask :) Not using this thing though (not sure why we have it). Thanks,
Weird!!
Jason
Re: [PATCH kernel 4/9] dma/swiotlb: Stop forcing SWIOTLB for TDISP devices
In reply to Jason GunthorpeQuoted 11 lines · Jason Gunthorpe
Quoted 7 lines · On Wed, Feb 25, 2026 at 12:57:01PM -0800, [email protected] wrote:
Quoted 3 lines
(since a device that's trusted to access private memory isn't necessarily prohibited from still also accessing shared memory as well), hmmm...
The specification allows it, but Linux DMA mapping core is not yet ready for it. So the expectation to start is that the device loses access to its original shared IOMMU mappings when converted to private operation.
Yes, the underlying translation changes, but no, it doesn't loose DMA access to any shared pages, it just goes through the T=1 IOMMU now.
Yes, what I meant to say is that Linux may need to be prepared for implementations that do not copy over the shared mappings. At least for early staging / minimum viable implementation for first merge.
Quoted 2 lines
The T=1 IOMMU will still have them mapped on all three platforms AFAIK.
Oh, I thought SEV-TIO had trouble with this, if this is indeed the case, great, ignore my first comment.
Quoted 4 lines
On TDX/CCA the CPU and IOMMU S2 tables are identical, so of course the shared pages are mapped. On AMD there is only one IOMMU so the page must also be mapped or non-TDISP is broken.
Quoted 8 lines
When this TDISP awareness is put in the DMA API it needs to be done in a way that allows
DMA_ATTR_CC_DECRYPTEDto keep working for TDISP devices.This is important because we are expecting these sorts of things to work as part of integrating non-TDISP RDMA devices into CC guests. We can't loose access to the shared pages that are shared with the non-TDISP devices...
Ok, I need to go look at this DMA_ATTR_CC_DECRYPTED proposal...
I have a v2 of a TEE I/O set going out shortly and sounds like it will need a rethink for this attribute proposal for v3. I think it still helps to have combo sets at this stage so the whole lifecycle is visible in one set, but it is nearly at the point of being too big a set to consider in one sitting.
Quoted 4 lines
Quoted 3 lines
So on ARM where shared addresses are high, it is future work to figure out how an accepted device might also access shared mappings outside the device's
dma_mask.
Quoted 8 lines
ARM has a "solution" right now. The location of the high bit is controlled by the VMM and the VMM cannot create a CC VM where the IPA space exceeds the
dma_maskof any assigned device.Thus the VMM must limit the total available DRAM to fit within the HW restrictions.
Hopefully TDX can do the same.
TDX does not have the same problem, but the ARM "solution" seems reasonable for now.
Re: [PATCH kernel 4/9] dma/swiotlb: Stop forcing SWIOTLB for TDISP devices
Quoted 11 lines · On Mon, Mar 02, 2026 at 03:53:13PM -0800, [email protected] wrote:
Quoted 6 lines
Quoted 3 lines
The specification allows it, but Linux DMA mapping core is not yet ready for it. So the expectation to start is that the device loses access to its original shared IOMMU mappings when converted to private operation.
Yes, the underlying translation changes, but no, it doesn't loose DMA access to any shared pages, it just goes through the T=1 IOMMU now.
Yes, what I meant to say is that Linux may need to be prepared for implementations that do not copy over the shared mappings. At least for early staging / minimum viable implementation for first merge.
Quoted 5 lines
Quoted 2 lines
The T=1 IOMMU will still have them mapped on all three platforms AFAIK.
Oh, I thought SEV-TIO had trouble with this, if this is indeed the case, great, ignore my first comment.
Alexey?
I think it is really important that shared mappings continue to be reachable by TDISP device.
Quoted 5 lines
I have a v2 of a TEE I/O set going out shortly and sounds like it will need a rethink for this attribute proposal for v3. I think it still helps to have combo sets at this stage so the whole lifecycle is visible in one set, but it is nearly at the point of being too big a set to consider in one sitting.
My problem is I can't get in one place an actually correct picture of how the IOVA translation works in all the arches and how the phys_addr_t works.
So it is hard to make sense of all these proposals. What I would love to see is one series that deals with this:
[PATCH v2 11/19] x86, dma: Allow accepted devices to map private memory
For *all* the arches, along with a description for each of:
* how their phys_addr_t is constructed
* how their S2 IOMMU mapping works
* how a vIOMMU S1 would change any of the above.
Then maybe we can see if we are actually doing it properly or not.
Quoted 11 lines
Quoted 8 lines
ARM has a "solution" right now. The location of the high bit is controlled by the VMM and the VMM cannot create a CC VM where the IPA space exceeds the
dma_maskof any assigned device.Thus the VMM must limit the total available DRAM to fit within the HW restrictions.
Hopefully TDX can do the same.
TDX does not have the same problem, but the ARM "solution" seems reasonable for now.
I'm surprised because Xu said:
This is same as Intel TDX, the GPA shared bit are used by IOMMU to target shared/private. You can imagine for T=1, there are 2 IOPTs, or 1 IOPT with all private at lower address & all shared at higher address.
https://lore.kernel.org/all/aaF6HD2gfe%2Fudl%2Fx@yilunxu-OptiPlex-7050/
So how come that not have exactly the same problem as ARM?
Jason
Re: [PATCH kernel 4/9] dma/swiotlb: Stop forcing SWIOTLB for TDISP devices
Jason Gunthorpe wrote:
[..]
Quoted 13 lines
Quoted 5 lines
I have a v2 of a TEE I/O set going out shortly and sounds like it will need a rethink for this attribute proposal for v3. I think it still helps to have combo sets at this stage so the whole lifecycle is visible in one set, but it is nearly at the point of being too big a set to consider in one sitting.
My problem is I can't get in one place an actually correct picture of how the IOVA translation works in all the arches and how the
phys_addr_tworks.So it is hard to make sense of all these proposals. What I would love to see is one series that deals with this:
Quoted 8 lines
[PATCH v2 11/19] x86, dma: Allow accepted devices to map private memory
For *all* the arches, along with a description for each of:
* how theirphys_addr_tis constructed
* how their S2 IOMMU mapping works
* how a vIOMMU S1 would change any of the above.Then maybe we can see if we are actually doing it properly or not.
Yes, this is my struggle as well. I will put this on the agenda for the next CCC call.
[..]
Quoted 10 lines
I'm surprised because Xu said:
This is same as Intel TDX, the GPA shared bit are used by IOMMU to target shared/private. You can imagine for T=1, there are 2 IOPTs, or 1 IOPT with all private at lower address & all shared at higher address.
https://lore.kernel.org/all/aaF6HD2gfe%2Fudl%2Fx@yilunxu-OptiPlex-7050/
So how come that not have exactly the same problem as ARM?
Sorry, yes TDX has same behavior as ARM, excuse the noise.
Alexey Kardashevskiy
maintainerRe: [PATCH kernel 6/9] x86/dma-direct: Stop changing encrypted page state for TDISP devices
In reply to Jason GunthorpeQuoted 5 lines · Jason Gunthorpe
Quoted 3 lines · Alexey Kardashevskiy
Quoted 3 lines
Quoted 3 lines
Without secure vIOMMU, no Cbit in the S2 table (==host) for any VM. SDTE (==IOMMU) decides on shared/private for the device, i.e. (device_cc_accepted()?private:shared).
"no Cbit" here was "there is Cbit in PTe and it is 0", rather than "Cbit is an address bit".
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Is this "Cbit" part of the CPU S2 page table address space or is it actually some PTE bit that says it is "encrypted" ?
afaik it is always (while SNP is enabled) a PTE bit that says "encrypted".
Quoted 10 lines
Quoted 4 lines
Quoted 1 line
It is confusing when you say it would start working with a vIOMMU.
When I mention vIOMMU, I mean the S1 table which is guest owned and which has Cbit in PTEs.
Yes, I understand this.
It seems from your email that the CPU S2 has the Cbit as part of the address and the S1 feeds it through to the S2, so it is genuinely has two addres spaces?
S1/S2 PTEs have Cbit. Addresses to look up those PTEs - do not.
(both are "addresses" - one in the PTE and another one - to look up the PTE)
Quoted 3 lines
While the IOMMU S1 does not and instead needs a PTE bit which is emphatically not an address bit because it does not feed through the S2?
afaik IOMMU works the same.
Quoted 13 lines
Quoted 5 lines
Quoted 3 lines
If 1<<51 is a valid IOPTE, and it is an actually address, then it should be mapped into the IOMMU S2, shouldn't it? If it is in the IOMMU S2 then shouldn't it work as a
dma_addr_t?It should (and checked with the HW folks), I just have not tried it as, like, whyyy.
Well, I think things work more sensibly if you don't have to mangle the address..
Quoted 4 lines
Quoted 3 lines
But in this case I would expect the vIOMMU to also use the same GPA space starting from 0 and also remove the C bit, as the S2 shouldn't have mappings starting at 1<<51.
Quoted 5 lines
Quoted 3 lines
How would then IOMMU know if DMA targets private or shared memory? The Cbit does not participate in the S2 translation as an address bit but IOMMU still knows what it is.
Same way it knows if there is no S1?
If no S1 - then sDTE decides on Cbit for the entire ASID (with the help of vTOM).
Quoted 1 line
Why does the S1 change anything?
S1 will have Cbit in individual PTEs, allowing per page control.
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
Quoted 3 lines
There is vTOM in SDTE which is "every
phys_addr_tabove vTOM is no Cbit, below - with Cbit" (and there is the same thing for the CPU side in SEV) but this not it, right?That seems like the IOMMU HW is specially handling the address bits in some way?
Quoted 6 lines
Quoted 4 lines
Yeah there is this capability. Except everything below vTOM is private and every above is shared so SME mask for it would be reverse than the CPU SME mask :) Not using this thing though (not sure why we have it). Thanks,
Weird!!
:)
I understand I am often confusing, trying to unconfuse (including myself)... Thanks,
Signature · 1 line
Alexey
Re: [PATCH kernel 6/9] x86/dma-direct: Stop changing encrypted page state for TDISP devices
Quoted 5 lines · Alexey Kardashevskiy
Quoted 3 lines
It seems from your email that the CPU S2 has the Cbit as part of the address and the S1 feeds it through to the S2, so it is genuinely has two addres spaces?
S1/S2 PTEs have Cbit. Addresses to look up those PTEs - do not.
So we are back to what I was saying before: using phys_addr_t to encode a PTE bit is probably a very confusing idea - especially when contrasted with the other arches that have a legitimate address bit.
Quoted 3 lines
Quoted 1 line
Same way it knows if there is no S1?
If no S1 - then sDTE decides on Cbit for the entire ASID (with the help of vTOM).
Sounds like the intention was the IOMMU shared/private space would be controlled with vTOM which actually does a create a legitimate address bit in the phys_addr_t.
A sDTE global control is OK for non-TDISP devices, or even devices that haven't entered RUN yet, but it is not OK for a TDISP device that must still be able to access shared memory.
Quoted 1 line
I understand I am often confusing, trying to unconfuse (including myself)... Thanks,
It seems to me the AMD architecture itself is pretty confusing. :\
Jason
Jason Gunthorpe
maintainerRe: [PATCH kernel 4/9] dma/swiotlb: Stop forcing SWIOTLB for TDISP devices
In reply to Jason GunthorpeQuoted 7 lines · Jason Gunthorpe
Quoted 2 lines
Oh, I thought SEV-TIO had trouble with this, if this is indeed the case, great, ignore my first comment.
Alexey?
I think it is really important that shared mappings continue to be reachable by TDISP device.
I think Alexey has clarified this in the other thread, and probably AMD has some work to do here.
The issue is AMD does not have seperate address spaces for shared/private like ARM does, instead it relies on a C bit in the *PTE* to determine shared/private.
The S2 IOMMU page table *does* have the full mapping of all shared & private pages but the HW requires a matching C bit to permit access.
If there is a S1 IOMMU then the IOPTEs of the VM can provide the C bit, so no problem.
If there is no S1 then the sDTE of the hypervisor controls the C bit, and it sounds like currently AMD sets this globally which effectively locks TDISP RUN devices to *only* access private memory.
I suspect AMD needs to use their vTOM feature to allow shared memory to remain available to TDISP RUN with a high/low address split.
Alexey, did I capture this properly?
Jason
Alexey Kardashevskiy
maintainerRe: [PATCH kernel 4/9] dma/swiotlb: Stop forcing SWIOTLB for TDISP devices
Quoted 16 lines · Jason Gunthorpe
Quoted 7 lines · Jason Gunthorpe
Quoted 2 lines
Oh, I thought SEV-TIO had trouble with this, if this is indeed the case, great, ignore my first comment.
Alexey?
I think it is really important that shared mappings continue to be reachable by TDISP device.
I think Alexey has clarified this in the other thread, and probably AMD has some work to do here.
The issue is AMD does not have seperate address spaces for shared/private like ARM does, instead it relies on a C bit in the *PTE* to determine shared/private.
Quoted 7 lines
The S2 IOMMU page table *does* have the full mapping of all shared & private pages but the HW requires a matching C bit to permit access.
If there is a S1 IOMMU then the IOPTEs of the VM can provide the C bit, so no problem.
If there is no S1 then the sDTE of the hypervisor controls the C bit,
sDTE is controlled by the FW (not the HV) on the VM behalf - the VM chooses whether to enable sDTE and therefore vTOM.
Quoted 2 lines
and it sounds like currently AMD sets this globally which effectively locks TDISP RUN devices to *only* access private memory.
Right. The assumption is that if the guest wants finer control - there is secure vIOMMU (in the works).
Quoted 2 lines
I suspect AMD needs to use their vTOM feature to allow shared memory to remain available to TDISP RUN with a high/low address split.
I could probably do something about it bit I wonder what is the real live use case which requires leaking SME mask, have a live example which I could try recreating?
Quoted 1 line
Alexey, did I capture this properly?
Yes, with the correction about sDTE above. Thanks,
Quoted 2 lines
Jason
Signature · 1 line
Alexey
Jason Gunthorpe
maintainerRe: [PATCH kernel 4/9] dma/swiotlb: Stop forcing SWIOTLB for TDISP devices
Quoted 6 lines · Alexey Kardashevskiy
Quoted 2 lines
I suspect AMD needs to use their vTOM feature to allow shared memory to remain available to TDISP RUN with a high/low address split.
I could probably do something about it bit I wonder what is the real live use case which requires leaking SME mask, have a live example which I could try recreating?
We need shared memory allocated through a DMABUF heap:
https://lore.kernel.org/all/[email protected]/
To work with all PCI devices in the system, TDISP or not.
Without this the ability for a TDISP device to ingest (encrypted) data requires all kinds of memcpy..
So the DMA API should see the DMA_ATTR_CC_DECRYPTED and setup the correct dma_dddr_t either by choosing the shared alias for the TDISP device's vTOM, or setting the C bit in a vIOMMU S1.
Jason
Alexey Kardashevskiy
maintainerRe: [PATCH kernel 4/9] dma/swiotlb: Stop forcing SWIOTLB for TDISP devices
Quoted 13 lines · Jason Gunthorpe
Quoted 6 lines · Alexey Kardashevskiy
Quoted 2 lines
I suspect AMD needs to use their vTOM feature to allow shared memory to remain available to TDISP RUN with a high/low address split.
I could probably do something about it bit I wonder what is the real live use case which requires leaking SME mask, have a live example which I could try recreating?
We need shared memory allocated through a DMABUF heap:
Quoted 8 lines
To work with all PCI devices in the system, TDISP or not.
Without this the ability for a TDISP device to ingest (encrypted) data requires all kinds of memcpy..
So the DMA API should see the
DMA_ATTR_CC_DECRYPTEDand setup the correctdma_dddr_teither by choosing the shared alias for the TDISP device's vTOM, or setting the C bit in a vIOMMU S1.
I can make this work by using some high enough bit as "Sbit" in vTOM to mark shared pages but I'll have to decouple dma_addr_encrypted/dma_addr_canonical (not many uses but still scary) from sme_me_mask and I wonder if anyone has recently attempted this so I won't have to reinvent?
(a reminder: below vTOM address == private, above vTOM == shared)
Thanks,
Signature · 1 line
Alexey
Alexey Kardashevskiy
maintainerRe: [PATCH kernel 4/9] dma/swiotlb: Stop forcing SWIOTLB for TDISP devices
In reply to Jason GunthorpeQuoted 13 lines · Jason Gunthorpe
Quoted 6 lines · Alexey Kardashevskiy
Quoted 2 lines
I suspect AMD needs to use their vTOM feature to allow shared memory to remain available to TDISP RUN with a high/low address split.
I could probably do something about it bit I wonder what is the real live use case which requires leaking SME mask, have a live example which I could try recreating?
We need shared memory allocated through a DMABUF heap:
Quoted 8 lines
To work with all PCI devices in the system, TDISP or not.
Without this the ability for a TDISP device to ingest (encrypted) data requires all kinds of memcpy..
So the DMA API should see the
DMA_ATTR_CC_DECRYPTEDand setup the correctdma_dddr_teither by choosing the shared alias for the TDISP device's vTOM, or setting the C bit in a vIOMMU S1.
Something like that?
https://github.com/AMDESE/linux-kvm/commit/266a41a1ea746557eb63debce886ce2c98820667
With some little hacks I can make this tree do TDISP DMA to private or shared (swiotlb) memory by steering via this vTOM thing. Thanks,
Quoted 2 lines
Jason
Signature · 1 line
Alexey
Alexey Kardashevskiy
maintainerRe: [PATCH kernel 4/9] dma/swiotlb: Stop forcing SWIOTLB for TDISP devices
Quoted 25 lines · Alexey Kardashevskiy
Quoted 13 lines · Jason Gunthorpe
Quoted 6 lines · Alexey Kardashevskiy
Quoted 2 lines
I suspect AMD needs to use their vTOM feature to allow shared memory to remain available to TDISP RUN with a high/low address split.
I could probably do something about it bit I wonder what is the real live use case which requires leaking SME mask, have a live example which I could try recreating?
We need shared memory allocated through a DMABUF heap:
Quoted 8 lines
To work with all PCI devices in the system, TDISP or not.
Without this the ability for a TDISP device to ingest (encrypted) data requires all kinds of memcpy..
So the DMA API should see the
DMA_ATTR_CC_DECRYPTEDand setup the correctdma_dddr_teither by choosing the shared alias for the TDISP device's vTOM, or setting the C bit in a vIOMMU S1.
Quoted 5 lines
Something like that?
https://github.com/AMDESE/linux-kvm/commit/266a41a1ea746557eb63debce886ce2c98820667
With some little hacks I can make this tree do TDISP DMA to private or shared (swiotlb) memory by steering via this vTOM thing. Thanks,
Ping? Thanks,
Quoted 6 lines
Quoted 5 lines
Jason
Signature · 1 line
Alexey
Jason Gunthorpe
maintainerRe: [PATCH kernel 4/9] dma/swiotlb: Stop forcing SWIOTLB for TDISP devices
Quoted 11 lines · Alexey Kardashevskiy
Quoted 9 lines
Quoted 3 lines
So the DMA API should see the
DMA_ATTR_CC_DECRYPTEDand setup the correctdma_dddr_teither by choosing the shared alias for the TDISP device's vTOM, or setting the C bit in a vIOMMU S1.Something like that?
https://github.com/AMDESE/linux-kvm/commit/266a41a1ea746557eb63debce886ce2c98820667
With some little hacks I can make this tree do TDISP DMA to private or shared (swiotlb) memory by steering via this vTOM thing. Thanks,
Ping? Thanks,
That seems approx right, it is broadl similar to what ARM is doing.. But the address map changes when switching to T=1 for AMD?
Jason
Alexey Kardashevskiy
maintainerRe: [PATCH kernel 4/9] dma/swiotlb: Stop forcing SWIOTLB for TDISP devices
Quoted 7 lines · Jason Gunthorpe
Quoted 6 lines · Alexey Kardashevskiy
Quoted 6 lines
Quoted 3 lines
So the DMA API should see the
DMA_ATTR_CC_DECRYPTEDand setup the correctdma_dddr_teither by choosing the shared alias for the TDISP device's vTOM, or setting the C bit in a vIOMMU S1.Something like that?
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
https://github.com/AMDESE/linux-kvm/commit/266a41a1ea746557eb63debce886ce2c98820667
With some little hacks I can make this tree do TDISP DMA to private or shared (swiotlb) memory by steering via this vTOM thing. Thanks,
Ping? Thanks,
That seems approx right, it is broadl similar to what ARM is doing.. But the address map changes when switching to T=1 for AMD?
Well, at the moment, in my WIP tree, I map the guest memory in the host IOMMU twice -
1) from 0 offset (and this is shared when T=0 and private when T=1) and
2) from vTOM offset (say, 1TB) - and this half of the mapping is always shared.
Thanks,
Signature · 1 line
Alexey