All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/3] RFC: Solve several problems in stage 2 translation
@ 2020-12-16 12:28 ` Yanan Wang
  0 siblings, 0 replies; 18+ messages in thread
From: Yanan Wang @ 2020-12-16 12:28 UTC (permalink / raw)
  To: linux-kernel, linux-arm-kernel, Marc Zyngier, Catalin Marinas,
	Will Deacon, James Morse, Julien Thierry, Suzuki K Poulose,
	Gavin Shan, Quentin Perret
  Cc: wanghaibin.wang, yezengruan, zhukeqian1, yuzenghui, Yanan Wang

Hi, this is the second version, thanks for reading.

PATCH1/3:
Procedures of hyp stage 1 mapping and guest stage 2 mapping are different, but
they are tied closely by function kvm_set_valid_leaf_pte(). So separate them by
rewriting kvm_set_valid_leaf_pte().

PATCH2/3:
To avoid unnecessary update and small loops, add prejudgement in the translation
fault handler: Skip updating the PTE with break-before-make if we are trying to
recreate the exact same mapping or only change the access permissions. Actually,
change of permissions will be handled through the relax_perms path next time if
necessary.

(1) If there are some vCPUs accessing the same GPA at the same time and the leaf
PTE is not set yet, then they will all cause translation faults and the first vCPU
holding mmu_lock will set valid leaf PTE, and the others will later update the old
PTE with a new one if they are different.

(2) When changing a leaf entry or a table entry with break-before-make, if there
are some vCPUs accessing the same GPA just catch the moment when the target PTE
is set invalid in a BBM procedure coincidentally, they will all cause translation
faults and will later update the old PTE with a new one if they are different.

The worst case can be like this: vCPU A causes a translation fault with RW prot and
sets the leaf PTE with RW permissions, and then the next vCPU B with RO prot updates
the PTE back to RO permissions with break-before-make. And the BBM-invalid moment
may trigger more unnecessary translation faults, then some useless small loops might
occur which could lead to vCPU stuck.

PATCH3/3:
We now mark the page dirty and set the bitmap before calling fault handlers in
user_mem_abort(), and we might end up having spurious dirty pages if update of
permissions or mapping has failed. So, mark the page dirty only if the fault is
handled successfully.

Let the guest directly enter again but not return to userspace if we were trying
to recreate the same mapping or only change access permissions with BBM, which is
not permitted in the mapping path.

Changes from v1:
- Make part of the diff as an independent patch (PATCH1/3),
  and add Will's Signed-off-by.
- Use *return -EPERM* way when changing permissions only in the mapping path.
- Add a new patch (PATCH3/3).

Yanan Wang (3):
  KVM: arm64: Decouple partial code of hyp stage 1 mapping and guest
    stage 2 mapping
  KVM: arm64: Add prejudgement for relaxing permissions only case in
    stage2 translation fault handler
  KVM: arm64: Mark the page dirty only if the fault is handled
    successfully

 arch/arm64/kvm/hyp/pgtable.c | 78 ++++++++++++++++++++----------------
 arch/arm64/kvm/mmu.c         | 18 +++++++--
 2 files changed, 58 insertions(+), 38 deletions(-)

-- 
2.19.1


^ permalink raw reply	[flat|nested] 18+ messages in thread

* [PATCH v2 0/3] RFC: Solve several problems in stage 2 translation
@ 2020-12-16 12:28 ` Yanan Wang
  0 siblings, 0 replies; 18+ messages in thread
From: Yanan Wang @ 2020-12-16 12:28 UTC (permalink / raw)
  To: linux-kernel, linux-arm-kernel, Marc Zyngier, Catalin Marinas,
	Will Deacon, James Morse, Julien Thierry, Suzuki K Poulose,
	Gavin Shan, Quentin Perret
  Cc: yuzenghui, wanghaibin.wang, Yanan Wang, zhukeqian1, yezengruan

Hi, this is the second version, thanks for reading.

PATCH1/3:
Procedures of hyp stage 1 mapping and guest stage 2 mapping are different, but
they are tied closely by function kvm_set_valid_leaf_pte(). So separate them by
rewriting kvm_set_valid_leaf_pte().

PATCH2/3:
To avoid unnecessary update and small loops, add prejudgement in the translation
fault handler: Skip updating the PTE with break-before-make if we are trying to
recreate the exact same mapping or only change the access permissions. Actually,
change of permissions will be handled through the relax_perms path next time if
necessary.

(1) If there are some vCPUs accessing the same GPA at the same time and the leaf
PTE is not set yet, then they will all cause translation faults and the first vCPU
holding mmu_lock will set valid leaf PTE, and the others will later update the old
PTE with a new one if they are different.

(2) When changing a leaf entry or a table entry with break-before-make, if there
are some vCPUs accessing the same GPA just catch the moment when the target PTE
is set invalid in a BBM procedure coincidentally, they will all cause translation
faults and will later update the old PTE with a new one if they are different.

The worst case can be like this: vCPU A causes a translation fault with RW prot and
sets the leaf PTE with RW permissions, and then the next vCPU B with RO prot updates
the PTE back to RO permissions with break-before-make. And the BBM-invalid moment
may trigger more unnecessary translation faults, then some useless small loops might
occur which could lead to vCPU stuck.

PATCH3/3:
We now mark the page dirty and set the bitmap before calling fault handlers in
user_mem_abort(), and we might end up having spurious dirty pages if update of
permissions or mapping has failed. So, mark the page dirty only if the fault is
handled successfully.

Let the guest directly enter again but not return to userspace if we were trying
to recreate the same mapping or only change access permissions with BBM, which is
not permitted in the mapping path.

Changes from v1:
- Make part of the diff as an independent patch (PATCH1/3),
  and add Will's Signed-off-by.
- Use *return -EPERM* way when changing permissions only in the mapping path.
- Add a new patch (PATCH3/3).

Yanan Wang (3):
  KVM: arm64: Decouple partial code of hyp stage 1 mapping and guest
    stage 2 mapping
  KVM: arm64: Add prejudgement for relaxing permissions only case in
    stage2 translation fault handler
  KVM: arm64: Mark the page dirty only if the fault is handled
    successfully

 arch/arm64/kvm/hyp/pgtable.c | 78 ++++++++++++++++++++----------------
 arch/arm64/kvm/mmu.c         | 18 +++++++--
 2 files changed, 58 insertions(+), 38 deletions(-)

-- 
2.19.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 18+ messages in thread

* [PATCH v2 1/3] KVM: arm64: Decouple partial code of hyp stage 1 mapping and guest stage 2 mapping
  2020-12-16 12:28 ` Yanan Wang
@ 2020-12-16 12:28   ` Yanan Wang
  -1 siblings, 0 replies; 18+ messages in thread
From: Yanan Wang @ 2020-12-16 12:28 UTC (permalink / raw)
  To: linux-kernel, linux-arm-kernel, Marc Zyngier, Catalin Marinas,
	Will Deacon, James Morse, Julien Thierry, Suzuki K Poulose,
	Gavin Shan, Quentin Perret
  Cc: wanghaibin.wang, yezengruan, zhukeqian1, yuzenghui, Yanan Wang

Procedures of hyp stage 1 mapping and guest stage 2 mapping are different,
but they are tied closely by function kvm_set_valid_leaf_pte().
So separate them by rewriting kvm_set_valid_leaf_pte().

Signed-off-by: Will Deacon <will@kernel.org>
Signed-off-by: Yanan Wang <wangyanan55@huawei.com>
---
 arch/arm64/kvm/hyp/pgtable.c | 54 ++++++++++++++++++------------------
 1 file changed, 27 insertions(+), 27 deletions(-)

diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c
index bdf8e55ed308..350f9f810930 100644
--- a/arch/arm64/kvm/hyp/pgtable.c
+++ b/arch/arm64/kvm/hyp/pgtable.c
@@ -170,10 +170,9 @@ static void kvm_set_table_pte(kvm_pte_t *ptep, kvm_pte_t *childp)
 	smp_store_release(ptep, pte);
 }
 
