From patchwork Tue Dec 8 14:24:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Brazdil X-Patchwork-Id: 11958737 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.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,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 9C83DC433FE for ; Tue, 8 Dec 2020 14:26:28 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (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 4FCB823A33 for ; Tue, 8 Dec 2020 14:26:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4FCB823A33 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.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=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc: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:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=BE6qBv1kFpdfU1Xg3VFROm+xHTiivLrVWNMfAStAre0=; b=ORpGyf7NpOg5+KlTwsA/FoVOo lxpX1fM9YNc0CpTsYgWxcdMjhwqK2XwocnMeIvK2hcAXJjR3wt4kUR3k8qltEmf+g3/shKmYjmDL6 1jpSBipScdfiYZtDYo/tMpb3DsKk+t+n/O8/b/RVQE2VTuJdL44Jii3iWEv9vjx7xrnuzHcO1bSzl 9rB+jvbnIbIgAHKFMJJMTBd3wu0UDKj+YEgO6Z38uWmIHWeordu069W4U3lNMoXEBiASmdU+fPpfo ohbZiNs7WJSmw48X1DQCcipOG2GlUrTDalx3AqdfFHSEnZ8KdNYdnpcY3hL5r0RracH4iKB0A1ISi SuEWWwV3A==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kmdvQ-0006l8-RV; Tue, 08 Dec 2020 14:25:08 +0000 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kmdvK-0006jD-5w for linux-arm-kernel@lists.infradead.org; Tue, 08 Dec 2020 14:25:05 +0000 Received: by mail-wr1-x442.google.com with SMTP id x6so12488647wro.11 for ; Tue, 08 Dec 2020 06:25:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ZJVcW+gDZ2QoZEFI86wiRHeEnmSVBb/mqFwXrVdG81k=; b=JuodSu1f9maE2qhArXiU3zxnxd+Aa1T/qMyiVTbr02hSTThljFG0K8+XSuMk4C0I98 0VaePBU0TePTYesJkS4wRGX2eLRP5rumtaLHudGToFoRx+rnWJGJKrkv87+jGXtZRwng ZRR0fP3GIFkKYGa8TSriFT8dkl7x8HXQC8XnCuhoZUKJVjkX14Y4IOp0vTvR/8O17plK SwPJlzQ3cszZ0KBxIj+UrHjQynYhPQgVPKRc2h4WiO8zgJwuVmZyJxu/VcYkh5g2iAgW LA1Eo7zh7aF1jUUXxzGvEI7fwv++bQjB3joY5++AW/v2tM1QJ1lF1lEYOv/S2a/XvQgr bIhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZJVcW+gDZ2QoZEFI86wiRHeEnmSVBb/mqFwXrVdG81k=; b=g9eOFmkL80gq9dHCbDLzYHJsDuMAWZhgJrd0YTLBklhmrC4D/OKwOB1RdJwnYehLjF JaYn74idqDRHdAE25w5nYeBuCuvidKA7DvUhYWJSk3Z3QE+O8+U7gZ0QKrxpZkq2C/ue +jPdjxfrvuz/RjMMw0u40H86DI7j9eCRt9gxEYFY7TuaFceMb2AGyBoZVi36ZrCaI1uX dLuueOziVXiQxnL0RylETVDRcI5vC56h7XzsEYYfA2BnunSh+kX4k99GXOABS53v6PRv UEENMhDkMhuQ5XyWwTB1E+n8GVXUPmt++IZrUCcfHFhTYac4wOxkDwOKlpxtbJ72G4tf iDPA== X-Gm-Message-State: AOAM532auho1A493BeNXuMn9TFIGVsdKbrvtKpuxTc82tKMBwuQuYnDp 5OYMKiASGDHH6IZ22Cxq+nLtyA== X-Google-Smtp-Source: ABdhPJz8XZZNRVczP1MNa+5GwvK6arhmg8wv+WVN7EM+CgWkgNOsNuQYcOEIW/yFZ+6gPYaHW1knsg== X-Received: by 2002:adf:dc87:: with SMTP id r7mr3566881wrj.305.1607437501067; Tue, 08 Dec 2020 06:25:01 -0800 (PST) Received: from localhost ([2a01:4b00:8523:2d03:258e:cb26:cef:a620]) by smtp.gmail.com with ESMTPSA id i8sm3763850wma.32.2020.12.08.06.24.59 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 08 Dec 2020 06:24:59 -0800 (PST) From: David Brazdil To: kvmarm@lists.cs.columbia.edu Subject: [PATCH 1/6] kvm: arm64: Prevent use of invalid PSCI v0.1 function IDs Date: Tue, 8 Dec 2020 14:24:47 +0000 Message-Id: <20201208142452.87237-2-dbrazdil@google.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201208142452.87237-1-dbrazdil@google.com> References: <20201208142452.87237-1-dbrazdil@google.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201208_092502_385573_C4EB5D9A X-CRM114-Status: GOOD ( 21.12 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , kernel-team@android.com, Suzuki K Poulose , Marc Zyngier , linux-kernel@vger.kernel.org, James Morse , linux-arm-kernel@lists.infradead.org, Catalin Marinas , David Brazdil , Will Deacon , Julien Thierry Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org PSCI driver exposes a struct containing the PSCI v0.1 function IDs configured in the DT. However, the struct does not convey the information whether these were set from DT or contain the default value zero. This could be a problem for PSCI proxy in KVM protected mode. Extend config passed to KVM with a bit mask with individual bits set depending on whether the corresponding function pointer in psci_ops is set, eg. set bit for PSCI_CPU_SUSPEND if psci_ops.cpu_suspend != NULL. Previously config was split into multiple global variables. Put everything into a single struct for convenience. Reported-by: Mark Rutland Signed-off-by: David Brazdil Signed-off-by: Marc Zyngier --- arch/arm64/include/asm/kvm_host.h | 20 +++++++++++ arch/arm64/kvm/arm.c | 14 +++++--- arch/arm64/kvm/hyp/nvhe/psci-relay.c | 53 +++++++++++++++++++++------- 3 files changed, 70 insertions(+), 17 deletions(-) diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index 11beda85ee7e..828d50d40dc2 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -240,6 +241,25 @@ struct kvm_host_data { struct kvm_pmu_events pmu_events; }; +#define KVM_HOST_PSCI_0_1_CPU_SUSPEND BIT(0) +#define KVM_HOST_PSCI_0_1_CPU_ON BIT(1) +#define KVM_HOST_PSCI_0_1_CPU_OFF BIT(2) +#define KVM_HOST_PSCI_0_1_MIGRATE BIT(3) + +struct kvm_host_psci_config { + /* PSCI version used by host. */ + u32 version; + + /* Function IDs used by host if version is v0.1. */ + struct psci_0_1_function_ids function_ids_0_1; + + /* Bitmask of functions enabled for v0.1, bits KVM_HOST_PSCI_0_1_*. */ + unsigned int enabled_functions_0_1; +}; + +extern struct kvm_host_psci_config kvm_nvhe_sym(kvm_host_psci_config); +#define kvm_host_psci_config CHOOSE_NVHE_SYM(kvm_host_psci_config) + struct vcpu_reset_state { unsigned long pc; unsigned long r0; diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index 6e637d2b4cfb..6a2f4e01b04f 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -66,8 +66,6 @@ static DEFINE_PER_CPU(unsigned char, kvm_arm_hardware_enabled); DEFINE_STATIC_KEY_FALSE(userspace_irqchip_in_use); extern u64 kvm_nvhe_sym(__cpu_logical_map)[NR_CPUS]; -extern u32 kvm_nvhe_sym(kvm_host_psci_version); -extern struct psci_0_1_function_ids kvm_nvhe_sym(kvm_host_psci_0_1_function_ids); int kvm_arch_vcpu_should_kick(struct kvm_vcpu *vcpu) { @@ -1618,8 +1616,16 @@ static bool init_psci_relay(void) return false; } - kvm_nvhe_sym(kvm_host_psci_version) = psci_ops.get_version(); - kvm_nvhe_sym(kvm_host_psci_0_1_function_ids) = get_psci_0_1_function_ids(); + kvm_host_psci_config.version = psci_ops.get_version(); + + if (kvm_host_psci_config.version == PSCI_VERSION(0, 1)) { + kvm_host_psci_config.function_ids_0_1 = get_psci_0_1_function_ids(); + kvm_host_psci_config.enabled_functions_0_1 = + (psci_ops.cpu_suspend ? KVM_HOST_PSCI_0_1_CPU_SUSPEND : 0) | + (psci_ops.cpu_off ? KVM_HOST_PSCI_0_1_CPU_OFF : 0) | + (psci_ops.cpu_on ? KVM_HOST_PSCI_0_1_CPU_ON : 0) | + (psci_ops.migrate ? KVM_HOST_PSCI_0_1_MIGRATE : 0); + } return true; } diff --git a/arch/arm64/kvm/hyp/nvhe/psci-relay.c b/arch/arm64/kvm/hyp/nvhe/psci-relay.c index 08dc9de69314..0d6f4aa39621 100644 --- a/arch/arm64/kvm/hyp/nvhe/psci-relay.c +++ b/arch/arm64/kvm/hyp/nvhe/psci-relay.c @@ -22,9 +22,8 @@ void kvm_hyp_cpu_resume(unsigned long r0); void __noreturn __host_enter(struct kvm_cpu_context *host_ctxt); /* Config options set by the host. */ -__ro_after_init u32 kvm_host_psci_version; -__ro_after_init struct psci_0_1_function_ids kvm_host_psci_0_1_function_ids; -__ro_after_init s64 hyp_physvirt_offset; +struct kvm_host_psci_config __ro_after_init kvm_host_psci_config; +s64 __ro_after_init hyp_physvirt_offset; #define __hyp_pa(x) ((phys_addr_t)((x)) + hyp_physvirt_offset) @@ -54,12 +53,41 @@ static u64 get_psci_func_id(struct kvm_cpu_context *host_ctxt) return func_id; } +static inline bool is_psci_0_1_function_enabled(unsigned int fn_bit) +{ + return kvm_host_psci_config.enabled_functions_0_1 & fn_bit; +} + +static inline bool is_psci_0_1_cpu_suspend(u64 func_id) +{ + return is_psci_0_1_function_enabled(KVM_HOST_PSCI_0_1_CPU_SUSPEND) && + (func_id == kvm_host_psci_config.function_ids_0_1.cpu_suspend); +} + +static inline bool is_psci_0_1_cpu_on(u64 func_id) +{ + return is_psci_0_1_function_enabled(KVM_HOST_PSCI_0_1_CPU_ON) && + (func_id == kvm_host_psci_config.function_ids_0_1.cpu_on); +} + +static inline bool is_psci_0_1_cpu_off(u64 func_id) +{ + return is_psci_0_1_function_enabled(KVM_HOST_PSCI_0_1_CPU_OFF) && + (func_id == kvm_host_psci_config.function_ids_0_1.cpu_off); +} + +static inline bool is_psci_0_1_migrate(u64 func_id) +{ + return is_psci_0_1_function_enabled(KVM_HOST_PSCI_0_1_MIGRATE) && + (func_id == kvm_host_psci_config.function_ids_0_1.migrate); +} + static bool is_psci_0_1_call(u64 func_id) { - return (func_id == kvm_host_psci_0_1_function_ids.cpu_suspend) || - (func_id == kvm_host_psci_0_1_function_ids.cpu_on) || - (func_id == kvm_host_psci_0_1_function_ids.cpu_off) || - (func_id == kvm_host_psci_0_1_function_ids.migrate); + return is_psci_0_1_cpu_suspend(func_id) || + is_psci_0_1_cpu_on(func_id) || + is_psci_0_1_cpu_off(func_id) || + is_psci_0_1_migrate(func_id); } static bool is_psci_0_2_call(u64 func_id) @@ -71,7 +99,7 @@ static bool is_psci_0_2_call(u64 func_id) static bool is_psci_call(u64 func_id) { - switch (kvm_host_psci_version) { + switch (kvm_host_psci_config.version) { case PSCI_VERSION(0, 1): return is_psci_0_1_call(func_id); default: @@ -248,12 +276,11 @@ asmlinkage void __noreturn kvm_host_psci_cpu_entry(bool is_cpu_on) static unsigned long psci_0_1_handler(u64 func_id, struct kvm_cpu_context *host_ctxt) { - if ((func_id == kvm_host_psci_0_1_function_ids.cpu_off) || - (func_id == kvm_host_psci_0_1_function_ids.migrate)) + if (is_psci_0_1_cpu_off(func_id) || is_psci_0_1_migrate(func_id)) return psci_forward(host_ctxt); - else if (func_id == kvm_host_psci_0_1_function_ids.cpu_on) + else if (is_psci_0_1_cpu_on(func_id)) return psci_cpu_on(func_id, host_ctxt); - else if (func_id == kvm_host_psci_0_1_function_ids.cpu_suspend) + else if (is_psci_0_1_cpu_suspend(func_id)) return psci_cpu_suspend(func_id, host_ctxt); else return PSCI_RET_NOT_SUPPORTED; @@ -304,7 +331,7 @@ bool kvm_host_psci_handler(struct kvm_cpu_context *host_ctxt) if (!is_psci_call(func_id)) return false; - switch (kvm_host_psci_version) { + switch (kvm_host_psci_config.version) { case PSCI_VERSION(0, 1): ret = psci_0_1_handler(func_id, host_ctxt); break; From patchwork Tue Dec 8 14:24:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Brazdil X-Patchwork-Id: 11958735 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.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,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=ham 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 850D6C4167B for ; Tue, 8 Dec 2020 14:26:26 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (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 1CB9E23A33 for ; Tue, 8 Dec 2020 14:26:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1CB9E23A33 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.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=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc: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:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=E/LuVmBWXC6n4Q3g1Zhj0gieGeUGm0p1nmdVFa8FGqA=; b=17BRaM+nEFBC1tGCFZyLTpkJ6 skYSbyzc1Vn0siSYifnXNOLjjrgxK+no7cMYolJ6vQIVAXtkFV3S96eXinJSMhDDYOAIj8pgpTqAv ZXuXlmJq4OcmvtnhMxFfP7vfM09nfzb40k239Op0oBSv2TXbzpIuDsAn1iwszLkOvs/6CmvfsW9Rb SkqW4WmzKkO4GS8YmN2N5Ksdy9WyznJntOjjcGcykzCGkzIfCSXZiOuUfanzUCgcrm38JsmB401l9 6c0zKt43P25dDZhzjZaNMM9RVediCnZ96V1/YySkqpU9rVhWusCB8BIQjxp4FgmVuoyOoIGRAL0wL FtQDen4nw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kmdvV-0006my-20; Tue, 08 Dec 2020 14:25:13 +0000 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kmdvM-0006k6-6g for linux-arm-kernel@lists.infradead.org; Tue, 08 Dec 2020 14:25:07 +0000 Received: by mail-wr1-x442.google.com with SMTP id a12so9618623wrv.8 for ; Tue, 08 Dec 2020 06:25:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Js+kADbtgM+vdnerlP9z0cKyj1NsUqnpPe0pQv1UIXw=; b=rNqDlvxyiJ1P0X/0WsQzcAkJH7Wxtpn3w4/snPmFyQE2KualXgw27WCaRrxPRFYwwI QsoSIhbDK/z907X9cKGawWx3YqPOhniUpNV1ttzOUbL2Xq2ygPlTp3uuFaexqbw2e7TM jdPGWa9M+DcgzmdFp0iih/gDDMH7slzsCXgDqnvpQ29RZuDbpmF3IqIKm06SjMnw2EzM WOtgcp0yD0ppJcFJgI573XFMmWxBCOKN5+aoJmLMv7u2bHi87WbHN7aVZrm92p/mzelu C76fa08qbD0a4wn1vmdzbRf2A1519kerYbbXV9QHDQqk2wmYfsyqYachY5A4E8hypG4o MFUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Js+kADbtgM+vdnerlP9z0cKyj1NsUqnpPe0pQv1UIXw=; b=A7IitXaMf20dwYLSvnCKG3XS0fKNSVKSLWKP93Nd//0FLj0P0FHIwjS/duXkTHojxy lQEra2DdnvhFQvthQrpeF6inO/hjKfT3rvdx7KVhKv570KOeA+3GGekE5xJeNOhZaSz8 IXUmOxpThxHYIcgH59wU4SC+oVNtnpwlDzb3KriGTPP02nyAXLav8fgdu4qsSaoyd8VZ ynBsRT1lJ8Qghyr4YNmzy8t+jdesDrWV1ZuoVlk58R//YlbrrPZyJCi6aVw1HRp08E4e I/w49IrEiXVP0XFSN4P3saiTNbONxtGXT6PQg/vb+632jQaUx5qrNvuyr3SaUIOPrRrB XxXg== X-Gm-Message-State: AOAM532jI7EahbbNppPKJFJYy5klnXiQp1e95ZJpFqr78+e4YjmevZNU McHdQz9PnLrD85yqvc1T7F9Yiw== X-Google-Smtp-Source: ABdhPJxHrjfFXJbqnCX9xFY5SICS+JzIJWzJPSavZ7ozgbyJlJghKGdV9NwVaAw/PLQwBO8RZFpRfA== X-Received: by 2002:adf:aa4a:: with SMTP id q10mr24761702wrd.276.1607437503226; Tue, 08 Dec 2020 06:25:03 -0800 (PST) Received: from localhost ([2a01:4b00:8523:2d03:258e:cb26:cef:a620]) by smtp.gmail.com with ESMTPSA id m8sm3952024wmc.27.2020.12.08.06.25.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 08 Dec 2020 06:25:02 -0800 (PST) From: David Brazdil To: kvmarm@lists.cs.columbia.edu Subject: [PATCH 2/6] kvm: arm64: Use lm_alias in nVHE-only VA conversion Date: Tue, 8 Dec 2020 14:24:48 +0000 Message-Id: <20201208142452.87237-3-dbrazdil@google.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201208142452.87237-1-dbrazdil@google.com> References: <20201208142452.87237-1-dbrazdil@google.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201208_092504_329100_51D4C980 X-CRM114-Status: GOOD ( 15.97 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , kernel-team@android.com, Suzuki K Poulose , Qian Cai , Marc Zyngier , linux-kernel@vger.kernel.org, James Morse , linux-arm-kernel@lists.infradead.org, Catalin Marinas , David Brazdil , Will Deacon , Julien Thierry Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org init_hyp_physvirt_offset() computes PA from a kernel VA. Conversion to kernel linear-map is required first but the code used kvm_ksym_ref() for this purpose. Under VHE that is a NOP and resulted in a runtime warning. Replace kvm_ksym_ref with lm_alias. Reported-by: Qian Cai Signed-off-by: David Brazdil --- arch/arm64/kvm/va_layout.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm64/kvm/va_layout.c b/arch/arm64/kvm/va_layout.c index d8cc51bd60bf..914732b88c69 100644 --- a/arch/arm64/kvm/va_layout.c +++ b/arch/arm64/kvm/va_layout.c @@ -42,7 +42,7 @@ static void init_hyp_physvirt_offset(void) u64 kern_va, hyp_va; /* Compute the offset from the hyp VA and PA of a random symbol. */ - kern_va = (u64)kvm_ksym_ref(__hyp_text_start); + kern_va = (u64)lm_alias(__hyp_text_start); hyp_va = __early_kern_hyp_va(kern_va); CHOOSE_NVHE_SYM(hyp_physvirt_offset) = (s64)__pa(kern_va) - (s64)hyp_va; } From patchwork Tue Dec 8 14:24:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Brazdil X-Patchwork-Id: 11958733 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.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,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=ham 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 86600C19437 for ; Tue, 8 Dec 2020 14:26:26 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (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 2630223A5B for ; Tue, 8 Dec 2020 14:26:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2630223A5B Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.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=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc: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:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=94c6bjFCuOlhatqhfBhD3BLi1VPSCR9P/SGrfFvpXLE=; b=IcqVH336c0xKm16lWT0x0L5id N4TVxlKkyzg+eal1gWoLPwOCkbKLvQx1snPrZlwen9H63aUhxiXZyGWzJwD9fIgxlcv5WrdijuXPV 07HiqLfDEMkmQt6u7IiSU8H19bI6c2E1M5yhxJ4RTCK0TuXtmaGlvahvYO8jU0vt16VRiIkQGDyD9 0A47qBLh+f0RxtfOHCSssytnhLhKmzpd97pCo6vWgpVUza/u1SnjfBDqsQOFSUfd3fDFGFV6WN7bG Zu2Ig3TjKeApknMNviL4T9CQ0kDD88IbMqSxHYj3iFfyQydIdtY83CT4qTFgFp8RyscWPPIQ3suEW iYjZ38feQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kmdvY-0006o3-9d; Tue, 08 Dec 2020 14:25:16 +0000 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kmdvO-0006kQ-88 for linux-arm-kernel@lists.infradead.org; Tue, 08 Dec 2020 14:25:07 +0000 Received: by mail-wr1-x443.google.com with SMTP id t16so1118274wra.3 for ; Tue, 08 Dec 2020 06:25:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=EaxldaDhN9JlM3hE+IVwd+bTy8bVzmLP3BfUJc4jBBQ=; b=gULKGUKDNs5K8nvvXyITt50X6Uz79vM8+89FVjcAK6zuOHuIsYhOe00OqWQpm5TSDx nO/IrbyzFdepEFETzFAk43WiZWmcNzfBkWmyFGZ7/CE3M3a8c8UgRUqJ1T7bxmgmEXTi ah1qwtxT+O8hgLZgyXup0DutJii6RxEe0micQGZqCFpncp18p3Nr1G4O378zaFhdYGmH 2rFzRZAG6RGGAifB5Ab+jkuNsBpkSU2V+GlcJZ5dEqcjjFYsMKVcpca30QjNdRH0HawY NNE+iIMrSbbHfJ6G/Tl1kfUA7TX/Mml25q29hbTuoaFYkbORxsivaK/tU69ho0TbxZvv iRSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=EaxldaDhN9JlM3hE+IVwd+bTy8bVzmLP3BfUJc4jBBQ=; b=HudXMdzpXQ7Y0tkG/VfZfF6fMIUr/NBcsbOQeyuD58NC00uK5TuYOBvtG/jp1C0iCO 8KQ0e9IDTkqJunIcS8P+WSpM6+haRrlleBeUxlQGkPbOQa1qFtuhV0TIhnFqAmbhnOBR NsIvnmdZ2jYe+r8TCkj68MIsaSMC11yz2Xb/4M6AZ1e/Fk/GQ4UcweHFTnwTN/XG3+0S vXy2Yd2keCAvmMZL5EVg3E7Tr4ltnqiyaIvGxrrG7jVUTptYBBJaDfoVCqrxKxjrsnhi zsFagcHC/iO9GAOBqausrymzAP9iOHzDwXHY+lCiz9N1z0DhggJzIjCkNPdG/XNB2YAh fDKw== X-Gm-Message-State: AOAM530mcM+EXFiU1znDJFWwgWV90GfI+/F5H+wium61aD0fJ0Rt/A0w jU5qi5kvLfiYpDNnVe2pwI43kg== X-Google-Smtp-Source: ABdhPJzYqcZS7aoqzu4qYNksPaO6tUAeFeTHSKRNPw1/fsSQ1g1CJLkKZZZyFEt/fPl04D3ibmVhAw== X-Received: by 2002:adf:f98b:: with SMTP id f11mr26057502wrr.235.1607437505274; Tue, 08 Dec 2020 06:25:05 -0800 (PST) Received: from localhost ([2a01:4b00:8523:2d03:258e:cb26:cef:a620]) by smtp.gmail.com with ESMTPSA id d9sm20747214wrs.26.2020.12.08.06.25.04 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 08 Dec 2020 06:25:04 -0800 (PST) From: David Brazdil To: kvmarm@lists.cs.columbia.edu Subject: [PATCH 3/6] kvm: arm64: Skip computing hyp VA layout for VHE Date: Tue, 8 Dec 2020 14:24:49 +0000 Message-Id: <20201208142452.87237-4-dbrazdil@google.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201208142452.87237-1-dbrazdil@google.com> References: <20201208142452.87237-1-dbrazdil@google.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201208_092506_358554_899F2C3D X-CRM114-Status: GOOD ( 15.53 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , kernel-team@android.com, Suzuki K Poulose , Marc Zyngier , linux-kernel@vger.kernel.org, James Morse , linux-arm-kernel@lists.infradead.org, Catalin Marinas , David Brazdil , Will Deacon , Julien Thierry Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Computing the hyp VA layout is redundant when the kernel runs in EL2 and hyp shares its VA mappings. Make calling kvm_compute_layout() conditional on not just CONFIG_KVM but also !is_kernel_in_hyp_mode(). Signed-off-by: David Brazdil --- arch/arm64/kernel/smp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm64/kernel/smp.c b/arch/arm64/kernel/smp.c index 18e9727d3f64..4e585cc892e8 100644 --- a/arch/arm64/kernel/smp.c +++ b/arch/arm64/kernel/smp.c @@ -434,7 +434,7 @@ static void __init hyp_mode_check(void) "CPU: CPUs started in inconsistent modes"); else pr_info("CPU: All CPU(s) started at EL1\n"); - if (IS_ENABLED(CONFIG_KVM)) + if (IS_ENABLED(CONFIG_KVM) && !is_kernel_in_hyp_mode()) kvm_compute_layout(); } From patchwork Tue Dec 8 14:24:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Brazdil X-Patchwork-Id: 11958741 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_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, 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 2AFDCC4167B for ; Tue, 8 Dec 2020 14:26:40 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (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 DE5E923AAC for ; Tue, 8 Dec 2020 14:26:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DE5E923AAC Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.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=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc: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:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=138588r9rDnLmx6h6umCrHPrJigbwsmr9aZjuc/dQ0g=; b=IxcjzOLmo9qac88V6YJX/2gdu 39c4Zr+BDIp3wQHr7zKooQfkAlVoM2WTHCrGMBMbef7HxX79iTCHdymuhqdVLHKmg2gdwn9zPq3YK oC1FAio0WVCv0vbUeRFkX4C0gGD01hkqxDsz8wStxkesv8B2DYiWKCvbajP4qeuPSs/AtK/d4NzaP Ge6WVO1uPrHrxIP/o572xBk/xEAGfRLHk4/6JjVnbfnMXp1UzCxJe+EAZ+zBDVY0idJ2rRSZZUbZF xA2CmIQHTk4sAIqrUt9a0jX96XpbDslGSSjV8zJoZKIJY276GsvdmVf5VRscdC/qqxnu3blYd7qsr a586shY5A==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kmdvb-0006on-CD; Tue, 08 Dec 2020 14:25:19 +0000 Received: from mail-wr1-x434.google.com ([2a00:1450:4864:20::434]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kmdvR-0006l4-4m for linux-arm-kernel@lists.infradead.org; Tue, 08 Dec 2020 14:25:10 +0000 Received: by mail-wr1-x434.google.com with SMTP id l9so7279471wrt.13 for ; Tue, 08 Dec 2020 06:25:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=BjhXUzKj/3SLZy5uNzA4C/K6PgPdZs4Iy7Z8pRwTud8=; b=MKIjDRNE/vH7SgozRRbntqZl5L9nka4a7Ks+O6ij33TKr2hIkODBY1hA1/m+K1veuj WmwIcpss4zZkKtcl7qo6wg+/fLKsBGX8FIHtR4xNHEfnIbVAC3cMcFL2+jTyZ9XTZYJu t0Kw8BRj5oukfXXBP2W3+TB6ljiySnAkgPs6ymhbS7wS2GHlFlJXwNF6FEUgQYtSbD3y wF2yRIF0xdIEf/V8Kgv5FInnkg1QXYusNQChJp6+OmEWnCJq5cKCAqzVfPUNWdTbqXrY oRhEBOujqBZKugx2DJAg6xp+aIgxxcE8BBKxRWh2ALqOgMNrYVnlyCrf2uyr5wu76iEH S7Jw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=BjhXUzKj/3SLZy5uNzA4C/K6PgPdZs4Iy7Z8pRwTud8=; b=Ot7dftfIE3V/3FULTGBBOV4jn6D1cWfDfpWVXFuTWjww2cKpuPvVmj+cr7tcrwNxTl dTldRfvjLmBWntEdDGM9zJiEuc5hKMBfUQTRIvNDrn6z1RnQALtbTZ1298g31SrRJF+T v9uECp4VBW3xtQPRTPOUiBynJqad9eojVCgmw/DeJt21Nz4W91lm2M5glX+g5Snr7z7Q Cm9PFvWhkEIN+vlvgL+VRBjh/FTdWu8vuIb+IWrOV0sKVUY1CJUdZ+xN+4+OgGT8JqPB 8wRb7lurfKO8MseDUElLKSJw7qUtGPHBZDe8F9pbmEmBtsZknXRCgYsjjz8/EJDT5nC/ NW+A== X-Gm-Message-State: AOAM533prT1OsmBIQKJ2FOHPGU4o/uqI6glT7lXMYEJF/OOPOlX879cy cmymmtiV0+DXp+mEM32firKpiA== X-Google-Smtp-Source: ABdhPJzoJxdQFiXPcs1IzkqG8RhT6d83cMB1+XcYtV3yavJzRs/oL8cti6OQk1Eth3W4tH2A/bO10Q== X-Received: by 2002:adf:e449:: with SMTP id t9mr24998689wrm.257.1607437507409; Tue, 08 Dec 2020 06:25:07 -0800 (PST) Received: from localhost ([2a01:4b00:8523:2d03:258e:cb26:cef:a620]) by smtp.gmail.com with ESMTPSA id 101sm14275907wrc.11.2020.12.08.06.25.06 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 08 Dec 2020 06:25:06 -0800 (PST) From: David Brazdil To: kvmarm@lists.cs.columbia.edu Subject: [PATCH 4/6] kvm: arm64: Minor cleanup of hyp variables used in host Date: Tue, 8 Dec 2020 14:24:50 +0000 Message-Id: <20201208142452.87237-5-dbrazdil@google.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201208142452.87237-1-dbrazdil@google.com> References: <20201208142452.87237-1-dbrazdil@google.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201208_092509_245861_4E59DDDE X-CRM114-Status: GOOD ( 18.14 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , kernel-team@android.com, Suzuki K Poulose , Marc Zyngier , linux-kernel@vger.kernel.org, James Morse , linux-arm-kernel@lists.infradead.org, Catalin Marinas , David Brazdil , Will Deacon , Julien Thierry Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Small cleanup moving declarations of hyp-exported variables to kvm_host.h and using macros to avoid having to refer to them with kvm_nvhe_sym() in host. No functional change intended. Signed-off-by: David Brazdil --- arch/arm64/include/asm/kvm_host.h | 6 ++++++ arch/arm64/kvm/arm.c | 4 +--- arch/arm64/kvm/hyp/nvhe/hyp-smp.c | 6 +++--- arch/arm64/kvm/va_layout.c | 5 ++--- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index 828d50d40dc2..bce2452b305c 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -260,6 +260,12 @@ struct kvm_host_psci_config { extern struct kvm_host_psci_config kvm_nvhe_sym(kvm_host_psci_config); #define kvm_host_psci_config CHOOSE_NVHE_SYM(kvm_host_psci_config) +extern s64 kvm_nvhe_sym(hyp_physvirt_offset); +#define hyp_physvirt_offset CHOOSE_NVHE_SYM(hyp_physvirt_offset) + +extern u64 kvm_nvhe_sym(hyp_cpu_logical_map)[NR_CPUS]; +#define hyp_cpu_logical_map CHOOSE_NVHE_SYM(hyp_cpu_logical_map) + struct vcpu_reset_state { unsigned long pc; unsigned long r0; diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index 6a2f4e01b04f..836ca763b91d 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -65,8 +65,6 @@ static bool vgic_present; static DEFINE_PER_CPU(unsigned char, kvm_arm_hardware_enabled); DEFINE_STATIC_KEY_FALSE(userspace_irqchip_in_use); -extern u64 kvm_nvhe_sym(__cpu_logical_map)[NR_CPUS]; - int kvm_arch_vcpu_should_kick(struct kvm_vcpu *vcpu) { return kvm_vcpu_exiting_guest_mode(vcpu) == IN_GUEST_MODE; @@ -1602,7 +1600,7 @@ static void init_cpu_logical_map(void) * allow any other CPUs from the `possible` set to boot. */ for_each_online_cpu(cpu) - kvm_nvhe_sym(__cpu_logical_map)[cpu] = cpu_logical_map(cpu); + hyp_cpu_logical_map[cpu] = cpu_logical_map(cpu); } static bool init_psci_relay(void) diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-smp.c b/arch/arm64/kvm/hyp/nvhe/hyp-smp.c index cbab0c6246e2..2997aa156d8e 100644 --- a/arch/arm64/kvm/hyp/nvhe/hyp-smp.c +++ b/arch/arm64/kvm/hyp/nvhe/hyp-smp.c @@ -14,14 +14,14 @@ * Other CPUs should not be allowed to boot because their features were * not checked against the finalized system capabilities. */ -u64 __ro_after_init __cpu_logical_map[NR_CPUS] = { [0 ... NR_CPUS-1] = INVALID_HWID }; +u64 __ro_after_init hyp_cpu_logical_map[NR_CPUS] = { [0 ... NR_CPUS-1] = INVALID_HWID }; u64 cpu_logical_map(unsigned int cpu) { - if (cpu >= ARRAY_SIZE(__cpu_logical_map)) + if (cpu >= ARRAY_SIZE(hyp_cpu_logical_map)) hyp_panic(); - return __cpu_logical_map[cpu]; + return hyp_cpu_logical_map[cpu]; } unsigned long __hyp_per_cpu_offset(unsigned int cpu) diff --git a/arch/arm64/kvm/va_layout.c b/arch/arm64/kvm/va_layout.c index 914732b88c69..70fcd6a12fe1 100644 --- a/arch/arm64/kvm/va_layout.c +++ b/arch/arm64/kvm/va_layout.c @@ -34,17 +34,16 @@ static u64 __early_kern_hyp_va(u64 addr) } /* - * Store a hyp VA <-> PA offset into a hyp-owned variable. + * Store a hyp VA <-> PA offset into a EL2-owned variable. */ static void init_hyp_physvirt_offset(void) { - extern s64 kvm_nvhe_sym(hyp_physvirt_offset); u64 kern_va, hyp_va; /* Compute the offset from the hyp VA and PA of a random symbol. */ kern_va = (u64)lm_alias(__hyp_text_start); hyp_va = __early_kern_hyp_va(kern_va); - CHOOSE_NVHE_SYM(hyp_physvirt_offset) = (s64)__pa(kern_va) - (s64)hyp_va; + hyp_physvirt_offset = (s64)__pa(kern_va) - (s64)hyp_va; } /* From patchwork Tue Dec 8 14:24:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Brazdil X-Patchwork-Id: 11958739 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.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,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=ham 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 BC86BC4361B for ; Tue, 8 Dec 2020 14:26:35 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (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 6612A23A33 for ; Tue, 8 Dec 2020 14:26:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6612A23A33 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.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=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc: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:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=ZUy+9yvciN6pcg612OrhrJGZLjS5isICRMbBB7xW8Ms=; b=aAFmtbQfkyDjtyAhGprzjPfH0 LtikHZeNU4SDS7k3zn8UDms7mrSUX1Xs/VhYKecI9EAdbmskCYJqzOvle0ckDFSvU+VJavfEOiXnv Czs+eJKJ5FzS1TreK2/E1wB/EKiXSMpznyxRVp9Tf631AKXGfEP7cojNp0v+7jfggTghOXC9njFOL /8BUewkHIUReg9fIl1anfa2BZXy/KRztypRJKV44t9i6zpkDxsJFui4SofkCooK+1uqGxkJkl7Xfb 9WVm5VxJs0cl2CzQGCR4U8wS1w4yeNcR4cHIwJ+9HmRTYChUkcZjvXxRu4GnaV6ZSYLP256xGp143 nGPsX135w==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kmdvh-0006qQ-Sx; Tue, 08 Dec 2020 14:25:25 +0000 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kmdvS-0006lv-LI for linux-arm-kernel@lists.infradead.org; Tue, 08 Dec 2020 14:25:11 +0000 Received: by mail-wr1-x441.google.com with SMTP id 91so12486504wrj.7 for ; Tue, 08 Dec 2020 06:25:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/OsSmUS/TA4WzvLCDGFMnERywT0JtFSnemYNOkWYU7I=; b=cDmmm0JhZog6Xpj0xnjDgjeGpv3JmrqqAS/Hzljmtb8vCenaWLk0Ip2XeAbYBS9NqG qTsMIEOZtuf8EF7qteO+W8tpzKkzx/uo957in9mqwbKHsZMWpNpdi+BoYHz9fMaBQ1tg Dzt8LNJ1VAjZQuATmdisp9eUPX8q90eYl6YgQTCE4z4PCr1nx2+P7/buuKoRG6NHG8Aj 46wk2xK1UOFU4WpTk3SghsahwJ/PcFhU7EYNW4J6ys7RaNjB2VMJko+6b9L31x4niW2K 0brar/neIAiT9q2EGjPKdN0j711bn51YXlrehLWLF3H/yZiZF8jdIXIPPYylY64Q0oSU xl1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/OsSmUS/TA4WzvLCDGFMnERywT0JtFSnemYNOkWYU7I=; b=aWXwB8Rfg8iSOb7aFa84qQPFDZzi0/U4ZPniZrJ2JpFlA8oAHPTnC8xZVaJHdicRJ+ OjObo7u1V4EbBS7u0SsAix7XtW+mzjqHwr3XxAbIsQaGF4UFOSwyaB0mDrAhMVx7ndjd 493A9BWpPxF+Baz+jiO8QMMyQcxSirCDe9TYl5inAZL3BRh0AERqCDP6pTixM7sAocKH UTcHjdWDaMoi3nYv3EEuUz2sjWlt8P6Hr5a/uX6Aagjemy619739gecSoRKxUWcj+l5P bjQLJZKMU3qBT2+G0WBGUKGPSZeV7r3hOoFt8lOJhM3KGiFinDeCb6iopq29r/5TLEtK bw6Q== X-Gm-Message-State: AOAM530TVNwIZB87OQOdse1asFaUoLdSHBkgmBqZocoocQDljmVOPuCE EwusrAX7VJE9aDfDEAgDd7frFw== X-Google-Smtp-Source: ABdhPJzAbt6RsNvdFXhB3aG8NC2B+lzZJ++35G/5BqR/OlHQfGVdFuDj/qtCUap6ioQzj3F+kC4a2g== X-Received: by 2002:adf:e444:: with SMTP id t4mr25488751wrm.152.1607437509535; Tue, 08 Dec 2020 06:25:09 -0800 (PST) Received: from localhost ([2a01:4b00:8523:2d03:258e:cb26:cef:a620]) by smtp.gmail.com with ESMTPSA id z21sm3843405wmk.20.2020.12.08.06.25.08 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 08 Dec 2020 06:25:08 -0800 (PST) From: David Brazdil To: kvmarm@lists.cs.columbia.edu Subject: [PATCH 5/6] kvm: arm64: Remove unused includes in psci-relay.c Date: Tue, 8 Dec 2020 14:24:51 +0000 Message-Id: <20201208142452.87237-6-dbrazdil@google.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201208142452.87237-1-dbrazdil@google.com> References: <20201208142452.87237-1-dbrazdil@google.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201208_092510_776110_B1DF34FD X-CRM114-Status: GOOD ( 12.66 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , kernel-team@android.com, Suzuki K Poulose , Marc Zyngier , linux-kernel@vger.kernel.org, James Morse , linux-arm-kernel@lists.infradead.org, Catalin Marinas , David Brazdil , Will Deacon , Julien Thierry Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Minor cleanup removing unused includes. Signed-off-by: David Brazdil --- arch/arm64/kvm/hyp/nvhe/psci-relay.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/arch/arm64/kvm/hyp/nvhe/psci-relay.c b/arch/arm64/kvm/hyp/nvhe/psci-relay.c index 0d6f4aa39621..1f7237e45148 100644 --- a/arch/arm64/kvm/hyp/nvhe/psci-relay.c +++ b/arch/arm64/kvm/hyp/nvhe/psci-relay.c @@ -7,11 +7,8 @@ #include #include #include -#include #include #include -#include -#include #include #include From patchwork Tue Dec 8 14:24:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Brazdil X-Patchwork-Id: 11958743 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.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,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 BEFFAC4361B for ; Tue, 8 Dec 2020 14:26:46 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (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 67BBA23A33 for ; Tue, 8 Dec 2020 14:26:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 67BBA23A33 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.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=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc: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:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=P23s8Url5aTe0OQ3IncRoFZeKo1i/AiBUe+iu+SqEsw=; b=bZnRmihhUs7IwBRIJHzHKvo9F UlmET5qSM+v0eQ4Nm7Ls9x3tGL95HmanfxkhLdmdD1HVbWxz9BCTKBc8DHdUtzDhrECFqZasWeZdJ SFjixjk8fXsWmkRbDxMoH2Vbp6HTBahc1762MNgTfpd0tPRxAdevgTEH4WVsc6wovnsx1DUCjGeaF crWZnkOJ4WR/lnCfE11U3pDeZOfDGvpqAmQrVU1EvmXpUuP8ipXexk2uXeCY4SXNffQG2cuK4ra7M 1XxaabyoVJAGJBBB2dX2rBCpq63psy2XPPgDo8znGiwQ4+vMyLI8Ely5h47bG7u5ekzwhSP0XfrF8 CcK/HTxVw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kmdvo-0006sU-IU; Tue, 08 Dec 2020 14:25:32 +0000 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kmdvU-0006mm-K6 for linux-arm-kernel@lists.infradead.org; Tue, 08 Dec 2020 14:25:13 +0000 Received: by mail-wr1-x443.google.com with SMTP id c1so4466448wrq.6 for ; Tue, 08 Dec 2020 06:25:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=f8/kp02WsOtyuCy6HonxO8TbrW5eGuVLEWwGykCnj2I=; b=cYNQMxDujCmqPGMeSjB/5132Iwcyi91EYgI1F304AcQrUlHZKwrKFnxd5VYUmZe9K3 qhfD9zstwz62Vgp0K320RLF7hLuvtr9nZDivEzCcR75CoOEA4hb3GFmeyES77O7KnMTF pAFnnE6967VFpJ/Fer47PSFKjnPHQQfe7mnE8sjmlVKr9apoDHds84eU2Nsa/WKlIBbn e+PddT+iFaoD3sljklf4jA3CdeJ4OWlAk0Nm10aXIftrVEcv1s96VvtC/zC6jeWwHJuO iIaowJGppOUfMxWaOtqumlHOPIktlTx+cXWMLrE/XMiCypkUNwIa2Z7JbNAXPdtn61gw lM5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=f8/kp02WsOtyuCy6HonxO8TbrW5eGuVLEWwGykCnj2I=; b=rZbeAP/tVDlJBp/cnUWO/GzIRmmOMKiIfzD/gKWFBaLibYxKZEM7vvOkXOz2XEpNaW VVj+uIxPBYW3KHr9O7KZVAufYBNjoQckeAX11df0eOSWkzzPNxfI31YApOmWia3QdmS4 G00+hYgn4ZP3DX9GXDP67qVjDG3zPH6FxQ/6C+tJdjo0ZwYM6hKSGAnz8wCTEV832rV5 eDKCsVtrv2pcl4sw8XB2RbrXFEzWu+uClUQhTiYjy7NGnfbGBrGik5CrfVFxqse/s03B IE2/Ff6kER1yXccuKer4Vs14pMpcJKmfXcuowmgY1YqnWHzZiYo6Me8s2DLiDcKJ1izJ fy1Q== X-Gm-Message-State: AOAM533sRejRdbJ3IUq3WcFEVLwLssH88XDXswheWmNmpopvjlSUY2lv +arWbmoigVr8zcEa6QFIuLe7Ug== X-Google-Smtp-Source: ABdhPJxMNnq/XmyKaQEfovB9gUn+Z+sXBgJfo586XxWEv01Ooqibpo3M5GZvW3EusOCR/yqN4TASEg== X-Received: by 2002:a5d:69cf:: with SMTP id s15mr17334520wrw.372.1607437511630; Tue, 08 Dec 2020 06:25:11 -0800 (PST) Received: from localhost ([2a01:4b00:8523:2d03:258e:cb26:cef:a620]) by smtp.gmail.com with ESMTPSA id b200sm3963032wmb.10.2020.12.08.06.25.10 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 08 Dec 2020 06:25:10 -0800 (PST) From: David Brazdil To: kvmarm@lists.cs.columbia.edu Subject: [PATCH 6/6] kvm: arm64: Move skip_host_instruction to adjust_pc.h Date: Tue, 8 Dec 2020 14:24:52 +0000 Message-Id: <20201208142452.87237-7-dbrazdil@google.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201208142452.87237-1-dbrazdil@google.com> References: <20201208142452.87237-1-dbrazdil@google.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201208_092512_758892_F4ACB456 X-CRM114-Status: GOOD ( 16.57 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , kernel-team@android.com, Suzuki K Poulose , Marc Zyngier , linux-kernel@vger.kernel.org, James Morse , linux-arm-kernel@lists.infradead.org, Catalin Marinas , David Brazdil , Will Deacon , Julien Thierry Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Move function for skipping host instruction in the host trap handler to a header file containing analogical helpers for guests. Signed-off-by: David Brazdil --- arch/arm64/kvm/hyp/include/hyp/adjust_pc.h | 9 +++++++++ arch/arm64/kvm/hyp/nvhe/hyp-main.c | 12 ++---------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/arch/arm64/kvm/hyp/include/hyp/adjust_pc.h b/arch/arm64/kvm/hyp/include/hyp/adjust_pc.h index b1f60923a8fe..61716359035d 100644 --- a/arch/arm64/kvm/hyp/include/hyp/adjust_pc.h +++ b/arch/arm64/kvm/hyp/include/hyp/adjust_pc.h @@ -59,4 +59,13 @@ static inline void __adjust_pc(struct kvm_vcpu *vcpu) } } +/* + * Skip an instruction while host sysregs are live. + * Assumes host is always 64-bit. + */ +static inline void kvm_skip_host_instr(void) +{ + write_sysreg_el2(read_sysreg_el2(SYS_ELR) + 4, SYS_ELR); +} + #endif diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-main.c b/arch/arm64/kvm/hyp/nvhe/hyp-main.c index bde658d51404..a906f9e2ff34 100644 --- a/arch/arm64/kvm/hyp/nvhe/hyp-main.c +++ b/arch/arm64/kvm/hyp/nvhe/hyp-main.c @@ -157,11 +157,6 @@ static void default_host_smc_handler(struct kvm_cpu_context *host_ctxt) __kvm_hyp_host_forward_smc(host_ctxt); } -static void skip_host_instruction(void) -{ - write_sysreg_el2(read_sysreg_el2(SYS_ELR) + 4, SYS_ELR); -} - static void handle_host_smc(struct kvm_cpu_context *host_ctxt) { bool handled; @@ -170,11 +165,8 @@ static void handle_host_smc(struct kvm_cpu_context *host_ctxt) if (!handled) default_host_smc_handler(host_ctxt); - /* - * Unlike HVC, the return address of an SMC is the instruction's PC. - * Move the return address past the instruction. - */ - skip_host_instruction(); + /* SMC was trapped, move ELR past the current PC. */ + kvm_skip_host_instr(); } void handle_trap(struct kvm_cpu_context *host_ctxt)