Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1152499pxu; Fri, 27 Nov 2020 00:34:43 -0800 (PST) X-Google-Smtp-Source: ABdhPJxov0o5YwT83XNMNhclTeFbrGV982FEGIwCRwMBiH4dO8RKFAD6dP8AKJxVQBlZW57RcXCh X-Received: by 2002:aa7:cfcd:: with SMTP id r13mr6544372edy.63.1606466083101; Fri, 27 Nov 2020 00:34:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606466083; cv=none; d=google.com; s=arc-20160816; b=ubq8HjGTGm1av7fyzBn9H/dKTB1rM5Xr1V3rU5gbm7ZsAbEDXLZoL62una2sKPY6Oh hBPP8mund05AXCAGvplO0yvNzbNGFQ2fA6MvrA6TYJwo56xvy/GIJLvNAALr3gDq9OS8 iGzWn+CMyH0z5LeArnJ6jB/hyQWAhOJVanPTO5f9AHCqOm8W//sUkoifp8qtOdDu9HWh eUg8OQILv0QjzG+VnOJpt9sQxwBiCIth037fqyV0iBRwR4D0u9PmR6diFXFQ4qnFMUFj Oa+Ix/b9VsJbOW9QvBr0bbD3PjjyogFYbepFY23fj408CG95Qyw8nhXfKHGPAbI28hiX lP1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=irDOCaoxBC7rYFpDng3539rKfl5EDMRei9R6iacpt5Q=; b=IMM966CdHg78AZKmZ756OUKUncai4rLKDTfeQ4G0qOX7hqSsdSeiECUkpTxz9KqDXs /e5ENX3vhT7rT/eXUfoqVeFA5wINLvZW/w4OjyJegAfGnbosLBUvVbZu/Wdx2lOaiOYt gvLutAYBrvXxwwqLEzXnmzSt8fSvRwCjr+k+k5LOUO0XK3ix2fKsFf3kr4Upnb6kw3ju gzOjc7R9Qdv0QozVuxU6egbabJLBE5RMVtNO6E4wwh+EYrBw66d61P1t1jQ4svyRqpma MRxMbCNANDyBN2+uPH6k/cLYgtmUhiNK0EFIiTkPMK9DDLc+D1qFg0dHENU2Np0KMR6P 5SHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=G+ViC3wP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 89si4758457edc.413.2020.11.27.00.34.18; Fri, 27 Nov 2020 00:34:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=G+ViC3wP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2403789AbgKZPzB (ORCPT + 99 others); Thu, 26 Nov 2020 10:55:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51210 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2403782AbgKZPzA (ORCPT ); Thu, 26 Nov 2020 10:55:00 -0500 Received: from mail-wr1-x444.google.com (mail-wr1-x444.google.com [IPv6:2a00:1450:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 23A42C0617A7 for ; Thu, 26 Nov 2020 07:55:00 -0800 (PST) Received: by mail-wr1-x444.google.com with SMTP id 23so2636052wrc.8 for ; Thu, 26 Nov 2020 07:55: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=irDOCaoxBC7rYFpDng3539rKfl5EDMRei9R6iacpt5Q=; b=G+ViC3wP1aisQEqSrtFyh4agtf+XRj/S5yCOQSPP+B9cEpF3CEG6DUz/bfIazuPr44 ziINsQardil0WvZ7VvAzP+ViHc8X/aDnyhZgkBWKaSicVgTkjL4koXMMvnWUKwj6Tubf yy+Yx/hK3LwwE2ezmO7wOtcTtG/OXrSJrdAmCkUrUTDGlG25Xz7C8mTrmfItIjst/2Po ItFdY9jyph4RS42NCu18FEzXe2QYDp7fg8a3lGHm5/Bq0J2aPx0WhjJGBCWrdIlkvbXW PRBJQEM/Aw0vr3SF+JCrYwHFypXblFfnJAf0xiWqOkWB+uG+6muEhHq41S+AwQVN50o4 /3AQ== 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=irDOCaoxBC7rYFpDng3539rKfl5EDMRei9R6iacpt5Q=; b=f5hUblwYWwVY0t/k8Hq3/d+LIp55m8SXRfC8+umbX3b+l8tDIcqI3sUT5VJ8wUYoe+ WqwEJIGq6UBUeWIS5BzjWRUkKfMReA0H9jNqsuTliVvAKK58+ZViCfzoByR0GgChQkNZ u278RpIkYH3jUTzF+bxaCU/mFA8r93QX8t6v8HdAEOJCAS7WN1xSLv6ni/utoZEnUVGo qYpU3eKGRZJgxh42+N3tyr6BWsacJnRDmuj4wQyvxuVbl9fTQ5G+QnWmUl8xo0S2YwH8 P4fqUTdxtaF4jRkoUPe/KcYO0A7j0SUJHvdgRMyBlbROQXCLSYH06xRaHVGSnxdDmTeG 2gRg== X-Gm-Message-State: AOAM531cmC5/bxcP0MauVR9BFl5vGUjrBQ9+5v2E2/8NSbYiFJBeR6Ce f7oc57zaoozjmxxI4OC1g/xxEA== X-Received: by 2002:adf:f102:: with SMTP id r2mr4652297wro.315.1606406098667; Thu, 26 Nov 2020 07:54:58 -0800 (PST) Received: from localhost ([2a01:4b00:8523:2d03:f008:704d:8d4b:9951]) by smtp.gmail.com with ESMTPSA id 35sm9328533wro.71.2020.11.26.07.54.57 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 26 Nov 2020 07:54:57 -0800 (PST) From: David Brazdil To: kvmarm@lists.cs.columbia.edu Cc: Jonathan Corbet , Catalin Marinas , Will Deacon , Marc Zyngier , James Morse , Julien Thierry , Suzuki K Poulose , Dennis Zhou , Tejun Heo , Christoph Lameter , Mark Rutland , Lorenzo Pieralisi , Sudeep Holla , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kernel-team@android.com, David Brazdil Subject: [PATCH v3 15/23] kvm: arm64: Add offset for hyp VA <-> PA conversion Date: Thu, 26 Nov 2020 15:54:13 +0000 Message-Id: <20201126155421.14901-16-dbrazdil@google.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201126155421.14901-1-dbrazdil@google.com> References: <20201126155421.14901-1-dbrazdil@google.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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 44a9fb462d24..e7091d89f0fc 100644 --- a/arch/arm64/kvm/hyp/nvhe/psci-relay.c +++ b/arch/arm64/kvm/hyp/nvhe/psci-relay.c @@ -18,6 +18,9 @@ /* Config options set by the host. */ u32 __ro_after_init kvm_host_psci_version; 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 4130b72e6891..d8cc51bd60bf 100644 --- a/arch/arm64/kvm/va_layout.c +++ b/arch/arm64/kvm/va_layout.c @@ -23,6 +23,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): @@ -54,6 +78,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) @@ -146,9 +172,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)); -- 2.29.2.454.gaff20da3a2-goog