Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp1143646rdb; Fri, 2 Feb 2024 15:42:51 -0800 (PST) X-Google-Smtp-Source: AGHT+IE2ymsxyskBBldkOhhtHzn0tFDkPP6uR3w5OD9i42VIvjETIYzAHrYRjgsRFayk4tovUtMw X-Received: by 2002:a05:6214:d46:b0:68c:44f7:6c8b with SMTP id 6-20020a0562140d4600b0068c44f76c8bmr3393215qvr.55.1706917371099; Fri, 02 Feb 2024 15:42:51 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706917371; cv=pass; d=google.com; s=arc-20160816; b=ta/CTuXIuKEePLS/tREbI5YZTYhz8bwPVrdznyrVDvKNF8p27LdRXx+AfubwCehiCh NbDa0gEuVKhXi0Qlr2ZfXLeM/lYpL/kfI9+5KEb0uPJhUpLdcDMoXIO8ncN/7z/rcnoh 3MmgVqhebaMVI+67W+VDvsWKHv8h/Vb+cu4WepqbvjQTDq+sCsR7n2zQKot8wsLzi7i5 7+VPw1kOAGD6V4CSHafhqxfcV8XCPmlMazsoRFdhj2nflBdx3GnpkaKM4lp2xrW2cbZP BLeA3i11u2eZLtmVmIkaPLl/30TZrrWC1tjZCc8zgPS1W2lg9LjsRLZP7Js6V6jqYKcu Vw6Q== 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=KreXj3XRcmUATlF2IWVhPeDd2ZfZ7NMvK9mcpXM1hJk=; fh=0c0UNOR7nyvgdjJBbAsASz7ObILVKg2gcVLKrPbBnvc=; b=VyPtqyx/5Hr+vEQj3WHiKZzwv7Zd7e5nPoy5tpZFAMa1ryGDSeIPNc19GaLYj+3I7Z P9foj+yEG+7JQoCpG5Rns9qA5U62g4FBK4FQLiNGEeRNAqYvVqo1C+rU5zU4Q82zrJZn pM8nKqODvBexA8sprjY+u+/1kCvdE1nwSPBNWOEpJcvtkWynTmiwDRdxWoDjvckNO8K6 J3XMO322boQJPu0NfRfeOPDuEt04lIdbmq3g7rZW0CRqtzHHhO1r+bRAEROkC0IxLWAf qJR3BxucCJBmOBcgZJUoMNT3kmf5MUQkKSr7dQ57tJTlIxU8sNykzHqSNKplSEvm+nm2 ShQA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=zZaZBQti; arc=pass (i=1 dkim=pass dkdomain=linuxfoundation.org); spf=pass (google.com: domain of linux-kernel+bounces-50724-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50724-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org X-Forwarded-Encrypted: i=1; AJvYcCXbHj50R/uvlvB+eYtUyWSCUc/9k0G6H1NxlYe5VVBgSv5pfMA6mQ2ccYL1wqojhrJ9T0UrXTa2ff8PemlpV96x1Q/NkC9sYWS0qGQWVQ== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id m7-20020a05620a290700b007855760151fsi2643855qkp.362.2024.02.02.15.42.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 15:42:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-50724-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=zZaZBQti; arc=pass (i=1 dkim=pass dkdomain=linuxfoundation.org); spf=pass (google.com: domain of linux-kernel+bounces-50724-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50724-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.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 ny.mirrors.kernel.org (Postfix) with ESMTPS id D42431C2174E for ; Fri, 2 Feb 2024 23:42:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5FA84133282; Fri, 2 Feb 2024 23:41:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="zZaZBQti" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 6F7F5132480; Fri, 2 Feb 2024 23:41:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706917284; cv=none; b=cyo6352daf3vZkL682RqS/dVtjGbHgw9ahPN46c1B7W0bIq8XFi9vpQ87j1MiQv+EX1cT5w3aeRCDSAUmYyIeJAbdpuNUTq6AVpAkjPHUwF09lZvJAbZ7NUBJS8bd3bBDEVw7VB/j/x15jyNsh97dkahsnIG3kVRy828+LxVxeA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706917284; c=relaxed/simple; bh=gX+4EF1aa8LAyzPJib2hQOtkg0CUXK5HquVqw1n55so=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ZFs8gdxcj8N9Airq5RhY43wj5OxueDzIVq7WOGncvu/lLEplgE4mLi4Y/xYqVMfiR2MVeIa0TlCgqlCZRFGb00g6vUDecAQjUt8zwNWxJlP3CFkvzGS/KEGPCetirt+/vyhtMjJMMbippS6H7UzRxeUTdCEJDgaaLIKUlVoUFfI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=zZaZBQti; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id BC7DDC433A6; Fri, 2 Feb 2024 23:41:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1706917283; bh=gX+4EF1aa8LAyzPJib2hQOtkg0CUXK5HquVqw1n55so=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=zZaZBQtipCcf5XBGD66l7h1yJKY1ffHOnvxlbMtnRWA3xh9aONF4zzKTO6U6oVTZG j4ftTBoZkLHG6gZyYjjrMLkVh+1o6h3+gq5c0PQg91mWkhiEgE6ngXzTGsBf+39xK8 S0wo69WpngQm/A6CTieAkB6+8kZG8WR58yEq4TGw= Date: Fri, 2 Feb 2024 15:41:23 -0800 From: Greg Kroah-Hartman To: Hamza Mahfooz Cc: linux-kernel@vger.kernel.org, stable@vger.kernel.org, "Rafael J. Wysocki" , Alex Deucher , Christian =?iso-8859-1?Q?K=F6nig?= , "Pan, Xinhui" , David Airlie , Daniel Vetter , Bjorn Helgaas , Mario Limonciello , Lijo Lazar , Srinivasan Shanmugam , Le Ma , =?iso-8859-1?Q?Andr=E9?= Almeida , James Zhu , Aurabindo Pillai , Alex Shi , Jerry Snitselaar , Wei Liu , Robin Murphy , amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-pci@vger.kernel.org Subject: Re: [PATCH 3/3] drm/amdgpu: wire up the can_remove() callback Message-ID: <2024020216-letdown-uproar-718d@gregkh> References: <20240202222603.141240-1-hamza.mahfooz@amd.com> <20240202222603.141240-3-hamza.mahfooz@amd.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: <20240202222603.141240-3-hamza.mahfooz@amd.com> On Fri, Feb 02, 2024 at 05:25:56PM -0500, Hamza Mahfooz wrote: > Removing an amdgpu device that still has user space references allocated > to it causes undefined behaviour. So, implement amdgpu_pci_can_remove() > and disallow devices that still have files allocated to them from being > unbound. > > Cc: stable@vger.kernel.org > Signed-off-by: Hamza Mahfooz > --- > drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 17 +++++++++++++++++ > 1 file changed, 17 insertions(+) > > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c > index cc69005f5b46..cfa64f3c5be5 100644 > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c > @@ -2323,6 +2323,22 @@ static int amdgpu_pci_probe(struct pci_dev *pdev, > return ret; > } > > +static bool amdgpu_pci_can_remove(struct pci_dev *pdev) > +{ > + struct drm_device *dev = pci_get_drvdata(pdev); > + > + mutex_lock(&dev->filelist_mutex); > + > + if (!list_empty(&dev->filelist)) { > + mutex_unlock(&dev->filelist_mutex); > + return false; > + } > + > + mutex_unlock(&dev->filelist_mutex); > + > + return true; Also, to be pedantic, this will not work as right after you returned "true" here, userspace could open a file, causing the same issue you are trying to prevent to have happen, happen. So even if we wanted to do this, which again, we do not, this isn't even a solution for it because it will still cause you problems. greg k-h