From patchwork Wed Dec 9 13:17: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: 11961357 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 CBC9AC433FE for ; Wed, 9 Dec 2020 13:19:20 +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 8620523101 for ; Wed, 9 Dec 2020 13:19:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8620523101 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=JvyXnFjjxAVQHLgn9X1qFSwy5FIW3Gyd1AVl9Ir3jfo=; b=ldgqgcHpktjzYwV+hmZQSWVVdo B3HnUmX5ZGffyRqm34LR+971GyWRD7ds/FxNl/uwEBJSaRS4j4nulwTyb+4gXZ9FCXSFNuCqeuP0z 8ym5NWUFv9aMvlnUHnKwRgj2IN7SH5iqJFz/gbdgFTxfiJsGCyswOQ72Re/Vz9JUHQI2++KTYNYkk zR+gRj/6ZhYgNkX8laFO9vj1AuJFrxbHLROrI4/q8CppUqYanEhAkW0qb9y0kyQGuiYdAdEgCJHs/ GpRsMO4ULpjEj//9NamFy2tRmNhdju2yk5ye97B34X1vHV7lC+SoT1sHuxWzzdDOH+fx+jb3VT+DX hnu1hCdg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kmzLu-0003B7-0n; Wed, 09 Dec 2020 13:17:54 +0000 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kmzLr-0003AX-EL for linux-arm-kernel@lists.infradead.org; Wed, 09 Dec 2020 13:17:52 +0000 Received: by mail-wr1-x444.google.com with SMTP id r7so1707905wrc.5 for ; Wed, 09 Dec 2020 05:17: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:mime-version :content-transfer-encoding; bh=QypmxVIIHfEpkRMXwz8jV9VsRXxLaN9Gc9MoWcFoJN0=; b=kn2qu9K6MOj2MXP522yIjJX7A97Hyx0Phr4xxfxonQ/CMS6ng7WChR5TEVRC/jU2Su QLDFFAMueBgyOZhIR07ndwQHRYzcAX4yJrUz2OCRVGpilBOzkQhlaLAaABKKbaOo2VEF vm89uw1HvqgH3laEQB7NJVxW/XObdLyra7NrslCf0vlFxqx2u7jdJNb7iV0jOZQSbq2Y d0vs+Dms5KmvwpkpRnRmDFhmF3eaZc7BPFquhJnN6ii8hgGK1fH3IELu7Upqef2nN15l lc04nXOiIITjkqdBMmjhqITcQracKHbhw499CO72Uc3kCIH/DtWhayfxko85ipVEYdo/ ehqQ== 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=QypmxVIIHfEpkRMXwz8jV9VsRXxLaN9Gc9MoWcFoJN0=; b=iPcXoKFE8WbtG5AWzeMsE0tzjB4iWOaEf19nc+xmV1l5FqBa7hnMtnM1MSQn4XeRIc 3ahdFP1Ek8LQ+ZEktUjs0pFX6bPOlZ9RuDIaWhOSoYKgJ/t7sNoGA6CkowhAqFrsFMK9 VbgXfi+TAP6myh2GWUTPGOXHEC94BXDppCl2utUGUlGRGZBX5/xGWS8U9lscjaDsiRpM 3EXtxBdxJortAd7+Ug3rfBpjtn+gx9ERlw26JDchPfYb38KHmgDf0qbflfKSM46kocR7 wAgcA9Ey4DHgaqdzp5umBk72+L4TzbDuWTE/u9vSdxs+7UJxOVpSebxKE97BU3AxEDi3 zfCg== X-Gm-Message-State: AOAM533OxJKRGRaDglGx7swrZUVSnMOTqqaGKCuPfYhZ0NYnbq1EggFM hvrCCJlIXEZA/HpOBWjn+OT25w== X-Google-Smtp-Source: ABdhPJxePgQkSVZVEUA4FZYzEF3UdagWSgDgT9hXezo4LvnwaZ1NClGbAw10690t+P/fIDVPZfv+0Q== X-Received: by 2002:adf:97db:: with SMTP id t27mr2599398wrb.375.1607519870252; Wed, 09 Dec 2020 05:17:50 -0800 (PST) Received: from localhost ([2a01:4b00:8523:2d03:9d1b:d0eb:db43:6cd2]) by smtp.gmail.com with ESMTPSA id d187sm3644642wmd.8.2020.12.09.05.17.48 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 09 Dec 2020 05:17:48 -0800 (PST) From: David Brazdil To: kvmarm@lists.cs.columbia.edu Subject: [PATCH 0/9] KVM: arm64: Relocate absolute hyp VAs Date: Wed, 9 Dec 2020 13:17:37 +0000 Message-Id: <20201209131746.85622-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-20201209_081751_563091_A6FD0155 X-CRM114-Status: GOOD ( 18.39 ) 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: kernel-team@android.com, Suzuki K Poulose , Catalin Marinas , linux-kernel@vger.kernel.org, James Morse , linux-arm-kernel@lists.infradead.org, Marc Zyngier , David Brazdil , Will Deacon , Ard Biesheuvel , Julien Thierry Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org nVHE hyp code is linked into the same kernel binary but executes under different memory mappings. If the compiler of hyp code chooses absolute addressing for accessing a symbol, the kernel linker will relocate that address to a kernel image virtual address, causing a runtime exception. So far the strategy has been to force PC-relative addressing by wrapping all symbol references with the hyp_symbol_addr macro. This is error prone and developer unfriendly. The series adds a new build-time step for nVHE hyp object file where positions targeted by R_AARCH64_ABS64 relocations are enumerated and the information stored in a separate ELF section in the kernel image. At runtime, the kernel first relocates all absolute addresses to their actual virtual offset (eg. for KASLR), and then addresses listed in this section are converted to hyp VAs. The RFC of this series did not have a build-time step and instead relied on filtering dynamic relocations at runtime. That approach does not work if the kernel is built with !CONFIG_RELOCATABLE, hence an always-present set of relocation positions was added. The series is based on the current kvmarm/next (commit 3a514592b6) and structured as follows: * patch 1 is Jamie's fix of .hyp.data..percpu alignment; already in master, not yet in kvmarm/next; included to avoid merge conflicts * patches 2-3 make sure that all sections referred to by hyp code are handled by the hyp linker script and prefixed with .hyp so they can be identified by the build-time tool * patches 4-6 contain the actual changes to identify and relocate VAs * patches 7-8 fix existing code that assumes kernel VAs * patch 9 removes the (now redundant) hyp_symbol_addr The series is also available at: https://android-kvm.googlesource.com/linux topic/hyp-reloc_v1 -David David Brazdil (8): KVM: arm64: Rename .idmap.text in hyp linker script KVM: arm64: Set up .hyp.rodata ELF section KVM: arm64: Add symbol at the beginning of each hyp section KVM: arm64: Generate hyp relocation data KVM: arm64: Apply hyp relocations at runtime KVM: arm64: Fix constant-pool users in hyp KVM: arm64: Remove patching of fn pointers in hyp KVM: arm64: Remove hyp_symbol_addr Jamie Iles (1): KVM: arm64: Correctly align nVHE percpu data arch/arm64/configs/defconfig | 1 + arch/arm64/include/asm/hyp_image.h | 29 +- arch/arm64/include/asm/kvm_asm.h | 20 -- arch/arm64/include/asm/kvm_mmu.h | 61 ++--- arch/arm64/include/asm/sections.h | 3 +- arch/arm64/kernel/image-vars.h | 1 - arch/arm64/kernel/smp.c | 4 +- arch/arm64/kernel/vmlinux.lds.S | 18 +- arch/arm64/kvm/arm.c | 7 +- arch/arm64/kvm/hyp/include/hyp/switch.h | 4 +- arch/arm64/kvm/hyp/nvhe/Makefile | 28 +- arch/arm64/kvm/hyp/nvhe/gen-hyprel.c | 326 +++++++++++++++++++++++ arch/arm64/kvm/hyp/nvhe/host.S | 29 +- arch/arm64/kvm/hyp/nvhe/hyp-init.S | 4 +- 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 | 14 +- arch/arm64/kvm/hyp/nvhe/psci-relay.c | 24 +- arch/arm64/kvm/hyp/vgic-v2-cpuif-proxy.c | 2 +- arch/arm64/kvm/va_layout.c | 34 ++- 20 files changed, 495 insertions(+), 129 deletions(-) create mode 100644 arch/arm64/kvm/hyp/nvhe/gen-hyprel.c --- 2.29.2.576.ga3fc446d84-goog