KVM: arm64: Fix unaligned addr case in mmu walking
PATCH 1/1 KVM: arm64: Fix unaligned addr case in mmu walking
If the start addr is not aligned with the granule size of that level. loop step size should be adjusted to boundary instead of simple kvm_granual_size(level) increment. Otherwise, some mmu entries might miss the chance to be walked through.
E.g. Assume the unmap range [data->addr, data->end] is [0xff00ab2000,0xff00cb2000] in level 2 walking and NOT block mapping. And the 1st part of that pmd entry is [0xff00ab2000,0xff00c00000]. The pmd value is 0x83fbd2c1002 (not valid entry). In this case, data->addr should be adjusted to 0xff00c00000 instead of 0xff00cb2000.
Without this fix, userspace "segment fault" error can be easily triggered by running simple gVisor runsc cases on an Ampere Altra server:
docker run --runtime=runsc -it --rm ubuntu /bin/bash
In container:
for i in `seq 1 100`;do ls;done
--- arch/arm64/kvm/hyp/pgtable.c | 1 + 1 file changed, 1 insertion(+)
arch/arm64/kvm/hyp/pgtable.c +1 -0
@@ -225,6 +225,7 @@ static inline int __kvm_pgtable_visit(struct kvm_pgtable_walk_data *data, goto out;if (!table) { + data->addr =ALIGN_DOWN (data->addr,kvm_granule_size (level)); data->addr +=kvm_granule_size (level); goto out; }
Signature · 6 lines
2.17.1 _______________________________________________ kvmarm mailing list [email protected] https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Marc Zyngier
maintainerHi Jia,
Quoted 7 lines · Jia He
If the start addr is not aligned with the granule size of that level. loop step size should be adjusted to boundary instead of simple
kvm_granual_size(level)increment. Otherwise, some mmu entries might miss the chance to be walked through.
E.g. Assume the unmap range [data->addr,data->end] is [0xff00ab2000,0xff00cb2000] in level 2 walking and NOT block mapping.
When does this occur? Upgrade from page mappings to block? Swap out?
Quoted 3 lines
And the 1st part of that pmd entry is [0xff00ab2000,0xff00c00000]. The pmd value is
0x83fbd2c1002(not valid entry). In this case,data->addrshould be adjusted to0xff00c00000instead of0xff00cb2000.
Let me see if I understand this. Assuming 4k pages, the region described above spans *two* 2M entries:
(a) ff00ab2000-ff00c00000, part of ff00a00000-ff00c00000
(b) ff00c00000-ff00db2000, part of ff00c00000-ff00e00000
(a) has no valid mapping, but (b) does. Because we fail to correctly align on a block boundary when skipping (a), we also skip (b), which is then left mapped.
Did I get it right? If so, yes, this is... annoying.
Understanding the circumstances this triggers in would be most interesting. This current code seems to assume that we get ranges aligned to mapping boundaries, but I seem to remember that the old code did use the stage2_*_addr_end() helpers to deal with this case.
Will: I don't think things have changed in that respect, right?
Quoted 8 lines
Without this fix, userspace "segment fault" error can be easily triggered by running simple gVisor runsc cases on an Ampere Altra server:
docker run --runtime=runsc -it --rm ubuntu /bin/bashIn container:
for i in `seq 1 100`;do ls;done
The workload on its own isn't that interesting. What I'd like to understand is what happens on the host during that time.
Quoted 12 lines
Reported-by Howard Zhang <[email protected]>Signed-off-by Jia He <[email protected]>--- arch/arm64/kvm/hyp/pgtable.c | 1 + 1 file changed, 1 insertion(+)arch/arm64/kvm/hyp/pgtable.c +0
-0
arch/arm64/kvm/hyp/pgtable.c static inline int __kvm_pgtable_visit(struct kvm_pgtable_walk_data *data, · line 231
Quoted 7 lines
arch/arm64/kvm/hyp/pgtable.c +1
-0@@ -225,6 +225,7 @@ static inline int __kvm_pgtable_visit(struct kvm_pgtable_walk_data *data, goto out;if (!table) { + data->addr =ALIGN_DOWN (data->addr,kvm_granule_size (level)); data->addr +=kvm_granule_size (level); goto out; }
It otherwise looks good to me. Quentin, Will: unless you object to this, I plan to take it in the next round of fixes with
Thanks,
M.
Signature · 5 lines
Without deviation from the norm, progress is not possible. _______________________________________________ kvmarm mailing list [email protected] https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Quoted 28 lines · Marc Zyngier
Hi Jia,
Quoted 7 lines · Jia He
If the start addr is not aligned with the granule size of that level. loop step size should be adjusted to boundary instead of simple
kvm_granual_size(level)increment. Otherwise, some mmu entries might miss the chance to be walked through.
E.g. Assume the unmap range [data->addr,data->end] is [0xff00ab2000,0xff00cb2000] in level 2 walking and NOT block mapping.When does this occur? Upgrade from page mappings to block? Swap out?
Quoted 3 lines
And the 1st part of that pmd entry is [0xff00ab2000,0xff00c00000]. The pmd value is
0x83fbd2c1002(not valid entry). In this case,data->addrshould be adjusted to0xff00c00000instead of0xff00cb2000.Let me see if I understand this. Assuming 4k pages, the region described above spans *two* 2M entries:
(a) ff00ab2000-ff00c00000, part of ff00a00000-ff00c00000
(b) ff00c00000-ff00db2000, part of ff00c00000-ff00e00000(a) has no valid mapping, but (b) does. Because we fail to correctly align on a block boundary when skipping (a), we also skip (b), which is then left mapped.
Quoted 8 lines
Did I get it right? If so, yes, this is... annoying.
Understanding the circumstances this triggers in would be most interesting. This current code seems to assume that we get ranges aligned to mapping boundaries, but I seem to remember that the old code did use the stage2_*_addr_end() helpers to deal with this case.
Will: I don't think things have changed in that respect, right?
Indeed we should still use stage2_*_addr_end(), especially in the unmap path that is mentioned here, so it would be helpful to have a little bit more context.
Quoted 25 lines
Quoted 7 lines
Without this fix, userspace "segment fault" error can be easily triggered by running simple gVisor runsc cases on an Ampere Altra server:
docker run --runtime=runsc -it --rm ubuntu /bin/bashIn container:
for i in `seq 1 100`;do ls;doneThe workload on its own isn't that interesting. What I'd like to understand is what happens on the host during that time.
Quoted 14 lines
Reported-by Howard Zhang <[email protected]>Signed-off-by Jia He <[email protected]>--- arch/arm64/kvm/hyp/pgtable.c | 1 + 1 file changed, 1 insertion(+)arch/arm64/kvm/hyp/pgtable.c +0
-0@@ -225,6 +225,7 @@ static inline int __kvm_pgtable_visit(struct kvm_pgtable_walk_data *data, goto out;
Quoted 8 lines
arch/arm64/kvm/hyp/pgtable.c static inline int __kvm_pgtable_visit(struct kvm_pgtable_walk_data *data, · line 231
Quoted 5 lines
arch/arm64/kvm/hyp/pgtable.c +1
-0if (!table) { + data->addr =ALIGN_DOWN (data->addr,kvm_granule_size (level)); data->addr +=kvm_granule_size (level); goto out; }It otherwise looks good to me. Quentin, Will: unless you object to this, I plan to take it in the next round of fixes with
Though I'm still unsure how we hit that today, the change makes sense on its own I think, so no objection from me.
Thanks,
Quentin
_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Hi Quentin and Marc
I noticed Marc had sent out new version on behalf of me, thanks for the help. I hated the time difference, sorry for the late.
Just answer the comments below to make it clear.
Quoted 15 lines
-----Original Message-----
From: Quentin Perret <[email protected]>
Sent: Wednesday, March 3, 2021 7:09 PM
To: Marc Zyngier <[email protected]>
Cc: Justin He <[email protected]>; [email protected]; James Morse <[email protected]>; Julien Thierry <[email protected]>; Suzuki Poulose <[email protected]>; Catalin Marinas <[email protected]>; Will Deacon <[email protected]>; Gavin Shan <[email protected]>; Yanan Wang <[email protected]>; linux-arm- [email protected]; [email protected]
Subject: Re: [PATCH] KVM: arm64: Fix unaligned addr case in mmu walkingQuoted 2 lines · Marc Zyngier
Hi Jia,
Quoted 29 lines
Quoted 6 lines
Quoted 4 lines · Jia He
If the start addr is not aligned with the granule size of that level. loop step size should be adjusted to boundary instead of simple
kvm_granual_size(level)increment. Otherwise, some mmu entries mightmiss
Quoted 22 lines
Quoted 3 lines
the chance to be walked through.
E.g. Assume the unmap range [data->addr,data->end] is [0xff00ab2000,0xff00cb2000] in level 2 walking and NOT block mapping.When does this occur? Upgrade from page mappings to block? Swap out?
Quoted 3 lines
And the 1st part of that pmd entry is [0xff00ab2000,0xff00c00000]. The pmd value is
0x83fbd2c1002(not valid entry). In this case,data->addrshould be adjusted to0xff00c00000instead of0xff00cb2000.Let me see if I understand this. Assuming 4k pages, the region described above spans *two* 2M entries:
(a) ff00ab2000-ff00c00000, part of ff00a00000-ff00c00000
(b) ff00c00000-ff00db2000, part of ff00c00000-ff00e00000(a) has no valid mapping, but (b) does. Because we fail to correctly align on a block boundary when skipping (a), we also skip (b), which is then left mapped.
Did I get it right? If so, yes, this is... annoying.
Yes, exactly the case
Quoted 10 lines
Quoted 6 lines
Understanding the circumstances this triggers in would be most interesting. This current code seems to assume that we get ranges aligned to mapping boundaries, but I seem to remember that the old code did use the stage2_*_addr_end() helpers to deal with this case.
Will: I don't think things have changed in that respect, right?
Indeed we should still use stage2_*_addr_end(), especially in the unmap path that is mentioned here, so it would be helpful to have a little bit more context.
Yes, stage2_pgd_addr_end() was still there but the stage2_pmd_addr_end() was removed.
Quoted 11 lines
Quoted 11 lines
Quoted 8 lines
Without this fix, userspace "segment fault" error can be easily triggered by running simple gVisor runsc cases on an Ampere Altra server:
docker run --runtime=runsc -it --rm ubuntu /bin/bashIn container:
for i in `seq 1 100`;do ls;doneThe workload on its own isn't that interesting. What I'd like to understand is what happens on the host during that time.
Okay
Quoted 26 lines
Quoted 9 lines
Review
Quoted 9 lines
Reported-by Howard Zhang <[email protected]>Signed-off-by Jia He <[email protected]>--- arch/arm64/kvm/hyp/pgtable.c | 1 + 1 file changed, 1 insertion(+)(quoted diff) +0
-0
b/arch/arm64/kvm/hyp/pgtable.cQuoted 4 lines
arch/arm64/kvm/hyp/pgtable.c static inline int __kvm_pgtable_visit(struct
Quoted 4 lines
index
bdf8e55ed308..4d99d07c610c100644arch/arm64/kvm/hyp/pgtable.c +0
-0@@ -225,6 +225,7 @@ static inline int __kvm_pgtable_visit(struct
kvm_pgtable_walk_data*data,Quoted 10 lines
arch/arm64/kvm/hyp/pgtable.c static inline int __kvm_pgtable_visit(struct kvm_pgtable_walk_data *data, · line 231
Quoted 7 lines
arch/arm64/kvm/hyp/pgtable.c +1
-0goto out;if (!table) { + data->addr =ALIGN_DOWN (data->addr,kvm_granule_size (level)); data->addr +=kvm_granule_size (level); goto out; }It otherwise looks good to me. Quentin, Will: unless you object to this, I plan to take it in the next round of fixes with
Quoted 5 lines
Though I'm still unsure how we hit that today, the change makes sense on its own I think, so no objection from me.
Thanks,
Quentin
_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Will Deacon
maintainerQuoted 28 lines · Marc Zyngier
Hi Jia,
Quoted 7 lines · Jia He
If the start addr is not aligned with the granule size of that level. loop step size should be adjusted to boundary instead of simple
kvm_granual_size(level)increment. Otherwise, some mmu entries might miss the chance to be walked through.
E.g. Assume the unmap range [data->addr,data->end] is [0xff00ab2000,0xff00cb2000] in level 2 walking and NOT block mapping.When does this occur? Upgrade from page mappings to block? Swap out?
Quoted 3 lines
And the 1st part of that pmd entry is [0xff00ab2000,0xff00c00000]. The pmd value is
0x83fbd2c1002(not valid entry). In this case,data->addrshould be adjusted to0xff00c00000instead of0xff00cb2000.Let me see if I understand this. Assuming 4k pages, the region described above spans *two* 2M entries:
(a) ff00ab2000-ff00c00000, part of ff00a00000-ff00c00000
(b) ff00c00000-ff00db2000, part of ff00c00000-ff00e00000(a) has no valid mapping, but (b) does. Because we fail to correctly align on a block boundary when skipping (a), we also skip (b), which is then left mapped.
Quoted 8 lines
Did I get it right? If so, yes, this is... annoying.
Understanding the circumstances this triggers in would be most interesting. This current code seems to assume that we get ranges aligned to mapping boundaries, but I seem to remember that the old code did use the stage2_*_addr_end() helpers to deal with this case.
Will: I don't think things have changed in that respect, right?
We've maintained stage2_pgd_addr_end() for the top-level iterator, but it looks like we're failing to do the rounding in __kvm_pgtable_visit() when hitting a leaf entry, so the caller (__kvm_pgtable_walk()) will terminate early.
I agree that it's annoying, as you'd have expected us to run into this earlier on.
Will
_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Will Deacon
maintainerQuoted 29 lines · Jia He
If the start addr is not aligned with the granule size of that level. loop step size should be adjusted to boundary instead of simple
kvm_granual_size(level)increment. Otherwise, some mmu entries might miss the chance to be walked through.
E.g. Assume the unmap range [data->addr,data->end] is [0xff00ab2000,0xff00cb2000] in level 2 walking and NOT block mapping. And the 1st part of that pmd entry is [0xff00ab2000,0xff00c00000]. The pmd value is0x83fbd2c1002(not valid entry). In this case,data->addrshould be adjusted to0xff00c00000instead of0xff00cb2000.Without this fix, userspace "segment fault" error can be easily triggered by running simple gVisor runsc cases on an Ampere Altra server:
docker run --runtime=runsc -it --rm ubuntu /bin/bashIn container:
for i in `seq 1 100`;do ls;doneReported-by Howard Zhang <[email protected]>Signed-off-by Jia He <[email protected]>--- arch/arm64/kvm/hyp/pgtable.c | 1 + 1 file changed, 1 insertion(+)arch/arm64/kvm/hyp/pgtable.c +0
-0
arch/arm64/kvm/hyp/pgtable.c static inline int __kvm_pgtable_visit(struct kvm_pgtable_walk_data *data, · line 229
Quoted 5 lines
arch/arm64/kvm/hyp/pgtable.c +1
-0@@ -225,6 +225,7 @@ static inline int __kvm_pgtable_visit(struct kvm_pgtable_walk_data *data, goto out;if (!table) { + data->addr =ALIGN_DOWN (data->addr,kvm_granule_size (level)); data->addr +=kvm_granule_size (level);
Can you replace both of these lines with:
data->addr = ALIGN(data->addr, kvm_granule_size(level));
instead?
Will
_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Marc Zyngier
maintainerQuoted 39 lines · Will Deacon
Quoted 29 lines · Jia He
If the start addr is not aligned with the granule size of that level. loop step size should be adjusted to boundary instead of simple
kvm_granual_size(level)increment. Otherwise, some mmu entries might miss the chance to be walked through.
E.g. Assume the unmap range [data->addr,data->end] is [0xff00ab2000,0xff00cb2000] in level 2 walking and NOT block mapping. And the 1st part of that pmd entry is [0xff00ab2000,0xff00c00000]. The pmd value is0x83fbd2c1002(not valid entry). In this case,data->addrshould be adjusted to0xff00c00000instead of0xff00cb2000.Without this fix, userspace "segment fault" error can be easily triggered by running simple gVisor runsc cases on an Ampere Altra server:
docker run --runtime=runsc -it --rm ubuntu /bin/bashIn container:
for i in `seq 1 100`;do ls;doneReported-by Howard Zhang <[email protected]>Signed-off-by Jia He <[email protected]>--- arch/arm64/kvm/hyp/pgtable.c | 1 + 1 file changed, 1 insertion(+)arch/arm64/kvm/hyp/pgtable.c +0
-0arch/arm64/kvm/hyp/pgtable.c static inline int __kvm_pgtable_visit(struct kvm_pgtable_walk_data *data, · line 229
Quoted 5 lines
arch/arm64/kvm/hyp/pgtable.c +1
-0@@ -225,6 +225,7 @@ static inline int __kvm_pgtable_visit(struct kvm_pgtable_walk_data *data, goto out;if (!table) { + data->addr =ALIGN_DOWN (data->addr,kvm_granule_size (level)); data->addr +=kvm_granule_size (level);Can you replace both of these lines with:
Quoted 3 lines
data->addr = ALIGN(data->addr, kvm_granule_size(level));instead?
Seems like a good option. I also took the liberty to rewrite the commit message in an effort to make it a bit clearer.
Jia, please let me know if you are OK with these cosmetic changes.
Thanks,
M.
From e0524b41a71e0f17d6dc8f197e421e677d584e72 Mon Sep 17 00:00:00 2001
From: Jia He <[email protected]>
Date: Wed, 3 Mar 2021 10:42:25 +0800
Subject: [PATCH] KVM: arm64: Fix range alignment when walking page tables
When walking the page tables at a given level, and if the start address for the range isn't aligned for that level, we propagate the misalignment on each iteration at that level.
This results in the walker ignoring a number of entries (depending on the original misalignment) on each subsequent iteration.
Properly aligning the address at the before the next iteration addresses the issue.
--- arch/arm64/kvm/hyp/pgtable.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/kvm/hyp/pgtable.c +1 -1
@@ -223,7 +223,7 @@ static inline int __kvm_pgtable_visit(struct kvm_pgtable_walk_data *data, goto out;if (!table) { - data->addr +=kvm_granule_size (level); + data->addr =ALIGN (data->addr,kvm_granule_size (level)); goto out; }
Signature · 9 lines
2.30.0 -- Without deviation from the norm, progress is not possible. _______________________________________________ kvmarm mailing list [email protected] https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Quoted 5 lines · Marc Zyngier
From
e0524b41a71e0f17d6dc8f197e421e677d584e72Mon Sep 17 00:00:00 2001
From: Jia He <[email protected]>
Date: Wed, 3 Mar 2021 10:42:25 +0800
Subject: [PATCH] KVM: arm64: Fix range alignment when walking page tables
Quoted 8 lines
When walking the page tables at a given level, and if the start address for the range isn't aligned for that level, we propagate the misalignment on each iteration at that level.
This results in the walker ignoring a number of entries (depending on the original misalignment) on each subsequent iteration.
Properly aligning the address at the before the next iteration
"at the before the next" ???
Quoted 18 lines
addresses the issue.
Reported-by Howard Zhang <[email protected]>Signed-off-by Jia He <[email protected]>Fixes b1e57de62cfb ("KVM: arm64: Add stand-alone page-table walker infrastructure")[maz: rewrite commit message]Signed-off-by Marc Zyngier <[email protected]>--- arch/arm64/kvm/hyp/pgtable.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/arm64/kvm/hyp/pgtable.c +0
-0
arch/arm64/kvm/hyp/pgtable.c static inline int __kvm_pgtable_visit(struct kvm_pgtable_walk_data *data, · line 228
Quoted 7 lines
arch/arm64/kvm/hyp/pgtable.c +1
-1@@ -223,7 +223,7 @@ static inline int __kvm_pgtable_visit(struct kvm_pgtable_walk_data *data, goto out;if (!table) { - data->addr +=kvm_granule_size (level); + data->addr =ALIGN (data->addr,kvm_granule_size (level)); goto out; }
If Jia is happy with it, please feel free to add:
Will
_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Hi Marc
Quoted 49 lines
-----Original Message-----
From: Will Deacon <[email protected]>
Sent: Thursday, March 4, 2021 5:13 AM
To: Marc Zyngier <[email protected]>
Cc: Justin He <[email protected]>; [email protected]; James Morse <[email protected]>; Julien Thierry <[email protected]>; Suzuki Poulose <[email protected]>; Catalin Marinas <[email protected]>; Gavin Shan <[email protected]>; Yanan Wang <[email protected]>; Quentin Perret <[email protected]>; linux-arm- [email protected]; [email protected]
Subject: Re: [PATCH] KVM: arm64: Fix unaligned addr case in mmu walkingQuoted 5 lines · Marc Zyngier
From
e0524b41a71e0f17d6dc8f197e421e677d584e72Mon Sep 17 00:00:00 2001
From: Jia He <[email protected]>
Date: Wed, 3 Mar 2021 10:42:25 +0800
Subject: [PATCH] KVM: arm64: Fix range alignment when walking page tablesQuoted 8 lines
When walking the page tables at a given level, and if the start address for the range isn't aligned for that level, we propagate the misalignment on each iteration at that level.
This results in the walker ignoring a number of entries (depending on the original misalignment) on each subsequent iteration.
Properly aligning the address at the before the next iteration
"at the before the next" ???
Quoted 6 lines
addresses the issue.
Reported-by Howard Zhang <[email protected]>Signed-off-by Jia He <[email protected]>Fixes b1e57de62cfb ("KVM: arm64: Add stand-alone page-table walkerinfrastructure")
arch/arm64/kvm/hyp/pgtable.c static inline int __kvm_pgtable_visit(struct
Quoted 12 lines
[maz: rewrite commit message]Signed-off-by Marc Zyngier <[email protected]>--- arch/arm64/kvm/hyp/pgtable.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/arm64/kvm/hyp/pgtable.c +0
-0@@ -223,7 +223,7 @@ static inline int __kvm_pgtable_visit(struct
kvm_pgtable_walk_data*data,
Quoted 5 lines
arch/arm64/kvm/hyp/pgtable.c static inline int __kvm_pgtable_visit(struct kvm_pgtable_walk_data *data, · line 226
Quoted 5 lines
arch/arm64/kvm/hyp/pgtable.c +1
-1goto out;if (!table) { - data->addr +=kvm_granule_size (level); + data->addr =ALIGN (data->addr,kvm_granule_size (level));
What if previous data->addr is already aligned with kvm_granule_size(level)? Hence a deadloop? Am I missing anything else?
--
Cheers,
Justin (Jia He)
Quoted 8 lines
arch/arm64/kvm/hyp/pgtable.c static inline int __kvm_pgtable_visit(struct · line 228
Quoted 2 lines
arch/arm64/kvm/hyp/pgtable.c +0
-0goto out; }If Jia is happy with it, please feel free to add:
Acked-by Will Deacon <[email protected]>Will
_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Marc Zyngier
maintainerQuoted 51 lines · Justin He
Hi Marc
Quoted 49 lines
-----Original Message-----
From: Will Deacon <[email protected]>
Sent: Thursday, March 4, 2021 5:13 AM
To: Marc Zyngier <[email protected]>
Cc: Justin He <[email protected]>; [email protected]; James Morse <[email protected]>; Julien Thierry <[email protected]>; Suzuki Poulose <[email protected]>; Catalin Marinas <[email protected]>; Gavin Shan <[email protected]>; Yanan Wang <[email protected]>; Quentin Perret <[email protected]>; linux-arm- [email protected]; [email protected]
Subject: Re: [PATCH] KVM: arm64: Fix unaligned addr case in mmu walkingQuoted 5 lines · Marc Zyngier
From
e0524b41a71e0f17d6dc8f197e421e677d584e72Mon Sep 17 00:00:00 2001
From: Jia He <[email protected]>
Date: Wed, 3 Mar 2021 10:42:25 +0800
Subject: [PATCH] KVM: arm64: Fix range alignment when walking page tablesQuoted 8 lines
When walking the page tables at a given level, and if the start address for the range isn't aligned for that level, we propagate the misalignment on each iteration at that level.
This results in the walker ignoring a number of entries (depending on the original misalignment) on each subsequent iteration.
Properly aligning the address at the before the next iteration
"at the before the next" ???
Quoted 6 lines
addresses the issue.
Reported-by Howard Zhang <[email protected]>Signed-off-by Jia He <[email protected]>Fixes b1e57de62cfb ("KVM: arm64: Add stand-alone page-table walkerinfrastructure")
arch/arm64/kvm/hyp/pgtable.c static inline int __kvm_pgtable_visit(struct
Quoted 12 lines
[maz: rewrite commit message]Signed-off-by Marc Zyngier <[email protected]>--- arch/arm64/kvm/hyp/pgtable.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/arm64/kvm/hyp/pgtable.c +0
-0@@ -223,7 +223,7 @@ static inline int __kvm_pgtable_visit(struct
kvm_pgtable_walk_data*data,
Quoted 8 lines
Quoted 5 lines
arch/arm64/kvm/hyp/pgtable.c static inline int __kvm_pgtable_visit(struct kvm_pgtable_walk_data *data, · line 226
Quoted 5 lines
arch/arm64/kvm/hyp/pgtable.c +1
-1goto out;if (!table) { - data->addr +=kvm_granule_size (level); + data->addr =ALIGN (data->addr,kvm_granule_size (level));What if previous
data->addris already aligned withkvm_granule_size(level)? Hence a deadloop? Am I missing anything else?
Indeed, well spotted. I'll revert to your original suggestion if everybody agrees...
Thanks,
M.
Signature · 5 lines
Jazz is not dead. It just smells funny... _______________________________________________ kvmarm mailing list [email protected] https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Quoted 48 lines · Marc Zyngier
Quoted 39 lines · Justin He
Quoted 39 lines · Marc Zyngier
Quoted 5 lines
From
e0524b41a71e0f17d6dc8f197e421e677d584e72Mon Sep 17 00:00:00 2001
From: Jia He <[email protected]>
Date: Wed, 3 Mar 2021 10:42:25 +0800
Subject: [PATCH] KVM: arm64: Fix range alignment when walking page tablesQuoted 8 lines
When walking the page tables at a given level, and if the start address for the range isn't aligned for that level, we propagate the misalignment on each iteration at that level.
This results in the walker ignoring a number of entries (depending on the original misalignment) on each subsequent iteration.
Properly aligning the address at the before the next iteration
"at the before the next" ???
Quoted 6 lines
addresses the issue.
Reported-by Howard Zhang <[email protected]>Signed-off-by Jia He <[email protected]>Fixes b1e57de62cfb ("KVM: arm64: Add stand-alone page-table walkerinfrastructure")
arch/arm64/kvm/hyp/pgtable.c static inline int __kvm_pgtable_visit(struct
Quoted 12 lines
[maz: rewrite commit message]Signed-off-by Marc Zyngier <[email protected]>--- arch/arm64/kvm/hyp/pgtable.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/arm64/kvm/hyp/pgtable.c +0
-0@@ -223,7 +223,7 @@ static inline int __kvm_pgtable_visit(struct
kvm_pgtable_walk_data*data,Quoted 2 lines
arch/arm64/kvm/hyp/pgtable.c +0
-0goto out;Quoted 7 lines
Quoted 3 lines
arch/arm64/kvm/hyp/pgtable.c static inline int __kvm_pgtable_visit(struct kvm_pgtable_walk_data *data, · line 226
Quoted 3 lines
arch/arm64/kvm/hyp/pgtable.c +1
-1if (!table) { - data->addr +=kvm_granule_size (level); + data->addr =ALIGN (data->addr,kvm_granule_size (level));What if previous
data->addris already aligned withkvm_granule_size(level)?
Hence a deadloop? Am I missing anything else?
Quoted 2 lines
Indeed, well spotted. I'll revert to your original suggestion if everybody agrees...
Heh, yeah, at least one of us is awake.
For the original patch, with the updated (including typo fix) commit message:
If that still counts for anything!
Will
_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Quoted 11 lines · Jia He
If the start addr is not aligned with the granule size of that level. loop step size should be adjusted to boundary instead of simple
kvm_granual_size(level)increment. Otherwise, some mmu entries might miss the chance to be walked through.
E.g. Assume the unmap range [data->addr,data->end] is [0xff00ab2000,0xff00cb2000] in level 2 walking and NOT block mapping. And the 1st part of that pmd entry is [0xff00ab2000,0xff00c00000]. The pmd value is0x83fbd2c1002(not valid entry). In this case,data->addrshould be adjusted to0xff00c00000instead of0xff00cb2000.[...]
Applied to fixes, thanks!
[1/1] KVM: arm64: Fix unaligned addr case in mmu walking
commit: e85583b3f1fe62c9b371a3100c1c91af94005ca9
Cheers,
M.
Signature · 7 lines
Without deviation from the norm, progress is not possible. _______________________________________________ kvmarm mailing list [email protected] https://lists.cs.columbia.edu/mailman/listinfo/kvmarm