From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796088588; b=D+fyng24K/SRUAkhhEt79JLPSIYMl3t7UJ4sqjrb/VkDeI/WnIB4tvl90pqLBq3IKLb0 Bjn/BPEWJSd1UbMZewTt8LlV8XS2MH3qZxg0j2G+LCMKo/l0kyMBsHt52OWJ/FmuPQRp4 xmATj9LGA1clE518e9EkoCDJi8/GrpDqeLAwcZ8phHHWMKSZ0cmY0wvlxda56cxNzl8c4 4I8oBmKiGvslrHqyMuN23gvpEFUvHnSgTMAyzFl1bdfWsjucbAgNEUYvX8UKzr05EmGp4 Xzm5zq9jE0VmxpXhCwofPoJ19Vy9ucQTVKEX2D2N9PKAG5gKblNEHzbbJPK9oCDnUoQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796088588; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=XB4uUtuz5TCllSNmudU5XeUIx/Qp9CyxUap+xRB8ACc=; b=mkfhvP/YrRDqRvEtWjORMAj3F4yFxPQCkV7YlL8pcChYMZb1R1rTF2q38/8vfl01kR4f zYsFXg2Lk2eBRDaLHonVhkDjVP/0K4mnBKkErLIrg3p8+7mqyugs30fO7kxWRE6AZzyqm IdP6MpUsTYnuywChN5QMdMmHqShsjA6xAfQxszQm4NbwpcQsBSe3nfDBV346woQykiyTM khqk3oETxGCX773DQgwtApUWY5GnX6U/yBf2fkLomY3SNl7Y28w2DMgfZ7kihFZlx1ZvH H5I9mGS5l0cfn+1tjShhm75EvgsXgQ5vrPN/OMRNEvxNZsQszG4oAiPvqK7yvC5fuWw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=akTcCmYG; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 810ED606A31A for ; Tue, 1 Dec 2026 01:29:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=akTcCmYG Received: by smtp.kernel.org (Postfix) with ESMTPSA id 16F891F00897; Tue, 1 Dec 2026 01:29:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796088588; bh=XB4uUtuz5TCllSNmudU5XeUIx/Qp9CyxUap+xRB8ACc=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=akTcCmYGaGPzZUn2ToLdI6S/o8yyKsfWsRjZA7BcZ1XJdkmWKgPEEJNeq0biZhXn6 RBTUZyW3/qupFRZcKuf4BEsosYNWTQa5jLsQrXA9Nrna33Mq8zk/pMY5j9PVQee9yu zPhnXhDftiHCzy2xthOaga9eXfFKn0v2PypZOnKvwkj3ySUIjg8Aedqr4jgv181SFC ljaghPVZSg/FbAg1oa36dE3kdK3qYaYt/Tw002Z9WV2w2tqHtUefn2DumpwG+piJqD KeuJ6OoxbERO1rlnoCHe7TfU1Xz2AvoQdnd8Tavyh/Ftc8Z7kIjmA+pQZ9NFR2Ztsy u8EaLZdXzDlfQ== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH] KVM: Fix kvm_range_has_memory_attributes() for a zero mask Reply-To: sashiko-reviews@lists.linux.dev To: liuqiangneo@163.com Cc: kvm@vger.kernel.org In-Reply-To: <20261201012137.12592-1-liuqiangneo@163.com> References: <20261201012137.12592-1-liuqiangneo@163.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Tue, 01 Dec 2026 01:29:47 +0000 X-Mailing-List: kvm@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found no new issues in this patch, but noticed 1 related pre-existing issue it does not introduce: - [Critical] KVM: x86/mmu: soft lockup in kvm_mmu_init_memslot_memory_attributes() [1] -- commit 26d303ac2ea9b5803694f4100f1c929f14b5809e Author: Qiang Liu KVM: Fix kvm_range_has_memory_attributes() for a zero mask This commit skips the xarray index check in kvm_range_has_vm_memory_attributes() when attrs is 0 so that holes skipped by xas_next_entry() are not rejected when mask is 0. > diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c > index 5a1a59d57e0b1..5367804209a2c 100644 > --- a/virt/kvm/kvm_main.c > +++ b/virt/kvm/kvm_main.c > @@ -2567,7 +2567,13 @@ bool kvm_range_has_vm_memory_attributes(struct kvm= *kvm, gfn_t start, gfn_t end, > =20 > WARN_ON_ONCE(!xa_to_value(entry)); > =20 > - if (xas.xa_index !=3D index || > + /* > + * With @attrs =3D=3D 0, xas_next_entry() can land past @index. > + * Skipped holes and reserved entries match; only real entries > + * with bits in @mask set are rejected. Checking index wrongly > + * rejects holes when @mask is 0. > + */ > + if ((attrs && xas.xa_index !=3D index) || > (xa_to_value(entry) & mask) !=3D attrs) > return false; > } [Severity: Critical] This problem wasn't introduced by this patch, but can scanning a large memslot with non-zero attributes trigger CPU soft lockups and RCU stalls [1]? When initializing memory attributes for a memslot, kvm_mmu_init_memslot_memory_attributes() loops over every potential hugepage and calls hugepage_has_attrs() -> kvm_range_has_vm_memory_attributes(), which walks every 4K gfn via xas_next() when attrs is non-zero: arch/x86/kvm/mmu/mmu.c:kvm_mmu_init_memslot_memory_attributes() { ... for (level =3D PG_LEVEL_2M; level <=3D KVM_MAX_HUGEPAGE_LEVEL; level++) { ... for (gfn =3D start; gfn < end; gfn +=3D nr_pages) { unsigned long attrs =3D kvm_get_vm_memory_attributes(kvm, gfn); if (hugepage_has_attrs(kvm, slot, gfn, level, attrs)) hugepage_clear_mixed(slot, gfn, level); ... } Neither the outer hugepage loop in kvm_mmu_init_memslot_memory_attributes() nor this inner xarray loop yields with cond_resched(), so initializing a large memslot runs through millions of pages without rescheduling. [1] https://sashiko.dev/#/bug/linux-6205ce47-c25f-4976-b384-7c6b88c376d3 --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261201012137.1259= 2-1-liuqiangneo@163.com?part=3D1