Skip to content

Commit

Permalink
asm/io.h: Add ioremap_driver_hardening
Browse files Browse the repository at this point in the history
This function is for declaring memory that should be shared with
a hypervisor in a confidential guest. If the architecture doesn't
implement it it's just ioremap.

Note this function is not supposed to be used directly by drivers.
But it will be used implicitly by pci_iomap -- based on the
authorized attribute -- and also by the PCI subsystem. To avoid
ifdefs we create a generic ioremap alias.

Signed-off-by: Andi Kleen <ak@linux.intel.com>
Signed-off-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
  • Loading branch information
Andi Kleen authored and Kuppuswamy Sathyanarayanan committed Apr 18, 2023
1 parent 0739cd6 commit d8bb168
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Documentation/driver-api/device-io.rst
Expand Up @@ -429,6 +429,17 @@ of the linear kernel memory area to a regular pointer.

Portable drivers should avoid the use of ioremap_cache().

ioremap_driver_hardened()
-------------------------

ioremap_driver_hardened() maps I/O memory so that it can be shared with the host
in a confidential guest platform. It is mainly used in platforms like
Trusted Domain Extensions (TDX).

Drivers should not need to use this function directly, but instead use
functions like pci_iomap_range(), which use it implicitly based on driver
authorization.

Architecture example
--------------------

Expand Down
2 changes: 2 additions & 0 deletions arch/alpha/include/asm/io.h
Expand Up @@ -308,6 +308,8 @@ static inline void __iomem *ioremap(unsigned long port, unsigned long size)
}

#define ioremap_wc ioremap
/* Share memory with host in confidential guest platforms */
#define ioremap_driver_hardened ioremap
#define ioremap_uc ioremap

static inline void iounmap(volatile void __iomem *addr)
Expand Down
2 changes: 2 additions & 0 deletions arch/mips/include/asm/io.h
Expand Up @@ -170,6 +170,8 @@ void iounmap(const volatile void __iomem *addr);
#define ioremap(offset, size) \
ioremap_prot((offset), (size), _CACHE_UNCACHED)
#define ioremap_uc ioremap
/* Share memory with host in confidential guest platforms */
#define ioremap_driver_hardened ioremap

/*
* ioremap_cache - map bus memory into CPU space
Expand Down
2 changes: 2 additions & 0 deletions arch/parisc/include/asm/io.h
Expand Up @@ -127,6 +127,8 @@ static inline void gsc_writeq(unsigned long long val, unsigned long addr)
*/
void __iomem *ioremap(unsigned long offset, unsigned long size);
#define ioremap_wc ioremap
/* Share memory with host in confidential guest platforms */
#define ioremap_driver_hardened ioremap
#define ioremap_uc ioremap
#define pci_iounmap pci_iounmap

Expand Down
2 changes: 2 additions & 0 deletions arch/sparc/include/asm/io_64.h
Expand Up @@ -426,6 +426,8 @@ static inline void __iomem *ioremap(unsigned long offset, unsigned long size)
#define ioremap_uc(X,Y) ioremap((X),(Y))
#define ioremap_wc(X,Y) ioremap((X),(Y))
#define ioremap_wt(X,Y) ioremap((X),(Y))
/* Share memory with host in confidential guest platforms */
#define ioremap_driver_hardened(X, Y) ioremap((X), (Y))
static inline void __iomem *ioremap_np(unsigned long offset, unsigned long size)
{
return NULL;
Expand Down
4 changes: 4 additions & 0 deletions arch/x86/include/asm/io.h
Expand Up @@ -325,6 +325,10 @@ extern void __iomem *ioremap_wc(resource_size_t offset, unsigned long size);
extern void __iomem *ioremap_wt(resource_size_t offset, unsigned long size);
#define ioremap_wt ioremap_wt

extern void __iomem *ioremap_driver_hardened(resource_size_t offset,
unsigned long size);
#define ioremap_driver_hardened ioremap_driver_hardened

extern bool is_early_ioremap_ptep(pte_t *ptep);

#define IO_SPACE_LIMIT 0xffff
Expand Down
5 changes: 5 additions & 0 deletions include/asm-generic/io.h
Expand Up @@ -1092,6 +1092,11 @@ static inline void __iomem *ioremap(phys_addr_t addr, size_t size)
#define ioremap_wt ioremap
#endif

/* Share memory with host in confidential guest platforms */
#ifndef ioremap_driver_hardened
#define ioremap_driver_hardened ioremap
#endif

/*
* ioremap_uc is special in that we do require an explicit architecture
* implementation. In general you do not want to use this function in a
Expand Down

0 comments on commit d8bb168

Please sign in to comment.