From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=91.218.175.69 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795433682; b=Z0/dP1DWF5l7EzfbYZsGBFF4WI/gXSLs7BhVh0b3RwVcY0foAAekbp4zCHtBUFrr7bZ1 J+AzVth9IXv6lWfyHVj+Q/CkuJDT7UqGLhVZZPmqlTX3gffVgfGpH66lu8pgHG8SB/REX Dyjxse1AkMn8E/kmHsmI7nMwjZkFUunfbYgvyLlufMPjbrgQV0YKf0sVAMJ8+TliT5LuL XyJYcP7fVvX5nrbsZ7QwN8Q7v6/yPf90W+Wo9s8AiWB29ZpGU0NNC5DQ5c/JfRlLymfwk mPhpnrsoV2r9yKIAmJG9bbFEGskl08UCOAZL7u7gTHPI88Hk0jDa40xTstBvUvbWhOQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795433682; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:From:To:Cc:Subject:Date:Message-ID: X-Mailer:MIME-Version:Content-Transfer-Encoding; bh=NPRhYDnwJRvicd4u9ac46NRRTHp7yf2uOQ6I7pysTOs=; b=lg8nWk9mt8bAgjbWYQVuXeNx9IaCnNBQsL3YL13V5pZ5Y7CaxU3rQxCWcMcwi+c5uugl DyKFoBwOM4fgTrJ1pXTv+5gyiO+PbJq4/RoZoMKL/14M6fHIogg9JyWyfAr3uUmJ6b5pN TSVyJ1grYMlKlwmcHMoEy5H9pINWOK3lsw1WMNmZ950UciiU1IXwyMKvJF3VIrOGTdinx nsAQTnhhoqtysfCdAkDiavO1+LHj2vE3AGT1lgH3rJu8C/upAAc29WMrR4WFevsS1q6pU VaHx3jSadTiFDHIGNSQEUU7CtyNaETt7hT1616qdFrR7eSumEPatHByIA2/LuRYHTQg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=LJyZfoTK; arc=none smtp.remote-ip=91.218.175.69 Received: from mta0.migadu.com (out-69.mta0.migadu.com [91.218.175.69]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2E045606A31A for ; Mon, 23 Nov 2026 11:34:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 2E045606A31A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=LJyZfoTK X-Envelope-To: kvm@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=sjV6qrYMC8GhJztUOTln5L8ygixllt0tnTT6CrNeYyI=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1795433680; v=1; x=1796038480; b=LJyZfoTK8ZtIYq9wmTcSMfhlUK4V/QQiyUq0/16fublnXDwgzY+bHufptb+40LP4Btx/jvBA tgXKmtXeFKVh5OcpvJu9iiFbyoBSjybXUlU/ZuYeQdOrleefE2eqzdiLKQDG/oSAAlKgTUANJKM GQzMMepdx6XCOdQtir/HYZbE= X-Envelope-To: kvm@vger.kernel.org Received: by smtp.migadu.com with ESMTPS id b141b18848b98b72; Mon, 23 Nov 2026 11:34:40 +0000 X-Mizu-Trace-ID: b141b18848b98b72 X-Migadu-Flow: FLOW_OUT From: Fuad Tabba To: Paolo Bonzini , Sean Christopherson Cc: kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Jonathan Corbet , Shuah Khan , Isaku Yamahata , Rick Edgecombe , Lorenzo Stoakes , Alexandru Elisei , Marc Zyngier , Oliver Upton , kvmarm@lists.linux.dev, Wei-Lin Chang , Anup Patel , Atish Patra , kvm-riscv@lists.infradead.org, Will Deacon , Fuad Tabba Subject: [PATCH v3 0/3] KVM: Bound KVM_PRE_FAULT_MEMORY by the vCPU's dirty ring Date: Mon, 23 Nov 2026 11:34:32 +0000 Message-ID: <20261123113435.1170711-1-fuad.tabba@linux.dev> X-Mailer: git-send-email 2.47.3 X-Mailing-List: kvm@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Hi folks, Changes since v2 [1]: - Added patch 2, which warns in api.rst against calling ioctls other than KVM_RUN while an exit is pending. (Sean) - Mentioned riscv as well as arm64 in patch 1's exit_reason paragraph. (Lorenzo) - Collected Lorenzo's Acked-by on patch 3. (thanks!) KVM_PRE_FAULT_MEMORY never checks the vCPU's dirty ring, so one call over a large enough range of populated, dirty-logged pages overflows it. The first patch stops the loop at the soft limit, as KVM_RUN does. The second warns userspace against calling ioctls other than KVM_RUN while an exit is pending. The third adds the case to pre_fault_memory_test. Pre-faulting isn't the only ioctl that can push past the ring's reserve. On x86, KVM_SET_MSRS does too when it writes the wall clock or the Hyper-V hypercall page. A guest can also push past the reserve within one exit, for example through the arm64 ITS. What those paths should do when the ring fills is an open question for the dirty ring API, which I don't think belongs in this series. I didn't include the kvm_dirty_ring_check_request() rewrite that Sean sketched on v1, since I think it can lose a request. It tests the request first and clears it afterwards. If the vCPU is scheduled out in between, loongarch sets the PV preempted flag in guest memory and x86 updates a Xen guest's runstate area, either of which pushes an entry. When that push makes the ring soft full, the request it makes is then cleared, and the vCPU runs with the ring soft full until its next push. Clearing first and re-setting, as the code does now, doesn't have that window. Based on Linux 7.4-rc2 (7475ea8b58616; also applies to kvm-x86/next cbe54fc3462b3 with git am -3). Cheers, /fuad [1] https://lore.kernel.org/all/20261117074428.7544-1-fuad.tabba@linux.dev/ Fuad Tabba (3): KVM: Stop KVM_PRE_FAULT_MEMORY when the vCPU's dirty ring is full KVM: Warn userspace against ioctls while an exit is pending KVM: selftests: Test KVM_PRE_FAULT_MEMORY against a full dirty ring Documentation/virt/kvm/api.rst | 20 ++-- include/linux/kvm_dirty_ring.h | 5 + .../selftests/kvm/pre_fault_memory_test.c | 102 ++++++++++++++++++ virt/kvm/kvm_main.c | 5 + 4 files changed, 126 insertions(+), 6 deletions(-) base-commit: 7475ea8b58616b33c04afb976cf0fbaad9dd63fb -- 2.47.3 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 8CAF1606A681 for ; Mon, 23 Nov 2026 11:34:49 +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=3bn4LVbR; dkim=fail reason="signature verification failed" (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=LJyZfoTK 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-Unsubscribe-Post:List-Owner; bh=LZtwlTHiFFoFU1uFELo+npyinXjOx7DsnYnvzC0IQjM=; b=3bn4LVbR9X3JZUw86pIUa7MP3Z 464Gop94h4SgM8Ur8cWAPj1yJYZgPRSt8eNEtZil8I5LBO93B9NmcDJql3ySmic1LadaXt3Xn2Rsg iopjwnIlQg7z9UZyX/eVjAH7kkU8dSUWxxPMxp/8F5VWmtOsgeBa/+CfF6OLMsIz8tWSwk+5jxQeq PBEzlTm1+j0CzWewyA+CfOlas8/Mt7fF1Z27AV0ZzpK0JsNSmky1ahtRxkklBbKSuuSpS2TvArlcB Q41Lq9h+ejG3R3yZ90Mn2qYk7jDAchZ4+1hH9KZk+0A3Fjwz2mNkZcKKjWmYNqO5ZOrwTVbTZjuqf CUgInAlw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xVSJs-00000003Bua-3g7e; Mon, 23 Nov 2026 11:34:49 +0000 Received: from out-113.mta1.migadu.com ([2001:41d0:203:375::71] helo=mta1.migadu.com) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xVSJm-00000003Brn-2lXn for kvm-riscv@lists.infradead.org; Mon, 23 Nov 2026 11:34:44 +0000 X-Envelope-To: kvm-riscv@lists.infradead.org DKIM-Signature: a=rsa-sha256; bh=sjV6qrYMC8GhJztUOTln5L8ygixllt0tnTT6CrNeYyI=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1795433680; v=1; x=1796038480; b=LJyZfoTK8ZtIYq9wmTcSMfhlUK4V/QQiyUq0/16fublnXDwgzY+bHufptb+40LP4Btx/jvBA tgXKmtXeFKVh5OcpvJu9iiFbyoBSjybXUlU/ZuYeQdOrleefE2eqzdiLKQDG/oSAAlKgTUANJKM GQzMMepdx6XCOdQtir/HYZbE= X-Envelope-To: kvm-riscv@lists.infradead.org Received: by smtp.migadu.com with ESMTPS id b141b18848b98b72; Mon, 23 Nov 2026 11:34:40 +0000 X-Mizu-Trace-ID: b141b18848b98b72 X-Migadu-Flow: FLOW_OUT From: Fuad Tabba To: Paolo Bonzini , Sean Christopherson Cc: kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Jonathan Corbet , Shuah Khan , Isaku Yamahata , Rick Edgecombe , Lorenzo Stoakes , Alexandru Elisei , Marc Zyngier , Oliver Upton , kvmarm@lists.linux.dev, Wei-Lin Chang , Anup Patel , Atish Patra , kvm-riscv@lists.infradead.org, Will Deacon , Fuad Tabba Subject: [PATCH v3 0/3] KVM: Bound KVM_PRE_FAULT_MEMORY by the vCPU's dirty ring Date: Mon, 23 Nov 2026 11:34:32 +0000 Message-ID: <20261123113435.1170711-1-fuad.tabba@linux.dev> X-Mailer: git-send-email 2.47.3 X-Archived-By: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261123_033442_840282_64EDA387 X-CRM114-Status: GOOD ( 14.02 ) X-Spam-Score: -2.1 (--) X-BeenThere: kvm-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "kvm-riscv" X-Spam-Status: No, score=-11.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,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 Hi folks, Changes since v2 [1]: - Added patch 2, which warns in api.rst against calling ioctls other than KVM_RUN while an exit is pending. (Sean) - Mentioned riscv as well as arm64 in patch 1's exit_reason paragraph. (Lorenzo) - Collected Lorenzo's Acked-by on patch 3. (thanks!) KVM_PRE_FAULT_MEMORY never checks the vCPU's dirty ring, so one call over a large enough range of populated, dirty-logged pages overflows it. The first patch stops the loop at the soft limit, as KVM_RUN does. The second warns userspace against calling ioctls other than KVM_RUN while an exit is pending. The third adds the case to pre_fault_memory_test. Pre-faulting isn't the only ioctl that can push past the ring's reserve. On x86, KVM_SET_MSRS does too when it writes the wall clock or the Hyper-V hypercall page. A guest can also push past the reserve within one exit, for example through the arm64 ITS. What those paths should do when the ring fills is an open question for the dirty ring API, which I don't think belongs in this series. I didn't include the kvm_dirty_ring_check_request() rewrite that Sean sketched on v1, since I think it can lose a request. It tests the request first and clears it afterwards. If the vCPU is scheduled out in between, loongarch sets the PV preempted flag in guest memory and x86 updates a Xen guest's runstate area, either of which pushes an entry. When that push makes the ring soft full, the request it makes is then cleared, and the vCPU runs with the ring soft full until its next push. Clearing first and re-setting, as the code does now, doesn't have that window. Based on Linux 7.4-rc2 (7475ea8b58616; also applies to kvm-x86/next cbe54fc3462b3 with git am -3). Cheers, /fuad [1] https://lore.kernel.org/all/20261117074428.7544-1-fuad.tabba@linux.dev/ Fuad Tabba (3): KVM: Stop KVM_PRE_FAULT_MEMORY when the vCPU's dirty ring is full KVM: Warn userspace against ioctls while an exit is pending KVM: selftests: Test KVM_PRE_FAULT_MEMORY against a full dirty ring Documentation/virt/kvm/api.rst | 20 ++-- include/linux/kvm_dirty_ring.h | 5 + .../selftests/kvm/pre_fault_memory_test.c | 102 ++++++++++++++++++ virt/kvm/kvm_main.c | 5 + 4 files changed, 126 insertions(+), 6 deletions(-) base-commit: 7475ea8b58616b33c04afb976cf0fbaad9dd63fb -- 2.47.3 -- kvm-riscv mailing list kvm-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/kvm-riscv