Received: by 2002:a05:7412:8d1c:b0:fa:4c10:6cad with SMTP id bj28csp135110rdb; Tue, 16 Jan 2024 18:22:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IF9Kq7YIbnHV03JiVUrHuZjqXslfGnJk+Kc1xCJq/FkClhIXKic6V05BLm0UuOXVrZ8w0jX X-Received: by 2002:a05:6358:731c:b0:175:5f:7976 with SMTP id d28-20020a056358731c00b00175005f7976mr9631382rwg.24.1705458166335; Tue, 16 Jan 2024 18:22:46 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705458166; cv=pass; d=google.com; s=arc-20160816; b=QDZQwaovNvkC2K3S0wO6g4s0yXY+cLEqwurUaif/6eEFAckid3V1Ezk83a0F7bCWWN 5PrfL2B8FUJ+SZc1eCwvoTm59WSjEAqM+NC1G4bxrKFMuCbxVvLxDr1bVlKLhdXaSl3r oQK10M8H3Jaft37g+27DNg7cwbuW9Z+o3SaAiPSDZYCj5dY3n65ukr2gNsheee2MLbWl q8MkJtZrD96zRW7zhCEzH6TcHTxymLs0RFxJur0YSPk2pIfpeBbNyPT3M4p64pawA4G7 V82REKXVdy23OsTQUsgqDF671R+qEDQJ6MIYVmHAQerzTrCZuKoNQ9Kl8AyIfHqbXNJB dNXw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=pYVZPcyXo7q2SktZ2+i1Gh7El+Ql5ZT8EyFJ+5OtVjg=; fh=c++RUaJZ5yRDYYVOcqDDVAN+ezOVJybDL4AzAJOol0I=; b=J+1O2KTUCXhnu1ee82sYdfoC7LblsL3TFJy7cNVNkkfUha0K1eYUL2wQazAw3Ga7RD 6pgtE5/4asKfb2YA/WMEJBY1kCcdFnGC0n/sSoKzndS2lJF1a9KI5TcVgWZxw5kiKcUl H18bAJskss7AhOcla8c3ZVh+jgGN8Mxd6kgJPurowJDAXofuDiiEMeL+iVq+s1xD0ShC qYlXj4+1fuHZEKx7Te+ExoO4jU2LTZT2hmd/P0AbxzVSedVPVfu1l6ULJO/4D4fh/aHQ HxqWzfurQ2Tq1NXlE9mql29uWsRTuLrdlz4Lk6B1Ujwa3yib++tj3ULZubnG9ulJuCXE 1aLw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ziepe.ca header.s=google header.b=n3+HvqFW; arc=pass (i=1 spf=pass spfdomain=ziepe.ca dkim=pass dkdomain=ziepe.ca); spf=pass (google.com: domain of linux-kernel+bounces-28458-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-28458-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id a3-20020a62d403000000b006da04ab75basi585582pfh.278.2024.01.16.18.22.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Jan 2024 18:22:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-28458-linux.lists.archive=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=@ziepe.ca header.s=google header.b=n3+HvqFW; arc=pass (i=1 spf=pass spfdomain=ziepe.ca dkim=pass dkdomain=ziepe.ca); spf=pass (google.com: domain of linux-kernel+bounces-28458-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-28458-linux.lists.archive=gmail.com@vger.kernel.org" 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 5ACB42828FA for ; Wed, 17 Jan 2024 02:20:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 380BB67C74; Wed, 17 Jan 2024 02:20:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b="n3+HvqFW" Received: from mail-qk1-f179.google.com (mail-qk1-f179.google.com [209.85.222.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E7EA35CBD for ; Wed, 17 Jan 2024 02:20:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705458025; cv=none; b=TldjZ2EPL+h5/lrAiH+QRJauxqV4uWKvGV4++5t5ldG9w6AzjYD7jaD+8Qk+NAKMDyetMKCVs18K611fKOInhFrVNfDpy8MadJoDWoMNGwqAgTO2eIlrEttmKRVzo/2+nIvrge2Pgn4TZSJGS2HMJsXSLb2m3fDpkfjKd+jh5h4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705458025; c=relaxed/simple; bh=7CVCiHmkWEtjZaOJE+H1yk91VAqzvFxUdjW7LQYfSRc=; h=Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Google-Smtp-Source:X-Received:Received: Received:Date:From:To:Cc:Subject:Message-ID:References: MIME-Version:Content-Type:Content-Disposition:In-Reply-To; b=Q58r2Xw9QBw5zOQAb5/UafCpxeEopgDR16LiHnK5khndtC2Uai38R7/H3I0SR37XretV/84Toy11xPeX66WORBW4LKcbBTk9z9UvKaDFitzJMGygu90KqDGnLfjKsN899jUzIoXZ4aNXr/mHasESZJ9wBsKMQUaK4jcmvYJvbK8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca; spf=pass smtp.mailfrom=ziepe.ca; dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b=n3+HvqFW; arc=none smtp.client-ip=209.85.222.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ziepe.ca Received: by mail-qk1-f179.google.com with SMTP id af79cd13be357-78329cb6742so520565485a.0 for ; Tue, 16 Jan 2024 18:20:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; t=1705458021; x=1706062821; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=pYVZPcyXo7q2SktZ2+i1Gh7El+Ql5ZT8EyFJ+5OtVjg=; b=n3+HvqFWQrMBUuylBVwt3ABK/gekkt2vCCFrQpILSDGnPprm4KmIx7xN8uPJRW3Rcb zxpjFgxehAI02cDFVrb8GKcjysr9Wxbsz58PxnTX3Z+9zQp57g5Tc3xEz+Y40HCKqZzB aWNlBjL3k/MAUt84DeIl6zEF5Memal1tiRlfSvVQOL5Nlbunvj0pPjLPzMwEYp/ml/DF 5SIuprZxl1MxC3psmlSUyklaKPcU42MZS2vACLz2gsCcOIMScSZ69RPr4kI5y6zTjrf0 mbcRziPs2AdU8N7VthB8R0n8UV7PUZg7mLHHVUsHVbExMKGl//EdnyX4Z0hvvNRW4Td3 bJXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705458021; x=1706062821; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=pYVZPcyXo7q2SktZ2+i1Gh7El+Ql5ZT8EyFJ+5OtVjg=; b=h9RpN4vnvL1hEL+Re79teDtk/yPAFzM8SVLN7pL5YIVkdyzhBWpvYHv2J72ytJDSFw 6N2dV7XtpxfNbY2YX0xrZ1vOfBgGUITgYYgHpjCKNwXnc/bqUeHM/j7Uw+tQGWTIXgCp aRVgCAJmC6DrIGcgNY/ePc87KAsLmtDja8HntkU/t6PQjT7+MElqVqanTCWoAPtdXkFu jqHeJn5unmGEDNkh/ehCos27F4s5yX4ob4l/qL7c8fK2yDbRhacuITbccFxXj/4DMq8O Dqp67mDQoIKwqK121c0qZVcrQOGBi8s7gdz67leuaCXrfGO5Q2iaO7vUaCFHu46rbPe5 nY3g== X-Gm-Message-State: AOJu0YwLz/Hxg/+9CfS8GaL/bI3Kfz767/oWOQ3VlaJ49SplwbdyGujn hgXCuVZXqiy1VOLRBZqrjOB9ilZRvIsThg== X-Received: by 2002:a05:620a:4554:b0:783:539a:f319 with SMTP id u20-20020a05620a455400b00783539af319mr7292948qkp.13.1705458021691; Tue, 16 Jan 2024 18:20:21 -0800 (PST) Received: from ziepe.ca (hlfxns017vw-142-68-80-239.dhcp-dynamic.fibreop.ns.bellaliant.net. [142.68.80.239]) by smtp.gmail.com with ESMTPSA id wa12-20020a05620a4d0c00b0078321f3e7c7sm4172575qkn.114.2024.01.16.18.20.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Jan 2024 18:20:21 -0800 (PST) Received: from jgg by wakko with local (Exim 4.95) (envelope-from ) id 1rPvXQ-004Zr6-Fb; Tue, 16 Jan 2024 22:20:20 -0400 Date: Tue, 16 Jan 2024 22:20:20 -0400 From: Jason Gunthorpe To: Robin Murphy Cc: Eric Badger , David Woodhouse , Lu Baolu , Joerg Roedel , Will Deacon , "open list:INTEL IOMMU (VT-d)" , open list Subject: Re: [PATCH] iommu/vt-d: Check for non-NULL domain on device release Message-ID: <20240117022020.GH50608@ziepe.ca> References: <20240113181713.1817855-1-ebadger@purestorage.com> <20240116152215.GE50608@ziepe.ca> <46a61123-dd22-46cb-8b2a-15431fcc03f1@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <46a61123-dd22-46cb-8b2a-15431fcc03f1@arm.com> On Wed, Jan 17, 2024 at 01:57:34AM +0000, Robin Murphy wrote: > > > --- > > > 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. We could call release_device on an unlikely error unwind path with a NULL domain for all drivers. > > 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). If only it were so simple.. It assumes drivers are structured to reset their devices using only MMIO before doing anything to setup DMA and trigger an iommu attach. A lot of drivers aren't and this whole scheme turns a bit sketchy. Some devices can't even do it at all. eg mlx5 has the crashing kernel quiet the device before passing over to the crash kernel because there is no way beyond FLR to regain control of a mlx5 device. > 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. Interesting point.. Makes sense to me > 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. So if we take this release_domain approach and we have the core code not call it for the defered attach case then the driver's release_device should just free memory allocated by probe and not touch the data structures? Then the idea is that drivers would only manipulate their STE/DTE/etc under attach and never in probe/release. Jason