From patchwork Mon Jul 24 11:04:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 124863 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9010:0:b0:3e4:2afc:c1 with SMTP id l16csp1734274vqg; Mon, 24 Jul 2023 04:32:49 -0700 (PDT) X-Google-Smtp-Source: APBJJlGndCRuOGVKRyg5X1Q2mgVVMB/byvuF2g72M3iVZlFufpG8DeQRjpxum4lQBelzn9tI77J2 X-Received: by 2002:a17:902:d4cc:b0:1a2:a904:c42e with SMTP id o12-20020a170902d4cc00b001a2a904c42emr12873546plg.24.1690198369012; Mon, 24 Jul 2023 04:32:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690198368; cv=none; d=google.com; s=arc-20160816; b=N5FoMTQg7pOr5rFNfRaShnUoG1kTYSETPgRa3Qya42BvPO8AKXZCqg3NUyfRKtyLHb prhGqwJ871KQdyhe8fKoIiyS7tx/UJ8i3tNm3x6OfqYT+dEdCz6K27y8AaPNNXOEtpkm bWtdcQcBe+udktBi6m9yCXtPWsjb6FH76BoKHS5ENNHTbUt2ylhNyU7jDRK+YzAdVeT2 93ySn331HmPow12GJkCmIdalU6verpWH/aceDWUddjcj63Oskurold8MOPWUddD46bCw DuNiVTOl7/UkSQMjZbdWr0cS9CGZbf6gXfua+vEfbrQDHBT/8MJPOPr0CD+HfVSzv+6u 3kHg== 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=JQX9phtgXzaU/yS4G592d2vAzkuwEjYtBco2LWA2ljM=; fh=25kVo4cotgMzE250R6E3K5ES7E7C2JawiavlW0h5mKU=; b=AbHVWdpuOJ9tnSCOCJY+ksJAtLC1bheoj4nZjeICZRyZHO+8ynN6t23txvXmqC/+0R qLlvcWVFDfvn8uygJ5A01/KSrcrhV1Pr8Eo4I3zbofaBowzp8nAMd6wGPWTh1e1TIBjk ppRLJAgmf0+7K85QGlzed+BwmD7TptSbk8mXcTCrHJ2RQ4LZ6zMk8xO9d3DQGgLfKzDJ 0QgvdWEcKxiZE44X00KQQX+EbyPHxx/1vJQDlXns7xcS3XGGeWFhH2UtPTC6rYSJUI8e z+ObGWYIdRmpUe0EL75F8Q565IVAbrIcf6nyYv2ItxN3JnC41Mp+JgrtI311dCRUyTgU Zwvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="eAYudO/j"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id le13-20020a170902fb0d00b001b84f9263e7si8256217plb.325.2023.07.24.04.32.35; Mon, 24 Jul 2023 04:32:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="eAYudO/j"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232733AbjGXLFP (ORCPT + 99 others); Mon, 24 Jul 2023 07:05:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58610 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230023AbjGXLFD (ORCPT ); Mon, 24 Jul 2023 07:05:03 -0400 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2D4B610C3; Mon, 24 Jul 2023 04:04:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1690196677; x=1721732677; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Jdb8ZB5daKdGFPrTc/NRXCndQLaxOJW2ZTy0hfrrfYc=; b=eAYudO/jVBxCKMJ9eWXTRpjrjtpVWzECmCkofr6AUgxEMLLNQnsMDdAv k4FV73GZ7K1zk5/5qzA+PpePp91RSqzQM380wxA89wwuP+ykyhYOCZkqJ wNEb2QB6tSWSfpLIjdnquMIqSRa2hia8RIgxQlu1rqUA0HbdznO4E/PEV CGakfMMYGMAj1J/A/IW5io+KaBm+7O2Pix7T410+QEBKmLVFWPbzcZwH3 ctCRY/vFODNG+eBReRcXRzjuZkaAhW4Tu0gDzyiYAt49sRwX8hb5yeigO gxgwInsdxVl6l+6IyoMNs1SBNX9rfqrKq1l/higY7TnMR0gMLQ6F3q96h w==; X-IronPort-AV: E=McAfee;i="6600,9927,10780"; a="347013321" X-IronPort-AV: E=Sophos;i="6.01,228,1684825200"; d="scan'208";a="347013321" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Jul 2023 04:04:25 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10780"; a="815775871" X-IronPort-AV: E=Sophos;i="6.01,228,1684825200"; d="scan'208";a="815775871" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by FMSMGA003.fm.intel.com with ESMTP; 24 Jul 2023 04:04:22 -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 Subject: [PATCH v3 12/17] iommufd/selftest: Add .get_resv_regions() for mock_dev Date: Mon, 24 Jul 2023 04:04:01 -0700 Message-Id: <20230724110406.107212-13-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230724110406.107212-1-yi.l.liu@intel.com> References: <20230724110406.107212-1-yi.l.liu@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772301444747871350 X-GMAIL-MSGID: 1772301444747871350 This makes mock_dev to report resv_regions. Signed-off-by: Yi Liu --- drivers/iommu/iommufd/selftest.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/drivers/iommu/iommufd/selftest.c b/drivers/iommu/iommufd/selftest.c index 271c6c261eb4..e40780db88b5 100644 --- a/drivers/iommu/iommufd/selftest.c +++ b/drivers/iommu/iommufd/selftest.c @@ -292,6 +292,32 @@ static void mock_domain_set_plaform_dma_ops(struct device *dev) */ } +static void iommufd_test_get_resv_regions(struct device *dev, + struct list_head *head) +{ + struct mock_dev *mdev = container_of(dev, struct mock_dev, dev); + struct interval_tree_node *reserved, *next; + + down_read(&mdev->reserved_rwsem); + for (reserved = interval_tree_iter_first(&mdev->reserved_itree, 0, ULONG_MAX); + reserved; reserved = next) { + struct iommu_resv_region *resv; + + next = interval_tree_iter_next(reserved, 0, ULONG_MAX); + /* Only adds IOMMU_RESV_DIRECT so far */ + resv = iommu_alloc_resv_region(reserved->start, + reserved->last + 1 - reserved->start, + IOMMU_READ | IOMMU_WRITE, + IOMMU_RESV_DIRECT, + GFP_ATOMIC); + if (!resv) + break; + + list_add_tail(&resv->list, head); + } + up_read(&mdev->reserved_rwsem); +} + static const struct iommu_ops mock_ops = { .owner = THIS_MODULE, .pgsize_bitmap = MOCK_IO_PAGE_SIZE, @@ -299,6 +325,7 @@ static const struct iommu_ops mock_ops = { .hw_info = mock_domain_hw_info, .domain_alloc = mock_domain_alloc, .capable = mock_domain_capable, + .get_resv_regions = iommufd_test_get_resv_regions, .set_platform_dma_ops = mock_domain_set_plaform_dma_ops, .default_domain_ops = &(struct iommu_domain_ops){