Thread (9 messages) 9 messages, 3 authors, 2020-12-15

Re: [RFC PATCH] KVM: arm64: Add prejudgement for relaxing permissions only case in stage2 translation fault handler

From: Will Deacon <will@kernel.org>
Date: 2020-12-11 10:02:07
Also in: lkml

On Fri, Dec 11, 2020 at 09:49:28AM +0000, Marc Zyngier wrote:
On 2020-12-11 08:01, Yanan Wang wrote:
quoted
@@ -461,25 +462,56 @@ static int stage2_map_set_prot_attr(enum
kvm_pgtable_prot prot,
 	return 0;
 }

+static bool stage2_set_valid_leaf_pte_pre(u64 addr, u32 level,
+					  kvm_pte_t *ptep, kvm_pte_t new,
+					  struct stage2_map_data *data)
+{
+	kvm_pte_t old = *ptep, old_attr, new_attr;
+
+	if ((old ^ new) & (~KVM_PTE_LEAF_ATTR_PERMS))
+		return false;
+
+	/*
+	 * Skip updating if we are trying to recreate exactly the same mapping
+	 * or to reduce the access permissions only. And update the valid leaf
+	 * PTE without break-before-make if we are trying to add more access
+	 * permissions only.
+	 */
+	old_attr = (old & KVM_PTE_LEAF_ATTR_PERMS) ^
KVM_PTE_LEAF_ATTR_HI_S2_XN;
+	new_attr = (new & KVM_PTE_LEAF_ATTR_PERMS) ^
KVM_PTE_LEAF_ATTR_HI_S2_XN;
+	if (new_attr <= old_attr)
+		return true;
+
+	WRITE_ONCE(*ptep, new);
+	kvm_call_hyp(__kvm_tlb_flush_vmid_ipa, data->mmu, addr, level);
I think what bothers me the most here is that we are turning a mapping into
a permission update, which makes the code really hard to read, and mixes
two things that were so far separate.

I wonder whether we should instead abort the update and simply take the
fault
again, if we ever need to do it.
That's a nice idea. If we could enforce that we don't alter permissions on
the map path, and instead just return e.g. -EAGAIN then that would be a
very neat solution and would cement the permission vs translation fault
division.

Will

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help