From nobody Mon Apr 6 16:31:19 2026 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=1773897837; cv=none; d=zohomail.com; s=zohoarc; b=X/tp00wE6ohV5AG5uwbTw2UqUvHNianXO0xwss/kuwPRrPAfOM2luQd+TyMS6ZCnpzAJkE/zLvOqsgjtw0CAZXq/uBVo8OSmzimS3ZLhnL2/m+hUaaZgcI7ZHX+sSQgFlckIGBK2AgNT1+zgKekh6pnXYagYM3kB59wls26h4OY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1773897837; h=Content-Type: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=JSObVbUyyNKBkfPDqfdG3YvtUZhUDTGtDJ8b3cvu7EU=; b=BkF59OzeP6sHMrZ25VkA/4d2g9AyhtBpowGW3FvlZed+LmhHTYg/swsuEO3CFxlFww2/E6pBD6a81pbBcUWWT5rUHmmkhUfMuSoTNNWQjKYwZlqONi/7Eyo4MhhcbDLnfnC8RnvTMDzeKdsb/F6AkJA0f5OijF8dwxuCWxgFAcg= 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 1773897837112264.31486168811637; Wed, 18 Mar 2026 22:23:57 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w35qy-0004ow-IT; Thu, 19 Mar 2026 01:23:28 -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 1w35qk-0004mv-WF for qemu-devel@nongnu.org; Thu, 19 Mar 2026 01:23:15 -0400 Received: from mgamail.intel.com ([198.175.65.20]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w35qj-0007tU-Fu for qemu-devel@nongnu.org; Thu, 19 Mar 2026 01:23:14 -0400 Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by orvoesa112.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Mar 2026 22:23:06 -0700 Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by fmviesa006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Mar 2026 22:23:03 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1773897794; x=1805433794; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=QuvOPLgWq33qfjM99tcEL47AWR773cTQyaf9yFQOg/M=; b=Z4ufSM8ekfXkli8kiwrYu5V4QIG4gpjk9udjuxgFaE2HFuyH2dEfxXkc m7HasEh2mlAFZBJBo6sV8On/oK2kgHwiJMdvmptPudiU5iS2W87yWIjrq nZPRI1ZOIaXlV8mTBJojEy0yncgHwj9FQxLgdYmTpZzVi6+yj2MpwQnkh cd8QV7ltT6F5a55s+DyY6joZ/C5as2p1CB9POanySWryrJtYAt5KrZsM0 zgDEPi64FrZWHKsVMCatOoC6uBNKsY7MQWME0/uduu4iCc7hZzevCy7e2 thRTERIMt/BM1TJ4i9mysgzEao7U07YvE8Z1+jgKYJiRTPVXEUJF/B9+N A==; X-CSE-ConnectionGUID: jBtewN6hTG+YBfZsKjo/5w== X-CSE-MsgGUID: ZSPVOkw+SD+pJxlHfGsLFw== X-IronPort-AV: E=McAfee;i="6800,10657,11733"; a="74660389" X-IronPort-AV: E=Sophos;i="6.23,128,1770624000"; d="scan'208";a="74660389" X-CSE-ConnectionGUID: 2/bsmXsVRWWLjwVi6/d5Qw== X-CSE-MsgGUID: iJRmHkU7ToC42YDPKLjPMg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,128,1770624000"; d="scan'208";a="218355527" From: Vivek Kasireddy To: qemu-devel@nongnu.org Cc: Vivek Kasireddy , Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PATCH v12 06/10] vfio/region: Add a helper to get VFIO region from memory region Date: Wed, 18 Mar 2026 22:15:55 -0700 Message-ID: <20260319052023.2088685-7-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260319052023.2088685-1-vivek.kasireddy@intel.com> References: <20260319052023.2088685-1-vivek.kasireddy@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=198.175.65.20; envelope-from=vivek.kasireddy@intel.com; helo=mgamail.intel.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 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.819, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.903, 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: qemu development 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: 1773897841870154100 Having a way to get the VFIO region associated with a memory region is helpful in various scenarios. For example, this capability can be useful in retrieving the region info such as index and offset needed for mapping a part of a VFIO region or creating a dmabuf. Cc: Alex Williamson Cc: C=C3=A9dric Le Goater Signed-off-by: Vivek Kasireddy --- hw/vfio/vfio-region.h | 10 ++++++++++ hw/vfio/region.c | 11 +++++++++++ 2 files changed, 21 insertions(+) diff --git a/hw/vfio/vfio-region.h b/hw/vfio/vfio-region.h index 9b21d4ee5b..3dd47f77f6 100644 --- a/hw/vfio/vfio-region.h +++ b/hw/vfio/vfio-region.h @@ -45,4 +45,14 @@ void vfio_region_unmap(VFIORegion *region); void vfio_region_exit(VFIORegion *region); void vfio_region_finalize(VFIORegion *region); =20 +/** + * Return the VFIO region associated with a given MemoryRegion. This can + * be useful in retrieving region info such as index and offset. + * + * @mr: MemoryRegion to use + * + * Returns the region or NULL on error. + */ +void *vfio_get_region_from_mr(MemoryRegion *mr); + #endif /* HW_VFIO_REGION_H */ diff --git a/hw/vfio/region.c b/hw/vfio/region.c index 47fdc2df34..9d7ac339c9 100644 --- a/hw/vfio/region.c +++ b/hw/vfio/region.c @@ -539,3 +539,14 @@ void vfio_region_mmaps_set_enabled(VFIORegion *region,= bool enabled) trace_vfio_region_mmaps_set_enabled(memory_region_name(region->mem), enabled); } + +void *vfio_get_region_from_mr(MemoryRegion *mr) +{ + while (mr->container) { + if (mr->ops =3D=3D &vfio_region_ops) { + return mr->opaque; + } + mr =3D mr->container; + } + return NULL; +} --=20 2.53.0