From patchwork Thu Jan 11 04:10:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 187160 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2411:b0:101:2151:f287 with SMTP id m17csp1219258dyi; Wed, 10 Jan 2024 20:12:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IF7QiNH+icrtK3OhLkHmfMRu8L78GaZFBwQ94cxkxO+pPGG2hGLRPkYSB5keyVVigUEq7lj X-Received: by 2002:a05:6358:7e42:b0:175:76bd:2c36 with SMTP id p2-20020a0563587e4200b0017576bd2c36mr754915rwm.37.1704946326790; Wed, 10 Jan 2024 20:12:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704946326; cv=none; d=google.com; s=arc-20160816; b=B7PxtsV4B5GZwKn9rBfaFm3vyZLzDwu4bAW0HjSkyUnNtDtd/uIZVg1cJ7Ft3opItg GcFL9WX8XsJWCJHRWaLCUU2b3C9x0qEosQSGxitw4YeYlOH94s7sf32N6Zx3sus1x6Fr 2fiRl0NVU+kMStgi0p74X+JEwh8LmqyS/lQOsCKCBJaq5ThNf/m1NOD+exdkdr74u8bV BtZkV4hhA2f9LTDDeou9ANO4lchMnusiy3/Ge5SIfnj/9OovciwCjrl4w6lgTjByOot+ nr5A++607eRrM4YqjpmkpmWPoTihFgOUUrTvnPoZdT4ne4H3L6k/LdpednpAfrgyT7XM 0Tmg== 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=JFzCBEpQD8yDOKlEdyHl4z5fKVBln57rI3WX0tRK/3w=; fh=aa7ajXSXkJe0gRz4CDJDDWs+jFd1z8IECXwIf+VZeM8=; b=yG8NHY9JdqyKU4+YoDhP10NJ0s/mge05KLgKpkyOX4n5CQhgBcSYduSzhe33SuLExy MqB3czjnS+B/BXPgy8P8+OcWSmRLv1yX27seZXee8P+1Y3rOLnTZSGKMaPc7sSZNLlnD c+vaFC8ocCO2ksT1lYoDh+V6J9J/0xAvySn9yEREf6aydyM0ZNzoQcPOypVbZzBJBlQg uFhJqErGVjKIoOc1MzKcKL4fXCjPlPfkkS9THqZjosGtUWo80gAKxbtXHiCYem+f3MUY gwxwjUe5EG3xxN4wzA9ZGc1mlVAESIiXBKJLB+ZoQEg4nHzQu3FtTioLeGrbBxdWnQu3 nxvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=e5YZxkBb; spf=pass (google.com: domain of linux-kernel+bounces-23052-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-23052-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 h13-20020a17090aa88d00b0028dbd5b9f76si263038pjq.116.2024.01.10.20.12.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jan 2024 20:12:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-23052-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=e5YZxkBb; spf=pass (google.com: domain of linux-kernel+bounces-23052-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-23052-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 7294428637A for ; Thu, 11 Jan 2024 04:12:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EEB1DDDA6; Thu, 11 Jan 2024 04:10:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="e5YZxkBb" 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 AEF746139; Thu, 11 Jan 2024 04:10:28 +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=1704946228; x=1736482228; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=jR0MOQ0kqVSVT6BksVmkq7HuXTI6cH5F4jkXr2f/2Kg=; b=e5YZxkBbbPGlNJfrm3fZHvnI2HlnrNbr5pf8sGd/uxjsQsPxPLr7SePe tlXQbQNr+qkSe/8l59BYOJnMRCEu9Coo2a2L1I4pKVURoPfMVN9iOuSX+ p9ESdCUtAiLntpaRials0aJ4q+1UrSMbgAu7Y9fkaX1RxKOL45yJ290CH 7b2v49d44vg8w3QvHvvndbUYuN+sIM2GfGRUJZbWwEoKEncYjhioCwl7Z FyIu2yuqq2wYRYLiWt9GQJmGnYW8fvfI4s4mQYTxPS+zQkTLKgAIK66Lx VpzEctFUGNVzrG/8CIsgnC7Igl2Sb+h39raAOLMDHRHhkKEe4YXGJ9HXw A==; X-IronPort-AV: E=McAfee;i="6600,9927,10949"; a="389167653" X-IronPort-AV: E=Sophos;i="6.04,185,1695711600"; d="scan'208";a="389167653" 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:28 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10949"; a="1113691862" X-IronPort-AV: E=Sophos;i="6.04,185,1695711600"; d="scan'208";a="1113691862" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by fmsmga005.fm.intel.com with ESMTP; 10 Jan 2024 20:10:26 -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 4/8] iommufd/selftest: Add mock_domain_cache_invalidate_user support Date: Wed, 10 Jan 2024 20:10:11 -0800 Message-Id: <20240111041015.47920-5-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: 1787765799665494485 X-GMAIL-MSGID: 1787765799665494485 From: Nicolin Chen Add mock_domain_cache_invalidate_user() data structure to support user space selftest program to cover user cache invalidation pathway. Reviewed-by: Kevin Tian Signed-off-by: Nicolin Chen Co-developed-by: Yi Liu Signed-off-by: Yi Liu --- drivers/iommu/iommufd/iommufd_test.h | 18 ++++++++++ drivers/iommu/iommufd/selftest.c | 50 ++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) diff --git a/drivers/iommu/iommufd/iommufd_test.h b/drivers/iommu/iommufd/iommufd_test.h index 7910fbe1962d..09dfc8aa65c4 100644 --- a/drivers/iommu/iommufd/iommufd_test.h +++ b/drivers/iommu/iommufd/iommufd_test.h @@ -148,4 +148,22 @@ struct iommu_hwpt_selftest { __u32 iotlb; }; +/* Should not be equal to any defined value in enum iommu_hwpt_invalidate_data_type */ +#define IOMMU_HWPT_INVALIDATE_DATA_SELFTEST 0xdeadbeef +#define IOMMU_HWPT_INVALIDATE_DATA_SELFTEST_INVALID 0xdadbeef + +/** + * struct iommu_hwpt_invalidate_selftest - Invalidation data for Mock driver + * (IOMMU_HWPT_INVALIDATE_DATA_SELFTEST) + * @flags: Invalidate flags + * @iotlb_id: Invalidate iotlb entry index + * + * If IOMMU_TEST_INVALIDATE_ALL is set in @flags, @iotlb_id will be ignored + */ +struct iommu_hwpt_invalidate_selftest { +#define IOMMU_TEST_INVALIDATE_FLAG_ALL (1 << 0) + __u32 flags; + __u32 iotlb_id; +}; + #endif diff --git a/drivers/iommu/iommufd/selftest.c b/drivers/iommu/iommufd/selftest.c index 022ef8f55088..23879135d1c3 100644 --- a/drivers/iommu/iommufd/selftest.c +++ b/drivers/iommu/iommufd/selftest.c @@ -473,9 +473,59 @@ static void mock_domain_free_nested(struct iommu_domain *domain) kfree(mock_nested); } +static int +mock_domain_cache_invalidate_user(struct iommu_domain *domain, + struct iommu_user_data_array *array) +{ + struct mock_iommu_domain_nested *mock_nested = + container_of(domain, struct mock_iommu_domain_nested, domain); + struct iommu_hwpt_invalidate_selftest inv; + u32 processed = 0; + int i = 0, j; + int rc = 0; + + if (array->type != IOMMU_HWPT_INVALIDATE_DATA_SELFTEST) { + rc = -EINVAL; + goto out; + } + + for ( ; i < array->entry_num; i++) { + rc = iommu_copy_struct_from_user_array(&inv, array, + IOMMU_HWPT_INVALIDATE_DATA_SELFTEST, + i, iotlb_id); + if (rc) + break; + + if (inv.flags & ~IOMMU_TEST_INVALIDATE_FLAG_ALL) { + rc = -EOPNOTSUPP; + break; + } + + if (inv.iotlb_id > MOCK_NESTED_DOMAIN_IOTLB_ID_MAX) { + rc = -EINVAL; + break; + } + + if (inv.flags & IOMMU_TEST_INVALIDATE_FLAG_ALL) { + /* Invalidate all mock iotlb entries and ignore iotlb_id */ + for (j = 0; j < MOCK_NESTED_DOMAIN_IOTLB_NUM; j++) + mock_nested->iotlb[j] = 0; + } else { + mock_nested->iotlb[inv.iotlb_id] = 0; + } + + processed++; + } + +out: + array->entry_num = processed; + return rc; +} + static struct iommu_domain_ops domain_nested_ops = { .free = mock_domain_free_nested, .attach_dev = mock_domain_nop_attach, + .cache_invalidate_user = mock_domain_cache_invalidate_user, }; static inline struct iommufd_hw_pagetable *