From patchwork Wed Dec 27 16:13:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 183496 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp1525246dyb; Wed, 27 Dec 2023 08:15:04 -0800 (PST) X-Google-Smtp-Source: AGHT+IGoBUjKwfZpQQHt086wadB3U0s59tZo94xb+5N+y8M7wTsQsa/gzTVHIO3QT/g2HXHEAibJ X-Received: by 2002:a05:6a20:bc98:b0:195:ebca:3d58 with SMTP id fx24-20020a056a20bc9800b00195ebca3d58mr1130885pzb.115.1703693704526; Wed, 27 Dec 2023 08:15:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703693704; cv=none; d=google.com; s=arc-20160816; b=z1bf5bCFs+LupVNyWYUZIw5hkw82KdcJl8d75CTihg5SPY2E4NfxLf6tufKl9kzLaI PKOOi/4LygE2E32NWAgW/xiVPxf/hY+7qEvVdBaLIzI7aIGGH3TmKgUfMoOL7naemMGx Ry1jrXOqIDGGKUc4PuSSIP/e89kix3reGAE4msaXaFwlax2yOw3wANEHrSaJf4THQAS7 sdLnYb8KSZsNr/mTxro3jUysBWOjiDZDWBP3qKPTJ/C3u7u2Ty1k4eX4m2YbL04HPQck s1fPUptXvgm9EpKmxnw1+URweGVYvjUMK7xMBA847ln9xZDj8iUOabfdXwXxt03Qh44j aabA== 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=piJTpE8t2TocI5lzNgP0mFifnJi+7CQhqa3VdVttssv1YGkGTWNQIkJ14vzMgTJ+RS Hb/Bku6YDJmxuMfRS3FDGo/axt/aJdE4pmlzg8xU2jbDhlWltKjn6a8gRN3H9wA4oC96 hfGZzCcYXoLzdQSxu8AawiEyzQVA0DDZIUd2AJ8DcaNpgEtD2IWAKl50HkAPNODs/UZl Z8wSQpAGZFfMLVWM+77tWJcrbZcVjqVZAUSAMRPHpZf4JTkXpj5nUwQErFTM+HX0ytEN /8sXaF3uY9k2uhNSAKbOUW58LUi5ranISmNeLK2KFL1LPLtoPvOOK83Xc6nRfCx6tuxM ZyUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=VzEPdn9z; spf=pass (google.com: domain of linux-kernel+bounces-12106-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-12106-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id y3-20020a634943000000b005cdf488ba0asi9472403pgk.746.2023.12.27.08.15.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Dec 2023 08:15:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-12106-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=VzEPdn9z; spf=pass (google.com: domain of linux-kernel+bounces-12106-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-12106-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 4916D281AC1 for ; Wed, 27 Dec 2023 16:15:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 05F5646B9F; Wed, 27 Dec 2023 16:14:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="VzEPdn9z" X-Original-To: linux-kernel@vger.kernel.org Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.115]) (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 0A3E545BF1; Wed, 27 Dec 2023 16:14:00 +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=1703693641; x=1735229641; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Y9zEpidkk+p5pkry7bIuq4ZUGve0T4w0aUbFgMriFaU=; b=VzEPdn9zz4V/O3L8NwWtvqge0g7ce3mkxCY4iDmZ1pSklFbM6t+0DPOD GoMiECOXeyvqxKJtS2rWpIQQdDvtWYkC962hwuBEp7DYx1j7lcVdcDDwq 5FTXk65n1sJgmTB356eGEd5BqKLRI9k8IDwk2g+imbeXWfQv+jjWX53tE bcb48MZ8iiXeotdS6CW98LXY/YeA/g1brgTf467zcXlHlMWIFuSw5H3Ri roG71+YO6+lymMlrsWC/fGoctMNZ3yiEYsAJpOkpZCDSyqYRTXmzsj7HZ aP+yMD8vyhx4z2hLgynpvSko3bkQ1oDvVs6BHgFqLViSMQ+GaceYmSoux A==; X-IronPort-AV: E=McAfee;i="6600,9927,10936"; a="396186182" X-IronPort-AV: E=Sophos;i="6.04,309,1695711600"; d="scan'208";a="396186182" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Dec 2023 08:13:59 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10936"; a="781775182" X-IronPort-AV: E=Sophos;i="6.04,309,1695711600"; d="scan'208";a="781775182" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by fmsmga007.fm.intel.com with ESMTP; 27 Dec 2023 08:13:58 -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 v8 01/10] iommu: Add cache_invalidate_user op Date: Wed, 27 Dec 2023 08:13:45 -0800 Message-Id: <20231227161354.67701-2-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231227161354.67701-1-yi.l.liu@intel.com> References: <20231227161354.67701-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: 1786452329778935563 X-GMAIL-MSGID: 1786452329778935563 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);