From: Peter Zijlstra <peterz@infradead.org>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: rostedt@goodmis.org, dave.hansen@intel.com,
linux-kernel@vger.kernel.org, x86@kernel.org,
keescook@chromium.org, seanjc@google.com
Subject: Re: [PATCH 0/5] x86/ftrace: Cure boot time W+X mapping
Date: Sat, 29 Oct 2022 13:30:16 +0200 [thread overview]
Message-ID: <Y10OyLCLAAS6rsZv@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <Y1osYVoLrpCabNrR@hirez.programming.kicks-ass.net>
On Thu, Oct 27, 2022 at 08:59:45AM +0200, Peter Zijlstra wrote:
> On Wed, Oct 26, 2022 at 10:59:29AM -0700, Linus Torvalds wrote:
>
> > Maybe you meant to do that, and this patch was just prep-work for the
> > arch code being the second stage?
>
> Yeah; also, since this is cross arch, we need a fallback. Anyway;
> robots hated on me for missing a few includes. I'll go prod at this
> more.
Got around to it; I added the below patch on top and things seem to
still boot so it must be good :-)
---
Subject: x86/mm: Implement native set_memory_rox()
From: Peter Zijlstra <peterz@infradead.org>
Date: Sat Oct 29 13:19:31 CEST 2022
Provide a native implementation of set_memory_rox(), avoiding the
double set_memory_ro();set_memory_x(); calls.
Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
arch/x86/include/asm/set_memory.h | 3 +++
arch/x86/mm/pat/set_memory.c | 10 ++++++++++
include/linux/set_memory.h | 2 ++
3 files changed, 15 insertions(+)
--- a/arch/x86/include/asm/set_memory.h
+++ b/arch/x86/include/asm/set_memory.h
@@ -6,6 +6,9 @@
#include <asm/page.h>
#include <asm-generic/set_memory.h>
+#define set_memory_rox set_memory_rox
+int set_memory_rox(unsigned long addr, int numpages);
+
/*
* The set_memory_* API can be used to change various attributes of a virtual
* address range. The attributes include:
--- a/arch/x86/mm/pat/set_memory.c
+++ b/arch/x86/mm/pat/set_memory.c
@@ -2025,6 +2025,16 @@ int set_memory_ro(unsigned long addr, in
return change_page_attr_clear(&addr, numpages, __pgprot(_PAGE_RW), 0);
}
+int set_memory_rox(unsigned long addr, int numpages)
+{
+ pgprot_t clr = __pgprot(_PAGE_RW);
+
+ if (__supported_pte_mask & _PAGE_NX)
+ clr.pgprot |= _PAGE_NX;
+
+ return change_page_attr_clear(&addr, numpages, clr, 0);
+}
+
int set_memory_rw(unsigned long addr, int numpages)
{
return change_page_attr_set(&addr, numpages, __pgprot(_PAGE_RW), 0);
--- a/include/linux/set_memory.h
+++ b/include/linux/set_memory.h
@@ -14,6 +14,7 @@ static inline int set_memory_x(unsigned
static inline int set_memory_nx(unsigned long addr, int numpages) { return 0; }
#endif
+#ifndef set_memory_rox
static inline int set_memory_rox(unsigned long addr, int numpages)
{
int ret = set_memory_ro(addr, numpages);
@@ -21,6 +22,7 @@ static inline int set_memory_rox(unsigne
return ret;
return set_memory_x(addr, numpages);
}
+#endif
#ifndef CONFIG_ARCH_HAS_SET_DIRECT_MAP
static inline int set_direct_map_invalid_noflush(struct page *page)
next prev parent reply other threads:[~2022-10-29 11:30 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-25 20:06 [PATCH 0/5] x86/ftrace: Cure boot time W+X mapping Peter Zijlstra
2022-10-25 20:06 ` [PATCH 1/5] mm: Move mm_cachep initialization to mm_init() Peter Zijlstra
2022-11-02 9:12 ` [tip: x86/mm] " tip-bot2 for Peter Zijlstra
2022-12-17 18:55 ` tip-bot2 for Peter Zijlstra
2022-10-25 20:06 ` [PATCH 2/5] x86/mm: Use mm_alloc() in poking_init() Peter Zijlstra
2022-11-02 9:12 ` [tip: x86/mm] " tip-bot2 for Peter Zijlstra
2022-12-17 18:55 ` tip-bot2 for Peter Zijlstra
2022-10-25 20:06 ` [PATCH 3/5] x86/mm: Initialize text poking earlier Peter Zijlstra
2022-11-02 9:12 ` [tip: x86/mm] " tip-bot2 for Peter Zijlstra
2022-12-17 18:55 ` tip-bot2 for Peter Zijlstra
2022-10-25 20:07 ` [PATCH 4/5] x86/ftrace: Remove SYSTEM_BOOTING exceptions Peter Zijlstra
2022-10-25 20:59 ` Steven Rostedt
2022-10-26 7:02 ` Peter Zijlstra
2022-11-02 9:12 ` [tip: x86/mm] " tip-bot2 for Peter Zijlstra
2022-12-17 18:55 ` tip-bot2 for Peter Zijlstra
2022-10-25 20:07 ` [PATCH 5/5] x86/mm: Do verify W^X at boot up Peter Zijlstra
2022-11-02 9:12 ` [tip: x86/mm] " tip-bot2 for Peter Zijlstra
2022-12-17 18:55 ` tip-bot2 for Peter Zijlstra
2022-10-25 23:07 ` [PATCH 0/5] x86/ftrace: Cure boot time W+X mapping Linus Torvalds
2022-10-25 23:17 ` Steven Rostedt
2022-10-26 7:15 ` Peter Zijlstra
2022-10-26 17:59 ` Linus Torvalds
2022-10-27 6:59 ` Peter Zijlstra
2022-10-29 11:30 ` Peter Zijlstra [this message]
2022-10-29 17:35 ` Linus Torvalds
2022-11-02 9:12 ` [tip: x86/mm] mm: Introduce set_memory_rox() tip-bot2 for Peter Zijlstra
2022-12-17 18:55 ` tip-bot2 for Peter Zijlstra
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=Y10OyLCLAAS6rsZv@hirez.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=dave.hansen@intel.com \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rostedt@goodmis.org \
--cc=seanjc@google.com \
--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