linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Michal Suchanek <msuchanek@suse.de>
To: linuxppc-dev@lists.ozlabs.org
Cc: "Benjamin Herrenschmidt" <benh@kernel.crashing.org>,
	"Paul Mackerras" <paulus@samba.org>,
	"Michael Ellerman" <mpe@ellerman.id.au>,
	"Peter Zijlstra" <peterz@infradead.org>,
	"Michal Suchanek" <msuchanek@suse.de>,
	"Kate Stewart" <kstewart@linuxfoundation.org>,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Philippe Ombredanne" <pombredanne@nexb.com>,
	"Nicholas Piggin" <npiggin@gmail.com>,
	"Tobin C. Harding" <me@tobin.cc>,
	"Mahesh Salgaonkar" <mahesh@linux.vnet.ibm.com>,
	"David Gibson" <david@gibson.dropbear.id.au>,
	"Al Viro" <viro@zeniv.linux.org.uk>,
	"Michael Neuling" <mikey@neuling.org>,
	"Oliver O'Halloran" <oohall@gmail.com>,
	"Naveen N. Rao" <naveen.n.rao@linux.vnet.ibm.com>,
	"Madhavan Srinivasan" <maddy@linux.vnet.ibm.com>,
	"Masami Hiramatsu" <mhiramat@kernel.org>,
	"Andrew Morton" <akpm@linux-foundation.org>,
	"Balbir Singh" <bsingharora@gmail.com>,
	"Sergey Senozhatsky" <sergey.senozhatsky@gmail.com>,
	"Christophe Leroy" <christophe.leroy@c-s.fr>,
	"Andrew Donnellan" <andrew.donnellan@au1.ibm.com>,
	"Daniel Axtens" <dja@axtens.net>,
	"Russell Currey" <ruscur@russell.cc>,
	"Joe Perches" <joe@perches.com>,
	"Bryant G. Ly" <bryantly@linux.vnet.ibm.com>,
	"Cédric Le Goater" <clg@kaod.org>,
	linux-kernel@vger.kernel.org
Subject: [PATCH RFC 5/8] powerpc/64: Patch barrier_nospec in modules
Date: Tue, 13 Mar 2018 19:33:03 +0100	[thread overview]
Message-ID: <7a0d36c27c354f04c803ce5c4ef743e6f753b2d6.1520965380.git.msuchanek@suse.de> (raw)
In-Reply-To: <cover.1520965380.git.msuchanek@suse.de>
In-Reply-To: <cover.1520965380.git.msuchanek@suse.de>

Copypasta from lwsync patching.

Note that unlike RFI which is patched only in kernel the nospec state
reflects settings at the time the module was loaded.

Iterating all modules and re-patching every time the settings change is
not implemented.

Signed-off-by: Michal Suchanek <msuchanek@suse.de>
---
 arch/powerpc/include/asm/setup.h  |  5 ++++-
 arch/powerpc/kernel/module.c      |  6 ++++++
 arch/powerpc/kernel/setup_64.c    |  4 ++--
 arch/powerpc/lib/feature-fixups.c | 17 ++++++++++++++---
 4 files changed, 26 insertions(+), 6 deletions(-)

