From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qk1-f181.google.com (mail-qk1-f181.google.com [209.85.222.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C42B972602 for ; Mon, 28 Sep 2026 13:30:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790602226; cv=none; b=UuSUT2/Fkk7WXXd3cjwcNBEQMS6BALoqD5M78+a0XWlyYgOqJcl/s8CYK0cyZnmVdnu+y5tOJL0FK9h9VTBpID1YXW0WBu6yEjv/JNB3K8du/AyLC1TH5XPMM2XyPM/cmEvEyP3173U7rNtS3nMrEdBC2spBCQ9cwK328nZG0kM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790602226; c=relaxed/simple; bh=u4F+lc3vx+jYByWGzH3MQLi5+iszxVz9Dw6kvDqbkF0=; h=From:To:Cc:Subject:In-Reply-To:Date:Message-ID:References: MIME-version:Content-type; b=Rp1te07SRlwOxxXPKn/+KuyRwxdOjFvY3bXMvtr0YbHA+K+2S71fjoqro8Eytxoz0VsK2OG5VCaWKv+E1do1rjIyYyMP3kh5G1k4ow8W0z4IcgvhXe1cv9f42UrdyDJJuZ39aS8JJdxMjmpMiR+7At5Divc1ePl6SKmMVEoLVOA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=j2wNPCkI; arc=none smtp.client-ip=209.85.222.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="j2wNPCkI" Received: by mail-qk1-f181.google.com with SMTP id af79cd13be357-93c7014af8eso104094185a.0 for ; Mon, 28 Sep 2026 06:30:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1790602223; x=1791207023; darn=vger.kernel.org; h=content-transfer-encoding:content-type:mime-version:references :message-id:date:in-reply-to:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to:content-type; bh=Xh2NHRfJCMfylFQd8bfgqsz1kSEX8TvOZMy0ZzkkjyY=; b=j2wNPCkIPr9VY64Ou+l1UKH4JEasIeLDhfuXps5KjDziKY0MBhMwSMBkLujCyyIeqh +IR/kE5K5ihWxaz2uuAQ1Zuek69IUSrvE4+xVFUKbOyZX7YLpvyKJglloMPSaZv4AnAG bQKxDS7tzeANVycaCJm+qgI5oQt0c1/1wacosE5hQIh+bhhHMc2quSBhq1sBcAGWMk5l 6c8k8MOgM6pYRd0ZA2VRzi2Q1+u2/eKp44pVtkz2/xiXwDARznEM2FSLGzzOfbdCIw47 wl2Vz4Qc4KYx+eIafnaLoKEqUVcUHWeYaiEhSyWQscYqnDizWF+zjvZgqp4VKxdeK4Zq w5fg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790602223; x=1791207023; h=content-transfer-encoding:content-type:mime-version:references :message-id:date:in-reply-to:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=Xh2NHRfJCMfylFQd8bfgqsz1kSEX8TvOZMy0ZzkkjyY=; b=nJ9mZQvDqx5LJyIgVsYAD+UMf9t+1tF4mVYh+QbE0lYngzbeL4naLkP6vLsGrGMai0 6rFu3D4B7YT8qui/3l8WRNs3gc6phWQk3vn7MX90tPoft1mxAC+QUsYtsAINmdfrutiM G0D07VLuyWv7zIgacU+igRqjXef4/MDZoubvgjFz/rmRV9euR4oxi1RY8QoyT6Oip1xY mZ0zilmXjmnf7GJaKw8tdxIMBk0+NEc6047n2UUINNFnPBXEautR0Fy/5s+v5mi4J/6q +6CgxoiKmzbcmmEBDPSzg7XdzyZLcvWBoGKGBB08vqmJTI8OmtCg8TrTIoUnAgkfm6mb TQXA== X-Forwarded-Encrypted: i=1; AKwUvBxbFZ3hq7TzKJbqF/YMekPzOWrtv4ztso0wb7By/bkECknM31TtVz8gYtIfbgQEWm5Nk6jG5c6r0jyS6Zs=@vger.kernel.org X-Gm-Message-State: AFuF++l9bU0kwIbFOC0iH9LbxTz0oKrBZvB9gv+lrAT7q2xSNw1fmC+V hSH4t+ThqdxDx7fQe6/svCtDf5UQ8GiIbPD3XArCD+8216anBTW9n4Mq X-Gm-Gg: AYBFou1rXtGG5gLukwAj/f/iGsYOkNGFCLtY0LbDnsePzGZJYMj4I2zgE92C+cTjLp9 c9N5kWPNeoYqwcI9rUHig8vs/daseeFNBv9+fM65cq/c7/0HMEq0ArdQAow8Qoxjzt2SU4iVKVH xJKf9Z80wqH+yUsfUgA22Kn5Cbn7SDL/Cf8EKTsGP8+2vj4f2gsEi8nQ5RpNUtl061FklgubBnf q+eIUHVvF3scOdWlnbAlA9BDPnlSP4qV2kcjL6eM5nIsHoauUIKV+df3YFJ3qeCqktHQaaY4hYV Pb8LUjPWFRp75zDnYANcM6oGTY6OdDx71aVDx+eOCX2aG8Whdbp7IHZMTWCfkCgmC/me8iT7ecv VUzgZ7W0F+006gxvSRJLEzEYnBXdHJSvFYTOPKl/hDvcstTp6bgNvGB77eyxtVDB1NAPSPTA4et fnybWJ7hw3+zm9jdi8vM785BunB6W1gMRCTKVsuYfGVEtU3oMzrxQT0owWvzwiay12awuA+kUBS vH9fbbBd/DOZrpKBgRcvCOQ58LID4oqWQIsWzO1ZzrnkhaH5ebh/w== X-Received: by 2002:a05:620a:2888:b0:93a:ea:b00e with SMTP id af79cd13be357-93c43d9e0eemr2013943785a.30.1790602206503; Mon, 28 Sep 2026 06:30:06 -0700 (PDT) Received: from pve-server ([49.205.216.49]) by smtp.gmail.com with ESMTPSA id af79cd13be357-93c813a443fsm151650285a.12.2026.09.28.06.29.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Sep 2026 06:30:05 -0700 (PDT) From: Ritesh Harjani (IBM) To: Amit Machhiwal , Madhavan Srinivasan , linuxppc-dev@lists.ozlabs.org Cc: Amit Machhiwal , Nicholas Piggin , Michael Ellerman , "Christophe Leroy (CS GROUP)" , Shrikanth Hegde , kvm-ppc@vger.kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Gautam Menghani , Harsh Prateek Bora , R Nageswara Sastry , Alexander Graf , linux-hardening@vger.kernel.org, stable@vger.kernel.org, Avi Kivity Subject: Re: [RESEND PATCH 1/3] KVM: PPC: Book3S HV: Add SRCU protection for virtual-mode HPT hcalls In-Reply-To: <20260928122837.8782-2-amachhiw@linux.ibm.com> Date: Mon, 28 Sep 2026 18:57:16 +0530 Message-ID: References: <20260928122837.8782-1-amachhiw@linux.ibm.com> <20260928122837.8782-2-amachhiw@linux.ibm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-version: 1.0 Content-type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Amit Machhiwal writes: > The virtual-mode HPT hcall handlers (H_ENTER, H_REMOVE, H_BULK_REMOVE, > H_CLEAR_REF, H_CLEAR_MOD) call into book3s_hv_rm_mmu.c, which accesses > memslots via kvm_memslots_raw(). kvm_memslots_raw() uses > rcu_dereference_raw_check() to bypass SRCU lockdep annotation checking. > This is safe in real mode because the entire guest entry/exit is wrapped > in srcu_read_lock/unlock inside kvmppc_run_core() and > kvmhv_run_single_vcpu(). > > However, since commit 6165d5dd99db ("KVM: PPC: Book3S HV: add virtual > mode handlers for HPT hcalls and page faults"), these same handlers are > also executed in virtual mode via kvmppc_pseries_do_hcall(), which runs > after SRCU has already been released on guest exit. > > A concurrent KVM_SET_USER_MEMORY_REGION deletion or move can therefore > call synchronize_srcu_expedited() — which does not wait for this thread — > and then kfree(slot) and vfree(slot->arch.rmap) while the hcall handler > still holds a raw pointer to the memslot. lock_rmap() then writes to > freed vmalloc memory, leading to use-after-free and memory corruption. > Because kvm_memslots_raw() suppresses lockdep checks, this race is > entirely silent. > > Fix this by factoring out the 7 HPT hcall handlers (H_REMOVE, H_ENTER, > H_READ, H_CLEAR_MOD, H_CLEAR_REF, H_PROTECT, H_BULK_REMOVE) into a > helper function, kvmppc_pseries_do_hpt_hcall(), and wrapping its call > site in srcu_read_lock(&kvm->srcu) / srcu_read_unlock(&kvm->srcu, idx). > Targeting only the HPT hcalls avoids wrapping non-HPT hcalls that sleep > (such as H_CONFER, H_REGISTER_VPA, H_PAGE_INIT) or handlers that already > acquire SRCU internally (such as H_RTAS). > > Fixes: 6165d5dd99db ("KVM: PPC: Book3S HV: add virtual mode handlers for HPT hcalls and page faults") > Cc: stable@vger.kernel.org # v5.14+ > Suggested-by: Ritesh Harjani (IBM) > Signed-off-by: Amit Machhiwal > --- > arch/powerpc/kvm/book3s_hv.c | 70 ++++++++++++++++++------------------ > 1 file changed, 35 insertions(+), 35 deletions(-) I had looked at this path in depth earlier itself. LGTM. Please feel free to add: Reviewed-by: Ritesh Harjani (IBM)