From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4ACF0401A08; Mon, 29 Jun 2026 11:19:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782731962; cv=none; b=d8B1RiogK2CxV0MbWuJaRIHk35ylbtPn5V04yUr5IF17DSCGwe6o63H3xRATowL+D4vnttdOU80i6DUlfrZ5s9ZUwy/mAtwAGNBVA4cL9cZUOYVG3SaeX/WObrSbxmU9h6btW+beaFTV3OctlSCwE0bCQW9hd3WO+XUeAML+AgQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782731962; c=relaxed/simple; bh=H1H7xLhZTiWLAZ00k8s2MDbYagBYOn2VOlBgJhEBaTs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QP3nwMnrjAZExYQdZ82yWDZulDLK8i2SSiBQPZaIB6rrzoyz+GUuUFp+USKvlqPe2WaQ3RpVon3X8VBaRw3CDviRSHRJNbm2h+YKsjbzxIualyT8WHVxUxl6VKU8WBSyLMvV61m8hIiyZChnEYfRRSUYlc7afaFMeMHarJYe0NQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=Xb6wlDDc; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b="Xb6wlDDc" 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 409D53565; Mon, 29 Jun 2026 04:19:16 -0700 (PDT) Received: from LeoBrasDK.cambridge.arm.com (LeoBrasDK.cambridge.arm.com [10.2.212.21]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 807843F905; Mon, 29 Jun 2026 04:19:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1782731960; bh=H1H7xLhZTiWLAZ00k8s2MDbYagBYOn2VOlBgJhEBaTs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Xb6wlDDccOT9ay2vnXMatlaGmrOvX4aC9DZLXLKNrsJre2JRQFPxlFhDYMs6JzqQS 8Qy3JO1+33UvQrZ24+tMWwsBQEdca91s3Wo+loUVfnRH5xCp4PgkoSVivFwPkb7+ql tCUmkJwNKyu/hVNO3wMopFCCphpAzN8dUH6LVjtA= From: Leonardo Bras To: Catalin Marinas , Will Deacon , Marc Zyngier , Oliver Upton , Joey Gouly , Steffen Eiden , Suzuki K Poulose , Zenghui Yu , "Rafael J. Wysocki" , Len Brown , Saket Dumbre , Paolo Bonzini , Jonathan Cameron , Chengwen Feng , Leonardo Bras , Kees Cook , =?UTF-8?q?Miko=C5=82aj=20Lenczewski?= , James Morse , Zeng Heng , mrigendrachaubey , Thomas Huth , Ryan Roberts , Yeoreum Yun , Mark Brown , Kevin Brodsky , James Clark , Fuad Tabba , Raghavendra Rao Ananta , Lorenzo Pieralisi , Sascha Bischoff , Anshuman Khandual , Tian Zheng Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kvmarm@lists.linux.dev, linux-acpi@vger.kernel.org, acpica-devel@lists.linux.dev, kvm@vger.kernel.org Subject: [PATCH v2 11/13] kvm/dirty_ring: Add arch-generic interface for hw-accelerated dirty-ring cleaning Date: Mon, 29 Jun 2026 12:17:59 +0100 Message-ID: <20260629111820.1873540-12-leo.bras@arm.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260629111820.1873540-1-leo.bras@arm.com> References: <20260629111820.1873540-1-leo.bras@arm.com> Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3023; i=leo.bras@arm.com; h=from:subject; bh=H1H7xLhZTiWLAZ00k8s2MDbYagBYOn2VOlBgJhEBaTs=; b=owGbwMvMwCX2pizjszvTwvWMp9WSGLKcQhJLnxkdevuk5NFsUz3DBuVrWhq39j64VNwpr8CTe syUoelJRykLgxgXg6yYIovso/mreL5PyThy5ccCmDmsTCBDGLg4BWAiUusYGY4dW+0n0H/0Z/68 qTIal9YrRFwsf/JOrqdr27Hz83r/nDBi+O+26qIAa9f04z1T3gfcnsf095pa7Bap6QYdcQtmT3z 19y8rAA== X-Developer-Key: i=leo.bras@arm.com; a=openpgp; fpr=36E6C95AE0F111CC5B6F4D2E688C33F8A0C5B0C5 Content-Transfer-Encoding: 8bit Introduce kvm_arch_dirty_ring_clear() that allow implementation of arch-specific hardware-accelerated dirty-ring routines. A call to that is added on kvm_dirty_ring_reset() and will fall back to software version if not implemented, or any error was detected in the arch-specific routine. For an arch to implement this function, it's required to provide it in a asm/kvm_dirty_bit.h and have CONFIG_HAVE_KVM_HW_DIRTY_BIT=y on building. If the arch does not implement it, and thus lack above config, the introduced snippet is expected to be compiled-out and have zero impact at runtime. Signed-off-by: Leonardo Bras --- include/linux/kvm_dirty_bit.h | 7 +++++++ virt/kvm/dirty_ring.c | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/include/linux/kvm_dirty_bit.h b/include/linux/kvm_dirty_bit.h index fa4f6b67b623..8492979d694e 100644 --- a/include/linux/kvm_dirty_bit.h +++ b/include/linux/kvm_dirty_bit.h @@ -11,17 +11,24 @@ static inline int kvm_arch_dirty_log_clear(struct kvm *kvm, struct kvm_memory_slot *memslot, struct kvm_clear_dirty_log *log, unsigned long *bitmap, bool *flush) { return -ENXIO; } +static inline int kvm_arch_dirty_ring_clear(struct kvm *kvm, + struct kvm_dirty_ring *ring, + int *nr_entries_reset) +{ + return -ENXIO; +} + #else /* CONFIG_HAVE_KVM_HW_DIRTY_BIT */ #include #endif /* CONFIG_HAVE_KVM_HW_DIRTY_BIT */ #endif /* __KVM_DIRTY_BIT_H__ */ diff --git a/virt/kvm/dirty_ring.c b/virt/kvm/dirty_ring.c index 42de1a511037..fe4e7da6cc4a 100644 --- a/virt/kvm/dirty_ring.c +++ b/virt/kvm/dirty_ring.c @@ -1,20 +1,21 @@ // SPDX-License-Identifier: GPL-2.0-only /* * KVM dirty ring implementation * * Copyright 2019 Red Hat, Inc. */ #include #include #include #include +#include #include #include "kvm_mm.h" int __weak kvm_cpu_dirty_log_size(struct kvm *kvm) { return 0; } u32 kvm_dirty_ring_get_rsvd_entries(struct kvm *kvm) { @@ -126,20 +127,23 @@ int kvm_dirty_ring_reset(struct kvm *kvm, struct kvm_dirty_ring *ring, struct kvm_dirty_gfn *entry; /* * Ensure concurrent calls to KVM_RESET_DIRTY_RINGS are serialized, * e.g. so that KVM fully resets all entries processed by a given call * before returning to userspace. Holding slots_lock also protects * the various memslot accesses. */ lockdep_assert_held(&kvm->slots_lock); + if (kvm_arch_dirty_ring_clear(kvm, ring, nr_entries_reset) >= 0) + return 0; + while (likely((*nr_entries_reset) < INT_MAX)) { if (signal_pending(current)) return -EINTR; entry = &ring->dirty_gfns[ring->reset_index & (ring->size - 1)]; if (!kvm_dirty_gfn_harvested(entry)) break; next_slot = READ_ONCE(entry->slot); -- 2.54.0