From patchwork Fri Feb 23 05:13:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolu Lu X-Patchwork-Id: 205206 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp415960dyb; Thu, 22 Feb 2024 22:36:32 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXNgLTDauNgEh+iEggkEuKBn1JqpfaFm72wJfj3cRhmpNptSXhbHyOLcAHaPx6FvnqnFtybMhyp6YdRlAqDInzXJUjxQQ== X-Google-Smtp-Source: AGHT+IFpbJhZatKwGrPZy/GXUvEjcaDBh15sfPmIwjI5d83EoPzyDZ7ApD+hCilIwS6+yJZFUbVd X-Received: by 2002:a05:6512:3ca3:b0:512:ae18:7492 with SMTP id h35-20020a0565123ca300b00512ae187492mr868744lfv.11.1708670191904; Thu, 22 Feb 2024 22:36:31 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708670191; cv=pass; d=google.com; s=arc-20160816; b=bHyhjzEchOMFRir9Lwj/nzM9LSypSnxCL2+RK3obkLqx25Wycb80Pc8rkiaZ+Hm4FU GndW+YqzT5fZ/VLO0n4/NFC1TLmJjPmsW7e91MLgCvbIapQLwUWNbJ7OyLp/UnjgcpdV dc77D5X1JITs4zAWTxZMYN0L7GyFhg5DMZStjHH9onK1bYeXOv5EAWJRYuZFN3LmjMbw o4n/64dzpkAi1ATUXFH/r7IjFMugg1c029LISY4N3ZbXUXSrYG4AfeC5KJw9MGWXx8Cb 1+N3dx3bw+tpPmtcCwYhn5O5AdtIPS5nYGp6UYiNNIA5d0v1vfVsfKMtO/Gc+CNf5NMN 6FNA== 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:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=D1GEU4cm6aYb7QbW1aaUlHVep/7eu1/VzCpBFWuDA2U=; fh=uyI/4ttAQPfURKZyGpapvNeqD+HuuY0cyBg8vJ5ndgc=; b=BWsnSmF8PhVCFYKAZt88EqEG7ujTnWjWbGjHJNdUST/xyvmavXwjWinb/gCYydrKuz 9sdct78A9jFuTYR0u711UFgzey8Twp69XCaNy3ySnkWN80KtBXClPxxh7ePWeiLi/Yc2 /RT7X0YqrWKYjeBdQ3h3aKXsNbRm+VdUFC29qC/fidVKKxW7GwJtBqHuA7x5gFxC1hdZ ipe+pQXP2ZDdCQY8Hkl4Xzf5NNE7xXbRraYKViuYfB2yEGkk1XBPkTnM0L8z87XGWZvT uOpkk9I+ZWcdRR9geZt5A0YJW8DWK69NYmQmYPfoFqoa3t6QsrRGi5lG5ZQ/6cFZjp9n Trxg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=XoUy9ZEh; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-77782-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-77782-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id l20-20020a1709060e1400b00a3f0ec18fb0si2727841eji.344.2024.02.22.22.36.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 22:36:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-77782-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=XoUy9ZEh; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-77782-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-77782-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 am.mirrors.kernel.org (Postfix) with ESMTPS id A48DA1F261D1 for ; Fri, 23 Feb 2024 05:19:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 856D212B6A; Fri, 23 Feb 2024 05:19:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="XoUy9ZEh" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.7]) (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 6177211738 for ; Fri, 23 Feb 2024 05:19:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708665545; cv=none; b=sYhFew7U3z1SaT7s3F9ENzCyVxK44zKTF+Bl1QK1bggI9CMWK+OKbnbA4PYeiAJF1cof4IEHuprg4dgOSHiRvfOQbbJiz4qhIcM4iv6ZbaoHNmt8DS9sUqUsl3Bl8mCu97FTi91i7GfGvVPEnN4DMhgDnedExJ/M0O/2JZwAlpY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708665545; c=relaxed/simple; bh=Tk9A4I0oMmelCpHSwdKZxqF1e4tJfbiF9SDU75PTANQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=JW01FW6N+xBciHXKaALe3ZS/cxw0sotytTEiu9ZebPy4BLgU1b4RKZmUKAI9Q905rOd97LdDuEFsfM64VEU21j404FW2PCWgVcDOdokck8g4emgK350JwfnHaTPpuO8ki1ju39vTIptjQG/7gM9Dbi3igbjcV/PYsiFbxSzZ2Rg= 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=XoUy9ZEh; arc=none smtp.client-ip=192.198.163.7 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=1708665544; x=1740201544; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Tk9A4I0oMmelCpHSwdKZxqF1e4tJfbiF9SDU75PTANQ=; b=XoUy9ZEhcb/1WdMDoh2xB+cxXgDkXzLTQq1CA/zYUy0eFejj2EiJYHAl QKXC99QAtS+bL+0whhLWtlpARk2t10FpgajrYXPb7XyWUfAt6fC3Q2Jeb AsVt6XmVd9YJB+EztX8xj0Ju93913+xIvCxNtMwTR5JEu8zlpAdux272v rbmzXU0pcREbNUis9Lh+NXMGvFOGXGhMgekUb3xLMQt76ErNpKiu12+L/ w7X7pVWN9/vPmGBdshMHurSFFwMhjNhgNcFlsdU3T2j0p9DrBRA0RcZMt TcwhYKQhpTxbh+MEF+CKAj+qOq8NXc+UsKKx/ndqo0NXm6whDzjnZccTh w==; X-IronPort-AV: E=McAfee;i="6600,9927,10992"; a="28395436" X-IronPort-AV: E=Sophos;i="6.06,179,1705392000"; d="scan'208";a="28395436" Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Feb 2024 21:19:04 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,179,1705392000"; d="scan'208";a="5999892" Received: from allen-box.sh.intel.com ([10.239.159.127]) by fmviesa006.fm.intel.com with ESMTP; 22 Feb 2024 21:19:02 -0800 From: Lu Baolu To: Joerg Roedel , Will Deacon , Robin Murphy , Jason Gunthorpe , Kevin Tian , Eric Badger Cc: iommu@lists.linux.dev, linux-kernel@vger.kernel.org, Lu Baolu , Jason Gunthorpe Subject: [PATCH 1/2] iommu: Add static iommu_ops->release_domain Date: Fri, 23 Feb 2024 13:13:01 +0800 Message-Id: <20240223051302.177596-2-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240223051302.177596-1-baolu.lu@linux.intel.com> References: <20240223051302.177596-1-baolu.lu@linux.intel.com> 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: 1791670555007026587 X-GMAIL-MSGID: 1791670555007026587 The current device_release callback for individual iommu drivers does the following: 1) Silent IOMMU DMA translation: It detaches any existing domain from the device and puts it into a blocking state (some drivers might use the identity state). 2) Resource release: It releases resources allocated during the device_probe callback and restores the device to its pre-probe state. Step 1 is challenging for individual iommu drivers because each must check if a domain is already attached to the device. Additionally, if a deferred attach never occurred, the device_release should avoid modifying hardware configuration regardless of the reason for its call. To simplify this process, introduce a static release_domain within the iommu_ops structure. It can be either a blocking or identity domain depending on the iommu hardware. The iommu core will decide whether to attach this domain before the device_release callback, eliminating the need for repetitive code in various drivers. Consequently, the device_release callback can focus solely on the opposite operations of device_probe, including releasing all resources allocated during that callback. Co-developed-by: Jason Gunthorpe Signed-off-by: Jason Gunthorpe Signed-off-by: Lu Baolu Reviewed-by: Kevin Tian --- include/linux/iommu.h | 1 + drivers/iommu/iommu.c | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/include/linux/iommu.h b/include/linux/iommu.h index de839fd01bb8..e3d9365b0fa9 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -585,6 +585,7 @@ struct iommu_ops { struct module *owner; struct iommu_domain *identity_domain; struct iommu_domain *blocked_domain; + struct iommu_domain *release_domain; struct iommu_domain *default_domain; }; diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 210dc7b4c8cf..fb06c3f47320 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -459,6 +459,18 @@ static void iommu_deinit_device(struct device *dev) iommu_device_unlink(dev->iommu->iommu_dev, dev); + /* + * If the iommu driver provides release_domain then the core code + * ensures that domain is attached prior to calling release_device. + * Drivers can use this to enforce a translation on the idle iommu. + * Usually the global static blocked_domain is a good choice. + * + * Anyway, if a deferred attach never happened then the release + * should still avoid touching any hardware configuration either. + */ + if (!dev->iommu->attach_deferred && ops->release_domain) + ops->release_domain->ops->attach_dev(ops->release_domain, dev); + /* * release_device() must stop using any attached domain on the device. * If there are still other devices in the group they are not effected From patchwork Fri Feb 23 05:13:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolu Lu X-Patchwork-Id: 205279 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp486468dyb; Fri, 23 Feb 2024 02:06:33 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWbXqTHMgd+a2bXcebNLYBxGutQD59WctuYR6WxTC3Ofi6/SgNqSEWi0EUQp5B13FhDwlH2BniDps0zAjWhPFDWDXudgg== X-Google-Smtp-Source: AGHT+IFIuDQvQ/txfn4Btx3snM9U+S08ssAegvNxM79SHClM+LF1eHelugU7e+PNna2tzQ63o8HY X-Received: by 2002:a05:6402:14d0:b0:564:4a18:45f1 with SMTP id f16-20020a05640214d000b005644a1845f1mr935157edx.17.1708682792960; Fri, 23 Feb 2024 02:06:32 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708682792; cv=pass; d=google.com; s=arc-20160816; b=kbSIsCamCkNZIHqt8NhHb/srd0bysyFjwihL7gIivADBbp0KjBFgMcrL2Qiff51eIx /K00LvRYwQ6d6zv75C7a2S4plYCeLb1DLrOpIYx75nXjCs0spJtAD3jruayZAGWUFfkQ MqOoQ58JjqZfxZnrlHY0NwMVBdcbSp/hgY29mycu3CilgPToUKyoHkr18wv9T5AAoiis 8NnMKrQd/8JkEEsktbT4ZJ5MevOCIVnvsMiGajWz99UfMiLfWWmzMzN5CQMSW3+HWIcX RmZjfPGB9zXCbPMO/80LDF61t6Wuy3PSZXL59UyS++KXSUKJIdDciiiv9LgIuBsi0Y06 nnYw== 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:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=+PEAaAkIgcEsCiZei4bxJ4a+U0NqNree5iHzl0weBcE=; fh=q/aNRRwbk+AHb42I2d6wYfBCRE+T0txaX+dEwQcyGW0=; b=mW4xX0oaqVXvzBb/LArV5X7TfbW64CLyCJLBPnXoq9ctScnL83j8x6Ljt3ZRKbvGHA qgbaVxahhtJR7RAcXyCLG+42pECqE5IpTKFviXor2I8iByvnocwEn3xniNMWFEbmxv6x XqHASIvXMYPKrORPfN3mK2Wqc/Q5aZiOFuH34OUAO72dil4ZrP08EPW9HleY8sn9m+y0 n/fHn0mTMtX76akXovodteST79Ky7O6QuMfmPqsiMqeBuB9Gag8YjcNwX7XpMajH0Fba ESaXCrUf9rVscI7yF8gPN88QqkpFh9otcMZt3NqsH0xbauW5NQMJY9QKlDHfa+7weP8e mKRw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=J8HQ4a42; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-77783-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-77783-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id ch12-20020a0564021bcc00b00564aaa765a6si3728224edb.249.2024.02.23.02.06.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Feb 2024 02:06:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-77783-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=J8HQ4a42; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-77783-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-77783-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 692DF1F26370 for ; Fri, 23 Feb 2024 05:19:42 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DF4BA12E46; Fri, 23 Feb 2024 05:19:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="J8HQ4a42" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.7]) (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 BE4C6125B8 for ; Fri, 23 Feb 2024 05:19:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708665548; cv=none; b=fmEI2CfYBoxh+YmhZ2wNGqe9R6YuG894VTtIIAW4I3t81Xn59T2Yy7e4+JHo57a9rOqxr2O3Q+SOSWNsnSeHNdLZnoF8lTpaXWGu3MsoiHFXfMdx98RioFfUSptPZ8aFSzDg0yOvpQbK5QW51b1pzQ2PN/pZmIi9dLZuhZIOwy0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708665548; c=relaxed/simple; bh=aj8WBi473QKu6WuNMZasSmz84DJgvffMYsFTZXTEz2c=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=aCiUqPw4fMebwTF/aJnT6kEx874TUkr+HIc+dIcAune5o+ASuoE7kXiWQsU6OmmoYZOWJxQUzyJtVPe4kzAYG5LSia4SXsVvuNyKtUrEkb8ukcocnmeBBq1kQ4aF1L9BxFclm+AuW9hfUak1aWhoGNRNpgJsTuALT62+AWjYKfk= 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=J8HQ4a42; arc=none smtp.client-ip=192.198.163.7 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=1708665547; x=1740201547; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=aj8WBi473QKu6WuNMZasSmz84DJgvffMYsFTZXTEz2c=; b=J8HQ4a42Y9/M9eF6VjeULe0cmZ+gQDAsCXydSNqqGZHt2cq3uZ91OI++ 52DqxWehh7/toKzE09GRn6mk/lOuyWbOWtAuVT4Yb/Ne05LeB/YyozMTR 6R09jHtBnwIf03339E7hW0txNyNEBzdw2ZQY6F27cEAcgPoG+H2eoBlas ZFpsPFj1EZsa5+x75QkFYyi6D9qTjnZppCA0LbDvk7yIMYtWXzBblViRX N7cWEyqYnSB9b4pDSXCOsJPPjHc7vKEV0sE8wYUqE/33e16ic6yPzWkDa Ul2T6shG3bNDwPATeRIvcLnTCru6Yb7QkJCQenqAoEch2oVNuhWTdg8mH A==; X-IronPort-AV: E=McAfee;i="6600,9927,10992"; a="28395445" X-IronPort-AV: E=Sophos;i="6.06,179,1705392000"; d="scan'208";a="28395445" Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Feb 2024 21:19:06 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,179,1705392000"; d="scan'208";a="5999900" Received: from allen-box.sh.intel.com ([10.239.159.127]) by fmviesa006.fm.intel.com with ESMTP; 22 Feb 2024 21:19:04 -0800 From: Lu Baolu To: Joerg Roedel , Will Deacon , Robin Murphy , Jason Gunthorpe , Kevin Tian , Eric Badger Cc: iommu@lists.linux.dev, linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH 2/2] iommu/vt-d: Fix NULL domain on device release Date: Fri, 23 Feb 2024 13:13:02 +0800 Message-Id: <20240223051302.177596-3-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240223051302.177596-1-baolu.lu@linux.intel.com> References: <20240223051302.177596-1-baolu.lu@linux.intel.com> 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: 1791683768076298239 X-GMAIL-MSGID: 1791683768076298239 In the kdump kernel, the IOMMU operates in deferred_attach mode. In this mode, info->domain may not yet be assigned by the time the release_device function is called. It leads to the following crash in the crash kernel: BUG: kernel NULL pointer dereference, address: 000000000000003c ... RIP: 0010:do_raw_spin_lock+0xa/0xa0 ... _raw_spin_lock_irqsave+0x1b/0x30 intel_iommu_release_device+0x96/0x170 iommu_deinit_device+0x39/0xf0 __iommu_group_remove_device+0xa0/0xd0 iommu_bus_notifier+0x55/0xb0 notifier_call_chain+0x5a/0xd0 blocking_notifier_call_chain+0x41/0x60 bus_notify+0x34/0x50 device_del+0x269/0x3d0 pci_remove_bus_device+0x77/0x100 p2sb_bar+0xae/0x1d0 ... i801_probe+0x423/0x740 Use the release_domain mechanism to fix it. Fixes: 586081d3f6b1 ("iommu/vt-d: Remove DEFER_DEVICE_DOMAIN_INFO") Reported-by: Eric Badger Closes: https://lore.kernel.org/r/20240113181713.1817855-1-ebadger@purestorage.com Signed-off-by: Lu Baolu Reviewed-by: Kevin Tian --- drivers/iommu/intel/iommu.c | 26 +------------------------- 1 file changed, 1 insertion(+), 25 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 61bb35046ea4..2c04ea90d22f 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -3798,30 +3798,6 @@ static void domain_context_clear(struct device_domain_info *info) &domain_context_clear_one_cb, info); } -static void dmar_remove_one_dev_info(struct device *dev) -{ - struct device_domain_info *info = dev_iommu_priv_get(dev); - struct dmar_domain *domain = info->domain; - struct intel_iommu *iommu = info->iommu; - unsigned long flags; - - if (!dev_is_real_dma_subdevice(info->dev)) { - if (dev_is_pci(info->dev) && sm_supported(iommu)) - intel_pasid_tear_down_entry(iommu, info->dev, - IOMMU_NO_PASID, false); - - iommu_disable_pci_caps(info); - domain_context_clear(info); - } - - spin_lock_irqsave(&domain->lock, flags); - list_del(&info->link); - spin_unlock_irqrestore(&domain->lock, flags); - - domain_detach_iommu(domain, iommu); - info->domain = NULL; -} - /* * Clear the page table pointer in context or pasid table entries so that * all DMA requests without PASID from the device are blocked. If the page @@ -4348,7 +4324,6 @@ static void intel_iommu_release_device(struct device *dev) { struct device_domain_info *info = dev_iommu_priv_get(dev); - dmar_remove_one_dev_info(dev); intel_pasid_free_table(dev); intel_iommu_debugfs_remove_dev(info); kfree(info); @@ -4839,6 +4814,7 @@ static const struct iommu_dirty_ops intel_dirty_ops = { const struct iommu_ops intel_iommu_ops = { .blocked_domain = &blocking_domain, + .release_domain = &blocking_domain, .capable = intel_iommu_capable, .hw_info = intel_iommu_hw_info, .domain_alloc = intel_iommu_domain_alloc,