From patchwork Thu Nov 19 16:25:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Brazdil X-Patchwork-Id: 11918207 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C9075C6369E for ; Thu, 19 Nov 2020 16:26: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 50D4222261 for ; Thu, 19 Nov 2020 16:26: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="e7ITKteG"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="cjerCYQS" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 50D4222261 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=/Gbcak2NCzfTwSSwraM7BcOWi5vx1zd1TN9bM02hfZ0=; b=e7ITKteGfFP5ZedTSCyM5HKjf NBW8smKxTi7DNJQcd7UAkVbHXvbwNAJh79DT3lQxAJiIQAqt8TYrGSkdD7JcTYOlyR2OwXeRH6hw8 3qhEV34oRNfOJU30VKDc9yAOnM9dERQAsAkXcI2vhllv3WyWKpsIu1GSrSqryzkhby7LIXd7g5KsQ JaoKbvn7fMraaa9oHnmqeM/YeUWfhP1Sj4O81eFXtJIDDNdREPmbyV48BMIxmvJ7xc2KWNTcyI/+n il1IfQHzM3upVVsZMtqY9PY5WXD5aLPxfvYtj7hYYOzZ5BquaNd/gnpp5+ZJM2MXdNYcpX4oo25y8 gqVo9pUGg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kfmkv-0004DP-Ty; Thu, 19 Nov 2020 16:25:57 +0000 Received: from mail-ej1-x643.google.com ([2a00:1450:4864:20::643]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kfmkp-0004Bm-0x for linux-arm-kernel@lists.infradead.org; Thu, 19 Nov 2020 16:25:51 +0000 Received: by mail-ej1-x643.google.com with SMTP id oq3so8739520ejb.7 for ; Thu, 19 Nov 2020 08:25: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=hj90LCz0D+DQiieyZ6toGkopYRcCnDLmGJUIDeGa0Ro=; b=cjerCYQSC57p+Bb2G3ff0Nn0PFg450gFtjyx3NZBzKsAR7gMmdHvvsG4FqIdx/iKn4 kXd5blgYmionqHxOpYneiVaatHmPngI7+YQzlp4XdB37ModkveOIq7cfC+ScplzfdFfW aFxC01KkfYRrppR4b2m5+csRKOx34cUbLsTN3uYQo+sOQCz7Qevc4p+dN38FjJ29fwZU M3zFyvj8FGRBTzXS3ZgIHbXCTJ2eHhCqrqjOh+87TLipwgFUEWF6KwrDBAAts8DJmwd/ VRBOK/tlrVlGeJ/GexMBc9mY3PRbmDnCcGteZilDTPgnRpkltW5O+2s5wwbcGjOL8e5s NhNw== 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=hj90LCz0D+DQiieyZ6toGkopYRcCnDLmGJUIDeGa0Ro=; b=ZxtKZq2kXRwnNLwz0lhTndoNJu2fooXs4ZcKx5cvLBXr7xOyN5UUzAHLNB72A3qOqR h66wYyct63+vOi6l5p0Z/1ZH8TDDcKSQGa5jUbC2qjtQ7QCKGmN0DiaXNkECzWTOw/nc SGBgOvIQkFr4GNxe+TdpFb34J50rB7qdujNR+4pwkS023n3Dhrs+bUJYOfN7vBZuQxAz MWHbZmAtF3olGPEAoquDsAkZpaYZLCXLn4izEGBbGCQyXZtYLOa+ngA/xk3Mn99lwJX3 lNrbZOFRuuepV5l1WgzsSZXgASiKq26Ii8EDvkm+gT4VpyXMmhTb0vWJrokT587b8hzt NMQQ== X-Gm-Message-State: AOAM533eOrq6p3Brkzlik9UX61cC7SWSqrxHnlDem2BnkVTXehb0L21G dgVHNmHwmXzfgHmCc/JKZZeZ0g5E15RWAQ== X-Google-Smtp-Source: ABdhPJy3FuEcXWKGxYGEsU2f9+i0XPWJ/SKtOYB+LMp3R8UV2UUxvy5sHXw+rpJ6SPZ9fF73+2ZgfQ== X-Received: by 2002:a17:906:85c9:: with SMTP id i9mr2600538ejy.487.1605803149723; Thu, 19 Nov 2020 08:25:49 -0800 (PST) Received: from localhost ([2a01:4b00:8523:2d03:9843:cd3f:f36b:d55c]) by smtp.gmail.com with ESMTPSA id j6sm15435631edy.87.2020.11.19.08.25.48 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 19 Nov 2020 08:25:48 -0800 (PST) From: David Brazdil To: kvmarm@lists.cs.columbia.edu Subject: [RFC PATCH 1/6] kvm: arm64: Set up .hyp.rodata ELF section Date: Thu, 19 Nov 2020 16:25:38 +0000 Message-Id: <20201119162543.78001-2-dbrazdil@google.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201119162543.78001-1-dbrazdil@google.com> References: <20201119162543.78001-1-dbrazdil@google.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201119_112551_108479_E5646D7C X-CRM114-Status: GOOD ( 17.70 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , kernel-team@android.com, Suzuki K Poulose , Marc Zyngier , linux-kernel@vger.kernel.org, James Morse , linux-arm-kernel@lists.infradead.org, Catalin Marinas , David Brazdil , Will Deacon , Ard Biesheuvel , Julien Thierry , Andrew Scull Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org We will need to recognize pointers in .rodata specific to hyp, so establish a .hyp.rodata ELF section. Merge it with the existing .hyp.data..ro_after_init as they are treated the same at runtime. Signed-off-by: David Brazdil --- arch/arm64/include/asm/sections.h | 2 +- arch/arm64/kernel/vmlinux.lds.S | 7 ++++--- arch/arm64/kvm/arm.c | 7 +++---- arch/arm64/kvm/hyp/nvhe/hyp.lds.S | 1 + 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/arch/arm64/include/asm/sections.h b/arch/arm64/include/asm/sections.h index 8ff579361731..a6f3557d1ab2 100644 --- a/arch/arm64/include/asm/sections.h +++ b/arch/arm64/include/asm/sections.h @@ -11,7 +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_ro_after_init_start[], __hyp_data_ro_after_init_end[]; +extern char __hyp_rodata_start[], __hyp_rodata_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 4382b5d0645d..6f2fd9734d63 100644 --- a/arch/arm64/kernel/vmlinux.lds.S +++ b/arch/arm64/kernel/vmlinux.lds.S @@ -31,10 +31,11 @@ jiffies = jiffies_64; __stop___kvm_ex_table = .; #define HYPERVISOR_DATA_SECTIONS \ - HYP_SECTION_NAME(.data..ro_after_init) : { \ - __hyp_data_ro_after_init_start = .; \ + HYP_SECTION_NAME(.rodata) : { \ + __hyp_rodata_start = .; \ *(HYP_SECTION_NAME(.data..ro_after_init)) \ - __hyp_data_ro_after_init_end = .; \ + *(HYP_SECTION_NAME(.rodata)) \ + __hyp_rodata_end = .; \ } #define HYPERVISOR_PERCPU_SECTION \ diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index d6d5211653b7..119c97e8900a 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -1688,11 +1688,10 @@ static int init_hyp_mode(void) goto out_err; } - err = create_hyp_mappings(kvm_ksym_ref(__hyp_data_ro_after_init_start), - kvm_ksym_ref(__hyp_data_ro_after_init_end), - PAGE_HYP_RO); + err = create_hyp_mappings(kvm_ksym_ref(__hyp_rodata_start), + kvm_ksym_ref(__hyp_rodata_end), PAGE_HYP_RO); if (err) { - kvm_err("Cannot map .hyp.data..ro_after_init section\n"); + kvm_err("Cannot map .hyp.rodata section\n"); goto out_err; } diff --git a/arch/arm64/kvm/hyp/nvhe/hyp.lds.S b/arch/arm64/kvm/hyp/nvhe/hyp.lds.S index 5d76ff2ba63e..b0789183d49d 100644 --- a/arch/arm64/kvm/hyp/nvhe/hyp.lds.S +++ b/arch/arm64/kvm/hyp/nvhe/hyp.lds.S @@ -17,4 +17,5 @@ SECTIONS { PERCPU_INPUT(L1_CACHE_BYTES) } HYP_SECTION(.data..ro_after_init) + HYP_SECTION(.rodata) } From patchwork Thu Nov 19 16:25:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Brazdil X-Patchwork-Id: 11918215 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A83E1C63697 for ; Thu, 19 Nov 2020 16:27:28 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2A5AA22240 for ; Thu, 19 Nov 2020 16:27:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="t4jpP2R4"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="VF2/Zvdb" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2A5AA22240 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=kUlkO64AYKBI13w3NU5eXAwNeYi9o39FOX+kIfzOqNg=; b=t4jpP2R48TMz45Dq5n24I8Nz2 yKjKxcvPrysyFo0nQCHan1MGCM4+GPJrNl03SY4YejXBFY5Zw/9Jej3m7pZio7PvOcPre1/bK5h/p fkHc/rxIuZPwurZU+8aiG2Zu90IFZcHjqztJTZt0+PxNZg1RYS8YPVxgl3eGGsa8LqQl7785AIu0U ichqhNW/94zgcxpia10/LZ6kUe2ZZ9dPwHjAZ56LNMF2A6BMTxEv7eArrh3KYyM2EpvwXQ8ZKRATg s7mum/aGtDU4CgzVfT4vv/Gzg5AmrajG9iWXtSko887hMD7vwPdQh3v0IS3nkx/CGJETbJaXyhKpq 5j56043mQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kfmky-0004EA-Bs; Thu, 19 Nov 2020 16:26:00 +0000 Received: from mail-ej1-x642.google.com ([2a00:1450:4864:20::642]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kfmkr-0004CR-No for linux-arm-kernel@lists.infradead.org; Thu, 19 Nov 2020 16:25:54 +0000 Received: by mail-ej1-x642.google.com with SMTP id f23so8776827ejk.2 for ; Thu, 19 Nov 2020 08:25:53 -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=TT/5iT0z6kx2joICZ1NAOPL4bFSWCCwquQqtGIEaOSE=; b=VF2/ZvdbNQRSshIgrCaZnLi+OohPfeVvaLrNMfYhzLvwIdDhd8kH2e7s3w8TeJhyJt lqiGFQq2fh2RuHE47qpHCqlUAPJnELkLqqFjbV1TAULxG1k3twib5U4GDLOVmUuFZdNE lV0AVoJiA3v/889w4eJeTYP0bfqNk3g2YfkQjD0TiZFzgKTDmksWN3EMIfxSf5W3hukh Vv+VXQfRXy4bqlxBRRGXxmbn9c6de8SL+IJSqGfQQUDMTTCNJK9rvgI4R+4KJESvTPH1 pDOjgFd/mVA2LPoFBXWBoewdcHQ3fyYW6RTLEar9cm+xIjSM4pQJKTFkZq0Oxq4agZ9N C4oQ== 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=TT/5iT0z6kx2joICZ1NAOPL4bFSWCCwquQqtGIEaOSE=; b=f0sIDG82dPLqyXlMmDOpPQL5rX51l9LqMVOXpFYAgEe4XPO9WRpqDSe21zibmDVccc BtuB2fGnFIZd/wdIOQGGNSqPytfsvEZWngB16wgjjKwfq7Xzna3r3S/oUBIYLQ4I6CHg vIgRdpSyA77Ll3oTcSeNPzaG2V4m13vzY8oJwmpAqHnJh4yFcaG/B0ioAS9inuCHDpVN 0ioj3lFT1SErdafOO0mennOJFA5ziS//ssTPwbHL/TI/OCg+nt8fS/RCJ7wox2/1mSsg 9t1S0iQWbIW+vNnviFlwTqIgqGGNDoKrDm/oRtMweQ8OvlZC3nNzYYBSNO0xYDtCZ/tX SFvA== X-Gm-Message-State: AOAM532mZ8pQWX5feP3h/7tmWVt5Lr95ZqNyBJUfhqZv1w3zpDpXQz7h RcpVGp34unNRA1NEyR/VbUeScA== X-Google-Smtp-Source: ABdhPJwP/VVLCtMC4MEEj1Tf0BE9yqBQPNpM9ZeLFkujWHC85kdVBcEDsd4LiFcCh9qpW7yuGVSGQQ== X-Received: by 2002:a17:906:b0d8:: with SMTP id bk24mr17537665ejb.113.1605803152633; Thu, 19 Nov 2020 08:25:52 -0800 (PST) Received: from localhost ([2a01:4b00:8523:2d03:9843:cd3f:f36b:d55c]) by smtp.gmail.com with ESMTPSA id lu33sm73443ejb.49.2020.11.19.08.25.50 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 19 Nov 2020 08:25:51 -0800 (PST) From: David Brazdil To: kvmarm@lists.cs.columbia.edu Subject: [RFC PATCH 2/6] kvm: arm64: Fix up RELA relocations in hyp code/data Date: Thu, 19 Nov 2020 16:25:39 +0000 Message-Id: <20201119162543.78001-3-dbrazdil@google.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201119162543.78001-1-dbrazdil@google.com> References: <20201119162543.78001-1-dbrazdil@google.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201119_112553_853618_EA664E01 X-CRM114-Status: GOOD ( 25.96 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , kernel-team@android.com, Suzuki K Poulose , Marc Zyngier , linux-kernel@vger.kernel.org, James Morse , linux-arm-kernel@lists.infradead.org, Catalin Marinas , David Brazdil , Will Deacon , Ard Biesheuvel , Julien Thierry , Andrew Scull Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org KVM nVHE code runs under a different VA mapping than the kernel, hence so far it relied only on PC-relative addressing to avoid accidentally using a relocated kernel VA from a constant pool (see hyp_symbol_addr). So as to reduce the possibility of a programmer error, fixup the relocated addresses instead. Let the kernel relocate them to kernel VA first, but then iterate over them again, filter those that point to hyp code/data and convert the kernel VA to hyp VA. This is done after kvm_compute_layout and before apply_alternatives. Signed-off-by: David Brazdil --- arch/arm64/include/asm/kvm_mmu.h | 1 + arch/arm64/kernel/smp.c | 4 +- arch/arm64/kvm/va_layout.c | 76 ++++++++++++++++++++++++++++++++ 3 files changed, 80 insertions(+), 1 deletion(-) diff --git a/arch/arm64/include/asm/kvm_mmu.h b/arch/arm64/include/asm/kvm_mmu.h index 5168a0c516ae..e5226f7e4732 100644 --- a/arch/arm64/include/asm/kvm_mmu.h +++ b/arch/arm64/include/asm/kvm_mmu.h @@ -105,6 +105,7 @@ alternative_cb_end void kvm_update_va_mask(struct alt_instr *alt, __le32 *origptr, __le32 *updptr, int nr_inst); void kvm_compute_layout(void); +void kvm_fixup_hyp_relocations(void); static __always_inline unsigned long __kern_hyp_va(unsigned long v) { diff --git a/arch/arm64/kernel/smp.c b/arch/arm64/kernel/smp.c index 18e9727d3f64..30241afc2c93 100644 --- a/arch/arm64/kernel/smp.c +++ b/arch/arm64/kernel/smp.c @@ -434,8 +434,10 @@ static void __init hyp_mode_check(void) "CPU: CPUs started in inconsistent modes"); else pr_info("CPU: All CPU(s) started at EL1\n"); - if (IS_ENABLED(CONFIG_KVM)) + if (IS_ENABLED(CONFIG_KVM)) { kvm_compute_layout(); + kvm_fixup_hyp_relocations(); + } } void __init smp_cpus_done(unsigned int max_cpus) diff --git a/arch/arm64/kvm/va_layout.c b/arch/arm64/kvm/va_layout.c index d8cc51bd60bf..b80fab974896 100644 --- a/arch/arm64/kvm/va_layout.c +++ b/arch/arm64/kvm/va_layout.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -82,6 +83,81 @@ __init void kvm_compute_layout(void) init_hyp_physvirt_offset(); } +#define __load_elf_u64(s) \ + ({ \ + extern u64 s; \ + u64 val; \ + \ + asm ("ldr %0, =%1" : "=r"(val) : "S"(&s)); \ + val; \ + }) + +static bool __is_within_bounds(u64 addr, char *start, char *end) +{ + return start <= (char*)addr && (char*)addr < end; +} + +static bool __is_in_hyp_section(u64 addr) +{ + return __is_within_bounds(addr, __hyp_text_start, __hyp_text_end) || + __is_within_bounds(addr, __hyp_rodata_start, __hyp_rodata_end) || + __is_within_bounds(addr, + CHOOSE_NVHE_SYM(__per_cpu_start), + CHOOSE_NVHE_SYM(__per_cpu_end)); +} + +static void __fixup_hyp_rel(u64 addr) +{ + u64 *ptr, kern_va, hyp_va; + + /* Adjust the relocation address taken from ELF for KASLR. */ + addr += kaslr_offset(); + + /* Skip addresses not in any of the hyp sections. */ + if (!__is_in_hyp_section(addr)) + return; + + /* Get the LM alias of the relocation address. */ + ptr = (u64*)kvm_ksym_ref((void*)addr); + + /* + * Read the value at the relocation address. It has already been + * relocated to the actual kernel kimg VA. + */ + kern_va = (u64)kvm_ksym_ref((void*)*ptr); + + /* Convert to hyp VA. */ + hyp_va = __early_kern_hyp_va(kern_va); + + /* Store hyp VA at the relocation address. */ + *ptr = __early_kern_hyp_va(kern_va); +} + +static void __fixup_hyp_rela(void) +{ + Elf64_Rela *rel; + size_t i, n; + + rel = (Elf64_Rela*)(kimage_vaddr + __load_elf_u64(__rela_offset)); + n = __load_elf_u64(__rela_size) / sizeof(*rel); + + for (i = 0; i < n; ++i) + __fixup_hyp_rel(rel[i].r_offset); +} + +/* + * The kernel relocated pointers to kernel VA. Iterate over relocations in + * the hypervisor ELF sections and convert them to hyp VA. This avoids the + * need to only use PC-relative addressing in hyp. + */ +__init void kvm_fixup_hyp_relocations(void) +{ + if (!IS_ENABLED(CONFIG_RELOCATABLE) || has_vhe()) + return; + + __fixup_hyp_rela(); +} + static u32 compute_instruction(int n, u32 rd, u32 rn) { u32 insn = AARCH64_BREAK_FAULT; From patchwork Thu Nov 19 16:25:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Brazdil X-Patchwork-Id: 11918209 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5D2A8C63697 for ; Thu, 19 Nov 2020 16:26: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 C85DF22240 for ; Thu, 19 Nov 2020 16:26: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="b3fWKip/"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="d5PO+tqR" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C85DF22240 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=AH0ah2NpYZzZS/z6cFnQpEgFpA+Z0BXo5Fh5Rfezo7E=; b=b3fWKip/J6j7E5PIJZnB6YjtC XkXr6gA32Ezg3D5tKlm0nBFnfM+kPsPX4Q2PMJ8yNHuovmX4eLNwVAtzZbQtgAMVHRh1NyNFEmuoW XHTzm5qkwL0HaH6p+vV2EgHD645XhF45Ks6mI/QvDn/bsH4XzJ4ivKVvaOvz9+0MFkFcsAh8SIY7e oinKuDdLol3zbcN0uKP8uWf+bf1aw5CMV36nk+FVl5MTru5eKPOanxk/qlXhiOkIaNJsDgDlpE4k2 JLa0q53XvDgQ2cJ9PHyMXxEbZ0Gtdo7AAAdhmjzJnQF6b1cTTyyqlLqOwFA2UonSVM+rot9dK3sfi QBHE/BJlw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kfml6-0004GZ-1A; Thu, 19 Nov 2020 16:26:08 +0000 Received: from mail-ed1-x544.google.com ([2a00:1450:4864:20::544]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kfmku-0004D3-Ka for linux-arm-kernel@lists.infradead.org; Thu, 19 Nov 2020 16:25:57 +0000 Received: by mail-ed1-x544.google.com with SMTP id t9so6453433edq.8 for ; Thu, 19 Nov 2020 08:25: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=4v/cI0W618Ll5oLWISpFhPxrIsIv3CzVb2jjngYJV1Y=; b=d5PO+tqR8NqolGIpflVwHQcaoSm8nizbEKWRPNduNGR++veNurs6hl8d+bpaVieFyx N/4qzptR0qOSoxQx7FQPsoe+iJswnHDVYtCadJO3C2slcCcPefUTQ+zOiNyarho+GJTQ eQVq93/itpn3uOMr/bNlKeAjhJZdy4EqJV6kjmkrHbofx2egXY3zQ+yRKs+a7dQtwgdK 4NoSRABTZAqopd6clg6Riim7meD6ewWkye8RYV/TV41uhgV3OcI7IOBtaWy6jDfV+Jfn HS8RCnV4PSHXaSeawTEOygjXqwZVK8R/FKpjfbB4tqH67KPho4pLvDzc9Uy4bjYb/kik IvoA== 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=4v/cI0W618Ll5oLWISpFhPxrIsIv3CzVb2jjngYJV1Y=; b=LZC83uQKqKlr7B8uBwBwRXxVrLh2sITZrlSlabRYJQc7Z16QP9nsF2eAxNOTJQYUXq SeHzQjOx5ACDt24qar4k2UUQ6bYij6Q2Av30zNgGXvlcbrDko5lSiMGKl1zEciWLd/ZH 3HnWYzLgkAldIVYQiyKzOkXsy+ZjQaYgaDYyXRN4+Q8ZkemOjfF0QGZgpIc1xNKegEGl 5Zhqwg3iCOnBo++gdujrszBrxjhAK4BrglZu9emTGeTteM6ira7MnYrtVpP2ZRczHhjW dFvlMTFsIuElwMP+mtHV7h9vLaugrOlvO1YhykdNB1LOBwnestui4aFKXC8J7TAInMlq iKTQ== X-Gm-Message-State: AOAM533hcV4FFWvIB+NaYui2481fIpg7ftHgIkQ8p7cuMxjUkX6Ep1BI pI8a5bvyoDEfuST5ei4OdqJi5aPJt1vPDw== X-Google-Smtp-Source: ABdhPJwsWb2PZ6sVei/sp7eotqJ6Uj+ntArrx/BCAAQKZymcK4INkpViSTd4Aa9KHDTnkjsffwkiyQ== X-Received: by 2002:a50:ccdb:: with SMTP id b27mr9198862edj.253.1605803154843; Thu, 19 Nov 2020 08:25:54 -0800 (PST) Received: from localhost ([2a01:4b00:8523:2d03:9843:cd3f:f36b:d55c]) by smtp.gmail.com with ESMTPSA id k2sm84334ejp.6.2020.11.19.08.25.53 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 19 Nov 2020 08:25:53 -0800 (PST) From: David Brazdil To: kvmarm@lists.cs.columbia.edu Subject: [RFC PATCH 3/6] kvm: arm64: Fix up RELR relocation in hyp code/data Date: Thu, 19 Nov 2020 16:25:40 +0000 Message-Id: <20201119162543.78001-4-dbrazdil@google.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201119162543.78001-1-dbrazdil@google.com> References: <20201119162543.78001-1-dbrazdil@google.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201119_112556_879515_10094378 X-CRM114-Status: GOOD ( 19.00 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , kernel-team@android.com, Suzuki K Poulose , Marc Zyngier , linux-kernel@vger.kernel.org, James Morse , linux-arm-kernel@lists.infradead.org, Catalin Marinas , David Brazdil , Will Deacon , Ard Biesheuvel , Julien Thierry , Andrew Scull Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The arm64 kernel also supports packing of relocation data using the RELR format. Implement a parser of RELR data and fixup the relocations using the same infra as RELA relocs. Signed-off-by: David Brazdil --- arch/arm64/kvm/va_layout.c | 41 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/arch/arm64/kvm/va_layout.c b/arch/arm64/kvm/va_layout.c index b80fab974896..7f45a98eacfd 100644 --- a/arch/arm64/kvm/va_layout.c +++ b/arch/arm64/kvm/va_layout.c @@ -145,6 +145,43 @@ static void __fixup_hyp_rela(void) __fixup_hyp_rel(rel[i].r_offset); } +#ifdef CONFIG_RELR +static void __fixup_hyp_relr(void) +{ + u64 *rel, *end; + + rel = (u64*)(kimage_vaddr + __load_elf_u64(__relr_offset)); + end = rel + (__load_elf_u64(__relr_size) / sizeof(*rel)); + + while (rel < end) { + unsigned n; + u64 addr = *(rel++); + + /* Address must not have the LSB set. */ + BUG_ON(addr & BIT(0)); + + /* Fix up the first address of the chain. */ + __fixup_hyp_rel(addr); + + /* + * Loop over bitmaps, i.e. as long as words' LSB is 1. + * Each bit (ordered from LSB to MSB) represents one word from + * the last full address (exclusive). If the corresponding bit + * is 1, there is a relative relocation on that word. + */ + for (n = 0; rel < end && (*rel & BIT(0)); n++) { + unsigned i; + u64 bitmap = *(rel++); + + for (i = 1; i < 64; ++i) { + if ((bitmap & BIT(i))) + __fixup_hyp_rel(addr + 8 * (63 * n + i)); + } + } + } +} +#endif + /* * The kernel relocated pointers to kernel VA. Iterate over relocations in * the hypervisor ELF sections and convert them to hyp VA. This avoids the @@ -156,6 +193,10 @@ __init void kvm_fixup_hyp_relocations(void) return; __fixup_hyp_rela(); + +#ifdef CONFIG_RELR + __fixup_hyp_relr(); +#endif } static u32 compute_instruction(int n, u32 rd, u32 rn) From patchwork Thu Nov 19 16:25:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Brazdil X-Patchwork-Id: 11918211 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0880BC63697 for ; Thu, 19 Nov 2020 16:26:49 +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 82EA522240 for ; Thu, 19 Nov 2020 16:26:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="p7kQYXZK"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="k1mkH5Vp" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 82EA522240 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=iosZX3tq4gW7mfN7pUAIvLTFi+uYlUKmcF/iAuKEuKM=; b=p7kQYXZK+4AQirxLtvNC/7jVK 0t00Fr/Ff4SwVpTovE+rv3PG5FAyxJq47Qg4i3T0BXtyr1HKfsPSQfFuc4CAB+GVSherQuldXTWa7 n6UkPgHANERdcbMqiGa5TlTeDVnqvIRj7/sXeUo7+SU9/vFJZ7ikfhbMr6Jnb38bAQeuxh2ThdFhL yDjlYsDz+qiDe8Y6CwbUHnVIJaCDsyHTnwxhhqIVnNJUMBWrS9OltFGjjdOrEDZNBJs/VT8QMpSqd WlDKkGIEgxCQrwl+cVpxBMiUAJyS9ulPx7mdVrrjDbsDHBtXEdapelIAR2nmh71PAfHYn3K0rEB2W XkBU6bPyg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kfmlG-0004Jq-Sm; Thu, 19 Nov 2020 16:26:18 +0000 Received: from mail-ej1-x643.google.com ([2a00:1450:4864:20::643]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kfmkw-0004DR-4o for linux-arm-kernel@lists.infradead.org; Thu, 19 Nov 2020 16:25:59 +0000 Received: by mail-ej1-x643.google.com with SMTP id 7so8782009ejm.0 for ; Thu, 19 Nov 2020 08:25: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=U1Lcn6Bd4XfPJVZpg/iAgt9bwB62SK3e+mkMsQgmis4=; b=k1mkH5VpRWxoRHM6/4uXMQ+2mNIrTpI3bzeVzL4Eq+TBVCrAhI6WY51UNkvUnkHkok sU1uyk5P398N4LFdkxWjG7dsnqAwLumIjARIWorBlisj1MlNzwfrmNTts90+aLS7JKNz gkZ4bewA7vI4XC511gEy5PnX1QNLEy7PS6q/z/rKoQaldCgOX6wvAVrbAbahJmo8YtOi 7rJ+ZrpdENaqoIX1FUtGI5xUs7CVKoKAwZVWRcS8BfsPSovMOfZ1/GCNrbvtGVCB/yN9 makp3oDRXdUvcItXGaXJW+Iw9jX+yej1cJsMThWyp+lSPCdh0JdW4i3W3QkO9Hpy6vdY nE9w== 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=U1Lcn6Bd4XfPJVZpg/iAgt9bwB62SK3e+mkMsQgmis4=; b=SQ3Oe6o9syTWXZ2grr8esA04LPfZ0XeK/J8kD/cX03TRpljoJmE7p8D9+nSyr8BiDp m4ZdNGWRimv/SRP+eFtLdp0Iax5VjPZ+T1h7aWZEKE9On3/7RyZVJmPCghwzjLC6oDNC 6E1SfVW7efGNGUnetN270UhUAoy42EXTm2Avykwck4/ejzRmB8kpy5P8vtIRsPg1hPOF PNVzt0fh9CwwjrQgh0Oagw7u0Kq+T6MerlX1OEVxotAzv9E7VwkHCliecJIqsJcAO9Ed w356rneFfLBXqedEBxjOMFyZU46epzrR0AKp48kT06JTv0c0o9kLC2xrzU4fvljdl34j cldg== X-Gm-Message-State: AOAM530FnAkIXdvjQDL0o2vh0jB4XIr7ktHg4vd+cXDLTCvZXFe6IbNo 3hHTcs6MbrBpJITj+fbcnCVVxA== X-Google-Smtp-Source: ABdhPJzsWcD3nhXsO2UcH2+U86idS8BWqbdQMCqEdUgqzp7r5etX5V0OtmywF0Avo8pCoOQSclM4yw== X-Received: by 2002:a17:906:ad85:: with SMTP id la5mr30963406ejb.423.1605803157084; Thu, 19 Nov 2020 08:25:57 -0800 (PST) Received: from localhost ([2a01:4b00:8523:2d03:9843:cd3f:f36b:d55c]) by smtp.gmail.com with ESMTPSA id jw7sm72123ejb.54.2020.11.19.08.25.55 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 19 Nov 2020 08:25:56 -0800 (PST) From: David Brazdil To: kvmarm@lists.cs.columbia.edu Subject: [RFC PATCH 4/6] kvm: arm64: Remove patching of fn pointers in hyp Date: Thu, 19 Nov 2020 16:25:41 +0000 Message-Id: <20201119162543.78001-5-dbrazdil@google.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201119162543.78001-1-dbrazdil@google.com> References: <20201119162543.78001-1-dbrazdil@google.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201119_112558_252536_44CA43A5 X-CRM114-Status: GOOD ( 17.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 , kernel-team@android.com, Suzuki K Poulose , Marc Zyngier , linux-kernel@vger.kernel.org, James Morse , linux-arm-kernel@lists.infradead.org, Catalin Marinas , David Brazdil , Will Deacon , Ard Biesheuvel , Julien Thierry , Andrew Scull Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Taking a function pointer will now generate a R_AARCH64_RELATIVE that is fixed up at early boot. Remove the alternative-based mechanism for converting the address from a kernel VA. Signed-off-by: David Brazdil Acked-by: Ard Biesheuvel --- arch/arm64/include/asm/kvm_mmu.h | 18 ------------------ arch/arm64/kernel/image-vars.h | 1 - arch/arm64/kvm/hyp/nvhe/hyp-main.c | 11 ++++------- arch/arm64/kvm/va_layout.c | 6 ------ 4 files changed, 4 insertions(+), 32 deletions(-) diff --git a/arch/arm64/include/asm/kvm_mmu.h b/arch/arm64/include/asm/kvm_mmu.h index e5226f7e4732..8cb8974ec9cc 100644 --- a/arch/arm64/include/asm/kvm_mmu.h +++ b/arch/arm64/include/asm/kvm_mmu.h @@ -121,24 +121,6 @@ static __always_inline unsigned long __kern_hyp_va(unsigned long v) #define kern_hyp_va(v) ((typeof(v))(__kern_hyp_va((unsigned long)(v)))) -static __always_inline unsigned long __kimg_hyp_va(unsigned long v) -{ - unsigned long offset; - - asm volatile(ALTERNATIVE_CB("movz %0, #0\n" - "movk %0, #0, lsl #16\n" - "movk %0, #0, lsl #32\n" - "movk %0, #0, lsl #48\n", - kvm_update_kimg_phys_offset) - : "=r" (offset)); - - return __kern_hyp_va((v - offset) | PAGE_OFFSET); -} - -#define kimg_fn_hyp_va(v) ((typeof(*v))(__kimg_hyp_va((unsigned long)(v)))) - -#define kimg_fn_ptr(x) (typeof(x) **)(x) - /* * We currently support using a VM-specified IPA size. For backward * compatibility, the default IPA size is fixed to 40bits. diff --git a/arch/arm64/kernel/image-vars.h b/arch/arm64/kernel/image-vars.h index 8539f34d7538..6379721236cf 100644 --- a/arch/arm64/kernel/image-vars.h +++ b/arch/arm64/kernel/image-vars.h @@ -64,7 +64,6 @@ __efistub__ctype = _ctype; /* Alternative callbacks for init-time patching of nVHE hyp code. */ KVM_NVHE_ALIAS(kvm_patch_vector_branch); KVM_NVHE_ALIAS(kvm_update_va_mask); -KVM_NVHE_ALIAS(kvm_update_kimg_phys_offset); KVM_NVHE_ALIAS(kvm_get_kimage_voffset); /* Global kernel state accessed by nVHE hyp code. */ diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-main.c b/arch/arm64/kvm/hyp/nvhe/hyp-main.c index b3db5f4eea27..7998eff5f0a2 100644 --- a/arch/arm64/kvm/hyp/nvhe/hyp-main.c +++ b/arch/arm64/kvm/hyp/nvhe/hyp-main.c @@ -110,9 +110,9 @@ static void handle___vgic_v3_restore_aprs(struct kvm_cpu_context *host_ctxt) typedef void (*hcall_t)(struct kvm_cpu_context *); -#define HANDLE_FUNC(x) [__KVM_HOST_SMCCC_FUNC_##x] = kimg_fn_ptr(handle_##x) +#define HANDLE_FUNC(x) [__KVM_HOST_SMCCC_FUNC_##x] = (hcall_t)handle_##x -static const hcall_t *host_hcall[] = { +static const hcall_t host_hcall[] = { HANDLE_FUNC(__kvm_vcpu_run), HANDLE_FUNC(__kvm_flush_vm_context), HANDLE_FUNC(__kvm_tlb_flush_vmid_ipa), @@ -132,7 +132,6 @@ static const hcall_t *host_hcall[] = { static void handle_host_hcall(struct kvm_cpu_context *host_ctxt) { DECLARE_REG(unsigned long, id, host_ctxt, 0); - const hcall_t *kfn; hcall_t hfn; id -= KVM_HOST_SMCCC_ID(0); @@ -140,13 +139,11 @@ static void handle_host_hcall(struct kvm_cpu_context *host_ctxt) if (unlikely(id >= ARRAY_SIZE(host_hcall))) goto inval; - kfn = host_hcall[id]; - if (unlikely(!kfn)) + hfn = host_hcall[id]; + if (unlikely(!hfn)) goto inval; cpu_reg(host_ctxt, 0) = SMCCC_RET_SUCCESS; - - hfn = kimg_fn_hyp_va(kfn); hfn(host_ctxt); return; diff --git a/arch/arm64/kvm/va_layout.c b/arch/arm64/kvm/va_layout.c index 7f45a98eacfd..0494315f71f2 100644 --- a/arch/arm64/kvm/va_layout.c +++ b/arch/arm64/kvm/va_layout.c @@ -373,12 +373,6 @@ static void generate_mov_q(u64 val, __le32 *origptr, __le32 *updptr, int nr_inst *updptr++ = cpu_to_le32(insn); } -void kvm_update_kimg_phys_offset(struct alt_instr *alt, - __le32 *origptr, __le32 *updptr, int nr_inst) -{ - generate_mov_q(kimage_voffset + PHYS_OFFSET, origptr, updptr, nr_inst); -} - void kvm_get_kimage_voffset(struct alt_instr *alt, __le32 *origptr, __le32 *updptr, int nr_inst) { From patchwork Thu Nov 19 16:25:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Brazdil X-Patchwork-Id: 11918217 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 77969C56201 for ; Thu, 19 Nov 2020 16:27:56 +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 E5E5C22261 for ; Thu, 19 Nov 2020 16:27:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="1Zp1TeHu"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="v5R/bPXr" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E5E5C22261 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=hzY57T3dvsrC78NpRfZeaZB/jDsq+qp4woAcZ5lFBcI=; b=1Zp1TeHuMZTbj32Ms02Ut2AD+ LHYNiC++vFeLOm4lDh2Loqi4hSe6Kit6sj3DxkTbCDbyp8tRpYbaaiJDboKmbhnnhPzt2WYnQgMSR Yzjz08mdY6GOAuZo9XPpku4jEvl6zFHd6njHbRwO9J0f+PzD6Ayv4m3gKJLrGln1oYtfa8DSKWE1L WE8gZCSh7tG+N5IFIy6ALRq/CSYl0T4CFz1yJDGxDa0wqRTYvLoIRTt707uxeq6IqvUZhq5ufX8Pb R0VSNY2pxOMucZJ8Dbaig6f1VNCystKIyE3YYJCpeQHaP/OPjvi4rpPIyRkrpDxUmtVDwpomKNYMJ jURhjGUSg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kfmlL-0004Ld-Vw; Thu, 19 Nov 2020 16:26:24 +0000 Received: from mail-ed1-x544.google.com ([2a00:1450:4864:20::544]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kfmky-0004EH-DN for linux-arm-kernel@lists.infradead.org; Thu, 19 Nov 2020 16:26:01 +0000 Received: by mail-ed1-x544.google.com with SMTP id m16so6480273edr.3 for ; Thu, 19 Nov 2020 08:26: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=5MlXwXUoGcLbD/WCygRzjYFVebEXnf5c/lUquykfRUk=; b=v5R/bPXr6yxIRC4TnJkHhfGPg52KN0BTKGKdHosqzHDrdjOBD3OoLCLlGpvJ9vpZw7 FSXShWWfwIGiDhhnTl+oinATAyoscG+OFYVmfCCL7jzESU8qE2IxvVgkmVLPG+p7Bx3R UHN1++6yqap4jQ2jeBeVZGOXdQq7aM0yVjNTXgCuXg6gJvlN6rsVY29Lj4/EWjZiGus5 N7pIT1izOm/VG9jeByFsBKDqO1z2FtKo53LfYREwOu7hPbTk42Ytd61KbHMnKl3nx/Lb jLDGaZD/BWTfhIwijj1lfSbsElbzU4oc3GfhlicRYmkGh04JSc+aoeChsMyHNNWmj+9n MbSg== 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=5MlXwXUoGcLbD/WCygRzjYFVebEXnf5c/lUquykfRUk=; b=kaF8Y+UMlIpxYQhhFZrVJsW2CNYuYsueAjzb3aASpJMQIvjRAbqLBWKe9jpCpu9HHM sMfg713lU8QXhD/0NtMPhoHiewotKgl28RqfFJQRPpBy1GTTolUv/nCXxPMDKQuKRX+n l5xOTnO5SBWlgTPM/omu4qZfL9nPb3cDywUZbOl7lucAwg/n5XySm6luRlVjT4JSnuVt fAnq7Vf0XYfLmCV2m+qGpvQff33EFtbVpTn+jgs5b/89JBOLh1jxgB6Q2sdVi01/CxpQ Nz/JIILS21tZRIxqfIXblDsUj1NmM1dqyoaXIGZRh2YmAJIJ/BEdgTqusz7pm1AIpvJF U9Vg== X-Gm-Message-State: AOAM530uzccLhhYnhPzagLm7SOAeEn2yBYeGO7adOeRGKVMBC8jlkegX 2RidQ74LYJTRra+OVLfKyBoFuQ== X-Google-Smtp-Source: ABdhPJx9s7H/MTHz69bsGrNQ0l5Py2P1/7O779gADrD4sMkOQcjiC5QVePAr1gZhJn1q2f5rE9zzyA== X-Received: by 2002:a05:6402:19b4:: with SMTP id o20mr7995752edz.103.1605803159276; Thu, 19 Nov 2020 08:25:59 -0800 (PST) Received: from localhost ([2a01:4b00:8523:2d03:9843:cd3f:f36b:d55c]) by smtp.gmail.com with ESMTPSA id g7sm15689057edl.5.2020.11.19.08.25.57 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 19 Nov 2020 08:25:58 -0800 (PST) From: David Brazdil To: kvmarm@lists.cs.columbia.edu Subject: [RFC PATCH 5/6] kvm: arm64: Fix constant-pool users in hyp Date: Thu, 19 Nov 2020 16:25:42 +0000 Message-Id: <20201119162543.78001-6-dbrazdil@google.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201119162543.78001-1-dbrazdil@google.com> References: <20201119162543.78001-1-dbrazdil@google.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201119_112600_565070_15CDBC49 X-CRM114-Status: GOOD ( 20.32 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , kernel-team@android.com, Suzuki K Poulose , Marc Zyngier , linux-kernel@vger.kernel.org, James Morse , linux-arm-kernel@lists.infradead.org, Catalin Marinas , David Brazdil , Will Deacon , Ard Biesheuvel , Julien Thierry , Andrew Scull Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hyp code used to use absolute addressing via a constant pool to obtain the kernel VA of 3 symbols - panic, __hyp_panic_string and __kvm_handle_stub_hvc. This used to work because the kernel would relocate the addresses in the constant pool to kernel VA at boot and hyp would simply load them from there. Now that relocations are fixed up to point to hyp VAs, this does not work any longer. Rework the helpers to convert hyp VA to kernel VA / PA as needed. Signed-off-by: David Brazdil --- arch/arm64/include/asm/kvm_mmu.h | 29 +++++++++++++++++++---------- arch/arm64/kvm/hyp/nvhe/host.S | 29 +++++++++++++++-------------- 2 files changed, 34 insertions(+), 24 deletions(-) diff --git a/arch/arm64/include/asm/kvm_mmu.h b/arch/arm64/include/asm/kvm_mmu.h index 8cb8974ec9cc..0676ff2105bb 100644 --- a/arch/arm64/include/asm/kvm_mmu.h +++ b/arch/arm64/include/asm/kvm_mmu.h @@ -72,9 +72,14 @@ alternative_cb kvm_update_va_mask alternative_cb_end .endm +.macro hyp_pa reg, tmp + ldr_l \tmp, hyp_physvirt_offset + add \reg, \reg, \tmp +.endm + /* - * Convert a kernel image address to a PA - * reg: kernel address to be converted in place + * Convert a hypervisor VA to a kernel image address + * reg: hypervisor address to be converted in place * tmp: temporary register * * The actual code generation takes place in kvm_get_kimage_voffset, and @@ -82,18 +87,22 @@ alternative_cb_end * perform the register allocation (kvm_get_kimage_voffset uses the * specific registers encoded in the instructions). */ -.macro kimg_pa reg, tmp +.macro hyp_kimg reg, tmp + /* Convert hyp VA -> PA. */ + hyp_pa \reg, \tmp + + /* Load kimage_voffset. */ alternative_cb kvm_get_kimage_voffset - movz \tmp, #0 - movk \tmp, #0, lsl #16 - movk \tmp, #0, lsl #32 - movk \tmp, #0, lsl #48 + movz \tmp, #0 + movk \tmp, #0, lsl #16 + movk \tmp, #0, lsl #32 + movk \tmp, #0, lsl #48 alternative_cb_end - /* reg = __pa(reg) */ - sub \reg, \reg, \tmp + /* Convert PA -> kimg VA. */ + add \reg, \reg, \tmp .endm - + #else #include diff --git a/arch/arm64/kvm/hyp/nvhe/host.S b/arch/arm64/kvm/hyp/nvhe/host.S index 596dd5ae8e77..bcb80d525d8c 100644 --- a/arch/arm64/kvm/hyp/nvhe/host.S +++ b/arch/arm64/kvm/hyp/nvhe/host.S @@ -74,27 +74,28 @@ SYM_FUNC_END(__host_enter) * void __noreturn __hyp_do_panic(bool restore_host, u64 spsr, u64 elr, u64 par); */ SYM_FUNC_START(__hyp_do_panic) - /* Load the format arguments into x1-7 */ - mov x6, x3 - get_vcpu_ptr x7, x3 - - mrs x3, esr_el2 - mrs x4, far_el2 - mrs x5, hpfar_el2 - /* Prepare and exit to the host's panic funciton. */ mov lr, #(PSR_F_BIT | PSR_I_BIT | PSR_A_BIT | PSR_D_BIT |\ PSR_MODE_EL1h) msr spsr_el2, lr ldr lr, =panic + hyp_kimg lr, x6 msr elr_el2, lr - /* - * Set the panic format string and enter the host, conditionally - * restoring the host context. - */ + /* Set the panic format string. Use the, now free, LR as scratch. */ + ldr lr, =__hyp_panic_string + hyp_kimg lr, x6 + + /* Load the format arguments into x1-7. */ + mov x6, x3 + get_vcpu_ptr x7, x3 + mrs x3, esr_el2 + mrs x4, far_el2 + mrs x5, hpfar_el2 + + /* Enter the host, conditionally restoring the host context. */ cmp x0, xzr - ldr x0, =__hyp_panic_string + mov x0, lr b.eq __host_enter_without_restoring b __host_enter_for_panic SYM_FUNC_END(__hyp_do_panic) @@ -124,7 +125,7 @@ SYM_FUNC_END(__hyp_do_panic) * Preserve x0-x4, which may contain stub parameters. */ ldr x5, =__kvm_handle_stub_hvc - kimg_pa x5, x6 + hyp_pa x5, x6 br x5 .L__vect_end\@: .if ((.L__vect_end\@ - .L__vect_start\@) > 0x80) From patchwork Thu Nov 19 16:25:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Brazdil X-Patchwork-Id: 11918213 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 12B4EC63697 for ; Thu, 19 Nov 2020 16:27: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 83A9422240 for ; Thu, 19 Nov 2020 16:27: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="PZY6gcEa"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="KQDbQtOp" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 83A9422240 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=od/5sQN3hNT0IDb+GtZT8JOrzMJy3zkNe0hcJk403xM=; b=PZY6gcEadS6iH7bRe//nUTmAS +R62QBT98PXvBQNZczOJWzGEVZMJGIgJ98P6zrwJa/W2nehQveusdTxYieSucc6CR8EuwXx2BXaFs 9knCWKvU99i2IiHw1cmLHLeBRlA8XUXo8xHMWtffJcTnrOsv6xZPHoHW10IANg7IkmFfsK0VjH60O f6ibYS57mCu243C8HFN2WMzOG7Oe2VEShtiRcsoht1EN8bw/EczQAsZ2u0FUQSZKuLdUac+T60tWV NP6gEicxncQbqv8nRPD/cD0v2aNO/xNIhNdMghs4ON7sGQCFap7V1W34HwJlTwzqe+IWxUUfvy52j 1cEpEIIDA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kfmlc-0004RD-EW; Thu, 19 Nov 2020 16:26:40 +0000 Received: from mail-ed1-x542.google.com ([2a00:1450:4864:20::542]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kfml1-0004Eq-Bp for linux-arm-kernel@lists.infradead.org; Thu, 19 Nov 2020 16:26:04 +0000 Received: by mail-ed1-x542.google.com with SMTP id d18so6452714edt.7 for ; Thu, 19 Nov 2020 08:26: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=Du1A1iohvYOXikNEv0tYZPkKvUMheyRm10QbPuVgnlA=; b=KQDbQtOpKGlA/mJE+IKXYs3nd9nRJy91CRVZ6hpu8lHeREkppXMaTHfErgzVmjd00n dxVTRWsn03RgwIp78LSBRmbwGjQ0Ysta0qEqtCYxX/Aw42cycA7Z3Si83t/T84oP7OjE XP2QIW0IKzQuuONquwHYq1b0lhWu0F8Ay88R5bcwanmVfL8zloykzAmLPzj3sF9L3pEz ye/en7DDEy9JnRLeJJSxVudY00hpdsmd9QPnBwGIvMPDqvaIhTalqmtNxOviEicwP+0m zd38ISBAid8iqz+ug7DqkjTEAbtMSaK/O/5zumXsM/LELNGvleSwfa5n36uwsTaZJlTv GajA== 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=Du1A1iohvYOXikNEv0tYZPkKvUMheyRm10QbPuVgnlA=; b=gdjfhBBVnJqBQ133xNONExrzToPvJi7PxS3ZVBiG6KgwzTT99CIo67qgrbLrkYqPYK AOfhE7GitcZKVo47Ks+cHIuke55ZaFB9G/nYf4G6jAPEfG5Rf7LC4JobpMSdvnMpVE1T DkNaIGZ3e0E0PYVdGPiW9fdE5ccj8UwhFiTE759BlZmnWCHIInFkotMpT4MP8TGs+nPH FDklCc9CI7Feae7tkY3Dg2Z90RC1ER1EH30UhXEMEv285zVFlWImsZlrl0d8edP2crge ady34i0YmCdqeUczg7Ym4Alq6cc6t7WDhC16IVLfOLkGdYWiK47iYb27wtp/jpBzJ8US 4jUw== X-Gm-Message-State: AOAM532G7IKftZh/2FZiPWYgLpS/7nDcho9B6bN9u4BKTJhGQ5oiC8AT xwgudTfkksVL4saBVBJa/GvEHA== X-Google-Smtp-Source: ABdhPJz+hVLzImDN1eqY0j2SdIgTYsByI/xefUNdZgBEv9BhBBzOHOWikqW/5dwv0rlHb5NhMij5fA== X-Received: by 2002:a50:cd09:: with SMTP id z9mr32082700edi.152.1605803161427; Thu, 19 Nov 2020 08:26:01 -0800 (PST) Received: from localhost ([2a01:4b00:8523:2d03:9843:cd3f:f36b:d55c]) by smtp.gmail.com with ESMTPSA id rn2sm58104ejb.94.2020.11.19.08.26.00 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 19 Nov 2020 08:26:00 -0800 (PST) From: David Brazdil To: kvmarm@lists.cs.columbia.edu Subject: [RFC PATCH 6/6] kvm: arm64: Remove hyp_symbol_addr Date: Thu, 19 Nov 2020 16:25:43 +0000 Message-Id: <20201119162543.78001-7-dbrazdil@google.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201119162543.78001-1-dbrazdil@google.com> References: <20201119162543.78001-1-dbrazdil@google.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201119_112603_482783_6F61D7CB 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 , kernel-team@android.com, Suzuki K Poulose , Marc Zyngier , linux-kernel@vger.kernel.org, James Morse , linux-arm-kernel@lists.infradead.org, Catalin Marinas , David Brazdil , Will Deacon , Ard Biesheuvel , Julien Thierry , Andrew Scull Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The helper was used to force PC-relative addressing in hyp code because absolute addressing via constant-pools used to generate kernel VAs. This was cumbersome and required programmers to remember to use the helper whenever they wanted to take a pointer. Now that hyp relocations are fixed up, there is no need for the helper any logner. Remove it. Signed-off-by: David Brazdil Acked-by: Ard Biesheuvel --- arch/arm64/include/asm/kvm_asm.h | 20 -------------------- arch/arm64/kvm/hyp/include/hyp/switch.h | 4 ++-- arch/arm64/kvm/hyp/nvhe/hyp-smp.c | 4 ++-- arch/arm64/kvm/hyp/nvhe/psci-relay.c | 4 ++-- arch/arm64/kvm/hyp/vgic-v2-cpuif-proxy.c | 2 +- 5 files changed, 7 insertions(+), 27 deletions(-) diff --git a/arch/arm64/include/asm/kvm_asm.h b/arch/arm64/include/asm/kvm_asm.h index 1a86581e581e..1961d23c0c40 100644 --- a/arch/arm64/include/asm/kvm_asm.h +++ b/arch/arm64/include/asm/kvm_asm.h @@ -203,26 +203,6 @@ extern void __vgic_v3_init_lrs(void); extern u32 __kvm_get_mdcr_el2(void); -/* - * Obtain the PC-relative address of a kernel symbol - * s: symbol - * - * The goal of this macro is to return a symbol's address based on a - * PC-relative computation, as opposed to a loading the VA from a - * constant pool or something similar. This works well for HYP, as an - * absolute VA is guaranteed to be wrong. Only use this if trying to - * obtain the address of a symbol (i.e. not something you obtained by - * following a pointer). - */ -#define hyp_symbol_addr(s) \ - ({ \ - typeof(s) *addr; \ - asm("adrp %0, %1\n" \ - "add %0, %0, :lo12:%1\n" \ - : "=r" (addr) : "S" (&s)); \ - addr; \ - }) - #define __KVM_EXTABLE(from, to) \ " .pushsection __kvm_ex_table, \"a\"\n" \ " .align 3\n" \ diff --git a/arch/arm64/kvm/hyp/include/hyp/switch.h b/arch/arm64/kvm/hyp/include/hyp/switch.h index 84473574c2e7..54f4860cd87c 100644 --- a/arch/arm64/kvm/hyp/include/hyp/switch.h +++ b/arch/arm64/kvm/hyp/include/hyp/switch.h @@ -505,8 +505,8 @@ static inline void __kvm_unexpected_el2_exception(void) struct exception_table_entry *entry, *end; unsigned long elr_el2 = read_sysreg(elr_el2); - entry = hyp_symbol_addr(__start___kvm_ex_table); - end = hyp_symbol_addr(__stop___kvm_ex_table); + entry = &__start___kvm_ex_table; + end = &__stop___kvm_ex_table; while (entry < end) { addr = (unsigned long)&entry->insn + entry->insn; diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-smp.c b/arch/arm64/kvm/hyp/nvhe/hyp-smp.c index ceb427aabb91..6870d9f3d4b7 100644 --- a/arch/arm64/kvm/hyp/nvhe/hyp-smp.c +++ b/arch/arm64/kvm/hyp/nvhe/hyp-smp.c @@ -33,8 +33,8 @@ unsigned long __hyp_per_cpu_offset(unsigned int cpu) if (cpu >= ARRAY_SIZE(kvm_arm_hyp_percpu_base)) hyp_panic(); - cpu_base_array = (unsigned long*)hyp_symbol_addr(kvm_arm_hyp_percpu_base); + cpu_base_array = (unsigned long*)(&kvm_arm_hyp_percpu_base[0]); this_cpu_base = kern_hyp_va(cpu_base_array[cpu]); - elf_base = (unsigned long)hyp_symbol_addr(__per_cpu_start); + elf_base = (unsigned long)&__per_cpu_start; return this_cpu_base - elf_base; } diff --git a/arch/arm64/kvm/hyp/nvhe/psci-relay.c b/arch/arm64/kvm/hyp/nvhe/psci-relay.c index 313ef42f0eab..f64380a49a72 100644 --- a/arch/arm64/kvm/hyp/nvhe/psci-relay.c +++ b/arch/arm64/kvm/hyp/nvhe/psci-relay.c @@ -147,7 +147,7 @@ static int psci_cpu_suspend(u64 func_id, struct kvm_cpu_context *host_ctxt) * point if it is a deep sleep state. */ ret = psci_call(func_id, power_state, - __hyp_pa(hyp_symbol_addr(__kvm_hyp_cpu_entry)), + __hyp_pa(__kvm_hyp_cpu_entry), __hyp_pa(cpu_params)); release_reset_state(cpu_state); @@ -182,7 +182,7 @@ static int psci_cpu_on(u64 func_id, struct kvm_cpu_context *host_ctxt) return PSCI_RET_ALREADY_ON; ret = psci_call(func_id, mpidr, - __hyp_pa(hyp_symbol_addr(__kvm_hyp_cpu_entry)), + __hyp_pa(__kvm_hyp_cpu_entry), __hyp_pa(cpu_params)); /* diff --git a/arch/arm64/kvm/hyp/vgic-v2-cpuif-proxy.c b/arch/arm64/kvm/hyp/vgic-v2-cpuif-proxy.c index 8f0585640241..87a54375bd6e 100644 --- a/arch/arm64/kvm/hyp/vgic-v2-cpuif-proxy.c +++ b/arch/arm64/kvm/hyp/vgic-v2-cpuif-proxy.c @@ -64,7 +64,7 @@ int __vgic_v2_perform_cpuif_access(struct kvm_vcpu *vcpu) } rd = kvm_vcpu_dabt_get_rd(vcpu); - addr = hyp_symbol_addr(kvm_vgic_global_state)->vcpu_hyp_va; + addr = kvm_vgic_global_state.vcpu_hyp_va; addr += fault_ipa - vgic->vgic_cpu_base; if (kvm_vcpu_dabt_iswrite(vcpu)) {