From patchwork Wed Nov 4 18:36:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Brazdil X-Patchwork-Id: 11881875 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 8CED8C2D0A3 for ; Wed, 4 Nov 2020 18:38:33 +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 EB9D52067C for ; Wed, 4 Nov 2020 18:38:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="26OvdY22"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="i5BcYNcM" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EB9D52067C 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=QsNDoYj7D1TI1Ty4MINc8Id7KpCvD8UxMd6in/DR2+s=; b=26OvdY22QD/+cpVezThy41JGE t99KfZk464u4yg8p+oUCu749ia4DugnEBJswf1xiqqBuaMcntESED9H/HOyKwTK4w4vpZxgb0aVt8 4t5GiK7KxibiIEAxf4IgZ4MMhWt+nhmHLCx4dGzss1eviyJcM5TZRodAfo7/g+ygI5W2e54csYZhh APPf5fLrq3+Qam2FEx/eAIY6Mj0YzG+8ZvCz8qbzvM4hBf/DLhYi7zj3+anlGIXhj1+VR/eq90pE1 RYEOMjPGZkF4kbfaWE2n2E7h6WwVoiPa4yIYeuIsJt8KlqK2FFY0380oODbk2mI6pQqIOt1v6ljG4 tvmQi1ZUQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaNeJ-0001eW-3M; Wed, 04 Nov 2020 18:36:47 +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 1kaNeE-0001cp-Q6 for linux-arm-kernel@lists.infradead.org; Wed, 04 Nov 2020 18:36:43 +0000 Received: by mail-wr1-x443.google.com with SMTP id w14so23120906wrs.9 for ; Wed, 04 Nov 2020 10:36:40 -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=z4vcpIwywIa5rhEfDa3o17Qy4qQsjexN6rFsZvVCzvI=; b=i5BcYNcM6qzN9gIC6Zos02dnE8rZIudFYfeZNcnVwst4EKmc2q2Ms0tbFD1K145rhN EyN53gm3SYcjXj8YeQ6px/NtuPMVkpv0swt2sKzFjniFPQHXjOXIiS7QGmMPwHCKGjEH 0Y3xO9i6IiXIkvBXE8sXwf5az6q2KrGHDE9VP6ovxCl47Hjt9bnzJ5X6mSzWBWX9/rMZ sUhvIEaRKj3w2xnjFLkI0BbBArxSG2s/9yPW2CInP6hqnbPKsOM1QaOm07yVZubZXTzR RbNN8m8Nvtbbf4tTxGVyg9zdj3UxpU6TOXKsOOF9/VaDzNPIbU98PtEkTT04FBQeh4Mu +bMg== 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=z4vcpIwywIa5rhEfDa3o17Qy4qQsjexN6rFsZvVCzvI=; b=YRwQ1cgP9TMD0wUTpOnVj7owH0LHEz+qaYdYasgnjCXqjrhrHUSdQi6/h19HXN7k3u f7GDdYUpyFKqJUZ5bd6luMLpIAcCsGMvB6ZIjM6O2/Cod7DbFtnldLj7iqpAXYFnyHkf yIy8uN3pm+k9EKbCZQstPub9ch+Uy7saFC/GmQJR5i4p8dw0Oc+PRWLQhyeh0qXl2TCl NdeZLqDMj8RpkcMPHiMl42y/x1IGDF2gQfBav65aNmSObfQ8Tv6xKLAbiz7OlW3c13l3 qLYmvNgqr3qxjWLav59CyhtjOq8WGRwQHuofoiILBj2kNk2KIHsmzOwz5P8khjCFIBh9 gGqQ== X-Gm-Message-State: AOAM530JorYuKvjMHQKLAo/xLIkEL4abDyf+axXqTPXyYPp4rT86I99M MPuUOxCTjbNXQ8ptYng2meAIZg== X-Google-Smtp-Source: ABdhPJzrzz9sHPqQ+PdVQq+JJJnWPJd6Kn6P7U2cR/hpaxn8sZnauzi5oOrw6gyAkzxG8ER6mhlOAQ== X-Received: by 2002:a05:6000:1252:: with SMTP id j18mr32575217wrx.18.1604514999931; Wed, 04 Nov 2020 10:36:39 -0800 (PST) Received: from localhost ([2a01:4b00:8523:2d03:c8d2:30f2:53c6:bc2]) by smtp.gmail.com with ESMTPSA id 15sm3271469wmg.1.2020.11.04.10.36.37 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 04 Nov 2020 10:36:38 -0800 (PST) From: David Brazdil To: kvmarm@lists.cs.columbia.edu Subject: [RFC PATCH 01/26] psci: Export configured PSCI version Date: Wed, 4 Nov 2020 18:36:05 +0000 Message-Id: <20201104183630.27513-2-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_133642_895410_E1713DD9 X-CRM114-Status: GOOD ( 20.09 ) 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 The version of PSCI that the kernel should use to communicate with firmware is typically obtained from probing PSCI_VERSION. However, that doesn't work for PSCI v0.1 where the host gets the information from DT/ACPI, or if PSCI is not supported / was disabled. KVM's PSCI proxy for the host needs to be configured with the same version used by the host driver. Expose the PSCI version used by the host. Signed-off-by: David Brazdil --- drivers/firmware/psci/psci.c | 6 ++++++ include/linux/psci.h | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/drivers/firmware/psci/psci.c b/drivers/firmware/psci/psci.c index 00af99b6f97c..ff523bdbfe3f 100644 --- a/drivers/firmware/psci/psci.c +++ b/drivers/firmware/psci/psci.c @@ -49,6 +49,8 @@ static int resident_cpu = -1; struct psci_operations psci_ops; static enum arm_smccc_conduit psci_conduit = SMCCC_CONDUIT_NONE; +int psci_driver_version = PSCI_VERSION(0, 0); + bool psci_tos_resident_on(int cpu) { return cpu == resident_cpu; @@ -461,6 +463,8 @@ static int __init psci_probe(void) return -EINVAL; } + psci_driver_version = ver; + psci_0_2_set_functions(); psci_init_migrate(); @@ -514,6 +518,8 @@ static int __init psci_0_1_init(struct device_node *np) pr_info("Using PSCI v0.1 Function IDs from DT\n"); + psci_driver_version = PSCI_VERSION(0, 1); + if (!of_property_read_u32(np, "cpu_suspend", &id)) { psci_function_id[PSCI_FN_CPU_SUSPEND] = id; psci_ops.cpu_suspend = psci_cpu_suspend; diff --git a/include/linux/psci.h b/include/linux/psci.h index 2a1bfb890e58..cb35b90d1746 100644 --- a/include/linux/psci.h +++ b/include/linux/psci.h @@ -21,6 +21,14 @@ bool psci_power_state_is_valid(u32 state); int psci_set_osi_mode(bool enable); bool psci_has_osi_support(void); +/** + * The version of the PSCI specification followed by the driver. + * This is equivalent to calling PSCI_VERSION except: + * (a) it also works for PSCI v0.1, which does not support PSCI_VERSION, and + * (b) it is set to v0.0 if the PSCI driver was not initialized. + */ +extern int psci_driver_version; + struct psci_operations { u32 (*get_version)(void); int (*cpu_suspend)(u32 state, unsigned long entry_point); From patchwork Wed Nov 4 18:36:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Brazdil X-Patchwork-Id: 11881869 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=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 BCD2EC63697 for ; Wed, 4 Nov 2020 18:37:24 +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 3CD8520719 for ; Wed, 4 Nov 2020 18:37:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="H7L6fNCF"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="GjufsStQ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3CD8520719 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=MdTfi2r319sFK+v9sglpmpto25L4QaR8wcYNwBxv+T0=; b=H7L6fNCFBgPBRZOsZRFQN2Ujf PNxIrhbt0X5NQftp2x8S/7GLyavD6V8Jzls1V6uMgWh5GJvjZy2hHZV2ST4UK+7t9FxmtyJw5Jcty +IJWCgTpVO75iAJtvtJIDhWeb8h0jFn7JY9NDfrKMpp1xFX8w/Q/WR2IZX0nwqh3AKiZMWQmPSnaO nGL0r3z1IbyLDCmJZgIf7VzIu0BzikJ9IOERVJOH8dtHYCblRxupneGizLqeFRStDV8ah5BbTEvgd HWANJxFCI972mKPHKicqkk63UTjLSoLDODNOPZJRqOCNFRGyyVUwZPc2YJO2Qexhfe9oUci2CewZp 8W0LhZEjw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaNeL-0001f9-Hi; Wed, 04 Nov 2020 18:36:49 +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 1kaNeG-0001dX-2N for linux-arm-kernel@lists.infradead.org; Wed, 04 Nov 2020 18:36:45 +0000 Received: by mail-wm1-x341.google.com with SMTP id s13so113979wmh.4 for ; Wed, 04 Nov 2020 10:36:43 -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=KMYzxJDYxfHlXJHNbiZJ0RtJwPETqciyv+NsXmdBd5Y=; b=GjufsStQ+HyoPB83S7Ba9wxZeSrIRXkcXxAxPID7JhjR+e70vcnGKegRMVIYfysv7o Aqy9GF51B2tXn8u3oe9zVHDNUbK2UjEYfUl0ImJtzs/qCnSFhbV8uAm01P1AEnwJSTKY 886tVk2x+NqZ5mbipyudrXGoKPfd75Ue1T3DpW0nxqJunhv6vnfS3Iwujj+lpucAL2j2 j0mudlvRcrcyi0KAqUQGnQDvtN05+8dSDdGl/vWDpoo8shIIkYtCVWQ7JrYQpG8Ud1tT DFeM3GX/XIeyX0MPssEYN6d5bp19EuNjOd7hRYPB3gs5DyH308XmOGyqTzEtvSLxC8S/ jr5A== 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=KMYzxJDYxfHlXJHNbiZJ0RtJwPETqciyv+NsXmdBd5Y=; b=n8ZaIBXiQ2EoIgNqtBqGZJH7KLM7lh+bA0EIyiaTGt5SkCmz8rWijvR0dqwvXDuu0P 11eTKep00WnsM6mGFn61yx1/eqFSGTAu5VXhffxJJ8FUSoS3E5c0xy1BFuCWbx+l0mE5 ykgkTVV+lVb9WAcThqk9LribeXyZA/odSG4UDObs3siEfVjjRZxZ6N/yJ8wC5OOC0Ymz PIiczI6RC0Ducq5pwHqNhAA/w2gx+KoOd/1ojWfwcMAX4zzImH8S5EcbO+0rLLp3tEsB rGQL++3KnpnPZ/Mvg1fMx32magk6WJzngVBZYlMdqOHkmexAYAhooVtfhWpFJwCC2b+p +lKQ== X-Gm-Message-State: AOAM531n0cN6x/IyXOoO180cfTnH8DjJgojVit4QlxK/1ZrnEayAoed+ 3NzGKGicyEG+nlAwUCJedhbtPA== X-Google-Smtp-Source: ABdhPJxe5MqDZ8brVsIs/z3j+gd8UQSoF3AlIuXpflyiQYSloiegdjfrS3Wak4Mz8sQzKefo8pVKsw== X-Received: by 2002:a7b:c748:: with SMTP id w8mr6054631wmk.32.1604515002281; Wed, 04 Nov 2020 10:36:42 -0800 (PST) Received: from localhost ([2a01:4b00:8523:2d03:c8d2:30f2:53c6:bc2]) by smtp.gmail.com with ESMTPSA id u10sm4014080wrw.36.2020.11.04.10.36.40 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 04 Nov 2020 10:36:41 -0800 (PST) From: David Brazdil To: kvmarm@lists.cs.columbia.edu Subject: [RFC PATCH 02/26] psci: Export configured PSCI function IDs Date: Wed, 4 Nov 2020 18:36:06 +0000 Message-Id: <20201104183630.27513-3-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_133644_159543_DC9255DC X-CRM114-Status: GOOD ( 15.27 ) 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 Function IDs used by PSCI are configurable for v0.1 via DT/APCI. If the host is using PSCI v0.1, KVM's PSCI proxy needs to use the same IDs. Expose the array holding the information. Signed-off-by: David Brazdil --- drivers/firmware/psci/psci.c | 10 +--------- include/linux/psci.h | 10 ++++++++++ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/drivers/firmware/psci/psci.c b/drivers/firmware/psci/psci.c index ff523bdbfe3f..ffcb88f60e21 100644 --- a/drivers/firmware/psci/psci.c +++ b/drivers/firmware/psci/psci.c @@ -60,15 +60,7 @@ typedef unsigned long (psci_fn)(unsigned long, unsigned long, unsigned long, unsigned long); static psci_fn *invoke_psci_fn; -enum psci_function { - PSCI_FN_CPU_SUSPEND, - PSCI_FN_CPU_ON, - PSCI_FN_CPU_OFF, - PSCI_FN_MIGRATE, - PSCI_FN_MAX, -}; - -static u32 psci_function_id[PSCI_FN_MAX]; +u32 psci_function_id[PSCI_FN_MAX]; #define PSCI_0_2_POWER_STATE_MASK \ (PSCI_0_2_POWER_STATE_ID_MASK | \ diff --git a/include/linux/psci.h b/include/linux/psci.h index cb35b90d1746..877d844ee6d9 100644 --- a/include/linux/psci.h +++ b/include/linux/psci.h @@ -29,6 +29,16 @@ bool psci_has_osi_support(void); */ extern int psci_driver_version; +enum psci_function { + PSCI_FN_CPU_SUSPEND, + PSCI_FN_CPU_ON, + PSCI_FN_CPU_OFF, + PSCI_FN_MIGRATE, + PSCI_FN_MAX, +}; + +extern u32 psci_function_id[PSCI_FN_MAX]; + struct psci_operations { u32 (*get_version)(void); int (*cpu_suspend)(u32 state, unsigned long entry_point); From patchwork Wed Nov 4 18:36:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Brazdil X-Patchwork-Id: 11881873 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=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 5B403C4741F for ; Wed, 4 Nov 2020 18:38:31 +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 D953D2067C for ; Wed, 4 Nov 2020 18:38:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="ozZSfyOX"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="Q5mK8uSR" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D953D2067C 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=If22Bqw4Ufx9Yf7fwqbA89aBZZaP9zOuAfONLiBLrtI=; b=ozZSfyOXor1gb6MkI3xN/lD4z 20L/cb2nXt3u7ktAoPKRPS8Rgq7HTnA3xvMcwOexYeQ32dZq+AziSjBqYFz/J6ORLhlN+gqvW9mf8 FDjzMrJwE1AoQORiECXHNrz0IEv1i6QugT3kBrQM5PofT2CohG01AkQyN8dYGGezydYanIRFUEJ+y JjtOIsK0s3whp3izcrBlln73Pm+xJJwFrRH35Xk0SliEQFed6fIVfiBclePxjSME730biV0iK5mBy nq3ZvdJfY78rVe5KUW7BFpt0xrxG/96yy5KvxXKCHaxhVWBZtGGnyGXHgnjqcOJxuLViQ8YeKo7Tm Snr4evxIQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaNeP-0001fr-1i; Wed, 04 Nov 2020 18:36:53 +0000 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaNeH-0001dz-Kb for linux-arm-kernel@lists.infradead.org; Wed, 04 Nov 2020 18:36:47 +0000 Received: by mail-wr1-x444.google.com with SMTP id c17so3796181wrc.11 for ; Wed, 04 Nov 2020 10:36:45 -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=dretx+OcQnNEgjiOHgLf5xuX2mgx6Pn+lAvUlmv1Umw=; b=Q5mK8uSRD63nfgGRd0lH16O0TMipT4yLtqy2sQBbkl08CNUezovnETohG9rebszGq8 0vdx8lJYS4mB9WRlz3W8/KzhCbjQ8OxW2FhSblN9uLFsDI/rbUQ9TTI97z7HhER3cXxs rHjtP/050BQ5K769dm085pH6Q/u7t7rMPpUVYc2OcIcJssNsO6XTa/wlRHRx9mZLv+IW Gahyfz5hGR7cT2wErqGNFxxxZEuHR04KSISkvpwR65eArEww7TerLaTFSSjHrDSUinvK oHAAy7K8iNU1EnePynpucNkY8ISIBbrT45JUUsnhQXdPmmoGe/ykyJmmKrz6zYHpmisf tptQ== 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=dretx+OcQnNEgjiOHgLf5xuX2mgx6Pn+lAvUlmv1Umw=; b=dspyJW+z7dK26PQdHZXu8RSguFcVifpNJtPdrLPfwzJCXeLt3O84qQPAILuzVSUVFk 8bZDgswwSvqfm2M6bP4NK5a9W40EB2+z4ca06txteDziiV7vFS0yseEK3o8fo8ab3NAj EhuzdhWZVhTw17pJdbMesc+an0zJTbmEb0Ev2egGtzWbkPTx26LfbY+NkVVCFeECIsSZ bovOXMKuhn5b27EGUysO0pqdctnL5sMJofsm4X82E7oN24HtQIBVRXAWSGS4t47megNE CuOYXBMxmLsmqIEOzqik7oKIYtgVHVc9qYryP1sVkfjCQXLlwxZm/hm62ysB4LGu+rk8 Mjlg== X-Gm-Message-State: AOAM532AjfG3X3N96ofQdSDac2k7/uyrTOaqFmlt+6ty2RxFck0vo7Fq fy7VRTyfyU/ctUd9dElodioUow== X-Google-Smtp-Source: ABdhPJzz9EDjWjSDrVKMul71N2NUVEw1fW+kiKrX84z0zmTkgi3rkWsvlxdP0L2e6xtC+jegDhXbQw== X-Received: by 2002:a05:6000:118c:: with SMTP id g12mr34650447wrx.246.1604515004320; Wed, 04 Nov 2020 10:36:44 -0800 (PST) Received: from localhost ([2a01:4b00:8523:2d03:c8d2:30f2:53c6:bc2]) by smtp.gmail.com with ESMTPSA id l16sm3665022wrx.5.2020.11.04.10.36.42 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 04 Nov 2020 10:36:43 -0800 (PST) From: David Brazdil To: kvmarm@lists.cs.columbia.edu Subject: [RFC PATCH 03/26] psci: Export psci_cpu_suspend_feature Date: Wed, 4 Nov 2020 18:36:07 +0000 Message-Id: <20201104183630.27513-4-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_133645_723100_CC19DECC X-CRM114-Status: GOOD ( 16.29 ) 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 KVM's PSCI proxy could probe the firmware to establish features supported for CPU_SUSPEND, but since the kernel's PSCI driver already does that, and other information about the driver is already exported, export the value of psci_cpu_suspend_feature as well for convenience. Signed-off-by: David Brazdil --- drivers/firmware/psci/psci.c | 2 +- include/linux/psci.h | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/firmware/psci/psci.c b/drivers/firmware/psci/psci.c index ffcb88f60e21..b6ad237b1518 100644 --- a/drivers/firmware/psci/psci.c +++ b/drivers/firmware/psci/psci.c @@ -71,7 +71,7 @@ u32 psci_function_id[PSCI_FN_MAX]; (PSCI_1_0_EXT_POWER_STATE_ID_MASK | \ PSCI_1_0_EXT_POWER_STATE_TYPE_MASK) -static u32 psci_cpu_suspend_feature; +u32 psci_cpu_suspend_feature; static bool psci_system_reset2_supported; static inline bool psci_has_ext_power_state(void) diff --git a/include/linux/psci.h b/include/linux/psci.h index 877d844ee6d9..a5832d91d493 100644 --- a/include/linux/psci.h +++ b/include/linux/psci.h @@ -29,6 +29,8 @@ bool psci_has_osi_support(void); */ extern int psci_driver_version; +extern u32 psci_cpu_suspend_feature; + enum psci_function { PSCI_FN_CPU_SUSPEND, PSCI_FN_CPU_ON, From patchwork Wed Nov 4 18:36:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Brazdil X-Patchwork-Id: 11881865 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 5345BC2D0A3 for ; Wed, 4 Nov 2020 18:37:30 +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 9C1BE20BED for ; Wed, 4 Nov 2020 18:37:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="kIcgB91H"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="h5c/xuFD" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9C1BE20BED 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=2WSMpCcF9Kqe5GWEGHnzf+phBtBZPJ5LrYz/MHg7lH4=; b=kIcgB91H18nwAwq1Wraye4z3S D8/7jPFqtlsHTAU0bMfmHDluHd7XypuPJVjvkLjw3zdf1PQJWpFWZr1W/+wHNiV3jou7I8C0bs1vS itYRSoKyUhbkN7ye9mfyFzQxlbfo8b5tR1zr+hMDnpzUFG0LDFr2tfZIr/oR5QAMRfDAgD6rEl65z pJt4lKkBtfld2m+r+qtUsAzEi3PajJlQRfQtHG7bbqD14e9wPu7ZkPqT6SbPMh20X0kTs73SpE8e4 9roy/iu0AlbnDhjATTDhjsll0TaKigQUpM9iNpAFkakOLAxBY67s8Gvb+D80M6w7PqfJ8keZIK21c 5t7v4QWgA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaNeS-0001h3-0O; Wed, 04 Nov 2020 18:36:56 +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 1kaNeJ-0001eX-D9 for linux-arm-kernel@lists.infradead.org; Wed, 04 Nov 2020 18:36:48 +0000 Received: by mail-wr1-x443.google.com with SMTP id b8so23174960wrn.0 for ; Wed, 04 Nov 2020 10:36:47 -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=selpDVExPrV+IgPEKGIlRfie/i9lgMV2qEZhs31ItAo=; b=h5c/xuFDGxhQNOOJxFYmZXPnLJyC4mt4eevQqa2BS/KDBE+R4+ZWYl3fiVp6+6GKml rdXluqt6BqUFOHQomC+HPz2nWSen/qcJZ0oTOtl2BKcUfsVXlAZy5wrHtufxBkAIWslB HCw8iLlb8kPY1W0YDvNIq7lH1izzFXSlNt9V7Ci06lt/x6qUvsjzXw6RN2ieTU+6G5qV /cCFrPXpeltx/hzuo9u7iu6TM54yUhX2W4sCEQjs+fR0UKJfMcmM+WiVu0qBnhnPuGND 9WjCSGx4PewL3YT53jbPkiQxHS63x1gGFZWbB7kh0Qe68aFM4yJTGc8g1TYn/PldTPi0 9YWw== 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=selpDVExPrV+IgPEKGIlRfie/i9lgMV2qEZhs31ItAo=; b=En7EfQ+yIomDgJIbPiswEjg68+FMUS1R2C9mITWpW+LcapE5s6y3Av+ailcqVdDKST BpcqcH9d03Yg24bAfD1QauH97SMMwzDmzAZsdrFJDcM1ovnUp0KtWAxftbsQY030c01H 0dC0ylp7C9VRoU73DWB90DYwAOSLpDcuX1a2Dd1sim8Nau6KeyCxccQuLvRBWAY44GmE vQ3xTpeo0iFYScZ2l+geeMgAxAs6ea6gO9kjG6KfErtihbXRNxWPcn8EmUEU+lFlfhm0 3GQkuWtl9PjlbF2H9VebUJttFaPFKNH+gI+WbtROwtWnkcae0xF5G6qtOCjLffcnX78W yr0Q== X-Gm-Message-State: AOAM531uyyXKhrustpS51d73zKJSqXzQXlcuhwREVApLMBT72up+elTe t02DbnzdUD02t2RUI96MNId5UQ== X-Google-Smtp-Source: ABdhPJyfkHHLx4wrmP7Kl9DrEZuORHnz2YFNiH75/raVrsXNU+mtkObCRVRsUfShJ+nawpNDAnF/uA== X-Received: by 2002:adf:edcf:: with SMTP id v15mr31926989wro.291.1604515006429; Wed, 04 Nov 2020 10:36:46 -0800 (PST) Received: from localhost ([2a01:4b00:8523:2d03:c8d2:30f2:53c6:bc2]) by smtp.gmail.com with ESMTPSA id u15sm3719292wrm.77.2020.11.04.10.36.45 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 04 Nov 2020 10:36:45 -0800 (PST) From: David Brazdil To: kvmarm@lists.cs.columbia.edu Subject: [RFC PATCH 04/26] arm64: Move MAIR_EL1_SET to asm/memory.h Date: Wed, 4 Nov 2020 18:36:08 +0000 Message-Id: <20201104183630.27513-5-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_133647_508010_81C2CDA5 X-CRM114-Status: GOOD ( 14.60 ) 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 KVM currently initializes MAIR_EL2 to the value of MAIR_EL1. In preparation for initializing MAIR_EL2 before MAIR_EL1, move the constant into a shared header file. Signed-off-by: David Brazdil --- arch/arm64/include/asm/memory.h | 13 +++++++++++++ arch/arm64/mm/proc.S | 13 ------------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/arch/arm64/include/asm/memory.h b/arch/arm64/include/asm/memory.h index cd61239bae8c..aca00737e771 100644 --- a/arch/arm64/include/asm/memory.h +++ b/arch/arm64/include/asm/memory.h @@ -152,6 +152,19 @@ #define MT_S2_FWB_NORMAL 6 #define MT_S2_FWB_DEVICE_nGnRE 1 +/* + * Default MAIR_EL1. MT_NORMAL_TAGGED is initially mapped as Normal memory and + * changed during __cpu_setup to Normal Tagged if the system supports MTE. + */ +#define MAIR_EL1_SET \ + (MAIR_ATTRIDX(MAIR_ATTR_DEVICE_nGnRnE, MT_DEVICE_nGnRnE) | \ + MAIR_ATTRIDX(MAIR_ATTR_DEVICE_nGnRE, MT_DEVICE_nGnRE) | \ + MAIR_ATTRIDX(MAIR_ATTR_DEVICE_GRE, MT_DEVICE_GRE) | \ + MAIR_ATTRIDX(MAIR_ATTR_NORMAL_NC, MT_NORMAL_NC) | \ + MAIR_ATTRIDX(MAIR_ATTR_NORMAL, MT_NORMAL) | \ + MAIR_ATTRIDX(MAIR_ATTR_NORMAL_WT, MT_NORMAL_WT) | \ + MAIR_ATTRIDX(MAIR_ATTR_NORMAL, MT_NORMAL_TAGGED)) + #ifdef CONFIG_ARM64_4K_PAGES #define IOREMAP_MAX_ORDER (PUD_SHIFT) #else diff --git a/arch/arm64/mm/proc.S b/arch/arm64/mm/proc.S index 23c326a06b2d..25ff21b3a1c6 100644 --- a/arch/arm64/mm/proc.S +++ b/arch/arm64/mm/proc.S @@ -45,19 +45,6 @@ #define TCR_KASAN_FLAGS 0 #endif -/* - * Default MAIR_EL1. MT_NORMAL_TAGGED is initially mapped as Normal memory and - * changed during __cpu_setup to Normal Tagged if the system supports MTE. - */ -#define MAIR_EL1_SET \ - (MAIR_ATTRIDX(MAIR_ATTR_DEVICE_nGnRnE, MT_DEVICE_nGnRnE) | \ - MAIR_ATTRIDX(MAIR_ATTR_DEVICE_nGnRE, MT_DEVICE_nGnRE) | \ - MAIR_ATTRIDX(MAIR_ATTR_DEVICE_GRE, MT_DEVICE_GRE) | \ - MAIR_ATTRIDX(MAIR_ATTR_NORMAL_NC, MT_NORMAL_NC) | \ - MAIR_ATTRIDX(MAIR_ATTR_NORMAL, MT_NORMAL) | \ - MAIR_ATTRIDX(MAIR_ATTR_NORMAL_WT, MT_NORMAL_WT) | \ - MAIR_ATTRIDX(MAIR_ATTR_NORMAL, MT_NORMAL_TAGGED)) - #ifdef CONFIG_CPU_PM /** * cpu_do_suspend - save CPU registers context From patchwork Wed Nov 4 18:36:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Brazdil X-Patchwork-Id: 11881883 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=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 6474CC2D0A3 for ; Wed, 4 Nov 2020 18:38:39 +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 DC02A2067C for ; Wed, 4 Nov 2020 18:38:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="ty4nbNW1"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="n8+AMW9H" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DC02A2067C 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=Oh1Njw8q/cpRKOhrTA0CvXCtaamZUbQdgLn8ZeZmYIE=; b=ty4nbNW1bmj0oateAQ0/BJ0l4 piFjwt3mwEUEsIXGQqcARc4apN3/Wbnm8gBipHLsbuQx4jge8c/iXRDxA54k7a5YjxZbpBOIBEk4Y Q10X6q1xiblcSdSyeJck4a6qeHP2JVcyLBOV/bF6uO+3IEyJLg7fqBouvbreDpa30+uNRJgn47RDy W/lQtzl3LRzbQjy4UKz/8duHH3NAPgGbH9be2jqDdiv7AQc4zVv7MXgkKgICvkvhI6T9KC7hUED8m KHV4AiEKevXISsngChuVd26gKFzzkZANP4J8Jk/+eOn4NFkwBp1Aaj2hj8JqmToYlAvJcWzuJ9oRK sPX/IlcaA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaNeb-0001kW-Ly; Wed, 04 Nov 2020 18:37:05 +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 1kaNeM-0001fO-6B for linux-arm-kernel@lists.infradead.org; Wed, 04 Nov 2020 18:36:51 +0000 Received: by mail-wr1-x443.google.com with SMTP id y12so23148659wrp.6 for ; Wed, 04 Nov 2020 10:36:50 -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=DIjGlXFqYL9FyveOV16h0d1a4eeVc3TLm9h73PIyC8E=; b=n8+AMW9H/IX3G8lz+cWGN1oavBIb5GbzZnNrEEdw+sYskA9ecY1TNAMYatbRQDl7uy nU1UQSUawSlfFozbAg0rTLm5KbnI/FEYx0M9/Kn5+yGcBQ27q37523/Vo/IZipYdWuM5 tw2FvnITfYxX4SXKqgpbQ4G76gBTOOkXtvxJTq7PtsfksWo89S01idD1OfYzSABuoFpP tVNb8gNrqGQGaUnf1bLkfw9v3P4dRzQICWnTURUB+lq5Xkz3zzjpXZlwLEPCy4VLihoo HEPi9o45di5YZQ7BQ/ZFrvoqXPnp9eMfV01QMcXfdeK2mVslLC+QAWW2jN6+MIZX9BRl qlGg== 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=DIjGlXFqYL9FyveOV16h0d1a4eeVc3TLm9h73PIyC8E=; b=VIc78q6yuQBuZ3Q2GqwIv7FkR1UjF8HtWu6Ph3GwOznw4g2W6GSPU15o4yxov4JAtv BsVR/8LbPAF9OW2xp8DAfCBQA4lWg6AM5gui0R1MF6x7I140OPF3wcXXy36OJMQYk/bO VVkato3yw6/zE9yHhhg/sZVeJX+Db10mZHjxX4N8Jz0fl0hUSsWeuQQjLqFUBbgQjBY3 J46bpLDmz6XzVmlBJ4hhW/RQ+aIKJJkfLgLI2fXfclFQMzvPGohstvEQjmhQ7uxKSki0 xfBTOG5s4GBNz3KuwrYsSXObwkffWaOlljB7wwdfpXkqGCToIehkx5usomq2Va336XQh BSiA== X-Gm-Message-State: AOAM533qyu8crqPb0iKY1shD4bIljfB30izetT4sw+dtY3iHWFz8hmDZ xmGj/vNhzIDcOATmGvETTv8Eyw== X-Google-Smtp-Source: ABdhPJwq7DN+2FlZtGXRhvnGQBPP7XUYeccP8u2X/rHVvW5yiq4qao29DK8F1rl8NE0ItwSBLn89Eg== X-Received: by 2002:a5d:640d:: with SMTP id z13mr32595956wru.28.1604515009243; Wed, 04 Nov 2020 10:36:49 -0800 (PST) Received: from localhost ([2a01:4b00:8523:2d03:c8d2:30f2:53c6:bc2]) by smtp.gmail.com with ESMTPSA id h12sm3718613wrw.70.2020.11.04.10.36.47 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 04 Nov 2020 10:36:48 -0800 (PST) From: David Brazdil To: kvmarm@lists.cs.columbia.edu Subject: [RFC PATCH 05/26] kvm: arm64: Initialize MAIR_EL2 using a constant Date: Wed, 4 Nov 2020 18:36:09 +0000 Message-Id: <20201104183630.27513-6-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_133650_398690_720D8DCC X-CRM114-Status: GOOD ( 16.85 ) 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 MAIR_EL2 is currently initialized to the value of MAIR_EL1, which itself is set to a constant MAIR_EL1_SET. Initialize MAIR_EL2 to the MAIR_EL1_SET constant directly in preparation of allowing KVM to start CPU cores itself and not initializing itself before ERETing to EL1. In that case, MAIR_EL2 will be initialized before MAIR_EL1. Signed-off-by: David Brazdil --- arch/arm64/kvm/hyp/nvhe/hyp-init.S | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-init.S b/arch/arm64/kvm/hyp/nvhe/hyp-init.S index b11a9d7db677..96e70f976ff5 100644 --- a/arch/arm64/kvm/hyp/nvhe/hyp-init.S +++ b/arch/arm64/kvm/hyp/nvhe/hyp-init.S @@ -111,7 +111,7 @@ alternative_else_nop_endif msr tcr_el2, x0 - mrs x0, mair_el1 + mov_q x0, MAIR_EL1_SET msr mair_el2, x0 isb From patchwork Wed Nov 4 18:36:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Brazdil X-Patchwork-Id: 11881885 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 0217CC2D0A3 for ; Wed, 4 Nov 2020 18:39:04 +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 749A120739 for ; Wed, 4 Nov 2020 18:39:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="xaNT8PGN"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="pwS+yO9a" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 749A120739 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=bJ9tw/2I3EKxC8ua06F7BRAh2VGjKeOCHTyRJFsjYpc=; b=xaNT8PGNXeOVEeoxvP7npZ3LE 6Y86AtSKmW3S93hrz/aJV0wYZssZOtY6xO8Pe4MF/E2RzvsnqCLLqlChn85QloZ9cRf0W6ahudLC6 vVZCV1SCJ3U1Qo7/52XJSSYv2IK7hzk/WXMTY2sihvDnfmwmw+cN09xEvAQUMSIasuY7Cmw/zMoa2 TafDznrkPZrlcmwfl36qoTAi0bfdEtROjV85RTj6wJyi4bY/PS8Ofq7e2UVqvpKkKP383d9Y+WrDj XUXWLhEHYLRon8GONVC6KSmDbZgq1LR0/kGJLRG+5IAXPOsEOP+hBCdQXRwbdLb54PgPz0EngL8yY gkRoHQLmg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaNel-0001ok-9C; Wed, 04 Nov 2020 18:37:15 +0000 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaNeO-0001fs-Iq for linux-arm-kernel@lists.infradead.org; Wed, 04 Nov 2020 18:36:53 +0000 Received: by mail-wm1-x342.google.com with SMTP id c9so3345641wml.5 for ; Wed, 04 Nov 2020 10:36:52 -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=/4FeYdmn3iB0IXLNt/H1CXu0UQ9fwGLnFLDS+u9FzHI=; b=pwS+yO9awK8oUBpQAVkLJuj63BH/WHRSAh1203sKJMLPgu/Z7WrtlqDJagBVCYrBaf EOF4SKuIVhlxAqijYs3lo1YFAo8JMGNuT2vGkFPRX2iSDKwMvMACiSGWDwM6hRJ50W30 rsJicMhiC6OYQ/2/CIUPbdAdRQpWJXMwejJYSsKhgwDaIDaZLSG1v9QGvqOLA1ErGg9d Iq0FStkmxGam8BquTREXKbmimi0koGzmcK9fr4eliQyQiNZJD/2xQZ2zt3TcJYss/+q2 PU8oK7Fyq8/xDdNN+GYMONZ2wzMa7EPpgD5F7CCcwZhZwvFOGbR9o6UrjPcEJN2uVbhb VRzw== 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=/4FeYdmn3iB0IXLNt/H1CXu0UQ9fwGLnFLDS+u9FzHI=; b=fiLZ/cjo3aZZBMosroTkJKJCH9WPiGsJi9aVeS1fwIjB/GFv5PBJEpVx40mcznYJEX H3IZJ9BbG11/ENdDws7EszItTpwEGjzn/shl6O5Ex1NPZrbILRNWENN4uBG50gfO7eou Y97ntd0ji/fLHE8jTPQK2sB57C7EyZUF2xT3XX4xP9QEnzF8Z4l+SYLlR9lKkhev7p7j kJ1reURSPcEsM4r/QDvcwGxSm8PyprbgjEoForhfjaKq4JVgvn2J7qBwl4RuplYUC0K+ 6YhC1OcSnvO+EM8c22JMPLXwmijdYN0PAWOTaUFNU5eRNNZiCjOI+tiEoBKFQ0cC/R1h hr8Q== X-Gm-Message-State: AOAM5314xdfsBCH4c/Z1nKL1LYqBAKykgqOQY1odbzenWzsvuuGyhMv+ V163azPrpQYnv9sPXfr59Uw6KSZkaQtUmr+F X-Google-Smtp-Source: ABdhPJx/hiCAz8Legoa47eblx4WAapjkBFpTOjmMETdF/oVexGY9XgUxpPgGgIkrhHQJMAw0LEe2bA== X-Received: by 2002:a05:600c:4147:: with SMTP id h7mr5966082wmm.186.1604515011165; Wed, 04 Nov 2020 10:36:51 -0800 (PST) Received: from localhost ([2a01:4b00:8523:2d03:c8d2:30f2:53c6:bc2]) by smtp.gmail.com with ESMTPSA id e25sm4070787wra.71.2020.11.04.10.36.49 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 04 Nov 2020 10:36:50 -0800 (PST) From: David Brazdil To: kvmarm@lists.cs.columbia.edu Subject: [RFC PATCH 06/26] kvm: arm64: Add .hyp.data ELF section Date: Wed, 4 Nov 2020 18:36:10 +0000 Message-Id: <20201104183630.27513-7-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_133652_728809_A713BAA4 X-CRM114-Status: GOOD ( 19.91 ) 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 Add rules for renaming a .data ELF section in KVM nVHE object files to .hyp.data, linking it into the kernel and mapping it in hyp at runtime. Signed-off-by: David Brazdil --- arch/arm64/include/asm/sections.h | 1 + arch/arm64/kernel/vmlinux.lds.S | 10 ++++++++++ arch/arm64/kvm/arm.c | 7 +++++++ arch/arm64/kvm/hyp/nvhe/hyp.lds.S | 3 +++ 4 files changed, 21 insertions(+) diff --git a/arch/arm64/include/asm/sections.h b/arch/arm64/include/asm/sections.h index 3994169985ef..255f76f592d7 100644 --- a/arch/arm64/include/asm/sections.h +++ b/arch/arm64/include/asm/sections.h @@ -11,6 +11,7 @@ extern char __alt_instructions[], __alt_instructions_end[]; extern char __hibernate_exit_text_start[], __hibernate_exit_text_end[]; extern char __hyp_idmap_text_start[], __hyp_idmap_text_end[]; extern char __hyp_text_start[], __hyp_text_end[]; +extern char __hyp_data_start[], __hyp_data_end[]; extern char __idmap_text_start[], __idmap_text_end[]; extern char __initdata_begin[], __initdata_end[]; extern char __inittext_begin[], __inittext_end[]; diff --git a/arch/arm64/kernel/vmlinux.lds.S b/arch/arm64/kernel/vmlinux.lds.S index 1bda604f4c70..a9a1612c084f 100644 --- a/arch/arm64/kernel/vmlinux.lds.S +++ b/arch/arm64/kernel/vmlinux.lds.S @@ -30,6 +30,13 @@ jiffies = jiffies_64; *(__kvm_ex_table) \ __stop___kvm_ex_table = .; +#define HYPERVISOR_DATA_SECTION \ + HYP_SECTION_NAME(.data) : { \ + __hyp_data_start = .; \ + *(HYP_SECTION_NAME(.data)) \ + __hyp_data_end = .; \ + } + #define HYPERVISOR_PERCPU_SECTION \ . = ALIGN(PAGE_SIZE); \ HYP_SECTION_NAME(.data..percpu) : { \ @@ -37,6 +44,7 @@ jiffies = jiffies_64; } #else /* CONFIG_KVM */ #define HYPERVISOR_EXTABLE +#define HYPERVISOR_DATA_SECTION #define HYPERVISOR_PERCPU_SECTION #endif @@ -207,6 +215,8 @@ SECTIONS EXIT_DATA } + HYPERVISOR_DATA_SECTION + PERCPU_SECTION(L1_CACHE_BYTES) HYPERVISOR_PERCPU_SECTION diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index 5750ec34960e..8bb9fffe2a8f 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -1602,6 +1602,13 @@ static int init_hyp_mode(void) goto out_err; } + err = create_hyp_mappings(kvm_ksym_ref(__hyp_data_start), + kvm_ksym_ref(__hyp_data_end), PAGE_HYP); + if (err) { + kvm_err("Cannot map hyp data section\n"); + goto out_err; + } + err = create_hyp_mappings(kvm_ksym_ref(__start_rodata), kvm_ksym_ref(__end_rodata), PAGE_HYP_RO); if (err) { diff --git a/arch/arm64/kvm/hyp/nvhe/hyp.lds.S b/arch/arm64/kvm/hyp/nvhe/hyp.lds.S index bb2d986ff696..bc1664d365a9 100644 --- a/arch/arm64/kvm/hyp/nvhe/hyp.lds.S +++ b/arch/arm64/kvm/hyp/nvhe/hyp.lds.S @@ -16,4 +16,7 @@ SECTIONS { HYP_SECTION_NAME(.data..percpu) : { PERCPU_INPUT(L1_CACHE_BYTES) } + + /* Put after '.data..percpu' because its name matches the same regex. */ + HYP_SECTION(.data) } From patchwork Wed Nov 4 18:36:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Brazdil X-Patchwork-Id: 11881881 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 0D494C2D0A3 for ; Wed, 4 Nov 2020 18:39:13 +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 71D212067C for ; Wed, 4 Nov 2020 18:39:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="Yomwv8Gg"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="Nx93E9yy" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 71D212067C 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=Ke1KSSZHYr9VehQBPi+MVKdb7mohGF9wzHx8dw6i8Ek=; b=Yomwv8GgYAnUCoXF9TY7yM4YS pvIoLAdC+FIUznYzHCyyhomSuPV09ntjCmOWa/iz2iibIaqqruR0rDWeTM9Lwr1Wsa83UXRz2oNfV tfH93iEX6NiGTi2Ayz80U+EfYEFj6remUKGLJ84bIrCdD9chEscuAW1lb3Arar5tChfgG+21aJXvP EbxUsMW3tH3AOOTyyacNGh9iERjBPzLdUxaDGm9HztvKljdNY1mmdfgGsgv2N2DImJbBPX4eVC6Xe +2+ynJhYkJg/hJtMgulSaRvQy20j89Ph8fmy2qWtZTp/DgAw2xAIq47v9JaRYtJ9EVeAfXZW5WBDB hoHNrKZ3Q==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaNev-0001ur-Iq; Wed, 04 Nov 2020 18:37:25 +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 1kaNeQ-0001gh-HN for linux-arm-kernel@lists.infradead.org; Wed, 04 Nov 2020 18:36:56 +0000 Received: by mail-wm1-x341.google.com with SMTP id h62so3286597wme.3 for ; Wed, 04 Nov 2020 10:36:54 -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=/Qa/ORiTczGU+wzc7d9QZzh5/niq1xeS+URCXTTt4r4=; b=Nx93E9yyY//kvChBV3KCeNqvnYwrNO2ZgDrCYTrU0G3sLsnpH5B+kY1/8elaSaHdfw HzA05rPUsQd+1O936ysg9hDnB+m7qGA0yA/fCbDjMEC24foxz3qejCDvvP/ogU38u4JJ U6iOV2bgUjnGUl0/kwdbTGln1yZ07j3+9EkIC1wznpT5C9dGNpaUL7flUrUywhoeJxep Wzq+coBb4Jkt0eRYX55seXPFpVc8OJBmMM9eXV/Na0tuwDnZ9llo+xBd+yflExNcQ+aW KL1CYXtO82nsOaaPC8oRLdp3PKxgmvCy1VlOydEjqSsUUncvVeg2+lmyb57UYZffXHjz fhig== 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=/Qa/ORiTczGU+wzc7d9QZzh5/niq1xeS+URCXTTt4r4=; b=A+VpJEk9t32rsn1mA2u7TtEuHMil3+olk1Jv7j6NjbYxYfpIhifqqoB8FjsQqM2LUY jq8hGJYEufd7mr7pxqZKsFextxUqc+mNZo0seLM/+HT+1rMo2bT0YUikmIHDN/i8mSJy Y0uEV/4lBzHayouAq+BNYyGgc+V8T8tQ4UbCjOFFSWQBGTBy6O0SKv5jsf0vKmCD9WkN hw/T+5lQOGGcGYkRT/b0cXxANcvXro42dmcHIIitGGVaTFT/KADcwx/Me/z/tbUs/5iX soYGn9bJBrgLNx8wSuPMKo85hMtcDdWVjHuOtGvl0FwVIFuEBHTSkVpXKYJbRWJgxIs3 cKBw== X-Gm-Message-State: AOAM530Oclt431pFv1yGHjSlHDAsipZx+YFlKP58yjau02AHFaxFlMy2 fOtmm6hXvMAWL4/Xu+YT33aZJ7UeY8gX4DCr X-Google-Smtp-Source: ABdhPJwP0oSnvZLNGQUvlE/1pKvC6M7nrsCqZGLWPZQiLMwgoxQ84TyR2rJEK0iBP/DF19+A8Bwokg== X-Received: by 2002:a7b:c11a:: with SMTP id w26mr5889073wmi.131.1604515013329; Wed, 04 Nov 2020 10:36:53 -0800 (PST) Received: from localhost ([2a01:4b00:8523:2d03:c8d2:30f2:53c6:bc2]) by smtp.gmail.com with ESMTPSA id e7sm4290328wrm.6.2020.11.04.10.36.51 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 04 Nov 2020 10:36:52 -0800 (PST) From: David Brazdil To: kvmarm@lists.cs.columbia.edu Subject: [RFC PATCH 07/26] kvm: arm64: Support per_cpu_ptr in nVHE hyp code Date: Wed, 4 Nov 2020 18:36:11 +0000 Message-Id: <20201104183630.27513-8-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_133654_608648_82B607F5 X-CRM114-Status: GOOD ( 21.19 ) 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 When compiling with __KVM_NVHE_HYPERVISOR__ redefine per_cpu_offset() to __hyp_per_cpu_offset() which looks up the base of the nVHE per-CPU region of the given cpu and computes its offset from the .hyp.data..percpu section. This enables use of per_cpu_ptr() helpers in nVHE hyp code. Until now only this_cpu_ptr() was supported by setting TPIDR_EL2. Signed-off-by: David Brazdil --- arch/arm64/include/asm/percpu.h | 6 ++++++ arch/arm64/kernel/image-vars.h | 3 +++ arch/arm64/kvm/hyp/nvhe/Makefile | 3 ++- arch/arm64/kvm/hyp/nvhe/percpu.c | 22 ++++++++++++++++++++++ 4 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 arch/arm64/kvm/hyp/nvhe/percpu.c diff --git a/arch/arm64/include/asm/percpu.h b/arch/arm64/include/asm/percpu.h index 1599e17379d8..8f1661603b78 100644 --- a/arch/arm64/include/asm/percpu.h +++ b/arch/arm64/include/asm/percpu.h @@ -239,6 +239,12 @@ PERCPU_RET_OP(add, add, ldadd) #define this_cpu_cmpxchg_8(pcp, o, n) \ _pcp_protect_return(cmpxchg_relaxed, pcp, o, n) +#ifdef __KVM_NVHE_HYPERVISOR__ +extern unsigned long __hyp_per_cpu_offset(unsigned int cpu); +#define __per_cpu_offset +#define per_cpu_offset(cpu) __hyp_per_cpu_offset((cpu)) +#endif + #include /* Redefine macros for nVHE hyp under DEBUG_PREEMPT to avoid its dependencies. */ diff --git a/arch/arm64/kernel/image-vars.h b/arch/arm64/kernel/image-vars.h index c615b285ff5b..78a42a7cdb72 100644 --- a/arch/arm64/kernel/image-vars.h +++ b/arch/arm64/kernel/image-vars.h @@ -103,6 +103,9 @@ KVM_NVHE_ALIAS(gic_nonsecure_priorities); KVM_NVHE_ALIAS(__start___kvm_ex_table); KVM_NVHE_ALIAS(__stop___kvm_ex_table); +/* Array containing bases of nVHE per-CPU memory regions. */ +KVM_NVHE_ALIAS(kvm_arm_hyp_percpu_base); + #endif /* CONFIG_KVM */ #endif /* __ARM64_KERNEL_IMAGE_VARS_H */ diff --git a/arch/arm64/kvm/hyp/nvhe/Makefile b/arch/arm64/kvm/hyp/nvhe/Makefile index ddde15fe85f2..c45f440cce51 100644 --- a/arch/arm64/kvm/hyp/nvhe/Makefile +++ b/arch/arm64/kvm/hyp/nvhe/Makefile @@ -6,7 +6,8 @@ asflags-y := -D__KVM_NVHE_HYPERVISOR__ ccflags-y := -D__KVM_NVHE_HYPERVISOR__ -obj-y := timer-sr.o sysreg-sr.o debug-sr.o switch.o tlb.o hyp-init.o host.o hyp-main.o +obj-y := timer-sr.o sysreg-sr.o debug-sr.o switch.o tlb.o hyp-init.o host.o \ + hyp-main.o percpu.o obj-y += ../vgic-v3-sr.o ../aarch32.o ../vgic-v2-cpuif-proxy.o ../entry.o \ ../fpsimd.o ../hyp-entry.o diff --git a/arch/arm64/kvm/hyp/nvhe/percpu.c b/arch/arm64/kvm/hyp/nvhe/percpu.c new file mode 100644 index 000000000000..5fd0c5696907 --- /dev/null +++ b/arch/arm64/kvm/hyp/nvhe/percpu.c @@ -0,0 +1,22 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (C) 2020 - Google LLC + * Author: David Brazdil + */ + +#include +#include +#include + +unsigned long __hyp_per_cpu_offset(unsigned int cpu) +{ + unsigned long *cpu_base_array; + unsigned long this_cpu_base; + + if (cpu >= ARRAY_SIZE(kvm_arm_hyp_percpu_base)) + hyp_panic(); + + cpu_base_array = kern_hyp_va(&kvm_arm_hyp_percpu_base[0]); + this_cpu_base = kern_hyp_va(cpu_base_array[cpu]); + return this_cpu_base - (unsigned long)&__per_cpu_start; +} From patchwork Wed Nov 4 18:36:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Brazdil X-Patchwork-Id: 11881867 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 C0B88C2D0A3 for ; Wed, 4 Nov 2020 18:38:15 +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 49DA22067C for ; Wed, 4 Nov 2020 18:38:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="oT1A33Ck"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="QGvBnzgo" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 49DA22067C 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=V18zqgwi4WbKm7RLYb++8YCjqbYUcGils+Zu7NNOqBU=; b=oT1A33Ckp1mf9/PXGZCZiRKER 1hVvseP+aKMzlw2lcWzNjPCsO+1VAVpfePq4lbBdToOGisgHghLiascUyr3B2tqNSsGMk3oqWNZMl 0L8uwqFGJJucmu4yMI5Lb4k1NnH73Tut75G2TprDKRZ47lWIoP07tKXwpUZq+Cuu8Xgmmn15qXthO f4/hfXiOYLR7lHJH1Ubbt6RXikrX+0efsjuAY504TsTHkX5/OimdPOrdU6QwnrkRNqIyuzKHcenzU GEg6X4+g/7I06nbq8Jh2WR0Zp5OaIyBV615HterIHbsit/aXyroBoO+YidzfSMnJaH1rLfi9uPopV qZdNd6nuQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaNfB-00022a-39; Wed, 04 Nov 2020 18:37:41 +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 1kaNeS-0001hZ-Iv for linux-arm-kernel@lists.infradead.org; Wed, 04 Nov 2020 18:36:57 +0000 Received: by mail-wr1-x443.google.com with SMTP id n18so23143843wrs.5 for ; Wed, 04 Nov 2020 10:36:56 -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=0K4yzmgUf7vVHr0iz04jMBBw0fWBZw8e2naPJ5vP+Z8=; b=QGvBnzgo0YRmIsUmCbkwh4pjuJnqEqI3AN4RP2WCjupA1IHn6Z0OnrMIpsPkymqpGw LP9vXOC4bb2uIkzXW0F524KSp23G15/moUgPgVXyGcaOdHz02/CsBg9vdKJ30wzamCGY /SWOL9tpI69HAqq6Lm3Ny8wX2p8T2D1MT7DbixVPelrjHpAmcQfQrSllDLrT8J7mD9cB 9GcGSiXbr5xTAA5lqnnidjDOw8yi3CjQw/YpYaC2iN/JQlLnH0UqksA8MHDMKqloZlF7 p+qMxb5zNbwWUudAMWkCby24Fe08vjsUpOoq5cImXofhjAevvHYe7xd/i7i9ef2L3nTG GeBw== 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=0K4yzmgUf7vVHr0iz04jMBBw0fWBZw8e2naPJ5vP+Z8=; b=Pit7uH/FVAtYZ/W6KIuHocVeR5CWrJmg5PLEqF/mTCynHWpS7FbkjhMad6kTdP5aGP V5Tnkcb07i9nOFkeYwDV7iF7fgjNptKZAuhQ0WRoSJEdGrj8JsNU2kUzojYDOjJz8W9Z SLgWTBdiRdzQQDiZeKYv81Cv6vCvDHvWhYh5pAyyIxoVuGhACbbOL9KmWVZpMbPu9M57 PqhKmMxttoDVI/mFU2Stbex9P0xbGHH6B+o8izyIMqXhb5VyJ20fzqRdtZmmV87AP4hq WHaIuzRVi3N3pg5B7Mme/zjubSjuYJK1YWgrehF5KQrsGDaTNLPp6q46Sj1jPp7ML10a gGyw== X-Gm-Message-State: AOAM531C+DHPBRfqLsQ0MTY6AAyukkH+fA6wJG8QXa/M0hZH2COyf8tz BFwd4szZcTvDT23G9CRdltXf6A== X-Google-Smtp-Source: ABdhPJxYOz8oN6hDQHajevWPLeTnGuUdeWGhUJpO55H7sotkzepkhC9LY3nZQ7oVr6rhj4DYoT519A== X-Received: by 2002:adf:f246:: with SMTP id b6mr33349825wrp.111.1604515015435; Wed, 04 Nov 2020 10:36:55 -0800 (PST) Received: from localhost ([2a01:4b00:8523:2d03:c8d2:30f2:53c6:bc2]) by smtp.gmail.com with ESMTPSA id l11sm3646430wro.89.2020.11.04.10.36.54 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 04 Nov 2020 10:36:54 -0800 (PST) From: David Brazdil To: kvmarm@lists.cs.columbia.edu Subject: [RFC PATCH 08/26] kvm: arm64: Create nVHE copy of cpu_logical_map Date: Wed, 4 Nov 2020 18:36:12 +0000 Message-Id: <20201104183630.27513-9-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_133656_803057_EEF205BC X-CRM114-Status: GOOD ( 20.18 ) 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 When KVM starts validating host's PSCI requests, it will need to map MPIDR back to the CPU ID. To this end, copy cpu_logical_map into nVHE hyp memory when KVM is initialized. Only copy the information for CPUs that are online at the point of KVM initialization so that KVM rejects CPUs whose features were not checked against the finalized capabilities. Signed-off-by: David Brazdil --- arch/arm64/kvm/arm.c | 17 +++++++++++++++++ arch/arm64/kvm/hyp/nvhe/percpu.c | 16 ++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index 8bb9fffe2a8f..58e9cc183bd5 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -1481,6 +1481,21 @@ static inline void hyp_cpu_pm_exit(void) } #endif +static void init_cpu_logical_map(void) +{ + extern u64 kvm_nvhe_sym(__cpu_logical_map)[NR_CPUS]; + int cpu; + + /* + * Copy the MPIDR <-> logical CPU ID mapping to hyp. + * Only copy the set of online CPUs whose features have been chacked + * against the finalized system capabilities. The hypervisor will not + * allow any other CPUs from the `possible` set to boot. + */ + for_each_online_cpu(cpu) + CHOOSE_NVHE_SYM(__cpu_logical_map)[cpu] = cpu_logical_map(cpu); +} + static int init_common_resources(void) { return kvm_set_ipa_limit(); @@ -1658,6 +1673,8 @@ static int init_hyp_mode(void) } } + init_cpu_logical_map(); + return 0; out_err: diff --git a/arch/arm64/kvm/hyp/nvhe/percpu.c b/arch/arm64/kvm/hyp/nvhe/percpu.c index 5fd0c5696907..8b7f6b7dbd48 100644 --- a/arch/arm64/kvm/hyp/nvhe/percpu.c +++ b/arch/arm64/kvm/hyp/nvhe/percpu.c @@ -8,6 +8,22 @@ #include #include +/* + * nVHE copy of data structures tracking available CPU cores. + * Only entries for CPUs that were online at KVM init are populated. + * Other CPUs should not be allowed to boot because their features were + * not checked against the finalized system capabilities. + */ +u64 __cpu_logical_map[NR_CPUS] = { [0 ... NR_CPUS-1] = INVALID_HWID }; + +u64 cpu_logical_map(int cpu) +{ + if (cpu < 0 || cpu >= ARRAY_SIZE(__cpu_logical_map)) + hyp_panic(); + + return __cpu_logical_map[cpu]; +} + unsigned long __hyp_per_cpu_offset(unsigned int cpu) { unsigned long *cpu_base_array; From patchwork Wed Nov 4 18:36:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Brazdil X-Patchwork-Id: 11881887 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 77EF8C2D0A3 for ; Wed, 4 Nov 2020 18:39:34 +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 F2ED12067C for ; Wed, 4 Nov 2020 18:39:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="qM4uDVRy"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="m8K5bU/p" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F2ED12067C 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=9jiSvNfiAIli0bNmDLSgXhH0SsLR42tJ1JUA1vw6wXU=; b=qM4uDVRyOBd8YsEOLIt2Xhc5V m9KzSw6ixMOpoSEAVyEU1l95kKa2mKvkB42+FfaAqS3z9K9pXPQw4ObEKNCE1/GgvJSBHAeQ9hLOX 0gluRiGf7TUb7TJi2DguSH6NlBO1uAIwNbfCVKlEg8kVJkKFWzjy5S8hbCl0hXk/YG6YmEGB8PmDg B9HFmnt7hQlpFlXhL8TbRInJMKwBi4nLkK0TZ2aWA7USlPAVgu4V2M0mOwjrZInDmkgVjvSsM0NNk VDGczB3Np1c1m0s7M4UV+BZ5rKOXpE7ahWYzuICpIMkqi8qOYZ11IyhoXrdcZ+wMld+G8cmBTXYO4 3ww8YqSnQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaNfH-00025b-HU; Wed, 04 Nov 2020 18:37:47 +0000 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaNeU-0001iU-Jx for linux-arm-kernel@lists.infradead.org; Wed, 04 Nov 2020 18:36:59 +0000 Received: by mail-wr1-x444.google.com with SMTP id e6so5904353wro.1 for ; Wed, 04 Nov 2020 10:36:58 -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=yHpZ9wtBmkho6WWTpMsPbAPapSxOhOKPIw2D5X4b/kc=; b=m8K5bU/p3bcrkcVWYa/Sh88AnifU54Kz8+53se/R/bVZ/VKDTqqZu7LmPsP4mFeNVv Q+q9Ko2M3D0VRvShU58WDoXLNfSfEjzW1HfzErPgkGP5JSvi5PS6PcA63vuZg7AiOYbc kHHZC2MfXu29algZJjbudHQlBWPHQ3gMUsnqJgiLae77ewjoh8ku7oVXra/O8Nn0j8ll EAg03uR6xdNvB2ESOV3tEc7FhB9sE2h96modaPk/60u8p6yBkJR/A55ctvaOXbZRKENj sASw51SSO4HpzZZmaANpV3IZ7TwUTPCAe2bH9uOKft0GjTlS6Gs9ws8Bu2TpG3PLBAzU huKw== 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=yHpZ9wtBmkho6WWTpMsPbAPapSxOhOKPIw2D5X4b/kc=; b=LCqfhuhMHEnhXGpmA8905AjsULBvCMEU9xJ2h4tmQywRCQ4aiui19nEINutBWuztTV sHjcWppP3UkxqivsIkFC+7PtQVgLUyr/q1FY1bZ3ncgqAqicZeyZMvgrY4F4BNqC9kdo edF5kFptFUaVtEl5XEfTFOSrLZ3kjchOsGI/cVBH2fHxvOOQ6QEN5UAKhrlQ6KFf7LQp RrP83LY+HTa9zi2byGWXbpx6OI7b/ljuyhFuLOpDy9b5WdmdbWLkiEFTGNt1sJOn3g9c 2WYpOGOPpQQojIlkbpCvT7SuJZ8A6guA+FOrEvRtiZO5/KTATlv8JLsta+ED2I1wvs7T r6Lg== X-Gm-Message-State: AOAM531aqQsI5uWx4/bqXU+GNn5FcDeGQnX0W5MfeseclqPlioWEXff+ +9X1XXJ/mOPxV/A4HIRG/fHiyg== X-Google-Smtp-Source: ABdhPJyGohO4e+3lizetDAfnmuzcf5QMzfiAMeVyZMS3REu9yZqv6LDFsroY0eavwMSVaSHDGXWjcg== X-Received: by 2002:adf:c803:: with SMTP id d3mr18719800wrh.108.1604515017450; Wed, 04 Nov 2020 10:36:57 -0800 (PST) Received: from localhost ([2a01:4b00:8523:2d03:c8d2:30f2:53c6:bc2]) by smtp.gmail.com with ESMTPSA id a17sm4198738wra.61.2020.11.04.10.36.56 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 04 Nov 2020 10:36:56 -0800 (PST) From: David Brazdil To: kvmarm@lists.cs.columbia.edu Subject: [RFC PATCH 09/26] kvm: arm64: Move hyp-init params to a per-CPU struct Date: Wed, 4 Nov 2020 18:36:13 +0000 Message-Id: <20201104183630.27513-10-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_133658_723065_D61009C5 X-CRM114-Status: GOOD ( 23.51 ) 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 Once we start initializing KVM on newly booted cores before the rest of the kernel, parameters to __do_hyp_init will need to be provided by EL2 rather than EL1. At that point it will not be possible to pass its four arguments directly because PSCI_CPU_ON only supports one context argument. Refactor __do_hyp_init to accept its parameters in a struct. This prepares the code for KVM booting cores as well as removes any limits on the number of __do_hyp_init arguments. Signed-off-by: David Brazdil --- arch/arm64/include/asm/kvm_asm.h | 7 +++++++ arch/arm64/include/asm/kvm_hyp.h | 4 ++++ arch/arm64/kernel/asm-offsets.c | 4 ++++ arch/arm64/kvm/arm.c | 26 ++++++++++++++------------ arch/arm64/kvm/hyp/nvhe/hyp-init.S | 21 ++++++++++----------- arch/arm64/kvm/hyp/nvhe/hyp-main.c | 2 ++ 6 files changed, 41 insertions(+), 23 deletions(-) diff --git a/arch/arm64/include/asm/kvm_asm.h b/arch/arm64/include/asm/kvm_asm.h index 54387ccd1ab2..a49a87a186c3 100644 --- a/arch/arm64/include/asm/kvm_asm.h +++ b/arch/arm64/include/asm/kvm_asm.h @@ -150,6 +150,13 @@ extern void *__vhe_undefined_symbol; #endif +struct kvm_nvhe_init_params { + phys_addr_t pgd_ptr; + unsigned long tpidr_el2; + unsigned long hyp_stack_ptr; + unsigned long vector_ptr; +}; + /* 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 6b664de5ec1f..a3289071f3d8 100644 --- a/arch/arm64/include/asm/kvm_hyp.h +++ b/arch/arm64/include/asm/kvm_hyp.h @@ -15,6 +15,10 @@ DECLARE_PER_CPU(struct kvm_cpu_context, kvm_hyp_ctxt); DECLARE_PER_CPU(unsigned long, kvm_hyp_vector); +#ifdef __KVM_NVHE_HYPERVISOR__ +DECLARE_PER_CPU(struct kvm_nvhe_init_params, kvm_init_params); +#endif + #define read_sysreg_elx(r,nvh,vh) \ ({ \ u64 reg; \ diff --git a/arch/arm64/kernel/asm-offsets.c b/arch/arm64/kernel/asm-offsets.c index 7d32fc959b1a..0cbb86135c7c 100644 --- a/arch/arm64/kernel/asm-offsets.c +++ b/arch/arm64/kernel/asm-offsets.c @@ -110,6 +110,10 @@ int main(void) DEFINE(CPU_APGAKEYLO_EL1, offsetof(struct kvm_cpu_context, sys_regs[APGAKEYLO_EL1])); DEFINE(HOST_CONTEXT_VCPU, offsetof(struct kvm_cpu_context, __hyp_running_vcpu)); DEFINE(HOST_DATA_CONTEXT, offsetof(struct kvm_host_data, host_ctxt)); + DEFINE(NVHE_INIT_PGD_PTR, offsetof(struct kvm_nvhe_init_params, pgd_ptr)); + DEFINE(NVHE_INIT_TPIDR_EL2, offsetof(struct kvm_nvhe_init_params, tpidr_el2)); + DEFINE(NVHE_INIT_STACK_PTR, offsetof(struct kvm_nvhe_init_params, hyp_stack_ptr)); + DEFINE(NVHE_INIT_VECTOR_PTR, offsetof(struct kvm_nvhe_init_params, vector_ptr)); #endif #ifdef CONFIG_CPU_PM DEFINE(CPU_CTX_SP, offsetof(struct cpu_suspend_ctx, sp)); diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index 58e9cc183bd5..ff200fc8d653 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -50,6 +50,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); /* The VMID used in the VTTBR */ static atomic64_t kvm_vmid_gen = ATOMIC64_INIT(1); @@ -1331,10 +1332,7 @@ static int kvm_map_vectors(void) static void cpu_init_hyp_mode(void) { - phys_addr_t pgd_ptr; - unsigned long hyp_stack_ptr; - unsigned long vector_ptr; - unsigned long tpidr_el2; + struct kvm_nvhe_init_params *params = this_cpu_ptr_nvhe_sym(kvm_init_params); struct arm_smccc_res res; /* Switch from the HYP stub to our own HYP init vector */ @@ -1345,13 +1343,18 @@ static void cpu_init_hyp_mode(void) * kernel's mapping to the linear mapping, and store it in tpidr_el2 * so that we can use adr_l to access per-cpu variables in EL2. */ - tpidr_el2 = (unsigned long)this_cpu_ptr_nvhe_sym(__per_cpu_start) - - (unsigned long)kvm_ksym_ref(CHOOSE_NVHE_SYM(__per_cpu_start)); + params->tpidr_el2 = (unsigned long)this_cpu_ptr_nvhe_sym(__per_cpu_start) - + (unsigned long)kvm_ksym_ref(CHOOSE_NVHE_SYM(__per_cpu_start)); - pgd_ptr = kvm_mmu_get_httbr(); - hyp_stack_ptr = __this_cpu_read(kvm_arm_hyp_stack_page) + PAGE_SIZE; - hyp_stack_ptr = kern_hyp_va(hyp_stack_ptr); - vector_ptr = (unsigned long)kern_hyp_va(kvm_ksym_ref(__kvm_hyp_host_vector)); + params->pgd_ptr = kvm_mmu_get_httbr(); + params->vector_ptr = (unsigned long)kern_hyp_va(kvm_ksym_ref(__kvm_hyp_host_vector)); + params->hyp_stack_ptr = kern_hyp_va(__this_cpu_read(kvm_arm_hyp_stack_page) + PAGE_SIZE); + + /* + * Flush the init params from the data cache because the struct will + * be read from while the MMU is off. + */ + __flush_dcache_area(params, sizeof(*params)); /* * Call initialization code, and switch to the full blown HYP code. @@ -1360,8 +1363,7 @@ static void cpu_init_hyp_mode(void) * cpus_have_const_cap() wrapper. */ BUG_ON(!system_capabilities_finalized()); - arm_smccc_1_1_hvc(KVM_HOST_SMCCC_FUNC(__kvm_hyp_init), - pgd_ptr, tpidr_el2, hyp_stack_ptr, vector_ptr, &res); + arm_smccc_1_1_hvc(KVM_HOST_SMCCC_FUNC(__kvm_hyp_init), virt_to_phys(params), &res); WARN_ON(res.a0 != SMCCC_RET_SUCCESS); /* diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-init.S b/arch/arm64/kvm/hyp/nvhe/hyp-init.S index 96e70f976ff5..6f3ac5d428ec 100644 --- a/arch/arm64/kvm/hyp/nvhe/hyp-init.S +++ b/arch/arm64/kvm/hyp/nvhe/hyp-init.S @@ -47,10 +47,7 @@ __invalid: /* * x0: SMCCC function ID - * x1: HYP pgd - * x2: per-CPU offset - * x3: HYP stack - * x4: HYP vectors + * x1: struct kvm_nvhe_init_params PA */ __do_hyp_init: /* Check for a stub HVC call */ @@ -71,10 +68,16 @@ __do_hyp_init: mov x0, #SMCCC_RET_NOT_SUPPORTED eret -1: - /* Set tpidr_el2 for use by HYP to free a register */ - msr tpidr_el2, x2 +1: ldr x0, [x1, #NVHE_INIT_TPIDR_EL2] + msr tpidr_el2, x0 + ldr x0, [x1, #NVHE_INIT_STACK_PTR] + mov sp, x0 + + ldr x0, [x1, #NVHE_INIT_VECTOR_PTR] + msr vbar_el2, x0 + + ldr x1, [x1, #NVHE_INIT_PGD_PTR] phys_to_ttbr x0, x1 alternative_if ARM64_HAS_CNP orr x0, x0, #TTBR_CNP_BIT @@ -134,10 +137,6 @@ alternative_else_nop_endif msr sctlr_el2, x0 isb - /* Set the stack and new vectors */ - mov sp, x3 - msr vbar_el2, x4 - /* Hello, World! */ mov x0, #SMCCC_RET_SUCCESS eret diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-main.c b/arch/arm64/kvm/hyp/nvhe/hyp-main.c index e2eafe2c93af..411b0f652417 100644 --- a/arch/arm64/kvm/hyp/nvhe/hyp-main.c +++ b/arch/arm64/kvm/hyp/nvhe/hyp-main.c @@ -14,6 +14,8 @@ #include +DEFINE_PER_CPU(struct kvm_nvhe_init_params, kvm_init_params); + static void handle_host_hcall(unsigned long func_id, struct kvm_cpu_context *host_ctxt) { From patchwork Wed Nov 4 18:36:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Brazdil X-Patchwork-Id: 11881871 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=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 00F0FC2D0A3 for ; Wed, 4 Nov 2020 18:38:25 +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 7A9112067C for ; Wed, 4 Nov 2020 18:38:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="ty/8XlP5"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="NS23bt/7" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7A9112067C 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=pIjfXC66ehNyZQNYcjzqiEAaUMi6Oz4blW2AhK09mh0=; b=ty/8XlP5dikoBUTeHkrfaBhT2 q4OT2qq4SY1nWZKe3aCL6udRq7gPiiA/ftHCpMzWyrMGv1Efxd02zM5vB1ws/MhHmAeEFvattW1Jb fsuZ4qNUe8W9hfdVSQc0UANi7o0AkYKhU5ExK/KhkMaaeul34YHWs8AVm4DBDSxjNszRALnLotpw4 cU3tA1MaL1X/78oSwPr+wvM9M8DbzBtxAmq85+p/qAShDmU8R2Io76dKeV3RVy1KD4QNF0ygdvUFT fHE8Dl9yuBKWeTtc4CtgRpWZ/xHmRZQxr0L4tW+hIOM9HWnnKxt+cwOyD3nCFHgQcw6PIIoQaQN1h ocSVh95XA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaNfL-00027k-9l; Wed, 04 Nov 2020 18:37:51 +0000 Received: from mail-wm1-x344.google.com ([2a00:1450:4864:20::344]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaNeW-0001jQ-Sg for linux-arm-kernel@lists.infradead.org; Wed, 04 Nov 2020 18:37:01 +0000 Received: by mail-wm1-x344.google.com with SMTP id d142so3350184wmd.4 for ; Wed, 04 Nov 2020 10:37:00 -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=fuG04+12p5GokhKo0kAWDPgSX2S/UpZSRo8GkJtW9dc=; b=NS23bt/72SalQlPudTi1kUeX4t6arEB5xzntdPJJpX9s45iPtfgG25FglOu4DBwuIG qzomur1VBzBc4eT5elwu7R8DhwGP3UWqyIW03ua3R8FF0NAFV/hAEUHGoNvJ92aATLPG Hc50WuDGVvCyF2qvzN1oqJ0pQ/uzyS1xVgM5ySHGA/2Zr3YWI9emxF2G0MZ57rF8fn3+ /WnduyCd+eCb7wr0OK7Tmj46TiKZLTLrEnko/9u8/wjW6APOdTjHk+YdTtjnX/xbcKQT NyqveU6uNgHoKOBvg7H8nh/7Qu06IfYBzm8UD65hQ3YltPI1FpIYhhvcUu8MMntcXDCu 4+Gg== 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=fuG04+12p5GokhKo0kAWDPgSX2S/UpZSRo8GkJtW9dc=; b=kIBtvogfoU2hAS8L9Q1v7LOfowc8/TWiFVai85SuqXuhBNRo4nN/66OHRvqggZ/8s2 tFv/4MoXBIqX6oK7cf8nsy93nXYOZZxystJ40Uof7cEx9WmBtEPenKUurDUrhzKwBCxu 24GvHRqBvl9V51vg8BcMQgYefRWnYYh8p50Hxdd2Uq2Rn4brDSVs41SCW/tYcC6BMML6 +GnOxWLYaegsCwZZ/GLKThtp4jofqSuasEW07G28KMP8Rc9qaKBw9sLWNYSOytgolxd0 JEzX9o6UMkyDaLdhG4/wxli6lm3SwM9mojfDEiIR19n54/mon3kv5onyEX1zAGbAfffE buqQ== X-Gm-Message-State: AOAM531ehnpFEVe1/Os7RtCS6cAfeG58VUIyjQRGLhfiB4CWNZcFy3bM CgMwOy8fmm63OqOvxcpl4+cCTQ== X-Google-Smtp-Source: ABdhPJwMQ/dqr9JqMtNDYjvCoJDFSybTlMO7ZERHRXz8pPXtXsVsNjnOk5mwvRVZ/l0H0MUNKyXdMw== X-Received: by 2002:a1c:1d92:: with SMTP id d140mr6025920wmd.48.1604515019649; Wed, 04 Nov 2020 10:36:59 -0800 (PST) Received: from localhost ([2a01:4b00:8523:2d03:c8d2:30f2:53c6:bc2]) by smtp.gmail.com with ESMTPSA id o184sm3518971wmo.37.2020.11.04.10.36.58 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 04 Nov 2020 10:36:58 -0800 (PST) From: David Brazdil To: kvmarm@lists.cs.columbia.edu Subject: [RFC PATCH 10/26] kvm: arm64: Refactor handle_trap to use a switch Date: Wed, 4 Nov 2020 18:36:14 +0000 Message-Id: <20201104183630.27513-11-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_133700_960511_2361E620 X-CRM114-Status: GOOD ( 15.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 , 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 Small refactor so that nVHE's handle_trap uses a switch on the Exception Class value of ESR_EL2 in preparation for adding a handler of SMC32/64. Signed-off-by: David Brazdil --- arch/arm64/kvm/hyp/nvhe/hyp-main.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-main.c b/arch/arm64/kvm/hyp/nvhe/hyp-main.c index 411b0f652417..19332c20fcde 100644 --- a/arch/arm64/kvm/hyp/nvhe/hyp-main.c +++ b/arch/arm64/kvm/hyp/nvhe/hyp-main.c @@ -16,9 +16,9 @@ DEFINE_PER_CPU(struct kvm_nvhe_init_params, kvm_init_params); -static void handle_host_hcall(unsigned long func_id, - struct kvm_cpu_context *host_ctxt) +static void handle_host_hcall(struct kvm_cpu_context *host_ctxt) { + unsigned long func_id = host_ctxt->regs.regs[0]; unsigned long ret = 0; switch (func_id) { @@ -109,11 +109,12 @@ static void handle_host_hcall(unsigned long func_id, void handle_trap(struct kvm_cpu_context *host_ctxt) { u64 esr = read_sysreg_el2(SYS_ESR); - unsigned long func_id; - if (ESR_ELx_EC(esr) != ESR_ELx_EC_HVC64) + switch (ESR_ELx_EC(esr)) { + case ESR_ELx_EC_HVC64: + handle_host_hcall(host_ctxt); + break; + default: hyp_panic(); - - func_id = host_ctxt->regs.regs[0]; - handle_host_hcall(func_id, host_ctxt); + } } From patchwork Wed Nov 4 18:36:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Brazdil X-Patchwork-Id: 11881891 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 D2386C2D0A3 for ; Wed, 4 Nov 2020 18:39:57 +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 59C4D20719 for ; Wed, 4 Nov 2020 18:39:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="P3djBdgi"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="FLweM/ej" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 59C4D20719 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=M0SpLzz2Eqx09uipzgcN8vI6opMSsrP4tR6inTCmqEg=; b=P3djBdgiHmeQiSfmF2pDRmXLF SdATkmuiX/rKSF/0MmUzY4fszTQ4f7qP0T+Cd+zI3ZT1zHWCHR2RhAqu7h/UzaHMBtCpf61nOl7Uz aasbCy2Xxp4XIluBje2fKfZiyS9LD0A12ubc0EVDh8F2EDS08yYykZPMTi0cqud8v7Im0vNbFH7sF ep5zpBSnsOdj99FJeOTjFUerOajuUx5gIqPcgxQSS+rtauI6JhS6wHa6MQPYr/HB3KGW6UnMuJSWR oYKpIp1uYgiOAeFN+mk6kdOhog2JaWKVGSOeaTKa3Kafi1QE/FvM0sqSD8XYOrc4TH4B/YYfUECy9 LNU94gfVA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaNfQ-0002AV-D0; Wed, 04 Nov 2020 18:37:56 +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 1kaNeY-0001kd-Vx for linux-arm-kernel@lists.infradead.org; Wed, 04 Nov 2020 18:37:04 +0000 Received: by mail-wr1-x443.google.com with SMTP id x7so23174308wrl.3 for ; Wed, 04 Nov 2020 10:37: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=/XiV/xyb/oxQezDPGz4nuk7rPAgGA4WPoABo7GSZc9U=; b=FLweM/ejVr077kt0BxmdZaKLd2NUAGBLdt+Xl5KQzdfFcd9eF/LMXEJkokLPMvZ9a+ hfbaQBGyseo9Pjpe7H+nKEg0+XrUdvlLF/nV2x/ZSde0pRjpgPJY/Um/hMqgsTD90wwc OYPTWLv1C4npRdBqUhp0CevNYBo0Rmolnkb1HOJjOjVAZ661Yt6IzHQRlpZ++EJt+IWz 3mX+P84xaR5OVWKfCPw/fOtDeXCD3GJsZnZQflX2GciuAoBoY11KAomfoUIuLSkuHSxX VGWMamcEk03fKaFJCYnRnqf5iSPiM/ljk6Hni9VeH26F5Rm/beemSXp3OYyoVAeRfGqh LMAA== 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=/XiV/xyb/oxQezDPGz4nuk7rPAgGA4WPoABo7GSZc9U=; b=ZMt+n2QGL6RtX6oqInGmWVvgc02tqxmSZEFiUSDEMOGm6Sw56XdpdN0MWsbL0ltYf4 kwnHhddtC9mLZire0n2cJofQpCeGYgTqW7AtGr9cc13AN5hDGlbB/IuHZERouPLAKJ8B hxUEWKX7aaEUnZHknfvl4JVrnYJ7/kKQrdn9NQO4NATucNE8S1lMdgNVvgOse6ygvx3R zuAgjoxO8zGBWUhJ/DgWtbG3NSBjny16uG078ZtTA2o4M+j/bBKXunTVT5HM5j2BRfpF WNCYtkpYNF+FCl0hFZhc023f/gjMpvrn7MQL5p7JAy9kUjcb0+lWLnEEciuVQf4CQsns nVYA== X-Gm-Message-State: AOAM533Jxqw1uKTBayoNigvUMGmv+Z/G3arBYOTC+48s+rG7s7iku4SE 1LXuHzUxvuKVUbDQ7axk2QHyoQ== X-Google-Smtp-Source: ABdhPJzUgDZWj99m0uouOyqL4e10XiJmy4BzKukc0Nq24Pn4sGnHwgjUMV0dshR/F19abv/jzM7BOg== X-Received: by 2002:adf:e94b:: with SMTP id m11mr33547026wrn.35.1604515021782; Wed, 04 Nov 2020 10:37:01 -0800 (PST) Received: from localhost ([2a01:4b00:8523:2d03:c8d2:30f2:53c6:bc2]) by smtp.gmail.com with ESMTPSA id d3sm1047189wrg.16.2020.11.04.10.37.00 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 04 Nov 2020 10:37:00 -0800 (PST) From: David Brazdil To: kvmarm@lists.cs.columbia.edu Subject: [RFC PATCH 11/26] kvm: arm64: Extract parts of el2_setup into a macro Date: Wed, 4 Nov 2020 18:36:15 +0000 Message-Id: <20201104183630.27513-12-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_133703_168908_D8F9C879 X-CRM114-Status: GOOD ( 23.75 ) 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 When the a CPU is booted in EL2, the kernel checks for VHE support and initializes the CPU core accordingly. For nVHE it also installs the stub vectors and drops down to EL1. Once KVM gains the ability to boot cores without going through the kernel entry point, it will need to initialize the CPU the same way. Extract the relevant bits of el2_setup into init_el2_state macro with an argument specifying whether to initialize for VHE or nVHE. No functional change. Size of el2_setup increased by 148 bytes due to duplication. Signed-off-by: David Brazdil --- arch/arm64/include/asm/kvm_asm.h | 128 ++++++++++++++++++++++++++++ arch/arm64/kernel/head.S | 140 +++---------------------------- 2 files changed, 141 insertions(+), 127 deletions(-) diff --git a/arch/arm64/include/asm/kvm_asm.h b/arch/arm64/include/asm/kvm_asm.h index a49a87a186c3..893327d1e449 100644 --- a/arch/arm64/include/asm/kvm_asm.h +++ b/arch/arm64/include/asm/kvm_asm.h @@ -331,6 +331,134 @@ extern char __smccc_workaround_1_smc[__SMCCC_WORKAROUND_1_SMC_SZ]; msr sp_el0, \tmp .endm +.macro init_el2_state mode + +.ifnes "\mode", "vhe" +.ifnes "\mode", "nvhe" +.error "Invalid 'mode' argument" +.endif +.endif + + mov_q x0, (SCTLR_EL2_RES1 | ENDIAN_SET_EL2) + msr sctlr_el2, x0 + isb + + /* + * Allow Non-secure EL1 and EL0 to access physical timer and counter. + * This is not necessary for VHE, since the host kernel runs in EL2, + * and EL0 accesses are configured in the later stage of boot process. + * Note that when HCR_EL2.E2H == 1, CNTHCTL_EL2 has the same bit layout + * as CNTKCTL_EL1, and CNTKCTL_EL1 accessing instructions are redefined + * to access CNTHCTL_EL2. This allows the kernel designed to run at EL1 + * to transparently mess with the EL0 bits via CNTKCTL_EL1 access in + * EL2. + */ +.ifeqs "\mode", "nvhe" + mrs x0, cnthctl_el2 + orr x0, x0, #3 // Enable EL1 physical timers + msr cnthctl_el2, x0 +.endif + msr cntvoff_el2, xzr // Clear virtual offset + +#ifdef CONFIG_ARM_GIC_V3 + /* GICv3 system register access */ + mrs x0, id_aa64pfr0_el1 + ubfx x0, x0, #ID_AA64PFR0_GIC_SHIFT, #4 + cbz x0, 3f + + mrs_s x0, SYS_ICC_SRE_EL2 + orr x0, x0, #ICC_SRE_EL2_SRE // Set ICC_SRE_EL2.SRE==1 + orr x0, x0, #ICC_SRE_EL2_ENABLE // Set ICC_SRE_EL2.Enable==1 + msr_s SYS_ICC_SRE_EL2, x0 + isb // Make sure SRE is now set + mrs_s x0, SYS_ICC_SRE_EL2 // Read SRE back, + tbz x0, #0, 3f // and check that it sticks + msr_s SYS_ICH_HCR_EL2, xzr // Reset ICC_HCR_EL2 to defaults +3: +#endif + + /* Populate ID registers. */ + mrs x0, midr_el1 + mrs x1, mpidr_el1 + msr vpidr_el2, x0 + msr vmpidr_el2, x1 + +#ifdef CONFIG_COMPAT + msr hstr_el2, xzr // Disable CP15 traps to EL2 +#endif + + /* EL2 debug */ + mrs x1, id_aa64dfr0_el1 + sbfx x0, x1, #ID_AA64DFR0_PMUVER_SHIFT, #4 + cmp x0, #1 + b.lt 4f // Skip if no PMU present + mrs x0, pmcr_el0 // Disable debug access traps + ubfx x0, x0, #11, #5 // to EL2 and allow access to +4: + csel x3, xzr, x0, lt // all PMU counters from EL1 + + /* Statistical profiling */ + ubfx x0, x1, #ID_AA64DFR0_PMSVER_SHIFT, #4 + cbz x0, 7f // Skip if SPE not present +.ifeqs "\mode", "nvhe" + mrs_s x4, SYS_PMBIDR_EL1 // If SPE available at EL2, + and x4, x4, #(1 << SYS_PMBIDR_EL1_P_SHIFT) + cbnz x4, 5f // then permit sampling of physical + mov x4, #(1 << SYS_PMSCR_EL2_PCT_SHIFT | \ + 1 << SYS_PMSCR_EL2_PA_SHIFT) + msr_s SYS_PMSCR_EL2, x4 // addresses and physical counter +5: + mov x1, #(MDCR_EL2_E2PB_MASK << MDCR_EL2_E2PB_SHIFT) + orr x3, x3, x1 // If we don't have VHE, then + b 7f // use EL1&0 translation. +.endif + orr x3, x3, #MDCR_EL2_TPMS // and disable access from EL1 +7: + msr mdcr_el2, x3 // Configure debug traps + + /* LORegions */ + mrs x1, id_aa64mmfr1_el1 + ubfx x0, x1, #ID_AA64MMFR1_LOR_SHIFT, 4 + cbz x0, 1f + msr_s SYS_LORC_EL1, xzr +1: + + /* Stage-2 translation */ + msr vttbr_el2, xzr + +.ifeqs "\mode", "nvhe" + /* + * When VHE is not in use, early init of EL2 and EL1 needs to be + * done here. + * When VHE _is_ in use, EL1 will not be used in the host and + * requires no configuration, and all non-hyp-specific EL2 setup + * will be done via the _EL1 system register aliases in __cpu_setup. + */ + mov_q x0, (SCTLR_EL1_RES1 | ENDIAN_SET_EL1) + msr sctlr_el1, x0 + + /* Coprocessor traps. */ + mov x0, #0x33ff + msr cptr_el2, x0 // Disable copro. traps to EL2 + + /* SVE register access */ + mrs x1, id_aa64pfr0_el1 + ubfx x1, x1, #ID_AA64PFR0_SVE_SHIFT, #4 + cbz x1, 7f + + bic x0, x0, #CPTR_EL2_TZ // Also disable SVE traps + msr cptr_el2, x0 // Disable copro. traps to EL2 + isb + mov x1, #ZCR_ELx_LEN_MASK // SVE: Enable full vector + msr_s SYS_ZCR_EL2, x1 // length for EL1. + + /* spsr */ +7: mov x0, #(PSR_F_BIT | PSR_I_BIT | PSR_A_BIT | PSR_D_BIT |\ + PSR_MODE_EL1h) + msr spsr_el2, x0 +.endif +.endm + #endif #endif /* __ARM_KVM_ASM_H__ */ diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S index d8d9caf02834..e7270b63abed 100644 --- a/arch/arm64/kernel/head.S +++ b/arch/arm64/kernel/head.S @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -499,153 +500,38 @@ SYM_FUNC_START(el2_setup) isb ret -1: mov_q x0, (SCTLR_EL2_RES1 | ENDIAN_SET_EL2) - msr sctlr_el2, x0 - +1: #ifdef CONFIG_ARM64_VHE /* - * Check for VHE being present. For the rest of the EL2 setup, - * x2 being non-zero indicates that we do have VHE, and that the - * kernel is intended to run at EL2. + * Check for VHE being present. x2 being non-zero indicates that we + * do have VHE, and that the kernel is intended to run at EL2. */ mrs x2, id_aa64mmfr1_el1 ubfx x2, x2, #ID_AA64MMFR1_VHE_SHIFT, #4 -#else - mov x2, xzr -#endif + cbz x2, el2_setup_nvhe - /* Hyp configuration. */ - mov_q x0, HCR_HOST_NVHE_FLAGS - cbz x2, set_hcr mov_q x0, HCR_HOST_VHE_FLAGS -set_hcr: msr hcr_el2, x0 isb - /* - * Allow Non-secure EL1 and EL0 to access physical timer and counter. - * This is not necessary for VHE, since the host kernel runs in EL2, - * and EL0 accesses are configured in the later stage of boot process. - * Note that when HCR_EL2.E2H == 1, CNTHCTL_EL2 has the same bit layout - * as CNTKCTL_EL1, and CNTKCTL_EL1 accessing instructions are redefined - * to access CNTHCTL_EL2. This allows the kernel designed to run at EL1 - * to transparently mess with the EL0 bits via CNTKCTL_EL1 access in - * EL2. - */ - cbnz x2, 1f - mrs x0, cnthctl_el2 - orr x0, x0, #3 // Enable EL1 physical timers - msr cnthctl_el2, x0 -1: - msr cntvoff_el2, xzr // Clear virtual offset - -#ifdef CONFIG_ARM_GIC_V3 - /* GICv3 system register access */ - mrs x0, id_aa64pfr0_el1 - ubfx x0, x0, #ID_AA64PFR0_GIC_SHIFT, #4 - cbz x0, 3f - - mrs_s x0, SYS_ICC_SRE_EL2 - orr x0, x0, #ICC_SRE_EL2_SRE // Set ICC_SRE_EL2.SRE==1 - orr x0, x0, #ICC_SRE_EL2_ENABLE // Set ICC_SRE_EL2.Enable==1 - msr_s SYS_ICC_SRE_EL2, x0 - isb // Make sure SRE is now set - mrs_s x0, SYS_ICC_SRE_EL2 // Read SRE back, - tbz x0, #0, 3f // and check that it sticks - msr_s SYS_ICH_HCR_EL2, xzr // Reset ICC_HCR_EL2 to defaults - -3: -#endif - - /* Populate ID registers. */ - mrs x0, midr_el1 - mrs x1, mpidr_el1 - msr vpidr_el2, x0 - msr vmpidr_el2, x1 - -#ifdef CONFIG_COMPAT - msr hstr_el2, xzr // Disable CP15 traps to EL2 -#endif - - /* EL2 debug */ - mrs x1, id_aa64dfr0_el1 - sbfx x0, x1, #ID_AA64DFR0_PMUVER_SHIFT, #4 - cmp x0, #1 - b.lt 4f // Skip if no PMU present - mrs x0, pmcr_el0 // Disable debug access traps - ubfx x0, x0, #11, #5 // to EL2 and allow access to -4: - csel x3, xzr, x0, lt // all PMU counters from EL1 - - /* Statistical profiling */ - ubfx x0, x1, #ID_AA64DFR0_PMSVER_SHIFT, #4 - cbz x0, 7f // Skip if SPE not present - cbnz x2, 6f // VHE? - mrs_s x4, SYS_PMBIDR_EL1 // If SPE available at EL2, - and x4, x4, #(1 << SYS_PMBIDR_EL1_P_SHIFT) - cbnz x4, 5f // then permit sampling of physical - mov x4, #(1 << SYS_PMSCR_EL2_PCT_SHIFT | \ - 1 << SYS_PMSCR_EL2_PA_SHIFT) - msr_s SYS_PMSCR_EL2, x4 // addresses and physical counter -5: - mov x1, #(MDCR_EL2_E2PB_MASK << MDCR_EL2_E2PB_SHIFT) - orr x3, x3, x1 // If we don't have VHE, then - b 7f // use EL1&0 translation. -6: // For VHE, use EL2 translation - orr x3, x3, #MDCR_EL2_TPMS // and disable access from EL1 -7: - msr mdcr_el2, x3 // Configure debug traps - - /* LORegions */ - mrs x1, id_aa64mmfr1_el1 - ubfx x0, x1, #ID_AA64MMFR1_LOR_SHIFT, 4 - cbz x0, 1f - msr_s SYS_LORC_EL1, xzr -1: - - /* Stage-2 translation */ - msr vttbr_el2, xzr - - cbz x2, install_el2_stub + init_el2_state vhe mov w0, #BOOT_CPU_MODE_EL2 // This CPU booted in EL2 isb ret +#endif -SYM_INNER_LABEL(install_el2_stub, SYM_L_LOCAL) - /* - * When VHE is not in use, early init of EL2 and EL1 needs to be - * done here. - * When VHE _is_ in use, EL1 will not be used in the host and - * requires no configuration, and all non-hyp-specific EL2 setup - * will be done via the _EL1 system register aliases in __cpu_setup. - */ - mov_q x0, (SCTLR_EL1_RES1 | ENDIAN_SET_EL1) - msr sctlr_el1, x0 - - /* Coprocessor traps. */ - mov x0, #0x33ff - msr cptr_el2, x0 // Disable copro. traps to EL2 - - /* SVE register access */ - mrs x1, id_aa64pfr0_el1 - ubfx x1, x1, #ID_AA64PFR0_SVE_SHIFT, #4 - cbz x1, 7f - - bic x0, x0, #CPTR_EL2_TZ // Also disable SVE traps - msr cptr_el2, x0 // Disable copro. traps to EL2 +SYM_INNER_LABEL(el2_setup_nvhe, SYM_L_LOCAL) + mov_q x0, HCR_HOST_NVHE_FLAGS + msr hcr_el2, x0 isb - mov x1, #ZCR_ELx_LEN_MASK // SVE: Enable full vector - msr_s SYS_ZCR_EL2, x1 // length for EL1. + + init_el2_state nvhe /* Hypervisor stub */ -7: adr_l x0, __hyp_stub_vectors + adr_l x0, __hyp_stub_vectors msr vbar_el2, x0 - /* spsr */ - mov x0, #(PSR_F_BIT | PSR_I_BIT | PSR_A_BIT | PSR_D_BIT |\ - PSR_MODE_EL1h) - msr spsr_el2, x0 msr elr_el2, lr mov w0, #BOOT_CPU_MODE_EL2 // This CPU booted in EL2 eret From patchwork Wed Nov 4 18:36:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Brazdil X-Patchwork-Id: 11881879 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 39831C4742C for ; Wed, 4 Nov 2020 18:38: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 BEBC720719 for ; Wed, 4 Nov 2020 18:38:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="SPHZNyRk"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="hv2R5Zu/" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BEBC720719 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=GHGd61FN3+GaHIWKCtlFpy6Pc6WZ8NA5lSDLVPRDlcg=; b=SPHZNyRkOAyu/KTNiUzL/RWQD RpP5vdIcaxzgtHAWmoJCjjv6Zngmf4/6yAZCfVJ5nuwKs8fgkYt6vxcTn8WG5m1NI2xdhAYNG9gSr 2jXo7BDSrBZ774aaL17VRhMV2bn76iJRuV+pimPs6DNf7+j4mnQES+LhQzdTEftDLUW+YHhbNXLPU KJ+kpgVzky5NQl9UdxFCjnqI24aTUb7mDD92XZp6pRQnT3AInRT9dBsByDkuKfUuyJGN4Hzv9ssru Ze+rLSyd/5gCITcEnyg/YX0NvOEQ/jhJNwihA9qvEbpm6+rI0jtgehPH3Aw0AnM2Hr2Vn/xTCggmM yPSrFSLJA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaNfZ-0002Gr-LG; Wed, 04 Nov 2020 18:38:05 +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 1kaNeb-0001lQ-It for linux-arm-kernel@lists.infradead.org; Wed, 04 Nov 2020 18:37:06 +0000 Received: by mail-wr1-x442.google.com with SMTP id k10so21832940wrw.13 for ; Wed, 04 Nov 2020 10:37:05 -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=nKgIpHjS/zdI3tb1vXzwoiiNM/jjodo8Otz1dws/lFM=; b=hv2R5Zu/z6mSOSF7dEe47i7r5T2cQPVysT7HoseP6g1eSaz6nNutmQSMgNBOdCt8eb PBT+5ilqIWofeWIil70QAAfQ++jMMGIDYwQCqScBeSD6s1/xacLom1Lg7Y6fr07ETPLc T5oVlB+HcrdVLb2F6SrnRwFCeUH9eLTNlKI8QXPxO6kK7HuFF6bgPtuTH+9dGZYRnmHe uXqrakMk7K/yAkrJV315umztyia9WU0yS91B2aTAWtmZ3Vxtl5rRie/Z8nLO2muqf32T +md4szIJBymJW9d9MDCf+3bjNANk8thtWZ0W8yjJnHGaSBHiCNp86qmYoNJNVZIuipRO Tl6A== 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=nKgIpHjS/zdI3tb1vXzwoiiNM/jjodo8Otz1dws/lFM=; b=pmTEz2JqLjU5+0xI5BW6dyif5y8Kd/XV9PP4rQ5R2X2llFdmY20c7uCv3fsn7jNIZV MUxn03TInLBNHAX45D524PcZ34LYSrlXi7IRj7ItTb/r9Cu8LL5Ez58s9h6s4vG2Igbx xw4h6GiqtyTWjv3nHAlkYmqJqJeYIG2wOY7BnTwH/yDcpa1YypO/7VodYAQR153cqwD2 z0OPmoN6eoJCYDwoU3YqmlWlHywnK5vfsOlIKgDJawofKKgL2iPrkSkYWcTxSGY0Bx7C BNSO+PwcDJJ6AMxSjGzDtA92iWUFK6e2zvdDfiGSwtFQ/I8I9Idr2eaoo7O3ZH7NcOPJ URUg== X-Gm-Message-State: AOAM532oSo3EvQkK69YiYoNRLQmwxTK1olTSJX44awwh25LgGW/jRXmZ TPEhDZUI5KBR7HOtCGJHCykKmg== X-Google-Smtp-Source: ABdhPJw7mLZKqMBluuUKvkKmIlrqh8pTnCd64tbISLpXPLgmZa+Ae3kp7ph+K6q6eNWevcaZKm0Gcw== X-Received: by 2002:a5d:5387:: with SMTP id d7mr33257971wrv.224.1604515023950; Wed, 04 Nov 2020 10:37:03 -0800 (PST) Received: from localhost ([2a01:4b00:8523:2d03:c8d2:30f2:53c6:bc2]) by smtp.gmail.com with ESMTPSA id t11sm3428092wmf.35.2020.11.04.10.37.02 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 04 Nov 2020 10:37:02 -0800 (PST) From: David Brazdil To: kvmarm@lists.cs.columbia.edu Subject: [RFC PATCH 12/26] kvm: arm64: Add SMC handler in nVHE EL2 Date: Wed, 4 Nov 2020 18:36:16 +0000 Message-Id: <20201104183630.27513-13-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_133705_801724_058E3649 X-CRM114-Status: GOOD ( 15.95 ) 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 Add handler of host SMCs in KVM nVHE trap handler. Forward all SMCs to EL3 and propagate the result back to EL1. This is done in preparation for validating host SMCs. Signed-off-by: David Brazdil --- arch/arm64/kvm/hyp/nvhe/hyp-main.c | 36 ++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-main.c b/arch/arm64/kvm/hyp/nvhe/hyp-main.c index 19332c20fcde..fffc2dc09a1f 100644 --- a/arch/arm64/kvm/hyp/nvhe/hyp-main.c +++ b/arch/arm64/kvm/hyp/nvhe/hyp-main.c @@ -106,6 +106,38 @@ static void handle_host_hcall(struct kvm_cpu_context *host_ctxt) host_ctxt->regs.regs[1] = ret; } +static void skip_host_instruction(void) +{ + write_sysreg_el2(read_sysreg_el2(SYS_ELR) + 4, SYS_ELR); +} + +static void forward_host_smc(struct kvm_cpu_context *host_ctxt) +{ + struct arm_smccc_res res; + + arm_smccc_1_1_smc(host_ctxt->regs.regs[0], host_ctxt->regs.regs[1], + host_ctxt->regs.regs[2], host_ctxt->regs.regs[3], + host_ctxt->regs.regs[4], host_ctxt->regs.regs[5], + host_ctxt->regs.regs[6], host_ctxt->regs.regs[7], + &res); + host_ctxt->regs.regs[0] = res.a0; + host_ctxt->regs.regs[1] = res.a1; + host_ctxt->regs.regs[2] = res.a2; + host_ctxt->regs.regs[3] = res.a3; +} + +static void handle_host_smc(struct kvm_cpu_context *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(); + + /* Forward SMC not handled in EL2 to EL3. */ + forward_host_smc(host_ctxt); +} + void handle_trap(struct kvm_cpu_context *host_ctxt) { u64 esr = read_sysreg_el2(SYS_ESR); @@ -114,6 +146,10 @@ void handle_trap(struct kvm_cpu_context *host_ctxt) case ESR_ELx_EC_HVC64: handle_host_hcall(host_ctxt); break; + case ESR_ELx_EC_SMC32: + case ESR_ELx_EC_SMC64: + handle_host_smc(host_ctxt); + break; default: hyp_panic(); } From patchwork Wed Nov 4 18:36:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Brazdil X-Patchwork-Id: 11881893 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 D3797C2D0A3 for ; Wed, 4 Nov 2020 18:40:10 +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 4EA132067C for ; Wed, 4 Nov 2020 18:40:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="iZJm9a8I"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="bnzTyIjl" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4EA132067C 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=7+esqcG9wikNUvSouj0GduOu890fsCrDkBKkF3wZJcg=; b=iZJm9a8ILnyP8WGy/F4VNbMgV J5GDVTWNKIi2oVH3nGcU5Z7a9WqhIsACsivI8ol37pQueXKpI9TOwa3e4TqI6zuoSRtD4LIZbTCVR eVAf1CFGgiRZFAtGtcwJNfa1nrmI0E+9LuJ++huz8Z0R1KR/wOr1htWXwpx7aGIYS/XThULBPdQpj xDm/eH458ewTZQ5gcrZ+EL88FjHwZmYRoEnDm4FX800hPs64szxU0NogxiP8FrLlIPVFPdbCj9vPf wTIxQAhqve/2+eWJJIJvukqPlqJmu0P1jpDaK2jHIQ9uIUiUSYdv/40P/G/GaF/ZEAMvYmN/TAXFC ojz5Sv96g==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaNfi-0002KA-1A; Wed, 04 Nov 2020 18:38:14 +0000 Received: from mail-wm1-x344.google.com ([2a00:1450:4864:20::344]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaNed-0001mX-2h for linux-arm-kernel@lists.infradead.org; Wed, 04 Nov 2020 18:37:08 +0000 Received: by mail-wm1-x344.google.com with SMTP id c18so3358610wme.2 for ; Wed, 04 Nov 2020 10:37:07 -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=B3d+QzOWawlq1O6qWW0gNBz2FTnwOmMHRq4HC+NVGn4=; b=bnzTyIjlyJiHyVe/d6fBeFTtZRk669wctKitVdZxL5eKRvHxekGaYaGcRkjMCnl+DJ NjrSTTKOO9SW5Up/qmMYqUnzUmpQTjhj/sMMMz8AhJTotYOXxVNy93wWdmv+JUht97Ao HNiPunbAncmDK5pB2s19mi4k1gFA/znMfI+oF77UIpwdETFox1QsQrbACiN6Wf3osi+v tzt2Pv3lRAYXItcD5VHXEh88CFzwhr65Oex5GMhkAIEzdLdD8yqxL6kdqk6I1wGuNgt5 VXhuHizaJ1OH4LXIlE74pCuUSg4sl7s20qWpBYUEqQTHorjOPMWW2ioRSnfrkL4Sj5WB na9Q== 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=B3d+QzOWawlq1O6qWW0gNBz2FTnwOmMHRq4HC+NVGn4=; b=dGWmMLCEIh4sW1u5hxgjfBO2rlwSfgmbxIMBCtwmCqeUtkj/vSmelnkke3vLtlP7aX KokMHAA7hVt8XBljdRlbzswD754QAiXevxsBOmCL9pfKcjEZwnqdgSyKI0z6oiAxQ6Bk /RhfS88kRcD6F43IgJyLGWwQgdTQE3OySir+WadBEoLuNdrWWoelTP7sVoH1B9215cKg EVgxRC/qp2QtxDJxXydjdGOND70IiihYXUNeupYjsLDvDbp2NRoZoNXipCi9TBM0J+gs RKexMAOhvREO9FUIWf5lJi3ND7rrlM9jFpnvw3ccpQA86qnC9VOoRj0UyDGQg09DTaqy JUGg== X-Gm-Message-State: AOAM532HCzjZndhJZm1KE3wCU77GbuHWnNGIw6e4TJr0pEqDmvHTKiKt x2aeEHQlPMlTkbOakM5XZ7UvXw== X-Google-Smtp-Source: ABdhPJxVS5jWFGrlmaTy+L20ANnS0eCOXwmlYOy6SIM8Ix3vFBWONSxQVU6NleEARPZn0hYfOxSTpw== X-Received: by 2002:a05:600c:22d7:: with SMTP id 23mr6155656wmg.67.1604515025991; Wed, 04 Nov 2020 10:37:05 -0800 (PST) Received: from localhost ([2a01:4b00:8523:2d03:c8d2:30f2:53c6:bc2]) by smtp.gmail.com with ESMTPSA id v6sm3660726wrs.39.2020.11.04.10.37.04 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 04 Nov 2020 10:37:05 -0800 (PST) From: David Brazdil To: kvmarm@lists.cs.columbia.edu Subject: [RFC PATCH 13/26] kvm: arm64: Bootstrap PSCI SMC handler in nVHE EL2 Date: Wed, 4 Nov 2020 18:36:17 +0000 Message-Id: <20201104183630.27513-14-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_133707_173688_7536A041 X-CRM114-Status: GOOD ( 27.98 ) 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 Add a handler of PSCI SMCs in nVHE hyp code. The handler is initialized with the version used by the host's PSCI driver and the function IDs it was configured with. If the SMC function ID matches one of the configured PSCI calls (for v0.1) or falls into the PSCI function ID range (for v0.2+), the SMC is handled by the PSCI handler. For now, all SMCs return PSCI_RET_NOT_SUPPORTED. Signed-off-by: David Brazdil --- arch/arm64/include/asm/kvm_hyp.h | 4 ++ arch/arm64/kvm/arm.c | 12 ++++ arch/arm64/kvm/hyp/nvhe/Makefile | 2 +- arch/arm64/kvm/hyp/nvhe/hyp-main.c | 4 ++ arch/arm64/kvm/hyp/nvhe/psci.c | 102 +++++++++++++++++++++++++++++ include/uapi/linux/psci.h | 1 + 6 files changed, 124 insertions(+), 1 deletion(-) create mode 100644 arch/arm64/kvm/hyp/nvhe/psci.c diff --git a/arch/arm64/include/asm/kvm_hyp.h b/arch/arm64/include/asm/kvm_hyp.h index a3289071f3d8..95a2bbbcc7e1 100644 --- a/arch/arm64/include/asm/kvm_hyp.h +++ b/arch/arm64/include/asm/kvm_hyp.h @@ -96,6 +96,10 @@ void deactivate_traps_vhe_put(void); u64 __guest_enter(struct kvm_vcpu *vcpu); +#ifdef __KVM_NVHE_HYPERVISOR__ +bool kvm_host_psci_handler(struct kvm_cpu_context *host_ctxt); +#endif + void __noreturn hyp_panic(void); #ifdef __KVM_NVHE_HYPERVISOR__ void __noreturn __hyp_do_panic(bool restore_host, u64 spsr, u64 elr, u64 par); diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index ff200fc8d653..cedec793da64 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #define CREATE_TRACE_POINTS @@ -1498,6 +1499,16 @@ static void init_cpu_logical_map(void) CHOOSE_NVHE_SYM(__cpu_logical_map)[cpu] = cpu_logical_map(cpu); } +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]; + + 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)); +} + static int init_common_resources(void) { return kvm_set_ipa_limit(); @@ -1676,6 +1687,7 @@ static int init_hyp_mode(void) } init_cpu_logical_map(); + init_psci(); return 0; diff --git a/arch/arm64/kvm/hyp/nvhe/Makefile b/arch/arm64/kvm/hyp/nvhe/Makefile index c45f440cce51..647b63337a51 100644 --- a/arch/arm64/kvm/hyp/nvhe/Makefile +++ b/arch/arm64/kvm/hyp/nvhe/Makefile @@ -7,7 +7,7 @@ asflags-y := -D__KVM_NVHE_HYPERVISOR__ ccflags-y := -D__KVM_NVHE_HYPERVISOR__ obj-y := timer-sr.o sysreg-sr.o debug-sr.o switch.o tlb.o hyp-init.o host.o \ - hyp-main.o percpu.o + hyp-main.o percpu.o psci.o obj-y += ../vgic-v3-sr.o ../aarch32.o ../vgic-v2-cpuif-proxy.o ../entry.o \ ../fpsimd.o ../hyp-entry.o diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-main.c b/arch/arm64/kvm/hyp/nvhe/hyp-main.c index fffc2dc09a1f..aa54db514550 100644 --- a/arch/arm64/kvm/hyp/nvhe/hyp-main.c +++ b/arch/arm64/kvm/hyp/nvhe/hyp-main.c @@ -134,6 +134,10 @@ static void handle_host_smc(struct kvm_cpu_context *host_ctxt) */ skip_host_instruction(); + /* Try to handle host's PSCI SMCs. */ + if (kvm_host_psci_handler(host_ctxt)) + return; + /* Forward SMC not handled in EL2 to EL3. */ forward_host_smc(host_ctxt); } diff --git a/arch/arm64/kvm/hyp/nvhe/psci.c b/arch/arm64/kvm/hyp/nvhe/psci.c new file mode 100644 index 000000000000..82d3b2c89658 --- /dev/null +++ b/arch/arm64/kvm/hyp/nvhe/psci.c @@ -0,0 +1,102 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (C) 2020 - Google LLC + * Author: David Brazdil + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +/* Config options set by the host. */ +u32 kvm_host_psci_version = PSCI_VERSION(0, 0); +u32 kvm_host_psci_function_id[PSCI_FN_MAX]; + +static u64 get_psci_func_id(struct kvm_cpu_context *host_ctxt) +{ + return host_ctxt->regs.regs[0]; +} + +static bool is_psci_0_1_call(u64 func_id) +{ + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(kvm_host_psci_function_id); ++i) { + if (func_id == kvm_host_psci_function_id[i]) + return true; + } + return false; +} + +static bool is_psci_0_2_fn_call(u64 func_id) +{ + u64 base = func_id & ~PSCI_0_2_FN_ID_MASK; + + return base == PSCI_0_2_FN_BASE || base == PSCI_0_2_FN64_BASE; +} + +static bool is_psci_call(u64 func_id) +{ + if (kvm_host_psci_version == PSCI_VERSION(0, 0)) + return false; + else if (kvm_host_psci_version == PSCI_VERSION(0, 1)) + return is_psci_0_1_call(func_id); + else + return is_psci_0_2_fn_call(func_id); +} + +static unsigned long psci_0_1_handler(u64 func_id, struct kvm_cpu_context *host_ctxt) +{ + return PSCI_RET_NOT_SUPPORTED; +} + +static unsigned long psci_0_2_handler(u64 func_id, struct kvm_cpu_context *host_ctxt) +{ + switch (func_id) { + default: + return PSCI_RET_NOT_SUPPORTED; + } +} + +static unsigned long psci_1_0_handler(u64 func_id, struct kvm_cpu_context *host_ctxt) +{ + int ret; + + ret = psci_0_2_handler(func_id, host_ctxt); + if (ret != PSCI_RET_NOT_SUPPORTED) + return ret; + + switch (func_id) { + default: + return PSCI_RET_NOT_SUPPORTED; + } +} + +bool kvm_host_psci_handler(struct kvm_cpu_context *host_ctxt) +{ + u64 func_id = get_psci_func_id(host_ctxt); + unsigned long ret; + + if (!is_psci_call(func_id)) + return false; + + if (kvm_host_psci_version == PSCI_VERSION(0, 1)) + ret = psci_0_1_handler(func_id, host_ctxt); + else if (kvm_host_psci_version == PSCI_VERSION(0, 2)) + ret = psci_0_2_handler(func_id, host_ctxt); + else if (PSCI_VERSION_MAJOR(kvm_host_psci_version) >= 1) + ret = psci_1_0_handler(func_id, host_ctxt); + else + ret = PSCI_RET_NOT_SUPPORTED; + + host_ctxt->regs.regs[0] = ret; + host_ctxt->regs.regs[1] = 0; + host_ctxt->regs.regs[2] = 0; + host_ctxt->regs.regs[3] = 0; + return true; +} diff --git a/include/uapi/linux/psci.h b/include/uapi/linux/psci.h index 2fcad1dd0b0e..0d52b8dbe8c2 100644 --- a/include/uapi/linux/psci.h +++ b/include/uapi/linux/psci.h @@ -29,6 +29,7 @@ #define PSCI_0_2_FN64_BASE \ (PSCI_0_2_FN_BASE + PSCI_0_2_64BIT) #define PSCI_0_2_FN64(n) (PSCI_0_2_FN64_BASE + (n)) +#define PSCI_0_2_FN_ID_MASK 0xffff #define PSCI_0_2_FN_PSCI_VERSION PSCI_0_2_FN(0) #define PSCI_0_2_FN_CPU_SUSPEND PSCI_0_2_FN(1) From patchwork Wed Nov 4 18:36:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Brazdil X-Patchwork-Id: 11881895 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 60BF9C2D0A3 for ; Wed, 4 Nov 2020 18:40:27 +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 E75712067C for ; Wed, 4 Nov 2020 18:40:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="jSbsVwIp"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="RUE++rKQ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E75712067C 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=hVfS/4VtsLh4XFznoGrAEyUSIM2YOgQtCczf01rzKeU=; b=jSbsVwIpiQKGCb+eyasFn9Dl0 M0UYECprs2oIpSrsNRKb7Ikzzez4tlDGwS1kuTIS/dpuE0NeF58sSou3IvpCeaTj8HikPI3RtN+q4 kH9Lbelk6nGiuGrRsCDD37pfWAcSjjwaTySfH3PIiMFGlHUJE33plES9rjIo/1k4o6Wi14C3Wbscf ikSOwMAoEHnjYrn0wqQEWNyY4pozAoSeRfzMpv4bFpRiFpA/sYnUpWDyRiNAm6hzxjyOQbJqF+sZs Bue5zUCT+48y7ReS0DWjWRt0uyjEIf2Mgph/KuMIAWy1zamBDuc/o+1bJnD45j+DY7ZlavQOvPmkp gYoMJiMqg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaNg0-0002XC-FW; Wed, 04 Nov 2020 18:38:32 +0000 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaNef-0001nV-9J for linux-arm-kernel@lists.infradead.org; Wed, 04 Nov 2020 18:37:10 +0000 Received: by mail-wm1-x343.google.com with SMTP id c18so3358727wme.2 for ; Wed, 04 Nov 2020 10:37:09 -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=9j0VMjjA6zCDdyx35vluqon5elvOXnResZEBXNSr1X0=; b=RUE++rKQXhZNCONaCTR19/HxXtVIIi3oRNevbUdThFpb7lSGOWgZt53CvjYIojGFXp bjoAX5PN9KRdcmvSZhoOooosMjRsjhO3yOCLuFsmXBnGqzHK6fNjiqbiboERhaoR7c65 AMmH+DGH/eYH/7R0jg5d77ub+nd4XbwPgg1O4y2VRz3/Jr8HAi516eAnsOUKhoFimz+U Rygz++/YusK5YxpHxDmVPdIlb5tTRErFbiYlp8wV57FtQTu49uSxeIyuOdoBt1iNhtHe b+NAvqUVRGyEdVlL/l8GZB8iHlSVM8gpAPm9CXxsZbVe2yoe6fVtsZ6ddqmVgU3IIcVq w77A== 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=9j0VMjjA6zCDdyx35vluqon5elvOXnResZEBXNSr1X0=; b=cw+nrwv8s4w/PQLJAWLPVe9HbBe8eTk+z/xNUrZ9h0DVrYcZNmzIzG3nJ0lx+9hovF kfSifPq5/dokYFQ07+t8Ej0ytgSYkAQZ24c96ihaoY5V9l7i3+22QKWVDhDTmxyAPgPX Tv6Weca9p6oH45FyKV1+LMVDYNEpU2mvfdRLVIea3tjt9Wxl3sxiYMGzuh0MGcUZaEC4 rVIhNuIFpCQO0Yat/u00PKoJa1RRffg/nzuHuy5ziasT0q5tlJ09L+9bEUG5s+f97ifp 1b4Bewgq22ZJZYK1SBA1Yw8935Sviro2xAU7FLsrU6eXW5G/YWNvfFdedXjmshw1vDsE tW0Q== X-Gm-Message-State: AOAM531txkWJsiuStvCH45lPugwGDA/k1Ky0Y0z5KqQrIcEJUWsqQyd+ EfaZCQszsd6Gln3DgvbmIjV7Gg== X-Google-Smtp-Source: ABdhPJzlA4HqRs854B2x+X/0kGzJzOL2QkOaSVtVknIKK6zQbS8XLXIwWdn8f9VXnZzMY6cgY+W9ng== X-Received: by 2002:a7b:c748:: with SMTP id w8mr6056505wmk.32.1604515028016; Wed, 04 Nov 2020 10:37:08 -0800 (PST) Received: from localhost ([2a01:4b00:8523:2d03:c8d2:30f2:53c6:bc2]) by smtp.gmail.com with ESMTPSA id 90sm3934768wrl.30.2020.11.04.10.37.06 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 04 Nov 2020 10:37:06 -0800 (PST) From: David Brazdil To: kvmarm@lists.cs.columbia.edu Subject: [RFC PATCH 14/26] kvm: arm64: Forward safe PSCI SMCs coming from host Date: Wed, 4 Nov 2020 18:36:18 +0000 Message-Id: <20201104183630.27513-15-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_133709_414800_ACB58D65 X-CRM114-Status: GOOD ( 19.22 ) 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 Forward the following PSCI SMCs issued by host to EL3 as they do not require the hypervisor's intervention. This assumes that EL3 correctly implements the PSCI specification. Only function IDs implemented in Linux are included. Where both 32-bit and 64-bit variants exist, it is assumed that the host will always use the 64-bit variant. * SMCs that only return information about the system * PSCI_VERSION - PSCI version implemented by EL3 * PSCI_FEATURES - optional features supported by EL3 * AFFINITY_INFO - power state of core/cluster * MIGRATE_INFO_TYPE - whether Trusted OS can be migrated * MIGRATE_INFO_UP_CPU - resident core of Trusted OS * operations which do not affect the hypervisor * MIGRATE - migrate Trusted OS to a different core * SET_SUSPEND_MODE - toggle OS-initiated mode * system shutdown/reset * SYSTEM_OFF * SYSTEM_RESET * SYSTEM_RESET2 Signed-off-by: David Brazdil --- arch/arm64/kvm/hyp/nvhe/psci.c | 40 +++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kvm/hyp/nvhe/psci.c b/arch/arm64/kvm/hyp/nvhe/psci.c index 82d3b2c89658..8f779560ab6f 100644 --- a/arch/arm64/kvm/hyp/nvhe/psci.c +++ b/arch/arm64/kvm/hyp/nvhe/psci.c @@ -50,14 +50,48 @@ static bool is_psci_call(u64 func_id) return is_psci_0_2_fn_call(func_id); } +static unsigned long psci_call(unsigned long fn, unsigned long arg0, + unsigned long arg1, unsigned long arg2) +{ + struct arm_smccc_res res; + + arm_smccc_1_1_smc(fn, arg0, arg1, arg2, &res); + return res.a0; +} + +static unsigned long psci_forward(struct kvm_cpu_context *host_ctxt) +{ + return psci_call(host_ctxt->regs.regs[0], host_ctxt->regs.regs[1], + host_ctxt->regs.regs[2], host_ctxt->regs.regs[3]); +} + +static __noreturn unsigned long psci_forward_noreturn(struct kvm_cpu_context *host_ctxt) +{ + psci_forward(host_ctxt); + hyp_panic(); /* unreachable */ +} + static unsigned long psci_0_1_handler(u64 func_id, struct kvm_cpu_context *host_ctxt) { - return PSCI_RET_NOT_SUPPORTED; + if (func_id == kvm_host_psci_function_id[PSCI_FN_MIGRATE]) + return psci_forward(host_ctxt); + else + return PSCI_RET_NOT_SUPPORTED; } static unsigned long psci_0_2_handler(u64 func_id, struct kvm_cpu_context *host_ctxt) { switch (func_id) { + case PSCI_0_2_FN_PSCI_VERSION: + case PSCI_0_2_FN64_AFFINITY_INFO: + case PSCI_0_2_FN64_MIGRATE: + case PSCI_0_2_FN_MIGRATE_INFO_TYPE: + case PSCI_0_2_FN64_MIGRATE_INFO_UP_CPU: + return psci_forward(host_ctxt); + case PSCI_0_2_FN_SYSTEM_OFF: + case PSCI_0_2_FN_SYSTEM_RESET: + psci_forward_noreturn(host_ctxt); + unreachable(); default: return PSCI_RET_NOT_SUPPORTED; } @@ -72,6 +106,10 @@ static unsigned long psci_1_0_handler(u64 func_id, struct kvm_cpu_context *host_ return ret; switch (func_id) { + case PSCI_1_0_FN_PSCI_FEATURES: + case PSCI_1_0_FN_SET_SUSPEND_MODE: + case PSCI_1_1_FN64_SYSTEM_RESET2: + return psci_forward(host_ctxt); default: return PSCI_RET_NOT_SUPPORTED; } From patchwork Wed Nov 4 18:36:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Brazdil X-Patchwork-Id: 11881899 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 80BB1C2D0A3 for ; Wed, 4 Nov 2020 18:40:34 +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 010D72067C for ; Wed, 4 Nov 2020 18:40:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="rpz55vDC"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="Hkql7qgZ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 010D72067C 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=50+BmwtR+TbdMHRWJ28AHrJyiYHOygaMvrw5HGJpNkw=; b=rpz55vDCWaCghtPq55vxp+1iL aqHbUgXF35hoexrLE5Y3XlAs5hzWBJB40FX3AHdRe5z4ucvKhZCcea8TSQfTfy5gzQxit5sAF/d19 vMXbNkf3ubbiCRktUbOwGvfz4IcAbXTjvu6V4ynheFmzVm7H1cBTvATd288ngubZarWS0E0vPMukZ 6dGiYU9uQi3nsFSfLxLxqQZRilSKrzRmVCVhsxwbfPqGhxBr5RIu1cfmkJ7Wrp8TuBj0HO1+3NJnE y7TDtx8lgiq8vtV0TCoZXUxSlKT/MQX2KaR6ZIwPKICKLfxovyOL4V8niFaieAeIOoCkzRP5iwge6 agc7izQXw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaNg7-0002bQ-Cv; Wed, 04 Nov 2020 18:38:39 +0000 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaNeh-0001od-8T for linux-arm-kernel@lists.infradead.org; Wed, 04 Nov 2020 18:37:13 +0000 Received: by mail-wm1-x342.google.com with SMTP id d142so3350700wmd.4 for ; Wed, 04 Nov 2020 10:37:11 -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=IMhhhU6UDnCZic4U0v9mlSCvJc9/cDfep6l/EJNs2R8=; b=Hkql7qgZIh094H5VuYpSIVjy6kzgeDA8ZQgltyGOpECDIh8BxbtQ1vC2IP76Y8D/SW 26fZ8diz3rjUlyZpgj+lmnh+rbYfjbMuzRqgpNGGA9X3yiyb6w6ST9GX+8zgdximBtLq LPzGXkiCl821fIRBlBt/yFj2EEHQXAkFtg4HenFUa6IyY7c/084XL0mVBsEwNoTqcnMv eiLz/WnUFvb4/K1mS6CckAIwJqhddN3kU7pWeQR9kXwxCmAz6AK4aPP6iJG6VFR61m9v bk4NZXV6Qkoh7xR9BqCaqTfXmbEwRJirP5X7z2dnIfwK5n74woEhG7QE9IG/BCgsaWn/ p3Hw== 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=IMhhhU6UDnCZic4U0v9mlSCvJc9/cDfep6l/EJNs2R8=; b=bZuqDsGSES22SrvY7oEPkhbV4WXTkpZ0fOzHhwavj8HC+ms+euL6qS2vStF2fI+6KQ oag7EDB0njYX4lNBKmkryvSiOEsSk7xXUxj/Cuf7ao0pa+KuE69sXr1kqN42el2rk6ZU Iq0CWb1PReZHnizEqoR2H5wdBnfjiuIKFhF4mgYdhRLIn/CtZh89ZJ75oLmX2OwYQwND YpWoy8M8RYWMkYlXzLkN9VhD7+eXF8ZbK/jkAn7grrsTM9nCpziInGb5HZdXEBfwdsnp Rs9MDT03iA7icN6BelxnDUq76/taIvMRcy90PFvZSz00tGT2LhEyfyCUFjfJMBi+rY+2 5rJQ== X-Gm-Message-State: AOAM530afk8+7mnCpNLbuTBGjXn9nx1cJ/MfGtkzpKsN1EAO5i3oIfPX Q4GpSHr5N5ddzxJDbxgAv9wTFg== X-Google-Smtp-Source: ABdhPJxt0mB9KgegrPj+SMz071z9EVqKZNk74keSqXTEW6yH2qJ021T+2wo2kFQ+H/1RCbQ7PtqAxA== X-Received: by 2002:a7b:cc0e:: with SMTP id f14mr5978436wmh.92.1604515030088; Wed, 04 Nov 2020 10:37:10 -0800 (PST) Received: from localhost ([2a01:4b00:8523:2d03:c8d2:30f2:53c6:bc2]) by smtp.gmail.com with ESMTPSA id w186sm3078822wmb.26.2020.11.04.10.37.08 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 04 Nov 2020 10:37:09 -0800 (PST) From: David Brazdil To: kvmarm@lists.cs.columbia.edu Subject: [RFC PATCH 15/26] arm64: kvm: Add standalone ticket spinlock implementation for use at hyp Date: Wed, 4 Nov 2020 18:36:19 +0000 Message-Id: <20201104183630.27513-16-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_133711_427866_3DB6FF8C X-CRM114-Status: GOOD ( 20.40 ) 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 From: Will Deacon We will soon need to synchronise multiple CPUs in the hyp text at EL2. The qspinlock-based locking used by the host is overkill for this purpose and relies on the kernel's "percpu" implementation for the MCS nodes. Implement a simple ticket locking scheme based heavily on the code removed by commit c11090474d70 ("arm64: locking: Replace ticket lock implementation with qspinlock"). Signed-off-by: Will Deacon Signed-off-by: David Brazdil --- arch/arm64/kvm/hyp/include/nvhe/spinlock.h | 96 ++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 arch/arm64/kvm/hyp/include/nvhe/spinlock.h diff --git a/arch/arm64/kvm/hyp/include/nvhe/spinlock.h b/arch/arm64/kvm/hyp/include/nvhe/spinlock.h new file mode 100644 index 000000000000..dc0397e5b5f2 --- /dev/null +++ b/arch/arm64/kvm/hyp/include/nvhe/spinlock.h @@ -0,0 +1,96 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * A stand-alone ticket spinlock implementation for use by the non-VHE + * KVM hypervisor code running at EL2. + * + * Copyright (C) 2020 Google LLC + * Author: Will Deacon + * + * Heavily based on the implementation removed by c11090474d70 which was: + * Copyright (C) 2012 ARM Ltd. + */ + +#ifndef __KVM_NVHE_HYPERVISOR__ +#error "Attempt to include nVHE code outside of EL2 object" +#endif + +#ifndef __ARM64_KVM_NVHE_SPINLOCK_H__ +#define __ARM64_KVM_NVHE_SPINLOCK_H__ + +#include +#include + +typedef union hyp_spinlock { + u32 __val; + struct { +#ifdef __AARCH64EB__ + u16 next, owner; +#else + u16 owner, next; + }; +#endif +} hyp_spinlock_t; + +#define hyp_spin_lock_init(l) \ +do { \ + *(l) = (hyp_spinlock_t){ .__val = 0 }; \ +} while (0) + +static inline void hyp_spin_lock(hyp_spinlock_t *lock) +{ + u32 tmp; + hyp_spinlock_t lockval, newval; + + asm volatile( + /* Atomically increment the next ticket. */ + ARM64_LSE_ATOMIC_INSN( + /* LL/SC */ +" prfm pstl1strm, %3\n" +"1: ldaxr %w0, %3\n" +" add %w1, %w0, #(1 << 16)\n" +" stxr %w2, %w1, %3\n" +" cbnz %w2, 1b\n", + /* LSE atomics */ +" mov %w2, #(1 << 16)\n" +" ldadda %w2, %w0, %3\n" + __nops(3)) + + /* Did we get the lock? */ +" eor %w1, %w0, %w0, ror #16\n" +" cbz %w1, 3f\n" + /* + * No: spin on the owner. Send a local event to avoid missing an + * unlock before the exclusive load. + */ +" sevl\n" +"2: wfe\n" +" ldaxrh %w2, %4\n" +" eor %w1, %w2, %w0, lsr #16\n" +" cbnz %w1, 2b\n" + /* We got the lock. Critical section starts here. */ +"3:" + : "=&r" (lockval), "=&r" (newval), "=&r" (tmp), "+Q" (*lock) + : "Q" (lock->owner) + : "memory"); +} + +static inline void hyp_spin_unlock(hyp_spinlock_t *lock) +{ + u64 tmp; + + asm volatile( + ARM64_LSE_ATOMIC_INSN( + /* LL/SC */ + " ldrh %w1, %0\n" + " add %w1, %w1, #1\n" + " stlrh %w1, %0", + /* LSE atomics */ + " mov %w1, #1\n" + " staddlh %w1, %0\n" + __nops(1)) + : "=Q" (lock->owner), "=&r" (tmp) + : + : "memory"); +} + +#endif /* __ARM64_KVM_NVHE_SPINLOCK_H__ */ From patchwork Wed Nov 4 18:36:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Brazdil X-Patchwork-Id: 11881889 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=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 E54B5C2D0A3 for ; Wed, 4 Nov 2020 18:39:44 +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 6983E20719 for ; Wed, 4 Nov 2020 18:39:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="t1UhFbjG"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="phvU+aAR" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6983E20719 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=s15ID3fBbsk5kZaTREUJ6rD9ZoxLlt3ywFefv63vdlw=; b=t1UhFbjGecN8Kz79CiUgNcWBD A2rCbaQxAPyeGVcYIOOgB9ZgF3klooD9snkKpMv9ihrFyfUdHkXg7s+Xc63zNYF5jedRN+yEe1LwC +/LgzVWU6E7Qb10Iyx3vvyDwnDGC0+HpAD3pPnnwbUSG40SoEuPvMABbwFzcrFw/4ep8JwqjGBCFm mxDMcMdN18vo+tpWnHmOUvLAoOglLtDmsKxx1wR6I3uLpQcZ1ti1TB76z8RAd96SuSQbdGi7biFNS c34P7ln5lVghBlQPKuro6G6KoYvb1b/P0SJrCHkDZ/Xu2cilZZe8Y21etmyWvTCCmXus+9iWBw+CG enObvjI5g==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaNgN-0002mi-Ow; Wed, 04 Nov 2020 18:38:55 +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 1kaNej-0001pW-SL for linux-arm-kernel@lists.infradead.org; Wed, 04 Nov 2020 18:37:15 +0000 Received: by mail-wr1-x441.google.com with SMTP id g12so23122207wrp.10 for ; Wed, 04 Nov 2020 10:37:13 -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=ZVjVFozTLdMZo3Qj+qmHuuLudZQ2Vnjr88mC0h8KdNc=; b=phvU+aAR0cMr4PSwYP4GPkWz29rXwGC9l6/gUkgEjJ41OCA08ZcE+n1PJzNz0U9axl S4dpFjCDxAzjGzMRrsJKFU28M4gkHv2uhaxYBrgJHsUcuvE+VD3lfqcNB5TohC56+pK/ yxLAWGHDqcd+ZySMPpb0Uc3ftPAUejRVMWEG281NsCzDDEqtT9MYem7+nqhqXqX7dAc/ MjbJFmxejTtBit6tLHcNLX36y+YPsBGpwamh2dfQLuneXQx1Va1B+hY0xXr/c7obRIYC 2yFJOmJFT8asy/4FASrFkHgHJ9WveV0lIgaATcylkuOr9Xn7oy5QE1FC6m2LVo7KbC5G b5xA== 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=ZVjVFozTLdMZo3Qj+qmHuuLudZQ2Vnjr88mC0h8KdNc=; b=kqAtbXdTUv3Jx1eFwu0z7ntxw9hpiylQ7xFRcCVhewBd2+pZH3Aptz5iaZpd2GCn5Y 7g9Qjp5MYRUXHOpsCybgVXCSYmiYgtQ0uLdMy/FdUqg4KpZBk4cihEQDbhz7Gy4U3rxI TeRcebZxTY7GxwyCkRGLmc6cI/HOhVU5pMmyL5XY3L4ifXsu4pP+gz0s2zwvGQPecnO9 RWj2DZI3aXzMakgnpt1dHB7I5bJwlVzo7wtBOoMgeKaOUIUPHPU0Do3IwT4eoE3vE3GK J0WH9gxrIyqDgMW2B0OymV0BMsR7ujOaUdja1goSM0qBXX1885YTcNS19d8KaZHFI6qT gfPQ== X-Gm-Message-State: AOAM530XgnEOiv+z4DEMFBhFYaerfJ1paTX9DJQR6KK1gYXcfis6R+pd rZ23pzpOHrDQss1+45A0/YDc/A== X-Google-Smtp-Source: ABdhPJzSOg5ehTCfdQXoJjzXBCOHpK0Uzw56Ie6OCbSaHqF4Y4sxI4USadgIi3s6J90cFV5gmW4tkw== X-Received: by 2002:adf:f245:: with SMTP id b5mr6282692wrp.389.1604515032310; Wed, 04 Nov 2020 10:37:12 -0800 (PST) Received: from localhost ([2a01:4b00:8523:2d03:c8d2:30f2:53c6:bc2]) by smtp.gmail.com with ESMTPSA id b14sm4016046wrx.35.2020.11.04.10.37.10 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 04 Nov 2020 10:37:11 -0800 (PST) From: David Brazdil To: kvmarm@lists.cs.columbia.edu Subject: [RFC PATCH 16/26] kvm: arm64: Add offset for hyp VA <-> PA conversion Date: Wed, 4 Nov 2020 18:36:20 +0000 Message-Id: <20201104183630.27513-17-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_133714_016519_809DD638 X-CRM114-Status: GOOD ( 15.91 ) 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 Add a host-initialized constant to KVM nVHE hyp code for converting between EL2 linear map virtual addresses and physical addresses. Also add `__hyp_pa` macro that performs the conversion. Signed-off-by: David Brazdil --- arch/arm64/kvm/arm.c | 15 +++++++++++++++ arch/arm64/kvm/hyp/nvhe/psci.c | 3 +++ 2 files changed, 18 insertions(+) diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index cedec793da64..580d4a656a7b 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -1484,6 +1484,20 @@ static inline void hyp_cpu_pm_exit(void) } #endif +static void init_hyp_physvirt_offset(void) +{ + extern s64 kvm_nvhe_sym(hyp_physvirt_offset); + unsigned long kern_vaddr, hyp_vaddr, paddr; + + /* Check that kvm_arm_hyp_percpu_base has been set. */ + BUG_ON(kvm_arm_hyp_percpu_base[0] == 0); + + kern_vaddr = kvm_arm_hyp_percpu_base[0]; + hyp_vaddr = kern_hyp_va(kern_vaddr); + paddr = __pa(kern_vaddr); + CHOOSE_NVHE_SYM(hyp_physvirt_offset) = (s64)paddr - (s64)hyp_vaddr; +} + static void init_cpu_logical_map(void) { extern u64 kvm_nvhe_sym(__cpu_logical_map)[NR_CPUS]; @@ -1686,6 +1700,7 @@ static int init_hyp_mode(void) } } + init_hyp_physvirt_offset(); init_cpu_logical_map(); init_psci(); diff --git a/arch/arm64/kvm/hyp/nvhe/psci.c b/arch/arm64/kvm/hyp/nvhe/psci.c index 8f779560ab6f..3eafcf48a29b 100644 --- a/arch/arm64/kvm/hyp/nvhe/psci.c +++ b/arch/arm64/kvm/hyp/nvhe/psci.c @@ -16,6 +16,9 @@ /* Config options set by the host. */ u32 kvm_host_psci_version = PSCI_VERSION(0, 0); u32 kvm_host_psci_function_id[PSCI_FN_MAX]; +s64 hyp_physvirt_offset; + +#define __hyp_pa(x) ((phys_addr_t)(x) + hyp_physvirt_offset) static u64 get_psci_func_id(struct kvm_cpu_context *host_ctxt) { 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]; From patchwork Wed Nov 4 18:36:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Brazdil X-Patchwork-Id: 11881897 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 2AA39C2D0A3 for ; Wed, 4 Nov 2020 18:40:15 +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 B573220719 for ; Wed, 4 Nov 2020 18:40:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="mnVcm9GZ"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="gEbk0tKi" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B573220719 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=igft53IzT5DU81Xp0rZqo0v796Ab3mdXZBK3T72ZImk=; b=mnVcm9GZslKqxcgwrI7ozw5tL OPuotkj/o6r14+myMdxAW3Hxmkbele32VK8x67S6yXTGhIs1TPwLTvjN6U+TEZxUxduWEDk5AY59P v22GJWS8ICOqBDWZAE6cHdxyCmcXh/BryWJO3EK75gXB8vQWL35txnuLyZKhU9isnJ9DXqeNdka4G 6B+V+04bxpU9ICL4BspE5kI2jwdOcmZk0Tw4QCJCzIWDk1IT/PkmUqGOfWN2x8p9Uoi3ru8l2PlD3 R6fQA4vOpJQfbIvhTongDv8Iti8kXCcYOzgDPkfNlX8krKveuMqYAe7jh2B2H+JoV3qYNpphL3HXu sQW/Vvftw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaNgy-0003BI-St; Wed, 04 Nov 2020 18:39:33 +0000 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaNen-0001ru-OY for linux-arm-kernel@lists.infradead.org; Wed, 04 Nov 2020 18:37:20 +0000 Received: by mail-wm1-x342.google.com with SMTP id s13so115444wmh.4 for ; Wed, 04 Nov 2020 10:37:17 -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=k1mZbgF5Ouf6celHonuP3A/s1Eh7mvuRv0TPOHTEAQo=; b=gEbk0tKiTb2BPXDRISpv4WCdZLKXkbNLCjo9s0sAl7NmT5+hkNrkumyGOXB7xc/JYH YXXMWPL4izPCNAKWaVBjsFPxiTj85GP1FLZnDTuyUdZ7/PODY8ozmEI3bzsOGhIqrlPj PR5DFKv8a9eoIKBPgbZOXc7z6HwbThHepHAzSJ6MXbm/AvlBnQLNI1xKBJUgOs7R+/GI JpqrxNWZZk9x5mTbJY2i9dQ4QZtZ/ZxKVbnD2PT5EtwNYOfFK8lGQdFnx7W1IwaRFg7W n0BgSJehlQZsUSwbm1Db3EwQnJf2RK63eIxGuJPtxBov4BTrqTjJKFIyEAa0/J8LrmfX Z3qA== 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=k1mZbgF5Ouf6celHonuP3A/s1Eh7mvuRv0TPOHTEAQo=; b=Sj6GWz9zIwdVKVYf4MTAjDt3/KH7BiQWkGp3qNdQHs9A0S6qyKLRd7H8zQHJX+kCE3 Rr9ru0DhdWgRBfiUU9BnH9n6kmQCygNmEAXpKjDp/mc0ZBGmhXmCuMT0OekzTbLKoO64 i+6TsYaIjR7ZJb6l9DQrvEF1E+kQgy8V35u4SZ5Ql4ctlBSMvQFwykNE/BxQS1cbcSB+ IXt9c5f6b+2GFlFoy5G3/e0f9WqD67WxQu2TdOYN/jS+iZmZaeW+d9NKoRn7ZUNf11CQ rFgLQrpVy1c9v22xck6gZRy7oQ9U+2b/M0XCxSDB0QyIqV3mFFf0C1P55jhI44TUM1p2 P2SA== X-Gm-Message-State: AOAM530DvsvdqLdZdSZMkEVrSjK6/Yxwt1gc7cP2T/vlU6xfMdNeWFvl Xnq5nVMazxD5rkODsKfl/NUewQ== X-Google-Smtp-Source: ABdhPJwJO5eUF6ZkZBcH8S7L48cw9sDQ5/YjzG6ipw3jIJSUlXblzToWcdhHw2LopEHH3RHQGlLScg== X-Received: by 2002:a7b:cf1a:: with SMTP id l26mr6109935wmg.18.1604515036611; Wed, 04 Nov 2020 10:37:16 -0800 (PST) Received: from localhost ([2a01:4b00:8523:2d03:c8d2:30f2:53c6:bc2]) by smtp.gmail.com with ESMTPSA id e7sm4292303wrm.6.2020.11.04.10.37.14 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 04 Nov 2020 10:37:15 -0800 (PST) From: David Brazdil To: kvmarm@lists.cs.columbia.edu Subject: [RFC PATCH 18/26] kvm: arm64: Intercept PSCI_CPU_OFF host SMC calls Date: Wed, 4 Nov 2020 18:36:22 +0000 Message-Id: <20201104183630.27513-19-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_133717_937961_FF6B5768 X-CRM114-Status: GOOD ( 19.35 ) 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 Add a handler of the CPU_OFF PSCI host SMC trapped in KVM nVHE hyp code. When invoked, it changes the recorded state of the core to OFF before forwarding the call to EL3. If the call fails, it changes the state back to ON and returns the error to the host. Signed-off-by: David Brazdil --- arch/arm64/kvm/hyp/nvhe/psci.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kvm/hyp/nvhe/psci.c b/arch/arm64/kvm/hyp/nvhe/psci.c index c3d0a6246c66..00dc0cab860c 100644 --- a/arch/arm64/kvm/hyp/nvhe/psci.c +++ b/arch/arm64/kvm/hyp/nvhe/psci.c @@ -13,6 +13,8 @@ #include #include +#include + /* Config options set by the host. */ u32 kvm_host_psci_version = PSCI_VERSION(0, 0); u32 kvm_host_psci_function_id[PSCI_FN_MAX]; @@ -20,6 +22,7 @@ s64 hyp_physvirt_offset; #define __hyp_pa(x) ((phys_addr_t)(x) + hyp_physvirt_offset) +static DEFINE_PER_CPU(hyp_spinlock_t, psci_cpu_lock); DEFINE_PER_CPU(enum kvm_nvhe_psci_state, psci_cpu_state); static u64 get_psci_func_id(struct kvm_cpu_context *host_ctxt) @@ -76,9 +79,32 @@ static __noreturn unsigned long psci_forward_noreturn(struct kvm_cpu_context *ho hyp_panic(); /* unreachable */ } +static int psci_cpu_off(u64 func_id, struct kvm_cpu_context *host_ctxt) +{ + hyp_spinlock_t *cpu_lock = this_cpu_ptr(&psci_cpu_lock); + enum kvm_nvhe_psci_state *cpu_power = this_cpu_ptr(&psci_cpu_state); + u32 power_state = (u32)host_ctxt->regs.regs[1]; + int ret; + + /* Change the recorded state to OFF before forwarding the call. */ + hyp_spin_lock(cpu_lock); + *cpu_power = KVM_NVHE_PSCI_CPU_OFF; + hyp_spin_unlock(cpu_lock); + + ret = psci_call(func_id, power_state, 0, 0); + + /* Call was unsuccessful. Restore the recorded state and return to host. */ + hyp_spin_lock(cpu_lock); + *cpu_power = KVM_NVHE_PSCI_CPU_ON; + hyp_spin_unlock(cpu_lock); + return ret; +} + static unsigned long psci_0_1_handler(u64 func_id, struct kvm_cpu_context *host_ctxt) { - if (func_id == kvm_host_psci_function_id[PSCI_FN_MIGRATE]) + if (func_id == kvm_host_psci_function_id[PSCI_FN_CPU_OFF]) + return psci_cpu_off(func_id, host_ctxt); + else if (func_id == kvm_host_psci_function_id[PSCI_FN_MIGRATE]) return psci_forward(host_ctxt); else return PSCI_RET_NOT_SUPPORTED; @@ -97,6 +123,8 @@ static unsigned long psci_0_2_handler(u64 func_id, struct kvm_cpu_context *host_ case PSCI_0_2_FN_SYSTEM_RESET: psci_forward_noreturn(host_ctxt); unreachable(); + case PSCI_0_2_FN_CPU_OFF: + return psci_cpu_off(func_id, host_ctxt); default: return PSCI_RET_NOT_SUPPORTED; } From patchwork Wed Nov 4 18:36:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Brazdil X-Patchwork-Id: 11881907 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=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 773E2C2D0A3 for ; Wed, 4 Nov 2020 18:41:38 +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 E5772206A4 for ; Wed, 4 Nov 2020 18:41:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="rWFYwEkF"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="C7k/+8DY" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E5772206A4 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=0pxLthSckE6Z+mClEwvqPYRQ4kFpGbvV9jaiJyb/DVQ=; b=rWFYwEkF2PfsIa0sSuIUEpf7E O1fFWVmdAocWiSJ9feTo8+oq68kSKboGn8Fq3zjz6i2HJXE5VOCpyFZyAzzAZjQj/XWvSaJaOBR9w MWFVfCjrFyMUh+20Dztw0KsghL24HPAvzUyhTDRxezqVjcKDzPx+pnkTsXqW6mgr0/zREVXcKc75w sBkJR62wbtOE3+vAcKEs3Y0iIq2Z8xvHvhk/53O6039v/c7mn8yfRkROtj6Vq6jPeATAIX2+5RvT8 L9M4HBremz7w6hu9O3B4mvpKtt4Q+Kx2VofVd5yeS9f3/vQLZb7ibKMl7DlVNU21HiAOojDQYEw7O WRa0Yem4A==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaNhE-0003NH-Tg; Wed, 04 Nov 2020 18:39:49 +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 1kaNeq-0001sf-19 for linux-arm-kernel@lists.infradead.org; Wed, 04 Nov 2020 18:37:21 +0000 Received: by mail-wr1-x443.google.com with SMTP id g12so23122583wrp.10 for ; Wed, 04 Nov 2020 10:37:19 -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=lntpB9k/GNt3DHKTS6XU+Lzi+3feR2/TDoLFam5OEsI=; b=C7k/+8DYRMsN5av0hh1p2auJO+TujqPhkBo9BQOirCYTD1fGH4MKjmZ90c5bMU7Dvs 7iXLOCA5XTk7X+s6+G/FADEg1vlFiJNnSKQpNHFzsfJuI/egt0VB2R4bGqay6pSEtMzV mugN96IDPyJUl9J8nZJmCNxxPlcS7q0g1lFjISxMbqwVf9hoORqeGPgKxbvioXh+Gz1z LKEVEAz2BDBUn3fCSiGXaFJKOrRpL0Tc+GLucbHuJ/FMZdaIvRy4x7frQIOcGnejA6Lw PAlCYBfM7fvOkTtGmNbT8j+d/lf3B55XUIwrtUiNVEb55mNzk9xPRhDXqT+vgc88HxfL Zb+w== 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=lntpB9k/GNt3DHKTS6XU+Lzi+3feR2/TDoLFam5OEsI=; b=rfAmp7UC8fkR4SmdbtjK6IPl7Z/o5GETSmYQcxXTLf9eWqL/7WxRMVW4PKdDF0nNPO QnE8v8bglDeU56DpIjs5B9H6LWr81+u5V6mgo5VB8ByXwVxH8VB7rxRhhOU1uM7bdATd G18olaHQVHAjj86gnZ/Zv8LMv6tjbp+hnHx2oX39jeOokOcBk070m3q9RECBRqJcCBRl aa3mBKYES3LQpW3H1GIk9knEbj/4h8ck2lafAoSUMDBsf1eVVWdp8pPTElWIQGmr5yFJ jk9ZimC9tMnuAQIPVh5pAJEOmFQtMzqOCVNO/rHghLSpKCulBipwYIIcgQ3SUITw6vXD 26XA== X-Gm-Message-State: AOAM533Cif+48BXbg20i51A/bb+RqcG/7nsgW53SB4vrPhtriiiTUMA5 UxrfLjLzZyF4h87Lll5RNQWLlg== X-Google-Smtp-Source: ABdhPJzp3ZjoC9LnEvi+UKHAL909ZKm0IHo36bHGz5PnMfBxU0GoHEvnmkwHDRi5tS6FA8eyTXdSfQ== X-Received: by 2002:adf:f104:: with SMTP id r4mr33995916wro.202.1604515038644; Wed, 04 Nov 2020 10:37:18 -0800 (PST) Received: from localhost ([2a01:4b00:8523:2d03:c8d2:30f2:53c6:bc2]) by smtp.gmail.com with ESMTPSA id r1sm3905404wro.18.2020.11.04.10.37.17 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 04 Nov 2020 10:37:17 -0800 (PST) From: David Brazdil To: kvmarm@lists.cs.columbia.edu Subject: [RFC PATCH 19/26] kvm: arm64: Extract __do_hyp_init into a helper function Date: Wed, 4 Nov 2020 18:36:23 +0000 Message-Id: <20201104183630.27513-20-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_133720_174736_4E8C4254 X-CRM114-Status: GOOD ( 16.29 ) 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 In preparation for adding a CPU entry point in nVHE hyp code, extract most of __do_hyp_init hypervisor initialization code into a common helper function. This will be invoked by the entry point to install KVM on the newly booted CPU. Signed-off-by: David Brazdil --- arch/arm64/kvm/hyp/nvhe/hyp-init.S | 39 +++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-init.S b/arch/arm64/kvm/hyp/nvhe/hyp-init.S index 6f3ac5d428ec..1726cc44b3ee 100644 --- a/arch/arm64/kvm/hyp/nvhe/hyp-init.S +++ b/arch/arm64/kvm/hyp/nvhe/hyp-init.S @@ -68,16 +68,35 @@ __do_hyp_init: mov x0, #SMCCC_RET_NOT_SUPPORTED eret -1: ldr x0, [x1, #NVHE_INIT_TPIDR_EL2] - msr tpidr_el2, x0 +1: mov x0, x1 + mov x4, lr + bl ___kvm_hyp_init + mov lr, x4 - ldr x0, [x1, #NVHE_INIT_STACK_PTR] - mov sp, x0 + /* Hello, World! */ + mov x0, #SMCCC_RET_SUCCESS + eret +SYM_CODE_END(__kvm_hyp_init) + +/* + * Initialize the hypervisor in EL2. + * + * Only modifies x0..x3 so as to not clobber callee-saved SMCCC registers + * and leave x4 for the caller. + * + * x0: struct kvm_nvhe_init_params PA + */ +SYM_CODE_START(___kvm_hyp_init) + ldr x1, [x0, #NVHE_INIT_TPIDR_EL2] + msr tpidr_el2, x1 + + ldr x1, [x0, #NVHE_INIT_STACK_PTR] + mov sp, x1 - ldr x0, [x1, #NVHE_INIT_VECTOR_PTR] - msr vbar_el2, x0 + ldr x1, [x0, #NVHE_INIT_VECTOR_PTR] + msr vbar_el2, x1 - ldr x1, [x1, #NVHE_INIT_PGD_PTR] + ldr x1, [x0, #NVHE_INIT_PGD_PTR] phys_to_ttbr x0, x1 alternative_if ARM64_HAS_CNP orr x0, x0, #TTBR_CNP_BIT @@ -137,10 +156,8 @@ alternative_else_nop_endif msr sctlr_el2, x0 isb - /* Hello, World! */ - mov x0, #SMCCC_RET_SUCCESS - eret -SYM_CODE_END(__kvm_hyp_init) + ret +SYM_CODE_END(___kvm_hyp_init) SYM_CODE_START(__kvm_handle_stub_hvc) cmp x0, #HVC_SOFT_RESTART From patchwork Wed Nov 4 18:36:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Brazdil X-Patchwork-Id: 11881911 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 81790C4741F for ; Wed, 4 Nov 2020 18:41:58 +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 0238A206C1 for ; Wed, 4 Nov 2020 18:41:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="J3kD8AF0"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="UB+tujjI" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0238A206C1 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=4YCEqHyZzLcqBykQbacFXU2T0WvPo9aXkX7skX8mFas=; b=J3kD8AF0YxJAMEoWPSnK5gSOm AQtKBXyY3FIOCuq24N2vEbb7qYUu1Kai/6obxgv+xlq9zo7o5O7emhC/aggJwqx58bVKheQnOsZ5B 72+ArQHiGtOTwEkRDsxmCDMikdtFXFvnWMpqHVRM00/iUNxZ3gqlosqrFwBPTBD7KTVWBymZNOpKd ZcuKvIiwNSNbjLNguqh3W3Ciy4JudybCeRiUdj/Ejz5wquhE5Bu8PiyOlOcoiPp01bpihmpww784K znnwnntkilxuiZtZd4uPM8OA0RjOSuvSphzADsqe0lxMLucyfXgJQiRbVA0MpF2ldu7fhRNbrFSC5 zzPxilRrA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaNhW-0003du-Uc; Wed, 04 Nov 2020 18:40:07 +0000 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaNes-0001tj-6h for linux-arm-kernel@lists.infradead.org; Wed, 04 Nov 2020 18:37:24 +0000 Received: by mail-wm1-x342.google.com with SMTP id c16so3272833wmd.2 for ; Wed, 04 Nov 2020 10:37:21 -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=u52kHMW+kn83ag3JaEyoWb0+pW9IMqD4BMU2psxNYnQ=; b=UB+tujjIDqFaIg2HCII9phSYVmB1j1zP+b/oy7LyLRa4tpi5vDWKwHeXFjBBncAnue t5NLaznwL2a6xMO0nB+gZ1W8lR7ASbIC/5uqmVhA4JQkT8FQVwPkHEVtrHZCcXTrelEg Zybm4GkCW5RvA/LoFm5TG4qJIoz2BcdeKP84kW3j4+j6F6ikYpJRGjwhjPTkgRLHOEOA cA6gGhLerR0LCsX7vhQgqN2GD4VTP/yLKxPGn0+VV1j/Z289/Gkvpx8lCV0Qvg7UoJaD DifqvbMmXizjEGf/EPyu+gGhSSM476YffGBtRUTz5V1wN96efp7x2jpSTvTq4TqipO86 eGoA== 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=u52kHMW+kn83ag3JaEyoWb0+pW9IMqD4BMU2psxNYnQ=; b=m3asz8o0BU9/wmSZX55XpMG3Q8WwzxbNtPNaLIcDpGdiTk+ZguFlZJIwyqxwhi7Wzc gXmxwWTCiRb3akxtxnjKMYiVhpTbRtVFjSVZsvrbloU8wh21RLmYuAnULin/6u+ZmUAK fZBBJYsJcjDv5PMg/pIUEsw04BWPbDv2ReAVhkcbE11Ngs4A0UKPSEKWSyCiTVjmOPGZ 48/vp1hvRdtRcsvADZETRWAwQ+vgWDljMSi6ndZtS5Pb7YyKiD7YnKu2B3xwrs0n89oS KvNljf+vBuUTQuqb7NUYDoAEe3+IfgGXm9S+iPA0CmHDd3L/7siq6fou4G0uA8fB/NJv nfCg== X-Gm-Message-State: AOAM533i3Mw0BVKlNr7JJ0jf/+ypwzLREOSg0AbrUXCfHRTKLg0iRNpS Ue9oxuHJbMn5utVMYzOkPnvYZHW8uXCbNi07 X-Google-Smtp-Source: ABdhPJwsJeUZZiJ/5qjoSIdAagJRDj0FAch74PF5fDj6WKHQ0ZxsPbVmvF9ETVGgMlYzKzkwDQ1P3g== X-Received: by 2002:a1c:2842:: with SMTP id o63mr5935820wmo.59.1604515040904; Wed, 04 Nov 2020 10:37:20 -0800 (PST) Received: from localhost ([2a01:4b00:8523:2d03:c8d2:30f2:53c6:bc2]) by smtp.gmail.com with ESMTPSA id t5sm4349312wrb.21.2020.11.04.10.37.19 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 04 Nov 2020 10:37:19 -0800 (PST) From: David Brazdil To: kvmarm@lists.cs.columbia.edu Subject: [RFC PATCH 20/26] kvm: arm64: Add CPU entry point in nVHE hyp Date: Wed, 4 Nov 2020 18:36:24 +0000 Message-Id: <20201104183630.27513-21-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_133723_367487_02E1635B X-CRM114-Status: GOOD ( 19.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 , 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 When nVHE hyp starts interception host's PSCI CPU_ON SMCs, it will need to install KVM on the newly booted CPU before returning to the host. Add an entry point which expects the same kvm_nvhe_init_params struct as the __kvm_hyp_init HVC in the CPU_ON context argument (x0). The entry point initializes EL2 state with the same init_el2_state macro used by the kernel's entry point. It then initializes KVM using the same helper function used in the __kvm_hyp_init HVC. When done, the entry point branches to a function provided in the init params. Signed-off-by: David Brazdil --- arch/arm64/include/asm/kvm_asm.h | 1 + arch/arm64/kernel/asm-offsets.c | 1 + arch/arm64/kvm/hyp/nvhe/hyp-init.S | 30 ++++++++++++++++++++++++++++++ 3 files changed, 32 insertions(+) diff --git a/arch/arm64/include/asm/kvm_asm.h b/arch/arm64/include/asm/kvm_asm.h index 9eecb37db6df..8350b95ce94e 100644 --- a/arch/arm64/include/asm/kvm_asm.h +++ b/arch/arm64/include/asm/kvm_asm.h @@ -155,6 +155,7 @@ struct kvm_nvhe_init_params { unsigned long tpidr_el2; unsigned long hyp_stack_ptr; unsigned long vector_ptr; + unsigned long psci_cpu_entry_fn; }; enum kvm_nvhe_psci_state { diff --git a/arch/arm64/kernel/asm-offsets.c b/arch/arm64/kernel/asm-offsets.c index 0cbb86135c7c..ffc84e68ad97 100644 --- a/arch/arm64/kernel/asm-offsets.c +++ b/arch/arm64/kernel/asm-offsets.c @@ -114,6 +114,7 @@ int main(void) DEFINE(NVHE_INIT_TPIDR_EL2, offsetof(struct kvm_nvhe_init_params, tpidr_el2)); DEFINE(NVHE_INIT_STACK_PTR, offsetof(struct kvm_nvhe_init_params, hyp_stack_ptr)); DEFINE(NVHE_INIT_VECTOR_PTR, offsetof(struct kvm_nvhe_init_params, vector_ptr)); + DEFINE(NVHE_INIT_PSCI_CPU_ENTRY_FN, offsetof(struct kvm_nvhe_init_params, psci_cpu_entry_fn)); #endif #ifdef CONFIG_CPU_PM DEFINE(CPU_CTX_SP, offsetof(struct cpu_suspend_ctx, sp)); diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-init.S b/arch/arm64/kvm/hyp/nvhe/hyp-init.S index 1726cc44b3ee..dd297a1a8f82 100644 --- a/arch/arm64/kvm/hyp/nvhe/hyp-init.S +++ b/arch/arm64/kvm/hyp/nvhe/hyp-init.S @@ -6,6 +6,7 @@ #include #include +#include #include #include @@ -159,6 +160,35 @@ alternative_else_nop_endif ret SYM_CODE_END(___kvm_hyp_init) +SYM_CODE_START(__kvm_hyp_cpu_entry) + msr SPsel, #1 // We want to use SP_EL{1,2} + + /* + * Check that the core was booted in EL2. Loop indefinitely if not + * because it cannot be safely given to the host without installing KVM. + */ + mrs x1, CurrentEL + cmp x1, #CurrentEL_EL2 + b.ne . + + /* Initialize EL2 CPU state to sane values. */ + mov x29, x0 + init_el2_state nvhe + mov x0, x29 + + /* + * Load hyp VA of C entry function. Must do so before switching on the + * MMU because the struct pointer is PA and not identity-mapped in hyp. + */ + ldr x29, [x0, #NVHE_INIT_PSCI_CPU_ENTRY_FN] + + /* Enable MMU, set vectors and stack. */ + bl ___kvm_hyp_init + + /* Leave idmap. */ + br x29 +SYM_CODE_END(__kvm_hyp_cpu_entry) + SYM_CODE_START(__kvm_handle_stub_hvc) cmp x0, #HVC_SOFT_RESTART b.ne 1f From patchwork Wed Nov 4 18:36:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Brazdil X-Patchwork-Id: 11881903 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=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 B4CECC4742C for ; Wed, 4 Nov 2020 18:41:00 +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 57D9520739 for ; Wed, 4 Nov 2020 18:41:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="HIDRAsb2"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="K5lok9pX" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 57D9520739 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=TL/rne2oGrE5feUHRLIGs8Cal4+HQuTCJTnbQJacSek=; b=HIDRAsb2MWBbmO2+LOx2u3cRW ROROxUG4k3OCWR286xsTvStkxa++uZ3rGsjLwHLErD4OyXzKbGx+sn5J10K0CDIwysbHOP3Bdak3u x8MWDnLOg0t4l0Q81PeHdeLPgDtdYMEj7+mP2831dKUNJNKYZwBS+rRWSKNMNnD3m1tPLFo+6+dHx EHakO9XnSJFdReaVVyZzpTTWGQg/VsCbgAwiGhzuexATG/TBioYye7OhxFb73hy6azTwZF25nSq/W tAtQOINpG1LuyEL1NHR+VyB0hTVPItNJm2SXcWDy8741w5gOZvqt8+6KLGBmzGXYl+kqy1IfR3clv rmMIMUVwQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaNho-0003o0-JE; Wed, 04 Nov 2020 18:40:24 +0000 Received: from mail-wm1-x344.google.com ([2a00:1450:4864:20::344]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaNeu-0001ul-Bc for linux-arm-kernel@lists.infradead.org; Wed, 04 Nov 2020 18:37:25 +0000 Received: by mail-wm1-x344.google.com with SMTP id s13so115764wmh.4 for ; Wed, 04 Nov 2020 10:37:24 -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=D2iY/f0Emp/4ip0BhAwKDaO2Rz6fYg/GzmDoqFEl2bY=; b=K5lok9pXB0Y/9UmYflOIZMDSkGGd3u23Q2HOsAtpB2GQgdWbczb37MrT+zOkXv17wT XLC9vOedqgdzZukxYXUCfWK/KmpoLoHZtcqTjOfbzpJCWVRhTNn0OILGLegfnc3HNByb EiNdcjUUM9WM0ul/8L3ypEWnLJH522G2M/Whv3nq2waX0fzH+tavrd5hfyBwCWZ47rIH M/e50E9Agk8EUpEMjPxiQU7m7K6l6KIaF84T3dfGn48L0baNZQrBvimX4U882V+fCi24 OWGZhINKWlBuvULKaAafjWdNi+d8GRiezt45uezGFm5E9OxwAXUa2w/uxQNhsQbs+D1U 3Czg== 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=D2iY/f0Emp/4ip0BhAwKDaO2Rz6fYg/GzmDoqFEl2bY=; b=pkvGxcAhDghXfavncSJ11YCL+yt1dxmOjdFrBbPLXAI0AmP5c9pBr16f1SfyN4d//W RH5X71cK3fQ55h0JX1+yhsuE741pQD1D29Pma5ZU7l5MjkXgvlBkzZ9Gjx6uU8ooKOYl VwHXtTMFlegOBlCLYgLgPiU/63EX5LyMmM7TPmceioHpaeDBfhAh2ZbikGJn6zPCnQO4 o+j+KXuQr24/AE3a70kFwdWhjbM/ZHyg4Dvwvj1U5nhoDrzEqw7LHjhLWX+uG+jyteLj WyPoKdjWrAzKBZcTC9HIdPE4I/9bZZ5ZiSDlWRX/F2HmmM3AAXcHBG9NCqUwTuthE77A uHTQ== X-Gm-Message-State: AOAM532TXB6RrwVLnFScduBhhORTighTRzAmI4eqZvvtNIuEukz7b9qP bzD+QgtUZwedcZTridORRV5Ndg== X-Google-Smtp-Source: ABdhPJxUC4D2whchkuH0BO+rZJkzPCz7MjPZCo5o94FSQjlFtlPHCIT/1kpZb8MvemUgYYaqMdixvg== X-Received: by 2002:a1c:b487:: with SMTP id d129mr6273792wmf.38.1604515043233; Wed, 04 Nov 2020 10:37:23 -0800 (PST) Received: from localhost ([2a01:4b00:8523:2d03:c8d2:30f2:53c6:bc2]) by smtp.gmail.com with ESMTPSA id d3sm1049184wrg.16.2020.11.04.10.37.21 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 04 Nov 2020 10:37:22 -0800 (PST) From: David Brazdil To: kvmarm@lists.cs.columbia.edu Subject: [RFC PATCH 21/26] kvm: arm64: Add function to enter host from KVM nVHE hyp code Date: Wed, 4 Nov 2020 18:36:25 +0000 Message-Id: <20201104183630.27513-22-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_133724_457625_A265E9C1 X-CRM114-Status: GOOD ( 15.39 ) 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 All nVHE hyp code is currently executed as handlers of host's HVCs. This will change as nVHE starts intercepting host's PSCI CPU_ON SMCs. The newly booted CPU will need to initialize EL2 state and then enter the host. Add __host_enter function that branches into the existing host state-restoring code after the trap handler would have returned. Signed-off-by: David Brazdil --- arch/arm64/kvm/hyp/nvhe/host.S | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/arch/arm64/kvm/hyp/nvhe/host.S b/arch/arm64/kvm/hyp/nvhe/host.S index ed27f06a31ba..ff04d7115eab 100644 --- a/arch/arm64/kvm/hyp/nvhe/host.S +++ b/arch/arm64/kvm/hyp/nvhe/host.S @@ -41,6 +41,7 @@ SYM_FUNC_START(__host_exit) bl handle_trap /* Restore host regs x0-x17 */ +__host_enter_restore_full: ldp x0, x1, [x29, #CPU_XREG_OFFSET(0)] ldp x2, x3, [x29, #CPU_XREG_OFFSET(2)] ldp x4, x5, [x29, #CPU_XREG_OFFSET(4)] @@ -63,6 +64,14 @@ __host_enter_without_restoring: sb SYM_FUNC_END(__host_exit) +/* + * void __noreturn __host_enter(struct kvm_cpu_context *host_ctxt); + */ +SYM_FUNC_START(__host_enter) + mov x29, x0 + b __host_enter_restore_full +SYM_FUNC_END(__host_enter) + /* * void __noreturn __hyp_do_panic(bool restore_host, u64 spsr, u64 elr, u64 par); */ From patchwork Wed Nov 4 18:36:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Brazdil X-Patchwork-Id: 11881913 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 DD0DEC2D0A3 for ; Wed, 4 Nov 2020 18:42:29 +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 432E6206C1 for ; Wed, 4 Nov 2020 18:42:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="BuxRRQuL"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="TxsjGKaO" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 432E6206C1 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=0UKElAZ9hO1umjkTD0Xf2xKB8lmn6idhSSJIHEK+X9g=; b=BuxRRQuLyLv+lr8h8xfLGh6nn fYEd5mGxVuCxMCuaEteqZBgf/d1S1lYh/xpuzp/A1ZFb5ib9V1GaFl5Hh5qA0pkeMgMobUop1QHbT ZolFOie0EwnraOu9VuTM03ElwgUVX3CJXrREx/yUFo5XD44N0DmUmlKyI8SaP0ka08B/mv3Ynt++J Ga13DGNG+M3LwV6FxU8+lMusAbsBvv4J0MkLWFLzmMwLsDWG3/bh7UqmevDUbjRIsHvHo1rtmb1jE iaP0pztLEYyguobfYAAovU/NYUbUG8oxkV3a9y1+5aOrHjpDJczKhI+LB7xbNtibmluPq/XyhWL9L 82qWoQv6g==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaNi2-0003ya-Dq; Wed, 04 Nov 2020 18:40:38 +0000 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaNew-0001vu-FP for linux-arm-kernel@lists.infradead.org; Wed, 04 Nov 2020 18:37:28 +0000 Received: by mail-wm1-x343.google.com with SMTP id c9so3347087wml.5 for ; Wed, 04 Nov 2020 10:37:26 -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=psZfm56b4NnuZJ+WZzr2WmBKhp4myVTyKEGCmvNKJks=; b=TxsjGKaOrDUcyBdWwkVl6gVpEsI0EyVoMSnxLfzex2v4DhMMNQ7qag73+RtH3qli9m 9yQ++ZOWDsggJ77v/O9QRR0JOGzotQwiGgq5vkaOHRqeOlvpkASr5A7KUIAW9HwhxmuS BVnoC85IyuzhS/a4STCqYT1dZ1Y7Wg9T7rcygwQJOsBVZNs0kH8FUssM0Chk5q3yMAde MaqOnTx5bomYLOASp9DUrdOJABRdWc8bYOQt6H2J/IjVa5FIrJmQ9muxkBEl96AIelSN lYn0gfhjT8XS6RXfifKhx8z7JBPE3g7SfKipoAOkEdyZhXP7Or6UVO1TeJ3x7HG1SXGb /Wqg== 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=psZfm56b4NnuZJ+WZzr2WmBKhp4myVTyKEGCmvNKJks=; b=i/GzxJZjrR+LxfsAURY3eU1nNdvczfG6rhYlfpwMKkUAQ6BeV51vDIaW9l9NSZePRP JQIOebDdVCiHTt+bCc1ycinMEujaeVNhRmw4IeOELqRfbdPhp9/qp44WM/8CctuiNQBF Dz6IMqh7rzOCmvn/G7Cq+2nR6K1dPfRcVg64okYEMfvFjgeSlbDAybZOjwFtYrDDAbwx +R2J3WzlYMtYgWLeW1GlUGrCpWVn5VWrp1SUQWrPOjqkHRDO2gOqonNC9LZl32GxSU/3 vkmnn6c5irhjdvlgEgPEM9tntCo3GkckCIjISP2vCCMsafF8NuE+iZaAvqfzWJkilss0 b11g== X-Gm-Message-State: AOAM5325wqL6nlFgjqm2MKDeMGgoVtovjdl1LHhkyn1UqfTDkAQhwQHZ VkqoUHKNmH+4uKuyp5UOOhZScA== X-Google-Smtp-Source: ABdhPJwKl9g4CE++tDKZXsF8rk/tYeIOyDzjpQI7vYRHtBkW57iNk1cV2dnVQZY8ATbWn1yB9MRW3w== X-Received: by 2002:a7b:c453:: with SMTP id l19mr5898950wmi.2.1604515045200; Wed, 04 Nov 2020 10:37:25 -0800 (PST) Received: from localhost ([2a01:4b00:8523:2d03:c8d2:30f2:53c6:bc2]) by smtp.gmail.com with ESMTPSA id u202sm3665680wmu.23.2020.11.04.10.37.23 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 04 Nov 2020 10:37:24 -0800 (PST) From: David Brazdil To: kvmarm@lists.cs.columbia.edu Subject: [RFC PATCH 22/26] kvm: arm64: Intercept PSCI_CPU_ON host SMC calls Date: Wed, 4 Nov 2020 18:36:26 +0000 Message-Id: <20201104183630.27513-23-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_133726_611629_72F49DAA X-CRM114-Status: GOOD ( 26.58 ) 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 Add a handler of the CPU_ON PSCI call from host. When invoked, it looks up the logical CPU ID corresponding to the provided MPIDR and populates the state struct of the target CPU with the provided x0, pc. It then calls CPU_ON itself, with an entry point in hyp that initializes EL2 state before returning ERET to the provided PC in EL1. Signed-off-by: David Brazdil --- arch/arm64/include/asm/kvm_hyp.h | 1 + arch/arm64/kvm/arm.c | 3 + arch/arm64/kvm/hyp/nvhe/psci.c | 113 +++++++++++++++++++++++++++++++ 3 files changed, 117 insertions(+) diff --git a/arch/arm64/include/asm/kvm_hyp.h b/arch/arm64/include/asm/kvm_hyp.h index cf4c1d16c3e0..2d88a2dad4de 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__ +asmlinkage void __noreturn kvm_host_psci_cpu_entry(void); 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 5b073806463e..166975999ead 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -1334,6 +1334,7 @@ static int kvm_map_vectors(void) static void cpu_init_hyp_mode(void) { + DECLARE_KVM_NVHE_SYM(kvm_host_psci_cpu_entry); struct kvm_nvhe_init_params *params = this_cpu_ptr_nvhe_sym(kvm_init_params); struct arm_smccc_res res; @@ -1351,6 +1352,8 @@ static void cpu_init_hyp_mode(void) params->pgd_ptr = kvm_mmu_get_httbr(); params->vector_ptr = (unsigned long)kern_hyp_va(kvm_ksym_ref(__kvm_hyp_host_vector)); params->hyp_stack_ptr = kern_hyp_va(__this_cpu_read(kvm_arm_hyp_stack_page) + PAGE_SIZE); + params->psci_cpu_entry_fn = (unsigned long)kern_hyp_va( + kvm_ksym_ref(CHOOSE_NVHE_SYM(kvm_host_psci_cpu_entry))); /* * Flush the init params from the data cache because the struct will diff --git a/arch/arm64/kvm/hyp/nvhe/psci.c b/arch/arm64/kvm/hyp/nvhe/psci.c index 00dc0cab860c..42ee5effa827 100644 --- a/arch/arm64/kvm/hyp/nvhe/psci.c +++ b/arch/arm64/kvm/hyp/nvhe/psci.c @@ -9,12 +9,15 @@ #include #include #include +#include #include #include #include #include +#define INVALID_CPU_ID UINT_MAX + /* Config options set by the host. */ u32 kvm_host_psci_version = PSCI_VERSION(0, 0); u32 kvm_host_psci_function_id[PSCI_FN_MAX]; @@ -24,6 +27,7 @@ s64 hyp_physvirt_offset; static DEFINE_PER_CPU(hyp_spinlock_t, psci_cpu_lock); DEFINE_PER_CPU(enum kvm_nvhe_psci_state, psci_cpu_state); +static DEFINE_PER_CPU(struct vcpu_reset_state, psci_cpu_reset); static u64 get_psci_func_id(struct kvm_cpu_context *host_ctxt) { @@ -79,6 +83,29 @@ static __noreturn unsigned long psci_forward_noreturn(struct kvm_cpu_context *ho hyp_panic(); /* unreachable */ } +static unsigned int find_cpu_id(u64 mpidr) +{ + int i; + + if (mpidr != INVALID_HWID) { + for (i = 0; i < NR_CPUS; i++) { + if (cpu_logical_map(i) == mpidr) + return i; + } + } + + return INVALID_CPU_ID; +} + +static phys_addr_t cpu_entry_pa(void) +{ + extern char __kvm_hyp_cpu_entry[]; + unsigned long kern_va; + + asm volatile("ldr %0, =%1" : "=r" (kern_va) : "S" (__kvm_hyp_cpu_entry)); + return kern_va - kimage_voffset; +} + static int psci_cpu_off(u64 func_id, struct kvm_cpu_context *host_ctxt) { hyp_spinlock_t *cpu_lock = this_cpu_ptr(&psci_cpu_lock); @@ -100,10 +127,76 @@ static int psci_cpu_off(u64 func_id, struct kvm_cpu_context *host_ctxt) return ret; } +static int psci_cpu_on(u64 func_id, struct kvm_cpu_context *host_ctxt) +{ + u64 mpidr = host_ctxt->regs.regs[1] & MPIDR_HWID_BITMASK; + unsigned long pc = host_ctxt->regs.regs[2]; + unsigned long r0 = host_ctxt->regs.regs[3]; + unsigned int cpu_id; + hyp_spinlock_t *cpu_lock; + enum kvm_nvhe_psci_state *cpu_power; + struct vcpu_reset_state *cpu_reset; + struct kvm_nvhe_init_params *cpu_params; + int ret; + + /* + * Find the logical CPU ID for the given MPIDR. The search set is + * the set of CPUs that were online at the point of KVM initialization. + * Booting other CPUs is rejected because their cpufeatures were not + * checked against the finalized capabilities. This could be relaxed + * by doing the feature checks in hyp. + */ + cpu_id = find_cpu_id(mpidr); + if (cpu_id == INVALID_CPU_ID) + return PSCI_RET_INVALID_PARAMS; + + cpu_lock = per_cpu_ptr(&psci_cpu_lock, cpu_id); + cpu_power = per_cpu_ptr(&psci_cpu_state, cpu_id); + cpu_reset = per_cpu_ptr(&psci_cpu_reset, cpu_id); + cpu_params = per_cpu_ptr(&kvm_init_params, cpu_id); + + do { + hyp_spin_lock(cpu_lock); + + if (*cpu_power != KVM_NVHE_PSCI_CPU_OFF) { + if (kvm_host_psci_version == PSCI_VERSION(0, 1)) + ret = PSCI_RET_INVALID_PARAMS; + else if (*cpu_power == KVM_NVHE_PSCI_CPU_ON) + ret = PSCI_RET_ALREADY_ON; + else + ret = PSCI_RET_ON_PENDING; + hyp_spin_unlock(cpu_lock); + return ret; + } + + *cpu_reset = (struct vcpu_reset_state){ + .pc = pc, + .r0 = r0, + }; + + ret = psci_call(func_id, mpidr, cpu_entry_pa(), __hyp_pa(cpu_params)); + + if (ret == PSCI_RET_SUCCESS) + *cpu_power = KVM_NVHE_PSCI_CPU_PENDING_ON; + + hyp_spin_unlock(cpu_lock); + + /* + * If recorded CPU state is OFF but EL3 reports that it's ON, + * we must have hit a race with CPU_OFF on the target core. + * Loop to try again. + */ + } while (ret == PSCI_RET_ALREADY_ON); + + return ret; +} + static unsigned long psci_0_1_handler(u64 func_id, struct kvm_cpu_context *host_ctxt) { if (func_id == kvm_host_psci_function_id[PSCI_FN_CPU_OFF]) return psci_cpu_off(func_id, host_ctxt); + else if (func_id == kvm_host_psci_function_id[PSCI_FN_CPU_ON]) + return psci_cpu_on(func_id, host_ctxt); else if (func_id == kvm_host_psci_function_id[PSCI_FN_MIGRATE]) return psci_forward(host_ctxt); else @@ -125,6 +218,8 @@ static unsigned long psci_0_2_handler(u64 func_id, struct kvm_cpu_context *host_ unreachable(); case PSCI_0_2_FN_CPU_OFF: return psci_cpu_off(func_id, host_ctxt); + case PSCI_0_2_FN64_CPU_ON: + return psci_cpu_on(func_id, host_ctxt); default: return PSCI_RET_NOT_SUPPORTED; } @@ -148,6 +243,24 @@ static unsigned long psci_1_0_handler(u64 func_id, struct kvm_cpu_context *host_ } } +void __noreturn __host_enter(struct kvm_cpu_context *host_ctxt); + +asmlinkage void __noreturn kvm_host_psci_cpu_entry(void) +{ + hyp_spinlock_t *cpu_lock = this_cpu_ptr(&psci_cpu_lock); + enum kvm_nvhe_psci_state *cpu_power = this_cpu_ptr(&psci_cpu_state); + struct vcpu_reset_state *cpu_reset = this_cpu_ptr(&psci_cpu_reset); + struct kvm_cpu_context *host_ctxt = &this_cpu_ptr(&kvm_host_data)->host_ctxt; + + hyp_spin_lock(cpu_lock); + *cpu_power = KVM_NVHE_PSCI_CPU_ON; + host_ctxt->regs.regs[0] = cpu_reset->r0; + write_sysreg_el2(cpu_reset->pc, SYS_ELR); + hyp_spin_unlock(cpu_lock); + + __host_enter(host_ctxt); +} + bool kvm_host_psci_handler(struct kvm_cpu_context *host_ctxt) { u64 func_id = get_psci_func_id(host_ctxt); From patchwork Wed Nov 4 18:36:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Brazdil X-Patchwork-Id: 11881901 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 0CDBAC2D0A3 for ; Wed, 4 Nov 2020 18:41:30 +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 754442067C for ; Wed, 4 Nov 2020 18:41:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="Q/0c0G2m"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="PTFxrsxx" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 754442067C 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=3Iq5JzxyoR0jnUkEkK02MdCOn10rPAAD4XvihGMEQ34=; b=Q/0c0G2ms3W6tsUjsHerT9+Za ZOACoAK6o76gMCyQqBwHkPbTlQFm6WCWwfonITebqodSNHFuhB77SsDkbTrrXLi/CnwyE0/iJcZpR XEe8wZkSTRvJxfOretwUqnvSXRSgpuOE3fuXSN7gts44lrESYBe+J467XTFpr9tuWz0ljc6LGItcg qLUJqOobVlvYWqhQJRjaNngoE2w3ETL2GEf6NjDoyNBdmazMMjsLraYkeSP4Jl72zo2cyWqJz3ho+ dV/Zk8hNmk6lX2Xm0Zd6G21BWxNswOU0WNG8fQvZD0nUzPUOGrHX7s06gpK18AwUzRWmpc/syxaUN LQ/YJa8TA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaNiE-00048L-BW; Wed, 04 Nov 2020 18:40:50 +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 1kaNez-0001wx-Od for linux-arm-kernel@lists.infradead.org; Wed, 04 Nov 2020 18:37:31 +0000 Received: by mail-wm1-x341.google.com with SMTP id d142so3351490wmd.4 for ; Wed, 04 Nov 2020 10:37:29 -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=4axi3BZMWI251/Z2i3b7o8wb6S4cFpifUi2vsGe+rz4=; b=PTFxrsxxpSERkmBRu9fPY5EKuAOc5OMAk+oP0QxNUjwk1I4qOAxjjuDjwlbiIQiOi4 ENPQ8dyCyKiCtZYIUoXP4qNzgO1iQmho4X26GDMojC0ezu7o+eSB9bOWq4XwW/fs9VsO GK+U7yFays8yxLyrBp6Ib20GJbzuKSQMyHfvfLWNZ2hziMNn+LNIYgMyU308/fzbV2UF OHxgxnoPZgOGtvfH4FD78QPYcZo6KN3V9aMoEobtBl8VI6DoiYPHBWqXUbTXgtrG9Xbp WcUVQDUTe6Bb2sVj3CdVNgiY1YkUaOtdTU0HThcbNldjcSi8LHR5ARyKviCnMhX0Jb7t IyDQ== 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=4axi3BZMWI251/Z2i3b7o8wb6S4cFpifUi2vsGe+rz4=; b=ljvl2mPqKyyfrin+bK+bAAOe1TwfDZy7YW5JVwheJ+9z/ACWf29tYnfB9dlyl7YcMV 84Kr3tfzacD2k6wPa41xxGgzr2EAQnWWoJMTCBwUzwj+8jJ2q79G9WvIfr2+Fmv4pw++ E5cWucpCd00nOT8kgFNgtA4yghz2J5dRqLTyGT61J6d6bn/JGtwuWkXyw/bQl4XUbezJ nXRufVDm4gqrJw3soLVH9Ipe2PR/UVZ7CHZnwd361lGb5dDxZqFw68EeCx2ydOfBH4FI i6T4por0TR3EcuLEUDherEEy9SPgcoPSwYQhTDOqezv6C3MpnTbz7HAiyp/wjv4XGcwV IHCw== X-Gm-Message-State: AOAM533kyKA2EyPJEeAtqjrlHBJAS20zB99nvyNQInnGFikTY2A+Oiyx GpkKdupHtnblTZQ2itaIpy5wkw== X-Google-Smtp-Source: ABdhPJyT68yOzbnYNGsOmY+iR0h6yG3pNS2GyT+gN1TQUnNhPh79E6sRyGypylEuZinN7xbmJFetAA== X-Received: by 2002:a1c:5545:: with SMTP id j66mr6336527wmb.31.1604515047599; Wed, 04 Nov 2020 10:37:27 -0800 (PST) Received: from localhost ([2a01:4b00:8523:2d03:c8d2:30f2:53c6:bc2]) by smtp.gmail.com with ESMTPSA id s11sm3661835wrm.56.2020.11.04.10.37.25 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 04 Nov 2020 10:37:26 -0800 (PST) From: David Brazdil To: kvmarm@lists.cs.columbia.edu Subject: [RFC PATCH 23/26] kvm: arm64: Intercept host's CPU_SUSPEND PSCI SMCs Date: Wed, 4 Nov 2020 18:36:27 +0000 Message-Id: <20201104183630.27513-24-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_133730_127296_D0C4213D X-CRM114-Status: GOOD ( 22.11 ) 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 Add a handler of CPU_SUSPEND host PSCI SMCs. When invoked, it determines whether the requested power state loses context, ie. whether it is indistinguishable from a WHI or whether it is a deeper sleep state that behaves like a CPU_OFF+CPU_ON. If it's the former, it forwards the call to EL3 and returns to the host after waking up. If it's the latter, it saves r0,pc of the host into and makes the same call to EL3 with the hyp CPU entry point. When the core wakes up, EL2 state is initialized before dropping back to EL1. Signed-off-by: David Brazdil --- arch/arm64/kvm/arm.c | 2 ++ arch/arm64/kvm/hyp/nvhe/psci.c | 49 +++++++++++++++++++++++++++++++++- drivers/firmware/psci/psci.c | 9 ------- include/uapi/linux/psci.h | 7 +++++ 4 files changed, 57 insertions(+), 10 deletions(-) diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index 166975999ead..6fbda652200b 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -1521,9 +1521,11 @@ 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]; + extern u32 kvm_nvhe_sym(kvm_host_psci_cpu_suspend_feature); int cpu; kvm_nvhe_sym(kvm_host_psci_version) = psci_driver_version; + kvm_nvhe_sym(kvm_host_psci_cpu_suspend_feature) = psci_cpu_suspend_feature; memcpy(kvm_nvhe_sym(kvm_host_psci_function_id), psci_function_id, sizeof(psci_function_id)); diff --git a/arch/arm64/kvm/hyp/nvhe/psci.c b/arch/arm64/kvm/hyp/nvhe/psci.c index 42ee5effa827..4899c8319bb4 100644 --- a/arch/arm64/kvm/hyp/nvhe/psci.c +++ b/arch/arm64/kvm/hyp/nvhe/psci.c @@ -21,6 +21,7 @@ /* Config options set by the host. */ u32 kvm_host_psci_version = PSCI_VERSION(0, 0); u32 kvm_host_psci_function_id[PSCI_FN_MAX]; +u32 kvm_host_psci_cpu_suspend_feature; s64 hyp_physvirt_offset; #define __hyp_pa(x) ((phys_addr_t)(x) + hyp_physvirt_offset) @@ -83,6 +84,20 @@ static __noreturn unsigned long psci_forward_noreturn(struct kvm_cpu_context *ho hyp_panic(); /* unreachable */ } +static bool psci_has_ext_power_state(void) +{ + return kvm_host_psci_cpu_suspend_feature & PSCI_1_0_FEATURES_CPU_SUSPEND_PF_MASK; +} + +static bool psci_power_state_loses_context(u32 state) +{ + const u32 mask = psci_has_ext_power_state() ? + PSCI_1_0_EXT_POWER_STATE_TYPE_MASK : + PSCI_0_2_POWER_STATE_TYPE_MASK; + + return state & mask; +} + static unsigned int find_cpu_id(u64 mpidr) { int i; @@ -106,6 +121,34 @@ static phys_addr_t cpu_entry_pa(void) return kern_va - kimage_voffset; } +static int psci_cpu_suspend(u64 func_id, struct kvm_cpu_context *host_ctxt) +{ + u64 power_state = host_ctxt->regs.regs[1]; + unsigned long pc = host_ctxt->regs.regs[2]; + unsigned long r0 = host_ctxt->regs.regs[3]; + hyp_spinlock_t *cpu_lock; + struct vcpu_reset_state *cpu_reset; + struct kvm_nvhe_init_params *cpu_params; + + if (!psci_power_state_loses_context(power_state)) { + /* This power state has the same semantics as WFI. */ + return psci_call(PSCI_0_2_FN64_CPU_SUSPEND, 0, 0, 0); + } + + cpu_lock = this_cpu_ptr(&psci_cpu_lock); + cpu_reset = this_cpu_ptr(&psci_cpu_reset); + cpu_params = this_cpu_ptr(&kvm_init_params); + + /* Resuming from this state has the same semantics as CPU_ON. */ + hyp_spin_lock(cpu_lock); + *cpu_reset = (struct vcpu_reset_state){ + .pc = pc, + .r0 = r0, + }; + hyp_spin_unlock(cpu_lock); + return psci_call(func_id, power_state, cpu_entry_pa(), __hyp_pa(cpu_params)); +} + static int psci_cpu_off(u64 func_id, struct kvm_cpu_context *host_ctxt) { hyp_spinlock_t *cpu_lock = this_cpu_ptr(&psci_cpu_lock); @@ -193,7 +236,9 @@ static int psci_cpu_on(u64 func_id, struct kvm_cpu_context *host_ctxt) static unsigned long psci_0_1_handler(u64 func_id, struct kvm_cpu_context *host_ctxt) { - if (func_id == kvm_host_psci_function_id[PSCI_FN_CPU_OFF]) + if (func_id == kvm_host_psci_function_id[PSCI_FN_CPU_SUSPEND]) + return psci_cpu_suspend(func_id, host_ctxt); + else if (func_id == kvm_host_psci_function_id[PSCI_FN_CPU_OFF]) return psci_cpu_off(func_id, host_ctxt); else if (func_id == kvm_host_psci_function_id[PSCI_FN_CPU_ON]) return psci_cpu_on(func_id, host_ctxt); @@ -216,6 +261,8 @@ static unsigned long psci_0_2_handler(u64 func_id, struct kvm_cpu_context *host_ case PSCI_0_2_FN_SYSTEM_RESET: psci_forward_noreturn(host_ctxt); unreachable(); + case PSCI_0_2_FN64_CPU_SUSPEND: + return psci_cpu_suspend(func_id, host_ctxt); case PSCI_0_2_FN_CPU_OFF: return psci_cpu_off(func_id, host_ctxt); case PSCI_0_2_FN64_CPU_ON: diff --git a/drivers/firmware/psci/psci.c b/drivers/firmware/psci/psci.c index b6ad237b1518..387e24409da7 100644 --- a/drivers/firmware/psci/psci.c +++ b/drivers/firmware/psci/psci.c @@ -62,15 +62,6 @@ static psci_fn *invoke_psci_fn; u32 psci_function_id[PSCI_FN_MAX]; -#define PSCI_0_2_POWER_STATE_MASK \ - (PSCI_0_2_POWER_STATE_ID_MASK | \ - PSCI_0_2_POWER_STATE_TYPE_MASK | \ - PSCI_0_2_POWER_STATE_AFFL_MASK) - -#define PSCI_1_0_EXT_POWER_STATE_MASK \ - (PSCI_1_0_EXT_POWER_STATE_ID_MASK | \ - PSCI_1_0_EXT_POWER_STATE_TYPE_MASK) - u32 psci_cpu_suspend_feature; static bool psci_system_reset2_supported; diff --git a/include/uapi/linux/psci.h b/include/uapi/linux/psci.h index 0d52b8dbe8c2..df3d85ce86f7 100644 --- a/include/uapi/linux/psci.h +++ b/include/uapi/linux/psci.h @@ -65,6 +65,10 @@ #define PSCI_0_2_POWER_STATE_AFFL_SHIFT 24 #define PSCI_0_2_POWER_STATE_AFFL_MASK \ (0x3 << PSCI_0_2_POWER_STATE_AFFL_SHIFT) +#define PSCI_0_2_POWER_STATE_MASK \ + (PSCI_0_2_POWER_STATE_ID_MASK | \ + PSCI_0_2_POWER_STATE_TYPE_MASK | \ + PSCI_0_2_POWER_STATE_AFFL_MASK) /* PSCI extended power state encoding for CPU_SUSPEND function */ #define PSCI_1_0_EXT_POWER_STATE_ID_MASK 0xfffffff @@ -72,6 +76,9 @@ #define PSCI_1_0_EXT_POWER_STATE_TYPE_SHIFT 30 #define PSCI_1_0_EXT_POWER_STATE_TYPE_MASK \ (0x1 << PSCI_1_0_EXT_POWER_STATE_TYPE_SHIFT) +#define PSCI_1_0_EXT_POWER_STATE_MASK \ + (PSCI_1_0_EXT_POWER_STATE_ID_MASK | \ + PSCI_1_0_EXT_POWER_STATE_TYPE_MASK) /* PSCI v0.2 affinity level state returned by AFFINITY_INFO */ #define PSCI_0_2_AFFINITY_LEVEL_ON 0 From patchwork Wed Nov 4 18:36:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Brazdil X-Patchwork-Id: 11881923 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=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 95190C2D0A3 for ; Wed, 4 Nov 2020 18:42:50 +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 15C86206C1 for ; Wed, 4 Nov 2020 18:42:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="XiQsLc1U"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="Wd2U/unp" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 15C86206C1 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=pyQsG0Ruz0OpRYTI4tEcyCVltw5cXpqR9bG8dN06IVQ=; b=XiQsLc1UfZdwYlReLgSGndobn P9hSXRIJJEre6NUa3HCQo2RKDnpclbkVJI8FEkwVW2c7o97Xdqn9EiMVjG7KLnQspV20+uqilN9sN dGfkYjA0DSvlgL6IW1ibPH9mV6IIikvgWODLOr09u0tEwkkmws03ruOOIebKMWyoA2Mq/FBEaz398 saBXHuS3hLa13C5HKQSTPEwuBhjiGBEAi56Yf/JhEXVbjKVkJXTHIup1DqkUOEqonSBmIlpVrrh6F hJRQ/G22rlx11W3Xv61W10RDMrC7Ho2dK4IAHnvvLDIHkY+itI4l11FpjRyXFlOGvRBqWLQXtdi6N 3X/Dag8Aw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaNiM-0004Cj-OY; Wed, 04 Nov 2020 18:40:58 +0000 Received: from mail-wm1-x344.google.com ([2a00:1450:4864:20::344]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaNf1-0001yM-BF for linux-arm-kernel@lists.infradead.org; Wed, 04 Nov 2020 18:37:32 +0000 Received: by mail-wm1-x344.google.com with SMTP id k18so3266875wmj.5 for ; Wed, 04 Nov 2020 10:37:31 -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=EXNwt+3vSlZrX0Tc14BJDd1gNrfJjl5kGrrEIH8XAj4=; b=Wd2U/unpY3ZmVHfcTbXAiJY7KLJhty+qkCnEOe1v+9gF7Tk+esJECns+5NE7xRADVQ rb4jMmrIrDFF3Uqc+kw+TsQP0kUBbP0Q60mBlfNxiHzEXnQZF440tMQx2el8T+naYfSe nl6S2po85sezmLtPjaY/udhRbTngUIYz9zKldqnrNaoNQummnBHmMim25jYYlhSDGnMB Cuq7Q+xfCJoLb+/MPsBLXPPSxHnCmLW/mhKnoYOoXXFQRNHjTAzA522j5kTSmzHtOXCP IKtntiI2vPQxFCCjANt2TbA2A8r58wUouHeIdCcZ/vjLL7AFsxzBAHJM1tvSTiqOAKAb /xjQ== 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=EXNwt+3vSlZrX0Tc14BJDd1gNrfJjl5kGrrEIH8XAj4=; b=ebWrXbI/yLJ4aDcieUoZKbJs8AQSZveWPwppcweR+w0UK79vTRnx4DDvbzTxNmr0fU 89ZL9uwPJNjM+3eQKpPnd99Uo4eGkME8qTIzxBYb1L+49GKQw8zfyEh3YVKrnK40U4KR GWaTUCIvNlKWkCa5gihiOq2Yd0gWPsH1Wdf8y/s4ryEk3l/z3rMQ5ZpFczyEd8OE0mpz IWEHDFxKJ0SRY986fBIX1r0HdMnfu0BlFhJFbqtmxZV57ElVR5w5z6eZ6o4NZHyDIIAb 0pPmHfjwBOZ4paOyeQycfI/hWsgA1ZskjikxIseZF8ftZLhSnwnQxJoH3UQu1nzJjHER EAjA== X-Gm-Message-State: AOAM530IZ4EZu5aNLCpSuTnjJPSeW9daKQg3P8jo3nx8lBtE25oPB6vI pDAcE9i5MOIECd5XP3ddxBjLpg== X-Google-Smtp-Source: ABdhPJwYR8Ha03TCz1M7oXikmCAwIAt1jt3ItFF9iYz0IjOXIOyB9xrETMaJm4+yQW9aUe1KTMy7ig== X-Received: by 2002:a7b:c401:: with SMTP id k1mr5901008wmi.120.1604515050112; Wed, 04 Nov 2020 10:37:30 -0800 (PST) Received: from localhost ([2a01:4b00:8523:2d03:c8d2:30f2:53c6:bc2]) by smtp.gmail.com with ESMTPSA id h4sm3635371wrp.52.2020.11.04.10.37.28 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 04 Nov 2020 10:37:28 -0800 (PST) From: David Brazdil To: kvmarm@lists.cs.columbia.edu Subject: [RFC PATCH 24/26] kvm: arm64: Keep nVHE EL2 vector installed Date: Wed, 4 Nov 2020 18:36:28 +0000 Message-Id: <20201104183630.27513-25-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_133731_451107_01D62BBE X-CRM114-Status: GOOD ( 16.74 ) 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 KVM by default keeps the stub vector installed and installs the nVHE vector only briefly for init and later on demand. Change this policy to install the vector at init and then never uninstall it. Signed-off-by: David Brazdil --- arch/arm64/kvm/arm.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index 6fbda652200b..3dff6af69eca 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -64,6 +64,11 @@ static bool vgic_present; static DEFINE_PER_CPU(unsigned char, kvm_arm_hardware_enabled); DEFINE_STATIC_KEY_FALSE(userspace_irqchip_in_use); +static bool keep_hyp_installed(void) +{ + return !is_kernel_in_hyp_mode(); +} + int kvm_arch_vcpu_should_kick(struct kvm_vcpu *vcpu) { return kvm_vcpu_exiting_guest_mode(vcpu) == IN_GUEST_MODE; @@ -1430,7 +1435,8 @@ static void _kvm_arch_hardware_disable(void *discard) void kvm_arch_hardware_disable(void) { - _kvm_arch_hardware_disable(NULL); + if (!keep_hyp_installed()) + _kvm_arch_hardware_disable(NULL); } #ifdef CONFIG_CPU_PM @@ -1473,11 +1479,13 @@ static struct notifier_block hyp_init_cpu_pm_nb = { static void __init hyp_cpu_pm_init(void) { - cpu_pm_register_notifier(&hyp_init_cpu_pm_nb); + if (!keep_hyp_installed()) + cpu_pm_register_notifier(&hyp_init_cpu_pm_nb); } static void __init hyp_cpu_pm_exit(void) { - cpu_pm_unregister_notifier(&hyp_init_cpu_pm_nb); + if (!keep_hyp_installed()) + cpu_pm_unregister_notifier(&hyp_init_cpu_pm_nb); } #else static inline void hyp_cpu_pm_init(void) @@ -1580,7 +1588,8 @@ static int init_subsystems(void) kvm_coproc_table_init(); out: - on_each_cpu(_kvm_arch_hardware_disable, NULL, 1); + if (err || !keep_hyp_installed()) + on_each_cpu(_kvm_arch_hardware_disable, NULL, 1); return err; } From patchwork Wed Nov 4 18:36:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Brazdil X-Patchwork-Id: 11881925 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 42E86C4741F for ; Wed, 4 Nov 2020 18:43:10 +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 C770C20719 for ; Wed, 4 Nov 2020 18:43:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="MREeEZym"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="B4IhEM6i" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C770C20719 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=yoxEpBQOZt0H9SemakFeBP701/YO+/99nKj9iEhgOHM=; b=MREeEZym/pbM7MIsK3eGmTUgn FyuLTeT2gBotYApzt++bC4DG7MK1ex2RKyIQm2UhHU2j0EnwAG6ZevkPwpLJ3qPI05oOcRPXNlWKS P0vCV+az9rDYJeA7r46azvv55H5azUZz4SiblLIRnMXagNIDMaPMIdhgUdJ8yHwAtGZVeUkZybZEi R8jBRh/VUbPJqrpRjgEeLlCw3NY7FL13YVGbM+a7sQtDANVf1rAQzYk4OZKGdh7RWqWYHP+7QT/UO 74LExhJZgNE7OpmyfT5Ohqe06l99lK8y71R/Re4d4EX6BPSKRMgi2hCAW2NG9H6H/iER8IG9bLLWf DrjceWQlg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaNih-0004R9-Oj; Wed, 04 Nov 2020 18:41:19 +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 1kaNf3-0001zc-RL for linux-arm-kernel@lists.infradead.org; Wed, 04 Nov 2020 18:37:36 +0000 Received: by mail-wr1-x443.google.com with SMTP id w1so23197097wrm.4 for ; Wed, 04 Nov 2020 10:37:33 -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=iZCBnLMJdYcxZwBzQ3Sarf0ddb9E9I/tpQ6NvhqLTsI=; b=B4IhEM6i7eYAD2ymU3gP34oS4vn1E/wZkt1PdaiPM5/5CtTpRosOvwsKQKo0X96cCK 0+g8w1fiydBxSAvZustLDS0jWbYdNwVoVeSGiVp01VErE+3NmXu2Zguj4zhDd3RQwoNG en6FWwAw0dLaqo1BuTfum7Ta4FxBg0BjZWLF6bqxR53vkiKPlHv0os4fdHkCfVcSOUha CL9qYevzyEmHuWS9pBv5RwzPROVRKDWww8V+k967+KldgQKur4GRkaO8J8q5SOBxRSpK YvVewWO1VZib5H/HpCQ7HbmNXpRdZWPNttE3mKM8sUogeVrex2BX1GvjsLxVqnF1JotD ALOQ== 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=iZCBnLMJdYcxZwBzQ3Sarf0ddb9E9I/tpQ6NvhqLTsI=; b=Tc8Xivd12MXVoXcOKxuph1O3XqpQYTNo13AAyifECJtsV920AQLEnVrUHMmDxq4RMX QNabtU4wxUK4DXuQaSq34vqNYa/DPj8VLoWQ3sqWw5FfdIG/Q6r7Ynsdv3Tqkt1BFu0I 4qnpaWOaNu2MISd74TJ6Vm7JiAbByVYa5u3CgKSiapFB01RL/ku5ltJO4YIO+sMkIQ+W QNQahPZZ2/gG0dgQfBVrGAcFMTiNG9WDVZBLNbO8fCC514aWqJ+FhHuymEE3XvrJN8/T lLiSFts5owFqUP1Lfy1/ZZSa7G6/zvNwe12BI7QqlVTEqnJBBcTl5tKFv3w9PlGKnG90 KGGg== X-Gm-Message-State: AOAM533JKFj9eNeC1XGZYisRUB9YddtEQfCSV9L2N6mZEpGCVdUrQ/Ga UcXoF9n0AQtfz0emYAd6wHj7DA== X-Google-Smtp-Source: ABdhPJwUdVDMguoQlzBKa3UHyXk6rhVG7P6EPtc5ja0S5UDbXD4NiQS5VqgFkkGyhfeVbjM4nCuCpA== X-Received: by 2002:adf:fe48:: with SMTP id m8mr33208177wrs.127.1604515052352; Wed, 04 Nov 2020 10:37:32 -0800 (PST) Received: from localhost ([2a01:4b00:8523:2d03:c8d2:30f2:53c6:bc2]) by smtp.gmail.com with ESMTPSA id r10sm3396829wmg.16.2020.11.04.10.37.30 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 04 Nov 2020 10:37:31 -0800 (PST) From: David Brazdil To: kvmarm@lists.cs.columbia.edu Subject: [RFC PATCH 25/26] kvm: arm64: Trap host SMCs Date: Wed, 4 Nov 2020 18:36:29 +0000 Message-Id: <20201104183630.27513-26-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_133735_684761_7CF093AA X-CRM114-Status: GOOD ( 14.87 ) 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 While nVHE KVM is installed, start trapping all host SMCs. By default, these are simply forwarded to EL3, but PSCI SMCs are validated first. Create new constant HCR_HOST_NVHE_STUB_FLAGS with the old set of HCR flags to use before the nVHE vector is installed or when switching back to stub vector. Extend HCR_HOST_NVHE_FLAGS to contain HCR_TSC. Set HCR_EL2 to it before installing nVHE vector. Signed-off-by: David Brazdil --- arch/arm64/include/asm/kvm_arm.h | 3 ++- arch/arm64/kernel/head.S | 2 +- arch/arm64/kvm/hyp/nvhe/hyp-init.S | 6 ++++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/arch/arm64/include/asm/kvm_arm.h b/arch/arm64/include/asm/kvm_arm.h index 64ce29378467..04b862955f32 100644 --- a/arch/arm64/include/asm/kvm_arm.h +++ b/arch/arm64/include/asm/kvm_arm.h @@ -79,7 +79,8 @@ HCR_AMO | HCR_SWIO | HCR_TIDCP | HCR_RW | HCR_TLOR | \ HCR_FMO | HCR_IMO | HCR_PTW ) #define HCR_VIRT_EXCP_MASK (HCR_VSE | HCR_VI | HCR_VF) -#define HCR_HOST_NVHE_FLAGS (HCR_RW | HCR_API | HCR_APK | HCR_ATA) +#define HCR_HOST_NVHE_STUB_FLAGS (HCR_RW | HCR_API | HCR_APK | HCR_ATA) +#define HCR_HOST_NVHE_FLAGS (HCR_HOST_NVHE_STUB_FLAGS | HCR_TSC) #define HCR_HOST_VHE_FLAGS (HCR_RW | HCR_TGE | HCR_E2H) /* TCR_EL2 Registers bits */ diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S index e7270b63abed..ea17413a04e0 100644 --- a/arch/arm64/kernel/head.S +++ b/arch/arm64/kernel/head.S @@ -522,7 +522,7 @@ SYM_FUNC_START(el2_setup) #endif SYM_INNER_LABEL(el2_setup_nvhe, SYM_L_LOCAL) - mov_q x0, HCR_HOST_NVHE_FLAGS + mov_q x0, HCR_HOST_NVHE_STUB_FLAGS msr hcr_el2, x0 isb diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-init.S b/arch/arm64/kvm/hyp/nvhe/hyp-init.S index dd297a1a8f82..97684deba6c1 100644 --- a/arch/arm64/kvm/hyp/nvhe/hyp-init.S +++ b/arch/arm64/kvm/hyp/nvhe/hyp-init.S @@ -88,6 +88,10 @@ SYM_CODE_END(__kvm_hyp_init) * x0: struct kvm_nvhe_init_params PA */ SYM_CODE_START(___kvm_hyp_init) + mov_q x1, HCR_HOST_NVHE_FLAGS + msr hcr_el2, x1 + isb + ldr x1, [x0, #NVHE_INIT_TPIDR_EL2] msr tpidr_el2, x1 @@ -220,6 +224,8 @@ reset: bic x5, x5, x6 // Clear SCTL_M and etc pre_disable_mmu_workaround msr sctlr_el2, x5 + mov_q x5, HCR_HOST_NVHE_STUB_FLAGS + msr hcr_el2, x5 isb /* Install stub vectors */ From patchwork Wed Nov 4 18:36:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Brazdil X-Patchwork-Id: 11881909 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 09448C2D0A3 for ; Wed, 4 Nov 2020 18:42:13 +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 7C605206C1 for ; Wed, 4 Nov 2020 18:42:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="UNg2u/Fc"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="il549hLI" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7C605206C1 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=AsGdxrgjlttRQjOc+7NdGlRcAuIZz+Of+Nc3xvV/kGQ=; b=UNg2u/FcVjjCF9FnVuJ3sKwc7 TCBXyCPn5fiPIf4Urrf93GzLGIGhLhvUh8+mGU1okrIIdXgU71L+hZw9Br36cnQjE0vlCI9GWb2ao urD4OvbhgG/Ic8m1x6GhJO5L5dfbuk3/QK5hovwk4PQcv0/5CmPqEENGc2M/TezIHluRCMH0Eukjr 0dgB2IWx0QJD5/RvzJ2jUbivseaVx8g7WS74fTdWxrktwBBb5Q84R96PVvwonzG4jVbGeYdFdxNK5 TqG8dhsBN9rfQID8oKUaolOxVKs0eqpc8ePqtNGIf1ONYDaC8l/XNvAy+3qBXc1ZZcce6QY/eRaCm fhEl9n0wg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaNix-0004a8-Lw; Wed, 04 Nov 2020 18:41:35 +0000 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaNf5-000203-Uz for linux-arm-kernel@lists.infradead.org; Wed, 04 Nov 2020 18:37:36 +0000 Received: by mail-wr1-x444.google.com with SMTP id w14so23123623wrs.9 for ; Wed, 04 Nov 2020 10:37:35 -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=HMYGIc+ZZLbnQbcx34p2ubDooBhnfGZkiSjL1q0xiNQ=; b=il549hLIFQg0qGoV2QrtJtovxpI7mz6Lm9xqwFQAuBrKk0Z6AC8ta8m/IhticSSWAg nunkDYzvs4sOKQEUNrHD/WF3I2uhhw/LMXkFntRbcYdyktGXJhujOyKn7jXnmAQUZjKX HWqGa+gOsc0TyXjwlKX20YcgvfXtgqTp7D+0BzkajGuiEkOeV+lo+Wug+iAynKlmeoIF fBs0MAQU3p+DN2M/yPDkSBwhSnnCxMkEh3Gygat3MvnDjwWQd21yPXJWRfdjbn8kXXgF Ja1pWoR4q5WXTD7ryuVkLcK79AhJCwCunoJp8jfhSnsqvKNqPlNwzC4naVUk6tC/hjBw D7Iw== 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=HMYGIc+ZZLbnQbcx34p2ubDooBhnfGZkiSjL1q0xiNQ=; b=Qn4paxaOJbX8l/d8Hh8V2mkpTTDeihk7y6mu2v59wd4MKRcp2CprabVAJ6o/fCiBl6 mE0p/AjoPqOasFSXaKFuLyDN5+ksHx5zbqj3KWAXk7/xqrGUexPRKPVjZzYbNbdfASCy HOO1WUzIZL4820BZqX82Fp0IlnSoSg7DFdDabaNtarKP/l5lksh+Km/+rn1y0Bg7vCCQ qGfDqkh8gVmrZAjDGuLplCXTlAtmpLej6jFGDFpBUWEPuVtEgspFW4UVHETD6tSRIDUe xUsdV/92WTiPX1RuMPTPFJ7W5B76VEJiV58E4u08pkT0v8DOHuOvUUGPx+7B5gDY0jlB 7O8A== X-Gm-Message-State: AOAM530hS38YBkPxvemAs3jfttZeccRlnNAoN19FueWqCCnxfukt0+MJ yFq2uR4tOFouVHam01skp/UUXw== X-Google-Smtp-Source: ABdhPJzPIMW7rJz/s7+my12k8/M0wSzNOf/au+3oC9aJIIDx/rVVLNmLVAtHZQ7yu1CygOZyQlw0UQ== X-Received: by 2002:a5d:4a4b:: with SMTP id v11mr4973650wrs.364.1604515054453; Wed, 04 Nov 2020 10:37:34 -0800 (PST) Received: from localhost ([2a01:4b00:8523:2d03:c8d2:30f2:53c6:bc2]) by smtp.gmail.com with ESMTPSA id w11sm3705303wmg.36.2020.11.04.10.37.32 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 04 Nov 2020 10:37:33 -0800 (PST) From: David Brazdil To: kvmarm@lists.cs.columbia.edu Subject: [RFC PATCH 26/26] kvm: arm64: Fix EL2 mode availability checks Date: Wed, 4 Nov 2020 18:36:30 +0000 Message-Id: <20201104183630.27513-27-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_133736_076434_2F30F147 X-CRM114-Status: GOOD ( 18.98 ) 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 With nVHE hyp code interception host's PSCI CPU_ON/OFF/SUSPEND SMCs, from the host's perspective new CPUs start booting in EL1 while previously they would have booted in EL2. The kernel logic which keeps track of the mode CPUs were booted in needs to be adjusted to account for this fact. Add a static key enabled if KVM nVHE initialization is successful. When the key is enabled, is_hyp_mode_available continues to report `true` because its users either treat it a check whether KVM will be / has been initialized, or whether stub HVCs can be made (eg. hibernate). is_hyp_mode_mismatched is changed to report `false` when the key is enabled. That's because all cores' modes matched at the point of KVM init and KVM will not allow cores not present at init to boot. That said, the function is never used after KVM is initialized. Signed-off-by: David Brazdil --- arch/arm64/include/asm/virt.h | 16 ++++++++++++++++ arch/arm64/kvm/arm.c | 5 +++++ 2 files changed, 21 insertions(+) diff --git a/arch/arm64/include/asm/virt.h b/arch/arm64/include/asm/virt.h index 6069be50baf9..597430b5f5aa 100644 --- a/arch/arm64/include/asm/virt.h +++ b/arch/arm64/include/asm/virt.h @@ -65,9 +65,18 @@ extern u32 __boot_cpu_mode[2]; void __hyp_set_vectors(phys_addr_t phys_vector_base); void __hyp_reset_vectors(void); +DECLARE_STATIC_KEY_FALSE(kvm_nvhe_initialized); + /* Reports the availability of HYP mode */ static inline bool is_hyp_mode_available(void) { + /* + * If KVM nVHE is initialized, all CPUs must have been booted in EL2. + * Avoid checking __boot_cpu_mode as CPUs now come up in EL1. + */ + if (IS_ENABLED(CONFIG_KVM) && static_branch_unlikely(&kvm_nvhe_initialized)) + return true; + return (__boot_cpu_mode[0] == BOOT_CPU_MODE_EL2 && __boot_cpu_mode[1] == BOOT_CPU_MODE_EL2); } @@ -75,6 +84,13 @@ static inline bool is_hyp_mode_available(void) /* Check if the bootloader has booted CPUs in different modes */ static inline bool is_hyp_mode_mismatched(void) { + /* + * If KVM nVHE is initialized, all CPUs must have been booted in EL2. + * Avoid checking __boot_cpu_mode as CPUs now come up in EL1. + */ + if (IS_ENABLED(CONFIG_KVM) && static_branch_unlikely(&kvm_nvhe_initialized)) + return false; + return __boot_cpu_mode[0] != __boot_cpu_mode[1]; } diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index 3dff6af69eca..e93956d6235d 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -47,6 +47,8 @@ __asm__(".arch_extension virt"); #endif +DEFINE_STATIC_KEY_FALSE(kvm_nvhe_initialized); + DECLARE_KVM_HYP_PER_CPU(unsigned long, kvm_hyp_vector); static DEFINE_PER_CPU(unsigned long, kvm_arm_hyp_stack_page); @@ -1841,6 +1843,9 @@ int kvm_arch_init(void *opaque) if (err) goto out_hyp; + if (!in_hyp_mode) + static_branch_enable(&kvm_nvhe_initialized); + if (in_hyp_mode) kvm_info("VHE mode initialized successfully\n"); else