Received: by 10.213.65.68 with SMTP id h4csp519257imn; Tue, 13 Mar 2018 11:37:09 -0700 (PDT) X-Google-Smtp-Source: AG47ELvXvJafKIz6GK0lYVPlXee3Yqz6ZuV21/3YfwX+yrnZb19CdMQG6jT8lOmNUBT0raVMqhx/ X-Received: by 2002:a17:902:604f:: with SMTP id a15-v6mr1280521plt.184.1520966229205; Tue, 13 Mar 2018 11:37:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1520966229; cv=none; d=google.com; s=arc-20160816; b=c+zfP/yjjRrjCtDmo6Pbu0ZruIQLTTfzGbXV5BLngYLon7pH7AoZaMoq2jZxdzLD+5 pBE7fohjbl8Xm6Y7+/CQHKmrauylVLjZ+xGBsxTtGt3mHp7VmdUC1RJKT37cJHmyVewv tp0TgejAwLbMK5iERj1E+FpLl1dqQsEh9F6QitpLTaTZGl4fXhPTIML10VsiSzdiVu4s mTH46TwwioDB67a12p76hgFOltmTI4ym8ffcv37TcTw0SR0dJSyi44xVoX4y10fbYo+x EnuLiYGiGHHkTxK4Qy+Kr4KXUppn0YFYHtdiMZODLio8hlL+MFoirnpfWvwrOU+dpg6y itsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=hlOmhYEnn0thJYdWyf2xLM+Uy7Trxi7BtC+lufyHbP8=; b=MmlwBObDIRPJB/d41gxd3foISYB7PcJaaKJN5iaKYuCjaFbOC+CLMJ3Z2jZ7fo6f8Y j9d9oUJWB6FFJwfvaSGUGkRwRYq2Zayg7M4FkLUlFYhr54qQ7tjghxXZ6n4Ku/0KCE/e 5ZLLAiSC6GkIhOp1CSfyK1W3Hj532hqDRM/q6gi/SYUAHC4q29+PXLfugPih5w+CX44Y y4gH3XtfTWtruviTm3DrcZC5I4EnGWhIJYNqoYP1YJJiQydKHuXFfSbJGWwfAPXePdE0 Z22YcAegk51ll0vqwRkaaK1IXBwiCUz0NjOp1MbEAsFOZNn+h8l/quFRkFNsZJYfyF03 YIcw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s3si564343pfi.32.2018.03.13.11.36.54; Tue, 13 Mar 2018 11:37:09 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752704AbeCMSfA (ORCPT + 99 others); Tue, 13 Mar 2018 14:35:00 -0400 Received: from mx2.suse.de ([195.135.220.15]:53527 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752522AbeCMSdy (ORCPT ); Tue, 13 Mar 2018 14:33:54 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 0B03EAF56; Tue, 13 Mar 2018 18:33:53 +0000 (UTC) From: Michal Suchanek To: linuxppc-dev@lists.ozlabs.org Cc: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , Peter Zijlstra , Michal Suchanek , Kate Stewart , Greg Kroah-Hartman , Philippe Ombredanne , Nicholas Piggin , "Tobin C. Harding" , Mahesh Salgaonkar , David Gibson , Al Viro , Michael Neuling , "Oliver O'Halloran" , "Naveen N. Rao" , Madhavan Srinivasan , Masami Hiramatsu , Andrew Morton , Balbir Singh , Sergey Senozhatsky , Christophe Leroy , Andrew Donnellan , Daniel Axtens , Russell Currey , Joe Perches , "Bryant G. Ly" , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , 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 Message-Id: <7a0d36c27c354f04c803ce5c4ef743e6f753b2d6.1520965380.git.msuchanek@suse.de> X-Mailer: git-send-email 2.13.6 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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