diff --git a/arch/powerpc/include/asm/setup.h b/arch/powerpc/include/asm/setup.h
index 486d02e4a310..7e3a41248810 100644
--- a/arch/powerpc/include/asm/setup.h
+++ b/arch/powerpc/include/asm/setup.h
@@ -58,7 +58,10 @@ enum spec_barrier_type {
 void __init setup_rfi_flush(enum l1d_flush_type, bool enable);
 void do_rfi_flush_fixups(enum l1d_flush_type types);
 void __init setup_barrier_nospec(enum spec_barrier_type, bool enable);
-void do_barrier_nospec_fixups(enum spec_barrier_type type);
+void do_barrier_nospec_fixups_kernel(enum spec_barrier_type type);
+void do_barrier_nospec_fixups(enum spec_barrier_type type,
+			      void *start, void *end);
+extern enum spec_barrier_type powerpc_barrier_nospec;
 
 #endif /* !__ASSEMBLY__ */
 
diff --git a/arch/powerpc/kernel/module.c b/arch/powerpc/kernel/module.c
index 3f7ba0f5bf29..7b6d0ec06a21 100644
--- a/arch/powerpc/kernel/module.c
+++ b/arch/powerpc/kernel/module.c
@@ -72,6 +72,12 @@ int module_finalize(const Elf_Ehdr *hdr,
 		do_feature_fixups(powerpc_firmware_features,
 				  (void *)sect->sh_addr,
 				  (void *)sect->sh_addr + sect->sh_size);
+
+	sect = find_section(hdr, sechdrs, "__spec_barrier_fixup");
+	if (sect != NULL)
+		do_barrier_nospec_fixups(powerpc_barrier_nospec,
+				  (void *)sect->sh_addr,
+				  (void *)sect->sh_addr + sect->sh_size);
 #endif
 
 	sect = find_section(hdr, sechdrs, "__lwsync_fixup");
diff --git a/arch/powerpc/kernel/setup_64.c b/arch/powerpc/kernel/setup_64.c
index 09f21a954bfc..d1d9f047161e 100644
--- a/arch/powerpc/kernel/setup_64.c
+++ b/arch/powerpc/kernel/setup_64.c
@@ -909,11 +909,11 @@ void barrier_nospec_enable(bool enable)
 
 	if (enable) {
 		powerpc_barrier_nospec = barrier_nospec_type;
-		do_barrier_nospec_fixups(powerpc_barrier_nospec);
+		do_barrier_nospec_fixups_kernel(powerpc_barrier_nospec);
 		on_each_cpu(do_nothing, NULL, 1);
 	} else {
 		powerpc_barrier_nospec = SPEC_BARRIER_NONE;
-		do_barrier_nospec_fixups(powerpc_barrier_nospec);
+		do_barrier_nospec_fixups_kernel(powerpc_barrier_nospec);
 	}
 }
 
diff --git a/arch/powerpc/lib/feature-fixups.c b/arch/powerpc/lib/feature-fixups.c
index 000e153184ad..b59ebc2215e8 100644
--- a/arch/powerpc/lib/feature-fixups.c
+++ b/arch/powerpc/lib/feature-fixups.c
@@ -156,14 +156,15 @@ void do_rfi_flush_fixups(enum l1d_flush_type types)
 	printk(KERN_DEBUG "rfi-flush: patched %d locations\n", i);
 }
 
-void do_barrier_nospec_fixups(enum spec_barrier_type type)
+void do_barrier_nospec_fixups(enum spec_barrier_type type,
+			      void *fixup_start, void *fixup_end)
 {
 	unsigned int instr, *dest;
 	long *start, *end;
 	int i;
 
-	start = PTRRELOC(&__start___spec_barrier_fixup),
-	end = PTRRELOC(&__stop___spec_barrier_fixup);
+	start = fixup_start;
+	end = fixup_end;
 
 	instr = 0x60000000; /* nop */
 
@@ -182,6 +183,16 @@ void do_barrier_nospec_fixups(enum spec_barrier_type type)
 	printk(KERN_DEBUG "barrier-nospec: patched %d locations\n", i);
 }
 
+void do_barrier_nospec_fixups_kernel(enum spec_barrier_type type)
+{
+	void *start, *end;
+
+	start = PTRRELOC(&__start___spec_barrier_fixup),
+	end = PTRRELOC(&__stop___spec_barrier_fixup);
+
+	do_barrier_nospec_fixups(type, start, end);
+}
+
 #endif /* CONFIG_PPC_BOOK3S_64 */
 
 void do_lwsync_fixups(unsigned long value, void *fixup_start, void *fixup_end)