-static bool kvm_set_valid_leaf_pte(kvm_pte_t *ptep, u64 pa, kvm_pte_t attr,
-				   u32 level)
+static kvm_pte_t kvm_init_valid_leaf_pte(u64 pa, kvm_pte_t attr, u32 level)
 {
-	kvm_pte_t old = *ptep, pte = kvm_phys_to_pte(pa);
+	kvm_pte_t pte = kvm_phys_to_pte(pa);
 	u64 type = (level == KVM_PGTABLE_MAX_LEVELS - 1) ? KVM_PTE_TYPE_PAGE :
 							   KVM_PTE_TYPE_BLOCK;
 
@@ -181,12 +180,7 @@ static bool kvm_set_valid_leaf_pte(kvm_pte_t *ptep, u64 pa, kvm_pte_t attr,
 	pte |= FIELD_PREP(KVM_PTE_TYPE, type);
 	pte |= KVM_PTE_VALID;
 
-	/* Tolerate KVM recreating the exact same mapping. */
-	if (kvm_pte_valid(old))
-		return old == pte;
-
-	smp_store_release(ptep, pte);
-	return true;
+	return pte;
 }
 
 static int kvm_pgtable_visitor_cb(struct kvm_pgtable_walk_data *data, u64 addr,
@@ -341,12 +335,17 @@ static int hyp_map_set_prot_attr(enum kvm_pgtable_prot prot,
 static bool hyp_map_walker_try_leaf(u64 addr, u64 end, u32 level,
 				    kvm_pte_t *ptep, struct hyp_map_data *data)
 {
+	kvm_pte_t new, old = *ptep;
 	u64 granule = kvm_granule_size(level), phys = data->phys;
 
 	if (!kvm_block_mapping_supported(addr, end, phys, level))
 		return false;
 
-	WARN_ON(!kvm_set_valid_leaf_pte(ptep, phys, data->attr, level));
+	/* Tolerate KVM recreating the exact same mapping */
+	new = kvm_init_valid_leaf_pte(phys, data->attr, level);
+	if (old != new && !WARN_ON(kvm_pte_valid(old)))
+		smp_store_release(ptep, new);
+
 	data->phys += granule;
 	return true;
 }
@@ -465,27 +464,29 @@ static bool stage2_map_walker_try_leaf(u64 addr, u64 end, u32 level,
 				       kvm_pte_t *ptep,
 				       struct stage2_map_data *data)
 {
+	kvm_pte_t new, old = *ptep;
 	u64 granule = kvm_granule_size(level), phys = data->phys;
+	struct page *page = virt_to_page(ptep);
 
 	if (!kvm_block_mapping_supported(addr, end, phys, level))
 		return false;
 
-	/*
-	 * If the PTE was already valid, drop the refcount on the table
-	 * early, as it will be bumped-up again in stage2_map_walk_leaf().
-	 * This ensures that the refcount stays constant across a valid to
-	 * valid PTE update.
-	 */
-	if (kvm_pte_valid(*ptep))
-		put_page(virt_to_page(ptep));
+	new = kvm_init_valid_leaf_pte(phys, data->attr, level);
+	if (kvm_pte_valid(old)) {
+		/* Tolerate KVM recreating the exact same mapping */
+		if (old == new)
+			goto out;
 
-	if (kvm_set_valid_leaf_pte(ptep, phys, data->attr, level))
-		goto out;
+		/* There's an existing different valid leaf entry, so perform
+		 * break-before-make.
+		 */
+		kvm_set_invalid_pte(ptep);
+		kvm_call_hyp(__kvm_tlb_flush_vmid_ipa, data->mmu, addr, level);
+		put_page(page);
+	}
 
-	/* There's an existing valid leaf entry, so perform break-before-make */
-	kvm_set_invalid_pte(ptep);
-	kvm_call_hyp(__kvm_tlb_flush_vmid_ipa, data->mmu, addr, level);
-	kvm_set_valid_leaf_pte(ptep, phys, data->attr, level);
+	smp_store_release(ptep, new);
+	get_page(page);
 out:
 	data->phys += granule;
 	return true;
@@ -527,7 +528,7 @@ static int stage2_map_walk_leaf(u64 addr, u64 end, u32 level, kvm_pte_t *ptep,
 	}
 
 	if (stage2_map_walker_try_leaf(addr, end, level, ptep, data))
-		goto out_get_page;
+		return 0;
 
 	if (WARN_ON(level == KVM_PGTABLE_MAX_LEVELS - 1))
 		return -EINVAL;
@@ -551,9 +552,8 @@ static int stage2_map_walk_leaf(u64 addr, u64 end, u32 level, kvm_pte_t *ptep,
 	}
 
 	kvm_set_table_pte(ptep, childp);
-
-out_get_page:
 	get_page(page);
+
 	return 0;
 }
 
-- 
2.19.1


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH v2 1/3] KVM: arm64: Decouple partial code of hyp stage 1 mapping and guest stage 2 mapping
@ 2020-12-16 12:28   ` Yanan Wang
  0 siblings, 0 replies; 18+ messages in thread
From: Yanan Wang @ 2020-12-16 12:28 UTC (permalink / raw)
  To: linux-kernel, linux-arm-kernel, Marc Zyngier, Catalin Marinas,
	Will Deacon, James Morse, Julien Thierry, Suzuki K Poulose,
	Gavin Shan, Quentin Perret
  Cc: yuzenghui, wanghaibin.wang, Yanan Wang, zhukeqian1, yezengruan

Procedures of hyp stage 1 mapping and guest stage 2 mapping are different,
but they are tied closely by function kvm_set_valid_leaf_pte().
So separate them by rewriting kvm_set_valid_leaf_pte().

Signed-off-by: Will Deacon <will@kernel.org>
Signed-off-by: Yanan Wang <wangyanan55@huawei.com>
---
 arch/arm64/kvm/hyp/pgtable.c | 54 ++++++++++++++++++------------------
 1 file changed, 27 insertions(+), 27 deletions(-)

diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c
index bdf8e55ed308..350f9f810930 100644
--- a/arch/arm64/kvm/hyp/pgtable.c
+++ b/arch/arm64/kvm/hyp/pgtable.c
@@ -170,10 +170,9 @@ static void kvm_set_table_pte(kvm_pte_t *ptep, kvm_pte_t *childp)
 	smp_store_release(ptep, pte);
 }
 
-static bool kvm_set_valid_leaf_pte(kvm_pte_t *ptep, u64 pa, kvm_pte_t attr,
-				   u32 level)
+static kvm_pte_t kvm_init_valid_leaf_pte(u64 pa, kvm_pte_t attr, u32 level)
 {
-	kvm_pte_t old = *ptep, pte = kvm_phys_to_pte(pa);
+	kvm_pte_t pte = kvm_phys_to_pte(pa);
 	u64 type = (level == KVM_PGTABLE_MAX_LEVELS - 1) ? KVM_PTE_TYPE_PAGE :
 							   KVM_PTE_TYPE_BLOCK;
 
@@ -181,12 +180,7 @@ static bool kvm_set_valid_leaf_pte(kvm_pte_t *ptep, u64 pa, kvm_pte_t attr,
 	pte |= FIELD_PREP(KVM_PTE_TYPE, type);
 	pte |= KVM_PTE_VALID;
 
-	/* Tolerate KVM recreating the exact same mapping. */
-	if (kvm_pte_valid(old))
-		return old == pte;
-
-	smp_store_release(ptep, pte);
-	return true;
+	return pte;
 }
 
 static int kvm_pgtable_visitor_cb(struct kvm_pgtable_walk_data *data, u64 addr,
@@ -341,12 +335,17 @@ static int hyp_map_set_prot_attr(enum kvm_pgtable_prot prot,
 static bool hyp_map_walker_try_leaf(u64 addr, u64 end, u32 level,
 				    kvm_pte_t *ptep, struct hyp_map_data *data)
 {
+	kvm_pte_t new, old = *ptep;
 	u64 granule = kvm_granule_size(level), phys = data->phys;
 
 	if (!kvm_block_mapping_supported(addr, end, phys, level))
 		return false;
 
-	WARN_ON(!kvm_set_valid_leaf_pte(ptep, phys, data->attr, level));
+	/* Tolerate KVM recreating the exact same mapping */
+	new = kvm_init_valid_leaf_pte(phys, data->attr, level);
+	if (old != new && !WARN_ON(kvm_pte_valid(old)))
+		smp_store_release(ptep, new);
+
 	data->phys += granule;
 	return true;
 }
@@ -465,27 +464,29 @@ static bool stage2_map_walker_try_leaf(u64 addr, u64 end, u32 level,
 				       kvm_pte_t *ptep,
 				       struct stage2_map_data *data)
 {
+	kvm_pte_t new, old = *ptep;
 	u64 granule = kvm_granule_size(level), phys = data->phys;
+	struct page *page = virt_to_page(ptep);
 
 	if (!kvm_block_mapping_supported(addr, end, phys, level))
 		return false;
 
-	/*
-	 * If the PTE was already valid, drop the refcount on the table
-	 * early, as it will be bumped-up again in stage2_map_walk_leaf().
-	 * This ensures that the refcount stays constant across a valid to
-	 * valid PTE update.
-	 */
-	if (kvm_pte_valid(*ptep))
-		put_page(virt_to_page(ptep));
+	new = kvm_init_valid_leaf_pte(phys, data->attr, level);
+	if (kvm_pte_valid(old)) {
+		/* Tolerate KVM recreating the exact same mapping */
+		if (old == new)
+			goto out;
 
-	if (kvm_set_valid_leaf_pte(ptep, phys, data->attr, level))
-		goto out;
+		/* There's an existing different valid leaf entry, so perform
+		 * break-before-make.
+		 */
+		kvm_set_invalid_pte(ptep);
+		kvm_call_hyp(__kvm_tlb_flush_vmid_ipa, data->mmu, addr, level);
+		put_page(page);
+	}
 
-	/* There's an existing valid leaf entry, so perform break-before-make */
-	kvm_set_invalid_pte(ptep);
-	kvm_call_hyp(__kvm_tlb_flush_vmid_ipa, data->mmu, addr, level);
-	kvm_set_valid_leaf_pte(ptep, phys, data->attr, level);
+	smp_store_release(ptep, new);
+	get_page(page);
 out:
 	data->phys += granule;
 	return true;
@@ -527,7 +528,7 @@ static int stage2_map_walk_leaf(u64 addr, u64 end, u32 level, kvm_pte_t *ptep,
 	}
 
 	if (stage2_map_walker_try_leaf(addr, end, level, ptep, data))
-		goto out_get_page;
+		return 0;
 
 	if (WARN_ON(level == KVM_PGTABLE_MAX_LEVELS - 1))
 		return -EINVAL;
@@ -551,9 +552,8 @@ static int stage2_map_walk_leaf(u64 addr, u64 end, u32 level, kvm_pte_t *ptep,
 	}
 
 	kvm_set_table_pte(ptep, childp);
-
-out_get_page:
 	get_page(page);
+
 	return 0;
 }
 
-- 
2.19.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH v2 2/3] KVM: arm64: Add prejudgement for relaxing permissions only case in stage2 translation fault handler
  2020-12-16 12:28 ` Yanan Wang
@ 2020-12-16 12:28   ` Yanan Wang
  -1 siblings, 0 replies; 18+ messages in thread
From: Yanan Wang @ 2020-12-16 12:28 UTC (permalink / raw)
  To: linux-kernel, linux-arm-kernel, Marc Zyngier, Catalin Marinas,
	Will Deacon, James Morse, Julien Thierry, Suzuki K Poulose,
	Gavin Shan, Quentin Perret
  Cc: wanghaibin.wang, yezengruan, zhukeqian1, yuzenghui, Yanan Wang

In dirty-logging, or dirty-logging-stopped time, even normal running
time of a guest configed with huge mappings and numbers of vCPUs,
translation faults by different vCPUs on the same GPA could occur
successively almost at the same time. There are two reasons for it.

(1) If there are some vCPUs accessing the same GPA at the same time and
the leaf PTE is not set yet, then they will all cause translation faults
and the first vCPU holding mmu_lock will set valid leaf PTE, and the
others will later update the old PTE with a new one if they are different.

(2) When changing a leaf entry or a table entry with break-before-make,
if there are some vCPUs accessing the same GPA just catch the moment when
the target PTE is set invalid in a BBM procedure coincidentally, they will
all cause translation faults and will later update the old PTE with a new
one if they are different.

The worst case can be like this: vCPU A causes a translation fault with RW
prot and sets the leaf PTE with RW permissions, and then the next vCPU B
with RO prot updates the PTE back to RO permissions with break-before-make.
And the BBM-invalid moment may trigger more unnecessary translation faults,
then some useless small loops might occur which could lead to vCPU stuck.

To avoid unnecessary update and small loops, add prejudgement in the
translation fault handler: Skip updating the PTE with break-before-make
if we are trying to recreate the exact same mapping or only change the
access permissions. Actually, change of permissions will be handled
through the relax_perms path next time if necessary.

Signed-off-by: Yanan Wang <wangyanan55@huawei.com>
---
 arch/arm64/kvm/hyp/pgtable.c | 28 +++++++++++++++++++---------
 1 file changed, 19 insertions(+), 9 deletions(-)

diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c
index 350f9f810930..8225ced49bad 100644
--- a/arch/arm64/kvm/hyp/pgtable.c
+++ b/arch/arm64/kvm/hyp/pgtable.c
@@ -45,6 +45,10 @@
 
 #define KVM_PTE_LEAF_ATTR_HI_S2_XN	BIT(54)
 
+#define KVM_PTE_LEAF_ATTR_S2_PERMS	(KVM_PTE_LEAF_ATTR_LO_S2_S2AP_R | \
+					 KVM_PTE_LEAF_ATTR_LO_S2_S2AP_W | \
+					 KVM_PTE_LEAF_ATTR_HI_S2_XN)
+
 struct kvm_pgtable_walk_data {
 	struct kvm_pgtable		*pgt;
 	struct kvm_pgtable_walker	*walker;
@@ -460,7 +464,7 @@ static int stage2_map_set_prot_attr(enum kvm_pgtable_prot prot,
 	return 0;
 }
 
-static bool stage2_map_walker_try_leaf(u64 addr, u64 end, u32 level,
+static int stage2_map_walker_try_leaf(u64 addr, u64 end, u32 level,
 				       kvm_pte_t *ptep,
 				       struct stage2_map_data *data)
 {
@@ -469,13 +473,18 @@ static bool stage2_map_walker_try_leaf(u64 addr, u64 end, u32 level,
 	struct page *page = virt_to_page(ptep);
 
 	if (!kvm_block_mapping_supported(addr, end, phys, level))
-		return false;
+		return 1;
 
 	new = kvm_init_valid_leaf_pte(phys, data->attr, level);
 	if (kvm_pte_valid(old)) {
-		/* Tolerate KVM recreating the exact same mapping */
-		if (old == new)
-			goto out;
+		/*
+		 * Skip updating the PTE with break-before-make if we are trying
+		 * to recreate the exact same mapping or only change the access
+		 * permissions. Actually, change of permissions will be handled
+		 * through the relax_perms path next time if necessary.
+		 */
+		if (!((old ^ new) & (~KVM_PTE_LEAF_ATTR_S2_PERMS)))
+			return -EAGAIN;
 
 		/* There's an existing different valid leaf entry, so perform
 		 * break-before-make.
@@ -487,9 +496,8 @@ static bool stage2_map_walker_try_leaf(u64 addr, u64 end, u32 level,
 
 	smp_store_release(ptep, new);
 	get_page(page);
-out:
 	data->phys += granule;
-	return true;
+	return 0;
 }
 
 static int stage2_map_walk_table_pre(u64 addr, u64 end, u32 level,
@@ -517,6 +525,7 @@ static int stage2_map_walk_table_pre(u64 addr, u64 end, u32 level,
 static int stage2_map_walk_leaf(u64 addr, u64 end, u32 level, kvm_pte_t *ptep,
 				struct stage2_map_data *data)
 {
+	int ret;
 	kvm_pte_t *childp, pte = *ptep;
 	struct page *page = virt_to_page(ptep);
 
@@ -527,8 +536,9 @@ static int stage2_map_walk_leaf(u64 addr, u64 end, u32 level, kvm_pte_t *ptep,
 		return 0;
 	}
 
-	if (stage2_map_walker_try_leaf(addr, end, level, ptep, data))
-		return 0;
+	ret = stage2_map_walker_try_leaf(addr, end, level, ptep, data);
+	if (ret <= 0)
+		return ret;
 
 	if (WARN_ON(level == KVM_PGTABLE_MAX_LEVELS - 1))
 		return -EINVAL;
-- 
2.19.1


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH v2 2/3] KVM: arm64: Add prejudgement for relaxing permissions only case in stage2 translation fault handler
@ 2020-12-16 12:28   ` Yanan Wang
  0 siblings, 0 replies; 18+ messages in thread
From: Yanan Wang @ 2020-12-16 12:28 UTC (permalink / raw)
  To: linux-kernel, linux-arm-kernel, Marc Zyngier, Catalin Marinas,
	Will Deacon, James Morse, Julien Thierry, Suzuki K Poulose,
	Gavin Shan, Quentin Perret
  Cc: yuzenghui, wanghaibin.wang, Yanan Wang, zhukeqian1, yezengruan

In dirty-logging, or dirty-logging-stopped time, even normal running
time of a guest configed with huge mappings and numbers of vCPUs,
translation faults by different vCPUs on the same GPA could occur
successively almost at the same time. There are two reasons for it.

(1) If there are some vCPUs accessing the same GPA at the same time and
the leaf PTE is not set yet, then they will all cause translation faults
and the first vCPU holding mmu_lock will set valid leaf PTE, and the
others will later update the old PTE with a new one if they are different.

(2) When changing a leaf entry or a table entry with break-before-make,
if there are some vCPUs accessing the same GPA just catch the moment when
the target PTE is set invalid in a BBM procedure coincidentally, they will
all cause translation faults and will later update the old PTE with a new
one if they are different.

The worst case can be like this: vCPU A causes a translation fault with RW
prot and sets the leaf PTE with RW permissions, and then the next vCPU B
with RO prot updates the PTE back to RO permissions with break-before-make.
And the BBM-invalid moment may trigger more unnecessary translation faults,
then some useless small loops might occur which could lead to vCPU stuck.

To avoid unnecessary update and small loops, add prejudgement in the
translation fault handler: Skip updating the PTE with break-before-make
if we are trying to recreate the exact same mapping or only change the
access permissions. Actually, change of permissions will be handled
through the relax_perms path next time if necessary.

Signed-off-by: Yanan Wang <wangyanan55@huawei.com>
---
 arch/arm64/kvm/hyp/pgtable.c | 28 +++++++++++++++++++---------
 1 file changed, 19 insertions(+), 9 deletions(-)

diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c
index 350f9f810930..8225ced49bad 100644
--- a/arch/arm64/kvm/hyp/pgtable.c
+++ b/arch/arm64/kvm/hyp/pgtable.c
@@ -45,6 +45,10 @@
 
 #define KVM_PTE_LEAF_ATTR_HI_S2_XN	BIT(54)
 
+#define KVM_PTE_LEAF_ATTR_S2_PERMS	(KVM_PTE_LEAF_ATTR_LO_S2_S2AP_R | \
+					 KVM_PTE_LEAF_ATTR_LO_S2_S2AP_W | \
+					 KVM_PTE_LEAF_ATTR_HI_S2_XN)
+
 struct kvm_pgtable_walk_data {
 	struct kvm_pgtable		*pgt;
 	struct kvm_pgtable_walker	*walker;
@@ -460,7 +464,7 @@ static int stage2_map_set_prot_attr(enum kvm_pgtable_prot prot,
 	return 0;
 }
 
-static bool stage2_map_walker_try_leaf(u64 addr, u64 end, u32 level,
+static int stage2_map_walker_try_leaf(u64 addr, u64 end, u32 level,
 				       kvm_pte_t *ptep,
 				       struct stage2_map_data *data)
 {
@@ -469,13 +473,18 @@ static bool stage2_map_walker_try_leaf(u64 addr, u64 end, u32 level,
 	struct page *page = virt_to_page(ptep);
 
 	if (!kvm_block_mapping_supported(addr, end, phys, level))
-		return false;
+		return 1;
 
 	new = kvm_init_valid_leaf_pte(phys, data->attr, level);
 	if (kvm_pte_valid(old)) {
-		/* Tolerate KVM recreating the exact same mapping */
-		if (old == new)
-			goto out;
+		/*
+		 * Skip updating the PTE with break-before-make if we are trying
+		 * to recreate the exact same mapping or only change the access
+		 * permissions. Actually, change of permissions will be handled
+		 * through the relax_perms path next time if necessary.
+		 */
+		if (!((old ^ new) & (~KVM_PTE_LEAF_ATTR_S2_PERMS)))
+			return -EAGAIN;
 
 		/* There's an existing different valid leaf entry, so perform
 		 * break-before-make.
@@ -487,9 +496,8 @@ static bool stage2_map_walker_try_leaf(u64 addr, u64 end, u32 level,
 
 	smp_store_release(ptep, new);
 	get_page(page);
-out:
 	data->phys += granule;
-	return true;
+	return 0;
 }
 
 static int stage2_map_walk_table_pre(u64 addr, u64 end, u32 level,
@@ -517,6 +525,7 @@ static int stage2_map_walk_table_pre(u64 addr, u64 end, u32 level,
 static int stage2_map_walk_leaf(u64 addr, u64 end, u32 level, kvm_pte_t *ptep,
 				struct stage2_map_data *data)
 {
+	int ret;
 	kvm_pte_t *childp, pte = *ptep;
 	struct page *page = virt_to_page(ptep);
 
@@ -527,8 +536,9 @@ static int stage2_map_walk_leaf(u64 addr, u64 end, u32 level, kvm_pte_t *ptep,
 		return 0;
 	}
 
-	if (stage2_map_walker_try_leaf(addr, end, level, ptep, data))
-		return 0;
+	ret = stage2_map_walker_try_leaf(addr, end, level, ptep, data);
+	if (ret <= 0)
+		return ret;
 
 	if (WARN_ON(level == KVM_PGTABLE_MAX_LEVELS - 1))
 		return -EINVAL;
-- 
2.19.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH v2 3/3] KVM: arm64: Mark the page dirty only if the fault is handled successfully
  2020-12-16 12:28 ` Yanan Wang
@ 2020-12-16 12:28   ` Yanan Wang
  -1 siblings, 0 replies; 18+ messages in thread
From: Yanan Wang @ 2020-12-16 12:28 UTC (permalink / raw)
  To: linux-kernel, linux-arm-kernel, Marc Zyngier, Catalin Marinas,
	Will Deacon, James Morse, Julien Thierry, Suzuki K Poulose,
	Gavin Shan, Quentin Perret
  Cc: wanghaibin.wang, yezengruan, zhukeqian1, yuzenghui, Yanan Wang

We now mark the page dirty and set the bitmap before calling fault handlers
in user_mem_abort(), and we might end up having spurious dirty pages if
update of permissions or mapping has failed.
So, mark the page dirty only if the fault is handled successfully.

Let the guest directly enter again but not return to userspace if we were
trying to recreate the same mapping or only change access permissions
with BBM, which is not permitted in the mapping path.

Signed-off-by: Yanan Wang <wangyanan55@huawei.com>
---
 arch/arm64/kvm/mmu.c | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c
index 75814a02d189..72e516a10914 100644
--- a/arch/arm64/kvm/mmu.c
+++ b/arch/arm64/kvm/mmu.c
@@ -879,11 +879,8 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,
 	if (vma_pagesize == PAGE_SIZE && !force_pte)
 		vma_pagesize = transparent_hugepage_adjust(memslot, hva,
 							   &pfn, &fault_ipa);
-	if (writable) {
+	if (writable)
 		prot |= KVM_PGTABLE_PROT_W;
-		kvm_set_pfn_dirty(pfn);
-		mark_page_dirty(kvm, gfn);
-	}
 
 	if (fault_status != FSC_PERM && !device)
 		clean_dcache_guest_page(pfn, vma_pagesize);
@@ -911,6 +908,19 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,
 					     memcache);
 	}
 
+	/* Mark the page dirty only if the fault is handled successfully */
+	if (writable && !ret) {
+		kvm_set_pfn_dirty(pfn);
+		mark_page_dirty(kvm, gfn);
+	}
+
+	/* Let the guest directly enter again if we were trying to recreate the
+	 * same mapping or only change access permissions with BBM, which is not
+	 * permitted in the mapping path.
+	 */
+	if (ret == -EAGAIN)
+		ret = 0;
+
 out_unlock:
 	spin_unlock(&kvm->mmu_lock);
 	kvm_set_pfn_accessed(pfn);
-- 
2.19.1


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH v2 3/3] KVM: arm64: Mark the page dirty only if the fault is handled successfully
@ 2020-12-16 12:28   ` Yanan Wang
  0 siblings, 0 replies; 18+ messages in thread
From: Yanan Wang @ 2020-12-16 12:28 UTC (permalink / raw)
  To: linux-kernel, linux-arm-kernel, Marc Zyngier, Catalin Marinas,
	Will Deacon, James Morse, Julien Thierry, Suzuki K Poulose,
	Gavin Shan, Quentin Perret
  Cc: yuzenghui, wanghaibin.wang, Yanan Wang, zhukeqian1, yezengruan

We now mark the page dirty and set the bitmap before calling fault handlers
in user_mem_abort(), and we might end up having spurious dirty pages if
update of permissions or mapping has failed.
So, mark the page dirty only if the fault is handled successfully.

Let the guest directly enter again but not return to userspace if we were
trying to recreate the same mapping or only change access permissions
with BBM, which is not permitted in the mapping path.

Signed-off-by: Yanan Wang <wangyanan55@huawei.com>
---
 arch/arm64/kvm/mmu.c | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c
index 75814a02d189..72e516a10914 100644
--- a/arch/arm64/kvm/mmu.c
+++ b/arch/arm64/kvm/mmu.c
@@ -879,11 +879,8 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,
 	if (vma_pagesize == PAGE_SIZE && !force_pte)
 		vma_pagesize = transparent_hugepage_adjust(memslot, hva,
 							   &pfn, &fault_ipa);
-	if (writable) {
+	if (writable)
 		prot |= KVM_PGTABLE_PROT_W;
-		kvm_set_pfn_dirty(pfn);
-		mark_page_dirty(kvm, gfn);
-	}
 
 	if (fault_status != FSC_PERM && !device)
 		clean_dcache_guest_page(pfn, vma_pagesize);
@@ -911,6 +908,19 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,
 					     memcache);
 	}
 
+	/* Mark the page dirty only if the fault is handled successfully */
+	if (writable && !ret) {
+		kvm_set_pfn_dirty(pfn);
+		mark_page_dirty(kvm, gfn);
+	}
+
+	/* Let the guest directly enter again if we were trying to recreate the
+	 * same mapping or only change access permissions with BBM, which is not
+	 * permitted in the mapping path.
+	 */
+	if (ret == -EAGAIN)
+		ret = 0;
+
 out_unlock:
 	spin_unlock(&kvm->mmu_lock);
 	kvm_set_pfn_accessed(pfn);
-- 
2.19.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* Re: [PATCH v2 0/3] RFC: Solve several problems in stage 2 translation
  2020-12-16 12:28 ` Yanan Wang
@ 2020-12-28  2:46   ` wangyanan (Y)
  -1 siblings, 0 replies; 18+ messages in thread
From: wangyanan (Y) @ 2020-12-28  2:46 UTC (permalink / raw)
  To: linux-kernel, linux-arm-kernel, Marc Zyngier, Catalin Marinas,
	Will Deacon, James Morse, Julien Thierry, Suzuki K Poulose,
	Gavin Shan, Quentin Perret
  Cc: wanghaibin.wang, yezengruan, zhukeqian1, yuzenghui

Hi Will, Marc,

Gently Ping.

Is there any comments about this V2 series?


Many thanks,

Yanan.

On 2020/12/16 20:28, Yanan Wang wrote:
> Hi, this is the second version, thanks for reading.
>
> PATCH1/3:
> Procedures of hyp stage 1 mapping and guest stage 2 mapping are different, but
> they are tied closely by function kvm_set_valid_leaf_pte(). So separate them by
> rewriting kvm_set_valid_leaf_pte().
>
> PATCH2/3:
> To avoid unnecessary update and small loops, add prejudgement in the translation
> fault handler: Skip updating the PTE with break-before-make if we are trying to
> recreate the exact same mapping or only change the access permissions. Actually,
> change of permissions will be handled through the relax_perms path next time if
> necessary.
>
> (1) If there are some vCPUs accessing the same GPA at the same time and the leaf
> PTE is not set yet, then they will all cause translation faults and the first vCPU
> holding mmu_lock will set valid leaf PTE, and the others will later update the old
> PTE with a new one if they are different.
>
> (2) When changing a leaf entry or a table entry with break-before-make, if there
> are some vCPUs accessing the same GPA just catch the moment when the target PTE
> is set invalid in a BBM procedure coincidentally, they will all cause translation
> faults and will later update the old PTE with a new one if they are different.
>
> The worst case can be like this: vCPU A causes a translation fault with RW prot and
> sets the leaf PTE with RW permissions, and then the next vCPU B with RO prot updates
> the PTE back to RO permissions with break-before-make. And the BBM-invalid moment
> may trigger more unnecessary translation faults, then some useless small loops might
> occur which could lead to vCPU stuck.
>
> PATCH3/3:
> We now mark the page dirty and set the bitmap before calling fault handlers in
> user_mem_abort(), and we might end up having spurious dirty pages if update of
> permissions or mapping has failed. So, mark the page dirty only if the fault is
> handled successfully.
>
> Let the guest directly enter again but not return to userspace if we were trying
> to recreate the same mapping or only change access permissions with BBM, which is
> not permitted in the mapping path.
>
> Changes from v1:
> - Make part of the diff as an independent patch (PATCH1/3),
>    and add Will's Signed-off-by.
> - Use *return -EPERM* way when changing permissions only in the mapping path.
> - Add a new patch (PATCH3/3).
>
> Yanan Wang (3):
>    KVM: arm64: Decouple partial code of hyp stage 1 mapping and guest
>      stage 2 mapping
>    KVM: arm64: Add prejudgement for relaxing permissions only case in
>      stage2 translation fault handler
>    KVM: arm64: Mark the page dirty only if the fault is handled
>      successfully
>
>   arch/arm64/kvm/hyp/pgtable.c | 78 ++++++++++++++++++++----------------
>   arch/arm64/kvm/mmu.c         | 18 +++++++--
>   2 files changed, 58 insertions(+), 38 deletions(-)
>

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v2 0/3] RFC: Solve several problems in stage 2 translation
@ 2020-12-28  2:46   ` wangyanan (Y)
  0 siblings, 0 replies; 18+ messages in thread
From: wangyanan (Y) @ 2020-12-28  2:46 UTC (permalink / raw)
  To: linux-kernel, linux-arm-kernel, Marc Zyngier, Catalin Marinas,
	Will Deacon, James Morse, Julien Thierry, Suzuki K Poulose,
	Gavin Shan, Quentin Perret
  Cc: yuzenghui, wanghaibin.wang, zhukeqian1, yezengruan

Hi Will, Marc,

Gently Ping.

Is there any comments about this V2 series?


Many thanks,

Yanan.

On 2020/12/16 20:28, Yanan Wang wrote:
> Hi, this is the second version, thanks for reading.
>
> PATCH1/3:
> Procedures of hyp stage 1 mapping and guest stage 2 mapping are different, but
> they are tied closely by function kvm_set_valid_leaf_pte(). So separate them by
> rewriting kvm_set_valid_leaf_pte().
>
> PATCH2/3:
> To avoid unnecessary update and small loops, add prejudgement in the translation
> fault handler: Skip updating the PTE with break-before-make if we are trying to
> recreate the exact same mapping or only change the access permissions. Actually,
> change of permissions will be handled through the relax_perms path next time if
> necessary.
>
> (1) If there are some vCPUs accessing the same GPA at the same time and the leaf
> PTE is not set yet, then they will all cause translation faults and the first vCPU
> holding mmu_lock will set valid leaf PTE, and the others will later update the old
> PTE with a new one if they are different.
>
> (2) When changing a leaf entry or a table entry with break-before-make, if there
> are some vCPUs accessing the same GPA just catch the moment when the target PTE
> is set invalid in a BBM procedure coincidentally, they will all cause translation
> faults and will later update the old PTE with a new one if they are different.
>
> The worst case can be like this: vCPU A causes a translation fault with RW prot and
> sets the leaf PTE with RW permissions, and then the next vCPU B with RO prot updates
> the PTE back to RO permissions with break-before-make. And the BBM-invalid moment
> may trigger more unnecessary translation faults, then some useless small loops might
> occur which could lead to vCPU stuck.
>
> PATCH3/3:
> We now mark the page dirty and set the bitmap before calling fault handlers in
> user_mem_abort(), and we might end up having spurious dirty pages if update of
> permissions or mapping has failed. So, mark the page dirty only if the fault is
> handled successfully.
>
> Let the guest directly enter again but not return to userspace if we were trying
> to recreate the same mapping or only change access permissions with BBM, which is
> not permitted in the mapping path.
>
> Changes from v1:
> - Make part of the diff as an independent patch (PATCH1/3),
>    and add Will's Signed-off-by.
> - Use *return -EPERM* way when changing permissions only in the mapping path.
> - Add a new patch (PATCH3/3).
>
> Yanan Wang (3):
>    KVM: arm64: Decouple partial code of hyp stage 1 mapping and guest
>      stage 2 mapping
>    KVM: arm64: Add prejudgement for relaxing permissions only case in
>      stage2 translation fault handler
>    KVM: arm64: Mark the page dirty only if the fault is handled
>      successfully
>
>   arch/arm64/kvm/hyp/pgtable.c | 78 ++++++++++++++++++++----------------
>   arch/arm64/kvm/mmu.c         | 18 +++++++--
>   2 files changed, 58 insertions(+), 38 deletions(-)
>

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v2 2/3] KVM: arm64: Add prejudgement for relaxing permissions only case in stage2 translation fault handler
  2020-12-16 12:28   ` Yanan Wang
@ 2021-01-13 15:44     ` Will Deacon
  -1 siblings, 0 replies; 18+ messages in thread
From: Will Deacon @ 2021-01-13 15:44 UTC (permalink / raw)
  To: Yanan Wang
  Cc: linux-kernel, linux-arm-kernel, Marc Zyngier, Catalin Marinas,
	James Morse, Julien Thierry, Suzuki K Poulose, Gavin Shan,
	Quentin Perret, wanghaibin.wang, yezengruan, zhukeqian1,
	yuzenghui

On Wed, Dec 16, 2020 at 08:28:43PM +0800, Yanan Wang wrote:
> In dirty-logging, or dirty-logging-stopped time, even normal running
> time of a guest configed with huge mappings and numbers of vCPUs,
> translation faults by different vCPUs on the same GPA could occur
> successively almost at the same time. There are two reasons for it.
> 
> (1) If there are some vCPUs accessing the same GPA at the same time and
> the leaf PTE is not set yet, then they will all cause translation faults
> and the first vCPU holding mmu_lock will set valid leaf PTE, and the
> others will later update the old PTE with a new one if they are different.
> 
> (2) When changing a leaf entry or a table entry with break-before-make,
> if there are some vCPUs accessing the same GPA just catch the moment when
> the target PTE is set invalid in a BBM procedure coincidentally, they will
> all cause translation faults and will later update the old PTE with a new
> one if they are different.
> 
> The worst case can be like this: vCPU A causes a translation fault with RW
> prot and sets the leaf PTE with RW permissions, and then the next vCPU B
> with RO prot updates the PTE back to RO permissions with break-before-make.
> And the BBM-invalid moment may trigger more unnecessary translation faults,
> then some useless small loops might occur which could lead to vCPU stuck.
> 
> To avoid unnecessary update and small loops, add prejudgement in the
> translation fault handler: Skip updating the PTE with break-before-make
> if we are trying to recreate the exact same mapping or only change the
> access permissions. Actually, change of permissions will be handled
> through the relax_perms path next time if necessary.
> 
> Signed-off-by: Yanan Wang <wangyanan55@huawei.com>
> ---
>  arch/arm64/kvm/hyp/pgtable.c | 28 +++++++++++++++++++---------
>  1 file changed, 19 insertions(+), 9 deletions(-)
> 
> diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c
> index 350f9f810930..8225ced49bad 100644
> --- a/arch/arm64/kvm/hyp/pgtable.c
> +++ b/arch/arm64/kvm/hyp/pgtable.c
> @@ -45,6 +45,10 @@
>  
>  #define KVM_PTE_LEAF_ATTR_HI_S2_XN	BIT(54)
>  
> +#define KVM_PTE_LEAF_ATTR_S2_PERMS	(KVM_PTE_LEAF_ATTR_LO_S2_S2AP_R | \
> +					 KVM_PTE_LEAF_ATTR_LO_S2_S2AP_W | \
> +					 KVM_PTE_LEAF_ATTR_HI_S2_XN)
> +
>  struct kvm_pgtable_walk_data {
>  	struct kvm_pgtable		*pgt;
>  	struct kvm_pgtable_walker	*walker;
> @@ -460,7 +464,7 @@ static int stage2_map_set_prot_attr(enum kvm_pgtable_prot prot,
>  	return 0;
>  }
>  
> -static bool stage2_map_walker_try_leaf(u64 addr, u64 end, u32 level,
> +static int stage2_map_walker_try_leaf(u64 addr, u64 end, u32 level,
>  				       kvm_pte_t *ptep,
>  				       struct stage2_map_data *data)
>  {
> @@ -469,13 +473,18 @@ static bool stage2_map_walker_try_leaf(u64 addr, u64 end, u32 level,
>  	struct page *page = virt_to_page(ptep);
>  
>  	if (!kvm_block_mapping_supported(addr, end, phys, level))
> -		return false;
> +		return 1;

It would probably be cleaner to return another error code here, as we
have failed to install a mapping (e.g. E2BIG or perhaps more perversely,
ENOTBLK). Then the caller can decide to install a trable.

Will

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v2 2/3] KVM: arm64: Add prejudgement for relaxing permissions only case in stage2 translation fault handler
@ 2021-01-13 15:44     ` Will Deacon
  0 siblings, 0 replies; 18+ messages in thread
From: Will Deacon @ 2021-01-13 15:44 UTC (permalink / raw)
  To: Yanan Wang
  Cc: Gavin Shan, Suzuki K Poulose, Marc Zyngier, Quentin Perret,
	linux-kernel, yezengruan, James Morse, linux-arm-kernel,
	Catalin Marinas, yuzenghui, wanghaibin.wang, zhukeqian1,
	Julien Thierry

On Wed, Dec 16, 2020 at 08:28:43PM +0800, Yanan Wang wrote:
> In dirty-logging, or dirty-logging-stopped time, even normal running
> time of a guest configed with huge mappings and numbers of vCPUs,
> translation faults by different vCPUs on the same GPA could occur
> successively almost at the same time. There are two reasons for it.
> 
> (1) If there are some vCPUs accessing the same GPA at the same time and
> the leaf PTE is not set yet, then they will all cause translation faults
> and the first vCPU holding mmu_lock will set valid leaf PTE, and the
> others will later update the old PTE with a new one if they are different.
> 
> (2) When changing a leaf entry or a table entry with break-before-make,
> if there are some vCPUs accessing the same GPA just catch the moment when
> the target PTE is set invalid in a BBM procedure coincidentally, they will
> all cause translation faults and will later update the old PTE with a new
> one if they are different.
> 
> The worst case can be like this: vCPU A causes a translation fault with RW
> prot and sets the leaf PTE with RW permissions, and then the next vCPU B
> with RO prot updates the PTE back to RO permissions with break-before-make.
> And the BBM-invalid moment may trigger more unnecessary translation faults,
> then some useless small loops might occur which could lead to vCPU stuck.
> 
> To avoid unnecessary update and small loops, add prejudgement in the
> translation fault handler: Skip updating the PTE with break-before-make
> if we are trying to recreate the exact same mapping or only change the
> access permissions. Actually, change of permissions will be handled
> through the relax_perms path next time if necessary.
> 
> Signed-off-by: Yanan Wang <wangyanan55@huawei.com>
> ---
>  arch/arm64/kvm/hyp/pgtable.c | 28 +++++++++++++++++++---------
>  1 file changed, 19 insertions(+), 9 deletions(-)
> 
> diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c
> index 350f9f810930..8225ced49bad 100644
> --- a/arch/arm64/kvm/hyp/pgtable.c
> +++ b/arch/arm64/kvm/hyp/pgtable.c
> @@ -45,6 +45,10 @@
>  
>  #define KVM_PTE_LEAF_ATTR_HI_S2_XN	BIT(54)
>  
> +#define KVM_PTE_LEAF_ATTR_S2_PERMS	(KVM_PTE_LEAF_ATTR_LO_S2_S2AP_R | \
> +					 KVM_PTE_LEAF_ATTR_LO_S2_S2AP_W | \
> +					 KVM_PTE_LEAF_ATTR_HI_S2_XN)
> +
>  struct kvm_pgtable_walk_data {
>  	struct kvm_pgtable		*pgt;
>  	struct kvm_pgtable_walker	*walker;
> @@ -460,7 +464,7 @@ static int stage2_map_set_prot_attr(enum kvm_pgtable_prot prot,
>  	return 0;
>  }
>  
> -static bool stage2_map_walker_try_leaf(u64 addr, u64 end, u32 level,
> +static int stage2_map_walker_try_leaf(u64 addr, u64 end, u32 level,
>  				       kvm_pte_t *ptep,
>  				       struct stage2_map_data *data)
>  {
> @@ -469,13 +473,18 @@ static bool stage2_map_walker_try_leaf(u64 addr, u64 end, u32 level,
>  	struct page *page = virt_to_page(ptep);
>  
>  	if (!kvm_block_mapping_supported(addr, end, phys, level))
> -		return false;
> +		return 1;

It would probably be cleaner to return another error code here, as we
have failed to install a mapping (e.g. E2BIG or perhaps more perversely,
ENOTBLK). Then the caller can decide to install a trable.

Will

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v2 3/3] KVM: arm64: Mark the page dirty only if the fault is handled successfully
  2020-12-16 12:28   ` Yanan Wang
@ 2021-01-13 15:51     ` Will Deacon
  -1 siblings, 0 replies; 18+ messages in thread
From: Will Deacon @ 2021-01-13 15:51 UTC (permalink / raw)
  To: Yanan Wang
  Cc: linux-kernel, linux-arm-kernel, Marc Zyngier, Catalin Marinas,
	James Morse, Julien Thierry, Suzuki K Poulose, Gavin Shan,
	Quentin Perret, wanghaibin.wang, yezengruan, zhukeqian1,
	yuzenghui

On Wed, Dec 16, 2020 at 08:28:44PM +0800, Yanan Wang wrote:
> We now mark the page dirty and set the bitmap before calling fault handlers
> in user_mem_abort(), and we might end up having spurious dirty pages if
> update of permissions or mapping has failed.
> So, mark the page dirty only if the fault is handled successfully.
> 
> Let the guest directly enter again but not return to userspace if we were
> trying to recreate the same mapping or only change access permissions
> with BBM, which is not permitted in the mapping path.
> 
> Signed-off-by: Yanan Wang <wangyanan55@huawei.com>
> ---
>  arch/arm64/kvm/mmu.c | 18 ++++++++++++++----
>  1 file changed, 14 insertions(+), 4 deletions(-)
> 
> diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c
> index 75814a02d189..72e516a10914 100644
> --- a/arch/arm64/kvm/mmu.c
> +++ b/arch/arm64/kvm/mmu.c
> @@ -879,11 +879,8 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,
>  	if (vma_pagesize == PAGE_SIZE && !force_pte)
>  		vma_pagesize = transparent_hugepage_adjust(memslot, hva,
>  							   &pfn, &fault_ipa);
> -	if (writable) {
> +	if (writable)
>  		prot |= KVM_PGTABLE_PROT_W;
> -		kvm_set_pfn_dirty(pfn);
> -		mark_page_dirty(kvm, gfn);
> -	}
>  
>  	if (fault_status != FSC_PERM && !device)
>  		clean_dcache_guest_page(pfn, vma_pagesize);
> @@ -911,6 +908,19 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,
>  					     memcache);
>  	}
>  
> +	/* Mark the page dirty only if the fault is handled successfully */
> +	if (writable && !ret) {
> +		kvm_set_pfn_dirty(pfn);
> +		mark_page_dirty(kvm, gfn);
> +	}
> +
> +	/* Let the guest directly enter again if we were trying to recreate the
> +	 * same mapping or only change access permissions with BBM, which is not
> +	 * permitted in the mapping path.
> +	 */
> +	if (ret == -EAGAIN)
> +		ret = 0;

Maybe just 'return ret != -EAGAIN ? ret : 0;' at the end of the function?

Will

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v2 3/3] KVM: arm64: Mark the page dirty only if the fault is handled successfully
@ 2021-01-13 15:51     ` Will Deacon
  0 siblings, 0 replies; 18+ messages in thread
From: Will Deacon @ 2021-01-13 15:51 UTC (permalink / raw)
  To: Yanan Wang
  Cc: Gavin Shan, Suzuki K Poulose, Marc Zyngier, Quentin Perret,
	linux-kernel, yezengruan, James Morse, linux-arm-kernel,
	Catalin Marinas, yuzenghui, wanghaibin.wang, zhukeqian1,
	Julien Thierry

On Wed, Dec 16, 2020 at 08:28:44PM +0800, Yanan Wang wrote:
> We now mark the page dirty and set the bitmap before calling fault handlers
> in user_mem_abort(), and we might end up having spurious dirty pages if
> update of permissions or mapping has failed.
> So, mark the page dirty only if the fault is handled successfully.
> 
> Let the guest directly enter again but not return to userspace if we were
> trying to recreate the same mapping or only change access permissions
> with BBM, which is not permitted in the mapping path.
> 
> Signed-off-by: Yanan Wang <wangyanan55@huawei.com>
> ---
>  arch/arm64/kvm/mmu.c | 18 ++++++++++++++----
>  1 file changed, 14 insertions(+), 4 deletions(-)
> 
> diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c
> index 75814a02d189..72e516a10914 100644
> --- a/arch/arm64/kvm/mmu.c
> +++ b/arch/arm64/kvm/mmu.c
> @@ -879,11 +879,8 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,
>  	if (vma_pagesize == PAGE_SIZE && !force_pte)
>  		vma_pagesize = transparent_hugepage_adjust(memslot, hva,
>  							   &pfn, &fault_ipa);
> -	if (writable) {
> +	if (writable)
>  		prot |= KVM_PGTABLE_PROT_W;
> -		kvm_set_pfn_dirty(pfn);
> -		mark_page_dirty(kvm, gfn);
> -	}
>  
>  	if (fault_status != FSC_PERM && !device)
>  		clean_dcache_guest_page(pfn, vma_pagesize);
> @@ -911,6 +908,19 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,
>  					     memcache);
>  	}
>  
> +	/* Mark the page dirty only if the fault is handled successfully */
> +	if (writable && !ret) {
> +		kvm_set_pfn_dirty(pfn);
> +		mark_page_dirty(kvm, gfn);
> +	}
> +
> +	/* Let the guest directly enter again if we were trying to recreate the
> +	 * same mapping or only change access permissions with BBM, which is not
> +	 * permitted in the mapping path.
> +	 */
> +	if (ret == -EAGAIN)
> +		ret = 0;

Maybe just 'return ret != -EAGAIN ? ret : 0;' at the end of the function?

Will

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v2 3/3] KVM: arm64: Mark the page dirty only if the fault is handled successfully
  2021-01-13 15:51     ` Will Deacon
@ 2021-01-14  9:28       ` wangyanan (Y)
  -1 siblings, 0 replies; 18+ messages in thread
From: wangyanan (Y) @ 2021-01-14  9:28 UTC (permalink / raw)
  To: Will Deacon
  Cc: linux-kernel, linux-arm-kernel, Marc Zyngier, Catalin Marinas,
	James Morse, Julien Thierry, Suzuki K Poulose, Gavin Shan,
	Quentin Perret, wanghaibin.wang, yezengruan, zhukeqian1,
	yuzenghui


On 2021/1/13 23:51, Will Deacon wrote:
> On Wed, Dec 16, 2020 at 08:28:44PM +0800, Yanan Wang wrote:
>> We now mark the page dirty and set the bitmap before calling fault handlers
>> in user_mem_abort(), and we might end up having spurious dirty pages if
>> update of permissions or mapping has failed.
>> So, mark the page dirty only if the fault is handled successfully.
>>
>> Let the guest directly enter again but not return to userspace if we were
>> trying to recreate the same mapping or only change access permissions
>> with BBM, which is not permitted in the mapping path.
>>
>> Signed-off-by: Yanan Wang <wangyanan55@huawei.com>
>> ---
>>   arch/arm64/kvm/mmu.c | 18 ++++++++++++++----
>>   1 file changed, 14 insertions(+), 4 deletions(-)
>>
>> diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c
>> index 75814a02d189..72e516a10914 100644
>> --- a/arch/arm64/kvm/mmu.c
>> +++ b/arch/arm64/kvm/mmu.c
>> @@ -879,11 +879,8 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,
>>   	if (vma_pagesize == PAGE_SIZE && !force_pte)
>>   		vma_pagesize = transparent_hugepage_adjust(memslot, hva,
>>   							   &pfn, &fault_ipa);
>> -	if (writable) {
>> +	if (writable)
>>   		prot |= KVM_PGTABLE_PROT_W;
>> -		kvm_set_pfn_dirty(pfn);
>> -		mark_page_dirty(kvm, gfn);
>> -	}
>>   
>>   	if (fault_status != FSC_PERM && !device)
>>   		clean_dcache_guest_page(pfn, vma_pagesize);
>> @@ -911,6 +908,19 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,
>>   					     memcache);
>>   	}
>>   
>> +	/* Mark the page dirty only if the fault is handled successfully */
>> +	if (writable && !ret) {
>> +		kvm_set_pfn_dirty(pfn);
>> +		mark_page_dirty(kvm, gfn);
>> +	}
>> +
>> +	/* Let the guest directly enter again if we were trying to recreate the
>> +	 * same mapping or only change access permissions with BBM, which is not
>> +	 * permitted in the mapping path.
>> +	 */
>> +	if (ret == -EAGAIN)
>> +		ret = 0;
> Maybe just 'return ret != -EAGAIN ? ret : 0;' at the end of the function?
Yes, it's more concise.

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v2 3/3] KVM: arm64: Mark the page dirty only if the fault is handled successfully
@ 2021-01-14  9:28       ` wangyanan (Y)
  0 siblings, 0 replies; 18+ messages in thread
From: wangyanan (Y) @ 2021-01-14  9:28 UTC (permalink / raw)
  To: Will Deacon
  Cc: Gavin Shan, Suzuki K Poulose, Marc Zyngier, Quentin Perret,
	linux-kernel, yezengruan, James Morse, linux-arm-kernel,
	Catalin Marinas, yuzenghui, wanghaibin.wang, zhukeqian1,
	Julien Thierry


On 2021/1/13 23:51, Will Deacon wrote:
> On Wed, Dec 16, 2020 at 08:28:44PM +0800, Yanan Wang wrote:
>> We now mark the page dirty and set the bitmap before calling fault handlers
>> in user_mem_abort(), and we might end up having spurious dirty pages if
>> update of permissions or mapping has failed.
>> So, mark the page dirty only if the fault is handled successfully.
>>
>> Let the guest directly enter again but not return to userspace if we were
>> trying to recreate the same mapping or only change access permissions
>> with BBM, which is not permitted in the mapping path.
>>
>> Signed-off-by: Yanan Wang <wangyanan55@huawei.com>
>> ---
>>   arch/arm64/kvm/mmu.c | 18 ++++++++++++++----
>>   1 file changed, 14 insertions(+), 4 deletions(-)
>>
>> diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c
>> index 75814a02d189..72e516a10914 100644
>> --- a/arch/arm64/kvm/mmu.c
>> +++ b/arch/arm64/kvm/mmu.c
>> @@ -879,11 +879,8 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,
>>   	if (vma_pagesize == PAGE_SIZE && !force_pte)
>>   		vma_pagesize = transparent_hugepage_adjust(memslot, hva,
>>   							   &pfn, &fault_ipa);
>> -	if (writable) {
>> +	if (writable)
>>   		prot |= KVM_PGTABLE_PROT_W;
>> -		kvm_set_pfn_dirty(pfn);
>> -		mark_page_dirty(kvm, gfn);
>> -	}
>>   
>>   	if (fault_status != FSC_PERM && !device)
>>   		clean_dcache_guest_page(pfn, vma_pagesize);
>> @@ -911,6 +908,19 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,
>>   					     memcache);
>>   	}
>>   
>> +	/* Mark the page dirty only if the fault is handled successfully */
>> +	if (writable && !ret) {
>> +		kvm_set_pfn_dirty(pfn);
>> +		mark_page_dirty(kvm, gfn);
>> +	}
>> +
>> +	/* Let the guest directly enter again if we were trying to recreate the
>> +	 * same mapping or only change access permissions with BBM, which is not
>> +	 * permitted in the mapping path.
>> +	 */
>> +	if (ret == -EAGAIN)
>> +		ret = 0;
> Maybe just 'return ret != -EAGAIN ? ret : 0;' at the end of the function?
Yes, it's more concise.

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v2 2/3] KVM: arm64: Add prejudgement for relaxing permissions only case in stage2 translation fault handler
  2021-01-13 15:44     ` Will Deacon
