From patchwork Fri Jan 26 10:53:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolu Lu X-Patchwork-Id: 19508 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2395:b0:106:343:edcb with SMTP id gw21csp26250dyb; Fri, 26 Jan 2024 09:27:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IHM8JmX9czCd7rs3h8q48UcFZ4nT8ZJ1BVM/3mgyet0dGATephruPflSF7ToZT5DrGCKkUv X-Received: by 2002:a05:6a00:9293:b0:6dd:d1f2:d9ee with SMTP id jw19-20020a056a00929300b006ddd1f2d9eemr186312pfb.36.1706290068163; Fri, 26 Jan 2024 09:27:48 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706290068; cv=pass; d=google.com; s=arc-20160816; b=n32h7/F6ASWYla5c4jvvUN4AHC96N/vinR25MoML0OrtycX/7wMyZFdU3xDBsByCDu 7H6FV0frDXSEwq7S+X3p4UKN40MNhLT23RSRo+N8k0MpwBx3XihuYjKMvzNGknbiSUeH aJec9/oM0lePTyp6rzTvs+S8LmOcipiIwgBHu/IGxLl43bH0vxjkDMXP70Nd4LN8Eh76 mzgE5kH+i5SnOvw3l+ua9jyb9sqV/7fZMPJ/QixDpRYMF14DqvWe892hMWlmaUketY9Q yN1znH3kOCDyRAR4UfxE/WkgqeN6cPTU+plGBNEw7s0DZ/ke3RGaw3Q83i+YYimCibfE o7ng== ARC-Message-Signature: i=2; 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=2Gof+hW6lHX4U+OBj8ghHdYuYiCG3OqF0TIqJNRHzQI=; fh=+Q0HmAbA9K+2Zsh7tjb8zIg0VTV8m8JrWwOI0YmM/vM=; b=rQq3VhR0PgoXDq6OqL+CWqXU5rbYrOMoULBtcbLdx4mG+f5f+BTQj0PtaFZDw1AyVE K0PKf6NIiaRDpYxY4kt94lVZ5pNtwo3hTv28kIPtr9vr/bUQmCmomfl7CsnRMm2xSs/q ahOSlHttK9WSPWbQgLeCXYP5nCtjMhlM1mvNLDshrYTB2CGp7mF2+pCx2ondO+LVHah+ nfN2DA8SbidXzO1kn8zgv3BXUM/EdOcvjNCPhObDYgHFlWQMYFVn9MJh2+8e9BzQmwia Fs68TC1mP59REdkgDi3yEo9IoKiEPKRuyCwq687VVLPtwvOfYa8cAMqavNrhwl/E/C/q hO/A== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=FcJK4Y4e; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-40011-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-40011-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id ay13-20020a056a00300d00b006de0ba39303si232730pfb.111.2024.01.26.09.27.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jan 2024 09:27:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-40011-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=FcJK4Y4e; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-40011-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-40011-ouuuleilei=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 sv.mirrors.kernel.org (Postfix) with ESMTPS id CA515289BCF for ; Fri, 26 Jan 2024 10:59:42 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6316614291; Fri, 26 Jan 2024 10:59:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="FcJK4Y4e" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.11]) (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 00C7F14273 for ; Fri, 26 Jan 2024 10:59:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706266766; cv=none; b=W2yTlIbpQa9/CR6IolOwWJSHaxXc1UxIJWJiTOiOIcnwEMPsqxC+mRvYgi/yYSy2f62mwEhf9VvdngUMIA/UEpraFZPgNCI9zlM4LDpJCnzTKfwd0eGbcbZck9lpua3NWsfsPpy1/G9aBa1wbe1GVthQ7eAOCRwHwlrI5PFNwBE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706266766; c=relaxed/simple; bh=Wl5UNtFVk8ZXZ4K+eceGuSpgE0BVMziZ4gm24eGRtS0=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=Hqwpcn+sspWdhG+UGPACLfMH0hDqBVbcnMkWAfTozjSt3Rz1YC6Iv5iUIIrlqWO6q6oFIF7FRNUk4Dmrg15PgSr2ErcbF3jtU1eHLo0/K8la0Xkgs3xu8x0X2udUJnOz3svzQRKkZ7cBbSWvT3XvM/62m3szXUrewRMfhERKBxw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=FcJK4Y4e; arc=none smtp.client-ip=192.198.163.11 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=1706266755; x=1737802755; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=Wl5UNtFVk8ZXZ4K+eceGuSpgE0BVMziZ4gm24eGRtS0=; b=FcJK4Y4eqGYRvbuIzCea3g2dO86nxfMT7gD1VGBZekE2n82eQtqn2FuW pPecwkZVgkRHiqXkVSkKjYJrjW7qPRPrp9ur5Ar9VjvGFy1oZd6TqtmNN TEvuknhZLKCSOvZabtyOEjQ8ADmS+DMbWW2leraHDTlWCXXCYrGJmehBl /2JL37zKFK7c6goK3WrohT7LLoqRfcTfB6NaK7oKJoE3KBMJbKZoEcbfK KiNB6D+xEkVxLY/mnS+CJVIM+RBNEIO31N7sXQhFYQG+rSnltxvZsW3lw 6nwSN9X9cpXK4ahGCgSkWFsrauyqU7fnbEevT0RiwaHoA0JzpNT5sK9th Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10964"; a="9123351" X-IronPort-AV: E=Sophos;i="6.05,216,1701158400"; d="scan'208";a="9123351" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jan 2024 02:59:14 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10964"; a="857367824" X-IronPort-AV: E=Sophos;i="6.05,216,1701158400"; d="scan'208";a="857367824" Received: from allen-box.sh.intel.com ([10.239.159.127]) by fmsmga004.fm.intel.com with ESMTP; 26 Jan 2024 02:59:12 -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 v2 0/2] Use right iommu_ops for mock device Date: Fri, 26 Jan 2024 18:53:39 +0800 Message-Id: <20240126105341.78086-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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789174814484066899 X-GMAIL-MSGID: 1789174814484066899 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. Probe the right iommu_ops for device by iterating over all the global drivers and calling their probe function to find a match. Change log: v2: - Iterate over all the global iommu drivers and calling their probe function to find a match. v1: https://lore.kernel.org/linux-iommu/20240111073213.180020-1-baolu.lu@linux.intel.com/ Lu Baolu (2): iommu: Use mutex instead of spinlock for iommu_device_list iommu: Probe right iommu_ops for device drivers/iommu/iommu.c | 98 ++++++++++++++++++++++++++----------------- 1 file changed, 59 insertions(+), 39 deletions(-)