From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D319EC369D5 for ; Mon, 28 Apr 2025 19:05:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=FYyPt2jR26wCNvi6PxzFs+Tv2/OybZasQ+Gm5GQ685c=; b=Q4dQOmBTUP+gwUJJO5HbipI3xZ JZNyL3HHbL6ybdrYF+cgYrKQTLZCLjRMx9PC6xkCjN/Njwhp0UZagSWe6Tnb+MqUR8PQcjKZ3cS/D 6QcVM/z6aL86ut0pDM7bBEmNzg+1dfloFUH212hxtOT3pJQsSAc1VFcmrG+Ca+rvQBHYDzEfNoqyv 5WUy0/5ohyqESAQL3BH+1XuaBzW72cIf3GSiptoTKRthMUPCN9oLBeUEIJ+Ab16aSIbC1dzOAgquR 1VXGKy8/uU/iz/g/pgECg9AAdq85SrocDtVjOB7NtE9yfR2JIYLpF0MSGQindGg4SjEM1TaxphWDx P+FZNzlQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1u9Tms-00000007ILD-1Auh; Mon, 28 Apr 2025 19:05:06 +0000 Received: from mail-pl1-x635.google.com ([2607:f8b0:4864:20::635]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1u9Tkk-00000007I7e-2vtd for linux-arm-kernel@lists.infradead.org; Mon, 28 Apr 2025 19:02:55 +0000 Received: by mail-pl1-x635.google.com with SMTP id d9443c01a7336-2264c9d0295so37385ad.0 for ; Mon, 28 Apr 2025 12:02:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1745866974; x=1746471774; darn=lists.infradead.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=FYyPt2jR26wCNvi6PxzFs+Tv2/OybZasQ+Gm5GQ685c=; b=JFmvsMz6BfrBi0TcPLIvMK84sGxX/YsEb9jJEzkeZht5f+Nu4utfXulsetKAoxF4XA xN7TBM0kttGE9Q06lRRKBi5OJ+SRzMLbW1JiZQa6MbjVz1I1seRR1mwQSgqD6I9PEzyz HEapRheOgkPKP59vE2m7O41y5k0/hSmjWj9/EOaKRJuBJfDjiveaIeVcpvA9hq/iHo2s HbQ+02l41N0B64sFfJdcnYpYTcrNnEZ2yRF5OzAuNTHRGR2VpQKly9G2ep2BpXX1wz7r t5DQG5jRQEY6QYcR9MzCzLXnOy6rx9OY/rFcEQGtRbak+RraMqpDcUz5+2mCKGku3Xek i8Vg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745866974; x=1746471774; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=FYyPt2jR26wCNvi6PxzFs+Tv2/OybZasQ+Gm5GQ685c=; b=pcZAIYOyhVzoCXnPv1gT89XqY7a36oTKduvxqAUSC53Y5hT86RN1P2Rg4mKnAOFd1Z blGtzcxmM2lDCVfDVs+Qx9+bn0dpJP19wi2GjjSFbzHqHdtB8co5JOc9ECNdsl4/noBy LhtGLPkkWq91v5eScEwXaj+CrE0iVxBwhxD5QaQxsRajiZDtDEzHL4hk4umkbt9mfjcD Y0e0LYHQmWR1b3QKHahjhe9QlQSq1Er0WUlBtf1Em1TH1e/1/hbGO54Bn3LLWwOAVM+J kpeTj90YY6Uw1bnZ8/Kx2jhWnKbL6t/owjT+sZEh8WJAhGVEGCZqPbTrJrce9zc2a2ye JqVA== X-Forwarded-Encrypted: i=1; AJvYcCVj8uVtDoVa5Hj+4XD6et4xciercuNY+NI8bYKJU2Ha3X+8DM3wwjPzczHmi6F7u87efNyNkKJ2Q9j1UX+dryxi@lists.infradead.org X-Gm-Message-State: AOJu0YxNDXrQWi5NkgJpLLqbpEJKjglBuBncnQf3Cm3ILtraSo9RPVZf MNLLCbwu3XJqh1kgoxirlEsGja952EbhofImcR8Jado1070zRmm6ue52t6w+lQ== X-Gm-Gg: ASbGnctZMI4xQTtkG0zKnlZvw9S9I4pHuyBUqH4h1VjrbexLrNThnE9R8BxZgz2c12t Ppvf+RV7VLpZHPzuGD79W7jqQ3XJN0UEs5uoW01YNvR3GYav7Fz7uLW2nLdMX8CatUXQQhRso9v BoLRppKwiERIL8HQ9Djqgs55e3u7b25h3WkKOlbsT00t2nJS++p0nz6AH7/kTbxPUgLTQkj8w85 I54eHYw/S+yzVKofFXI2txbeBwNR2VhLAfTA3BOCxO3EhFj1sy2mJcx7tGbZa9u+klKok2kpiet Rc/9P3sIo8HfolHgVfL/vsPddeuqQCD2yvS7/BSJunM+AoOwQSynNsOeWXJdERXVYvqAlfEG X-Google-Smtp-Source: AGHT+IEJGsiJDrtJlEO2nY+Xes9iIUQJtfbQGQMK+W7yiK5m4Ms2rwNKriCBn3CEAxNgqNLQt8mwbw== X-Received: by 2002:a17:903:32cc:b0:21f:3f5c:d24c with SMTP id d9443c01a7336-22de6bc7c32mr473905ad.0.1745866973500; Mon, 28 Apr 2025 12:02:53 -0700 (PDT) Received: from google.com (2.210.143.34.bc.googleusercontent.com. [34.143.210.2]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-309eef7cc58sm9392543a91.0.2025.04.28.12.02.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Apr 2025 12:02:52 -0700 (PDT) Date: Mon, 28 Apr 2025 19:02:42 +0000 From: Pranjal Shrivastava To: Nicolin Chen Cc: jgg@nvidia.com, kevin.tian@intel.com, corbet@lwn.net, will@kernel.org, bagasdotme@gmail.com, robin.murphy@arm.com, joro@8bytes.org, thierry.reding@gmail.com, vdumpa@nvidia.com, jonathanh@nvidia.com, shuah@kernel.org, jsnitsel@redhat.com, nathan@kernel.org, peterz@infradead.org, yi.l.liu@intel.com, mshavit@google.com, zhangzekun11@huawei.com, iommu@lists.linux.dev, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-tegra@vger.kernel.org, linux-kselftest@vger.kernel.org, patches@lists.linux.dev, mochs@nvidia.com, alok.a.tiwari@oracle.com, vasant.hegde@amd.com Subject: Re: [PATCH v2 07/22] iommufd/selftest: Add covearge for viommu data Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250428_120254_747623_C8ACF75E X-CRM114-Status: GOOD ( 22.91 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Fri, Apr 25, 2025 at 10:58:02PM -0700, Nicolin Chen wrote: > Extend the existing test_cmd/err_viommu_alloc helpers to accept optional > user data. And add a TEST_F for a loopback test. > > Signed-off-by: Nicolin Chen Reviewed-by: Pranjal Shrivastava > --- > tools/testing/selftests/iommu/iommufd_utils.h | 21 +++++++++----- > tools/testing/selftests/iommu/iommufd.c | 29 +++++++++++++++---- > .../selftests/iommu/iommufd_fail_nth.c | 5 ++-- > 3 files changed, 39 insertions(+), 16 deletions(-) > > diff --git a/tools/testing/selftests/iommu/iommufd_utils.h b/tools/testing/selftests/iommu/iommufd_utils.h > index 72f6636e5d90..a5d4cbd089ba 100644 > --- a/tools/testing/selftests/iommu/iommufd_utils.h > +++ b/tools/testing/selftests/iommu/iommufd_utils.h > @@ -897,7 +897,8 @@ static int _test_cmd_trigger_iopf(int fd, __u32 device_id, __u32 pasid, > pasid, fault_fd)) > > static int _test_cmd_viommu_alloc(int fd, __u32 device_id, __u32 hwpt_id, > - __u32 type, __u32 flags, __u32 *viommu_id) > + __u32 flags, __u32 type, void *data, > + __u32 data_len, __u32 *viommu_id) > { > struct iommu_viommu_alloc cmd = { > .size = sizeof(cmd), > @@ -905,6 +906,8 @@ static int _test_cmd_viommu_alloc(int fd, __u32 device_id, __u32 hwpt_id, > .type = type, > .dev_id = device_id, > .hwpt_id = hwpt_id, > + .data_uptr = (uint64_t)data, > + .data_len = data_len, > }; > int ret; > > @@ -916,13 +919,15 @@ static int _test_cmd_viommu_alloc(int fd, __u32 device_id, __u32 hwpt_id, > return 0; > } > > -#define test_cmd_viommu_alloc(device_id, hwpt_id, type, viommu_id) \ > - ASSERT_EQ(0, _test_cmd_viommu_alloc(self->fd, device_id, hwpt_id, \ > - type, 0, viommu_id)) > -#define test_err_viommu_alloc(_errno, device_id, hwpt_id, type, viommu_id) \ > - EXPECT_ERRNO(_errno, \ > - _test_cmd_viommu_alloc(self->fd, device_id, hwpt_id, \ > - type, 0, viommu_id)) > +#define test_cmd_viommu_alloc(device_id, hwpt_id, type, data, data_len, \ > + viommu_id) \ > + ASSERT_EQ(0, _test_cmd_viommu_alloc(self->fd, device_id, hwpt_id, 0, \ > + type, data, data_len, viommu_id)) > +#define test_err_viommu_alloc(_errno, device_id, hwpt_id, type, data, \ > + data_len, viommu_id) \ > + EXPECT_ERRNO(_errno, \ > + _test_cmd_viommu_alloc(self->fd, device_id, hwpt_id, 0, \ > + type, data, data_len, viommu_id)) > > static int _test_cmd_vdevice_alloc(int fd, __u32 viommu_id, __u32 idev_id, > __u64 virt_id, __u32 *vdev_id) > diff --git a/tools/testing/selftests/iommu/iommufd.c b/tools/testing/selftests/iommu/iommufd.c > index 1a8e85afe9aa..8ebbb7fda02d 100644 > --- a/tools/testing/selftests/iommu/iommufd.c > +++ b/tools/testing/selftests/iommu/iommufd.c > @@ -2688,7 +2688,7 @@ FIXTURE_SETUP(iommufd_viommu) > > /* Allocate a vIOMMU taking refcount of the parent hwpt */ > test_cmd_viommu_alloc(self->device_id, self->hwpt_id, > - IOMMU_VIOMMU_TYPE_SELFTEST, > + IOMMU_VIOMMU_TYPE_SELFTEST, NULL, 0, > &self->viommu_id); > > /* Allocate a regular nested hwpt */ > @@ -2727,24 +2727,27 @@ TEST_F(iommufd_viommu, viommu_negative_tests) > if (self->device_id) { > /* Negative test -- invalid hwpt (hwpt_id=0) */ > test_err_viommu_alloc(ENOENT, device_id, 0, > - IOMMU_VIOMMU_TYPE_SELFTEST, NULL); > + IOMMU_VIOMMU_TYPE_SELFTEST, NULL, 0, > + NULL); > > /* Negative test -- not a nesting parent hwpt */ > test_cmd_hwpt_alloc(device_id, ioas_id, 0, &hwpt_id); > test_err_viommu_alloc(EINVAL, device_id, hwpt_id, > - IOMMU_VIOMMU_TYPE_SELFTEST, NULL); > + IOMMU_VIOMMU_TYPE_SELFTEST, NULL, 0, > + NULL); > test_ioctl_destroy(hwpt_id); > > /* Negative test -- unsupported viommu type */ > test_err_viommu_alloc(EOPNOTSUPP, device_id, self->hwpt_id, > - 0xdead, NULL); > + 0xdead, NULL, 0, NULL); > EXPECT_ERRNO(EBUSY, > _test_ioctl_destroy(self->fd, self->hwpt_id)); > EXPECT_ERRNO(EBUSY, > _test_ioctl_destroy(self->fd, self->viommu_id)); > } else { > test_err_viommu_alloc(ENOENT, self->device_id, self->hwpt_id, > - IOMMU_VIOMMU_TYPE_SELFTEST, NULL); > + IOMMU_VIOMMU_TYPE_SELFTEST, NULL, 0, > + NULL); > } > } > > @@ -2791,6 +2794,20 @@ TEST_F(iommufd_viommu, viommu_alloc_nested_iopf) > } > } > > +TEST_F(iommufd_viommu, viommu_alloc_with_data) > +{ > + struct iommu_viommu_selftest data = { > + .in_data = 0xbeef, > + }; > + > + if (self->device_id) { > + test_cmd_viommu_alloc(self->device_id, self->hwpt_id, > + IOMMU_VIOMMU_TYPE_SELFTEST, &data, > + sizeof(data), &self->viommu_id); > + assert(data.out_data == data.in_data); > + } > +} > + > TEST_F(iommufd_viommu, vdevice_alloc) > { > uint32_t viommu_id = self->viommu_id; > @@ -3105,7 +3122,7 @@ TEST_F(iommufd_device_pasid, pasid_attach) > > /* Allocate a regular nested hwpt based on viommu */ > test_cmd_viommu_alloc(self->device_id, parent_hwpt_id, > - IOMMU_VIOMMU_TYPE_SELFTEST, > + IOMMU_VIOMMU_TYPE_SELFTEST, NULL, 0, > &viommu_id); > test_cmd_hwpt_alloc_nested(self->device_id, viommu_id, > IOMMU_HWPT_ALLOC_PASID, > diff --git a/tools/testing/selftests/iommu/iommufd_fail_nth.c b/tools/testing/selftests/iommu/iommufd_fail_nth.c > index e11ec4b121fc..f7ccf1822108 100644 > --- a/tools/testing/selftests/iommu/iommufd_fail_nth.c > +++ b/tools/testing/selftests/iommu/iommufd_fail_nth.c > @@ -688,8 +688,9 @@ TEST_FAIL_NTH(basic_fail_nth, device) > IOMMU_HWPT_DATA_NONE, 0, 0)) > return -1; > > - if (_test_cmd_viommu_alloc(self->fd, idev_id, hwpt_id, > - IOMMU_VIOMMU_TYPE_SELFTEST, 0, &viommu_id)) > + if (_test_cmd_viommu_alloc(self->fd, idev_id, hwpt_id, 0, > + IOMMU_VIOMMU_TYPE_SELFTEST, NULL, 0, > + &viommu_id)) > return -1; > > if (_test_cmd_vdevice_alloc(self->fd, viommu_id, idev_id, 0, &vdev_id)) > -- > 2.43.0 >