From patchwork Wed Nov 4 18:36:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Brazdil X-Patchwork-Id: 11881905 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=-12.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,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 7827EC2D0A3 for ; Wed, 4 Nov 2020 18:41:08 +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 158CD2067C for ; Wed, 4 Nov 2020 18:41:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="TY1mmuDv"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="glZIgG4S" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 158CD2067C 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=8Gt3WzhAKylODzlVCWBhiHHmew8ZIxYyOWN6/z85o/U=; b=TY1mmuDvrfC5HntSSR2IPBYeP 0Ch3tIwyL3X2Ahu8bHWskcZiy7Vsic/99IhxCvqdhH18jnoEpNfi6K2djEMPcOkYxOAzgkhRwYpPc JmoxdBOUhSRayCJhBsWLRj/m9SuMygCB4zVU12NdVkEcALo6PckgPqpBtOwUpeqzanEdB9wiMF6d/ 8CQexKSWbc4RQSkTorXWxKBZuSQsopSl6iV4jX2vXF8u31/WgZCN3twAsXH2+/jcHPqoqoHIFZvMY wvdz9ncfTUoeaJRirUXNVncwdKswxPbbZGhl3XqAE29qJ+VH6SPuaZwwdhg8W6RbaWumuAvdIfTEy ydjpq8l0w==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaNge-0002y8-PF; Wed, 04 Nov 2020 18:39:12 +0000 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaNel-0001qM-PW for linux-arm-kernel@lists.infradead.org; Wed, 04 Nov 2020 18:37:17 +0000 Received: by mail-wm1-x341.google.com with SMTP id v5so3365290wmh.1 for ; Wed, 04 Nov 2020 10:37:15 -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=NtbQNJ0uZzWKg9gLgK2M3GouFY/UQOUZaNHatLeLQ8M=; b=glZIgG4SvpZZisD70c1QAFcHNEqwgKXE55ekUwKFPprz1IIkVpSXlyWYgAtg2MCZM5 GqbKCZ3+xM/3+eOqF8D5wUxLEkEa6IQiJBeW8l6gSOLPRjEyrZUczqmCfQWxw0KjFRAV UTg06vSZoQR1ZRffNmFizJslF0vRdkKBwRISs0LhkuKK3dxmFpeYQzWGseWjGXaP53pX /XHsM9yTMR0wqMauTJgRe+RH3fb0nyXd+XMoMRPI3fdzZHBU1YxFys0+gatGpOM+mWw3 9Y1glJporpQT5vgTtSIAUmA3HuRnvrogowxslIbDEDS242fjxYGpkpL7E97BbqlKk7yy /SVQ== 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=NtbQNJ0uZzWKg9gLgK2M3GouFY/UQOUZaNHatLeLQ8M=; b=R55l6jkE89AJFnVK0lWTPFaLPocp9i1enk2/wSbnhHKTn3n14h23Kyhm0Pvw+HtFYA 7+yuxB/Wnnc4JK18wYpbj5oedZtRo5vBRJUbagxtvq/h4fwiqN8y6X1+kNRKZv3j2WZv zIhTEyfTCDeHnC47cgbX+Z0jEbePg9xhrYgK79AXnYu9IoaXaJDlPQhXScCTBAJ2q/iM XZs3yFw+bw0GM/JY6Nqmeqa23yrmT/ov8OoTYGSPk5GRnDIXiWKVCqrQcULH9q///yVy S+24W0SHkD6QAcIULkqvFYsfAA7PFONHKhZPGV9pglDxd5xqJXW+fFsN53r68+zgGJDw ttnA== X-Gm-Message-State: AOAM532iDRmM0vQqz+3rcki2QSt0F8Mgyr49+/qTr9XjHzvSYeM+jfEk iQxLpoKavsMdK4b86jd91huvKQ4GJoMf0MOv X-Google-Smtp-Source: ABdhPJxJRepCEtlNkPsKx2eanZXbzlkYpzLB45jmxePnFjEoeyIHr7ruHFcNIkE+7lLzMGGiaX+Q4g== X-Received: by 2002:a1c:4144:: with SMTP id o65mr6301427wma.171.1604515034317; Wed, 04 Nov 2020 10:37:14 -0800 (PST) Received: from localhost ([2a01:4b00:8523:2d03:c8d2:30f2:53c6:bc2]) by smtp.gmail.com with ESMTPSA id w4sm3692651wrk.28.2020.11.04.10.37.12 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 04 Nov 2020 10:37:13 -0800 (PST) From: David Brazdil To: kvmarm@lists.cs.columbia.edu Subject: [RFC PATCH 17/26] kvm: arm64: Bootstrap PSCI power state of host CPUs Date: Wed, 4 Nov 2020 18:36:21 +0000 Message-Id: <20201104183630.27513-18-dbrazdil@google.com> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201104183630.27513-1-dbrazdil@google.com> References: <20201104183630.27513-1-dbrazdil@google.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201104_133716_080120_199564D1 X-CRM114-Status: GOOD ( 17.88 ) 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 , Lorenzo Pieralisi , kernel-team@android.com, Suzuki K Poulose , Marc Zyngier , Quentin Perret , linux-kernel@vger.kernel.org, James Morse , linux-arm-kernel@lists.infradead.org, Catalin Marinas , Tejun Heo , Dennis Zhou , Christoph Lameter , David Brazdil , Will Deacon , Julien Thierry , Andrew Scull Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Proxying host's PSCI SMCs will require synchronizing CPU_ON/OFF/SUSPEND calls based on the observed state of individual cores. Add a per-CPU enum that tracks the power state of each core and initialize all CPUs online at the point of KVM init to ON. Signed-off-by: David Brazdil --- arch/arm64/include/asm/kvm_asm.h | 6 ++++++ arch/arm64/include/asm/kvm_hyp.h | 1 + arch/arm64/kvm/arm.c | 5 +++++ arch/arm64/kvm/hyp/nvhe/psci.c | 2 ++ 4 files changed, 14 insertions(+) diff --git a/arch/arm64/include/asm/kvm_asm.h b/arch/arm64/include/asm/kvm_asm.h index 893327d1e449..9eecb37db6df 100644 --- a/arch/arm64/include/asm/kvm_asm.h +++ b/arch/arm64/include/asm/kvm_asm.h @@ -157,6 +157,12 @@ struct kvm_nvhe_init_params { unsigned long vector_ptr; }; +enum kvm_nvhe_psci_state { + KVM_NVHE_PSCI_CPU_OFF = 0, + KVM_NVHE_PSCI_CPU_PENDING_ON, + KVM_NVHE_PSCI_CPU_ON, +}; + /* Translate a kernel address @ptr into its equivalent linear mapping */ #define kvm_ksym_ref(ptr) \ ({ \ diff --git a/arch/arm64/include/asm/kvm_hyp.h b/arch/arm64/include/asm/kvm_hyp.h index 95a2bbbcc7e1..cf4c1d16c3e0 100644 --- a/arch/arm64/include/asm/kvm_hyp.h +++ b/arch/arm64/include/asm/kvm_hyp.h @@ -97,6 +97,7 @@ void deactivate_traps_vhe_put(void); u64 __guest_enter(struct kvm_vcpu *vcpu); #ifdef __KVM_NVHE_HYPERVISOR__ +void kvm_host_psci_cpu_init(void); bool kvm_host_psci_handler(struct kvm_cpu_context *host_ctxt); #endif diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index 580d4a656a7b..5b073806463e 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -52,6 +52,7 @@ DECLARE_KVM_HYP_PER_CPU(unsigned long, kvm_hyp_vector); static DEFINE_PER_CPU(unsigned long, kvm_arm_hyp_stack_page); unsigned long kvm_arm_hyp_percpu_base[NR_CPUS]; DECLARE_KVM_NVHE_PER_CPU(struct kvm_nvhe_init_params, kvm_init_params); +DECLARE_KVM_NVHE_PER_CPU(enum kvm_nvhe_psci_state, psci_cpu_state); /* The VMID used in the VTTBR */ static atomic64_t kvm_vmid_gen = ATOMIC64_INIT(1); @@ -1517,10 +1518,14 @@ static void init_psci(void) { extern u32 kvm_nvhe_sym(kvm_host_psci_version); extern u32 kvm_nvhe_sym(kvm_host_psci_function_id)[PSCI_FN_MAX]; + int cpu; kvm_nvhe_sym(kvm_host_psci_version) = psci_driver_version; memcpy(kvm_nvhe_sym(kvm_host_psci_function_id), psci_function_id, sizeof(psci_function_id)); + + for_each_online_cpu(cpu) + *per_cpu_ptr_nvhe_sym(psci_cpu_state, cpu) = KVM_NVHE_PSCI_CPU_ON; } static int init_common_resources(void) diff --git a/arch/arm64/kvm/hyp/nvhe/psci.c b/arch/arm64/kvm/hyp/nvhe/psci.c index 3eafcf48a29b..c3d0a6246c66 100644 --- a/arch/arm64/kvm/hyp/nvhe/psci.c +++ b/arch/arm64/kvm/hyp/nvhe/psci.c @@ -20,6 +20,8 @@ s64 hyp_physvirt_offset; #define __hyp_pa(x) ((phys_addr_t)(x) + hyp_physvirt_offset) +DEFINE_PER_CPU(enum kvm_nvhe_psci_state, psci_cpu_state); + static u64 get_psci_func_id(struct kvm_cpu_context *host_ctxt) { return host_ctxt->regs.regs[0];