From patchwork Tue Jan 7 14:27:09 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xu Yilun X-Patchwork-Id: 13930047 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E8B971991CA; Wed, 8 Jan 2025 02:28:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736303317; cv=none; b=N1GUyI3hXSWRugOr6LvikQznPT2Ta2unzwwolXQsJTZ0sArjw0E/R6qUoL/mT3f9Qlg88E/1AvlH/ZL3kT7tQwEsufH3kADfbSUb8q6jUITHSnigOYmc9flZGCoDTm2OVYxKhOGTuR6BZ0+bIeX1kocKhXMIQad8NBdcWXX84Xc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736303317; c=relaxed/simple; bh=F0o6l345++Qco2fqWYYKPWB6A9m+I3zwAF5W1WMcfyA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=oFLQFxcRuoTz9uweiDZldvdQA2a2RDcATx9T+USKgxsdwtrpV03VMZDbw6soAh/OtKshiu6iy59gOhmzFIRvrN2+T9fhGdWp5ve8knxNJXt5uiTM7J+WaSmX+6IcJZDzmWslpVMsOjYQ5r/bgVbgRnCvjifxlueaIr36rWOMaIE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=NmZqvgKQ; arc=none smtp.client-ip=198.175.65.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="NmZqvgKQ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1736303316; x=1767839316; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=F0o6l345++Qco2fqWYYKPWB6A9m+I3zwAF5W1WMcfyA=; b=NmZqvgKQ/1lY2BEAONQZ/CUIpSr5JAeAxd1R3IpGe3NUzWucaq5vmkHI 4DhoKW4K3w9Altw5vBWzq2PC+SzxoCa6lAVc/579LyRAFM8qaptE2xnV3 BLs4HoGkcdyya9fVdm2L7rUaLLxQx5Ce1MC1tr7pgUR0dtUHOY0M3vnVZ QoKmrga0qddkd3rzKQ87HNOoRdmexlIjjz9VFyuI7X6jA+DkaNHTvVNEh 8+6mvG3kh7qwGCK734dqul5+jhIxMxNz/D2MVonMFf9cbKQDcGUzov/0F wxH+LegBvM8n0AKMCvzaEl/lvNyVFRSGSebmXvnIbdiN5uwoKEoH7x/yR A==; X-CSE-ConnectionGUID: 8104q0QoQc+QP2sU2NdFVA== X-CSE-MsgGUID: ItZ2BB8cQpCwNiiz1G6uiw== X-IronPort-AV: E=McAfee;i="6700,10204,11308"; a="47010452" X-IronPort-AV: E=Sophos;i="6.12,296,1728975600"; d="scan'208";a="47010452" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Jan 2025 18:28:36 -0800 X-CSE-ConnectionGUID: IiAlLdr9QPSpM57H4QGriw== X-CSE-MsgGUID: WBxJUeAuQ4aLnvdrp+VNWQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,224,1728975600"; d="scan'208";a="103793561" Received: from yilunxu-optiplex-7050.sh.intel.com ([10.239.159.165]) by orviesa008.jf.intel.com with ESMTP; 07 Jan 2025 18:28:31 -0800 From: Xu Yilun To: kvm@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-media@vger.kernel.org, linaro-mm-sig@lists.linaro.org, sumit.semwal@linaro.org, christian.koenig@amd.com, pbonzini@redhat.com, seanjc@google.com, alex.williamson@redhat.com, jgg@nvidia.com, vivek.kasireddy@intel.com, dan.j.williams@intel.com, aik@amd.com Cc: yilun.xu@intel.com, yilun.xu@linux.intel.com, linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org, lukas@wunner.de, yan.y.zhao@intel.com, daniel.vetter@ffwll.ch, leon@kernel.org, baolu.lu@linux.intel.com, zhenzhong.duan@intel.com, tao1.su@intel.com Subject: [RFC PATCH 02/12] vfio: Export vfio device get and put registration helpers Date: Tue, 7 Jan 2025 22:27:09 +0800 Message-Id: <20250107142719.179636-3-yilun.xu@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250107142719.179636-1-yilun.xu@linux.intel.com> References: <20250107142719.179636-1-yilun.xu@linux.intel.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Vivek Kasireddy These helpers are useful for managing additional references taken on the device from other associated VFIO modules. Original-patch-by: Jason Gunthorpe Signed-off-by: Vivek Kasireddy --- drivers/vfio/vfio_main.c | 2 ++ include/linux/vfio.h | 2 ++ 2 files changed, 4 insertions(+) diff --git a/drivers/vfio/vfio_main.c b/drivers/vfio/vfio_main.c index 1fd261efc582..620a3ee5d04d 100644 --- a/drivers/vfio/vfio_main.c +++ b/drivers/vfio/vfio_main.c @@ -171,11 +171,13 @@ void vfio_device_put_registration(struct vfio_device *device) if (refcount_dec_and_test(&device->refcount)) complete(&device->comp); } +EXPORT_SYMBOL_GPL(vfio_device_put_registration); bool vfio_device_try_get_registration(struct vfio_device *device) { return refcount_inc_not_zero(&device->refcount); } +EXPORT_SYMBOL_GPL(vfio_device_try_get_registration); /* * VFIO driver API diff --git a/include/linux/vfio.h b/include/linux/vfio.h index 000a6cab2d31..2258b0585330 100644 --- a/include/linux/vfio.h +++ b/include/linux/vfio.h @@ -279,6 +279,8 @@ static inline void vfio_put_device(struct vfio_device *device) int vfio_register_group_dev(struct vfio_device *device); int vfio_register_emulated_iommu_dev(struct vfio_device *device); void vfio_unregister_group_dev(struct vfio_device *device); +bool vfio_device_try_get_registration(struct vfio_device *device); +void vfio_device_put_registration(struct vfio_device *device); int vfio_assign_device_set(struct vfio_device *device, void *set_id); unsigned int vfio_device_set_open_count(struct vfio_device_set *dev_set);