Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2445230yba; Mon, 15 Apr 2019 11:47:05 -0700 (PDT) X-Google-Smtp-Source: APXvYqywRjoWaSWUYW+3Pw258zF80Dst3cbgACPgObhsm7Xop3B8DITbT6jnQW3qXYOksR6vCfif X-Received: by 2002:a17:902:ab87:: with SMTP id f7mr76790187plr.85.1555354025250; Mon, 15 Apr 2019 11:47:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555354025; cv=none; d=google.com; s=arc-20160816; b=AUtmL9D7iykqZLCNxncDoqWuZ0WhvIfW72zyYryRsUG9bSqWlVUjLhP8gDSR09cEVH r55CPI5wPKXq3O2P9SpqE20C3FXXpOb9qsSgPghZcft/zsQXTY9SbtMy2P+awapcQBb8 mRnX+WVC9AnYO4PfH+DG1ZZZWNnDdMbDPmbUM+LL7+YwJvFXFDk9my+cOmt+7HrGDlxG f01yaK8STjS16MiIlvPUx4yMgvuCd21PaYTGDqYDyJw8A2H3lY08gDgW5XjSLKWB+k+u TcYxj8cGv2uxuWqUNE7/KEdjemzuRzCCkoEdeOZjXC4YVfHnvqRbgb0kMnRh3BPKR6OG NT4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=LZmUUZPWLSq3M5RBpeH1u5zzGvkvIJ4s0+Da3c3pLqM=; b=LXkKxxHTxBXVBB4zcUMM0fzMHlx8fVmfWRy/xvh0w2hpCbtP2XPjkyceAmFkKSvcXL hfQ9eMqzjw75jZo6MsUUYL7ag0x0bOP129Wt+2U4gQCAWebRHYJYrJGAtGrEpPiX2YXt B+sXYzFrL0kijpy/YwefPne6EHOELUMB8f8RPrOPlxvdMcucplrnIPlY1tfP6IYQ0Obt 4WRX4kHIU1539agFXNfsVYTuVcFV0573nHnwyGJf4GPGbJVgWhS+VEarvR8A3prqI/ab mUIVrN2QLa1m0iYHT+MplWV8agPyweluEZsyEr/WdGqriNGnFCO8mdItNToyys3Xhboq EgbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=amePdFoe; 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 12si37694891pgn.67.2019.04.15.11.46.48; Mon, 15 Apr 2019 11:47:05 -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; dkim=pass header.i=@kernel.org header.s=default header.b=amePdFoe; 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 S1728468AbfDOSpv (ORCPT + 99 others); Mon, 15 Apr 2019 14:45:51 -0400 Received: from mail.kernel.org ([198.145.29.99]:48292 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728434AbfDOSpt (ORCPT ); Mon, 15 Apr 2019 14:45:49 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 77D252073F; Mon, 15 Apr 2019 18:45:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1555353947; bh=qWgxOea/jLjWItresIwWBw4qcKRAn6ZBypqyWesMsmk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=amePdFoeEoC2PEMouGUEVrSsqavI2Yg1s/ZebEELSx6P/oyrL3VLp6I7/eJjkxYC5 sB8T0DfFyfM2pEg8IuUzgydKQtv5AUsvQY3MHAKwA5HDH+j4dA3I32SNp96v18YsIg fu50+tvX7pwyizsFa8Tputz/oHOKbYHgx5fSsw+g= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Michael Ellerman , Sasha Levin Subject: [PATCH 4.9 15/76] powerpc/64s: Enable barrier_nospec based on firmware settings Date: Mon, 15 Apr 2019 20:43:39 +0200 Message-Id: <20190415183711.923938651@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190415183707.712011689@linuxfoundation.org> References: <20190415183707.712011689@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org commit cb3d6759a93c6d0aea1c10deb6d00e111c29c19c upstream. Check what firmware told us and enable/disable the barrier_nospec as appropriate. We err on the side of enabling the barrier, as it's no-op on older systems, see the comment for more detail. Signed-off-by: Michael Ellerman Signed-off-by: Sasha Levin --- arch/powerpc/include/asm/setup.h | 1 + arch/powerpc/kernel/security.c | 60 ++++++++++++++++++++++++++ arch/powerpc/platforms/powernv/setup.c | 1 + arch/powerpc/platforms/pseries/setup.c | 1 + 4 files changed, 63 insertions(+) diff --git a/arch/powerpc/include/asm/setup.h b/arch/powerpc/include/asm/setup.h index a225b5c42e76..84ae150ce6a6 100644 --- a/arch/powerpc/include/asm/setup.h +++ b/arch/powerpc/include/asm/setup.h @@ -51,6 +51,7 @@ enum l1d_flush_type { void setup_rfi_flush(enum l1d_flush_type, bool enable); void do_rfi_flush_fixups(enum l1d_flush_type types); +void setup_barrier_nospec(void); void do_barrier_nospec_fixups(bool enable); extern bool barrier_nospec_enabled; diff --git a/arch/powerpc/kernel/security.c b/arch/powerpc/kernel/security.c index 34d436fe2498..d0e974da4918 100644 --- a/arch/powerpc/kernel/security.c +++ b/arch/powerpc/kernel/security.c @@ -9,6 +9,7 @@ #include #include +#include #include #include @@ -23,6 +24,65 @@ static void enable_barrier_nospec(bool enable) do_barrier_nospec_fixups(enable); } +void setup_barrier_nospec(void) +{ + bool enable; + + /* + * It would make sense to check SEC_FTR_SPEC_BAR_ORI31 below as well. + * But there's a good reason not to. The two flags we check below are + * both are enabled by default in the kernel, so if the hcall is not + * functional they will be enabled. + * On a system where the host firmware has been updated (so the ori + * functions as a barrier), but on which the hypervisor (KVM/Qemu) has + * not been updated, we would like to enable the barrier. Dropping the + * check for SEC_FTR_SPEC_BAR_ORI31 achieves that. The only downside is + * we potentially enable the barrier on systems where the host firmware + * is not updated, but that's harmless as it's a no-op. + */ + enable = security_ftr_enabled(SEC_FTR_FAVOUR_SECURITY) && + security_ftr_enabled(SEC_FTR_BNDS_CHK_SPEC_BAR); + + enable_barrier_nospec(enable); +} + +#ifdef CONFIG_DEBUG_FS +static int barrier_nospec_set(void *data, u64 val) +{ + switch (val) { + case 0: + case 1: + break; + default: + return -EINVAL; + } + + if (!!val == !!barrier_nospec_enabled) + return 0; + + enable_barrier_nospec(!!val); + + return 0; +} + +static int barrier_nospec_get(void *data, u64 *val) +{ + *val = barrier_nospec_enabled ? 1 : 0; + return 0; +} + +DEFINE_SIMPLE_ATTRIBUTE(fops_barrier_nospec, + barrier_nospec_get, barrier_nospec_set, "%llu\n"); + +static __init int barrier_nospec_debugfs_init(void) +{ + debugfs_create_file("barrier_nospec", 0600, powerpc_debugfs_root, NULL, + &fops_barrier_nospec); + return 0; +} +device_initcall(barrier_nospec_debugfs_init); +#endif /* CONFIG_DEBUG_FS */ + ssize_t cpu_show_meltdown(struct device *dev, struct device_attribute *attr, char *buf) { bool thread_priv; diff --git a/arch/powerpc/platforms/powernv/setup.c b/arch/powerpc/platforms/powernv/setup.c index 17203abf38e8..eb5464648810 100644 --- a/arch/powerpc/platforms/powernv/setup.c +++ b/arch/powerpc/platforms/powernv/setup.c @@ -123,6 +123,7 @@ static void pnv_setup_rfi_flush(void) security_ftr_enabled(SEC_FTR_L1D_FLUSH_HV)); setup_rfi_flush(type, enable); + setup_barrier_nospec(); } static void __init pnv_setup_arch(void) diff --git a/arch/powerpc/platforms/pseries/setup.c b/arch/powerpc/platforms/pseries/setup.c index 91ade7755823..2b2759c98c7e 100644 --- a/arch/powerpc/platforms/pseries/setup.c +++ b/arch/powerpc/platforms/pseries/setup.c @@ -525,6 +525,7 @@ void pseries_setup_rfi_flush(void) security_ftr_enabled(SEC_FTR_L1D_FLUSH_PR); setup_rfi_flush(types, enable); + setup_barrier_nospec(); } static void __init pSeries_setup_arch(void) -- 2.19.1