From patchwork Fri Oct 20 09:24:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 155921 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp929415vqb; Fri, 20 Oct 2023 02:26:47 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFPaHORImBeO2BnDCe64KRyb3+uqN10hw8MNBVSlEPdy38VhpP5oIW0DWYMXa/aRNE0LOWc X-Received: by 2002:a17:902:7407:b0:1ca:86db:1d31 with SMTP id g7-20020a170902740700b001ca86db1d31mr1416674pll.7.1697794006729; Fri, 20 Oct 2023 02:26:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697794006; cv=none; d=google.com; s=arc-20160816; b=U4LQQ/9SWxnKrN2cnUyEF3iLOE/MRLNND//hpUDHWn+3TrKWZcUfozebW6keKNvjc5 /tKKnZHjPh8iolnXAu3G+NPujwkp7aRBehggaeLhQOX9ZD2uBVB088gn1OGl9brBTmdz 0f9ja5p3sNj0x6Kic3eFgoFzitXlAzsPv8k+pbzXm2u2z+75gpd9ysQOsz6dVEdXEnxm sgc1DIyUEAxyMs9fA6bcfijlV/iu4HYHrJy8RIWLVuIODP22aWhZAeiS/AvUEHdlHhyG PIjQ/T/R0h9wXwudb6LMDuHsxRa0ntfZQafGKPJdtGHTCDegd4d4e0Po190wror+vXlh VbRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Cr5DSJXszzqG3oGxpqgFAb5Hczun0AIKx/KY7dbq06Y=; fh=AYfEg8UxxCZNlRHxnJWvHuqsheVQzM8ymhb/+J0VVdk=; b=CiUNtRW7YyTHFvjCSQOHUfmOnUCk62pXNiyykkI4ya+HVeeTxA4+JunrpIn2bGEtBF dwh+55kGeLSO91W1AxUl3HwmmqdPv1Ern96h6q9jchkSgyPMn/1Y8rXz96nVLgwHlVO3 RTNoa2W/8RA6tNneQ3Bg5ncKwczOAX/KzlhyMCsl4g7HSjHz5pVNkcRl2yQ9ZyF0R9R9 NaT/mt1ns1GiGcZT6pgAhH8G/LDJS6sT3GAGunzTNbj/L/NZ5iBl5xg0xegrUnNJ7vdp W1laMcE5tF+tl+UbY3y7nj7ZsNlBUCQpKj2zBP0kYCeE2RKEC/KISJJdXRenopW3a2Y5 UZQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=GZjN6cWd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id b2-20020a170902d50200b001c5b9ef1d34si1472021plg.340.2023.10.20.02.26.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 02:26:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=GZjN6cWd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id B24C7808D200; Fri, 20 Oct 2023 02:25:23 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376728AbjJTJY6 (ORCPT + 25 others); Fri, 20 Oct 2023 05:24:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53268 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376682AbjJTJYg (ORCPT ); Fri, 20 Oct 2023 05:24:36 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B1CB0D55; Fri, 20 Oct 2023 02:24:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1697793873; x=1729329873; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=hmwgRc80fGvIZ+07OlU/ados8MLJWNBOFdMd2h2m8n4=; b=GZjN6cWdNVTdSIqfizbYRDjKtePQztrD9i3oZGmnwLqJJpoD/qSg4XW+ AAEhfbuhHDZkfn/yHf7jU39kkzLCkbBHOK+UKmMI6byXSH3hZRVf2PFqG Cm7//hlyCZjKBMN2L+lQHjzV5pD81l+Zi7jGHdpr0elLAeEzbckCse/Fc R8grp0DAgsp9C20DSmGE9zpbZvsNJok0o1IlKVhAIYIGiGkRDhN0FR0kf IeYq9HRvM8HB8k1Mt7s7T90oX2eC+0feqkY7hmHKTxkOZVpz2bo40iVWy VaGZp+q0LcEonvJhifS8LfeOHPbaOSnUkszn09ohywnjRDTmnF+/fSd0M A==; X-IronPort-AV: E=McAfee;i="6600,9927,10868"; a="472685508" X-IronPort-AV: E=Sophos;i="6.03,238,1694761200"; d="scan'208";a="472685508" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Oct 2023 02:24:30 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10868"; a="750859682" X-IronPort-AV: E=Sophos;i="6.03,238,1694761200"; d="scan'208";a="750859682" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by orsmga007.jf.intel.com with ESMTP; 20 Oct 2023 02:24:30 -0700 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 Subject: [PATCH v5 4/6] iommufd/selftest: Add mock_domain_cache_invalidate_user support Date: Fri, 20 Oct 2023 02:24:24 -0700 Message-Id: <20231020092426.13907-5-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231020092426.13907-1-yi.l.liu@intel.com> References: <20231020092426.13907-1-yi.l.liu@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Fri, 20 Oct 2023 02:25:23 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780266048631581552 X-GMAIL-MSGID: 1780266048631581552 From: Nicolin Chen Add mock_domain_cache_invalidate_user() data structure to support user space selftest program to cover user cache invalidation pathway. Signed-off-by: Nicolin Chen Signed-off-by: Yi Liu --- drivers/iommu/iommufd/iommufd_test.h | 17 +++++++++++ drivers/iommu/iommufd/selftest.c | 43 ++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/drivers/iommu/iommufd/iommufd_test.h b/drivers/iommu/iommufd/iommufd_test.h index 440ec3d64099..a96838516db9 100644 --- a/drivers/iommu/iommufd/iommufd_test.h +++ b/drivers/iommu/iommufd/iommufd_test.h @@ -127,4 +127,21 @@ struct iommu_hwpt_selftest { __u32 iotlb; }; +/** + * struct iommu_hwpt_invalidate_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_ALL (1ULL << 0) + __u32 flags; + __u32 iotlb_id; +}; + +#define IOMMU_TEST_INVALIDATE_ERR_FETCH 0xdeadbeee +#define IOMMU_TEST_INVALIDATE_ERR_REQ 0xdeadbeef + #endif diff --git a/drivers/iommu/iommufd/selftest.c b/drivers/iommu/iommufd/selftest.c index 5f513c5d6876..abd942cf3a79 100644 --- a/drivers/iommu/iommufd/selftest.c +++ b/drivers/iommu/iommufd/selftest.c @@ -404,9 +404,52 @@ 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, + u32 *error_code) +{ + struct mock_iommu_domain_nested *mock_nested = + container_of(domain, struct mock_iommu_domain_nested, domain); + struct iommu_hwpt_invalidate_selftest inv; + int rc = 0; + int i, j; + + if (domain->type != IOMMU_DOMAIN_NESTED) + return -EINVAL; + + for (i = 0; i < array->entry_num; i++) { + rc = iommu_copy_struct_from_user_array(&inv, array, + IOMMU_HWPT_DATA_SELFTEST, + i, iotlb_id); + if (rc) { + *error_code = IOMMU_TEST_INVALIDATE_ERR_FETCH; + goto err; + } + /* Invalidate all mock iotlb entries and ignore iotlb_id */ + if (inv.flags & IOMMU_TEST_INVALIDATE_ALL) { + for (j = 0; j < MOCK_NESTED_DOMAIN_IOTLB_NUM; j++) + mock_nested->iotlb[j] = 0; + continue; + } + /* Treat out-of-boundry iotlb_id as a request error */ + if (inv.iotlb_id > MOCK_NESTED_DOMAIN_IOTLB_ID_MAX) { + *error_code = IOMMU_TEST_INVALIDATE_ERR_REQ; + rc = -EINVAL; + goto err; + } + mock_nested->iotlb[inv.iotlb_id] = 0; + } + +err: + array->entry_num = i; + 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 *