public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Nadav Amit <namit@vmware.com>
To: Ingo Molnar <mingo@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>,
	Andy Lutomirski <luto@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	Willy Tarreau <w@1wt.eu>, Nadav Amit <nadav.amit@gmail.com>,
	<x86@kernel.org>, <linux-kernel@vger.kernel.org>,
	Nadav Amit <namit@vmware.com>
Subject: [PATCH RFC v2 2/6] x86: Save pti_disable for each mm_context
Date: Thu, 15 Feb 2018 08:35:58 -0800	[thread overview]
Message-ID: <20180215163602.61162-3-namit@vmware.com> (raw)
In-Reply-To: <20180215163602.61162-1-namit@vmware.com>

Save for each mm->context whether page-table isolation should be
disabled. In order not to make intrusive changes, the information is
saved in the PGD page metadata.

Signed-off-by: Nadav Amit <namit@vmware.com>
---
 arch/x86/include/asm/mmu.h | 3 +++
 arch/x86/include/asm/pti.h | 9 +++++++++
 arch/x86/mm/pgtable.c      | 4 +++-
 arch/x86/mm/pti.c          | 9 +++++++--
 4 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
index 5ff3e8af2c20..fb8db4a09d8a 100644
--- a/arch/x86/include/asm/mmu.h
+++ b/arch/x86/include/asm/mmu.h
@@ -36,6 +36,9 @@ typedef struct {
 	/* True if mm supports a task running in 32 bit compatibility mode. */
 	unsigned short ia32_compat;
 #endif
+#ifdef CONFIG_PAGE_TABLE_ISOLATION
+	unsigned short pti_disable;
+#endif
 
 	struct mutex lock;
 	void __user *vdso;			/* vdso base address */
diff --git a/arch/x86/include/asm/pti.h b/arch/x86/include/asm/pti.h
index 0b5ef05b2d2d..96a5fbfedf7a 100644
--- a/arch/x86/include/asm/pti.h
+++ b/arch/x86/include/asm/pti.h
@@ -4,9 +4,18 @@
 #ifndef __ASSEMBLY__
 
 #ifdef CONFIG_PAGE_TABLE_ISOLATION
+static inline unsigned short mm_pti_disable(struct mm_struct *mm)
+{
+	if (mm == NULL)
+		return 0;
+
+	return mm->context.pti_disable;
+}
+
 extern void pti_init(void);
 extern void pti_check_boottime_disable(void);
 #else
+static inline unsigned short mm_pti_disable(struct mm_struct *mm) { return 0; }
 static inline void pti_check_boottime_disable(void) { }
 #endif
 
diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
index 004abf9ebf12..ef0394a97adb 100644
--- a/arch/x86/mm/pgtable.c
+++ b/arch/x86/mm/pgtable.c
@@ -139,7 +139,9 @@ static void pgd_ctor(struct mm_struct *mm, pgd_t *pgd)
 	if (!SHARED_KERNEL_PMD) {
 		pgd_set_mm(pgd, mm);
 		pgd_list_add(pgd);
-	}
+	} else if (IS_ENABLED(CONFIG_PAGE_TABLE_ISOLATION) &&
+		   static_cpu_has(X86_FEATURE_PTI))
+		pgd_set_mm(pgd, mm);
 }
 
 static void pgd_dtor(pgd_t *pgd)
diff --git a/arch/x86/mm/pti.c b/arch/x86/mm/pti.c
index ce38f165489b..a973a291a34d 100644
--- a/arch/x86/mm/pti.c
+++ b/arch/x86/mm/pti.c
@@ -134,10 +134,15 @@ pgd_t __pti_set_user_pgd(pgd_t *pgdp, pgd_t pgd)
 	 *     may execute from it
 	 *  - we don't have NX support
 	 *  - we're clearing the PGD (i.e. the new pgd is not present).
+	 *  - PTI is disabled.
 	 */
 	if ((pgd.pgd & (_PAGE_USER|_PAGE_PRESENT)) == (_PAGE_USER|_PAGE_PRESENT) &&
-	    (__supported_pte_mask & _PAGE_NX))
-		pgd.pgd |= _PAGE_NX;
+	    (__supported_pte_mask & _PAGE_NX)) {
+		struct mm_struct *mm = pgd_page_get_mm(virt_to_page(pgdp));
+
+		if (!mm_pti_disable(mm))
+			pgd.pgd |= _PAGE_NX;
+	}
 
 	/* return the copy of the PGD we want the kernel to use: */
 	return pgd;
-- 
2.14.1

  parent reply	other threads:[~2018-02-15 16:37 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-15 16:35 [PATCH RFC v2 0/6] x86: Disabling PTI in compatibility mode Nadav Amit
2018-02-15 16:35 ` [PATCH RFC v2 1/6] x86: Skip PTI when disable indication is set Nadav Amit
2018-02-15 18:10   ` Dave Hansen
2018-02-15 19:51   ` Andy Lutomirski
2018-02-15 20:51     ` Nadav Amit
2018-02-15 23:35       ` Andy Lutomirski
2018-02-15 16:35 ` Nadav Amit [this message]
2018-02-15 16:35 ` [PATCH RFC v2 3/6] x86: Switching page-table isolation Nadav Amit
2018-02-15 16:36 ` [PATCH RFC v2 4/6] x86: Disable PTI on compatibility mode Nadav Amit
2018-02-15 20:02   ` Andy Lutomirski
2018-02-15 20:58     ` Nadav Amit
2018-02-15 23:29       ` Andy Lutomirski
2018-02-16  0:08         ` Linus Torvalds
2018-02-16  0:22           ` Nadav Amit
2018-02-16  0:42             ` Linus Torvalds
2018-02-16  3:03               ` Andy Lutomirski
2018-02-16  4:55                 ` Nadav Amit
2018-02-16  0:35           ` Andrew Cooper
2018-02-16 15:20           ` Andy Lutomirski
2018-02-16  7:11         ` Cyrill Gorcunov
2018-02-16 22:07           ` Dmitry Safonov
2018-02-16 22:11             ` Nadav Amit
2018-02-16 16:25     ` Dmitry Safonov
2018-02-15 16:36 ` [PATCH RFC v2 5/6] x86: Use global pages when PTI is disabled Nadav Amit
2018-02-15 16:54   ` Dave Hansen
2018-02-15 17:36     ` Nadav Amit
2018-02-15 17:47     ` Nadav Amit
2018-02-15 18:08       ` Dave Hansen
2018-02-15 19:53   ` Andy Lutomirski
2018-02-15 20:32     ` Dave Hansen
2018-02-15 20:45       ` Nadav Amit
2018-02-15 16:36 ` [PATCH RFC v2 6/6] selftest: x86: test using CS64 on compatibility-mode Nadav Amit
2018-02-16  0:21 ` [PATCH RFC v2 0/6] x86: Disabling PTI in compatibility mode Dave Hansen
2018-02-16  0:25   ` Nadav Amit
2018-02-16  0:42     ` Dave Hansen
2018-02-16  0:48       ` Nadav Amit
2018-02-16  0:45     ` Andrew Cooper
2018-02-16  0:51       ` Nadav Amit
2018-02-16  1:04         ` Andrew Cooper
2018-02-16  3:05         ` Andy Lutomirski

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=20180215163602.61162-3-namit@vmware.com \
    --to=namit@vmware.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=mingo@redhat.com \
    --cc=nadav.amit@gmail.com \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    --cc=w@1wt.eu \
    --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