* [PATCH] x86/mm/pti: Handle unaligned addr to PMD-mapped page in pti_clone_pgtable
@ 2019-09-19 5:53 Song Liu
2019-09-23 11:27 ` Peter Zijlstra
0 siblings, 1 reply; 3+ messages in thread
From: Song Liu @ 2019-09-19 5:53 UTC (permalink / raw)
To: linux-kernel
Cc: Song Liu, kernel-team, x86, Thomas Gleixner, Ingo Molnar,
Peter Zijlstra, Linus Torvalds
To clone page table of PMD-mapped pages, pti_clone_pgtable() requires PMD
aligned start address. [1] adds warning for unaligned addresses. However,
there is still no warning for unaligned address to valid huge pmd [2].
Add alignment check in valid pmd_large() case. If the address is
unaligned, round it down to the nearest PMD aligned address and show
warning.
[1] commit 825d0b73cd75 ("x86/mm/pti: Handle unaligned address gracefully
in pti_clone_pagetable()")
[2] https://lore.kernel.org/lkml/156864062019.3407.14798418565580024723.tglx@nanos.tec.linutronix.de/
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Song Liu <songliubraving@fb.com>
---
arch/x86/mm/pti.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/arch/x86/mm/pti.c b/arch/x86/mm/pti.c
index 7f2140414440..d224115c350d 100644
--- a/arch/x86/mm/pti.c
+++ b/arch/x86/mm/pti.c
@@ -343,6 +343,10 @@ pti_clone_pgtable(unsigned long start, unsigned long end,
}
if (pmd_large(*pmd) || level == PTI_CLONE_PMD) {
+ /* warn and round_down() unaligned addr */
+ if (WARN_ON_ONCE(addr & ~PMD_MASK))
+ addr &= PMD_MASK;
+
target_pmd = pti_user_pagetable_walk_pmd(addr);
if (WARN_ON(!target_pmd))
return;
--
2.17.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] x86/mm/pti: Handle unaligned addr to PMD-mapped page in pti_clone_pgtable
2019-09-19 5:53 [PATCH] x86/mm/pti: Handle unaligned addr to PMD-mapped page in pti_clone_pgtable Song Liu
@ 2019-09-23 11:27 ` Peter Zijlstra
2019-09-23 18:12 ` Linus Torvalds
0 siblings, 1 reply; 3+ messages in thread
From: Peter Zijlstra @ 2019-09-23 11:27 UTC (permalink / raw)
To: Song Liu
Cc: linux-kernel, kernel-team, x86, Thomas Gleixner, Ingo Molnar,
Linus Torvalds
On Wed, Sep 18, 2019 at 10:53:12PM -0700, Song Liu wrote:
> To clone page table of PMD-mapped pages, pti_clone_pgtable() requires PMD
> aligned start address. [1] adds warning for unaligned addresses. However,
> there is still no warning for unaligned address to valid huge pmd [2].
>
> Add alignment check in valid pmd_large() case. If the address is
> unaligned, round it down to the nearest PMD aligned address and show
> warning.
>
> [1] commit 825d0b73cd75 ("x86/mm/pti: Handle unaligned address gracefully
> in pti_clone_pagetable()")
> [2] https://lore.kernel.org/lkml/156864062019.3407.14798418565580024723.tglx@nanos.tec.linutronix.de/
>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: Ingo Molnar <mingo@kernel.org>
> Cc: Peter Zijlstra (Intel) <peterz@infradead.org>
> Cc: Linus Torvalds <torvalds@linux-foundation.org>
> Signed-off-by: Song Liu <songliubraving@fb.com>
> ---
> arch/x86/mm/pti.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/arch/x86/mm/pti.c b/arch/x86/mm/pti.c
> index 7f2140414440..d224115c350d 100644
> --- a/arch/x86/mm/pti.c
> +++ b/arch/x86/mm/pti.c
> @@ -343,6 +343,10 @@ pti_clone_pgtable(unsigned long start, unsigned long end,
> }
>
> if (pmd_large(*pmd) || level == PTI_CLONE_PMD) {
> + /* warn and round_down() unaligned addr */
> + if (WARN_ON_ONCE(addr & ~PMD_MASK))
> + addr &= PMD_MASK;
> +
> target_pmd = pti_user_pagetable_walk_pmd(addr);
> if (WARN_ON(!target_pmd))
> return;
I'm conflicted on this one... the only use of addr here is
pti_user_pagetable_walk_pmd() and that already masks things, so the
fixup is 'pointless'.
Also the location is weird; we'd want to do alignment enforcement before
we commence the for-loop, methinks.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] x86/mm/pti: Handle unaligned addr to PMD-mapped page in pti_clone_pgtable
2019-09-23 11:27 ` Peter Zijlstra
@ 2019-09-23 18:12 ` Linus Torvalds
0 siblings, 0 replies; 3+ messages in thread
From: Linus Torvalds @ 2019-09-23 18:12 UTC (permalink / raw)
To: Peter Zijlstra
Cc: Song Liu, Linux Kernel Mailing List, kernel-team,
the arch/x86 maintainers, Thomas Gleixner, Ingo Molnar
On Mon, Sep 23, 2019 at 4:28 AM Peter Zijlstra <peterz@infradead.org> wrote:
>
> I'm conflicted on this one... the only use of addr here is
> pti_user_pagetable_walk_pmd() and that already masks things, so the
> fixup is 'pointless'.
No it's not.
The *other* use of 'addr' is
addr += PMD_SIZE;
and then repeat the loop.
And that repeat might then use it for the page-level case the next iteration.
> Also the location is weird; we'd want to do alignment enforcement before
> we commence the for-loop, methinks.
No. See again. The alignment is different for the different cases
inside the loop. Some do per-page stuff, some do per-pmd stuff, and
some do per-pud stuff.
And you don't know which you'll hit a-priori (because it's not limited
to the 'level' testing).
Linus
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-09-23 18:12 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-19 5:53 [PATCH] x86/mm/pti: Handle unaligned addr to PMD-mapped page in pti_clone_pgtable Song Liu
2019-09-23 11:27 ` Peter Zijlstra
2019-09-23 18:12 ` Linus Torvalds
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®