From patchwork Mon Nov 16 20:43: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: 11910825 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 33158C2D0A3 for ; Mon, 16 Nov 2020 20:49: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 AAD912223D for ; Mon, 16 Nov 2020 20:49: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="lXJElsOd"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="V0kKFYAC" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AAD912223D 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=Zvpi+kTp8+ta7q+izvgsRBXFKdCGp/7KJGCIjd6Pv14=; b=lXJElsOdTAna1dnCfarKvTYUE 7j+1M4Qla072w42BU1WParHFukie9QQpe4gOreIkeTkucQk33JEmPwnodnc3gFhGEaIckWETIKBNZ 9sQUrA7dPpCzt42ZtxdezGF5uEkaK97HtbtW0NaJiFmTt16x60jwDps+tTlq9uFisshYE5+gtDa04 8CBn6+9RPWmKPnUH4kwUTr6oT9WU4V6nrMDXuzjsqw57rjWc4KfmzflqzfNKRW7Kx8HpChv3xcdFL ykUb4hmktuzAyGBzbslITFJtRgGlCKaiPzCmoG1ZRilvaWXDh4cCRwUYvE0RP4S9MiAX/WBsVuiqF G1TC9PB8Q==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kelOM-0000RC-8I; Mon, 16 Nov 2020 20:46:26 +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 1kelLs-0007lR-03 for linux-arm-kernel@lists.infradead.org; Mon, 16 Nov 2020 20:43:56 +0000 Received: by mail-wm1-x344.google.com with SMTP id p22so593651wmg.3 for ; Mon, 16 Nov 2020 12:43:51 -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=tbKc0XACzM2ruUCBvbubjeIAaEVu68JylfPt9mceM1c=; b=V0kKFYACpKx5jE69f+4aUeVVVU0VxycZFFIX0Z1f7dnoyAJr09Ps1E9SsrP/0GOfEU aPhG5sBGQx5FVnsM2+CIFWKtR9QzPGV3r+sDwdzniDxXDodE2urN3MpQBawaYZ2T4IIR xD/KJ3c0EnuyX/Av2vEm1PdejW7PnbDH++SSaafdD9isNZNnqIQfO1OMFacu1LmNLtl8 2zBH0XHJZdSBLpqSLEn+acR3I9sPPF2clR3r380SSkH/u0ZgqN1kp+BO+K699A5dUPFY +irj4fwGT2++WFzSsD4gCBkTDfiqo4T9tJlaVrajFemZJDON9TaBI0yynHgtOyLAYsIM XmdA== 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=tbKc0XACzM2ruUCBvbubjeIAaEVu68JylfPt9mceM1c=; b=TFpKulhjMGhTQoT3FmZV5rr5plyhhObjVTh4kbAOt3NH/YHD/N3pZXsP7n0Zgy62ot jLiNpULRw4gnXfV2X7SzrOZuJXOFBm53kJLrmktIMGaTTro/gqIjsCLBNr5C2Ce2A7Go bFlx6I3Kip7QoHC+cF1lGK1nJLCtfgxUjH108yUvgmYh1na99StQyZRAJmSRlsywkX9r ktDs/0I3EUmAdgIaL8xrWLqrt0HRLoKhAT5raxgtpAguOH8PYauno9ML5fd3Z8VeXpwp WsP42AlFAjaauOwTpYfs6STvz7H02y68U8Bg+1kCe/rfaq7irazV/jqBoAWvcFL1szGh KCSA== X-Gm-Message-State: AOAM531E5fOK5Jn1oZ0GJeGjhLibqI5+KajdjTJVRJqku7G2vWLg9SC6 Ig3P54IpufMi17Y0LEH5H9XcIERteTxI774yjOk= X-Google-Smtp-Source: ABdhPJwqhw97XZrxLyHY9+fXCxOlyroHhFsnnL0TEFTRcWcLWzN0zrDmnJ4SoEdyylNRdDXrSB3g6g== X-Received: by 2002:a7b:cb09:: with SMTP id u9mr694636wmj.109.1605559430793; Mon, 16 Nov 2020 12:43:50 -0800 (PST) Received: from localhost ([2a01:4b00:8523:2d03:bc40:bd71:373a:1b33]) by smtp.gmail.com with ESMTPSA id i6sm530365wma.42.2020.11.16.12.43.49 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 16 Nov 2020 12:43:49 -0800 (PST) From: David Brazdil To: kvmarm@lists.cs.columbia.edu Subject: [PATCH v2 13/24] kvm: arm64: Add offset for hyp VA <-> PA conversion Date: Mon, 16 Nov 2020 20:43:07 +0000 Message-Id: <20201116204318.63987-14-dbrazdil@google.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201116204318.63987-1-dbrazdil@google.com> References: <20201116204318.63987-1-dbrazdil@google.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201116_154352_213115_8215EDD6 X-CRM114-Status: GOOD ( 17.21 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , kernel-team@android.com, Lorenzo Pieralisi , Andrew Walbran , 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/hyp/nvhe/psci-relay.c | 3 +++ arch/arm64/kvm/va_layout.c | 30 +++++++++++++++++++++++++--- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/arch/arm64/kvm/hyp/nvhe/psci-relay.c b/arch/arm64/kvm/hyp/nvhe/psci-relay.c index d75d3f896bfd..1583b63322c4 100644 --- a/arch/arm64/kvm/hyp/nvhe/psci-relay.c +++ b/arch/arm64/kvm/hyp/nvhe/psci-relay.c @@ -16,6 +16,9 @@ /* Config options set by the host. */ u32 __ro_after_init kvm_host_psci_version = PSCI_VERSION(0, 0); u32 __ro_after_init kvm_host_psci_function_id[PSCI_FN_MAX]; +s64 __ro_after_init 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) { diff --git a/arch/arm64/kvm/va_layout.c b/arch/arm64/kvm/va_layout.c index e0404bcab019..744a0d998ad3 100644 --- a/arch/arm64/kvm/va_layout.c +++ b/arch/arm64/kvm/va_layout.c @@ -22,6 +22,30 @@ static u8 tag_lsb; static u64 tag_val; static u64 va_mask; +/* + * Compute HYP VA by using the same computation as kern_hyp_va(). + */ +static u64 __early_kern_hyp_va(u64 addr) +{ + addr &= va_mask; + addr |= tag_val << tag_lsb; + return addr; +} + +/* + * Store a hyp VA <-> PA offset into a hyp-owned variable. + */ +static void init_hyp_physvirt_offset(void) +{ + extern s64 kvm_nvhe_sym(hyp_physvirt_offset); + u64 kern_va, hyp_va; + + /* Compute the offset from the hyp VA and PA of a random symbol. */ + kern_va = (u64)kvm_ksym_ref(__hyp_text_start); + hyp_va = __early_kern_hyp_va(kern_va); + CHOOSE_NVHE_SYM(hyp_physvirt_offset) = (s64)__pa(kern_va) - (s64)hyp_va; +} + /* * We want to generate a hyp VA with the following format (with V == * vabits_actual): @@ -53,6 +77,8 @@ __init void kvm_compute_layout(void) tag_val |= get_random_long() & GENMASK_ULL(vabits_actual - 2, tag_lsb); } tag_val >>= tag_lsb; + + init_hyp_physvirt_offset(); } static u32 compute_instruction(int n, u32 rd, u32 rn) @@ -150,9 +176,7 @@ void kvm_patch_vector_branch(struct alt_instr *alt, /* * Compute HYP VA by using the same computation as kern_hyp_va() */ - addr = (uintptr_t)kvm_ksym_ref(__kvm_hyp_vector); - addr &= va_mask; - addr |= tag_val << tag_lsb; + addr = __early_kern_hyp_va((u64)kvm_ksym_ref(__kvm_hyp_vector)); /* Use PC[10:7] to branch to the same vector in KVM */ addr |= ((u64)origptr & GENMASK_ULL(10, 7));