From patchwork Fri Apr 21 10:40:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Zyngier X-Patchwork-Id: 1771845 Return-Path: X-Original-To: incoming-imx@patchwork.ozlabs.org Delivered-To: patchwork-incoming-imx@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=linux-arm-kernel-bounces+incoming-imx=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=SwKcD51R; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=infradead.org header.i=@infradead.org header.a=rsa-sha256 header.s=desiato.20200630 header.b=UFpRwzTt; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=VP4qOS+o; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Q2syX6CHfz23td for ; Fri, 21 Apr 2023 21:40:04 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :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=Y/xe8XCU+Eb8kqZI0ZVupttb3JBPa6nfwCFuiSoSCV8=; b=SwKcD51R8fD6Kz bJ/Bx8CIiHBz91DGuUgJTNBi0zCnKSkIuh/e2MeSf+kTVwotF0TsHCLHloSZUdRKnVFtWm7o101Qb 7tMJDSY14kcRrTs7WBh3ghdJDFaotsKeWVSfUdjdcYheEELxZu7/osaOU3g/PVGGNx0w7Zi7fHrp/ w4ZhN7lVp3nmmdmG+7gRABfVzI+5n0S5LpSg7RUZK2sIo2SE5npBqMSg/2b4pDhexENY6mpMABln+ E7bXq6U3ZuY1I8p/peJ89gIjjN5HgyasqkCUFk/WqS9v3nB/5vRCN6vw4EViiSE/6J+H844WlgIN8 IHKyFXWtjUIAHtI2eU3w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1ppp7K-00Ajwq-1l; Fri, 21 Apr 2023 11:39:54 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1ppp7I-00Ajw0-2K for linux-arm-kernel@bombadil.infradead.org; Fri, 21 Apr 2023 11:39:52 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:MIME-Version :Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:In-Reply-To:References; bh=FaEl69t8lMy4I6/E5MA/tTa8Fqths8rdGFHvYSSKO2E=; b=UFpRwzTtR3q7qIssJM8z5BunZ9 fOUBN5aXgPLR4LP/UZWBpZlAWhDV65ilgW0qbSXQzV6vOYm6iklSEQgOOb7aQVr+kVVCc4m/+tK1G rEKWwraXlq/ncBZZmTkwDZ9BCw29sFDnsjun3fOzfaZOncFrwm7lP2FPLa8c7vzpU6pBcaVFlecpO u+rdm/cztamZ7ATFqxt3jK8beDjHtWzhqqPD/d5MTCA4gzdxhwEFZAAURy91ihute0rtwSP4u1FFc E399R/tqZap28G8zVguZa48nyrFxDW2utPdAz0wndVh7zH2IBz5s6zeg4KONxU8+hWrAP+BPc8iVC Pf7KByQQ==; Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by desiato.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1ppoBj-005GEF-1F for linux-arm-kernel@lists.infradead.org; Fri, 21 Apr 2023 10:40:25 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 27BE261701; Fri, 21 Apr 2023 10:40:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 663F2C433EF; Fri, 21 Apr 2023 10:40:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1682073616; bh=f54QJY5K8mTuwzMvRZL1+NpMfvBNMm/MjfsZ4+NoQoE=; h=From:To:Cc:Subject:Date:From; b=VP4qOS+ovkzE2fmFjLtlvdi6QqRnjDZU86UAt4XRif0RIZLBkISSmQ3hUX+5qhDFp q0sG0eAwMs6da8otU1sI64Zfqq2sCWy4uJg71V0iOk0BHaNl/mVqKWzcq/9BVTh9AY C5auvXr4bokF/MOM0LRWSZ+ug/zrShz0zUqaZvXu/hk3VPSQ6ns4wx9u2UKn5khht+ XtagEKqs7WhytoqUHy/g1e6Oli81xHy0rDY68BuDsyfU2hz0DVEWdiq1mjyr2udn9t MWmccEtnz80uKXZqTdYWjkYcxztPQs5F1nULvelgBRHMtMq+gDb7Ex+Cka99pWO+ni o8jKCvQsVyy3A== Received: from sofa.misterjones.org ([185.219.108.64] helo=valley-girl.lan) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1ppoBa-00A96s-2s; Fri, 21 Apr 2023 11:40:14 +0100 From: Marc Zyngier To: Paolo Bonzini Cc: Christoffer Dall , Colin Ian King , Colton Lewis , Jeremy Linton , Mark Brown , Oliver Upton , Reiji Watanabe , Ryan Roberts , Sean Christopherson , Suzuki K Poulose , James Morse , Zenghui Yu , kvmarm@lists.linux.dev, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [GIT PULL] KVM/arm64 updates for v6.4 Date: Fri, 21 Apr 2023 11:40:05 +0100 Message-Id: <20230421104005.3017731-1-maz@kernel.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: pbonzini@redhat.com, christoffer.dall@arm.com, colin.i.king@gmail.com, coltonlewis@google.com, jeremy.linton@arm.com, broonie@kernel.org, oliver.upton@linux.dev, reijiw@google.com, ryan.roberts@arm.com, seanjc@google.com, suzuki.poulose@arm.com, james.morse@arm.com, yuzenghui@huawei.com, kvmarm@lists.linux.dev, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230421_114023_845083_A306E275 X-CRM114-Status: GOOD ( 23.66 ) X-Spam-Score: -2.5 (--) X-Spam-Report: Spam detection software, running on the system "desiato.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Hi Paolo, Here's the initial set of changes for KVM/arm64. A bunch of infrastructure changes this time around, with two new user visible changes (hypercall forwarding to userspace, global counter offset) and a [...] Content analysis details: (-2.5 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [2604:1380:4641:c500:0:0:0:1 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.0 DKIMWL_WL_HIGH DKIMwl.org - High trust sender X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+incoming-imx=patchwork.ozlabs.org@lists.infradead.org Hi Paolo, Here's the initial set of changes for KVM/arm64. A bunch of infrastructure changes this time around, with two new user visible changes (hypercall forwarding to userspace, global counter offset) and a large set of locking inversion fixes. The remaining of the patches contain the NV timer emulation code, and a small set of less important fixes/improvements. Please pull, M. The following changes since commit 197b6b60ae7bc51dd0814953c562833143b292aa: Linux 6.3-rc4 (2023-03-26 14:40:20 -0700) are available in the Git repository at: git://git.kernel.org/pub/scm/linux/kernel/git/kvmarm/kvmarm.git tags/kvmarm-6.4 for you to fetch changes up to 36fe1b29b3cae48f781011abd5a0b9e938f5b35f: Merge branch kvm-arm64/spec-ptw into kvmarm-master/next (2023-04-21 09:44:58 +0100) ---------------------------------------------------------------- KVM/arm64 updates for 6.4 - Numerous fixes for the pathological lock inversion issue that plagued KVM/arm64 since... forever. - New framework allowing SMCCC-compliant hypercalls to be forwarded to userspace, hopefully paving the way for some more features being moved to VMMs rather than be implemented in the kernel. - Large rework of the timer code to allow a VM-wide offset to be applied to both virtual and physical counters as well as a per-timer, per-vcpu offset that complements the global one. This last part allows the NV timer code to be implemented on top. - A small set of fixes to make sure that we don't change anything affecting the EL1&0 translation regime just after having having taken an exception to EL2 until we have executed a DSB. This ensures that speculative walks started in EL1&0 have completed. - The usual selftest fixes and improvements. ---------------------------------------------------------------- Colin Ian King (1): KVM: selftests: Fix spelling mistake "KVM_HYPERCAL_EXIT_SMC" -> "KVM_HYPERCALL_EXIT_SMC" Marc Zyngier (33): KVM: arm64: timers: Use a per-vcpu, per-timer accumulator for fractional ns arm64: Add CNTPOFF_EL2 register definition arm64: Add HAS_ECV_CNTPOFF capability KVM: arm64: timers: Use CNTPOFF_EL2 to offset the physical timer KVM: arm64: timers: Allow physical offset without CNTPOFF_EL2 KVM: arm64: Expose {un,}lock_all_vcpus() to the rest of KVM KVM: arm64: timers: Allow userspace to set the global counter offset KVM: arm64: timers: Allow save/restoring of the physical timer KVM: arm64: timers: Rationalise per-vcpu timer init KVM: arm64: timers: Abstract per-timer IRQ access KVM: arm64: timers: Move the timer IRQs into arch_timer_vm_data KVM: arm64: Elide kern_hyp_va() in VHE-specific parts of the hypervisor KVM: arm64: timers: Fast-track CNTPCT_EL0 trap handling KVM: arm64: timers: Abstract the number of valid timers per vcpu KVM: arm64: Document KVM_ARM_SET_CNT_OFFSETS and co KVM: arm64: nv: timers: Add a per-timer, per-vcpu offset KVM: arm64: nv: timers: Support hyp timer emulation KVM: arm64: selftests: Add physical timer registers to the sysreg list KVM: arm64: selftests: Deal with spurious timer interrupts KVM: arm64: selftests: Augment existing timer test to handle variable offset KVM: arm64: Expose SMC/HVC width to userspace KVM: arm64: nvhe: Synchronise with page table walker on vcpu run KVM: arm64: Handle 32bit CNTPCTSS traps KVM: arm64: nvhe: Synchronise with page table walker on TLBI KVM: arm64: pkvm: Document the side effects of kvm_flush_dcache_to_poc() KVM: arm64: vhe: Synchronise with page table walker on MMU update KVM: arm64: vhe: Drop extra isb() on guest exit Merge branch kvm-arm64/lock-inversion into kvmarm-master/next Merge branch kvm-arm64/timer-vm-offsets into kvmarm-master/next Merge branch kvm-arm64/selftest/lpa into kvmarm-master/next Merge branch kvm-arm64/selftest/misc-6.4 into kvmarm-master/next Merge branch kvm-arm64/smccc-filtering into kvmarm-master/next Merge branch kvm-arm64/spec-ptw into kvmarm-master/next Mark Brown (1): KVM: selftests: Comment newly defined aarch64 ID registers Oliver Upton (20): KVM: arm64: Avoid vcpu->mutex v. kvm->lock inversion in CPU_ON KVM: arm64: Avoid lock inversion when setting the VM register width KVM: arm64: Use config_lock to protect data ordered against KVM_RUN KVM: arm64: Use config_lock to protect vgic state KVM: x86: Redefine 'longmode' as a flag for KVM_EXIT_HYPERCALL KVM: arm64: Add a helper to check if a VM has ran once KVM: arm64: Add vm fd device attribute accessors KVM: arm64: Rename SMC/HVC call handler to reflect reality KVM: arm64: Start handling SMCs from EL1 KVM: arm64: Refactor hvc filtering to support different actions KVM: arm64: Use a maple tree to represent the SMCCC filter KVM: arm64: Add support for KVM_EXIT_HYPERCALL KVM: arm64: Introduce support for userspace SMCCC filtering KVM: arm64: Return NOT_SUPPORTED to guest for unknown PSCI version KVM: arm64: Let errors from SMCCC emulation to reach userspace KVM: selftests: Add a helper for SMCCC calls with SMC instruction KVM: selftests: Add test for SMCCC filter KVM: arm64: Prevent userspace from handling SMC64 arch range KVM: arm64: Test that SMC64 arch calls are reserved KVM: arm64: vgic: Don't acquire its_lock before config_lock Reiji Watanabe (2): KVM: arm64: Acquire mp_state_lock in kvm_arch_vcpu_ioctl_vcpu_init() KVM: arm64: Have kvm_psci_vcpu_on() use WRITE_ONCE() to update mp_state Ryan Roberts (3): KVM: selftests: Fixup config fragment for access_tracking_perf_test KVM: selftests: arm64: Fix pte encode/decode for PA bits > 48 KVM: selftests: arm64: Fix ttbr0_el1 encoding for PA bits > 48 Documentation/virt/kvm/api.rst | 71 ++- Documentation/virt/kvm/devices/vm.rst | 79 +++ arch/arm64/include/asm/kvm_host.h | 25 +- arch/arm64/include/asm/kvm_mmu.h | 4 + arch/arm64/include/asm/sysreg.h | 3 + arch/arm64/include/uapi/asm/kvm.h | 36 ++ arch/arm64/kernel/cpufeature.c | 11 + arch/arm64/kvm/arch_timer.c | 550 ++++++++++++++++----- arch/arm64/kvm/arm.c | 147 +++++- arch/arm64/kvm/guest.c | 31 +- arch/arm64/kvm/handle_exit.c | 36 +- arch/arm64/kvm/hyp/include/hyp/switch.h | 53 ++ arch/arm64/kvm/hyp/nvhe/debug-sr.c | 2 - arch/arm64/kvm/hyp/nvhe/mem_protect.c | 7 + arch/arm64/kvm/hyp/nvhe/switch.c | 18 + arch/arm64/kvm/hyp/nvhe/timer-sr.c | 18 +- arch/arm64/kvm/hyp/nvhe/tlb.c | 38 +- arch/arm64/kvm/hyp/vhe/switch.c | 7 +- arch/arm64/kvm/hyp/vhe/sysreg-sr.c | 12 + arch/arm64/kvm/hypercalls.c | 189 ++++++- arch/arm64/kvm/pmu-emul.c | 25 +- arch/arm64/kvm/psci.c | 37 +- arch/arm64/kvm/reset.c | 15 +- arch/arm64/kvm/sys_regs.c | 10 + arch/arm64/kvm/trace_arm.h | 6 +- arch/arm64/kvm/vgic/vgic-debug.c | 8 +- arch/arm64/kvm/vgic/vgic-init.c | 36 +- arch/arm64/kvm/vgic/vgic-its.c | 33 +- arch/arm64/kvm/vgic/vgic-kvm-device.c | 85 ++-- arch/arm64/kvm/vgic/vgic-mmio-v3.c | 4 +- arch/arm64/kvm/vgic/vgic-mmio.c | 12 +- arch/arm64/kvm/vgic/vgic-v4.c | 11 +- arch/arm64/kvm/vgic/vgic.c | 27 +- arch/arm64/kvm/vgic/vgic.h | 3 - arch/arm64/tools/cpucaps | 1 + arch/arm64/tools/sysreg | 4 + arch/x86/include/asm/kvm_host.h | 7 + arch/x86/include/uapi/asm/kvm.h | 3 + arch/x86/kvm/x86.c | 6 +- include/clocksource/arm_arch_timer.h | 1 + include/kvm/arm_arch_timer.h | 34 +- include/kvm/arm_hypercalls.h | 6 +- include/kvm/arm_vgic.h | 1 + include/uapi/linux/kvm.h | 12 +- tools/testing/selftests/kvm/Makefile | 1 + tools/testing/selftests/kvm/aarch64/arch_timer.c | 56 ++- tools/testing/selftests/kvm/aarch64/get-reg-list.c | 15 +- tools/testing/selftests/kvm/aarch64/smccc_filter.c | 268 ++++++++++ tools/testing/selftests/kvm/config | 1 + .../selftests/kvm/include/aarch64/processor.h | 13 + .../testing/selftests/kvm/lib/aarch64/processor.c | 91 ++-- 51 files changed, 1759 insertions(+), 410 deletions(-) create mode 100644 tools/testing/selftests/kvm/aarch64/smccc_filter.c