Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp1586193rwe; Thu, 1 Sep 2022 23:34:07 -0700 (PDT) X-Google-Smtp-Source: AA6agR4lmrWFdsi4DsXR+oYgIDuMv6r2NqXwogEem9I2ZJ6G4wQemUkMYkyN8StqDQuxH5oJYfAP X-Received: by 2002:a17:906:cc5d:b0:73d:c534:1aaa with SMTP id mm29-20020a170906cc5d00b0073dc5341aaamr25962482ejb.626.1662100447655; Thu, 01 Sep 2022 23:34:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662100447; cv=none; d=google.com; s=arc-20160816; b=mIAhYF9ahWq5EISM9cAbWphcIbR0fxO1pBotFvl2K6o1ALb7EmtG6wkaGNpc0784ji mVlw7tXG5+K9ZLc2+aDj7xq/SfaFDGD8rodMsfmMkD9DVXNL2uqP0CSvnzFFahzf7fNY Fy27oWmic3JeAAYqhTYHeRJlCOTalmu6Jvq4h/oDZ/t+pHClMVPxgBUk4p0WFbZGUiCw ZDokkeuLFL9hoP/hhUYpDP1izd3SLFFlmsgl2+4uIGLKlD5WEIr7Ju4nOdi5CYqgT3Z6 J4XtbFh7XOjn32zszUhORMJprolOLd2GaI+88D4f2Nmhr3K0ZLO1r4wrkPTs4+HJA/zN F37w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=9fonjwP5O3TqKHEUgulOIK6xea/cpfosEH2vg/a42mU=; b=Wm4/Jz736w+PiwlbpEzZXoAk5d5/ivykR8uThOHzEX2theGqbv0QfdPr4fBVbjrm9q k7NCRq9FkdPHQcyICOnWOnxjqgtIuP7QqJVGYNQxKAPyureLafvGllC2E5ncNSxIKQ47 wCfyDggJlYi1RJUkaMuimFvu1QVvuQPF2bVRNilFtNx5iZRDkF1sD1M2MQyE+RxZroCT xf1VSM4RZ6xkS1G4b4gucyY78GCvUQ4bFPiXfnyFkcqTYps2D1YiYvIbEJyAloObhiEJ mRiKnfMSowC/XihPLxYFALCL5NAYfnlbMefgIy9UC5tCcIXJnXESsIcfawsPrUnP+lon 5usQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=GGEJaSZJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l6-20020a056402254600b0044796abf102si1294787edb.436.2022.09.01.23.33.40; Thu, 01 Sep 2022 23:34:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=GGEJaSZJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235259AbiIBFyI (ORCPT + 99 others); Fri, 2 Sep 2022 01:54:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47496 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232927AbiIBFyG (ORCPT ); Fri, 2 Sep 2022 01:54:06 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A1B8B2DA6; Thu, 1 Sep 2022 22:54:05 -0700 (PDT) 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 ams.source.kernel.org (Postfix) with ESMTPS id 17AECB829E2; Fri, 2 Sep 2022 05:54:04 +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: X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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