@ 2021-01-14  9:28       ` wangyanan (Y)
  -1 siblings, 0 replies; 18+ messages in thread
From: wangyanan (Y) @ 2021-01-14  9:28 UTC (permalink / raw)
  To: Will Deacon
  Cc: linux-kernel, linux-arm-kernel, Marc Zyngier, Catalin Marinas,
	James Morse, Julien Thierry, Suzuki K Poulose, Gavin Shan,
	Quentin Perret, wanghaibin.wang, yezengruan, zhukeqian1,
	yuzenghui


On 2021/1/13 23:44, Will Deacon wrote:
> On Wed, Dec 16, 2020 at 08:28:43PM +0800, Yanan Wang wrote:
>> In dirty-logging, or dirty-logging-stopped time, even normal running
>> time of a guest configed with huge mappings and numbers of vCPUs,
>> translation faults by different vCPUs on the same GPA could occur
>> successively almost at the same time. There are two reasons for it.
>>
>> (1) If there are some vCPUs accessing the same GPA at the same time and
>> the leaf PTE is not set yet, then they will all cause translation faults
>> and the first vCPU holding mmu_lock will set valid leaf PTE, and the
>> others will later update the old PTE with a new one if they are different.
>>
>> (2) When changing a leaf entry or a table entry with break-before-make,
>> if there are some vCPUs accessing the same GPA just catch the moment when
>> the target PTE is set invalid in a BBM procedure coincidentally, they will
>> all cause translation faults and will later update the old PTE with a new
>> one if they are different.
>>
>> The worst case can be like this: vCPU A causes a translation fault with RW
>> prot and sets the leaf PTE with RW permissions, and then the next vCPU B
>> with RO prot updates the PTE back to RO permissions with break-before-make.
>> And the BBM-invalid moment may trigger more unnecessary translation faults,
>> then some useless small loops might occur which could lead to vCPU stuck.
>>
>> To avoid unnecessary update and small loops, add prejudgement in the
>> translation fault handler: Skip updating the PTE with break-before-make
>> if we are trying to recreate the exact same mapping or only change the
>> access permissions. Actually, change of permissions will be handled
>> through the relax_perms path next time if necessary.
>>
>> Signed-off-by: Yanan Wang <wangyanan55@huawei.com>
>> ---
>>   arch/arm64/kvm/hyp/pgtable.c | 28 +++++++++++++++++++---------
>>   1 file changed, 19 insertions(+), 9 deletions(-)
>>
>> diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c
>> index 350f9f810930..8225ced49bad 100644
>> --- a/arch/arm64/kvm/hyp/pgtable.c
>> +++ b/arch/arm64/kvm/hyp/pgtable.c
>> @@ -45,6 +45,10 @@
>>   
>>   #define KVM_PTE_LEAF_ATTR_HI_S2_XN	BIT(54)
>>   
>> +#define KVM_PTE_LEAF_ATTR_S2_PERMS	(KVM_PTE_LEAF_ATTR_LO_S2_S2AP_R | \
>> +					 KVM_PTE_LEAF_ATTR_LO_S2_S2AP_W | \
>> +					 KVM_PTE_LEAF_ATTR_HI_S2_XN)
>> +
>>   struct kvm_pgtable_walk_data {
>>   	struct kvm_pgtable		*pgt;
>>   	struct kvm_pgtable_walker	*walker;
>> @@ -460,7 +464,7 @@ static int stage2_map_set_prot_attr(enum kvm_pgtable_prot prot,
>>   	return 0;
>>   }
>>   
>> -static bool stage2_map_walker_try_leaf(u64 addr, u64 end, u32 level,
>> +static int stage2_map_walker_try_leaf(u64 addr, u64 end, u32 level,
>>   				       kvm_pte_t *ptep,
>>   				       struct stage2_map_data *data)
>>   {
>> @@ -469,13 +473,18 @@ static bool stage2_map_walker_try_leaf(u64 addr, u64 end, u32 level,
>>   	struct page *page = virt_to_page(ptep);
>>   
>>   	if (!kvm_block_mapping_supported(addr, end, phys, level))
>> -		return false;
>> +		return 1;
> It would probably be cleaner to return another error code here, as we
> have failed to install a mapping (e.g. E2BIG or perhaps more perversely,
> ENOTBLK). Then the caller can decide to install a trable.
>
Ok, I will make some adjustment for this and post the v3 soon after.

Thanks,

Yanan.


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v2 2/3] KVM: arm64: Add prejudgement for relaxing permissions only case in stage2 translation fault handler
@ 2021-01-14  9:28       ` wangyanan (Y)
  0 siblings, 0 replies; 18+ messages in thread
