From patchwork Mon Aug 2 21:53:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 12414855 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 80975C432BE for ; Mon, 2 Aug 2021 21:56:17 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 44C4260187 for ; Mon, 2 Aug 2021 21:56:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 44C4260187 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=soleen.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org 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:To:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=2MrSrnG8d2a7lCZFf3JPsoC+fkdR6t+gCSBwuGjlkLQ=; b=Z/Z7JEJDQ4NOxZ 22UAl9jZz4Gb+a7DpK6CGhgLBXxI/xlnGM8ppmgv0WSF6FAV9RWRv4fpZWJJwQLAGnzD/HagW+KB4 spUu59AVg1S6emsJjFd/+uEu/DG74A67kg/AIGV/r2pVb/2kaeghcTFJqWMhsJv1dYyCXpfrnmgz8 dkUtjmG35GohgFCc56chAlaMtR1Cn1se5A/ei1plyb43CYFGpWevmzoKg9Mc3CQZfTqsDBKpk0ZYD 3v7UwSVVs1QpEh8rTekySPyJn4GC3ZWBstvP7riY+2O+ZllBjUrwW2725xOQECqY3izoJXBIFdBTz YmQX3sJHCIqvt855S6oA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mAft3-000Jls-8J; Mon, 02 Aug 2021 21:54:17 +0000 Received: from mail-qk1-x731.google.com ([2607:f8b0:4864:20::731]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mAfsz-000JjP-SL for linux-arm-kernel@lists.infradead.org; Mon, 02 Aug 2021 21:54:15 +0000 Received: by mail-qk1-x731.google.com with SMTP id 129so18126610qkg.4 for ; Mon, 02 Aug 2021 14:54:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=gpKUHaMAwkHB+q+UElCl69jZKnxiURz6Ucy0xkR2ELY=; b=mmGBEfnF9oZBlRuZblnuO8IgGciEd2V3OTlp4jdC//Y9f0WVpenL/OBOeVgveoRMwK wGT90RC7SKYswp9xlxMNjNoEZxUXiYv1oApAYHpcxpWe8tf6N4lQTVgE2Rl8MF1Jhwak IwElBw5j6ZSZWrGaDF64dNenVk8adI9vzpmEdI1vCNgmblGrXwAif7ZQ8wWR87WigxCn MN3qDKfl2RADG4h1zeg2WiGTzf7ZyIXlFU6DWq3NQO/zuQkkRfp581JDmFTlPmXrnmFP zxFEB75mCaToQgA6HJeeqdFJTs3x8N1jTVfZxqyMvfo/U22dsK/mdxKjhxQpuWjj5f6V Sjvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=gpKUHaMAwkHB+q+UElCl69jZKnxiURz6Ucy0xkR2ELY=; b=hqS0pXEEU+vOFzEKfQBLklzmp+0dhtDvIJuHwWlTRo0ahBWo+fjw8RgQ6pw8VEruoB IVQZGBRCzoMhccN7simWcCmkdwCXGllep5nhfwqkAyXCRq2Q9KCTpgxPbR6oAZK5jWOc l4KRtMwJnlN8Qyo85lWrvaEzc1IlTnmVX4h03zDhfF5CMCsh7FYZQpgg57vfKwK8OIoG K2nN4C7hyJQCNPP0Z6q7So/1Q7iaOSQcN4nfhRN59kwP3yu4IdbFrMdBX/lY9tNvr3Nu TVzI1YhX7ZAcasrjuxPksRaVpGm02gX+EEzqu2EBEYGRzw1E16jnoJet1FXPXl7rX/k2 eYsQ== X-Gm-Message-State: AOAM532hL7g6m9XNlwyZooH35v0sIMdPPAJjG01quWnRR0xP8w2xUeLH 7DSutsynJobqPNEdi3XLvwJ9Ww== X-Google-Smtp-Source: ABdhPJxUfhb3Dku9KW46dPB118JL9YX+skltVkhp7xJNLax/VRpKXlKrybwlyB5FLGyYAGhSLrA6sQ== X-Received: by 2002:a37:a058:: with SMTP id j85mr12147273qke.471.1627941252530; Mon, 02 Aug 2021 14:54:12 -0700 (PDT) Received: from localhost.localdomain (c-73-69-118-222.hsd1.nh.comcast.net. [73.69.118.222]) by smtp.gmail.com with ESMTPSA id v11sm5479216qtc.0.2021.08.02.14.54.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Aug 2021 14:54:12 -0700 (PDT) From: Pavel Tatashin To: pasha.tatashin@soleen.com, jmorris@namei.org, sashal@kernel.org, ebiederm@xmission.com, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, corbet@lwn.net, catalin.marinas@arm.com, will@kernel.org, linux-arm-kernel@lists.infradead.org, maz@kernel.org, james.morse@arm.com, vladimir.murzin@arm.com, matthias.bgg@gmail.com, linux-mm@kvack.org, mark.rutland@arm.com, steve.capper@arm.com, rfontana@redhat.com, tglx@linutronix.de, selindag@gmail.com, tyhicks@linux.microsoft.com, kernelfans@gmail.com, akpm@linux-foundation.org, madvenka@linux.microsoft.com Subject: [PATCH v16 01/15] arm64: kernel: add helper for booted at EL2 and not VHE Date: Mon, 2 Aug 2021 17:53:54 -0400 Message-Id: <20210802215408.804942-2-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210802215408.804942-1-pasha.tatashin@soleen.com> References: <20210802215408.804942-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210802_145413_969292_B1154E19 X-CRM114-Status: GOOD ( 15.85 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Replace places that contain logic like this: is_hyp_mode_available() && !is_kernel_in_hyp_mode() With a dedicated boolean function is_hyp_nvhe(). This will be needed later in kexec in order to sooner switch back to EL2. Suggested-by: James Morse Signed-off-by: Pavel Tatashin --- arch/arm64/include/asm/virt.h | 5 +++++ arch/arm64/kernel/cpu-reset.h | 3 +-- arch/arm64/kernel/hibernate.c | 2 +- arch/arm64/kernel/sdei.c | 2 +- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/arch/arm64/include/asm/virt.h b/arch/arm64/include/asm/virt.h index 7379f35ae2c6..a9457e96203c 100644 --- a/arch/arm64/include/asm/virt.h +++ b/arch/arm64/include/asm/virt.h @@ -128,6 +128,11 @@ static __always_inline bool is_protected_kvm_enabled(void) return cpus_have_final_cap(ARM64_KVM_PROTECTED_MODE); } +static inline bool is_hyp_nvhe(void) +{ + return is_hyp_mode_available() && !is_kernel_in_hyp_mode(); +} + #endif /* __ASSEMBLY__ */ #endif /* ! __ASM__VIRT_H */ diff --git a/arch/arm64/kernel/cpu-reset.h b/arch/arm64/kernel/cpu-reset.h index 9a7b1262ef17..81b3d0fe7a63 100644 --- a/arch/arm64/kernel/cpu-reset.h +++ b/arch/arm64/kernel/cpu-reset.h @@ -20,8 +20,7 @@ static inline void __noreturn __nocfi cpu_soft_restart(unsigned long entry, { typeof(__cpu_soft_restart) *restart; - unsigned long el2_switch = !is_kernel_in_hyp_mode() && - is_hyp_mode_available(); + unsigned long el2_switch = is_hyp_nvhe(); restart = (void *)__pa_symbol(function_nocfi(__cpu_soft_restart)); cpu_install_idmap(); diff --git a/arch/arm64/kernel/hibernate.c b/arch/arm64/kernel/hibernate.c index 46a0b4d6e251..4c9533f4c0c4 100644 --- a/arch/arm64/kernel/hibernate.c +++ b/arch/arm64/kernel/hibernate.c @@ -49,7 +49,7 @@ extern int in_suspend; /* Do we need to reset el2? */ -#define el2_reset_needed() (is_hyp_mode_available() && !is_kernel_in_hyp_mode()) +#define el2_reset_needed() (is_hyp_nvhe()) /* temporary el2 vectors in the __hibernate_exit_text section. */ extern char hibernate_el2_vectors[]; diff --git a/arch/arm64/kernel/sdei.c b/arch/arm64/kernel/sdei.c index 47f77d1234cb..d20620a1c51a 100644 --- a/arch/arm64/kernel/sdei.c +++ b/arch/arm64/kernel/sdei.c @@ -202,7 +202,7 @@ unsigned long sdei_arch_get_entry_point(int conduit) * dropped to EL1 because we don't support VHE, then we can't support * SDEI. */ - if (is_hyp_mode_available() && !is_kernel_in_hyp_mode()) { + if (is_hyp_nvhe()) { pr_err("Not supported on this hardware/boot configuration\n"); goto out_err; }