File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -106,4 +106,12 @@ static inline unsigned long host_s2_pgtable_pages(void)
106106 return res ;
107107}
108108
109+ #define KVM_FFA_MBOX_NR_PAGES 1
110+
111+ static inline unsigned long hyp_ffa_proxy_pages (void )
112+ {
113+ /* A page each for the hypervisor's RX and TX mailboxes. */
114+ return 2 * KVM_FFA_MBOX_NR_PAGES ;
115+ }
116+
109117#endif /* __ARM64_KVM_PKVM_H__ */
Original file line number Diff line number Diff line change 1111#define FFA_MIN_FUNC_NUM 0x60
1212#define FFA_MAX_FUNC_NUM 0x7F
1313
14- int hyp_ffa_init (void );
14+ int hyp_ffa_init (void * pages );
1515bool kvm_host_ffa_handler (struct kvm_cpu_context * host_ctxt );
1616
1717#endif /* __KVM_HYP_FFA_H */
Original file line number Diff line number Diff line change 2828
2929#include <linux/arm-smccc.h>
3030#include <linux/arm_ffa.h>
31+ #include <asm/kvm_pkvm.h>
32+
3133#include <nvhe/ffa.h>
3234#include <nvhe/trap_handler.h>
35+ #include <nvhe/spinlock.h>
3336
3437/*
3538 * "ID value 0 must be returned at the Non-secure physical FF-A instance"
3639 * We share this ID with the host.
3740 */
3841#define HOST_FFA_ID 0
3942
43+ struct kvm_ffa_buffers {
44+ hyp_spinlock_t lock ;
45+ void * tx ;
46+ void * rx ;
47+ };
48+
49+ /*
50+ * Note that we don't currently lock these buffers explicitly, instead
51+ * relying on the locking of the host FFA buffers as we only have one
52+ * client.
53+ */
54+ static struct kvm_ffa_buffers hyp_buffers ;
55+
4056static void ffa_to_smccc_error (struct arm_smccc_res * res , u64 ffa_errno )
4157{
4258 * res = (struct arm_smccc_res ) {
@@ -124,7 +140,7 @@ bool kvm_host_ffa_handler(struct kvm_cpu_context *host_ctxt)
124140 return true;
125141}
126142
127- int hyp_ffa_init (void )
143+ int hyp_ffa_init (void * pages )
128144{
129145 struct arm_smccc_res res ;
130146
@@ -145,5 +161,11 @@ int hyp_ffa_init(void)
145161 if (res .a2 != HOST_FFA_ID )
146162 return - EINVAL ;
147163
164+ hyp_buffers = (struct kvm_ffa_buffers ) {
165+ .lock = __HYP_SPIN_LOCK_UNLOCKED ,
166+ .tx = pages ,
167+ .rx = pages + (KVM_FFA_MBOX_NR_PAGES * PAGE_SIZE ),
168+ };
169+
148170 return 0 ;
149171}
Original file line number Diff line number Diff line change @@ -29,6 +29,7 @@ static void *vmemmap_base;
2929static void * vm_table_base ;
3030static void * hyp_pgt_base ;
3131static void * host_s2_pgt_base ;
32+ static void * ffa_proxy_pages ;
3233static struct kvm_pgtable_mm_ops pkvm_pgtable_mm_ops ;
3334static struct hyp_pool hpool ;
3435
@@ -58,6 +59,11 @@ static int divide_memory_pool(void *virt, unsigned long size)
5859 if (!host_s2_pgt_base )
5960 return - ENOMEM ;
6061
62+ nr_pages = hyp_ffa_proxy_pages ();
63+ ffa_proxy_pages = hyp_early_alloc_contig (nr_pages );
64+ if (!ffa_proxy_pages )
65+ return - ENOMEM ;
66+
6167 return 0 ;
6268}
6369
@@ -315,7 +321,7 @@ void __noreturn __pkvm_init_finalise(void)
315321 if (ret )
316322 goto out ;
317323
318- ret = hyp_ffa_init ();
324+ ret = hyp_ffa_init (ffa_proxy_pages );
319325 if (ret )
320326 goto out ;
321327
Original file line number Diff line number Diff line change @@ -78,6 +78,7 @@ void __init kvm_hyp_reserve(void)
7878 hyp_mem_pages += host_s2_pgtable_pages ();
7979 hyp_mem_pages += hyp_vm_table_pages ();
8080 hyp_mem_pages += hyp_vmemmap_pages (STRUCT_HYP_PAGE_SIZE );
81+ hyp_mem_pages += hyp_ffa_proxy_pages ();
8182
8283 /*
8384 * Try to allocate a PMD-aligned region to reduce TLB pressure once
You can’t perform that action at this time.
0 commit comments