Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp1478036rdd; Wed, 10 Jan 2024 23:38:34 -0800 (PST) X-Google-Smtp-Source: AGHT+IGNJnUQKx/4oDf5JyrGbVLfYZloYs1+j4v0gRZvQKASwUj9ZwzGOEg2HSBnZami5EradWUp X-Received: by 2002:a05:620a:44ca:b0:783:389a:6ce2 with SMTP id y10-20020a05620a44ca00b00783389a6ce2mr1039570qkp.152.1704958714166; Wed, 10 Jan 2024 23:38:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704958714; cv=none; d=google.com; s=arc-20160816; b=KOwq8gBmMwW/nwsgKqvGjsEBMdkD56DwI02ogd7GTliuW8obrlfrms5IKYsqaLdUA8 lShnv0jscQFBwtftPYBvsOu9oqRdC4kFZqeyvTrzrUdttpqLSEluCE7lkc879uomqJ7K nDG9EBgcnC7gPY701fm5hlOq9iJi6gmbyhb/DyhDna1fxe5x6lJG4TltXsr0AvhiQkQt qo5VvN5CVd+EQN5q/LduftvSXitMhJs0C7jSozdqwo0RKQczL1Q5pPRgFO6AXnJG/DOz LolM/gyj/zOX48CilheD2qBecCxsKK6oVFTMLyp85j+99iAxJqxfMRnbk67mOki40Ykk xHcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=78EoG9KRunOmmTTTfZ3u8tZJrj0yOC5v6z3POPxmC7k=; fh=+Q0HmAbA9K+2Zsh7tjb8zIg0VTV8m8JrWwOI0YmM/vM=; b=etoMsocJXGr+17EVcfJ+bOZQzL8DuyiSrArigDPc2hHggMMWNSXDEICmzlnBTdQcUN 0D15XbIucemcikrGq0KP9O0cpxTK+zl+0d/3nSOvMVQXe8Bs2Cew0D8apZfZO6dIWij4 TL8Cit4IBZMcvEI4z+HcZGMfOc89cw5zePJwhWhPIKn6IRwk/1JowxWmrwnEHZFJbGfi sDJi4HGJW7PUI6+xlglO0LcB2GVYzBNQmMxV+uGeLqDDebZ6aEjh6Znk1fuImMCtRLNM 6ETDbLH1LD6kFkkypP+8oujuYTcGfH2ZAVmUlAWurL0sSSQo0MpvZHp8M0Y86bhr5XAN gIbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=N6FpV21f; spf=pass (google.com: domain of linux-kernel+bounces-23158-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-23158-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id oq29-20020a05620a611d00b007824fe47b7csi426434qkn.28.2024.01.10.23.38.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jan 2024 23:38:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-23158-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=N6FpV21f; spf=pass (google.com: domain of linux-kernel+bounces-23158-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-23158-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id E40211C23568 for ; Thu, 11 Jan 2024 07:38:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A2129D2E2; Thu, 11 Jan 2024 07:38:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="N6FpV21f" Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.31]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6AD1FD28F for ; Thu, 11 Jan 2024 07:38:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1704958705; x=1736494705; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=1P8soOsSAg4WFnLHZTKMOzbTMCW8wETbL0uhEPdgccw=; b=N6FpV21fHeJknRBKaPXaG/kKeWdYqsgJLMwDQ9ynSW7vShP1ZfLk/ALh qG6wkO0yYKjDAWsF9bRuhR3XN6s1s7y6ZGXVyuJ4WO01Jn9h3isT/0o8m fxi6OjbG3aR7OSMKIBQE9ZqR2+/5q1G5+4zZEIj5oDKmSz85nR+zOXdQE jMCzIWVJvW8CoqG9OstXg82rIevgzuCHR55byhH+qakZGmPq0+78IDdxX 3RgwSEUOsZLRWq0iNkE37iaLbU4byEjW96Vx0K78ZQwOcDO2XLrA/hnvS T0jmmRlpSl9CjMEgckV+eVnT/KwxIjHnWkAE2UOZ0K5YrzDt9t646UIe/ A==; X-IronPort-AV: E=McAfee;i="6600,9927,10949"; a="463056662" X-IronPort-AV: E=Sophos;i="6.04,185,1695711600"; d="scan'208";a="463056662" Received: from orviesa001.jf.intel.com ([10.64.159.141]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jan 2024 23:37:39 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.04,185,1695711600"; d="scan'208";a="30909609" Received: from allen-box.sh.intel.com ([10.239.159.127]) by orviesa001.jf.intel.com with ESMTP; 10 Jan 2024 23:37:35 -0800 From: Lu Baolu To: Jason Gunthorpe , Kevin Tian , Joerg Roedel , Will Deacon , Robin Murphy Cc: iommu@lists.linux.dev, linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH 1/1] iommufd/selftest: Use right iommu_ops for mock device Date: Thu, 11 Jan 2024 15:32:13 +0800 Message-Id: <20240111073213.180020-1-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit In the iommu probe device path, __iommu_probe_device() gets the iommu_ops for the device from dev->iommu->fwspec if this field has been initialized before probing. Otherwise, it will lookup the global iommu device list and use the iommu_ops of the first iommu device which has no dev->iommu->fwspec. This causes the wrong iommu_ops to be used for the mock device on x86 platforms where dev->iommu->fwspec is not used. Preallocate the fwspec for the mock device so that the right iommu ops can be used. Fixes: 17de3f5fdd35 ("iommu: Retire bus ops") Cc: Robin Murphy Signed-off-by: Lu Baolu --- drivers/iommu/iommufd/selftest.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/drivers/iommu/iommufd/selftest.c b/drivers/iommu/iommufd/selftest.c index cf3e9fed039e..4eca67b8a5c6 100644 --- a/drivers/iommu/iommufd/selftest.c +++ b/drivers/iommu/iommufd/selftest.c @@ -611,6 +611,8 @@ static void mock_dev_release(struct device *dev) static struct mock_dev *mock_dev_create(unsigned long dev_flags) { + struct iommu_fwspec *fwspec; + struct dev_iommu *param; struct mock_dev *mdev; int rc; @@ -621,10 +623,28 @@ static struct mock_dev *mock_dev_create(unsigned long dev_flags) if (!mdev) return ERR_PTR(-ENOMEM); + /* fwspec and param will be freed in the iommu core */ + fwspec = kzalloc(sizeof(*fwspec), GFP_KERNEL); + if (!fwspec) { + kfree(mdev); + return ERR_PTR(-ENOMEM); + } + fwspec->ops = &mock_ops; + + param = kzalloc(sizeof(*param), GFP_KERNEL); + if (!param) { + kfree(mdev); + kfree(fwspec); + return ERR_PTR(-ENOMEM); + } + mutex_init(¶m->lock); + param->fwspec = fwspec; + device_initialize(&mdev->dev); mdev->flags = dev_flags; mdev->dev.release = mock_dev_release; mdev->dev.bus = &iommufd_mock_bus_type.bus; + mdev->dev.iommu = param; rc = dev_set_name(&mdev->dev, "iommufd_mock%u", atomic_inc_return(&mock_dev_num)); @@ -638,6 +658,8 @@ static struct mock_dev *mock_dev_create(unsigned long dev_flags) err_put: put_device(&mdev->dev); + kfree(param); + kfree(fwspec); return ERR_PTR(rc); } -- 2.34.1