From patchwork Fri Jul 12 05:28:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 11041513 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8151F138B for ; Fri, 12 Jul 2019 05:40:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6D27228BAD for ; Fri, 12 Jul 2019 05:40:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 612A528BBB; Fri, 12 Jul 2019 05:40:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 11DAF28BAD for ; Fri, 12 Jul 2019 05:40:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=bLSscBmNJRGAuE2Om45Yx19FF7uscGX3IETCW+Os4OY=; b=cmlxn5A0cmtyiZ atONe84f+4EeGGgK7Ilf0VBoty3wfo3oJIpdZwNyBnXbfInbgYkAHTb9wdAROyXwyvjDpNnGimq+x bErNH1RQgV/yZ/u5Z95j/N7Yejxo+2Z79r/XZ2j20hgLTBocj3v7+PuB8befVgN0XrY52L891Ig9F E9TryNnAsZfXuDYUduDnDTS6JBa4e36nBt2ixl78u7wWHn6xFXGxjSSGgFItvlsRNK1hgyWSEz11B meSnXBOZdQEhPWem1Cc0t6Irj6R4UrphI2vbFP9Na1R6wC43DMcxgBFK+l9qyo/69HwdjamQT24cc H89axSWLZyRPWiNpDU9A==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1hloHu-0000mB-Ca; Fri, 12 Jul 2019 05:40:06 +0000 Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1hlo8F-0001TT-G5 for linux-arm-kernel@lists.infradead.org; Fri, 12 Jul 2019 05:30:09 +0000 Received: by mail-pl1-x644.google.com with SMTP id y8so4190193plr.12 for ; Thu, 11 Jul 2019 22:30:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=7MRMdAKqkkU6zuM8WMZXIs4D8fug3sxafZUJy2Rr9SE=; b=hdQErRJG50LhllXMbuwbsA/8lrvNcZxpQqCGeAJBq56yYh3HaWRUDSGzQn2miXcBiI /TlBhgCC1WkHTcD40KOEjN2EDpb6jUNgkjaEA4DWazgx/EdYZy5PJ9sbGJAknfASxnGK qE3yhnWZQfXykkr81R7Tjuz9//PhJEJDhKF947CYY80uNlAxwfR9GfbN7m3Hf9SHZCn2 uEC40ee7iZMBBo1mIYZqCZx4Pc+U3uvrvxT62VUkpuDcVVy9kxIB/7M2Q2x5i8KHKNzN etpNyZz1UF1JdeaCRR84z6xMxcl0xlMeNanpZFQIsgTOvJmPJX8xAxP8YR6i+Zu4OnGT lBNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7MRMdAKqkkU6zuM8WMZXIs4D8fug3sxafZUJy2Rr9SE=; b=bCdgAlnxA8nPniCnoHPku5v+6vpY5JmQL9YFnAHOFyfUckagiRM6NqQMwngcL5MQJ1 goGjEwwZHIuS8LVRWSUy0GUMplqpKi1ml0tRd2LtBalXbv13KdWanquDVge/26jrgz// aJ/F6xe9yk0i+soWFLraFbjI5LUvif1ZM5mwDk2K6ugcdx/5CQB0ETO+gVZejKOlOM7M oRinbnHaxPHk1xa5rduRV5pgvuPFtWMGTbD22InXdrbk/1EGVQumcCaKvatoP+GPkriQ 4nLMcN8oQw/E03tL5PvUKmmP8HuzabiDq2U6Ppnxuk540xIy0ZKZtpXnpfluWgMi7NqE 3NtA== X-Gm-Message-State: APjAAAVcmG6wsE5Jj2sf59q3By4Xf1pATCb3ciFSJ4t7G2dj8u4EoQR2 v4U98F8OoWSFl9olBArFTJENUw== X-Google-Smtp-Source: APXvYqyS6Ew+8n/SMiTxYzwjHR7AMoLvDMKuezPrhjABfJGL2Mw1QTJ1wCqLX06dCzy/7jjUi6Jg0Q== X-Received: by 2002:a17:902:ba8e:: with SMTP id k14mr9155933pls.256.1562909406966; Thu, 11 Jul 2019 22:30:06 -0700 (PDT) Received: from localhost ([122.172.28.117]) by smtp.gmail.com with ESMTPSA id m11sm6618260pgk.65.2019.07.11.22.30.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Jul 2019 22:30:06 -0700 (PDT) From: Viresh Kumar To: stable@vger.kernel.org, Julien Thierry Subject: [PATCH v4.4 V2 25/43] arm64: Move BP hardening to check_and_switch_context Date: Fri, 12 Jul 2019 10:58:13 +0530 Message-Id: X-Mailer: git-send-email 2.21.0.rc0.269.g1a574e7a288b In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190711_223007_820907_D8F01BD8 X-CRM114-Status: GOOD ( 13.79 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Marc Zyngier , Viresh Kumar , Will Deacon , mark.brown@arm.com, Catalin Marinas , Russell King , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Marc Zyngier commit a8e4c0a919ae310944ed2c9ace11cf3ccd8a609b upstream. We call arm64_apply_bp_hardening() from post_ttbr_update_workaround, which has the unexpected consequence of being triggered on every exception return to userspace when ARM64_SW_TTBR0_PAN is selected, even if no context switch actually occured. This is a bit suboptimal, and it would be more logical to only invalidate the branch predictor when we actually switch to a different mm. In order to solve this, move the call to arm64_apply_bp_hardening() into check_and_switch_context(), where we're guaranteed to pick a different mm context. Acked-by: Will Deacon Signed-off-by: Marc Zyngier Signed-off-by: Catalin Marinas Signed-off-by: Viresh Kumar --- arch/arm64/mm/context.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/arm64/mm/context.c b/arch/arm64/mm/context.c index be42bd3dca5c..de5afc27b4e6 100644 --- a/arch/arm64/mm/context.c +++ b/arch/arm64/mm/context.c @@ -183,6 +183,8 @@ void check_and_switch_context(struct mm_struct *mm, unsigned int cpu) raw_spin_unlock_irqrestore(&cpu_asid_lock, flags); switch_mm_fastpath: + arm64_apply_bp_hardening(); + cpu_switch_mm(mm->pgd, mm); } @@ -193,8 +195,6 @@ asmlinkage void post_ttbr_update_workaround(void) "ic iallu; dsb nsh; isb", ARM64_WORKAROUND_CAVIUM_27456, CONFIG_CAVIUM_ERRATUM_27456)); - - arm64_apply_bp_hardening(); } static int asids_init(void)