History

vfio: powerpc/spapr: Register memory and define IOMMU v2

The existing implementation accounts the whole DMA window in the locked_vm counter. This is going to be worse with multiple containers and huge DMA windows. Also, real-time accounting would requite additional tracking of accounted pages due to the page size difference - IOMMU uses 4K pages and system uses 4K or 64K pages. Another issue is that actual pages pinning/unpinning happens on every DMA map/unmap request. This does not affect the performance much now as we spend way too much time now on switching context between guest/userspace/host but this will start to matter when we add in-kernel DMA map/unmap acceleration. This introduces a new IOMMU type for SPAPR - VFIO_SPAPR_TCE_v2_IOMMU. New IOMMU deprecates VFIO_IOMMU_ENABLE/VFIO_IOMMU_DISABLE and introduces 2 new ioctls to register/unregister DMA memory - VFIO_IOMMU_SPAPR_REGISTER_MEMORY and VFIO_IOMMU_SPAPR_UNREGISTER_MEMORY - which receive user space address and size of a memory region which needs to be pinned/unpinned and counted in locked_vm. New IOMMU splits physical pages pinning and TCE table update into 2 different operations. It requires: 1) guest pages to be registered first 2) consequent map/unmap requests to work only with pre-registered memory. For the default single window case this means that the entire guest (instead of 2GB) needs to be pinned before using VFIO. When a huge DMA window is added, no additional pinning will be required, otherwise it would be guest RAM + 2GB. The new memory registration ioctls are not supported by VFIO_SPAPR_TCE_IOMMU. Dynamic DMA window and in-kernel acceleration will require memory to be preregistered in order to work. The accounting is done per the user process. This advertises v2 SPAPR TCE IOMMU and restricts what the userspace can do with v1 or v2 IOMMUs. In order to support memory pre-registration, we need a way to track the use of every registered memory region and only allow unregistration if a region is not in use anymore. So we need a way to tell from what region the just cleared TCE was from. This adds a userspace view of the TCE table into iommu_table struct. It contains userspace address, one per TCE entry. The table is only allocated when the ownership over an IOMMU group is taken which means it is only used from outside of the powernv code (such as VFIO). As v2 IOMMU supports IODA2 and pre-IODA2 IOMMUs (which do not support DDW API), this creates a default DMA window for IODA2 for consistency.

Alexey Kardashevskiy committed 11 years ago

Commit 2157e7b1 parent 15b244a4 files · +482 −83Browse files

Showing the changes to include/uapi (1 of 4 files). Show all

Unified · Split

include/uapi/linux/vfio.h+27−0
@@ -36,6 +36,8 @@ · 35 unmodified lines
36/* Two-stage IOMMU */36/* Two-stage IOMMU */
37#define VFIO_TYPE1_NESTING_IOMMU 6 /* Implies v2 */37#define VFIO_TYPE1_NESTING_IOMMU 6 /* Implies v2 */
38 38
39#define VFIO_SPAPR_TCE_v2_IOMMU 7
40
39/*41/*
40 * The IOCTL interface is designed for extensibility by embedding the42 * The IOCTL interface is designed for extensibility by embedding the
41 * structure length (argsz) and flags into structures passed between43 * structure length (argsz) and flags into structures passed between
@@ -507,6 +509,31 @@ struct vfio_eeh_pe_op { · 465 unmodified lines
507 509
508#define VFIO_EEH_PE_OP _IO(VFIO_TYPE, VFIO_BASE + 21)510#define VFIO_EEH_PE_OP _IO(VFIO_TYPE, VFIO_BASE + 21)
509 511
512/**
513 * VFIO_IOMMU_SPAPR_REGISTER_MEMORY - _IOW(VFIO_TYPE, VFIO_BASE + 17, struct vfio_iommu_spapr_register_memory)
514 *
515 * Registers user space memory where DMA is allowed. It pins
516 * user pages and does the locked memory accounting so
517 * subsequent VFIO_IOMMU_MAP_DMA/VFIO_IOMMU_UNMAP_DMA calls
518 * get faster.
519 */
520struct vfio_iommu_spapr_register_memory {
521 __u32 argsz;
522 __u32 flags;
523 __u64 vaddr; /* Process virtual address */
524 __u64 size; /* Size of mapping (bytes) */
525};
526#define VFIO_IOMMU_SPAPR_REGISTER_MEMORY _IO(VFIO_TYPE, VFIO_BASE + 17)
527
528/**
529 * VFIO_IOMMU_SPAPR_UNREGISTER_MEMORY - _IOW(VFIO_TYPE, VFIO_BASE + 18, struct vfio_iommu_spapr_register_memory)
530 *
531 * Unregisters user space memory registered with
532 * VFIO_IOMMU_SPAPR_REGISTER_MEMORY.
533 * Uses vfio_iommu_spapr_register_memory for parameters.
534 */
535#define VFIO_IOMMU_SPAPR_UNREGISTER_MEMORY _IO(VFIO_TYPE, VFIO_BASE + 18)
536
510/* ***************************************************************** */537/* ***************************************************************** */
511 538
512#endif /* _UAPIVFIO_H */539#endif /* _UAPIVFIO_H */