From patchwork Mon May 22 11:57:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 13250247 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1546EC7EE2A for ; Mon, 22 May 2023 11:58:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233593AbjEVL60 (ORCPT ); Mon, 22 May 2023 07:58:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233352AbjEVL6Z (ORCPT ); Mon, 22 May 2023 07:58:25 -0400 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C8D38AC; Mon, 22 May 2023 04:58:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1684756692; x=1716292692; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Xm8HXFuDuHey+fE5CePuVx0wvg4tCNkUAB2IrNq4Tis=; b=bgTXbH5QjrP+B7VhsXxIhtk/e8jjub+hvP9YdMSRRP/avpVjHlL9GKPW amo8oW73vJpf/NzRWjUDfbjPtzKbfb2+IFVsERtsFi8gEhvG6pBXlhue5 N7ZolpuMB8ztPn6RvifVSLDjxFuyURPQnhfgMIQ9qRaLNLe9qq2060rsx 5rOZFCvCAUOwq0Bs+mEbLqlt57FlOxELR9EXsE99DRXdocBTpE/yp6imI L1WRw6VXFTFlfcIo2F8cjJrC/C21lOAgpV5HhP5kYjg01A+iqI6pIri+k RVICKKwq6gXfF8gRTQQeJRk56RZOBh2e/h4fZ4GtsaPKOWmHwZruBK5wC w==; X-IronPort-AV: E=McAfee;i="6600,9927,10717"; a="356128199" X-IronPort-AV: E=Sophos;i="6.00,184,1681196400"; d="scan'208";a="356128199" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 May 2023 04:57:59 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10717"; a="815660193" X-IronPort-AV: E=Sophos;i="6.00,184,1681196400"; d="scan'208";a="815660193" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by fmsmga002.fm.intel.com with ESMTP; 22 May 2023 04:57:59 -0700 From: Yi Liu To: alex.williamson@redhat.com, jgg@nvidia.com, kevin.tian@intel.com Cc: joro@8bytes.org, robin.murphy@arm.com, cohuck@redhat.com, eric.auger@redhat.com, nicolinc@nvidia.com, kvm@vger.kernel.org, mjrosato@linux.ibm.com, chao.p.peng@linux.intel.com, yi.l.liu@intel.com, yi.y.sun@linux.intel.com, peterx@redhat.com, jasowang@redhat.com, shameerali.kolothum.thodi@huawei.com, lulu@redhat.com, suravee.suthikulpanit@amd.com, intel-gvt-dev@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, linux-s390@vger.kernel.org, xudong.hao@intel.com, yan.y.zhao@intel.com, terrence.xu@intel.com, yanting.jiang@intel.com, zhenzhong.duan@intel.com, clegoate@redhat.com Subject: [PATCH v6 06/10] iommufd: Add helper to retrieve iommufd_ctx and devid Date: Mon, 22 May 2023 04:57:47 -0700 Message-Id: <20230522115751.326947-7-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230522115751.326947-1-yi.l.liu@intel.com> References: <20230522115751.326947-1-yi.l.liu@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This is needed by the vfio-pci driver to report affected devices in the hot-reset for a given device. Tested-by: Terrence Xu Signed-off-by: Yi Liu --- drivers/iommu/iommufd/device.c | 24 ++++++++++++++++++++++++ include/linux/iommufd.h | 6 ++++++ 2 files changed, 30 insertions(+) diff --git a/drivers/iommu/iommufd/device.c b/drivers/iommu/iommufd/device.c index 4571344c8508..ff3142dca96f 100644 --- a/drivers/iommu/iommufd/device.c +++ b/drivers/iommu/iommufd/device.c @@ -146,6 +146,18 @@ void iommufd_device_unbind(struct iommufd_device *idev) } EXPORT_SYMBOL_NS_GPL(iommufd_device_unbind, IOMMUFD); +struct iommufd_ctx *iommufd_device_to_ictx(struct iommufd_device *idev) +{ + return idev->ictx; +} +EXPORT_SYMBOL_NS_GPL(iommufd_device_to_ictx, IOMMUFD); + +u32 iommufd_device_to_id(struct iommufd_device *idev) +{ + return idev->obj.id; +} +EXPORT_SYMBOL_NS_GPL(iommufd_device_to_id, IOMMUFD); + static int iommufd_device_setup_msi(struct iommufd_device *idev, struct iommufd_hw_pagetable *hwpt, phys_addr_t sw_msi_start) @@ -493,6 +505,18 @@ void iommufd_access_destroy(struct iommufd_access *access) } EXPORT_SYMBOL_NS_GPL(iommufd_access_destroy, IOMMUFD); +struct iommufd_ctx *iommufd_access_to_ictx(struct iommufd_access *access) +{ + return access->ictx; +} +EXPORT_SYMBOL_NS_GPL(iommufd_access_to_ictx, IOMMUFD); + +u32 iommufd_access_to_id(struct iommufd_access *access) +{ + return access->obj.id; +} +EXPORT_SYMBOL_NS_GPL(iommufd_access_to_id, IOMMUFD); + int iommufd_access_attach(struct iommufd_access *access, u32 ioas_id) { struct iommufd_ioas *new_ioas; diff --git a/include/linux/iommufd.h b/include/linux/iommufd.h index 33fe57e95e42..e49c16cd6831 100644 --- a/include/linux/iommufd.h +++ b/include/linux/iommufd.h @@ -25,6 +25,9 @@ void iommufd_device_unbind(struct iommufd_device *idev); int iommufd_device_attach(struct iommufd_device *idev, u32 *pt_id); void iommufd_device_detach(struct iommufd_device *idev); +struct iommufd_ctx *iommufd_device_to_ictx(struct iommufd_device *idev); +u32 iommufd_device_to_id(struct iommufd_device *idev); + struct iommufd_access_ops { u8 needs_pin_pages : 1; void (*unmap)(void *data, unsigned long iova, unsigned long length); @@ -46,6 +49,9 @@ iommufd_access_create(struct iommufd_ctx *ictx, void iommufd_access_destroy(struct iommufd_access *access); int iommufd_access_attach(struct iommufd_access *access, u32 ioas_id); +struct iommufd_ctx *iommufd_access_to_ictx(struct iommufd_access *access); +u32 iommufd_access_to_id(struct iommufd_access *access); + void iommufd_ctx_get(struct iommufd_ctx *ictx); #if IS_ENABLED(CONFIG_IOMMUFD)