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 C70D3C54EE9 for ; Fri, 2 Sep 2022 05:54:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 47851800B8; Fri, 2 Sep 2022 01:54:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 426CE8008D; Fri, 2 Sep 2022 01:54:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2EE76800B8; Fri, 2 Sep 2022 01:54:05 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 1BCE78008D for ; Fri, 2 Sep 2022 01:54:05 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id E3FEEA097C for ; Fri, 2 Sep 2022 05:54:04 +0000 (UTC) X-FDA: 79866079608.03.0F33183 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf13.hostedemail.com (Postfix) with ESMTP id 4B9C320032 for ; Fri, 2 Sep 2022 05:54:04 +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 4918761FC9; Fri, 2 Sep 2022 05:54:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1EA39C433D6; Fri, 2 Sep 2022 05:54:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1662098042; bh=ZCVrwOVxOedAeqF2VJSJ1MqkSUOoFJ5Np/T1O/uuDaQ=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=GGEJaSZJ8TfObC5gfj4WAIRrRx68MXYadMFrna4EP4/bOJpTVng5KpRT9w2WMvQ9A aJ72J6pQIjZkfyU24srJC0MhvFk0SUv+cm02ezR/h5yw3zm4CbOLw6b6r+bLStgM86 bnLuLeyBgv0eBlvCCB0w1mbRqh6w2xNBKZFV+Ih4= Date: Fri, 2 Sep 2022 07:53:59 +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=1662098044; 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=9fonjwP5O3TqKHEUgulOIK6xea/cpfosEH2vg/a42mU=; b=EJOKH7GHB/cuhCVrYo1VKOpAt7g8Ne25xpo353rL+Hpky8rcPujQ8FkgEt71nG6c/AzW6X W90B0ogKucFOxpT+UDkDnmoxvbSSnRsYBMLl+mXY/nbxOdlZqCmqAMd5fdjuUyw18yIDpa ogq3qITSs2/xyYTo4hnscxjgx2LURu4= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=linuxfoundation.org header.s=korg header.b=GGEJaSZJ; spf=pass (imf13.hostedemail.com: domain of gregkh@linuxfoundation.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=gregkh@linuxfoundation.org; dmarc=pass (policy=none) header.from=linuxfoundation.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1662098044; a=rsa-sha256; cv=none; b=bM5sqxuFoMm7DS1XQutXJdkmUUyIJdRyF8ehzyghIGKdooQyFep1IMW2Bi9BOhi0dlccgI Rm5JOrncc1i9j46mt+02PzEvZRCLGo3yWOS0tT30MgezHvmXrRPDwfOqp44IDp/xSHe+JU t1x+FWvXkDXaNJF/+luZIgMCp/VOyq0= X-Stat-Signature: fuz576fr98rcz8t6wf31cpjm5yy79ufp X-Rspamd-Queue-Id: 4B9C320032 Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=linuxfoundation.org header.s=korg header.b=GGEJaSZJ; spf=pass (imf13.hostedemail.com: domain of gregkh@linuxfoundation.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=gregkh@linuxfoundation.org; dmarc=pass (policy=none) header.from=linuxfoundation.org X-Rspamd-Server: rspam12 X-Rspam-User: X-HE-Tag: 1662098044-970370 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 01:16:54PM -0600, Logan Gunthorpe wrote: > > > On 2022-09-01 12:36, Greg Kroah-Hartman wrote: > > On Thu, Sep 01, 2022 at 12:14:25PM -0600, Logan Gunthorpe wrote: > >> 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. > > This surprises me. Can you elaborate on this classic issue? There's long threads about it on the ksummit discuss mailing list and other places. > I've definitely seen uses of devm that expect the calls will be torn > down in reverse order they are added. Sorry, I didn't mean to imply the ordering of the devm code is incorrect, that's fine. It's when you have things in the devm "chain" that need to be freed in a different order that stuff gets messy. Like irqs and clocks and other types of resources that have "actions" associated with them. > The existing p2pdma code will > certainly fail quite significantly if a devm_kzalloc() releases its > memory before the devm_memmap_pages() cleans up. There's also already an > action that is used to cleanup before the last devm_kzalloc() call > happens. If ordering is not guaranteed, then devm seems fairly broken > and unusable and I'd have to drop all uses from this code and go back to > the error prone method. Also what's the point of > devm_add_action_or_reset() if it doesn't guarantee the ordering or the > release? I have never used devm_add_action_or_reset() so I can't say why it is there. I am just pointing out that manually messing with a sysfs group from a driver is a huge flag that something is wrong. A driver should almost never be touching a raw kobject or calling any sysfs_* call if all is normal, which is why I questioned this. > But if it's that important I can make the change to these patches for v10. Try it the way I suggest, with a remove() callback, and see if that looks simpler and easier to follow and maintain over time. thanks, greg k-h