linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Song Liu <songliubraving@fb.com>
To: <linux-kernel@vger.kernel.org>
Cc: Song Liu <songliubraving@fb.com>, <kernel-team@fb.com>,
	<x86@kernel.org>, Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Linus Torvalds <torvalds@linux-foundation.org>
Subject: [PATCH] x86/mm/pti: Handle unaligned addr to PMD-mapped page in pti_clone_pgtable
Date: Wed, 18 Sep 2019 22:53:12 -0700	[thread overview]
Message-ID: <20190919055312.3020652-1-songliubraving@fb.com> (raw)

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


             reply	other threads:[~2019-09-19  5:54 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-19  5:53 Song Liu [this message]
2019-09-23 11:27 ` [PATCH] x86/mm/pti: Handle unaligned addr to PMD-mapped page in pti_clone_pgtable Peter Zijlstra
2019-09-23 18:12   ` Linus Torvalds

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190919055312.3020652-1-songliubraving@fb.com \
    --to=songliubraving@fb.com \
    --cc=kernel-team@fb.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.org \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).