mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-08-31 11:41:29 -04:00
Merge branch 'for-next/coco' into for-next/core
* for-next/coco: arm64: RSI: fix field-spanning write warning in attestation token init virt: arm-cca-guest: Drop unused assignment of platform_device_id driver data arm64/coco: Add pKVM as a CC platform arm64/mm: Simplify SWIOTLB setup in arch_mm_preinit() virt: arm-cca-guest: use migrate_disable() for attestation token requests
This commit is contained in:
@@ -3,6 +3,9 @@
|
||||
#define _ASM_ARM64_HYPERVISOR_H
|
||||
|
||||
#include <asm/xen/hypervisor.h>
|
||||
#include <linux/jump_label.h>
|
||||
|
||||
DECLARE_STATIC_KEY_FALSE(pkvm_guest);
|
||||
|
||||
void kvm_init_hyp_services(void);
|
||||
bool kvm_arm_hyp_service_available(u32 func_id);
|
||||
@@ -10,8 +13,18 @@ void kvm_arm_target_impl_cpu_init(void);
|
||||
|
||||
#ifdef CONFIG_ARM_PKVM_GUEST
|
||||
void pkvm_init_hyp_services(void);
|
||||
|
||||
static inline bool is_protected_kvm_guest(void)
|
||||
{
|
||||
return static_branch_unlikely(&pkvm_guest);
|
||||
}
|
||||
#else
|
||||
static inline void pkvm_init_hyp_services(void) { };
|
||||
|
||||
static inline bool is_protected_kvm_guest(void)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
static inline void kvm_arch_init_hyp_services(void)
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#ifndef __ASM_MEM_ENCRYPT_H
|
||||
#define __ASM_MEM_ENCRYPT_H
|
||||
|
||||
#include <asm/hypervisor.h>
|
||||
#include <asm/rsi.h>
|
||||
|
||||
struct device;
|
||||
@@ -20,7 +21,7 @@ int realm_register_memory_enc_ops(void);
|
||||
|
||||
static inline bool force_dma_unencrypted(struct device *dev)
|
||||
{
|
||||
return is_realm_world();
|
||||
return is_realm_world() || is_protected_kvm_guest();
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -88,6 +88,14 @@ static inline long rsi_set_addr_range_state(phys_addr_t start,
|
||||
return res.a0;
|
||||
}
|
||||
|
||||
#define RSI_ATTEST_CHALLENGE_MIN_SIZE 32
|
||||
#define RSI_ATTEST_CHALLENGE_MAX_SIZE 64
|
||||
|
||||
struct rsi_attestation_token_init_args {
|
||||
unsigned long fid;
|
||||
u8 challenge[RSI_ATTEST_CHALLENGE_MAX_SIZE];
|
||||
};
|
||||
|
||||
/**
|
||||
* rsi_attestation_token_init - Initialise the operation to retrieve an
|
||||
* attestation token.
|
||||
@@ -109,18 +117,21 @@ static inline long rsi_set_addr_range_state(phys_addr_t start,
|
||||
static inline long
|
||||
rsi_attestation_token_init(const u8 *challenge, unsigned long size)
|
||||
{
|
||||
struct arm_smccc_1_2_regs regs = { 0 };
|
||||
union {
|
||||
struct arm_smccc_1_2_regs regs;
|
||||
struct rsi_attestation_token_init_args init;
|
||||
} args = { 0 };
|
||||
|
||||
/* The challenge must be at least 32bytes and at most 64bytes */
|
||||
if (!challenge || size < 32 || size > 64)
|
||||
if (!challenge || size < RSI_ATTEST_CHALLENGE_MIN_SIZE ||
|
||||
size > RSI_ATTEST_CHALLENGE_MAX_SIZE)
|
||||
return -EINVAL;
|
||||
|
||||
regs.a0 = SMC_RSI_ATTESTATION_TOKEN_INIT;
|
||||
memcpy(®s.a1, challenge, size);
|
||||
arm_smccc_1_2_smc(®s, ®s);
|
||||
args.init.fid = SMC_RSI_ATTESTATION_TOKEN_INIT;
|
||||
memcpy(args.init.challenge, challenge, size);
|
||||
arm_smccc_1_2_smc(&args.regs, &args.regs);
|
||||
|
||||
if (regs.a0 == RSI_SUCCESS)
|
||||
return regs.a1;
|
||||
if (args.regs.a0 == RSI_SUCCESS)
|
||||
return args.regs.a1;
|
||||
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
#include <linux/memblock.h>
|
||||
#include <linux/psci.h>
|
||||
#include <linux/swiotlb.h>
|
||||
#include <linux/cc_platform.h>
|
||||
#include <linux/platform_device.h>
|
||||
|
||||
#include <asm/io.h>
|
||||
@@ -23,17 +22,6 @@ EXPORT_SYMBOL(prot_ns_shared);
|
||||
DEFINE_STATIC_KEY_FALSE_RO(rsi_present);
|
||||
EXPORT_SYMBOL(rsi_present);
|
||||
|
||||
bool cc_platform_has(enum cc_attr attr)
|
||||
{
|
||||
switch (attr) {
|
||||
case CC_ATTR_MEM_ENCRYPT:
|
||||
return is_realm_world();
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(cc_platform_has);
|
||||
|
||||
static bool rsi_version_matches(void)
|
||||
{
|
||||
unsigned long ver_lower, ver_higher;
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include <linux/errno.h>
|
||||
#include <linux/swap.h>
|
||||
#include <linux/init.h>
|
||||
#include <linux/cc_platform.h>
|
||||
#include <linux/cache.h>
|
||||
#include <linux/mman.h>
|
||||
#include <linux/nodemask.h>
|
||||
@@ -36,6 +37,7 @@
|
||||
|
||||
#include <asm/boot.h>
|
||||
#include <asm/fixmap.h>
|
||||
#include <asm/hypervisor.h>
|
||||
#include <asm/kasan.h>
|
||||
#include <asm/kernel-pgtable.h>
|
||||
#include <asm/kvm_host.h>
|
||||
@@ -336,25 +338,21 @@ void __init arch_setup_zero_pages(void)
|
||||
void __init arch_mm_preinit(void)
|
||||
{
|
||||
unsigned int flags = SWIOTLB_VERBOSE;
|
||||
bool swiotlb = max_pfn > PFN_DOWN(arm64_dma_phys_limit);
|
||||
|
||||
if (is_realm_world()) {
|
||||
swiotlb = true;
|
||||
if (is_realm_world() || is_protected_kvm_guest()) {
|
||||
flags |= SWIOTLB_FORCE;
|
||||
}
|
||||
|
||||
if (IS_ENABLED(CONFIG_DMA_BOUNCE_UNALIGNED_KMALLOC) && !swiotlb) {
|
||||
} else if (max_pfn <= PFN_DOWN(arm64_dma_phys_limit)) {
|
||||
/*
|
||||
* If no bouncing needed for ZONE_DMA, reduce the swiotlb
|
||||
* buffer for kmalloc() bouncing to 1MB per 1GB of RAM.
|
||||
*/
|
||||
unsigned long size =
|
||||
DIV_ROUND_UP(memblock_phys_mem_size(), 1024);
|
||||
|
||||
swiotlb_adjust_size(min(swiotlb_size_or_default(), size));
|
||||
swiotlb = true;
|
||||
}
|
||||
|
||||
swiotlb_init(swiotlb, flags);
|
||||
swiotlb_init(true, flags);
|
||||
|
||||
/*
|
||||
* Check boundaries twice: Some fundamental inconsistencies can be
|
||||
@@ -416,6 +414,17 @@ void dump_mem_limit(void)
|
||||
}
|
||||
}
|
||||
|
||||
bool cc_platform_has(enum cc_attr attr)
|
||||
{
|
||||
switch (attr) {
|
||||
case CC_ATTR_MEM_ENCRYPT:
|
||||
return is_realm_world() || is_protected_kvm_guest();
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(cc_platform_has);
|
||||
|
||||
#ifdef CONFIG_EXECMEM
|
||||
static u64 module_direct_base __ro_after_init = 0;
|
||||
static u64 module_plt_base __ro_after_init = 0;
|
||||
|
||||
@@ -16,54 +16,38 @@
|
||||
|
||||
/**
|
||||
* struct arm_cca_token_info - a descriptor for the token buffer.
|
||||
* @challenge: Pointer to the challenge data
|
||||
* @challenge_size: Size of the challenge data
|
||||
* @granule: PA of the granule to which the token will be written
|
||||
* @offset: Offset within granule to start of buffer in bytes
|
||||
* @result: result of rsi_attestation_token_continue operation
|
||||
*/
|
||||
struct arm_cca_token_info {
|
||||
void *challenge;
|
||||
unsigned long challenge_size;
|
||||
phys_addr_t granule;
|
||||
unsigned long offset;
|
||||
unsigned long result;
|
||||
};
|
||||
|
||||
static void arm_cca_attestation_init(void *param)
|
||||
{
|
||||
struct arm_cca_token_info *info;
|
||||
|
||||
info = (struct arm_cca_token_info *)param;
|
||||
|
||||
info->result = rsi_attestation_token_init(info->challenge,
|
||||
info->challenge_size);
|
||||
}
|
||||
|
||||
/**
|
||||
* arm_cca_attestation_continue - Retrieve the attestation token data.
|
||||
*
|
||||
* @param: pointer to the arm_cca_token_info
|
||||
* @info: pointer to the arm_cca_token_info
|
||||
*
|
||||
* Attestation token generation is a long running operation and therefore
|
||||
* the token data may not be retrieved in a single call. Moreover, the
|
||||
* token retrieval operation must be requested on the same CPU on which the
|
||||
* attestation token generation was initialised.
|
||||
* This helper function is therefore scheduled on the same CPU multiple
|
||||
* This helper function must therefore be executed on the same CPU multiple
|
||||
* times until the entire token data is retrieved.
|
||||
*/
|
||||
static void arm_cca_attestation_continue(void *param)
|
||||
static unsigned long
|
||||
arm_cca_attestation_continue(struct arm_cca_token_info *info)
|
||||
{
|
||||
unsigned long ret;
|
||||
unsigned long len;
|
||||
unsigned long size;
|
||||
struct arm_cca_token_info *info;
|
||||
|
||||
info = (struct arm_cca_token_info *)param;
|
||||
|
||||
size = RSI_GRANULE_SIZE - info->offset;
|
||||
info->result = rsi_attestation_token_continue(info->granule,
|
||||
info->offset, size, &len);
|
||||
ret = rsi_attestation_token_continue(info->granule, info->offset, size,
|
||||
&len);
|
||||
info->offset += len;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -74,8 +58,8 @@ static void arm_cca_attestation_continue(void *param)
|
||||
*
|
||||
* Initialise the attestation token generation using the challenge data
|
||||
* passed in the TSM descriptor. Allocate memory for the attestation token
|
||||
* and schedule calls to retrieve the attestation token on the same CPU
|
||||
* on which the attestation token generation was initialised.
|
||||
* and retrieve the attestation token on the same CPU on which the
|
||||
* attestation token generation was initialised.
|
||||
*
|
||||
* The challenge data must be at least 32 bytes and no more than 64 bytes. If
|
||||
* less than 64 bytes are provided it will be zero padded to 64 bytes.
|
||||
@@ -85,12 +69,11 @@ static void arm_cca_attestation_continue(void *param)
|
||||
* * %-EINVAL - A parameter was not valid.
|
||||
* * %-ENOMEM - Out of memory.
|
||||
* * %-EFAULT - Failed to get IPA for memory page(s).
|
||||
* * A negative status code as returned by smp_call_function_single().
|
||||
*/
|
||||
static int arm_cca_report_new(struct tsm_report *report, void *data)
|
||||
{
|
||||
int ret;
|
||||
int cpu;
|
||||
int ret = 0;
|
||||
unsigned long rsi_result;
|
||||
long max_size;
|
||||
unsigned long token_size = 0;
|
||||
struct arm_cca_token_info info;
|
||||
@@ -103,37 +86,33 @@ static int arm_cca_report_new(struct tsm_report *report, void *data)
|
||||
|
||||
/*
|
||||
* The attestation token 'init' and 'continue' calls must be
|
||||
* performed on the same CPU. smp_call_function_single() is used
|
||||
* instead of simply calling get_cpu() because of the need to
|
||||
* allocate outblob based on the returned value from the 'init'
|
||||
* call and that cannot be done in an atomic context.
|
||||
* performed on the same CPU, so disable CPU migration around
|
||||
* those operations.
|
||||
*/
|
||||
cpu = smp_processor_id();
|
||||
migrate_disable();
|
||||
|
||||
info.challenge = desc->inblob;
|
||||
info.challenge_size = desc->inblob_len;
|
||||
|
||||
ret = smp_call_function_single(cpu, arm_cca_attestation_init,
|
||||
&info, true);
|
||||
if (ret)
|
||||
return ret;
|
||||
max_size = info.result;
|
||||
|
||||
if (max_size <= 0)
|
||||
return -EINVAL;
|
||||
max_size = rsi_attestation_token_init(desc->inblob, desc->inblob_len);
|
||||
if (max_size <= 0) {
|
||||
ret = -EINVAL;
|
||||
goto exit_migrate_enable;
|
||||
}
|
||||
|
||||
/* Allocate outblob */
|
||||
token = kvzalloc(max_size, GFP_KERNEL);
|
||||
if (!token)
|
||||
return -ENOMEM;
|
||||
if (!token) {
|
||||
ret = -ENOMEM;
|
||||
goto exit_migrate_enable;
|
||||
}
|
||||
|
||||
/*
|
||||
* Since the outblob may not be physically contiguous, use a page
|
||||
* to bounce the buffer from RMM.
|
||||
*/
|
||||
buf = alloc_pages_exact(RSI_GRANULE_SIZE, GFP_KERNEL);
|
||||
if (!buf)
|
||||
return -ENOMEM;
|
||||
if (!buf) {
|
||||
ret = -ENOMEM;
|
||||
goto exit_migrate_enable;
|
||||
}
|
||||
|
||||
/* Get the PA of the memory page(s) that were allocated */
|
||||
info.granule = (unsigned long)virt_to_phys(buf);
|
||||
@@ -144,21 +123,15 @@ static int arm_cca_report_new(struct tsm_report *report, void *data)
|
||||
info.offset = 0;
|
||||
do {
|
||||
/*
|
||||
* Schedule a call to retrieve a sub-granule chunk
|
||||
* of data per loop iteration.
|
||||
* Retrieve a sub-granule chunk of data per loop
|
||||
* iteration.
|
||||
*/
|
||||
ret = smp_call_function_single(cpu,
|
||||
arm_cca_attestation_continue,
|
||||
(void *)&info, true);
|
||||
if (ret != 0) {
|
||||
token_size = 0;
|
||||
goto exit_free_granule_page;
|
||||
}
|
||||
} while (info.result == RSI_INCOMPLETE &&
|
||||
rsi_result = arm_cca_attestation_continue(&info);
|
||||
} while (rsi_result == RSI_INCOMPLETE &&
|
||||
info.offset < RSI_GRANULE_SIZE);
|
||||
|
||||
/* Break out in case of failure */
|
||||
if (info.result != RSI_SUCCESS && info.result != RSI_INCOMPLETE) {
|
||||
if (rsi_result != RSI_SUCCESS && rsi_result != RSI_INCOMPLETE) {
|
||||
ret = -ENXIO;
|
||||
token_size = 0;
|
||||
goto exit_free_granule_page;
|
||||
@@ -173,12 +146,14 @@ static int arm_cca_report_new(struct tsm_report *report, void *data)
|
||||
break;
|
||||
memcpy(&token[token_size], buf, info.offset);
|
||||
token_size += info.offset;
|
||||
} while (info.result == RSI_INCOMPLETE);
|
||||
} while (rsi_result == RSI_INCOMPLETE);
|
||||
|
||||
report->outblob = no_free_ptr(token);
|
||||
exit_free_granule_page:
|
||||
report->outblob_len = token_size;
|
||||
free_pages_exact(buf, RSI_GRANULE_SIZE);
|
||||
exit_migrate_enable:
|
||||
migrate_enable();
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -223,7 +198,7 @@ module_exit(arm_cca_guest_exit);
|
||||
|
||||
/* modalias, so userspace can autoload this module when RSI is available */
|
||||
static const struct platform_device_id arm_cca_match[] __maybe_unused = {
|
||||
{ RSI_PDEV_NAME, 0},
|
||||
{ .name = RSI_PDEV_NAME },
|
||||
{ }
|
||||
};
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include <asm/hypervisor.h>
|
||||
|
||||
static size_t pkvm_granule;
|
||||
DEFINE_STATIC_KEY_FALSE_RO(pkvm_guest);
|
||||
|
||||
static int arm_smccc_do_one_page(u32 func_id, phys_addr_t phys)
|
||||
{
|
||||
@@ -120,4 +121,6 @@ void pkvm_init_hyp_services(void)
|
||||
|
||||
if (kvm_arm_hyp_service_available(ARM_SMCCC_KVM_FUNC_MMIO_GUARD))
|
||||
arm64_ioremap_prot_hook_register(&mmio_guard_ioremap_hook);
|
||||
|
||||
static_branch_enable(&pkvm_guest);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user