From patchwork Thu Mar 1 12:54:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Shi X-Patchwork-Id: 10251371 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7CCF9602B5 for ; Thu, 1 Mar 2018 13:26:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6B45A1FFFF for ; Thu, 1 Mar 2018 13:26:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 601E82015F; Thu, 1 Mar 2018 13:26:47 +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=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID 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 BBA271FFFF for ; Thu, 1 Mar 2018 13:26:45 +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:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: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=0iaEi18lYgoIV77sVjIjgTu/Doubw+r8TCl9oHOxAFU=; b=JKR00iq+8aH4O8z6dRvdh+Kl9+ rxvD3YDEazCy3WVd1mk/h8YdZQ2KDr8gx9KmQBPk7M7Mt9Vh/85ggDDxaBY2Nx2YqQWtQvNQW2ckH dfOCw+/nzDuEw8CYlrGZZDbgo2vp6y8Tf+C21G++jnwYd9ahT31C496OlcvUrB9ydOLP+Dw2dTFnB BUVylvqnr/pLLYE100xgajtyG8iSm2oLmB7C4a5dVysNKb2eRhQIZcA+21njTrqs+Rzm+9M5eWrHL 8JwpAozScc0p0jic4L5UxLkKfPqJXdASyuu2uRcfOVo4BLViMnoz3eAr5VxzLRKKqXDbFVnIO90W3 9YwtN+zg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1erOEM-00006Z-5n; Thu, 01 Mar 2018 13:26:42 +0000 Received: from mail-pl0-x244.google.com ([2607:f8b0:400e:c01::244]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1erNnV-0002qI-Jy for linux-arm-kernel@lists.infradead.org; Thu, 01 Mar 2018 13:00:40 +0000 Received: by mail-pl0-x244.google.com with SMTP id v9-v6so3581855plp.12 for ; Thu, 01 Mar 2018 04:58:47 -0800 (PST) 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; bh=YTi+3EgVxwTxApY3ucUH/g1LD9enZczbL8ouc6EbVOA=; b=YOD8Yuf8Eht7WwsO2JikzfyCrD/zUq3mDMabSjHjiBmlZ7LEMeNgKyqNYRMTppc499 AKj8idWMxjeL7qN6Oo9fxNE8q7JAJdy0toCtrOanbS47W/vuAcgTaf9VCKVL27przxMd QeVDBxPnK9PsrR3SzNx+ME1pZBJfYGjrS1q+Q= 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; bh=YTi+3EgVxwTxApY3ucUH/g1LD9enZczbL8ouc6EbVOA=; b=f83AXja6z3F4C72hO71LtKiUOznkMMHHJPMCuI7xgjUlap0s+RZ0glLLDO4wEVuiaj lFl85YAhqg7SDW1Sic3r20ATDo/w98ifM+Ocvicyoia7FvFQv04fYvCFCmf/THBSm3yv nKnHPbqzPMLCO+5A5DQRLNvtq6On7keXYsqpirr/ZHjVR+w8kLfITHislzvcOWsM5mqX HW9cTf26SEe914vtP5GCS8UTC7V6auWgZPTnDch9IFVhNBAAy0Pdx3DBU0t7c1G1HISh fZR/LqV0bc+BpxGY7afE1IkKkgpQy4SJMilUaI4BxHG1clqYL2XKkaLLqDhEHLej54Dz JVmA== X-Gm-Message-State: APf1xPDK+koQTxQs0gFSo0FxYxm49DxkMjiE6eN3yVL3CFg4id+RKRXA yOwU18JxgGcTct3vnENaQ/T68iOuIN8= X-Google-Smtp-Source: AG47ELsgvdv889GZkRoNxZhwuaugUaeNlR/+ZYs+1tsQN/dRTsgOlj11aoYXW33+9LPDHxvvvjgbgw== X-Received: by 2002:a17:902:f44:: with SMTP id 62-v6mr1819010ply.27.1519909126862; Thu, 01 Mar 2018 04:58:46 -0800 (PST) Received: from localhost.localdomain (176.122.172.82.16clouds.com. [176.122.172.82]) by smtp.gmail.com with ESMTPSA id x4sm2289655pfb.46.2018.03.01.04.58.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 01 Mar 2018 04:58:46 -0800 (PST) From: Alex Shi To: Marc Zyngier , Will Deacon , Ard Biesheuvel , Catalin Marinas , stable@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 24/45] arm64: Move BP hardening to check_and_switch_context Date: Thu, 1 Mar 2018 20:54:01 +0800 Message-Id: <1519908862-11425-25-git-send-email-alex.shi@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1519908862-11425-1-git-send-email-alex.shi@linaro.org> References: <1519908862-11425-1-git-send-email-alex.shi@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180301_045858_269075_D0F15592 X-CRM114-Status: GOOD ( 14.16 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alex Shi MIME-Version: 1.0 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 a8e4c0a919ae 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: Will Deacon Signed-off-by: Alex Shi --- arch/arm64/mm/context.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/arch/arm64/mm/context.c b/arch/arm64/mm/context.c index afc9266..36416e4 100644 --- a/arch/arm64/mm/context.c +++ b/arch/arm64/mm/context.c @@ -221,6 +221,7 @@ 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); } @@ -231,8 +232,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)