-- 
2.13.6

  parent reply	other threads:[~2018-03-13 18:33 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-13 18:32 [PATCH RFC 0/8] powerpc barrier_nospec Michal Suchanek
2018-03-13 18:32 ` [PATCH RFC 1/8] powerpc: Add barrier_nospec Michal Suchanek
2018-03-13 20:01   ` Peter Zijlstra
2018-03-15 19:15     ` [PATCH RFC rebase 0/9] powerpc barrier_nospec Michal Suchanek
2018-03-15 19:15       ` [PATCH RFC rebase 1/9] powerpc: Add barrier_nospec Michal Suchanek
2018-03-15 19:15       ` [PATCH RFC rebase 2/9] powerpc: Use barrier_nospec in copy_from_user Michal Suchanek
2018-03-15 21:37         ` Linus Torvalds
2018-03-16 13:22           ` Michael Ellerman
2018-03-15 19:15       ` [PATCH RFC rebase 3/9] powerpc/64: Use barrier_nospec in syscall entry Michal Suchanek
2018-03-16  5:18         ` Nicholas Piggin
2018-03-16  9:15           ` Michal Suchánek
2018-03-16 10:46             ` Nicholas Piggin
2018-03-16 13:28             ` Michael Ellerman
2018-03-16 17:08             ` Linus Torvalds
2018-03-15 19:15       ` [PATCH RFC rebase 4/9] powerpc/64s: Use barrier_nospec in RFI_FLUSH_SLOT Michal Suchanek
2018-03-15 19:15       ` [PATCH RFC rebase 5/9] powerpc/64s: Add support for ori barrier_nospec patching Michal Suchanek
2018-03-15 19:15       ` [PATCH RFC rebase 6/9] powerpc/64: Patch barrier_nospec in modules Michal Suchanek
2018-03-15 19:15       ` [PATCH RFC rebase 7/9] powerpc/64: barrier_nospec: Add debugfs trigger Michal Suchanek
2018-03-15 19:15       ` [PATCH RFC rebase 8/9] powerpc/64s: barrier_nospec: Add hcall triggerr Michal Suchanek
2018-03-15 19:15       ` [PATCH RFC rebase 9/9] powerpc/64: barrier_nospec: Add commandline trigger Michal Suchanek
2018-03-23 15:59         ` Diana Madalina Craciun
2018-03-16  8:08       ` [PATCH RFC rebase 0/9] powerpc barrier_nospec Greg Kroah-Hartman
2018-03-16  9:31         ` Michal Suchánek
2018-03-13 18:33 ` [PATCH RFC 2/8] powerpc: Use barrier_nospec in copy_from_user Michal Suchanek
2018-03-13 18:33 ` [PATCH RFC 3/8] powerpc/64: Use barrier_nospec in syscall entry Michal Suchanek
2018-03-13 18:33 ` [PATCH RFC 4/8] powerpc/64s: Add support for ori barrier_nospec Michal Suchanek
2018-03-13 18:33 ` Michal Suchanek [this message]
2018-03-13 18:33 ` [PATCH RFC 6/8] powerpc/64: barrier_nospec: Add debugfs trigger Michal Suchanek
2018-03-13 18:33 ` [PATCH RFC 7/8] powerpc/64s: barrier_nospec: Add hcall triggerr Michal Suchanek
2018-03-13 18:33 ` [PATCH RFC 8/8] powerpc/64: barrier_nospec: Add commandline trigger Michal Suchanek

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=7a0d36c27c354f04c803ce5c4ef743e6f753b2d6.1520965380.git.msuchanek@suse.de \
    --to=msuchanek@suse.de \
    --cc=akpm@linux-foundation.org \
    --cc=andrew.donnellan@au1.ibm.com \
    --cc=benh@kernel.crashing.org \
    --cc=bryantly@linux.vnet.ibm.com \
    --cc=bsingharora@gmail.com \
    --cc=christophe.leroy@c-s.fr \
    --cc=clg@kaod.org \
    --cc=david@gibson.dropbear.id.au \
    --cc=dja@axtens.net \
    --cc=gregkh@linuxfoundation.org \
    --cc=joe@perches.com \
    --cc=kstewart@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=maddy@linux.vnet.ibm.com \
    --cc=mahesh@linux.vnet.ibm.com \
    --cc=me@tobin.cc \
    --cc=mhiramat@kernel.org \
    --cc=mikey@neuling.org \
    --cc=mpe@ellerman.id.au \
    --cc=naveen.n.rao@linux.vnet.ibm.com \
    --cc=npiggin@gmail.com \
    --cc=oohall@gmail.com \
    --cc=paulus@samba.org \
    --cc=peterz@infradead.org \
    --cc=pombredanne@nexb.com \
    --cc=ruscur@russell.cc \
    --cc=sergey.senozhatsky@gmail.com \
    --cc=viro@zeniv.linux.org.uk \
    /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).