From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 61E06C433FE for ; Wed, 23 Nov 2022 18:09:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=g3tqVL4gV+XuZXYpON91pY6XUFOPjNZ+fXAFiKUNnDs=; b=pKRX0QxBF6JAVv VztoPkkTM1bfiOltzP/id6OvL8QTtJSZUB/rWCCQm4eaQfGqFri6Nqc6ytjxV4fwI0L3Ge/9VwG6e tM6YZCIfBgwPL2kkgjERTfKWkduHH1k3piVn6W1TP5sPTRQ4ssLnv2Vi8lnxO0bOTjtHfUVN9QVK6 G/h/sNqlvaU+ao6PCzdL3xzPdo18ZTHodiUuxxDFLjJffmvEx1uPBOOs+tuUJp3/Ul7BGfJlkEi+j foPD1czVxt6nKd7Mlr2tlc1Js08xNmMbpsEKWMC/lVzCXG1MK580IZ28LDnzc9Pc0OduKBI7T0SpX 5UF0ijjIwxJjAGQz+tww==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oxu9y-001QrI-Ul; Wed, 23 Nov 2022 18:07:47 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oxu5Q-001OU9-2X for linux-arm-kernel@lists.infradead.org; Wed, 23 Nov 2022 18:03:05 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 9BD7661E5B; Wed, 23 Nov 2022 18:03:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A2E6EC4347C; Wed, 23 Nov 2022 18:03:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1669226583; bh=/06c1AFm9siBdxdxi3Oz+BqxrOQoh3mbA1h3KtX2Muk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ckdJkB3lT+/Jdyck04NGTOYK4W3ujG4iysnnK14h5VsN3Y6kghuICByAayzrrEutU ZbbWvh0Rq0769kOeB9Y+LdbCZxj6FUVGxE1IeWrDpAFmV0lbNTH5Be30xBfLg6tUZ7 hWMsd3bSjz56paB54qflixJoz5/e0ndA/rCnmaaYpnjKWoMnD+1Jg70n75Nqk7hPHm 3kdnP/HVIkMzm9zoMOMMmJjGOsiY721WbL3fXd8NFIGXcLD89RwXxZfPT38juboX2F EGuCGiSQxERA/QJ5WTwcryM57j7sVLYD6SF6mk/7T2/Ecw4HPUWnqXY3BhNqkJSNqg OB24XO67HmLtA== From: Mark Brown To: Catalin Marinas , Will Deacon Cc: Mark Rutland , Ard Biesheuvel , linux-arm-kernel@lists.infradead.org, Mark Brown Subject: [PATCH v1 1/2] arm64/kpti: Move DAIF masking to C code Date: Wed, 23 Nov 2022 18:02:08 +0000 Message-Id: <20221123180209.634650-2-broonie@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221123180209.634650-1-broonie@kernel.org> References: <20221123180209.634650-1-broonie@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2610; i=broonie@kernel.org; h=from:subject; bh=/06c1AFm9siBdxdxi3Oz+BqxrOQoh3mbA1h3KtX2Muk=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBjfmAfBIT+Nmjwj/8T8rCPZQV4KF3S70x2lUbr8RH2 3ibiF8SJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCY35gHwAKCRAk1otyXVSH0GqJB/ 0bl6eJ6cZEfBzB0/05VJdSSp44u/kbXr4K5nypdxiOCKX3fBVKiz2r7aqGhPXCj5uIQB8VqxVy2Svz jeQIDGpRSF6T7Mg//1kJfhjB5uI74264CTWKT2MKY9PO1xPJQ7ARGdnwA0V87KwNi9tzdA+AoemSZK kQY9c/9M4qtkSGa6bb5twA9PZhcKHWcN8/pYcxermCLOE0xPt0Z49fp34pw97pF/RUrT1VHFmrJEEZ xqh9bMJsxWJWOKxwX/Ah9qSMP+i9XKv+TDyyORXnE41Aq3z3Kiatf9RgOW+gkT5b148iseExqpfJER Jd56bNTAHqCKzlngnFoHDqzn54vDQL X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221123_100304_239042_A19A3592 X-CRM114-Status: GOOD ( 18.16 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org We really don't want to take an exception while replacing TTBR1 so we mask DAIF during the actual update. Currently this is done in the assembly function idmap_cpu_replace_ttbr1() but it could equally be done in the only caller of that function, cpu_replace_ttbr1(). This simplifies the assembly code slightly and means that when working with the code around masking DAIF flags there is one less piece of assembly code which needs to be considered. While we're at it add a comment which makes explicit why we are masking DAIF in this code. There should be no functional effect. Signed-off-by: Mark Brown --- arch/arm64/include/asm/mmu_context.h | 10 ++++++++++ arch/arm64/mm/proc.S | 4 ---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/arch/arm64/include/asm/mmu_context.h b/arch/arm64/include/asm/mmu_context.h index d3f8b5df0c1f..72dbd6400549 100644 --- a/arch/arm64/include/asm/mmu_context.h +++ b/arch/arm64/include/asm/mmu_context.h @@ -18,6 +18,7 @@ #include #include +#include #include #include #include @@ -152,6 +153,7 @@ static inline void cpu_replace_ttbr1(pgd_t *pgdp, pgd_t *idmap) typedef void (ttbr_replace_func)(phys_addr_t); extern ttbr_replace_func idmap_cpu_replace_ttbr1; ttbr_replace_func *replace_phys; + unsigned long daif; /* phys_to_ttbr() zeros lower 2 bits of ttbr with 52-bit PA */ phys_addr_t ttbr1 = phys_to_ttbr(virt_to_phys(pgdp)); @@ -171,7 +173,15 @@ static inline void cpu_replace_ttbr1(pgd_t *pgdp, pgd_t *idmap) replace_phys = (void *)__pa_symbol(idmap_cpu_replace_ttbr1); __cpu_install_idmap(idmap); + + /* + * We really don't want to take *any* exceptions while TTBR1 is + * in the process of being replaced so mask everything. + */ + daif = local_daif_save(); replace_phys(ttbr1); + local_daif_restore(daif); + cpu_uninstall_idmap(); } diff --git a/arch/arm64/mm/proc.S b/arch/arm64/mm/proc.S index b9ecbbae1e1a..066fa60b93d2 100644 --- a/arch/arm64/mm/proc.S +++ b/arch/arm64/mm/proc.S @@ -189,16 +189,12 @@ SYM_FUNC_END(cpu_do_resume) * called by anything else. It can only be executed from a TTBR0 mapping. */ SYM_TYPED_FUNC_START(idmap_cpu_replace_ttbr1) - save_and_disable_daif flags=x2 - __idmap_cpu_set_reserved_ttbr1 x1, x3 offset_ttbr1 x0, x3 msr ttbr1_el1, x0 isb - restore_daif x2 - ret SYM_FUNC_END(idmap_cpu_replace_ttbr1) .popsection -- 2.30.2 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel