From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=95.215.58.143 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794901475; b=I5XzuboU66/fXYlgYUTocPY6GJ+Gn8Q42C1k8wNU5yRG8NHUn5NrqBWFiYk8XtfEgMv/ 82gFRGuHF3VROmpo/MGuUVvMQFuT3XbwfeYOTTtPGfYOPFwqHp9Da/UnrUQuly9NUMD+T ZVgVPlgtbKN6K45R63luy6zETI5oHcynwcG6SdDYnAtAEi1uLNpvWSjassQ57FoG82y8B VUHYnH9TFhmf0DoNVgYpN/x6wxPk99igLR79gxbQ/9iz5+Gu1wtVipnA28rLrsyXzp05v bgNyypyeMOPaoAo6Szy0NDCJ0PRS7IRaIvpmMud8umKjlTvtdeLmhbAu9v0C9ybbX9Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794901475; 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=nJTrCNw3zk+mXzjZgUU06g5zrC28b74qTBb4oPoWMbI=; b=48xN9HybFwuDmLOikC1lxJBQ9Zn67unMWfIDSpRq46q5x917FUDvxCoDBHrDJ+qDpG5l 8vwvHfUpMiPmUDdT+Z+8z751U696vUGp1ugfWhhfbombXKFOrDXYUUGlwitV8DnZ3KP3P /9/jRvr19DaqEja2vXZuE1CxMdgwPeRK4gSxWq1LhRlSPKeRcKeemKMyAolnkd3qpJpKE X/4umrcva0ZBsTRNG7dOVNG569iwpF1ZFZbjA4IyE0wYj1uT1U0czt+RdTNf/28d3AMsV ibmghtLmFh+Iw2CBjSV4PO0+cUklqbspWTyDaCNesNymCwZphkTmweYql2PjEKbsh6A== 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=LcnE2VaX; arc=none smtp.remote-ip=95.215.58.143 Received: from mta1.migadu.com (out-143.mta1.migadu.com [95.215.58.143]) (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 7EA12606A323 for ; Tue, 17 Nov 2026 07:44:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 7EA12606A323 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=LcnE2VaX X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=jVZ0So2orIv5BaxqX0IyQ9plkTtzDC6ZmcHPOd8EIw8=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1794901471; v=1; x=1795506271; b=LcnE2VaXEP+TPqzgXkMdVBNZgvqDYPebl0F/CaOo2PK3AKIjTNMEuYpvb49G+0UkSOWXZmUv vh8Y62g58sZuKdq6b2U6yBhCRR0U2qhJkRVhWaeJbya9W+XUFsJ0tFp3Yey7pmdC0nJZ/VI+jPH IhstGmJ1C8EdVtz/lL3Gitlw= X-Envelope-To: linux-kernel@vger.kernel.org Received: by smtp.migadu.com with ESMTPS id d5bc28d01129cadc; Tue, 17 Nov 2026 07:44:31 +0000 X-Mizu-Trace-ID: d5bc28d01129cadc 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 , Will Deacon , Fuad Tabba Subject: [PATCH v2 0/2] KVM: Bound KVM_PRE_FAULT_MEMORY by the vCPU's dirty ring Date: Tue, 17 Nov 2026 07:44:26 +0000 Message-ID: <20261117074428.7544-1-fuad.tabba@linux.dev> X-Mailer: git-send-email 2.47.3 X-Mailing-List: linux-kernel@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 v1 [1]: - Switched the check to kvm_dirty_ring_check_request(). (Sean) - The test checks that each page is reported exactly once, whatever the order. (Lorenzo) - Fixed the test on 64K-page arm64 hosts by sizing its range in host pages. - Various fixes. (Lorenzo) - Dropped Lorenzo's Reviewed-by on patch 1, since the check changed. 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 patch 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/20261110110724.3614412-1-fuad.tabba@linux.dev/ Fuad Tabba (2): KVM: Stop KVM_PRE_FAULT_MEMORY when the vCPU's dirty ring is full KVM: selftests: Test KVM_PRE_FAULT_MEMORY against a full dirty ring Documentation/virt/kvm/api.rst | 9 +- include/linux/kvm_dirty_ring.h | 5 + .../selftests/kvm/pre_fault_memory_test.c | 101 ++++++++++++++++++ virt/kvm/kvm_main.c | 5 + 4 files changed, 118 insertions(+), 2 deletions(-) -- 2.47.3