From: wangyanan (Y) @ 2021-01-14  9:28 UTC (permalink / raw)
  To: Will Deacon
  Cc: Gavin Shan, Suzuki K Poulose, Marc Zyngier, Quentin Perret,
	linux-kernel, yezengruan, James Morse, linux-arm-kernel,
	Catalin Marinas, yuzenghui, wanghaibin.wang, zhukeqian1,
	Julien Thierry


On 2021/1/13 23:44, Will Deacon wrote:
> On Wed, Dec 16, 2020 at 08:28:43PM +0800, Yanan Wang wrote:
>> In dirty-logging, or dirty-logging-stopped time, even normal running
>> time of a guest configed with huge mappings and numbers of vCPUs,
>> translation faults by different vCPUs on the same GPA could occur
>> successively almost at the same time. There are two reasons for it.
>>
>> (1) If there are some vCPUs accessing the same GPA at the same time and
>> the leaf PTE is not set yet, then they will all cause translation faults
>> and the first vCPU holding mmu_lock will set valid leaf PTE, and the
>> others will later update the old PTE with a new one if they are different.
>>
>> (2) When changing a leaf entry or a table entry with break-before-make,
>> if there are some vCPUs accessing the same GPA just catch the moment when
>> the target PTE is set invalid in a BBM procedure coincidentally, they will
>> all cause translation faults and will later update the old PTE with a new
>> one if they are different.
>>
>> The worst case can be like this: vCPU A causes a translation fault with RW
>> prot and sets the leaf PTE with RW permissions, and then the next vCPU B
>> with RO prot updates the PTE back to RO permissions with break-before-make.
>> And the BBM-invalid moment may trigger more unnecessary translation faults,
>> then some useless small loops might occur which could lead to vCPU stuck.
>>
>> To avoid unnecessary update and small loops, add prejudgement in the
>> translation fault handler: Skip updating the PTE with break-before-make
>> if we are trying to recreate the exact same mapping or only change the
>> access permissions. Actually, change of permissions will be handled
>> through the relax_perms path next time if necessary.
>>
>> Signed-off-by: Yanan Wang <wangyanan55@huawei.com>
>> ---
>>   arch/arm64/kvm/hyp/pgtable.c | 28 +++++++++++++++++++---------
>>   1 file changed, 19 insertions(+), 9 deletions(-)
>>
>> diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c
>> index 350f9f810930..8225ced49bad 100644
>> --- a/arch/arm64/kvm/hyp/pgtable.c
>> +++ b/arch/arm64/kvm/hyp/pgtable.c
>> @@ -45,6 +45,10 @@
>>   
>>   #define KVM_PTE_LEAF_ATTR_HI_S2_XN	BIT(54)
>>   
>> +#define KVM_PTE_LEAF_ATTR_S2_PERMS	(KVM_PTE_LEAF_ATTR_LO_S2_S2AP_R | \
>> +					 KVM_PTE_LEAF_ATTR_LO_S2_S2AP_W | \
>> +					 KVM_PTE_LEAF_ATTR_HI_S2_XN)
>> +
>>   struct kvm_pgtable_walk_data {
>>   	struct kvm_pgtable		*pgt;
>>   	struct kvm_pgtable_walker	*walker;
>> @@ -460,7 +464,7 @@ static int stage2_map_set_prot_attr(enum kvm_pgtable_prot prot,
>>   	return 0;
>>   }
>>   
>> -static bool stage2_map_walker_try_leaf(u64 addr, u64 end, u32 level,
>> +static int stage2_map_walker_try_leaf(u64 addr, u64 end, u32 level,
>>   				       kvm_pte_t *ptep,
>>   				       struct stage2_map_data *data)
>>   {
>> @@ -469,13 +473,18 @@ static bool stage2_map_walker_try_leaf(u64 addr, u64 end, u32 level,
>>   	struct page *page = virt_to_page(ptep);
>>   
>>   	if (!kvm_block_mapping_supported(addr, end, phys, level))
>> -		return false;
>> +		return 1;
> It would probably be cleaner to return another error code here, as we
> have failed to install a mapping (e.g. E2BIG or perhaps more perversely,
> ENOTBLK). Then the caller can decide to install a trable.
>
Ok, I will make some adjustment for this and post the v3 soon after.

Thanks,

Yanan.


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2021-01-14  9:30 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-16 12:28 [PATCH v2 0/3] RFC: Solve several problems in stage 2 translation Yanan Wang
2020-12-16 12:28 ` Yanan Wang
2020-12-16 12:28 ` [PATCH v2 1/3] KVM: arm64: Decouple partial code of hyp stage 1 mapping and guest stage 2 mapping Yanan Wang
2020-12-16 12:28   ` Yanan Wang
2020-12-16 12:28 ` [PATCH v2 2/3] KVM: arm64: Add prejudgement for relaxing permissions only case in stage2 translation fault handler Yanan Wang
2020-12-16 12:28   ` Yanan Wang
2021-01-13 15:44   ` Will Deacon
2021-01-13 15:44     ` Will Deacon
2021-01-14  9:28     ` wangyanan (Y)
2021-01-14  9:28       ` wangyanan (Y)
2020-12-16 12:28 ` [PATCH v2 3/3] KVM: arm64: Mark the page dirty only if the fault is handled successfully Yanan Wang
2020-12-16 12:28   ` Yanan Wang
2021-01-13 15:51   ` Will Deacon
2021-01-13 15:51     ` Will Deacon
2021-01-14  9:28     ` wangyanan (Y)
2021-01-14  9:28       ` wangyanan (Y)
2020-12-28  2:46 ` [PATCH v2 0/3] RFC: Solve several problems in stage 2 translation wangyanan (Y)
2020-12-28  2:46   ` wangyanan (Y)

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.