From patchwork Mon Nov 27 06:34: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: 170010 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce62:0:b0:403:3b70:6f57 with SMTP id o2csp2888257vqx; Sun, 26 Nov 2023 22:35:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IG/FbMcSs/5L1EtanvG6HJt0ZBzhcmtR4B9zRcGHcEf74srTwxDGcH8mmpMDIpC8ayOFSqQ X-Received: by 2002:a05:6a00:3a18:b0:6c0:4006:4195 with SMTP id fj24-20020a056a003a1800b006c040064195mr11505265pfb.0.1701066900808; Sun, 26 Nov 2023 22:35:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701066900; cv=none; d=google.com; s=arc-20160816; b=IZlOOsaSKP4njiVYtyLif3fkRs3tjt/lBtMZk69eBH1L6g+DFbRfu+/3EK5amPeKhI 4+hClUFbX/klsWXkVl2Sn3Dq01jPJONFoewlw4bo/v2mD6AQ81mTo4k6rglaIEtijg+a uyLOz2kZZD8Q4oO+YyZIchcfnfbYb9Rw6kPt8kfMEoScZHBlN9INsfB+Ng0BeqNkhMJe WB/P703cG6T3cy9a3aoT0/vSYKUEUQThULnXX+5WG9GGY6safbXvlUV3+7xo70vqxSAa u5Abb/sp65vFWBsHlfXfXTpXsawD3fpe6Nbf8x6FSwhr8E+wqX8KwViGl9ejmW7sRR/5 IdRg== 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=sm39zDE6QLcnKl/0aVSZECLdSGyAjx+MliOELqThv2o=; fh=gm0A6EtasJwovXfz1TpeYfkY+4H0EN5E4rSCpite+Dk=; b=AXp7TNXhJYOVUAgi1qz/0+MGJPXTvOsGiwSWdeFi2E4zOYMaZ5+/YIHmj2sicotiVy dQ9inEsDoTaUCz3CuDGtgOdufCLyUNeu3K6jFKt+nkPp0hBjEhh2p1BDP5b0vUb0A1dA SU+zpQ6ZtvjtIJ5hRZtXQ8zkrKlnmT+3FNsmLxRbEipZPPCh05E+lYIn2HA95F/QLidL nqfRMryQoSMqfwNRviQYY0PDAyFiwo81OKRxHrdREFdedJPBec+DSrl8UTRMhbNbJLNP dr9rWmWwrztn+VkK0E0L6AJBXffpkaYRMnV4tQ9l2eRVNB3ruS7WcDwVL3IvtJQ+9R1G YwJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=iKWhKpOy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id i2-20020a635402000000b005b7160263f2si8855871pgb.154.2023.11.26.22.35.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Nov 2023 22:35:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=iKWhKpOy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (Postfix) with ESMTP id 708868060032; Sun, 26 Nov 2023 22:34:55 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232314AbjK0Gel (ORCPT + 99 others); Mon, 27 Nov 2023 01:34:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45812 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230476AbjK0Gea (ORCPT ); Mon, 27 Nov 2023 01:34:30 -0500 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D3CFC12F; Sun, 26 Nov 2023 22:34:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701066876; x=1732602876; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=yZ2ZM14suqOR6uWNGYJVIr5wJqTHJJ9fSMownQVohd4=; b=iKWhKpOyvcGW0g8bPt36MIBtXJVO2xGPoxx2gGzI1KIBJdYUSuVuB9rm pGCAjbSFDreSGjjAfdDoCPX+oWRrRn07SkfHmoZ1Nl6qO8oMzFH19HBbd OHTLoxZ9kXGs9aJm4xrGLITRGT1gYm3lOvG7bQcvm47DMOzOcNGSbPOHe KkrTAZWh5hVLMtCDG3NFNOFPkw/s+FyalU8JmrDOGzsL/f+fblUnDdsZY B7Tds8I6ekV+8tsF6l7h/XozE4UHVMUMOgNXg2OrRhP1hOAHIpT9/IgYB hXaWemA/o2wSQX2tMN3LyO5Mhf2pb605Vrj78WOgNJPhSO/0smxDdunPA Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10906"; a="391518172" X-IronPort-AV: E=Sophos;i="6.04,230,1695711600"; d="scan'208";a="391518172" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Nov 2023 22:34:36 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10906"; a="838608940" X-IronPort-AV: E=Sophos;i="6.04,230,1695711600"; d="scan'208";a="838608940" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by fmsmga004.fm.intel.com with ESMTP; 26 Nov 2023 22:34:35 -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 Subject: [PATCH 4/8] iommufd/selftest: Add set_dev_pasid and remove_dev_pasid in mock iommu Date: Sun, 26 Nov 2023 22:34:24 -0800 Message-Id: <20231127063428.127436-5-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231127063428.127436-1-yi.l.liu@intel.com> References: <20231127063428.127436-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,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.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 (agentk.vger.email [0.0.0.0]); Sun, 26 Nov 2023 22:34:55 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783697926640073137 X-GMAIL-MSGID: 1783697926640073137 The two callbacks are needed to make pasid_attach/detach path complete for mock device. A nop is enough for set_dev_pasid, a domain type check in the remove_dev_pasid is also helpful. Signed-off-by: Yi Liu --- drivers/iommu/iommufd/selftest.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/drivers/iommu/iommufd/selftest.c b/drivers/iommu/iommufd/selftest.c index f2d4599f701b..221a206bf38f 100644 --- a/drivers/iommu/iommufd/selftest.c +++ b/drivers/iommu/iommufd/selftest.c @@ -440,6 +440,31 @@ static struct iommu_device *mock_probe_device(struct device *dev) return &mock_iommu_device; } +static void mock_iommu_remove_dev_pasid(struct device *dev, ioasid_t pasid) +{ + struct iommu_domain *domain; + + /* Domain type specific cleanup: */ + domain = iommu_get_domain_for_dev_pasid(dev, pasid, 0); + if (domain) { + switch (domain->type) { + case IOMMU_DOMAIN_NESTED: + case IOMMU_DOMAIN_UNMANAGED: + break; + default: + /* should never reach here */ + WARN_ON(1); + break; + } + } +} + +static int mock_domain_set_dev_pasid_nop(struct iommu_domain *domain, + struct device *dev, ioasid_t pasid) +{ + return 0; +} + static const struct iommu_ops mock_ops = { /* * IOMMU_DOMAIN_BLOCKED cannot be returned from def_domain_type() @@ -455,6 +480,7 @@ static const struct iommu_ops mock_ops = { .capable = mock_domain_capable, .device_group = generic_device_group, .probe_device = mock_probe_device, + .remove_dev_pasid = mock_iommu_remove_dev_pasid, .default_domain_ops = &(struct iommu_domain_ops){ .free = mock_domain_free, @@ -462,6 +488,7 @@ static const struct iommu_ops mock_ops = { .map_pages = mock_domain_map_pages, .unmap_pages = mock_domain_unmap_pages, .iova_to_phys = mock_domain_iova_to_phys, + .set_dev_pasid = mock_domain_set_dev_pasid_nop, }, }; @@ -519,6 +546,7 @@ 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, + .set_dev_pasid = mock_domain_set_dev_pasid_nop, }; static inline struct iommufd_hw_pagetable *