From patchwork Thu Sep 30 14:30:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 12528501 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C6596C433FE for ; Thu, 30 Sep 2021 14:31:19 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 5AE7161A2C for ; Thu, 30 Sep 2021 14:31:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 5AE7161A2C Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=soleen.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 4DC179400A1; Thu, 30 Sep 2021 10:31:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4666394003A; Thu, 30 Sep 2021 10:31:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 243709400A1; Thu, 30 Sep 2021 10:31:18 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0236.hostedemail.com [216.40.44.236]) by kanga.kvack.org (Postfix) with ESMTP id 1379D94003A for ; Thu, 30 Sep 2021 10:31:18 -0400 (EDT) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id BEE9130C69 for ; Thu, 30 Sep 2021 14:31:17 +0000 (UTC) X-FDA: 78644477394.08.BC15B8D Received: from mail-qt1-f173.google.com (mail-qt1-f173.google.com [209.85.160.173]) by imf21.hostedemail.com (Postfix) with ESMTP id 72F2CD03459D for ; Thu, 30 Sep 2021 14:31:17 +0000 (UTC) Received: by mail-qt1-f173.google.com with SMTP id e16so5787388qte.13 for ; Thu, 30 Sep 2021 07:31:17 -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=ZgbetCXmU2I4AxLznQ7nGzSUyVlFTduK3mMsOCeyR2E=; b=NvUabrPKnpzcu5TeS9l5XS+8SzQvkmleB8d/hakxdXIDBVUCJ9US6MWCXxhdTzzOig rr/9DOSe6KjgBFl4joofHr//byFKjS0nSWBIndIorTah/fBqaOu/+2XRbb7FbH0UuTwv Qs+9FnH6mov9SV8ogh3PfFtbpic6oXECOAXGs49oQpo/gRXLDCIhgwUHOgU2toON5fDa ZxNRn+d1qmt4sgmUbA+DVxfghB99G1F4g68Ox7xXTW6zqsK4O3qyumJD+UElSbXa4FRJ ayCH2de8a5bJEypbyBdzpWcQ30ht6ipCMWAJuJAaNNHEDZVYI6LaWbsuZo+3w/8KAA/g cSew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZgbetCXmU2I4AxLznQ7nGzSUyVlFTduK3mMsOCeyR2E=; b=C1u1LTqQQZhCLeKk3f7gcxMqD+obPV2AiAWv0R2q07Evd9JjJRbUNCCMQOj8X3joym lD4I0i9s2icFW1SIY3udmDsqxYYHIsVAH0O0bturGQpD+wq5ldJs5TYjr5wEn0c91ky4 I868X8XRWKwrLeyh6J+9npHhv0RXjqxx5m3rwkDPEqUJ3wGeimzMLp38lLiB/T1s47VZ 1rTU2mPgW6nhoaz2Z2/Iv8nuuwNLdpKMHRT8BCxLLPER3Eh7Jrqm7bcfNQZe4hE45X6B 2S9xeo46H/sLvjQUiAzhokpPyLY7OORGqjf1oMXCDIfBAjay7IDzELT6QCPsc2wqw+7h LOpw== X-Gm-Message-State: AOAM531uINqOP+chh+J47mfVOyzro7hkgKDLBofTG+5Qf+OVOTSdCcfP kIW7siV+jAGfomPxAQRY280iyw== X-Google-Smtp-Source: ABdhPJxvgW9/FtyJRraTI54gn/Z60LChe52Uu0d4MLes/qY0mj18LYUViK9I0CDtWXyZAWETFAM8yw== X-Received: by 2002:ac8:4c84:: with SMTP id j4mr6839446qtv.411.1633012276760; Thu, 30 Sep 2021 07:31:16 -0700 (PDT) Received: from soleen.c.googlers.com.com (189.216.85.34.bc.googleusercontent.com. [34.85.216.189]) by smtp.gmail.com with ESMTPSA id l195sm1528731qke.98.2021.09.30.07.31.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Sep 2021 07:31:16 -0700 (PDT) From: Pasha Tatashin To: pasha.tatashin@soleen.com, 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, kernelfans@gmail.com, akpm@linux-foundation.org Subject: [PATCH v18 01/15] arm64: kernel: add helper for booted at EL2 and not VHE Date: Thu, 30 Sep 2021 14:30:59 +0000 Message-Id: <20210930143113.1502553-2-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.33.0.800.g4c38ced690-goog In-Reply-To: <20210930143113.1502553-1-pasha.tatashin@soleen.com> References: <20210930143113.1502553-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 72F2CD03459D X-Stat-Signature: fuyko6xz3fehnsyoctih5j58asujqpmq Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=soleen.com header.s=google header.b=NvUabrPK; dmarc=none; spf=pass (imf21.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.160.173 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com X-HE-Tag: 1633012277-236761 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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: Pasha Tatashin Acked-by: Catalin Marinas --- 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; }