Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp1761795rdb; Mon, 9 Oct 2023 01:53:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGUgu+8FTWaK06aCVdosEQ/SFMbBULe8X4JQM9/9gPtnMw2uBcLhwXWYZhHCYntYA+psXls X-Received: by 2002:a05:6358:880e:b0:143:8e40:917b with SMTP id hv14-20020a056358880e00b001438e40917bmr16216854rwb.9.1696841582260; Mon, 09 Oct 2023 01:53:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696841582; cv=none; d=google.com; s=arc-20160816; b=bRc0/XRmx6wf855ejrdRjt5Wb/GNiz18ag9Vjyo/wQwB2VoD0Sn+8zZSlsPN0OuOGz lPBDBmQQxuHZn8xEKpNYHWVTfjFwoRWq84urPrW55gCRcv7fKX+atxKILxU26Z7Jm86Q KNS7kkHFO05n1LsAcYgQTdO1bNFjs39f4tza4JHYwAbP2M0ksEM1p57+N7vjRcK0mKk5 /vwINlfmEcAY7WZwAh4EzB3lPLBCdJWhvz0FQQ4GdnT7R2nBZNhpYaoVIf0aT0NApZiT 4kShCPuCDO+6YDVccZ+LKr3TYwYV9+lTP/i8nA04FNb4FfYSiOVlQBKR21/FTbVGdFrq +fNA== 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=yHmW4gZxdfwFkx7515EPceM8OYbTjBVQx/IVLavM1/w=; fh=ncJBVmsnOSqrX1O37yfYEzicwaA2e7ARxnsU7aiysyE=; b=SdSRgYjAhK1RWZaVLN0F/ZXp8zkI3HVCWfLB3Ux+QQlziZmRUnpDp6RYqI48qDseKs vqFa2/O8DEvJ6p4aVCGGV78XjX4BYXmtZM8PvzzO53I5ZrVmAwuSm+3NGHIJ25tUKfz6 KHic2aVRo7KN+i0Q7dSbGV8ft+dwhFNOp5H2QJHG3ooaFiE6/ioDWZ252gNZWUVLERuB lWI+jJVE96BZj9iX7XFxxT4xMtecYZKkJKrELHWWMMl/UrsSpuVscH7bjpdg/G2ooTQp swoQ3SHE2vpeGpwvMfLZUA5UWHRPOStuutQmFewf11feuwU3WFD7Bi8Kyq9tOmalbBxB neDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ZO90lCD+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id 137-20020a63018f000000b00578b4082453si8961578pgb.712.2023.10.09.01.53.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 01:53:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ZO90lCD+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 fry.vger.email (Postfix) with ESMTP id C759C80D2E50; Mon, 9 Oct 2023 01:52:46 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345645AbjJIIwV (ORCPT + 99 others); Mon, 9 Oct 2023 04:52:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45872 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345641AbjJIIvl (ORCPT ); Mon, 9 Oct 2023 04:51:41 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E9BBED; Mon, 9 Oct 2023 01:51: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=1696841498; x=1728377498; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=r/ghgXXFlCC5X+m363LcA6Jn28Rpf678n/rxTiOLSIg=; b=ZO90lCD+bDqiDh0qMA4Dq9b6XnY+fYZXUDyLyD5zf5sApFTqYBjQmV04 lJ8qMHzBWDO75wrRddpdIKOc1jTAT8Sou5qquJM2KreQZlv2UO1d7LHoa wCylcVtRGnnTzKZWIn3dTCdPSSnDiDOYJau5Or1kBtX0M9z9FcSwfmvuQ n0h12aGyCy5Cl2epS+e3PFwHFfwIVtkIcvuh2RZ2brDh7AQUwcq+QT7n5 FzlNYWX/ajEm6+cPvUol83ODoS/05y8ye2okgWuVGVPZtYxwU57pKaj3d pxMU4SxyTAesSSs3EKNexAiMvwb7rdZ4/PWtpmLxb4w6f9K7hOzfPrU1y g==; X-IronPort-AV: E=McAfee;i="6600,9927,10857"; a="364390846" X-IronPort-AV: E=Sophos;i="6.03,209,1694761200"; d="scan'208";a="364390846" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Oct 2023 01:51:37 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10857"; a="818781714" X-IronPort-AV: E=Sophos;i="6.03,209,1694761200"; d="scan'208";a="818781714" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by fmsmga008.fm.intel.com with ESMTP; 09 Oct 2023 01:51:36 -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 Subject: [RFC 6/7] iommufd/selftest: Add test coverage for SIOV virtual device Date: Mon, 9 Oct 2023 01:51:22 -0700 Message-Id: <20231009085123.463179-7-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231009085123.463179-1-yi.l.liu@intel.com> References: <20231009085123.463179-1-yi.l.liu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=2.7 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.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 (fry.vger.email [0.0.0.0]); Mon, 09 Oct 2023 01:52:47 -0700 (PDT) X-Spam-Level: ** This adds test coverage for SIOV virtual device by passsing a non-zero pasid to IOMMU_TEST_OP_MOCK_DOMAIN op, and check if the SIOV virtual device (a.k.a pasid of this device) is attached to the mock domain, then tries to replace with a new hwpt and other types of hwpts, and check if the attached domain of this virtual device is correct. Signed-off-by: Yi Liu --- tools/testing/selftests/iommu/iommufd.c | 53 ++++++++++++++++++- .../selftests/iommu/iommufd_fail_nth.c | 26 +++++++++ 2 files changed, 77 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/iommu/iommufd.c b/tools/testing/selftests/iommu/iommufd.c index 9a1fbba89e96..945ab07a8b84 100644 --- a/tools/testing/selftests/iommu/iommufd.c +++ b/tools/testing/selftests/iommu/iommufd.c @@ -2031,14 +2031,20 @@ FIXTURE(iommufd_device_pasid) uint32_t device_id; }; +FIXTURE_VARIANT(iommufd_device_pasid) +{ + uint32_t pasid; +}; + FIXTURE_SETUP(iommufd_device_pasid) { self->fd = open("/dev/iommu", O_RDWR); ASSERT_NE(-1, self->fd); test_ioctl_ioas_alloc(&self->ioas_id); - test_cmd_mock_domain(self->ioas_id, 0, &self->stdev_id, - &self->hwpt_id, &self->device_id); + test_cmd_mock_domain(self->ioas_id, variant->pasid, + &self->stdev_id, &self->hwpt_id, + &self->device_id); } FIXTURE_TEARDOWN(iommufd_device_pasid) @@ -2046,6 +2052,12 @@ FIXTURE_TEARDOWN(iommufd_device_pasid) teardown_iommufd(self->fd, _metadata); } +/* For SIOV test */ +FIXTURE_VARIANT_ADD(iommufd_device_pasid, siov_pasid_600) +{ + .pasid = 600, //this is the default pasid for the SIOV virtual device +}; + TEST_F(iommufd_device_pasid, pasid_attach) { if (self->device_id) { @@ -2071,6 +2083,43 @@ TEST_F(iommufd_device_pasid, pasid_attach) IOMMU_HWPT_ALLOC_DATA_SELFTEST, &data, sizeof(data)); + if (variant->pasid) { + uint32_t new_hwpt_id = 0; + + ASSERT_EQ(0, + test_cmd_pasid_check_domain(self->fd, + self->stdev_id, + variant->pasid, + self->hwpt_id, + &result)); + EXPECT_EQ(1, result); + test_cmd_hwpt_alloc(self->device_id, self->ioas_id, + 0, &new_hwpt_id); + test_cmd_mock_domain_replace(self->stdev_id, + new_hwpt_id); + ASSERT_EQ(0, + test_cmd_pasid_check_domain(self->fd, + self->stdev_id, + variant->pasid, + new_hwpt_id, + &result)); + EXPECT_EQ(1, result); + + /* + * Detach hwpt from variant->pasid, and check if the + * variant->pasid has null domain + */ + test_cmd_pasid_detach(variant->pasid); + ASSERT_EQ(0, + test_cmd_pasid_check_domain(self->fd, + self->stdev_id, + variant->pasid, + 0, &result)); + EXPECT_EQ(1, result); + + test_ioctl_destroy(new_hwpt_id); + } + /* * Attach ioas to pasid 100, should succeed, domain should * be valid. diff --git a/tools/testing/selftests/iommu/iommufd_fail_nth.c b/tools/testing/selftests/iommu/iommufd_fail_nth.c index 691903c63de0..a5fb45d99869 100644 --- a/tools/testing/selftests/iommu/iommufd_fail_nth.c +++ b/tools/testing/selftests/iommu/iommufd_fail_nth.c @@ -644,6 +644,32 @@ TEST_FAIL_NTH(basic_fail_nth, device) self->pasid = 0; + if (_test_ioctl_destroy(self->fd, self->stdev_id)) + return -1; + + self->pasid = 300; + self->stdev_id = 0; + + /* Test for SIOV virtual devices attach */ + if (_test_cmd_mock_domain(self->fd, ioas_id, self->pasid, + &self->stdev_id, NULL, &idev_id)) + return -1; + + /* Test for SIOV virtual device replace */ + if (_test_cmd_mock_domain_replace(self->fd, self->stdev_id, + hwpt_id, NULL)) + return -1; + + if (_test_cmd_pasid_detach(self->fd, self->stdev_id, self->pasid)) + return -1; + + self->pasid = 0; + + if (_test_ioctl_destroy(self->fd, self->stdev_id)) + return -1; + + self->stdev_id = 0; + return 0; } -- 2.34.1