From patchwork Thu Nov 19 16:25:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Brazdil X-Patchwork-Id: 11918205 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=-11.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,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 5A40BC56201 for ; Thu, 19 Nov 2020 16:26:22 +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 DB22422240 for ; Thu, 19 Nov 2020 16:26:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="LNgAGbnp"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="HNhCr9vU" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DB22422240 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: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:In-Reply-To:References:List-Owner; bh=A3FGhqu66Jg7j3cczZ3/uIQ1k3kPsHFFVizwqcnhWjk=; b=LNgAGbnp/53Y1dEYbOIXgUk42O TXWDWYSq+MFcCNrdn1qLR32qQSsk1YZOV97UfJAHr1LiNQDVEgNoV+1oJu54HtdfZ8kxT7Q4wx/NA MWCBOq5uOkv9ttnTNYQTNpuPuJoAARQnghhE6A5erCBzOs1V4hCgXdraU3ElAjWMR48xtRhJ2rQ7/ R1tMgYbHFlM4guSGcG08qLHHngf/cXwlYHgyW/G05FtWMFClYgu0z4+G+9fIgcvXYxPxRQxtfqQig Hu+lXsxnldAvusPWokva1pFxwQTJi6Evm/udYBr6thZw/AeCofznpmpa9nOf4ozgWd63Dqp9P3QTi rPUBAl1w==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kfmkq-0004CH-MW; Thu, 19 Nov 2020 16:25:52 +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 1kfmkn-0004BC-Eu for linux-arm-kernel@lists.infradead.org; Thu, 19 Nov 2020 16:25:50 +0000 Received: by mail-ej1-x642.google.com with SMTP id o21so8756056ejb.3 for ; Thu, 19 Nov 2020 08:25:48 -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:mime-version :content-transfer-encoding; bh=2GruhQdqr+wzWu7YIuTjo4e/TRyXrwSpjT/ODeg/Yqc=; b=HNhCr9vU0ISFuiHpPTfBE/dnSa1k1AQmT5a5owhc4HAvKKm3lmsYZp8SXMp+lTOqLJ oA3puTIhotxShLQBAg0rlM4WDEQkkC69CqcXEaiU9EAiBKKxtasmjjIbIeazLFtic2MI fLz07UvbuvQYFFiUzTKn15TR5mxfbYbxOQpkI5/9WHICtRExdl10ClVPeje4PwMD++Sp 5gJtKtlsgxdEDaopQgVhEbsCfANljY7EtRJZz+x93MNooDxOX9ReqlU+WdfT/OoDCbh6 DZ4+nKQgm0TMuhm7MKG6SISpKF0WEI9VVfoZtlPQUmeHaXi/qPVmsTWyh3Hr2yUJQNso SF0w== 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:mime-version :content-transfer-encoding; bh=2GruhQdqr+wzWu7YIuTjo4e/TRyXrwSpjT/ODeg/Yqc=; b=dgBsU9v7i1emZqZlrvE3wpO9qr8Ae7ryeneGiYsWCnIuMFejQCy42f01fFKsLzfJD/ XP0Z/JeOl3tapZG3Um66ZlGbsYynY0+sfRZrdBBH1be+dfKP1aAqgW6CKl+uZrmyh81O nLDjKB5f+AIsLhqoLfy8jA08M5ImsP9Nom/K8dJw0teSK5tXHYr1Wqsuh316tNT3DA7r ageXfOiyMHtlP4JVABxXu1513Jx2S9U25izXx1cJiyE/Z+8bKd/vOByBww3IwmSCwfa2 jInA5rbkAMbMqFc0OQkcxw67zgxNPGymuUmXF25C8q6jTO/Jt7cIXTwpSclPxozXO/Oc A4mw== X-Gm-Message-State: AOAM532G/mcDw06AdbF8SROoKAQLywT4i8YMUb+UJpI4lyZ2+vZcIWMf RSLnXJdg8jzN7d5i89BENx6E4eSveE8VOQ== X-Google-Smtp-Source: ABdhPJx5kfoZrvZqP/Uo4FFewwoV/LxEuk0ZaZ0aeXlkfVXWjL868auf9G7gfWTXVZ0FB7pclJWrVQ== X-Received: by 2002:a17:906:3ec8:: with SMTP id d8mr29647604ejj.32.1605803147524; Thu, 19 Nov 2020 08:25:47 -0800 (PST) Received: from localhost ([2a01:4b00:8523:2d03:9843:cd3f:f36b:d55c]) by smtp.gmail.com with ESMTPSA id 2sm66968ejw.65.2020.11.19.08.25.46 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 19 Nov 2020 08:25:46 -0800 (PST) From: David Brazdil To: kvmarm@lists.cs.columbia.edu Subject: [RFC PATCH 0/6] kvm: arm64: Fix up hyp relocations Date: Thu, 19 Nov 2020 16:25:37 +0000 Message-Id: <20201119162543.78001-1-dbrazdil@google.com> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201119_112549_569353_B3692093 X-CRM114-Status: GOOD ( 13.42 ) 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 Hi, KVM nVHE hyp code runs under different VA mapping than the kernel, which meant that .hyp.text code had to use PC-relative addressing because relocations would produce a kernel VA. Programmers had to be extremely careful with C semantics to not break this fragile setup. See hyp_symbol_addr comments for details. Now that we're moving to all nVHE hyp code/data being in separate ELF sections from the rest of the kernel, it is becoming possible to revisit relocations during early boot, filter those used by nVHE hyp and converting those (already relocated) kern VAs to hyp VAs. Sending this as an RFC, mainly to get feedback but also because it's only lightly tested. It still feels hacky but much more robust than the existing approach. The one place where I see somebody breaking this is the list of ELF sections owned by ELF. That list is currently evolving but should stabilize over time. The patches are based on kvmarm/queue (with Marc's "Host EL2 entry improvements") and my "Opt-in always-on nVHE hypervisor" v2 series. -David David Brazdil (6): kvm: arm64: Set up .hyp.rodata ELF section kvm: arm64: Fix up RELA relocations in hyp code/data kvm: arm64: Fix up RELR relocation in hyp code/data kvm: arm64: Remove patching of fn pointers in hyp kvm: arm64: Fix constant-pool users in hyp kvm: arm64: Remove hyp_symbol_addr arch/arm64/include/asm/kvm_asm.h | 20 ---- arch/arm64/include/asm/kvm_mmu.h | 48 ++++----- arch/arm64/include/asm/sections.h | 2 +- arch/arm64/kernel/image-vars.h | 1 - arch/arm64/kernel/smp.c | 4 +- arch/arm64/kernel/vmlinux.lds.S | 7 +- arch/arm64/kvm/arm.c | 7 +- arch/arm64/kvm/hyp/include/hyp/switch.h | 4 +- arch/arm64/kvm/hyp/nvhe/host.S | 29 +++--- arch/arm64/kvm/hyp/nvhe/hyp-main.c | 11 +- arch/arm64/kvm/hyp/nvhe/hyp-smp.c | 4 +- arch/arm64/kvm/hyp/nvhe/hyp.lds.S | 1 + arch/arm64/kvm/hyp/nvhe/psci-relay.c | 4 +- arch/arm64/kvm/hyp/vgic-v2-cpuif-proxy.c | 2 +- arch/arm64/kvm/va_layout.c | 123 +++++++++++++++++++++-- 15 files changed, 175 insertions(+), 92 deletions(-)