From nobody Mon Feb 9 01:21:40 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=1770104053; cv=none; d=zohomail.com; s=zohoarc; b=HPYNM0rtLZEidU+NEC9ct3T+sFr/H684f0FT79mk7RcgaJ9tLssbFWBfd+cA5uojnB8vIw2qOidkwEwIaS4QhljnQ7TLX5nBFfnojNDD+8WeyH4WX2tdkmvcH4ivAYf9c+BMH9NUs/sT9Gacm5Hwrl1s2AIZj4d9EYika+SilTI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770104053; 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=oXkxCkb5yDecPBp87JpMAAg/WYB+TI0ipRNsgrCT188=; b=gSyV7lz9FP9I70O6gUfEskOkVhICjJuxr82ECcwkMwa6QJKBsNerZG7Ky5viomaHC9WuFsySGsbB3WokkGFEvEV+agvNl1a8eOn1WWa6jruF6tMkzKL2tpsR6xKb2nNrALV9KDIGs0qOODNokDPz9siWZ53mV59ictsnbmubWWY= 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 1770104053829444.75043218587234; Mon, 2 Feb 2026 23:34:13 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vnAu3-0007Kz-9L; Tue, 03 Feb 2026 02:32:51 -0500 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 1vnAu0-0007Em-O1 for qemu-devel@nongnu.org; Tue, 03 Feb 2026 02:32:49 -0500 Received: from mgamail.intel.com ([192.198.163.10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vnAtx-0006DN-4k for qemu-devel@nongnu.org; Tue, 03 Feb 2026 02:32:47 -0500 Received: from orviesa001.jf.intel.com ([10.64.159.141]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Feb 2026 23:32:37 -0800 Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Feb 2026 23:32:36 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1770103965; x=1801639965; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=6rfHFdfPdD8BjvFsHmnrTLtCCMNlWfo+Utny8DB0OFs=; b=D8q+t+K7SdrBVC0P6Hznysqfuv5yTa6ChOgjyHqu54HfO702OnCFjI7P VFwXJzXSS5XQWGMu00lNe/bxEPBUgOQOUUE1bUlJgIv2DPoQ8C9Oz9uHY NJx4NjMZb61JPlien9+2ZUJUYifn18y2/bWPUf45sdLKise59gC7c2vUR 0XdEXSxCWRTC7N0YBT4XoM+3BmMWnL54maoKNyB/Abi8YbyNjHPtsZhbD qaKACSIfCczj5vTjs8af9pjAkIPJmLwRCRL6I0cxgoMbJFfOVx7RdxS5l V6YPmiZdCKr/LcZNMXA5Yut9k0TIugU41XUZpItPAeRzHnL2gJPfU8Ggf w==; X-CSE-ConnectionGUID: fgE8vR3BQFS/nESFw5Z2Ug== X-CSE-MsgGUID: DPOmfZC4TWKL3UGJxqxTzQ== X-IronPort-AV: E=McAfee;i="6800,10657,11690"; a="82640916" X-IronPort-AV: E=Sophos;i="6.21,270,1763452800"; d="scan'208";a="82640916" X-CSE-ConnectionGUID: fx77WMWSRl2AH532SxsqEw== X-CSE-MsgGUID: SHG5BDBKSSCyZrPJNtKNiw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,270,1763452800"; d="scan'208";a="247373108" From: Vivek Kasireddy To: qemu-devel@nongnu.org Cc: Vivek Kasireddy , Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PATCH v5 08/12] vfio/region: Add a helper to get region index from memory region Date: Mon, 2 Feb 2026 23:30:15 -0800 Message-ID: <20260203073200.848183-9-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260203073200.848183-1-vivek.kasireddy@intel.com> References: <20260203073200.848183-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=192.198.163.10; envelope-from=vivek.kasireddy@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: 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: 1770104126246158500 Having a way to figure out the region index (or bar) associated with a memory region is helpful in various scenarios. For example, this capability can be useful in retrieving the region info 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/region.c | 14 ++++++++++++++ include/hw/vfio/vfio-device.h | 10 ++++++++++ 2 files changed, 24 insertions(+) diff --git a/hw/vfio/region.c b/hw/vfio/region.c index ab39d77574..9c3dc19ee1 100644 --- a/hw/vfio/region.c +++ b/hw/vfio/region.c @@ -461,3 +461,17 @@ void vfio_region_mmaps_set_enabled(VFIORegion *region,= bool enabled) trace_vfio_region_mmaps_set_enabled(memory_region_name(region->mem), enabled); } + +int vfio_get_region_index_from_mr(MemoryRegion *mr) +{ + VFIORegion *region; + + while (mr->container) { + if (mr->ops =3D=3D &vfio_region_ops) { + region =3D mr->opaque; + return region->nr; + } + mr =3D mr->container; + } + return -1; +} diff --git a/include/hw/vfio/vfio-device.h b/include/hw/vfio/vfio-device.h index 828a31c006..596c7f5a10 100644 --- a/include/hw/vfio/vfio-device.h +++ b/include/hw/vfio/vfio-device.h @@ -308,6 +308,16 @@ bool vfio_device_has_region_cap(VFIODevice *vbasedev, = int region, uint16_t cap_t =20 int vfio_device_get_irq_info(VFIODevice *vbasedev, int index, struct vfio_irq_info *info); + +/** + * Return the region index associated with a given MemoryRegion. The index + * can be useful in retrieving region info. + * + * @mr: MemoryRegion to use + * + * Returns the region index or -1 on error. + */ +int vfio_get_region_index_from_mr(MemoryRegion *mr); #endif =20 /* Returns 0 on success, or a negative errno. */ --=20 2.50.1