From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.4 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B54FDC3F2D3 for ; Fri, 28 Feb 2020 15:13:43 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6F97424699 for ; Fri, 28 Feb 2020 15:13:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b="Ljgpp5xG" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6F97424699 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 002396B0005; Fri, 28 Feb 2020 10:13:43 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id EF3CF6B0006; Fri, 28 Feb 2020 10:13:42 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DE3A66B0007; Fri, 28 Feb 2020 10:13:42 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0218.hostedemail.com [216.40.44.218]) by kanga.kvack.org (Postfix) with ESMTP id C551A6B0005 for ; Fri, 28 Feb 2020 10:13:42 -0500 (EST) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 53236181BC800 for ; Fri, 28 Feb 2020 15:13:42 +0000 (UTC) X-FDA: 76539880284.30.teeth52_779369bd91705 X-HE-Tag: teeth52_779369bd91705 X-Filterd-Recvd-Size: 5685 Received: from mail-qv1-f65.google.com (mail-qv1-f65.google.com [209.85.219.65]) by imf39.hostedemail.com (Postfix) with ESMTP for ; Fri, 28 Feb 2020 15:13:41 +0000 (UTC) Received: by mail-qv1-f65.google.com with SMTP id p2so1466025qvo.10 for ; Fri, 28 Feb 2020 07:13:41 -0800 (PST) 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:user-agent; bh=Wq8nlNbsnwZz9fji3Cl/zgmv4zDoBKk4NoZF3W2wkDQ=; b=Ljgpp5xGPFtER1NGPwiitpNKYovODnCioFFOFLTyn2Ck/JR8HVTOx6j2p+g2nfn+c7 ZZ4POl/CTaYoux0tyCmDMX6rtKyDdXnlMSGlJzLw9GbBTTzDfneWvjGmL5R0O0CGmHup 2kp9E5S8Nxk8bHWYOZucZY6zoQaHVHi1zuuqGFV82FSHWkJZ4RoRvoylWAS0Wx4bc8K9 VTIK4BTuE9ZYLVtjSIRYLN6ZaAkL0DcdWHFg4QbbWrjltc2/+KxfoeQyempXAsF7sI0A w3wliYOLVxCpNm799lBmqygk+nsWvEVxFVFJ7Lj2RQ/PkFIeGuOpHh4CgFZttaO2QJlZ F0/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=Wq8nlNbsnwZz9fji3Cl/zgmv4zDoBKk4NoZF3W2wkDQ=; b=dE/ZgBmYp3+a6ndMaJH4SAV4QtDOLoerKXj83UaSKftFb0emS1WDtrsFIgwU5q18G8 O2sjzDirYSJ+KcyGQbJOe33ifRCto2YAiLp0HoBMwmQvUqhPfjiE1pMilURzgpLAFTVl AWZBEZ7BmV89Fk8zElN5mQY04+hrt/EdOC0kxHqewFzNWs+stgWaV1pnkZFUjKEjRhGY gbZG9xHRFbqohOQ4gSlIjDEbamZCc9lDgSu6NaXX5jKwY0DLi6nG6jm/3M6HQ7iUFMGg WLPaBmolwMuHAcgV8NYz6oIrI3RHvswopfODYSCvpW23H9ezZtPKXAojwtuOVkDU7N+/ +g8A== X-Gm-Message-State: APjAAAUShv7RYMJ6a1jb8b10fS2gU2nTmlCeCS9RLhNfRbgsKmEEyLip pzz10LDlvZw3S2UBO6+ynWer5A== X-Google-Smtp-Source: APXvYqzNk6wZcWW+lmBBUW/lZq2ZIkoXwN/aWaAwf7XC2b5DqYukekLVZ6CR2bhdZGkTfI1iTFM0Cw== X-Received: by 2002:a05:6214:a62:: with SMTP id ef2mr3484481qvb.109.1582902820845; Fri, 28 Feb 2020 07:13:40 -0800 (PST) Received: from ziepe.ca (hlfxns017vw-142-68-57-212.dhcp-dynamic.fibreop.ns.bellaliant.net. [142.68.57.212]) by smtp.gmail.com with ESMTPSA id a128sm5296832qkc.44.2020.02.28.07.13.40 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 28 Feb 2020 07:13:40 -0800 (PST) Received: from jgg by mlx.ziepe.ca with local (Exim 4.90_1) (envelope-from ) id 1j7hKe-0005qo-0Q; Fri, 28 Feb 2020 11:13:40 -0400 Date: Fri, 28 Feb 2020 11:13:40 -0400 From: Jason Gunthorpe To: Jean-Philippe Brucker Cc: mark.rutland@arm.com, linux-pci@vger.kernel.org, linux-mm@kvack.org, will@kernel.org, Dimitri Sivanich , catalin.marinas@arm.com, zhangfei.gao@linaro.org, devicetree@vger.kernel.org, kevin.tian@intel.com, Arnd Bergmann , robh+dt@kernel.org, linux-arm-kernel@lists.infradead.org, Greg Kroah-Hartman , iommu@lists.linux-foundation.org, Andrew Morton , robin.murphy@arm.com, christian.koenig@amd.com Subject: Re: [PATCH v4 01/26] mm/mmu_notifiers: pass private data down to alloc_notifier() Message-ID: <20200228151339.GS31668@ziepe.ca> References: <20200224182401.353359-1-jean-philippe@linaro.org> <20200224182401.353359-2-jean-philippe@linaro.org> <20200224190056.GT31668@ziepe.ca> <20200225092439.GB375953@myrica> <20200225140814.GW31668@ziepe.ca> <20200228143935.GA2156@myrica> <20200228144844.GQ31668@ziepe.ca> <20200228150427.GF2156@myrica> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200228150427.GF2156@myrica> User-Agent: Mutt/1.9.4 (2018-02-28) 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 Fri, Feb 28, 2020 at 04:04:27PM +0100, Jean-Philippe Brucker wrote: > On Fri, Feb 28, 2020 at 10:48:44AM -0400, Jason Gunthorpe wrote: > > On Fri, Feb 28, 2020 at 03:39:35PM +0100, Jean-Philippe Brucker wrote: > > > > > + list_for_each_entry_rcu(bond, &io_mm->devices, mm_head) { > > > > > + /* > > > > > + * To ensure that we observe the initialization of io_mm fields > > > > > + * by io_mm_finalize() before the registration of this bond to > > > > > + * the list by io_mm_attach(), introduce an address dependency > > > > > + * between bond and io_mm. It pairs with the smp_store_release() > > > > > + * from list_add_rcu(). > > > > > + */ > > > > > + io_mm = rcu_dereference(bond->io_mm); > > > > > > > > A rcu_dereference isn't need here, just a normal derference is fine. > > > > > > bond->io_mm is annotated with __rcu (for iommu_sva_get_pasid_generic(), > > > which does bond->io_mm under rcu_read_lock()) > > > > I'm surprised the bond->io_mm can change over the lifetime of the > > bond memory.. > > The normal lifetime of the bond is between device driver calls to bind() > and unbind(). If the mm exits early, though, we clear bond->io_mm. The > bond is then stale but can only be freed when the device driver releases > it with unbind(). I usually advocate for simple use of these APIs. The mm_notifier_get() should happen in bind() and the matching put should happen in the call_rcu callbcak that does the kfree. Then you can never get a stale pointer. Don't worry about exit_mmap(). release() is an unusual callback and I see alot of places using it wrong. The purpose of release is to invalidate_all, that is it. Also, confusingly release may be called multiple times in some situations, so it shouldn't disturb anything that might impact a 2nd call. Jason