From patchwork Thu Jan 11 04:10:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 187157 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2411:b0:101:2151:f287 with SMTP id m17csp1218918dyi; Wed, 10 Jan 2024 20:11:06 -0800 (PST) X-Google-Smtp-Source: AGHT+IHnCdB5vIB+znm4n+2wTru1l3XIv+Mx4Ol+LEIcSGh/1zNjWtvLpkz0dOsRZY7sf7Lin2Yq X-Received: by 2002:a05:620a:1376:b0:783:1b7b:aa89 with SMTP id d22-20020a05620a137600b007831b7baa89mr782886qkl.79.1704946266495; Wed, 10 Jan 2024 20:11:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704946266; cv=none; d=google.com; s=arc-20160816; b=yyotH1iF4F7txE7DGIkv6JqDAqh/a1yAx1NW5oRSmdb2nOLCqqMCIAdMBh/WfjzDyp E/k7g2ElYELPmzMesivjZnm59abhL9+A1v+lTjGRnmHyNdXhRgvE9w4qVxletcTlp2Iq mRTrDXbabGW9pTJTjzhv+i8B3i2jmCLPkJy60YIYW3v97Eu9Liai14PnZG7/JKMmAg9a I3ERC1QLjmdUBI2Z2wZLoSG4YX/IdxfBlCmxvbCfqVDk7UCCmRktT+mSdlBBo+mva7Sc eMMLOMVGeTMZzngC8mUyk+vUN69T0d4UpPBmh2TYwqoHr1NFIwrcDaSlIWYm8B0JCWXL IP9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=G4fmvkcaeOHHBHLQRAT2Jn/KP4KGND5PuhBsZcLHVxg=; fh=aa7ajXSXkJe0gRz4CDJDDWs+jFd1z8IECXwIf+VZeM8=; b=xV34QJPxCbqMpsXToIP3l2bSQ1K0BOzT7UIKTokqZxn2gylFkSvTZKFzbsUNHhvYpf emH72h2ww6eNbVpGBC/voqnT05gCP1/gZK8zmB8PNI4SS79STXe9MchvRdJzyYswzbQE Anwz9bUSadh7s7FRMeEOtsIo+8l55DpAuo2jm7cxGX2s8r+MK7NfzaelyqJcxcpb7zwn dmkIWa8BdMDjdZrOQpB89SBpq1ZK2YHsjyW+fvFrPcSzC5dPwDPq7gHQo0Z6yO/edBDJ DNlOWjcCTtW/eBc4Mx7ovmD6rdypz6sROC/bfFMtEGp42JQbubvNvIGIud7r0vm4ReYt zJ9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=gB+PzIrH; spf=pass (google.com: domain of linux-kernel+bounces-23048-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-23048-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id u18-20020a05620a121200b007819059f7efsi189481qkj.766.2024.01.10.20.11.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jan 2024 20:11:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-23048-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=gB+PzIrH; spf=pass (google.com: domain of linux-kernel+bounces-23048-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-23048-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 0CC551C22DEE for ; Thu, 11 Jan 2024 04:11:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 341D55672; Thu, 11 Jan 2024 04:10:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="gB+PzIrH" Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.20]) (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 0867210F3; Thu, 11 Jan 2024 04:10:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1704946224; x=1736482224; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=eheKmIiZIGJEgkz55tUg5C8gYGgoEc13PJeJt4LC/O0=; b=gB+PzIrHkIHk7/12B7FxbgX5cSgS+ZcvaDOutlljYbbX4Qxo4hwKCwT+ 9x8HMPS0iNPU4ivEQFNfzocoKss/T1WkVYt7QNubOYA8XWg2hnXnUBRmx 4LizDIAGqudwQeJRfqc3zm5a3zqQV7TXFs6nTDTHOGrxYle9I5OJXR6S0 1O1r+atlsgN6VCMkCJ0wm1OYMgDyhW1K02Ol9kr50wTG9N/08qdlM4RQD v8ZFTMyAAyeYmucD8lRTuPncoYh83zooe1AA416P5kaTXbnGRt0w8nBcm BTUotg2nqsSipZ3ZvsN9bSVQEnW9BW3Ah0qMCk3tk0nxk60VwoN+EZkn5 g==; X-IronPort-AV: E=McAfee;i="6600,9927,10949"; a="389167612" X-IronPort-AV: E=Sophos;i="6.04,185,1695711600"; d="scan'208";a="389167612" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jan 2024 20:10:23 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10949"; a="1113691808" X-IronPort-AV: E=Sophos;i="6.04,185,1695711600"; d="scan'208";a="1113691808" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by fmsmga005.fm.intel.com with ESMTP; 10 Jan 2024 20:10:21 -0800 From: Yi Liu To: joro@8bytes.org, alex.williamson@redhat.com, jgg@nvidia.com, kevin.tian@intel.com, robin.murphy@arm.com, baolu.lu@linux.intel.com Cc: 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, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, zhenzhong.duan@intel.com, joao.m.martins@oracle.com, xin.zeng@intel.com, yan.y.zhao@intel.com, j.granados@samsung.com, binbin.wu@linux.intel.com Subject: [PATCH v11 1/8] iommu: Add cache_invalidate_user op Date: Wed, 10 Jan 2024 20:10:08 -0800 Message-Id: <20240111041015.47920-2-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240111041015.47920-1-yi.l.liu@intel.com> References: <20240111041015.47920-1-yi.l.liu@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787765736291431058 X-GMAIL-MSGID: 1787765736291431058 From: Lu Baolu The updates of the PTEs in the nested page table will be propagated to the hardware caches. Add a new domain op cache_invalidate_user for the userspace to flush the hardware caches for a nested domain through iommufd. No wrapper for it, as it's only supposed to be used by iommufd. Then, pass in invalidation requests in form of a user data array containing a number of invalidation data entries. Reviewed-by: Kevin Tian Signed-off-by: Lu Baolu Signed-off-by: Nicolin Chen Signed-off-by: Yi Liu --- include/linux/iommu.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/include/linux/iommu.h b/include/linux/iommu.h index 6291aa7b079b..93c0d12dd047 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -284,6 +284,23 @@ struct iommu_user_data { size_t len; }; +/** + * struct iommu_user_data_array - iommu driver specific user space data array + * @type: The data type of all the entries in the user buffer array + * @uptr: Pointer to the user buffer array + * @entry_len: The fixed-width length of an entry in the array, in bytes + * @entry_num: The number of total entries in the array + * + * The user buffer includes an array of requests with format defined in + * include/uapi/linux/iommufd.h + */ +struct iommu_user_data_array { + unsigned int type; + void __user *uptr; + size_t entry_len; + u32 entry_num; +}; + /** * __iommu_copy_struct_from_user - Copy iommu driver specific user space data * @dst_data: Pointer to an iommu driver specific user data that is defined in @@ -440,6 +457,13 @@ struct iommu_ops { * @iotlb_sync_map: Sync mappings created recently using @map to the hardware * @iotlb_sync: Flush all queued ranges from the hardware TLBs and empty flush * queue + * @cache_invalidate_user: Flush hardware cache for user space IO page table. + * The @domain must be IOMMU_DOMAIN_NESTED. The @array + * passes in the cache invalidation requests, in form + * of a driver data structure. The driver must update + * array->entry_num to report the number of handled + * invalidation requests. The driver data structure + * must be defined in include/uapi/linux/iommufd.h * @iova_to_phys: translate iova to physical address * @enforce_cache_coherency: Prevent any kind of DMA from bypassing IOMMU_CACHE, * including no-snoop TLPs on PCIe or other platform @@ -465,6 +489,8 @@ struct iommu_domain_ops { size_t size); void (*iotlb_sync)(struct iommu_domain *domain, struct iommu_iotlb_gather *iotlb_gather); + int (*cache_invalidate_user)(struct iommu_domain *domain, + struct iommu_user_data_array *array); phys_addr_t (*iova_to_phys)(struct iommu_domain *domain, dma_addr_t iova);