Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp6850563ioo; Thu, 2 Jun 2022 15:19:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzcOC1ttDwDzprlzWlXctelG5yB9U3QNF1GrRGeK115PtawbiDO37gRvEOghzhQyVU9BYNW X-Received: by 2002:a17:902:ccc9:b0:15b:c265:b7a0 with SMTP id z9-20020a170902ccc900b0015bc265b7a0mr6981681ple.107.1654208378005; Thu, 02 Jun 2022 15:19:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654208377; cv=none; d=google.com; s=arc-20160816; b=TF19g/VYStr6FJ4Wskz6gO3zM/EXo1LoZ6/f1Ab5S/hgIgV4SyoTPHNjjsJh6vOrbQ EXdXuwMhKG5zThFCJVJg/VvsNO8NC3jxtnUorFrf0mDjq9zE5Shj9nIV84xXJnNCqvUZ bu5lW6Pv4eFXH4VQpyFDQQrE34PfA32QQkxIqH3Wbn6ZVNWsNEE5b2hkNxL6jo11BVgA 9I09PTZW7uXdE77vGHRsAlKpGVUGsO/sJo1YWGrQc8P3DodXjPDl4cVaNI4AKJQW9lq7 6XMsyosR7kkkrnnaN0841OcmPfTcJH55M6Lp0nCKOTJIV/ha2RtPrHCrFc4OFvEOKDsF WIFQ== 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=s4YbZJYHvK3nVAxdvdm+/MuYfvjkcChJJ4+lAokhsws=; b=Gt2W2G1pmClHxX+x5p1hLg7fllDuiZEM6/maRrqzvEzpAlrvzENJVvjJ2KEuQNOLQy rKhDgzUvUOr7lU/b/FDMy5JT5ki2MTucCx8Nbu9mQu16NKwANV8o0nABtHxnpvks+rY0 2elB9gzA9svWJwgmdxFiIIrIBrTzjkyIZNsrs4/aizIOXbqRV/iaMpFyGg+WfgxF/rm5 LRF4FQIw605fPEDyNySX2NTpsQAMz8teFl1/G1SBtBDP9udIQc3Jh5A5gEyaGbfL9sLa KsUPHR6oWLfQAaGoAIRPh6AqDuS58K4+1vQFZUNlgBgzA5c8SasKKhzGuV/BHpCrh8Gn YdgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ziepe.ca header.s=google header.b=oY3UkNUX; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b8-20020a170902d50800b0016641a8abcfsi3785100plg.549.2022.06.02.15.19.24; Thu, 02 Jun 2022 15:19:37 -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=@ziepe.ca header.s=google header.b=oY3UkNUX; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237426AbiFBRTU (ORCPT + 99 others); Thu, 2 Jun 2022 13:19:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54496 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231524AbiFBRTS (ORCPT ); Thu, 2 Jun 2022 13:19:18 -0400 Received: from mail-qv1-xf2c.google.com (mail-qv1-xf2c.google.com [IPv6:2607:f8b0:4864:20::f2c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C18EE208B05 for ; Thu, 2 Jun 2022 10:19:17 -0700 (PDT) Received: by mail-qv1-xf2c.google.com with SMTP id cv1so3966150qvb.5 for ; Thu, 02 Jun 2022 10:19:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=s4YbZJYHvK3nVAxdvdm+/MuYfvjkcChJJ4+lAokhsws=; b=oY3UkNUXzvT4gdwz2capbciaRVMUwQe4uTXMNLZq5rB+SzgWV5Y9KoY1sDKwk8gWEZ 3+Q6uw1zQKFy/Unx4HtSstHVhLVkyZWxIMc80Ov1HAVUKCwD358EREeYDHhZDZ8k2MZs bhOn53kb4QxCMIITNdm+0c1NDnpndPfQjTJuD8TnE5Uv3cFfjqWJqQft0Z4nj9YH3uBX nPBbjR1L9pvnoVrAHHIKs0Q9BrMid/o8PxXfUbP6XGG/0m5N+an4nPqyjM2uURiJ8hW5 nebfcv+yWDiGXnYLe+dR4uJdRKeLgQOn7tZfDT3mAn3r317E5qS4d++iGATXbWfBN5kK ZpSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=s4YbZJYHvK3nVAxdvdm+/MuYfvjkcChJJ4+lAokhsws=; b=FALCDH7sHRgisOpXrsEn3w5p9vZAj/1Fnz/QY9RCdak84/rlNxam36ebZdeB23r+Jk sdtlHUpK8LvQPTu5SSWxUc9zgYsKbeDZ+iwDexPvmHa8veEDBftrAK1ykQK/0M2RZX3L 4xH+5FP4G1pZicXEKP0FB3vhD4lm5A/91sqfk0HaGDxC0bQo+1PnWVmNtjiNVAVxBLBH 7QRm+EXLqhNVCYrwcLsb4Pz7OeNwrXYTvyoUwiJu3wqfKoJEnpU3Ugjv1NTDO9yY4/vT JKrxEx0Cg3mCDUVsK50g9tTJJVTG5YF1GUCFsj40DCR+yd5+uOJDmc3HMzlqVJkv4VAI 3HiA== X-Gm-Message-State: AOAM531oDAvkVLXV7jkOJPB8/t0cNd0iZ4C+dQFEsHrpiPzLo4iOtHp9 Ib/MbRrDPg470hpPXtkxTgtfGA== X-Received: by 2002:ad4:5b81:0:b0:465:ded8:780 with SMTP id 1-20020ad45b81000000b00465ded80780mr6281647qvp.119.1654190356566; Thu, 02 Jun 2022 10:19:16 -0700 (PDT) Received: from ziepe.ca (hlfxns017vw-142-162-113-129.dhcp-dynamic.fibreop.ns.bellaliant.net. [142.162.113.129]) by smtp.gmail.com with ESMTPSA id p200-20020a3742d1000000b0069fc13ce1e7sm3510487qka.24.2022.06.02.10.18.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Jun 2022 10:18:55 -0700 (PDT) Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1nwoSV-00GUM1-QB; Thu, 02 Jun 2022 14:18:07 -0300 Date: Thu, 2 Jun 2022 14:18:07 -0300 From: Jason Gunthorpe 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, iommu@lists.linux-foundation.org, Stephen Bates , Christoph Hellwig , Dan Williams , Christian =?utf-8?B?S8O2bmln?= , John Hubbard , Don Dutile , Matthew Wilcox , Daniel Vetter , Jakowski Andrzej , Minturn Dave B , Jason Ekstrand , Dave Hansen , Xiong Jianxin , Bjorn Helgaas , Ira Weiny , Robin Murphy , Martin Oliveira , Chaitanya Kulkarni , Ralph Campbell , Bjorn Helgaas Subject: Re: [PATCH v6 20/21] PCI/P2PDMA: Introduce pci_mmap_p2pmem() Message-ID: <20220602171807.GM2960187@ziepe.ca> References: <20220407154717.7695-1-logang@deltatee.com> <20220407154717.7695-21-logang@deltatee.com> <20220527125501.GD2960187@ziepe.ca> <20220527190307.GG2960187@ziepe.ca> <20220602000038.GK2960187@ziepe.ca> <400baba7-1cd6-09d4-4de9-2a73f08afc79@deltatee.com> <20220602163059.GL2960187@ziepe.ca> <28824558-4fd5-e054-6c8d-5e045d52f795@deltatee.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <28824558-4fd5-e054-6c8d-5e045d52f795@deltatee.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, 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, Jun 02, 2022 at 10:45:55AM -0600, Logan Gunthorpe wrote: > > > > On 2022-06-02 10:30, Jason Gunthorpe wrote: > > On Thu, Jun 02, 2022 at 10:16:10AM -0600, Logan Gunthorpe wrote: > > > >>> Just stuff the pages into the mmap, and your driver unprobe will > >>> automatically block until all the mmaps are closed - no different than > >>> having an open file descriptor or something. > >> > >> Oh is that what we want? > > > > Yes, it is the typical case - eg if you have a sysfs file open unbind > > hangs indefinitely. Many drivers can't unbind while they have open file > > descriptors/etc. > > > > A couple drivers go out of their way to allow unbinding while a live > > userspace exists but this can get complicated. Usually there should be > > a good reason. > > This is not my experience. All the drivers I've worked with do not block > unbind with open file descriptors (at least for char devices). I know, > for example, that having a file descriptor open of /dev/nvmeX does not > cause unbinding to block. So there are lots of bugs in the kernel, and I've seen many drivers that think calling cdev_device_del() is all they need to do - and then happily allow cdev ioctl's/etc on a de-initialized driver struct. Drivers that do take care of this usually have to put a lock around all their fops to serialize against unbind. RDMA uses SRCU, iirc TPM used a rwlock. But this is tricky and hurts fops performance. I don't know what nvme did to protect against this, I didn't notice an obvious lock. > I figured this was the expectation as the userspace process doing > the unbind won't be able to be interrupted seeing there's no way to > fail on that path. Though, it certainly would make things a lot > easier if the unbind can block indefinitely as it usually requires > some complicated locking. As I said, this is what sysfs does today and I don't see that ever changing. If you userspace has a sysfs file open then the driver unbind hangs until the file is closed. So, doing as bad as sysfs seems like a reasonable baseline to me. > Do you have an example of this? What mechanisms are developers using to > block unbind with open file descriptors? Sysfs maintains a refcount with a bias that is basically a fancied rwlock. Most places use some kind of refcount triggering a completion. Sleep on the completion until refcount is 0 on unbind kind of thing. Jason