From nobody Mon Apr 13 11:07:22 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=1772853167; cv=none; d=zohomail.com; s=zohoarc; b=WCEBSOlivbEWVEjj+jO5CRbGN3l+KgsgLEk4cDIMlILwKEznoEaNzShJ3F71GIzJkwtwMn9z9x91CDQM/p0zsouG7WaiLFAbAT7FcoLG1OmO5/fuz71gb5byUUDOKYbTVEmDteANH5PCig6Fu5XivFaUSakvHgz/aFbx65LviE0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1772853167; 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=OvvXna9asyBYuGGCY/V62xry7x8KfmAwpbl4bxe8+oE=; b=S3UH7MRpdi/2u1cdCgKrlnXK2z+zf1WrhkflsMX9dBNbEXoaz3rLx8rb9yZvYuKsTwht10pU67zRLRpdigoigSqC8AlO0yaXrcdgBfe8USU+lSWBqVjbPv/Li/S8zXMsTaOeeEQLwc/SR57mn2iBo+QFXEuF7B8BvfUhcZD5z3c= 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 1772853167410329.8760312496132; Fri, 6 Mar 2026 19:12:47 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vyi4V-0004nf-So; Fri, 06 Mar 2026 22:11:19 -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 1vyi4R-0004lg-2n for qemu-devel@nongnu.org; Fri, 06 Mar 2026 22:11:15 -0500 Received: from mgamail.intel.com ([192.198.163.7]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vyi4P-0000oK-BK for qemu-devel@nongnu.org; Fri, 06 Mar 2026 22:11:14 -0500 Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Mar 2026 19:11:01 -0800 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; 06 Mar 2026 19:11:01 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1772853073; x=1804389073; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=1TEvr2QnTOUFzPzfTMXk5IYYw/2XkOgNrkkXD+yNNs8=; b=Bi4V6+pwYc91lJji3ycMp5qW2bh3IgiHFugBd5gRVfp2z2CJRzLcsD8Q n78Sn1+L29CFzQ4rhAbcYud/UcuURz44yu7AGPGMvtspoLdyHAJrLQ20I ziSmdsB3dkQ4Rjs1WH6sjfuuNy9HcMSRxzKu6klz6TWfuOhfqAdPZ8T3M IUdsi3Bd8dKq279oKUxLIpD+b/YlqZl6XbUMMq4ZzV08yGuuhl7+0NNH2 1v9dvx9YEyAiNPA7m0e3IzasKIQYh2LT63BbU/LymeWpDQRzvluCKiybA nP+gUil03IpLKPf3qX/ZEb6vXSAQUulZI09/56nZPGZ4cPgWUGrmuqJxX A==; X-CSE-ConnectionGUID: 4f/Bpr1mSlyvhKZjYvs66w== X-CSE-MsgGUID: UbOl8diNTcC+qZKDttRPcQ== X-IronPort-AV: E=McAfee;i="6800,10657,11721"; a="99434029" X-IronPort-AV: E=Sophos;i="6.23,106,1770624000"; d="scan'208";a="99434029" X-CSE-ConnectionGUID: zHPNlRYwTa+0um0pZfA80w== X-CSE-MsgGUID: qbiYDQdmS6qywCqWvIcb9g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,106,1770624000"; d="scan'208";a="215813774" From: Vivek Kasireddy To: qemu-devel@nongnu.org Cc: Vivek Kasireddy , Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PATCH v10 06/10] vfio/region: Add a helper to get region index from memory region Date: Fri, 6 Mar 2026 19:05:55 -0800 Message-ID: <20260307030812.1224392-7-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260307030812.1224392-1-vivek.kasireddy@intel.com> References: <20260307030812.1224392-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.7; envelope-from=vivek.kasireddy@intel.com; helo=mgamail.intel.com X-Spam_score_int: -32 X-Spam_score: -3.3 X-Spam_bar: --- X-Spam_report: (-3.3 / 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.411, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.679, 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: 1772853172139154100 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 47fdc2df34..4cb92216ef 100644 --- a/hw/vfio/region.c +++ b/hw/vfio/region.c @@ -539,3 +539,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.53.0