Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 96CADECAAD3 for ; Thu, 1 Sep 2022 18:36:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 304D580041; Thu, 1 Sep 2022 14:36:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 28D9C8000D; Thu, 1 Sep 2022 14:36:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1084880041; Thu, 1 Sep 2022 14:36:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id F24038000D for ; Thu, 1 Sep 2022 14:36:45 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id CFC2C14074F for ; Thu, 1 Sep 2022 18:36:45 +0000 (UTC) X-FDA: 79864372770.01.9A3A1A1 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf15.hostedemail.com (Postfix) with ESMTP id 743F6A0046 for ; Thu, 1 Sep 2022 18:36:45 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 8DB9C61CFB; Thu, 1 Sep 2022 18:36:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 68479C433D6; Thu, 1 Sep 2022 18:36:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1662057404; bh=4EGc98ePtGVoW/OVpl29pIB0Xv/vWLpMdUFKeCItABY=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=xFeGxXLUUQuSqZdVXhkzgw5JZFhnJkqiyA7MU8ELHe3FJve40mXqCLp9o6Fh+/lAf yijiTz3pzHkV1ZEn5hg/537CIQ4D8j2AVuE8Pd8EnOW7zd0tEDyU+ODP2GX+/Dt8iD Xilxi4k7yFbvYeFd6jE9lPw3HjO8pop87qrBfh24= Date: Thu, 1 Sep 2022 20:36:41 +0200 From: Greg Kroah-Hartman To: Logan Gunthorpe Cc: linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, linux-block@vger.kernel.org, linux-pci@vger.kernel.org, linux-mm@kvack.org, Christoph Hellwig , Dan Williams , Jason Gunthorpe , Christian =?iso-8859-1?Q?K=F6nig?= , John Hubbard , Don Dutile , Matthew Wilcox , Daniel Vetter , Minturn Dave B , Jason Ekstrand , Dave Hansen , Xiong Jianxin , Bjorn Helgaas , Ira Weiny , Robin Murphy , Martin Oliveira , Chaitanya Kulkarni , Ralph Campbell , Stephen Bates Subject: Re: [PATCH v9 7/8] PCI/P2PDMA: Allow userspace VMA allocations through sysfs Message-ID: References: <20220825152425.6296-1-logang@deltatee.com> <20220825152425.6296-8-logang@deltatee.com> <4a4bca1e-bebf-768f-92d4-92eb8ae714e1@deltatee.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1662057405; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=1AT1S+3qhBfI4/31yANv2bvnScixdjnjUQEHEM7f9Bc=; b=R+6hed6S5KTCNW6u0qV69JjqhnxSJI1Mcy9XyDl2kMFdyba+L/ICmfz1mLaQkBiWAv0si9 shfJtpPR7SlyHf7cu7jmcQ2aJu9hKvD4C2onFFJZg+pBtNnh87PoN7WdNSOLzIcSBpJlbQ yUpDNa30W3pZnGyoKpvrmpp9bG6Qkks= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=linuxfoundation.org header.s=korg header.b=xFeGxXLU; dmarc=pass (policy=none) header.from=linuxfoundation.org; spf=pass (imf15.hostedemail.com: domain of gregkh@linuxfoundation.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=gregkh@linuxfoundation.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1662057405; a=rsa-sha256; cv=none; b=ZpUMcXzsYs0kUc3CP2UhUA+awaUbAbl5iog2V0Q8qIxhnmoKoFlS/0/cVltsGb8s0qTJZ1 E0ouwdQfoRszsHtXJFV233wG4WzOYypR4pXBHEHDqRWbHI8lxijNTGeVlUjT/spTPbw7Qo 3YHXexmNrmBJwD8krXljt5DuU+iu56I= Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=linuxfoundation.org header.s=korg header.b=xFeGxXLU; dmarc=pass (policy=none) header.from=linuxfoundation.org; spf=pass (imf15.hostedemail.com: domain of gregkh@linuxfoundation.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=gregkh@linuxfoundation.org X-Rspamd-Queue-Id: 743F6A0046 X-Stat-Signature: usnyfrxreffw51rcm7zw8zzxrphw17oi X-Rspam-User: X-Rspamd-Server: rspam02 X-HE-Tag: 1662057405-993182 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Thu, Sep 01, 2022 at 12:14:25PM -0600, Logan Gunthorpe wrote: > > > > On 2022-09-01 10:42, Greg Kroah-Hartman wrote: > > On Thu, Sep 01, 2022 at 10:32:55AM -0600, Logan Gunthorpe wrote: > >> On 2022-09-01 10:20, Greg Kroah-Hartman wrote: > >>> On Thu, Aug 25, 2022 at 09:24:24AM -0600, Logan Gunthorpe wrote: > >>>> + /* > >>>> + * Removing the alloc attribute from sysfs will call > >>>> + * unmap_mapping_range() on the inode, teardown any existing userspace > >>>> + * mappings and prevent new ones from being created. > >>>> + */ > >>>> + sysfs_remove_file_from_group(&pdev->dev.kobj, &p2pmem_alloc_attr.attr, > >>>> + p2pmem_group.name); > >>> > >>> Wait, why are you manually removing the sysfs file here? It's part of > >>> the group, if you do this then it is gone for forever, right? Why > >>> manually do this the sysfs core should handle this for you if the device > >>> is removed. > >> > >> We have to make sure the mappings are all removed before the cleanup of > >> devm_memremap_pages() which will wait for all the pages to be freed. > > > > Then don't use devm_ functions. Why not just use the manual functions > > instead as you know when you want to tear this down. > > Well we haven't plugged in a remove call into p2pdma, that would be more > work and more interfaces touching the PCI code. Note: this code isn't a > driver but a set of PCI helpers available to other PCI drivers. > Everything that's setup is using the devm interfaces and gets torn down > with the same. So I don't really see the benefit of making the change > you propose. The issue is the classic one with the devm helpers. They do not lend themselves to resource management issues that require ordering or other sort of dependencies. Please do not use them here, just put in a remove callback as you eventually will need it anyway, as you have a strong requirement for what gets freed when, and the devm api does not provide for that well. thanks, greg k-h