Skip to content

Commit 1a08f49

Browse files
committed
Merge branch kvm-arm64/ffa-proxy into kvmarm/next
* kvm-arm64/ffa-proxy: : pKVM FF-A Proxy, courtesy Will Deacon and Andrew Walbran : : From the cover letter: : : pKVM's primary goal is to protect guest pages from a compromised host by : enforcing access control restrictions using stage-2 page-tables. Sadly, : this cannot prevent TrustZone from accessing non-secure memory, and a : compromised host could, for example, perform a 'confused deputy' attack : by asking TrustZone to use pages that have been donated to protected : guests. This would effectively allow the host to have TrustZone : exfiltrate guest secrets on its behalf, hence breaking the isolation : that pKVM intends to provide. : : This series addresses this problem by providing pKVM with the ability to : monitor SMCs following the Arm FF-A protocol. FF-A provides (among other : things) a set of memory management APIs allowing the Normal World to : share, donate or lend pages with Secure. By monitoring these SMCs, pKVM : can ensure that the pages that are shared, lent or donated to Secure by : the host kernel are only pages that it owns. KVM: arm64: pkvm: Add support for fragmented FF-A descriptors KVM: arm64: Handle FFA_FEATURES call from the host KVM: arm64: Handle FFA_MEM_LEND calls from the host KVM: arm64: Handle FFA_MEM_RECLAIM calls from the host KVM: arm64: Handle FFA_MEM_SHARE calls from the host KVM: arm64: Add FF-A helpers to share/unshare memory with secure world KVM: arm64: Handle FFA_RXTX_MAP and FFA_RXTX_UNMAP calls from the host KVM: arm64: Allocate pages for hypervisor FF-A mailboxes KVM: arm64: Probe FF-A version and host/hyp partition ID during init KVM: arm64: Block unsafe FF-A calls from the host Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
2 parents 8351039 + 0a9f15f commit 1a08f49

12 files changed

Lines changed: 897 additions & 1 deletion

File tree

arch/arm64/include/asm/kvm_host.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,7 @@ struct kvm_host_data {
420420
struct kvm_host_psci_config {
421421
/* PSCI version used by host. */
422422
u32 version;
423+
u32 smccc_version;
423424

424425
/* Function IDs used by host if version is v0.1. */
425426
struct psci_0_1_function_ids function_ids_0_1;

arch/arm64/include/asm/kvm_pkvm.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
#ifndef __ARM64_KVM_PKVM_H__
77
#define __ARM64_KVM_PKVM_H__
88

9+
#include <linux/arm_ffa.h>
910
#include <linux/memblock.h>
11+
#include <linux/scatterlist.h>
1012
#include <asm/kvm_pgtable.h>
1113

1214
/* Maximum number of VMs that can co-exist under pKVM. */
@@ -106,4 +108,23 @@ static inline unsigned long host_s2_pgtable_pages(void)
106108
return res;
107109
}
108110

111+
#define KVM_FFA_MBOX_NR_PAGES 1
112+
113+
static inline unsigned long hyp_ffa_proxy_pages(void)
114+
{
115+
size_t desc_max;
116+
117+
/*
118+
* The hypervisor FFA proxy needs enough memory to buffer a fragmented
119+
* descriptor returned from EL3 in response to a RETRIEVE_REQ call.
120+
*/
121+
desc_max = sizeof(struct ffa_mem_region) +
122+
sizeof(struct ffa_mem_region_attributes) +
123+
sizeof(struct ffa_composite_mem_region) +
124+
SG_MAX_SEGMENTS * sizeof(struct ffa_mem_region_addr_range);
125+
126+
/* Plus a page each for the hypervisor's RX and TX mailboxes. */
127+
return (2 * KVM_FFA_MBOX_NR_PAGES) + DIV_ROUND_UP(desc_max, PAGE_SIZE);
128+
}
129+
109130
#endif /* __ARM64_KVM_PKVM_H__ */

arch/arm64/kvm/arm.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1938,6 +1938,7 @@ static bool __init init_psci_relay(void)
19381938
}
19391939

19401940
kvm_host_psci_config.version = psci_ops.get_version();
1941+
kvm_host_psci_config.smccc_version = arm_smccc_get_version();
19411942

19421943
if (kvm_host_psci_config.version == PSCI_VERSION(0, 1)) {
19431944
kvm_host_psci_config.function_ids_0_1 = get_psci_0_1_function_ids();
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/* SPDX-License-Identifier: GPL-2.0-only */
2+
/*
3+
* Copyright (C) 2022 - Google LLC
4+
* Author: Andrew Walbran <qwandor@google.com>
5+
*/
6+
#ifndef __KVM_HYP_FFA_H
7+
#define __KVM_HYP_FFA_H
8+
9+
#include <asm/kvm_host.h>
10+
11+
#define FFA_MIN_FUNC_NUM 0x60
12+
#define FFA_MAX_FUNC_NUM 0x7F
13+
14+
int hyp_ffa_init(void *pages);
15+
bool kvm_host_ffa_handler(struct kvm_cpu_context *host_ctxt);
16+
17+
#endif /* __KVM_HYP_FFA_H */

arch/arm64/kvm/hyp/include/nvhe/mem_protect.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ extern struct host_mmu host_mmu;
5757
enum pkvm_component_id {
5858
PKVM_ID_HOST,
5959
PKVM_ID_HYP,
60+
PKVM_ID_FFA,
6061
};
6162

6263
extern unsigned long hyp_nr_cpus;
@@ -66,6 +67,8 @@ int __pkvm_host_share_hyp(u64 pfn);
6667
int __pkvm_host_unshare_hyp(u64 pfn);
6768
int __pkvm_host_donate_hyp(u64 pfn, u64 nr_pages);
6869
int __pkvm_hyp_donate_host(u64 pfn, u64 nr_pages);
70+
int __pkvm_host_share_ffa(u64 pfn, u64 nr_pages);
71+
int __pkvm_host_unshare_ffa(u64 pfn, u64 nr_pages);
6972

7073
bool addr_is_memory(phys_addr_t phys);
7174
int host_stage2_idmap_locked(phys_addr_t addr, u64 size, enum kvm_pgtable_prot prot);

arch/arm64/kvm/hyp/nvhe/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ lib-objs := $(addprefix ../../../lib/, $(lib-objs))
2222

2323
hyp-obj-y := timer-sr.o sysreg-sr.o debug-sr.o switch.o tlb.o hyp-init.o host.o \
2424
hyp-main.o hyp-smp.o psci-relay.o early_alloc.o page_alloc.o \
25-
cache.o setup.o mm.o mem_protect.o sys_regs.o pkvm.o stacktrace.o
25+
cache.o setup.o mm.o mem_protect.o sys_regs.o pkvm.o stacktrace.o ffa.o
2626
hyp-obj-y += ../vgic-v3-sr.o ../aarch32.o ../vgic-v2-cpuif-proxy.o ../entry.o \
2727
../fpsimd.o ../hyp-entry.o ../exception.o ../pgtable.o
2828
hyp-obj-$(CONFIG_DEBUG_LIST) += list_debug.o

0 commit comments

Comments
 (0)