From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 04A27606A33A for ; Fri, 4 Dec 2026 09:09:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=3+ncl39b; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=foss header.b=t7O/pS5i DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Unsubscribe-Post:List-Owner; bh=Dqf3TZ9MTZmDfVeH0LaZfe00JbwVICL7gv+2YdLjrv8=; b=3+ncl39b1T0brD9cF+DMyG3vLn mwf9FR22g3NlZoVjEXrwuiLPlfjPvaxjdo9ciFAsvLdN6SBcYmHPgFeZCytta5OffPwcyrPj7wCHN +uZN772Uv+Z2C7vUTj6M5puidHU3JfUbZoWP13/AG/MWFxsyxmwHJ9YLaEZMw4qK5OPvclsWTqXhd jo6J7SphVjfQztCjPQRGjPD3TDOcGEPIxq/+Ka6kt9AwMWkIofbnufdx+Yb0ouhDubz8UjG0RHuqY Fc7GYgCyjzTW073HY0bLJ+any2MFed7SM7Oqc2+5gc+Kf7v7JgcsBpN1NxITSOWo3hyO0OHEVRI34 fZbQ3mDg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xZPIS-0000000HISk-20Mb; Fri, 04 Dec 2026 09:09:42 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xZPII-0000000HIQq-2m5C for linux-arm-kernel@lists.infradead.org; Fri, 04 Dec 2026 09:09:36 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 7A8BA14BF; Fri, 4 Dec 2026 01:09:26 -0800 (PST) Received: from entos-yitian-01.Arm.com (unknown [10.168.196.233]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 9B4603F632; Fri, 4 Dec 2026 01:09:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1796375369; bh=VHHa3b8JfR9bou5aBWqoOGruS1FpiCmn352lEMjc928=; h=From:To:Cc:Subject:Date:From; b=t7O/pS5iiZ3hQ0+WarESXXT1xaYggWLuaoXjXfLwc6eTP9USGlUdEO7vtU7e2C4jr Cryp7sNdhzN/oXfLTxakUjJnXij8Gi4V7tCc++5ZJKyorZIhPL7zS3fdoJUXlb6YX3 3bHc0bjYkjhJ6VzPobCGMiUov5F6hTl7y9mrpHRQ= From: Jia He To: Marc Zyngier , Oliver Upton , Fuad Tabba Cc: Jia He , Joey Gouly , Steffen Eiden , Suzuki K Poulose , Zenghui Yu , Catalin Marinas , Will Deacon , Mark Rutland , Paolo Bonzini , Sean Christopherson , Shuah Khan , Sascha Bischoff , Lorenzo Stoakes , Dan Carpenter , Yao Yuan , linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH v2 0/2] KVM: arm64: Don't load hardware vCPU state before first run Date: Fri, 4 Dec 2026 09:09:12 +0000 Message-Id: <20261204090914.459990-1-justin.he@arm.com> X-Mailer: git-send-email 2.34.1 X-Archived-By: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261204_010935_354659_6B95F863 X-CRM114-Status: UNSURE ( 8.54 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -4.4 (----) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" X-Spam-Status: No, score=-14.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 KVM_PRE_FAULT_MEMORY and KVM_SET_VCPU_EVENTS call vcpu_load() before the first KVM_RUN, while arm64 only finalises VM and vCPU state on the first KVM_RUN. On NV, this lets userspace queue KVM_REQ_MAP_L1_VNCR_EL2 without a vncr_tlb and dereference NULL in kvm_map_l1_vncr() on the first KVM_RUN. With 5651590be08a ("KVM: arm64: Load the vcpu in KVM_SET_VCPU_EVENTS"), an all-zero KVM_SET_VCPU_EVENTS before the first KVM_RUN is enough, even with pre-faulting disabled. Patch 1 skips the arch vcpu_load()/vcpu_put() callbacks until the vCPU has run once, and switches VHE enter_vmid_context() to __hyp_running_vcpu. Patch 2 extends nv_pre_fault_memory_test. KVM_SET_VCPU_EVENTS before the first run still evaluates injection against unfinalised state; that is left for a separate change. Tested on a Neoverse-N2 host (with lockdep enabled): - With pre-faulting disabled, an all-zero KVM_SET_VCPU_EVENTS before the first KVM_RUN reproduces the NULL vncr_tlb dereference. - With this series applied, neither KVM_PRE_FAULT_MEMORY nor KVM_SET_VCPU_EVENTS triggers the oops (10 runs each), and nv_pre_fault_memory_test passes. Based on kvmarm/fixes (kvmarm-fixes-7.4-3). Changes since v1: - Rebased on kvmarm/fixes. - Patch 1: cover KVM_SET_VCPU_EVENTS as well. - Patch 1: keep the VHE enter_vmid_context() change and explain the MMU notifier/reclaim case (Marc, Lorenzo). - Patch 1: drop the vgic_maintenance_handler() change (Marc, Lorenzo). - Patch 1: tighten commit message and move test notes to cover letter. - Drop v1 patch 2 (Marc). - Patch 2: list the test cases in the commit message, fix two comments and a message (Yao Yuan). v1: https://lore.kernel.org/r/20261123150917.2679600-1-justin.he@arm.com Jia He (2): KVM: arm64: Don't load hardware vCPU state before first run KVM: selftests: arm64: Test KVM_PRE_FAULT_MEMORY before first KVM_RUN arch/arm64/kvm/arm.c | 17 +- arch/arm64/kvm/hyp/vhe/tlb.c | 3 +- .../kvm/arm64/nv_pre_fault_memory_test.c | 338 ++++++++++++++++-- 3 files changed, 318 insertions(+), 40 deletions(-) -- 2.34.1