Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp1121332rdb; Fri, 2 Feb 2024 14:41:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IEkzBAAZjzlRKUJmr8GfbY7Yg6QviE0/4koFvZvj9drkZ6mh/qah57g7WDMPn/cNZpX95Q6 X-Received: by 2002:a05:620a:4cd:b0:783:e312:b212 with SMTP id 13-20020a05620a04cd00b00783e312b212mr7257933qks.28.1706913675970; Fri, 02 Feb 2024 14:41:15 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706913675; cv=pass; d=google.com; s=arc-20160816; b=TDs5qNs4yNSC82rHnvbEwZm5SEbnhFLM6NnvsK5h/uyK3rnASCGAdB5QfyUukXRcFC 7IqDr3vEnr4f5Yg7HN3RSUd4tf3yQJ2NzNNwuumxzGiWib+KP88bCRK6tneERT7zxFRG E7wWv3UlRJ94Ldl+gyruXUsdYgNhtLJaULPKISTaa2ELW+a2DDAChJ1RFafarQzbCblQ vL/97zSYe05aKPxlBdzKtmBYi8q7AhTqRCZyNm3UzbExLLp7MC0Na70lqI3V7G+AaZfp cuiKHx8B1QNmMROSWI+igpxr6ckShfQRhAIDNkrbK0C0FZiJI+v2Da+qdvE0Yuczwg8Z 4PSw== 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:message-id:subject:cc:to:from :date:dkim-signature; bh=cQ84/dM6r5+XQ9l1JYmTyXL65cu1ZciN2WFkzUcV0Fo=; fh=GNDCKAG5aNHPmBnmpoSnNWmz26BlbrHPjBXx++gRRoo=; b=uWhmfWibGESeYAx4w/aYV7GaZS/tWL2GbRlB1II3xNtVgmPvndG1u5f9QEGayMOMKJ CgWS5Z982unfZoV9mkNl+g8ogSCaseIP3WtSj1T+WS4Q98MrA5P9+d+uzf5GqZB5KgRy 6xmUh4LIPINYDdkLyIWhWzJ9oqqCRFYC8KojL0HWa/ArOmzk96PwdbxI7dbBJb3ihEZG nybZZGEbLTylDqngMUy/q/EprSigOZ/mcCHbYl21FvHg+/kO+Du4Q1Z7b9ar5MR50gTU tMf/IldfHNI0aZBXBw0ocAN16nxPgiHkt3AreoPeN6bmJu2lgktyQeTi9QeDf7y1yM50 ZabQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=C0BT3gKq; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-50677-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50677-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=1; AJvYcCXTWqysQQ7piLt65TnxP2iLmto6iywRZR2/igwjGtK4J3POU7zM0k55gmTXXCETA7Yby/QDXKf79S4vdreogdhWXfToYE2HjNddpqb+nw== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id v18-20020ae9e312000000b0078552f9938dsi2941123qkf.618.2024.02.02.14.41.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 14:41:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-50677-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=C0BT3gKq; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-50677-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50677-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=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 ny.mirrors.kernel.org (Postfix) with ESMTPS id B83741C2318B for ; Fri, 2 Feb 2024 22:41:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6DEA8126F1F; Fri, 2 Feb 2024 22:41:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="C0BT3gKq" 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 85FF85FF01; Fri, 2 Feb 2024 22:41:04 +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=1706913664; cv=none; b=Yais/WTUy5NhLpPtfvBWVJmYsEtMpb0i9c/jRAWQAwYZ7CPxhHGre089r7Svrivkj4+a/2HnNePxJO3PkF6Ja98pvOJXNZMcdJlHWZew5/akG7HzFts+3xPAg5grlI3gnS/Vi8SbVfGIYw3yi1pqWkhOiD3AsRQIuR1VhTTHe+E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706913664; c=relaxed/simple; bh=exAcKdkKTYBbj02//ly4ATQZUG2yWNQEYrX161BJntQ=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition:In-Reply-To; b=XReBinshtzcOl61vvAHjnU1hVahw3TkPKdfE8Szrs4swwpWeLZhl0gTgMdnVGx3tv6e1a/3yTv8oh39ud1VO7kZ4W0wQomXai8OSh9QlRj3pBb5u8l9oG315+Fkz3Fef67OFPTeUz8GVo/n1QS6tmodq6uTXTr2a3RTTyNhqOcU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=C0BT3gKq; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id C09AFC433F1; Fri, 2 Feb 2024 22:41:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706913664; bh=exAcKdkKTYBbj02//ly4ATQZUG2yWNQEYrX161BJntQ=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=C0BT3gKqwpPjY19LTrjlAry5YR+7VFmLrXnqBKSxsPdigLPMyFBx1J8fLuBgr6+Lm SlOqNOr5Ox2iiPD8FwnoRna1dURYlqzetiDJ68DVSJKAlQWGXM5rBcBu91MeSbgsjn FSnTpRo7EFNyAoBUtXWrjpuSQQvoSWnAKFGfGA4afTAkdDkrBPMjn5W3bDvsG8cIRq CSXLOS+4bWNuRPtFrlrAQrrcf+vsjyX+BBnZPKKN43iy0nD2+DJDIva9KxjUIxRTPB ax9ObTb5QHrm7ecQsHgyoNM6FgVNee0xu7OxCAwTzZfNui7WbRUtlVBSNXAqkRvUyc 3kOV+bOjZbkvQ== Date: Fri, 2 Feb 2024 16:41:02 -0600 From: Bjorn Helgaas To: Hamza Mahfooz Cc: linux-kernel@vger.kernel.org, stable@vger.kernel.org, Greg Kroah-Hartman , "Rafael J. Wysocki" , Alex Deucher , Christian =?utf-8?B?S8O2bmln?= , "Pan, Xinhui" , David Airlie , Daniel Vetter , Bjorn Helgaas , Mario Limonciello , Lijo Lazar , Srinivasan Shanmugam , Le Ma , =?utf-8?B?QW5kcsOp?= 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, Bartosz Golaszewski Subject: Re: [PATCH 3/3] drm/amdgpu: wire up the can_remove() callback Message-ID: <20240202224102.GA732304@bhelgaas> 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> [+cc Bartosz] 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. Maybe this would help for things that are completely built-in or soldered down, but nothing can prevent a user from physically pulling a card or cable, so I don't think this is a generic solution to the problem of dangling user space references. Maybe Bartosz's recent LPC talk is relevant: https://lpc.events/event/17/contributions/1627/ > 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; > +} > + > static void > amdgpu_pci_remove(struct pci_dev *pdev) > { > @@ -2929,6 +2945,7 @@ static struct pci_driver amdgpu_kms_pci_driver = { > .name = DRIVER_NAME, > .id_table = pciidlist, > .probe = amdgpu_pci_probe, > + .can_remove = amdgpu_pci_can_remove, > .remove = amdgpu_pci_remove, > .shutdown = amdgpu_pci_shutdown, > .driver.pm = &amdgpu_pm_ops, > -- > 2.43.0 >