Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp1409453rdd; Wed, 10 Jan 2024 20:10:38 -0800 (PST) X-Google-Smtp-Source: AGHT+IFknzMlFMyZqNqzT0VCvBtGGpZHf72rFSeYzMvhZGf8A80pSx2FQi7O30I/h3g20eLrvQ38 X-Received: by 2002:a05:6a20:6a07:b0:199:f2bb:f166 with SMTP id p7-20020a056a206a0700b00199f2bbf166mr457587pzk.30.1704946238626; Wed, 10 Jan 2024 20:10:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704946238; cv=none; d=google.com; s=arc-20160816; b=TBH2z+HmhB9OiO21BzVBYRbl39qQrh6irslyT+Jb+1RDekOglmamJAWfXdRwKoHlAB 195fk7fDFAWSopRynu0GlDtPFKRSJCVIvrxkfaKmOmbLUIpBnt9k1WJAfD5/ixqXDs87 ydz2PFTBy6LF9UZup0NdR6or+5h4Xxey5xlzlkIAEMybjdDcxe5quJUPVt1QoC20VHPe RyP4F3e73CK8qhed+tK/kYl6pO52DN5xya7ecj89+rBtVZPqTXjHzbiQkGt7OuNYJpg1 ATlsMKRudySRc77aMxLlWRyi8+kcCo6L2uj2ZuTU3GbIFUhWORxqhhG2dicWDqmpA/Gz sjCQ== 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-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-23048-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id iz7-20020a170902ef8700b001d4e1f1eea7si217278plb.461.2024.01.10.20.10.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jan 2024 20:10:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-23048-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; 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-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-23048-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 49A46286321 for ; Thu, 11 Jan 2024 04:10:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4E4D31C29; Thu, 11 Jan 2024 04:10:26 +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 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 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); -- 2.34.1