mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-02-17 21:50:44 -05:00
For ioremap(), so far we only checked if it was a device (RIPAS_DEV) to choose an encrypted vs decrypted mapping. However, we may have firmware reserved memory regions exposed to the OS (e.g., EFI Coco Secret Securityfs, ACPI CCEL). We need to make sure that anything that is RIPAS_RAM (i.e., Guest protected memory with RMM guarantees) are also mapped as encrypted. Rephrasing the above, anything that is not RIPAS_EMPTY is guaranteed to be protected by the RMM. Thus we choose encrypted mapping for anything that is not RIPAS_EMPTY. While at it, rename the helper function __arm64_is_protected_mmio => arm64_rsi_is_protected to clearly indicate that this not an arm64 generic helper, but something to do with Realms. Cc: Sami Mujawar <sami.mujawar@arm.com> Cc: Will Deacon <will@kernel.org> Cc: Catalin Marinas <catalin.marinas@arm.com> Cc: Aneesh Kumar K.V <aneesh.kumar@kernel.org> Cc: Steven Price <steven.price@arm.com> Reviewed-by: Gavin Shan <gshan@redhat.com> Reviewed-by: Steven Price <steven.price@arm.com> Tested-by: Sami Mujawar <sami.mujawar@arm.com> Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com> Signed-off-by: Will Deacon <will@kernel.org>
71 lines
1.6 KiB
C
71 lines
1.6 KiB
C
/* SPDX-License-Identifier: GPL-2.0-only */
|
|
/*
|
|
* Copyright (C) 2024 ARM Ltd.
|
|
*/
|
|
|
|
#ifndef __ASM_RSI_H_
|
|
#define __ASM_RSI_H_
|
|
|
|
#include <linux/errno.h>
|
|
#include <linux/jump_label.h>
|
|
#include <asm/rsi_cmds.h>
|
|
|
|
#define RSI_PDEV_NAME "arm-cca-dev"
|
|
|
|
DECLARE_STATIC_KEY_FALSE(rsi_present);
|
|
|
|
void __init arm64_rsi_init(void);
|
|
|
|
bool arm64_rsi_is_protected(phys_addr_t base, size_t size);
|
|
|
|
static inline bool is_realm_world(void)
|
|
{
|
|
return static_branch_unlikely(&rsi_present);
|
|
}
|
|
|
|
static inline int rsi_set_memory_range(phys_addr_t start, phys_addr_t end,
|
|
enum ripas state, unsigned long flags)
|
|
{
|
|
unsigned long ret;
|
|
phys_addr_t top;
|
|
|
|
while (start != end) {
|
|
ret = rsi_set_addr_range_state(start, end, state, flags, &top);
|
|
if (ret || top < start || top > end)
|
|
return -EINVAL;
|
|
start = top;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
/*
|
|
* Convert the specified range to RAM. Do not use this if you rely on the
|
|
* contents of a page that may already be in RAM state.
|
|
*/
|
|
static inline int rsi_set_memory_range_protected(phys_addr_t start,
|
|
phys_addr_t end)
|
|
{
|
|
return rsi_set_memory_range(start, end, RSI_RIPAS_RAM,
|
|
RSI_CHANGE_DESTROYED);
|
|
}
|
|
|
|
/*
|
|
* Convert the specified range to RAM. Do not convert any pages that may have
|
|
* been DESTROYED, without our permission.
|
|
*/
|
|
static inline int rsi_set_memory_range_protected_safe(phys_addr_t start,
|
|
phys_addr_t end)
|
|
{
|
|
return rsi_set_memory_range(start, end, RSI_RIPAS_RAM,
|
|
RSI_NO_CHANGE_DESTROYED);
|
|
}
|
|
|
|
static inline int rsi_set_memory_range_shared(phys_addr_t start,
|
|
phys_addr_t end)
|
|
{
|
|
return rsi_set_memory_range(start, end, RSI_RIPAS_EMPTY,
|
|
RSI_CHANGE_DESTROYED);
|
|
}
|
|
#endif /* __ASM_RSI_H_ */
|