Skip to content

Commit 8884fd1

Browse files
author
Marc Zyngier
committed
Merge branch kvm-arm64/mmu-misc-6.12 into kvmarm-master/next
* kvm-arm64/mmu-misc-6.12: : . : Various minor MMU improvements and bug-fixes: : : - Prevent MTE tags being restored by userspace if we are actively : logging writes, as that's a recipe for disaster : : - Correct the refcount on a page that is not considered for MTE : tag copying (such as a device) : : - When walking a page table to split blocks, keep the DSB at the end : the walk, as there is no need to perform it on every store. : : - Fix boundary check when transfering memory using FFA : . KVM: arm64: Add memory length checks and remove inline in do_ffa_mem_xfer KVM: arm64: Disallow copying MTE to guest memory while KVM is dirty logging KVM: arm64: Release pfn, i.e. put page, if copying MTE tags hits ZONE_DEVICE KVM: arm64: Move data barrier to end of split walk Signed-off-by: Marc Zyngier <[email protected]>
2 parents 0d56099 + f26a525 commit 8884fd1

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

arch/arm64/kvm/guest.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,6 +1045,11 @@ int kvm_vm_ioctl_mte_copy_tags(struct kvm *kvm,
10451045

10461046
mutex_lock(&kvm->slots_lock);
10471047

1048+
if (write && atomic_read(&kvm->nr_memslots_dirty_logging)) {
1049+
ret = -EBUSY;
1050+
goto out;
1051+
}
1052+
10481053
while (length > 0) {
10491054
kvm_pfn_t pfn = gfn_to_pfn_prot(kvm, gfn, write, NULL);
10501055
void *maddr;
@@ -1059,6 +1064,7 @@ int kvm_vm_ioctl_mte_copy_tags(struct kvm *kvm,
10591064
page = pfn_to_online_page(pfn);
10601065
if (!page) {
10611066
/* Reject ZONE_DEVICE memory */
1067+
kvm_release_pfn_clean(pfn);
10621068
ret = -EFAULT;
10631069
goto out;
10641070
}

arch/arm64/kvm/hyp/nvhe/ffa.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -426,9 +426,9 @@ static void do_ffa_mem_frag_tx(struct arm_smccc_res *res,
426426
return;
427427
}
428428

429-
static __always_inline void do_ffa_mem_xfer(const u64 func_id,
430-
struct arm_smccc_res *res,
431-
struct kvm_cpu_context *ctxt)
429+
static void __do_ffa_mem_xfer(const u64 func_id,
430+
struct arm_smccc_res *res,
431+
struct kvm_cpu_context *ctxt)
432432
{
433433
DECLARE_REG(u32, len, ctxt, 1);
434434
DECLARE_REG(u32, fraglen, ctxt, 2);
@@ -440,9 +440,6 @@ static __always_inline void do_ffa_mem_xfer(const u64 func_id,
440440
u32 offset, nr_ranges;
441441
int ret = 0;
442442

443-
BUILD_BUG_ON(func_id != FFA_FN64_MEM_SHARE &&
444-
func_id != FFA_FN64_MEM_LEND);
445-
446443
if (addr_mbz || npages_mbz || fraglen > len ||
447444
fraglen > KVM_FFA_MBOX_NR_PAGES * PAGE_SIZE) {
448445
ret = FFA_RET_INVALID_PARAMETERS;
@@ -461,6 +458,11 @@ static __always_inline void do_ffa_mem_xfer(const u64 func_id,
461458
goto out_unlock;
462459
}
463460

461+
if (len > ffa_desc_buf.len) {
462+
ret = FFA_RET_NO_MEMORY;
463+
goto out_unlock;
464+
}
465+
464466
buf = hyp_buffers.tx;
465467
memcpy(buf, host_buffers.tx, fraglen);
466468

@@ -512,6 +514,13 @@ static __always_inline void do_ffa_mem_xfer(const u64 func_id,
512514
goto out_unlock;
513515
}
514516

517+
#define do_ffa_mem_xfer(fid, res, ctxt) \
518+
do { \
519+
BUILD_BUG_ON((fid) != FFA_FN64_MEM_SHARE && \
520+
(fid) != FFA_FN64_MEM_LEND); \
521+
__do_ffa_mem_xfer((fid), (res), (ctxt)); \
522+
} while (0);
523+
515524
static void do_ffa_mem_reclaim(struct arm_smccc_res *res,
516525
struct kvm_cpu_context *ctxt)
517526
{

arch/arm64/kvm/hyp/pgtable.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1547,7 +1547,6 @@ static int stage2_split_walker(const struct kvm_pgtable_visit_ctx *ctx,
15471547
*/
15481548
new = kvm_init_table_pte(childp, mm_ops);
15491549
stage2_make_pte(ctx, new);
1550-
dsb(ishst);
15511550
return 0;
15521551
}
15531552

@@ -1559,8 +1558,11 @@ int kvm_pgtable_stage2_split(struct kvm_pgtable *pgt, u64 addr, u64 size,
15591558
.flags = KVM_PGTABLE_WALK_LEAF,
15601559
.arg = mc,
15611560
};
1561+
int ret;
15621562

1563-
return kvm_pgtable_walk(pgt, addr, size, &walker);
1563+
ret = kvm_pgtable_walk(pgt, addr, size, &walker);
1564+
dsb(ishst);
1565+
return ret;
15641566
}
15651567

15661568
int __kvm_pgtable_stage2_init(struct kvm_pgtable *pgt, struct kvm_s2_mmu *mmu,

0 commit comments

Comments
 (0)