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: 12528493 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 B2D72C433FE for ; Thu, 30 Sep 2021 14:33:34 +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 7694F60FC2 for ; Thu, 30 Sep 2021 14:33:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 7694F60FC2 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=Y4Eb6sS93HoOqU+F9JOyR0QPNTgNbAH5vAoRYbtSnRs=; b=WB/rauubF3EEWx 0//7q0DthVPoWSRrWvQw2V0lDVlyzE68RidWdI8eh2QNPYtuObC45Xeh9sv4OU22Iad77GVr8Uben 0WYDuQTuOgxu37r1+mCo+tEewGzev3BvRzaGHgNCi2YjRspN5tZHmOQ2w9/FxIA0D4wlhda1aYUhe nfs4FPBsBQ0HA7WrENL1SLxdbABxINrEJpNU8UG0530GlnguGIfQJX27WTs21CqsVp+O5zp9FxkMk 4eNrQDykjbAnga1wR+ZbwDpUwqugzvK2YHDwTXopqY5AkRYIbtPYBqUg7GvxeBaHCXFoHa/MA+XVP K554noYmESvncfwknubw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mVx6E-00EhfY-3D; Thu, 30 Sep 2021 14:31:50 +0000 Received: from mail-qt1-x835.google.com ([2607:f8b0:4864:20::835]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mVx5h-00EhN2-GX for linux-arm-kernel@lists.infradead.org; Thu, 30 Sep 2021 14:31:21 +0000 Received: by mail-qt1-x835.google.com with SMTP id d8so5836087qtd.5 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=ZCtCXoF3QBw5tbEk01bZF5siMsB0SX+eG2hWn3GocMaG39QRBrFCRT8FodO1tf2uTQ UyNjj4fpul2F3liBgO9N/yxarD7HHWuhk/l0/Q8XWA7LMs4BXD6cmlFeC7dL0DJdKBdI J3rl5vOUhulW7s7meW/azAjXf7gkYmM2KCx+YQCLica26NluJClK7qCj4qWgk/jVC0fU P0wUg9cz6hJPeJoVx8NSjjZqyiw6vHH9gsIInjch7ewfvuqF3mtCpA57Atha9ER9GDGP F1qZIrwDboie2pQaGq237VJ50vHqlDA8JGpUTpCKyg9ni73nLkEERL+5WQCMjgBkXk5M uIlA== X-Gm-Message-State: AOAM530P7ACiE14bqaSE+5qIT71Pnvf+KwJUkpTGZOhobeNapFP/st8D DOe/X1vlYjFhxqzuutpYYq9fHQ== 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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210930_073117_582099_ED10BD8E X-CRM114-Status: GOOD ( 15.12 ) 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: 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; }