From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 60152CA9ED0 for ; Mon, 12 Oct 2026 21:58:55 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1840310F2E5; Mon, 12 Oct 2026 21:58:50 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.7]) by gabe.freedesktop.org (Postfix) with ESMTPS id C9ADA10F2E5; Mon, 12 Oct 2026 21:58:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1791842324; x=1823378324; h=date:from:to:cc:subject:message-id:references: in-reply-to:mime-version; bh=sIIV62Xb2PuEvwQO3rLjCl0MDlTJ9kHF5Q7+LoREkfs=; b=fA2ZK/xcfCCM73uBXygRQAEQGo/A+yTI26eJ6HzR7NMPwAkXGXLqrmsr aLVJrGPx6svtMOVcPXwBtwfjpmfiV4rposdJ00CNaBjG9bE3AmQvkFzQ9 lv0qJxsXqHih67QSCuy2+6wxcbtW7graDAgNTa7pIDBR6KD7giRFeP2vP P4F/vC6pOJiqtRCiQsPyuf2MNcwmlxvjFi4+xI7jVfqkTJ+jS31+G2T2d Fiw1K6wEQa07CLQybvOAI5cZPrtqjhKv3IIUIH4R0/73QSa+4OzDYPCfe V6sDHqoiC4UKZu086R9D4GljOuIfuk8dusB1J6Tf4TjzF3NpJnZ4ScDGJ Q==; X-CSE-ConnectionGUID: 4mLmo3jvTEamKIqfXCUyZA== X-CSE-MsgGUID: gvN+UBaFRdWQlgiYdX8TfA== X-IronPort-AV: E=McAfee;i="6800,10657,11933"; a="459093" X-IronPort-AV: E=Sophos;i="6.27,154,1787036400"; d="scan'208";a="459093" Received: from fmviesa011.fm.intel.com ([10.60.135.151]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Oct 2026 14:58:44 -0700 X-CSE-ConnectionGUID: JuBGcbemQsuUqiBAojH0qw== X-CSE-MsgGUID: hYsy9SXuQwSi82qR06BaDw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,154,1787036400"; d="scan'208";a="2846871" Received: from fmsmsx902.amr.corp.intel.com ([10.18.126.91]) by fmviesa011.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Oct 2026 14:58:44 -0700 Received: from FMSMSX901.amr.corp.intel.com (10.18.126.90) by fmsmsx902.amr.corp.intel.com (10.18.126.91) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.49; Mon, 12 Oct 2026 14:58:43 -0700 Received: from fmsedg903.ED.cps.intel.com (10.1.192.145) by FMSMSX901.amr.corp.intel.com (10.18.126.90) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.49 via Frontend Transport; Mon, 12 Oct 2026 14:58:43 -0700 Received: from SN4PR2101CU001.outbound.protection.outlook.com (40.93.195.64) by edgegateway.intel.com (192.55.55.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.49; Mon, 12 Oct 2026 14:58:42 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=QrvzzgH0BIDoOHxmxD5TTZ9Ypp6MT/OnYWWjJ2DygSf+c92qp5lzNLd3hCLBeYy1PBmvZomZc37sk6uDVe+fIXHUVZgxYv6fDfx+I9S5w9PULaPN7Bb40nlhvXCp4nP/JoINctY0FqWRVGGMCGK7X8PmQ4WeZv5Z5yksrNMByvGdw4FInTuExq5e/AWVxeD6jNkvTDt5K10kQiECZo5N/1zeMvbMfXMH3MTE5ZzO/idGppUTbdviuTthRKBEUl3VYrllQHXUJshTgyxKJZsOOPPBe7B0ZUqMGt/f0MBWRYGnD448M8BznY46fi+CsWZEV6mAnU+d/NcjLUUfBg183Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=IdcCzvr9tq6yTbjn0D5SgMjTgzhNSvAOR/MUI3wuF4Q=; b=DKzZ+xOYkJLYR3/tQ74jw/4TUFv0XUKp0oxnLYGxzgecGJz5YC7hnLCae8OFYPJcWroTMwybNCJ1oQbLEH8YJ+KE/g8fGsAsY+tev9LC4iG5xdUMPWqYVO1Z/AhyGhta8FrZIVSUtuodS7QLIQK1vMVqMNnggJacgs8oiK5NNtOjYO3KRqLw38a7jW6XJ0dX23n2YjtJUKeSzlgSVC2o1YlUuCwIcHXTEOuM6m/LiaNq2XZs71rccbgcwiRp1L8YP83TjGzt77byxFGm5DwPFgF3tsfwIKOjDsC917DTxWNcvc1cPeocqeaiP+WgEE301/bwZBjqLRpJaz/brjpXXA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Authentication-Results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; Received: from PH0PR11MB4792.namprd11.prod.outlook.com (2603:10b6:510:32::11) by IA3PR11MB9327.namprd11.prod.outlook.com (2603:10b6:208:57a::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.496.23; Mon, 12 Oct 2026 21:58:33 +0000 Received: from PH0PR11MB4792.namprd11.prod.outlook.com ([fe80::fec9:8db4:c768:8289]) by PH0PR11MB4792.namprd11.prod.outlook.com ([fe80::fec9:8db4:c768:8289%6]) with mapi id 15.21.0472.016; Mon, 12 Oct 2026 21:58:33 +0000 Date: Mon, 12 Oct 2026 14:58:31 -0700 From: Matthew Brost To: Niranjana Vishwanathapura CC: , Subject: Re: [PATCH 1/2] drm/gem: add helper to detect self-imported PRIME dma-bufs Message-ID: References: <20261012180543.1488703-4-niranjana.vishwanathapura@intel.com> <20261012180543.1488703-5-niranjana.vishwanathapura@intel.com> Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <20261012180543.1488703-5-niranjana.vishwanathapura@intel.com> X-ClientProxiedBy: BY3PR04CA0024.namprd04.prod.outlook.com (2603:10b6:a03:217::29) To PH0PR11MB4792.namprd11.prod.outlook.com (2603:10b6:510:32::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PH0PR11MB4792:EE_|IA3PR11MB9327:EE_ X-MS-Office365-Filtering-Correlation-Id: 685b9695-9c28-4df8-505e-08df28abf587 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|23010399003|366016|1800799024|376014|22082099003|18002099003|10067099003|261009221227099003|261009223027099003|4143699003|11063799006|5023799004|56012099006; X-Microsoft-Antispam-Message-Info: zTCEoJzxYDWhqeVAlByqya+mDSypwweZQVLFxHoxB/SxWG9CJwRqzdqbcKc5sapgammq84ojWU+WCBGhsv7Dg1UQG0StLuywEjc87tDDkDG5quAlPR1H9rsNsz9B8J3DYSvF25qAsC8x2/YQz6jV4Be1NiZc9lF0L+ag/mnk1SbEVnymyIJxqcY8bicrzUbaJ4EfhFn4u2580JGTdaylU6wpc9lkEzybRzZInUECv56pDAIclCpMw5rAHmZGAD/EVPhs6rp+91U24lPUhVdrH/Mqmr3H7Y0YmNOSQNtdTS8+JZuhDTrzDizz2VeVX4RPMoY/F1TVU6lTdIqK7LRTU8Q87YlCWFth3yb8f8CArpo2jvZ9QHpmXw4NJu0vZ4g1Tb6MaHtzmpS5rkAXsWqkGG+Gf7IRTfXh0oNkshciNAGKec+ofYDpm8lUyTVAB4j7KLHn4jZchgvNgYwEzYIulxhRT6JhPj/aAs9AZ7RgswoS4k7sBBHFZxHL/q45SBmZCQwnX1P7h+qkH5fHD/LxMwLe28QNtNhPyt33li8ced7LQJszgoGvOT7dcfPEV00ektmZwswkjQvgCaOSqQ84cLWvaE2/EOfzTy6XgogYrpIcg8BPOwiY5AMpjn77xAkcRk2gmHL+G5+lELQwrKKbzxWF4HPYUBL3cL/hvk8pGjQ= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PH0PR11MB4792.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(23010399003)(366016)(1800799024)(376014)(22082099003)(18002099003)(10067099003)(261009221227099003)(261009223027099003)(4143699003)(11063799006)(5023799004)(56012099006); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?a/XOf9uxW5cBxJJTxJKlJp/HQAHuEPsWXN/OW5r0CMAdXc0vpk3p7Lv4IhhH?= =?us-ascii?Q?YJse/xQJFyLCSRosvzWa7VTxBPr6U07xOm5l0bOHkocN/6S+VNoY3mT644Ln?= =?us-ascii?Q?H20aOWTiO9C+KrAtsf6N5KCj5XfmZ4RzjNFAw9dVd986QmpofZcfkbwRzYuF?= =?us-ascii?Q?Vrei4rzPgMu9nBtNiM2STm6xKOQ6q+UCruA6N98Qn2K2ro0T+MvpZNuaZIE7?= =?us-ascii?Q?xjDzIm2TzaKS1Ut5G3aYe9TpTXravq6v71F5IX6x1fGU1fc5tSC2Lkf/TGhU?= =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6ehmAbk8Zgk59c5Uwtw== X-MS-Exchange-CrossTenant-Network-Message-Id: 685b9695-9c28-4df8-505e-08df28abf587 X-MS-Exchange-CrossTenant-AuthSource: PH0PR11MB4792.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Oct 2026 21:58:33.5548 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Un1dx7iufEDrLWmASyWlQMMLyDMM6/dbLi/ltmBguAFG9pJFI7Hn8SJdp97X7HHc5fYV6EYdD2gCRO9rqiIoHA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA3PR11MB9327 X-OriginatorOrg: intel.com X-BeenThere: intel-xe@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel Xe graphics driver List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-xe-bounces@lists.freedesktop.org Sender: "Intel-xe" On Mon, Oct 12, 2026 at 11:05:42AM -0700, Niranjana Vishwanathapura wrote: > From: Farah Kassabri > > Add drm_gem_prime_self_import() to detect and handle the case where a > PRIME dma-buf being imported was exported by the same DRM device. > > When the dma-buf originates from the importing device and uses the > expected dma-buf ops, the helper returns the associated GEM object and > takes an extra reference on it. This allows drivers to bypass the > generic PRIME import path and avoid taking an additional reference on > the dma-buf file. > > The helper simplifies self-import handling and avoids duplication of > this pattern across DRM drivers. > > Signed-off-by: Farah Kassabri > Signed-off-by: Niranjana Vishwanathapura Reviewed-by: Matthew Brost I would suggest for this series at least one other driver be fixed to use this helper or all drivers (a decent model should be able to do this easily) to show this isn't just an Xe idea. > --- > drivers/gpu/drm/drm_prime.c | 48 ++++++++++++++++++++++++++++++------- > include/drm/drm_prime.h | 4 ++++ > 2 files changed, 44 insertions(+), 8 deletions(-) > > diff --git a/drivers/gpu/drm/drm_prime.c b/drivers/gpu/drm/drm_prime.c > index 9b44c78cd77f..588910c250b8 100644 > --- a/drivers/gpu/drm/drm_prime.c > +++ b/drivers/gpu/drm/drm_prime.c > @@ -974,15 +974,9 @@ struct drm_gem_object *drm_gem_prime_import_dev(struct drm_device *dev, > struct drm_gem_object *obj; > int ret; > > - if (drm_gem_is_prime_exported_dma_buf(dev, dma_buf)) { > - /* > - * Importing dmabuf exported from our own gem increases > - * refcount on gem itself instead of f_count of dmabuf. > - */ > - obj = dma_buf->priv; > - drm_gem_object_get(obj); > + obj = drm_gem_prime_self_import(dev, dma_buf, &drm_gem_prime_dmabuf_ops); > + if (obj) > return obj; > - } > > if (!dev->driver->gem_prime_import_sg_table) > return ERR_PTR(-EINVAL); > @@ -1116,3 +1110,41 @@ void drm_prime_gem_destroy(struct drm_gem_object *obj, struct sg_table *sg) > dma_buf_put(dma_buf); > } > EXPORT_SYMBOL(drm_prime_gem_destroy); > + > +/** > + * drm_gem_prime_self_import - Attempt to import a dma-buf exported by this DRM device > + * @dev: DRM device performing the import > + * @dma_buf: dma-buf to import > + * @expected_ops: dma-buf ops used by this driver > + * > + * If @dma_buf was exported by this DRM device using @expected_ops, return the > + * corresponding GEM object and take an extra reference on it. In this case, > + * the import avoids taking a reference on the dma-buf file and instead bumps > + * the GEM object's refcount directly. > + * > + * Returns: > + * A referenced GEM object on success, or %NULL if the dma-buf was not exported > + * by this device or does not match @expected_ops. > + */ > +struct drm_gem_object *drm_gem_prime_self_import(struct drm_device *dev, > + struct dma_buf *dma_buf, > + const struct dma_buf_ops *expected_ops) > +{ > + struct drm_gem_object *obj; > + > + if (dma_buf->ops != expected_ops) > + return NULL; > + > + obj = dma_buf->priv; > + if (obj->dev != dev) > + return NULL; > + > + /* > + * Importing dmabuf exported from our own gem increases > + * refcount on gem itself instead of f_count of dmabuf. > + */ > + drm_gem_object_get(obj); > + > + return obj; > +} > +EXPORT_SYMBOL(drm_gem_prime_self_import); > diff --git a/include/drm/drm_prime.h b/include/drm/drm_prime.h > index f50f862f0d8b..d378404f8ab4 100644 > --- a/include/drm/drm_prime.h > +++ b/include/drm/drm_prime.h > @@ -54,6 +54,7 @@ struct device; > struct dma_buf_export_info; > struct dma_buf; > struct dma_buf_attachment; > +struct dma_buf_ops; > struct iosys_map; > > enum dma_data_direction; > @@ -108,6 +109,9 @@ struct drm_gem_object *drm_gem_prime_import_dev(struct drm_device *dev, > struct device *attach_dev); > struct drm_gem_object *drm_gem_prime_import(struct drm_device *dev, > struct dma_buf *dma_buf); > +struct drm_gem_object *drm_gem_prime_self_import(struct drm_device *dev, > + struct dma_buf *dma_buf, > + const struct dma_buf_ops *expected_ops); > > void drm_prime_gem_destroy(struct drm_gem_object *obj, struct sg_table *sg); > > -- > 2.43.0 >