From patchwork Tue Jan 2 14:38:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 184367 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp4483167dyb; Tue, 2 Jan 2024 06:40:11 -0800 (PST) X-Google-Smtp-Source: AGHT+IG8jqSjJZvOSCVNwAkzkW+1GtPqe7+EBJj4Krlhu7j0B14cuFDixvUxK27s+RQrsXyCaDzy X-Received: by 2002:ac2:44c6:0:b0:50e:546b:53bb with SMTP id d6-20020ac244c6000000b0050e546b53bbmr6705726lfm.136.1704206411643; Tue, 02 Jan 2024 06:40:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704206411; cv=none; d=google.com; s=arc-20160816; b=hpxljo4kP7eAVsoH0Ic+evhqr0l5EPdekZkfeGvq8DEPCXW/YApK9fk0emRjj2oa7z uYDZ4loFYb9O8XGZxGq6o+cojmCRQ+qfwrfFWWFIRUVrp3MsbFBU1hiyJE/Y+dH5xcqg oIPEircUjxoAqF3Z3S49dYWL8Mz01AnImMU7I6pon0waRASBY9CPud66q/lN2LOXF6FZ Bb+TVZhY2AuyJGWZSf2J0QpBszYThfZ2rkDgZJXA7sMPkdgpYo+Qv/9DEkxfvrLL20tq pjvsOf6XljHYNQbFDMHggwQu3BXZGUBgf33jtJn+4EAnv/bL399xhmL37QGbPGhpJveM KDlA== 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-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14490-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id i25-20020a508719000000b0055337154dfbsi8027303edb.437.2024.01.02.06.40.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 06:40:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-14490-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; 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-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14490-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 3C9121F22DB2 for ; Tue, 2 Jan 2024 14:40:11 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CBDCE1548F; Tue, 2 Jan 2024 14:38:44 +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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1786989942326869306 X-GMAIL-MSGID: 1786989942326869306 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);