Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp575933pxb; Thu, 19 Nov 2020 08:28:48 -0800 (PST) X-Google-Smtp-Source: ABdhPJyWbboLi7TRZm14RkIK2cfhjEQPhXq/qCaHgtNF3xa7BhaoukBlTOUsAX7YQbbiK4YlCD3k X-Received: by 2002:aa7:df89:: with SMTP id b9mr31966932edy.335.1605803328580; Thu, 19 Nov 2020 08:28:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605803328; cv=none; d=google.com; s=arc-20160816; b=saVSgnbm0Vw2h/0leACVXQN4VS4+pbPQsd7teaRcR2zAE3YKIJTcGnBhpHfKubDs9w 2HNt1DMV5Ds9YiGxa9w3C6V5Cnvao0sNQy6K/R8Lki83sQrOhn3ZVJthUwfveqM2EoHu 7sz1P1OeuRplRwhcjbtVGFTZquMsxF7Qk+s4KfIjFzHWGHZtZXOcp62P/eM3i4JV+ZDf dCHANH85Y4F76u00qXSzLSir5LreEsLt3nHQyQoFCCdCEM+32k4CKOug4UMBdP58HmxU 1IYRPEx5EPS6+9ewCQq6bxdqKaGc4ouDbs0LhCE84pEidyo3fLlzckZSHDCwpPpwcgNr 8i9w== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=2GruhQdqr+wzWu7YIuTjo4e/TRyXrwSpjT/ODeg/Yqc=; b=WfBXRqGErPx+BdhyEz3pTEsUR4m/GVq4+PS74KEdpY8TQhNIjyRijQWJ9b9MO/aLYX 2S9EXtv5z/KWZEdoGvUbSq3Ha1GeziblHZOfdKzwRtOimaofUhoa7HfOnQCBpYOE125D iPOgHhLSoT/pCcdVVX4NiR/xdr9O29t/M7xMx01InHayWmmlrjmfkKhF76paBl0/smDl t0EEx7IdmMGY0dqUT5cX2OSGgi7wtlCZWnifKMrHwGNIU0RviDIpbK+ddMbLjox0pz4i 6TKxcYi+EphBMYCUYoAUYI80bV0M8R/HcmTfJcbLVrrIHaptsC+3QxWuAeBUdIYQsK62 suNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=HNhCr9vU; 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 bi17si133868edb.582.2020.11.19.08.28.25; Thu, 19 Nov 2020 08:28:48 -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=HNhCr9vU; 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 S1728614AbgKSQZt (ORCPT + 99 others); Thu, 19 Nov 2020 11:25:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53742 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728011AbgKSQZt (ORCPT ); Thu, 19 Nov 2020 11:25:49 -0500 Received: from mail-ej1-x641.google.com (mail-ej1-x641.google.com [IPv6:2a00:1450:4864:20::641]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 066A2C0613CF for ; Thu, 19 Nov 2020 08:25:49 -0800 (PST) Received: by mail-ej1-x641.google.com with SMTP id y17so8710489ejh.11 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=FPF0TsERvS0C5MOOlkWQLaUu/BRaj0ybVM55nmGcDNaBp2S1yh0LSVVe8EIiWEOCcF pGAmdtGEkULAZVPRXsZWVYhpGn0CNfFZ4yDGk20mt9FZAB9ZkHIhQZTlNEXmcbi7TIWd 2H8h6mXQftZ0CEMOFDnxmqHTzA+CAnY9l36hsgqIQVEaXw8lQIHASjnIWbTbV+6kYsyu 0VeSq3Fydjft1UWVOszCB9rKEMlx7z6t/Qa7R0uzx75ba/JEMYeMl71jwtdNKtM09UNj Ic4r/tu9I0Nxg2qJQXs7vN5TuTyX4URkUgG6/eheC+X1pMOmPqi4zgymsMZufEFBx/hx gHTg== X-Gm-Message-State: AOAM530LD4mG+nPhQ0iZdQGaqCIVp9uM98rjoA6IC71QhVm9+5tkyQOi EDRNVUgAbLxmKED92ETLpiFHRQ== 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 Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Marc Zyngier , James Morse , Julien Thierry , Suzuki K Poulose , Catalin Marinas , Will Deacon , Mark Rutland , Andrew Scull , Ard Biesheuvel , kernel-team@android.com, David Brazdil 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 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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(-) -- 2.29.2.299.gdc1121823c-goog