Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1439860ybt; Thu, 25 Jun 2020 06:15:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy5MgbFjU44lzwRFPdAMRHmKEFDkEnr4Ol8k+n0EUewZCfBYDfvztvKgI0cTVdMVa0BTQfR X-Received: by 2002:a17:906:bb0c:: with SMTP id jz12mr1395129ejb.27.1593090905361; Thu, 25 Jun 2020 06:15:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593090905; cv=none; d=google.com; s=arc-20160816; b=jP2IESYt16p0l8UmGgm2437W2CipjIV7PlVMJhDl4dXv68cCJjsViRjRjMTutIrNYJ VAc25FqM5gi8NcCUtBWAyyZjeO0q2bCCNLe5FyaJOnQ7DyQ3zQtKiobQk3OBKn4tTO2Q vRp4Byllxb5FTWhlj5yrBJb+2ey7YcUaSmaiVnI+oJ8mMdE5MPlSjbgp+wze4FAuM90a bv1El2LpAHqtBvTCD9bK070/2mfxBBgkpYf0/6Oya2FEP1vHSuj7IXU3d4QNDDE++maO Zdbb/HAiPG9qsII9/PLb5kC81HXjG9sb5CdvxjPTcEk1THLDTnoUTfmmD8IdtPFUTich WHGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=xPV3vLHNPqkWUx4FYbA872hJ3EvgoWDkGiwzLIz0i8U=; b=tmitmUhJPxAu7h8i816Du4k8y2Ak0QKbTxEvFEwp9wQ2UimT9n6NRXfcDMlzgaHMqd v9mVS5n+yXeTim5yweQB8bA+YVzCGmU9jtD04AGcL4j/j6vVHUDqckGRzC2yfIFmYyGe UA6wkHdmNT1Fprv4lnbBv3mPGg9kvgaopy/s0DGedi65w2SmUa8btow0G+vQ3/0RLMO9 X2gFJuXaWbNAXGKedqKY253KVCfmnmg1LFcaNVg/GJ08bqJo4dOkaCuahfxah4Df6BJR YWRDXb/tbGk4rNpT7+YwFoivxuOeEi7YEV5LYi7B/M3NVEg9Te6oFlbU3wi5Hvil/cb0 R2fw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=gGBLG82B; 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 g14si1128499ejw.376.2020.06.25.06.14.40; Thu, 25 Jun 2020 06:15:05 -0700 (PDT) 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=gGBLG82B; 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 S2404805AbgFYNO0 (ORCPT + 99 others); Thu, 25 Jun 2020 09:14:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35016 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404710AbgFYNO0 (ORCPT ); Thu, 25 Jun 2020 09:14:26 -0400 Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DF62CC08C5C1 for ; Thu, 25 Jun 2020 06:14:25 -0700 (PDT) Received: by mail-wm1-x341.google.com with SMTP id l17so5531540wmj.0 for ; Thu, 25 Jun 2020 06:14:25 -0700 (PDT) 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=xPV3vLHNPqkWUx4FYbA872hJ3EvgoWDkGiwzLIz0i8U=; b=gGBLG82B4G0LEWygJGTzyWDxE7LGM0L04ycqzZcdpej60fX9ic9cyP3pey9aWRuKDP MEWYYdEcSpnwIT1cFiSack6kKFOzTLryy0omOBzokPhYm12AsPuIxoqqh5W6aHn621D6 U9ZssHu6Eex5heudfWc82FctcVHaaLkgC+pXJ+NVpzKwBy8TUe45g4VlE+KU/FeFf4a8 JBocUY8ly2fU97u6R6i6lai7EsMjyXK3JtqlwCdnsdWM5KetusRrsTWUM7vapkRAEPiV q+modrlkmRcC27WIhL9RdDHKF0iM7BdD3SDGFNwrAKLjRKnTcT8hiwiqX23KkQWfYgYk qusA== 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=xPV3vLHNPqkWUx4FYbA872hJ3EvgoWDkGiwzLIz0i8U=; b=Hs1Rayw62bzJkY8LSdLElviGjNbWIjTNMwnZrtTHJfm3WkGG9F3X09fAEz8Y4DPMtF 2Aa2NYq87WsyAr9pQhMBzrlKE020MxH/eRdGSHyAb1RJUhke+YNPSqKZr3jVYShQbJEn YwHl6F5sqNp/tIzB59RBkMfzTXyUI7DAVWA5Qp5xzlLOyOOcw/wOcNTumcEVhHE8gcg0 pVmhMqMreoSd/NuDfbVutCfvKRnISEJja7abxL/Mha1lkDElloVWdc3PQHJGMoaf/y+B orPBzJkDw+hujnG1dqNY0u3tvI7b28NU+PzLHneUtxQMvGGH9vi1BQMfmzhT4XmkuV8h ZmPA== X-Gm-Message-State: AOAM5302woq9+N23+Hush70GuQxKGS4SnZB1twMAe6kFv1QVWzFh9ZRG 8oi+LUhheQfitDtqYIbXkMkdag== X-Received: by 2002:a7b:c92e:: with SMTP id h14mr3246932wml.36.1593090864288; Thu, 25 Jun 2020 06:14:24 -0700 (PDT) Received: from localhost ([2a01:4b00:8523:2d03:c126:6748:7a9d:2d]) by smtp.gmail.com with ESMTPSA id c206sm13401130wmf.36.2020.06.25.06.14.23 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 25 Jun 2020 06:14:23 -0700 (PDT) From: David Brazdil To: Marc Zyngier , Will Deacon , Catalin Marinas , James Morse , Julien Thierry , Suzuki K Poulose Cc: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, android-kvm@google.com, kernel-team@android.com, David Brazdil Subject: [PATCH v4 00/15] Split off nVHE hyp code Date: Thu, 25 Jun 2020 14:14:05 +0100 Message-Id: <20200625131420.71444-1-dbrazdil@google.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Refactor files in arch/arm64/kvm/hyp to compile all code which runs in EL2 under nVHE into separate object files from the rest of KVM. This is done in preparation for being able to unmap hyp code from EL1 and kernel code/data from EL2 but has other benefits too, notably: * safe use of KASAN/UBSAN/GCOV instrumentation on VHE code, * no need for __hyp_text annotations. nVHE-specific code is moved to hyp/nvhe and compiled with custom build rules similar to those used by EFI stub. Shared source files are compiled under both VHE and nVHE build rules. Where a source file contained both VHE and nVHE code, it is split into a shared header file and two C source files. This is done one file per commit to make review easier. All nVHE symbols are prefixed with "__kvm_nvhe_" to avoid collisions with VHE variants (also inspired by EFI stub). Since this prefixes unresolved symbols too, image-vars.h contains a list of kernel symbol aliases where nVHE code still refers to kernel proper. The list grows fairly large as the patch series progresses and code is moved around, but at the end contains 20 symbols. These remaining dependencies on kernel proper will be further reduced in the future. No functional changes are intended but code was simplified whenever the refactoring made it possible. Tested by running kvm-unit-tests on QEMU 5.0 with VHE/nVHE and GIC v2/v3. Dual compilation of code shared by VHE/nVHE increase the size of the kernel. Bloat-o-meter vmlinux diff shows an increase of 21 KB on the ELF symbol level. Size of Image.gz is up by 10 KB; size of Image is unchanged, presumably due to ELF section alignment. This is based off v5.8-rc2. Available in branch 'topic/el2-obj-v4' of git repo: https://android-kvm.googlesource.com/linux Changes v3 -> v4: * rebase onto v5.8-rc2 (trivial) * add SYM_DATA_START/END around __smccc_workaround_1_smc * move VHE-specific source files into hyp/vhe * move headers shared by VHE/nVHE into hyp/include * define __KVM_VHE_HYPERVISOR__ for VHE-specific code * has_vhe() compile-time determinable when used in hyp/ * KVM_NVHE_ALIAS macro in image-vars.h, comments throughout series * #define hyp symbols in kernel to magically select between VHE/nVHE variant * duplicate hyp/tlb.c instead of splitting it * pass idmap_t0sz to hyp-init as parameter to avoid symbol alias Changes v2 -> v3: * rebase onto v5.8-rc1 * remove patch changing hypcall interface to function IDs * move hyp-init.S to nVHE * fix symbol aliasing under CONFIG_ARM64_PSEUDO_NMI and CONFIG_ARM64_SVE * remove VHE's unused __kvm_enable_ssbs() * make nVHE use VHE's hyp_panic_string for consistent use of absolute relocs when returning pointers back to kernel * replace __noscs annotation (added to __hyp_text macro) with build rule Changes v1 -> v2: * change nVHE symbol prefix from __hyp_text_ to __kvm_nvhe_ * rename __HYPERVISOR__ macro to __KVM_NVHE_HYPERVISOR__ * use hcall jump table instead of array of function pointers * drop patch to unify HVC callers * move __smccc_workaround_1_smc to own file * header guards for hyp/*.h * improve helpers for handling VHE/nVHE hyp syms in kernel proper * improve commit messages, cover letter -David Andrew Scull (2): arm64: kvm: Handle calls to prefixed hyp functions arm64: kvm: Move hyp-init.S to nVHE David Brazdil (13): arm64: kvm: Fix symbol dependency in __hyp_call_panic_nvhe arm64: kvm: Move __smccc_workaround_1_smc to .rodata arm64: kvm: Add build rules for separate VHE/nVHE object files arm64: kvm: Use build-time defines in has_vhe() arm64: kvm: Build hyp-entry.S separately for VHE/nVHE arm64: kvm: Duplicate hyp/tlb.c for VHE/nVHE arm64: kvm: Split hyp/switch.c to VHE/nVHE arm64: kvm: Split hyp/debug-sr.c to VHE/nVHE arm64: kvm: Split hyp/sysreg-sr.c to VHE/nVHE arm64: kvm: Duplicate hyp/timer-sr.c for VHE/nVHE arm64: kvm: Compile remaining hyp/ files for both VHE/nVHE arm64: kvm: Remove __hyp_text macro, use build rules instead arm64: kvm: Lift instrumentation restrictions on VHE arch/arm64/include/asm/kvm_asm.h | 48 +- arch/arm64/include/asm/kvm_emulate.h | 2 +- arch/arm64/include/asm/kvm_host.h | 23 +- arch/arm64/include/asm/kvm_hyp.h | 15 +- arch/arm64/include/asm/mmu.h | 7 - arch/arm64/include/asm/virt.h | 13 +- arch/arm64/kernel/image-vars.h | 51 + arch/arm64/kvm/Makefile | 2 +- arch/arm64/kvm/arm.c | 18 +- arch/arm64/kvm/hyp/Makefile | 24 +- arch/arm64/kvm/hyp/aarch32.c | 6 +- arch/arm64/kvm/hyp/entry.S | 1 - arch/arm64/kvm/hyp/fpsimd.S | 1 - arch/arm64/kvm/hyp/hyp-entry.S | 21 +- .../{debug-sr.c => include/hyp/debug-sr.h} | 78 +- arch/arm64/kvm/hyp/include/hyp/switch.h | 509 ++++++++++ .../{sysreg-sr.c => include/hyp/sysreg-sr.h} | 162 +-- arch/arm64/kvm/hyp/nvhe/Makefile | 42 + arch/arm64/kvm/hyp/nvhe/debug-sr.c | 77 ++ arch/arm64/kvm/{ => hyp/nvhe}/hyp-init.S | 24 +- arch/arm64/kvm/hyp/nvhe/switch.c | 272 +++++ arch/arm64/kvm/hyp/nvhe/sysreg-sr.c | 46 + arch/arm64/kvm/hyp/{ => nvhe}/timer-sr.c | 6 +- arch/arm64/kvm/hyp/{ => nvhe}/tlb.c | 100 +- arch/arm64/kvm/hyp/smccc_wa.S | 32 + arch/arm64/kvm/hyp/switch.c | 936 ------------------ arch/arm64/kvm/hyp/vgic-v2-cpuif-proxy.c | 4 +- arch/arm64/kvm/hyp/vgic-v3-sr.c | 130 ++- arch/arm64/kvm/hyp/vhe/Makefile | 11 + arch/arm64/kvm/hyp/vhe/debug-sr.c | 26 + arch/arm64/kvm/hyp/vhe/switch.c | 219 ++++ arch/arm64/kvm/hyp/vhe/sysreg-sr.c | 114 +++ arch/arm64/kvm/hyp/vhe/timer-sr.c | 12 + arch/arm64/kvm/hyp/vhe/tlb.c | 162 +++ scripts/kallsyms.c | 1 + 35 files changed, 1786 insertions(+), 1409 deletions(-) rename arch/arm64/kvm/hyp/{debug-sr.c => include/hyp/debug-sr.h} (71%) create mode 100644 arch/arm64/kvm/hyp/include/hyp/switch.h rename arch/arm64/kvm/hyp/{sysreg-sr.c => include/hyp/sysreg-sr.h} (56%) create mode 100644 arch/arm64/kvm/hyp/nvhe/Makefile create mode 100644 arch/arm64/kvm/hyp/nvhe/debug-sr.c rename arch/arm64/kvm/{ => hyp/nvhe}/hyp-init.S (91%) create mode 100644 arch/arm64/kvm/hyp/nvhe/switch.c create mode 100644 arch/arm64/kvm/hyp/nvhe/sysreg-sr.c rename arch/arm64/kvm/hyp/{ => nvhe}/timer-sr.c (84%) rename arch/arm64/kvm/hyp/{ => nvhe}/tlb.c (55%) create mode 100644 arch/arm64/kvm/hyp/smccc_wa.S delete mode 100644 arch/arm64/kvm/hyp/switch.c create mode 100644 arch/arm64/kvm/hyp/vhe/Makefile create mode 100644 arch/arm64/kvm/hyp/vhe/debug-sr.c create mode 100644 arch/arm64/kvm/hyp/vhe/switch.c create mode 100644 arch/arm64/kvm/hyp/vhe/sysreg-sr.c create mode 100644 arch/arm64/kvm/hyp/vhe/timer-sr.c create mode 100644 arch/arm64/kvm/hyp/vhe/tlb.c -- 2.27.0