From patchwork Wed Mar 3 00:22:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 12114005 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=-16.8 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 91530C433E0 for ; Wed, 3 Mar 2021 18:11:33 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (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 09B8664E6F for ; Wed, 3 Mar 2021 18:11:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 09B8664E6F Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=soleen.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; 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=RHC26DOCaEh0UGZGzsmH+fP0EsSVIBH3J7+XFneg7Oc=; b=K6+acTAq+KPAgqGCQoaeXvODy 8dLhkDmlE5Cn98scLfIcmCNAI2dJklFEGITtBHAZf5zaPxzMZAcvDRNPqrFyA9gzAjYVes5I2KDcr QQeMIyxASR+zRWKGWCFlW41EgbE3GkVm5yMcr2gL+thFXU/s4MPze+DCi5568TWneRUNlJHfhr92v jX5Tqo2qrbiydnyiPTBRR+CRP6s+sEH3RhjzDu4TBl/1FTR2AA6Bg/7uAEKN0Mg2kFOXKKJtzzEsK c0SpLfhBE8KwxcyZjBws3WbgrSyK0aMEq4sMPTEYp/+rXrcA+8FqPWbQWJzowdMgtC6+hRP4oWJFX KUVR7mzWQ==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lHVva-005xFx-M7; Wed, 03 Mar 2021 18:08:56 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lHSyo-005GVM-1O for linux-arm-kernel@desiato.infradead.org; Wed, 03 Mar 2021 15:00:02 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:To:From:Sender:Reply-To:Cc: Content-Type:Content-ID:Content-Description; bh=t5r+nQTDiOBjAcARZmxYD2C/XCnn3pF+1dbE/Rdt76g=; b=uEJddvtEUaHs7HHMGU75TsmDko YBQM+Bl4Vf4xJ9K4CgLiQ9S8SF8+ZqiCwFas2l0JHoEV7IPQsNRg+jTtW2r8QSFEgTPYGEjVl3+3A UEGY7s21CLD0RfhNOJf6oQQyjGyOA3wlj4zD2/x9bFpZJe5fTPAp/bjzUPhtom3bXMqISn8e9NGj/ oglXYuy7n5YKyHbjYNhfb7McsCXTC/ejPlTMZ5VFgeFvgWft1hTX0CHmef8gFmTEDF6k0zmwGbk9d WOgQtN0geCB8UOFk2kWJ0a4pTUOASi9IxJ2n/+cqsDmbaYd1MDB0viHRG1J63Vc4qESdOvah/22L9 /zp9AeFA==; Received: from mail-qt1-x836.google.com ([2607:f8b0:4864:20::836]) by casper.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lHFIm-000jc1-Fs for linux-arm-kernel@lists.infradead.org; Wed, 03 Mar 2021 00:23:46 +0000 Received: by mail-qt1-x836.google.com with SMTP id s15so16291321qtq.0 for ; Tue, 02 Mar 2021 16:23:40 -0800 (PST) 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=t5r+nQTDiOBjAcARZmxYD2C/XCnn3pF+1dbE/Rdt76g=; b=SwKTL4eCvkIvgxU6lGAV//PLN7/clkFuLLU3DXUzK1tQP8M45hnpri8l5cR3f1+Ylp sMpfdEfEz+Et5fTiJRblDRcFcdDME1BtQOImc3LBxmY2ee/EnHXeyesUtIl0vD64exx+ VcRzv+DTWT/hDHKT9/XTJeTMiBflR4d/CWf1PPm9mvSFV7yUEEIVgbmppDsdR6CWOocz V0blw/3FCGwiuLgjQvSQ/B5NmZjurWUX6kzX83Lt5n0pSVAHFZPPAh+CUnOKE143JiH9 EaWCHQ+48dXFnyzY6WGGo0svwQnyOB1kX9/+fl90p2Ln1YIFMmaJnFRL2kdEe5kov6l2 jBiQ== 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=t5r+nQTDiOBjAcARZmxYD2C/XCnn3pF+1dbE/Rdt76g=; b=NBK4EF89GX0aTvGpkYq7ZMZ0thG+vbCaAP++hPjmoZP61RBWDPD8h27R2ptlak49u7 uREpLGB3VEr/1fR85bH1nEGmam/D+v6FiZvuz+57+ie6w3Pdg3TEKDMiQ6ZdHUyZYi/9 a9/RU2xHgksc4A0B6p51OuSVZaMRBqKYrH/kiFi+5ihaEyy5vxl60jpGuovh1q91fN8D FResCEtAT70Z9VYMa0k5/0enK9X2dCx+BzQR4amL0BtBsal4SBKDaNWJTPr5B/t9Iq9t +IGcb9WxCDiA31v7GdPRImeIotMvXKoxi22o2pFQ5cHn3Xu8D1LCezEGsTfAUFHmORxw 1GZA== X-Gm-Message-State: AOAM530+3DzXVrIt5cbwvmVEOw6IRj2w8wYOGNNbH/f3RBRqwW3wKlFy yJr3zJPbdzQliBkwWxU9T/GpoA== X-Google-Smtp-Source: ABdhPJzO9otEd6iJTRYqtDhi+XwWHgyDvgnqwPpNWgOkK7byt0RQkwHr9BNXQF6YdGG3LDA/I4eZOQ== X-Received: by 2002:ac8:d44:: with SMTP id r4mr19942609qti.7.1614730958326; Tue, 02 Mar 2021 16:22:38 -0800 (PST) Received: from localhost.localdomain (c-73-69-118-222.hsd1.nh.comcast.net. [73.69.118.222]) by smtp.gmail.com with ESMTPSA id r3sm16690512qkm.129.2021.03.02.16.22.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Mar 2021 16:22:37 -0800 (PST) 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 Subject: [PATCH v12 04/17] arm64: kernel: add helper for booted at EL2 and not VHE Date: Tue, 2 Mar 2021 19:22:17 -0500 Message-Id: <20210303002230.1083176-5-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210303002230.1083176-1-pasha.tatashin@soleen.com> References: <20210303002230.1083176-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-20210303_002345_949968_57A511A4 X-CRM114-Status: GOOD ( 15.17 ) 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_callable(). 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 | 9 +++------ arch/arm64/kernel/sdei.c | 2 +- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/arch/arm64/include/asm/virt.h b/arch/arm64/include/asm/virt.h index 7379f35ae2c6..4216c8623538 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_callable(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 ed50e9587ad8..1922e7a690f8 100644 --- a/arch/arm64/kernel/cpu-reset.h +++ b/arch/arm64/kernel/cpu-reset.h @@ -20,8 +20,7 @@ static inline void __noreturn 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_callable(); restart = (void *)__pa_symbol(__cpu_soft_restart); cpu_install_idmap(); diff --git a/arch/arm64/kernel/hibernate.c b/arch/arm64/kernel/hibernate.c index b1cef371df2b..c764574a1acb 100644 --- a/arch/arm64/kernel/hibernate.c +++ b/arch/arm64/kernel/hibernate.c @@ -48,9 +48,6 @@ */ extern int in_suspend; -/* Do we need to reset el2? */ -#define el2_reset_needed() (is_hyp_mode_available() && !is_kernel_in_hyp_mode()) - /* temporary el2 vectors in the __hibernate_exit_text section. */ extern char hibernate_el2_vectors[]; @@ -125,7 +122,7 @@ int arch_hibernation_header_save(void *addr, unsigned int max_size) hdr->reenter_kernel = _cpu_resume; /* We can't use __hyp_get_vectors() because kvm may still be loaded */ - if (el2_reset_needed()) + if (is_hyp_callable()) hdr->__hyp_stub_vectors = __pa_symbol(__hyp_stub_vectors); else hdr->__hyp_stub_vectors = 0; @@ -387,7 +384,7 @@ int swsusp_arch_suspend(void) dcache_clean_range(__idmap_text_start, __idmap_text_end); /* Clean kvm setup code to PoC? */ - if (el2_reset_needed()) { + if (is_hyp_callable()) { dcache_clean_range(__hyp_idmap_text_start, __hyp_idmap_text_end); dcache_clean_range(__hyp_text_start, __hyp_text_end); } @@ -482,7 +479,7 @@ int swsusp_arch_resume(void) * * We can skip this step if we booted at EL1, or are running with VHE. */ - if (el2_reset_needed()) { + if (is_hyp_callable()) { phys_addr_t el2_vectors = (phys_addr_t)hibernate_exit; el2_vectors += hibernate_el2_vectors - __hibernate_exit_text_start; /* offset */ diff --git a/arch/arm64/kernel/sdei.c b/arch/arm64/kernel/sdei.c index 2c7ca449dd51..af0ac2f920cf 100644 --- a/arch/arm64/kernel/sdei.c +++ b/arch/arm64/kernel/sdei.c @@ -200,7 +200,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_callable()) { pr_err("Not supported on this hardware/boot configuration\n"); goto out_err; }