From nobody Sat Nov 15 17:08:38 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1749716980; cv=none; d=zohomail.com; s=zohoarc; b=W3gtkrFpgSkBaIPTU7Ygd/gGD79xyJmwdpwTHpqXuetMlnt3ERUrATSjPaTw0a45EHzCHCF5mzmyWwHokkxL49fjfTDcwMJYLlCV32WaoMZl9MsPwfi4OmOhUEkb11wvOAAVNl1f2ex7zEfRt+RSBGnfwLNlRScRFvyizyTUglY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749716980; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Za6nBvK55fR3DmrYBDomCCN4NVTEtK3FPtJJxch/6HQ=; b=k2fJ3qqvctp8TsoAe0QQElk0xmixjB5uMrdpyCy15R4kx9vP14cBAJFjlJYhhIf4qV2uJHLGbBr8TwIOwalbbRLAat4VLaCpBxoFiyk/YNAiWdfqcv2Zo76TZVYP2gVeUgHzhNTK3Z53Wn0ee/Z70h2JCzzyrGfMgpgSZHHoDAQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1749716980642379.35566108346734; Thu, 12 Jun 2025 01:29:40 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uPdIO-00086c-4h; Thu, 12 Jun 2025 04:28:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uPdIJ-0007zr-1T for qemu-devel@nongnu.org; Thu, 12 Jun 2025 04:28:19 -0400 Received: from mgamail.intel.com ([192.198.163.8]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uPdIG-0004FP-Qp for qemu-devel@nongnu.org; Thu, 12 Jun 2025 04:28:18 -0400 Received: from orviesa004.jf.intel.com ([10.64.159.144]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jun 2025 01:28:10 -0700 Received: from emr-bkc.sh.intel.com ([10.112.230.82]) by orviesa004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jun 2025 01:28:05 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1749716897; x=1781252897; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=IoDfVvR6sOQKPtD7NymR46Bpd3lDqmDVR2c529+KaPQ=; b=iScjMdZnPz1jcbmpfxh47T+ApnM15FnHpwKhIwZ7OnzhGZslMAjJj7sk oqSN5YSad0ZfwbdyWSHG3UKoyzvavLeCeYUqcL7zW9qF+fF3Z9ZjNDpNs zi7aOnNnZ/Bet5rjMQelr80kPiMyTLgIW1mhRN/pN+jjFBdvnWH5uoiFk HysafEQgpcvkE5ZbdopM1GYsPSo4cm5Hsaf3nu8Zzk+/5xR81ix1APNid DSWEKogmj91iEMKoyqWC1AQAhEKLYn28XUnm2gnoHaxgH3rtvl+2Ndm/j 6P7GJZad9cNUQubja9aJRyueovj9RbCU3XHZzcMcqfzfuLSKcxN8RMNjm g==; X-CSE-ConnectionGUID: tiPsQvMYS8aScLrBUKTRGg== X-CSE-MsgGUID: eAKeem/pScOZtZHBtYNjpg== X-IronPort-AV: E=McAfee;i="6800,10657,11461"; a="69453444" X-IronPort-AV: E=Sophos;i="6.16,230,1744095600"; d="scan'208";a="69453444" X-CSE-ConnectionGUID: DiI5kDGUQzyaj1BObYm3GA== X-CSE-MsgGUID: 2lPuQWzSQNiOrb/Uvrf9AA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.16,230,1744095600"; d="scan'208";a="152442037" From: Chenyi Qiang To: David Hildenbrand , Alexey Kardashevskiy , Peter Xu , Gupta Pankaj , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Michael Roth Cc: Chenyi Qiang , qemu-devel@nongnu.org, kvm@vger.kernel.org, Williams Dan J , Zhao Liu , Baolu Lu , Gao Chao , Xu Yilun , Li Xiaoyao , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Alex Williamson Subject: [PATCH v7 3/5] memory: Unify the definiton of ReplayRamPopulate() and ReplayRamDiscard() Date: Thu, 12 Jun 2025 16:27:44 +0800 Message-ID: <20250612082747.51539-4-chenyi.qiang@intel.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250612082747.51539-1-chenyi.qiang@intel.com> References: <20250612082747.51539-1-chenyi.qiang@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=192.198.163.8; envelope-from=chenyi.qiang@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1749716983061116600 Content-Type: text/plain; charset="utf-8" Update ReplayRamDiscard() function to return the result and unify the ReplayRamPopulate() and ReplayRamDiscard() to ReplayRamDiscardState() at the same time due to their identical definitions. This unification simplifies related structures, such as VirtIOMEMReplayData, which makes it cleaner. Reviewed-by: David Hildenbrand Reviewed-by: Pankaj Gupta Reviewed-by: Xiaoyao Li Signed-off-by: Chenyi Qiang --- Changes in v7: - Add Reviewed-by from Xiaoyao and Pankaj. Changes in v6: - Add Reviewed-by from David - Add a documentation comment for the prototype change Changes in v5: - Rename ReplayRamStateChange to ReplayRamDiscardState (David) - return data->fn(s, data->opaque) instead of 0 in virtio_mem_rdm_replay_discarded_cb(). (Alexey) Changes in v4: - Modify the commit message. We won't use Replay() operation when doing the attribute change like v3. --- hw/virtio/virtio-mem.c | 21 +++++++------- include/system/memory.h | 64 ++++++++++++++++++++++++++++++----------- migration/ram.c | 5 ++-- system/memory.c | 12 ++++---- 4 files changed, 66 insertions(+), 36 deletions(-) diff --git a/hw/virtio/virtio-mem.c b/hw/virtio/virtio-mem.c index 2e491e8c44..c46f6f9c3e 100644 --- a/hw/virtio/virtio-mem.c +++ b/hw/virtio/virtio-mem.c @@ -1732,7 +1732,7 @@ static bool virtio_mem_rdm_is_populated(const RamDisc= ardManager *rdm, } =20 struct VirtIOMEMReplayData { - void *fn; + ReplayRamDiscardState fn; void *opaque; }; =20 @@ -1740,12 +1740,12 @@ static int virtio_mem_rdm_replay_populated_cb(Memor= yRegionSection *s, void *arg) { struct VirtIOMEMReplayData *data =3D arg; =20 - return ((ReplayRamPopulate)data->fn)(s, data->opaque); + return data->fn(s, data->opaque); } =20 static int virtio_mem_rdm_replay_populated(const RamDiscardManager *rdm, MemoryRegionSection *s, - ReplayRamPopulate replay_fn, + ReplayRamDiscardState replay_fn, void *opaque) { const VirtIOMEM *vmem =3D VIRTIO_MEM(rdm); @@ -1764,14 +1764,13 @@ static int virtio_mem_rdm_replay_discarded_cb(Memor= yRegionSection *s, { struct VirtIOMEMReplayData *data =3D arg; =20 - ((ReplayRamDiscard)data->fn)(s, data->opaque); - return 0; + return data->fn(s, data->opaque); } =20 -static void virtio_mem_rdm_replay_discarded(const RamDiscardManager *rdm, - MemoryRegionSection *s, - ReplayRamDiscard replay_fn, - void *opaque) +static int virtio_mem_rdm_replay_discarded(const RamDiscardManager *rdm, + MemoryRegionSection *s, + ReplayRamDiscardState replay_fn, + void *opaque) { const VirtIOMEM *vmem =3D VIRTIO_MEM(rdm); struct VirtIOMEMReplayData data =3D { @@ -1780,8 +1779,8 @@ static void virtio_mem_rdm_replay_discarded(const Ram= DiscardManager *rdm, }; =20 g_assert(s->mr =3D=3D &vmem->memdev->mr); - virtio_mem_for_each_unplugged_section(vmem, s, &data, - virtio_mem_rdm_replay_discarded_= cb); + return virtio_mem_for_each_unplugged_section(vmem, s, &data, + virtio_mem_rdm_replay_dis= carded_cb); } =20 static void virtio_mem_rdm_register_listener(RamDiscardManager *rdm, diff --git a/include/system/memory.h b/include/system/memory.h index 60983d4977..eb2618e1b4 100644 --- a/include/system/memory.h +++ b/include/system/memory.h @@ -576,8 +576,20 @@ static inline void ram_discard_listener_init(RamDiscar= dListener *rdl, rdl->double_discard_supported =3D double_discard_supported; } =20 -typedef int (*ReplayRamPopulate)(MemoryRegionSection *section, void *opaqu= e); -typedef void (*ReplayRamDiscard)(MemoryRegionSection *section, void *opaqu= e); +/** + * ReplayRamDiscardState: + * + * The callback handler for #RamDiscardManagerClass.replay_populated/ + * #RamDiscardManagerClass.replay_discarded to invoke on populated/discard= ed + * parts. + * + * @section: the #MemoryRegionSection of populated/discarded part + * @opaque: pointer to forward to the callback + * + * Returns 0 on success, or a negative error if failed. + */ +typedef int (*ReplayRamDiscardState)(MemoryRegionSection *section, + void *opaque); =20 /* * RamDiscardManagerClass: @@ -651,36 +663,38 @@ struct RamDiscardManagerClass { /** * @replay_populated: * - * Call the #ReplayRamPopulate callback for all populated parts within= the - * #MemoryRegionSection via the #RamDiscardManager. + * Call the #ReplayRamDiscardState callback for all populated parts wi= thin + * the #MemoryRegionSection via the #RamDiscardManager. * * In case any call fails, no further calls are made. * * @rdm: the #RamDiscardManager * @section: the #MemoryRegionSection - * @replay_fn: the #ReplayRamPopulate callback + * @replay_fn: the #ReplayRamDiscardState callback * @opaque: pointer to forward to the callback * * Returns 0 on success, or a negative error if any notification faile= d. */ int (*replay_populated)(const RamDiscardManager *rdm, MemoryRegionSection *section, - ReplayRamPopulate replay_fn, void *opaque); + ReplayRamDiscardState replay_fn, void *opaque); =20 /** * @replay_discarded: * - * Call the #ReplayRamDiscard callback for all discarded parts within = the - * #MemoryRegionSection via the #RamDiscardManager. + * Call the #ReplayRamDiscardState callback for all discarded parts wi= thin + * the #MemoryRegionSection via the #RamDiscardManager. * * @rdm: the #RamDiscardManager * @section: the #MemoryRegionSection - * @replay_fn: the #ReplayRamDiscard callback + * @replay_fn: the #ReplayRamDiscardState callback * @opaque: pointer to forward to the callback + * + * Returns 0 on success, or a negative error if any notification faile= d. */ - void (*replay_discarded)(const RamDiscardManager *rdm, - MemoryRegionSection *section, - ReplayRamDiscard replay_fn, void *opaque); + int (*replay_discarded)(const RamDiscardManager *rdm, + MemoryRegionSection *section, + ReplayRamDiscardState replay_fn, void *opaque); =20 /** * @register_listener: @@ -721,15 +735,31 @@ uint64_t ram_discard_manager_get_min_granularity(cons= t RamDiscardManager *rdm, bool ram_discard_manager_is_populated(const RamDiscardManager *rdm, const MemoryRegionSection *section); =20 +/** + * ram_discard_manager_replay_populated: + * + * A wrapper to call the #RamDiscardManagerClass.replay_populated callback + * of the #RamDiscardManager. + * + * Returns 0 on success, or a negative error if any notification failed. + */ int ram_discard_manager_replay_populated(const RamDiscardManager *rdm, MemoryRegionSection *section, - ReplayRamPopulate replay_fn, + ReplayRamDiscardState replay_fn, void *opaque); =20 -void ram_discard_manager_replay_discarded(const RamDiscardManager *rdm, - MemoryRegionSection *section, - ReplayRamDiscard replay_fn, - void *opaque); +/** + * ram_discard_manager_replay_discarded: + * + * A wrapper to call the #RamDiscardManagerClass.replay_discarded callback + * of the #RamDiscardManager. + * + * Returns 0 on success, or a negative error if any notification failed. + */ +int ram_discard_manager_replay_discarded(const RamDiscardManager *rdm, + MemoryRegionSection *section, + ReplayRamDiscardState replay_fn, + void *opaque); =20 void ram_discard_manager_register_listener(RamDiscardManager *rdm, RamDiscardListener *rdl, diff --git a/migration/ram.c b/migration/ram.c index d26dbd37c4..2d4af497b5 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -848,8 +848,8 @@ static inline bool migration_bitmap_clear_dirty(RAMStat= e *rs, return ret; } =20 -static void dirty_bitmap_clear_section(MemoryRegionSection *section, - void *opaque) +static int dirty_bitmap_clear_section(MemoryRegionSection *section, + void *opaque) { const hwaddr offset =3D section->offset_within_region; const hwaddr size =3D int128_get64(section->size); @@ -868,6 +868,7 @@ static void dirty_bitmap_clear_section(MemoryRegionSect= ion *section, } *cleared_bits +=3D bitmap_count_one_with_offset(rb->bmap, start, npage= s); bitmap_clear(rb->bmap, start, npages); + return 0; } =20 /* diff --git a/system/memory.c b/system/memory.c index d0c186e9f6..76b44b8220 100644 --- a/system/memory.c +++ b/system/memory.c @@ -2138,7 +2138,7 @@ bool ram_discard_manager_is_populated(const RamDiscar= dManager *rdm, =20 int ram_discard_manager_replay_populated(const RamDiscardManager *rdm, MemoryRegionSection *section, - ReplayRamPopulate replay_fn, + ReplayRamDiscardState replay_fn, void *opaque) { RamDiscardManagerClass *rdmc =3D RAM_DISCARD_MANAGER_GET_CLASS(rdm); @@ -2147,15 +2147,15 @@ int ram_discard_manager_replay_populated(const RamD= iscardManager *rdm, return rdmc->replay_populated(rdm, section, replay_fn, opaque); } =20 -void ram_discard_manager_replay_discarded(const RamDiscardManager *rdm, - MemoryRegionSection *section, - ReplayRamDiscard replay_fn, - void *opaque) +int ram_discard_manager_replay_discarded(const RamDiscardManager *rdm, + MemoryRegionSection *section, + ReplayRamDiscardState replay_fn, + void *opaque) { RamDiscardManagerClass *rdmc =3D RAM_DISCARD_MANAGER_GET_CLASS(rdm); =20 g_assert(rdmc->replay_discarded); - rdmc->replay_discarded(rdm, section, replay_fn, opaque); + return rdmc->replay_discarded(rdm, section, replay_fn, opaque); } =20 void ram_discard_manager_register_listener(RamDiscardManager *rdm, --=20 2.43.5