Received: by 2002:a05:7412:8d1c:b0:fa:4c10:6cad with SMTP id bj28csp126381rdb; Tue, 16 Jan 2024 17:59:30 -0800 (PST) X-Google-Smtp-Source: AGHT+IEYQCmqNJ/1I0izr9u54UcgFzRpmGoJOzmc7zgpdND1GioiL0mUfFLDg6GezMZh3kRyLfp+ X-Received: by 2002:a9d:7a93:0:b0:6e0:cc83:b421 with SMTP id l19-20020a9d7a93000000b006e0cc83b421mr982308otn.61.1705456770358; Tue, 16 Jan 2024 17:59:30 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705456770; cv=pass; d=google.com; s=arc-20160816; b=jWBIKJKMCEW3ZZRKqj83dmJh86/CL77MT7G/Wb7JqRr+m/HnrxvgzZ13Szb8J4po2/ nwuASBXOW5XOziPk+ZhaiY2NKgqsNZm2oaUi9k0TAo/oRcj24nPXV3fsNkyUA8qslpwl oaXQVannRkQQE4ueAuKRofUJkQXafx3VnL6RpqBENMJreEgh6wgOvFrth9a+OjRymYwS GPPVLLuZuKSZMb7USY+M1Ynnqy9sK4EKXy5cgmvwTf2tM2ncVirgcl5A+5a6MSwRGJsD WDA7NOfGWAh9gbTOsa4XpzaKLXUJuLP/k76qVemsiRkxTEs0lRubrolwAYbubk+lai6p Kp0A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id; bh=bHCmKfdCKOkr+rbpbd+PvBki5+gVN4nZXjiw+t8UUCA=; fh=OP5Mdm/Wt5jT0XlNyiQPwy9Z5xOyjdOF9feQHPhVuXk=; b=zhlN6iC2KDTvN3t96+X3JZ7sz8qh7At/CI/OD5O4xWMlDv9XZ5+yYW4AvjRTBuwuJ1 mxz3pc0yf2XJ+qGKGr+HRyGYZadfKt3VVGO+AdzV6NHtpKnS5yT+iH4LpM0HnVcEU83N NkmA7No7PTpNGQPGk3WDRahkTgOJFPloM5KZBNhcB1uDsBpb2XDE59KxiJ0sxwQRdbHA AvxaT+szFo35T41ZOBMAcg6uwbTYdGZayx/yXIk70yJhLbZQtRMWiS8iyWkpaADN88xQ DVvMt9Q7ZoMqVpSwcnE29dEMcLDLA7c1ARpcYmupn0QWJfddYeaPeho7ImCR40eXehAf I7xg== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-28446-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-28446-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id d34-20020a631d62000000b005cdb499a9aasi12274972pgm.704.2024.01.16.17.59.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Jan 2024 17:59:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-28446-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-28446-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-28446-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 40B0DB21F42 for ; Wed, 17 Jan 2024 01:57:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 70D5017FD; Wed, 17 Jan 2024 01:57:42 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1545F10E9 for ; Wed, 17 Jan 2024 01:57:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705456662; cv=none; b=k+B6dg1q/D92196bEDwFu7Cz8ORvby+N9n+A5vNM18Y1/8+Vb+5FawfoHQM/Z3aVSVwBB65o+/Qm//BZJLD/r8Hqixo+R8xTnFchIjPDmTDm35E/w5wh3kmdAGSVQ/8m4AoS8/qKvZ+ZiMpNTA7dZJn8UMklZcxKSXs2Hh5n5uY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705456662; c=relaxed/simple; bh=/SrlWjIMTigyESjz1QsaSHrVg3bHKGkzoomgx993OW4=; h=Received:Received:Message-ID:Date:MIME-Version:User-Agent:Subject: Content-Language:To:Cc:References:From:In-Reply-To:Content-Type: Content-Transfer-Encoding; b=s5Yj1wdyey6D0hEwlVW73iSzTuVO7NXQ6vkIywKN7DOw1vjMY5lXUm/Msam3NDeVRy9aHjDjfkByg/m6bZqK7PzbrMKVaAmhbooflwq2rp+/14PHKtONIG/J7nYSg0kX/RaRj20aD3jV0pJtZRUkUK4COzFrcK+z1LnwcmRQC1I= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 8D5182F4; Tue, 16 Jan 2024 17:58:24 -0800 (PST) Received: from [10.57.46.46] (unknown [10.57.46.46]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id E4D763F5A1; Tue, 16 Jan 2024 17:57:36 -0800 (PST) Message-ID: <46a61123-dd22-46cb-8b2a-15431fcc03f1@arm.com> Date: Wed, 17 Jan 2024 01:57:34 +0000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] iommu/vt-d: Check for non-NULL domain on device release Content-Language: en-GB To: Jason Gunthorpe , Eric Badger Cc: David Woodhouse , Lu Baolu , Joerg Roedel , Will Deacon , "open list:INTEL IOMMU (VT-d)" , open list References: <20240113181713.1817855-1-ebadger@purestorage.com> <20240116152215.GE50608@ziepe.ca> From: Robin Murphy In-Reply-To: <20240116152215.GE50608@ziepe.ca> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 2024-01-16 3:22 pm, Jason Gunthorpe wrote: > On Sat, Jan 13, 2024 at 10:17:13AM -0800, Eric Badger wrote: >> In the kdump kernel, the IOMMU will operate in deferred_attach mode. In >> this mode, info->domain may not yet be assigned by the time the >> release_device function is called, which leads to the following crash in >> the crashkernel: > > This never worked right? But why are you getting to release in a crash > kernel in the first place, that seems kinda weird.. > >> 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 >> >> Signed-off-by: Eric Badger > > It should have a fixes line, but I'm not sure what it is.. > >> --- >> drivers/iommu/intel/iommu.c | 10 ++++++---- >> 1 file changed, 6 insertions(+), 4 deletions(-) > > Unfortunately this issue is likely systemic in all the drivers. All two of the drivers which support deferred attach, that is. > Something I've been thinking about for a while now is to have the > option for the core code release to set the driver to a specific > releasing domain (probably a blocking or identity global static) > > A lot of drivers are open coding this internally in their release > functions, like Intel. But it really doesn't deserve to be special. Either way it shouldn't apply in this case, though. Crash kernels *are* special. The whole point of deferred attach is that we don't disturb anything unless we've got as far as definitely using a given default domain (from which we can infer the relevant client device should have been reset and quiesced). Thus regardless of why release might get called, if a deferred attach never happened then the release should still avoid touching any hardware configuration either. I'd suggest using dev->iommu->attach_deferred as the condition rather than a NULL domain, to be clear that it's the *only* valid reason to not have a domain at this point. Thanks, Robin.