Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp6580277rdb; Tue, 2 Jan 2024 06:39:34 -0800 (PST) X-Google-Smtp-Source: AGHT+IHbWgkDqNQ/Cr584D6qpdh3dOlfRQkyyT1GravBn4l5a/sJWU7OhjI6/Xys9wfZjDMqoYI6 X-Received: by 2002:a05:622a:24c:b0:428:327c:311c with SMTP id c12-20020a05622a024c00b00428327c311cmr881073qtx.53.1704206374104; Tue, 02 Jan 2024 06:39:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704206374; cv=none; d=google.com; s=arc-20160816; b=hqopd8dK/L/K2/39ofWKDQySqBmXxdWapE3eqeNLAH47BA46FQyPh12DOqcEfCjyFB L+L8wuq8Uq0eFmmCfY7xWiGB6nJO3gBp2dkTPmC7jj+o/qeHnCG1EdeoHZ0s2z3rLwnc 2qkCewDLAppqCp4nwJWGY84gMDXLvyfdDuX0/GDVUIYaXUIKYnbO8AlimIgaRGLmmgar 7D5wR/JU9SbkHyKqNlwFcOHuTlcPSXLKTv5HfWMDTH632dTkmSdl8ppvLCT7Qr3LO1Sm JrGx7tC6xsU0EKUERdMUJb5Sy52LLlXHzI3sFu2pseY3SHMiz0h3aHZQ8CF3KozIUtaV 74sw== 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=cmmE61uWQDmtK6kaEvaJmx5NWQkq2czzSV7UX/pgsTU=; fh=JbgkfaGVOLJQIgFMcRSNKOzjVQFwxW1pSzjP6daOUwc=; b=OIEc/gFcPWarI23p45TsYQpmpnHVLKeb5BFoWzZuPg/lhGcKpL88F7n7DREVP+yi41 aQCUaO/YKbkzDk+gSu0oLCTfxSl4Y+1w6YrILBdrL3vAyP/xmTk1Iw40m2PThf71IGYw dbketwfVkJRTPPcvFHn4yVO0GKSBrTuqhVr/xcGE3VJ3xGl0kICp/bi3GZal7NLk8J3r xuPh7HJ6VC+Q8pgQwtAUDhaQjhsu2C8mHPc10HZ9MjWKxBM+fsz8GtipqiXfRbVSNyiT mIBOSfDertmWZTUER4Kj3tABLbANs3hIWEzjYLmJ18t8XJinGDhjYejRoezBraxsW+Hu Njag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ijH6wurV; spf=pass (google.com: domain of linux-kernel+bounces-14490-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14490-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id v40-20020a05622a18a800b004257ba79a12si26417130qtc.715.2024.01.02.06.39.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 06:39:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-14490-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ijH6wurV; spf=pass (google.com: domain of linux-kernel+bounces-14490-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14490-linux.lists.archive=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 D01461C221DD for ; Tue, 2 Jan 2024 14:39:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EC05514F61; Tue, 2 Jan 2024 14:38:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="ijH6wurV" X-Original-To: linux-kernel@vger.kernel.org Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) (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 5BFEF12E70; Tue, 2 Jan 2024 14:38:39 +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=1704206319; x=1735742319; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Y9zEpidkk+p5pkry7bIuq4ZUGve0T4w0aUbFgMriFaU=; b=ijH6wurV3hdAHIIaT9POzAP1MCuGujZ52C48D7K68O+36lAJpqZ1do6J z4D2VYRCJwbfNmJAF7N24EK3yP9+MFf2x6FIyo6gwzOyNAT4it4TBERZ5 NU2s0AOi+GyITKaogWTkLpu5MKTe37AGCU7nlScVX6fCEbCzlqeOxuMtZ KyjrXrntd8lsJLJtbr9memzX2B+qZFTkA1tdcvjVg/BietnfG+m+UBnhd Z7CxxDMvSfXq4Pb1l+MUjOG9yju67GFYPwxN4637t5illMUrxFiGWK677 Rxcs1Xo2cgWmA6UmUuo8EZ4JwcIaMSZTkqAY0uakj3/YRAy3kDucjbL4i g==; X-IronPort-AV: E=McAfee;i="6600,9927,10941"; a="10270411" X-IronPort-AV: E=Sophos;i="6.04,325,1695711600"; d="scan'208";a="10270411" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jan 2024 06:38:39 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10941"; a="923234251" X-IronPort-AV: E=Sophos;i="6.04,325,1695711600"; d="scan'208";a="923234251" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by fmsmga001.fm.intel.com with ESMTP; 02 Jan 2024 06:38:37 -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 Subject: [PATCH v10 01/10] iommu: Add cache_invalidate_user op Date: Tue, 2 Jan 2024 06:38:25 -0800 Message-Id: <20240102143834.146165-2-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240102143834.146165-1-yi.l.liu@intel.com> References: <20240102143834.146165-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 Content-Transfer-Encoding: 8bit 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 conatining a number of invalidation data entries. Signed-off-by: Lu Baolu Reviewed-by: Kevin Tian 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); -- 2.34.1