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 1DC00C2BB85 for ; Tue, 14 Apr 2020 18:09:16 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D1B5D20767 for ; Tue, 14 Apr 2020 18:09:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b="HUV9qAl0" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D1B5D20767 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 5EF588E0008; Tue, 14 Apr 2020 14:09:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5A0318E0001; Tue, 14 Apr 2020 14:09:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 48DEC8E0008; Tue, 14 Apr 2020 14:09:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0020.hostedemail.com [216.40.44.20]) by kanga.kvack.org (Postfix) with ESMTP id 2ECE98E0001 for ; Tue, 14 Apr 2020 14:09:15 -0400 (EDT) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id E66C7180AD807 for ; Tue, 14 Apr 2020 18:09:14 +0000 (UTC) X-FDA: 76707247428.28.move99_6dc84c2065647 X-HE-Tag: move99_6dc84c2065647 X-Filterd-Recvd-Size: 5332 Received: from mail-qk1-f194.google.com (mail-qk1-f194.google.com [209.85.222.194]) by imf26.hostedemail.com (Postfix) with ESMTP for ; Tue, 14 Apr 2020 18:09:14 +0000 (UTC) Received: by mail-qk1-f194.google.com with SMTP id c63so14357046qke.2 for ; Tue, 14 Apr 2020 11:09:14 -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:user-agent; bh=bv0sJf01GOa0wIzpOx9SRUfmEHLHh5Wp99C/Vrgdaec=; b=HUV9qAl0/LTHa4gW9R5GB8bZskgMoquMycxLWoNqVXVK2lCPXRRchgd9fNWmRJ3r3E MwOpBF6IYEAIRmh+0P+Mk/Xdy5ihB9c56BGZ9huMOY7437gGh4cXj2ES77WCdjN3h14P vz4I9nCHk4olhkup2TXyZYzBKURBuBpg2EVTYcri8bZwVCHw5clEERw7k1EtxwCQTnnM VJSbHXiqAULOv3ywp1xrIzqfxDneUHsXKLo7wHnHwkX7qU6WFdjY2E7rloSUWnmAC5gN 4MMiLhwcwPZJrM0qv+cchcfFMGuVM8+32TSi5HJ9+6a8/GOL1PH/AfPEODAh7ce0zWHj Orfw== 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=bv0sJf01GOa0wIzpOx9SRUfmEHLHh5Wp99C/Vrgdaec=; b=r7bNnhdwU07UCWsu5TuvyOtcywlDMZDj9cJoHGPsDjvh55VWIzP/vEtKdhnooA+vcF VaFkGN67zXFufN+xRST8DF0TB1iK6vvGOdh0zDxhbvdEWxmnWS3UTufUGKWjfekSHydF b1IPOOhcGNLXdnfs+LfBG0fOq71LzezGZg4bUAAKN/WVdcE18/I5/+Kf/zJMX2cn5qCI NcQGOS2ToydnC1z30oqtv67OgC0J7FpjYOoRk4u5RajbclAgzdcmaM3P4tUA3eiB5bPZ TuEOq/4NWbjN2kpMpRL2tUPM0r754vFBCPBkWvnEm5cBIbkVZjEcf/WEum3clDdFuqLh 3Oeg== X-Gm-Message-State: AGi0PuaeDKXWEvcsKBkfwML7G+L5xRg8jnA+QEUHIMpXwFoqDCSIEBWJ w/uLKDOC7AKyyry66gCBkDhXCQ== X-Google-Smtp-Source: APiQypLF3T0ctlDMYDCZmNS5QXnrk26ya+xUobfqsrIExRvDdUeoVWUu8wspkPshY2Cg+OHu4MKS2Q== X-Received: by 2002:a37:8645:: with SMTP id i66mr23325550qkd.229.1586887753646; Tue, 14 Apr 2020 11:09:13 -0700 (PDT) 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 f13sm11354811qti.47.2020.04.14.11.09.12 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 14 Apr 2020 11:09:13 -0700 (PDT) Received: from jgg by mlx.ziepe.ca with local (Exim 4.90_1) (envelope-from ) id 1jOPzk-0007ib-Gs; Tue, 14 Apr 2020 15:09:12 -0300 Date: Tue, 14 Apr 2020 15:09:12 -0300 From: Jason Gunthorpe To: Jean-Philippe Brucker Cc: iommu@lists.linux-foundation.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-pci@vger.kernel.org, linux-mm@kvack.org, joro@8bytes.org, catalin.marinas@arm.com, will@kernel.org, robin.murphy@arm.com, kevin.tian@intel.com, baolu.lu@linux.intel.com, Jonathan.Cameron@huawei.com, jacob.jun.pan@linux.intel.com, christian.koenig@amd.com, zhangfei.gao@linaro.org, xuzaibo@huawei.com, Andrew Morton , Arnd Bergmann , Christoph Hellwig , Dimitri Sivanich , Greg Kroah-Hartman Subject: Re: [PATCH v5 01/25] mm/mmu_notifiers: pass private data down to alloc_notifier() Message-ID: <20200414180912.GH5100@ziepe.ca> References: <20200414170252.714402-1-jean-philippe@linaro.org> <20200414170252.714402-2-jean-philippe@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200414170252.714402-2-jean-philippe@linaro.org> 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 Tue, Apr 14, 2020 at 07:02:29PM +0200, Jean-Philippe Brucker wrote: > The new allocation scheme introduced by commit 2c7933f53f6b > ("mm/mmu_notifiers: add a get/put scheme for the registration") provides > a convenient way for users to attach notifier data to an mm. However, it > would be even better to create this notifier data atomically. > > Since the alloc_notifier() callback only takes an mm argument at the > moment, some users have to perform the allocation in two times. > alloc_notifier() initially creates an incomplete structure, which is > then finalized using more context once mmu_notifier_get() returns. This > second step requires extra care to order memory accesses against live > invalidation. > > The IOMMU SVA module, which attaches an mm to multiple devices, > exemplifies this situation. In essence it does: > > mmu_notifier_get() > alloc_notifier() > A = kzalloc() > /* MMU notifier is published */ > A->ctx = ctx; // (1) > device->A = A; > list_add_rcu(device, A->devices); // (2) > > The invalidate notifier, which may start running before A is fully > initialized, does the following: > > io_mm_invalidate(A) > list_for_each_entry_rcu(device, A->devices) > device->invalidate(A->ctx) This could probably also have been reliably fixed by not having A->ctx be allocated memory, but inlined into the notifier struct But I can't think of a down side to not add a params either. Reviewed-by: Jason Gunthorpe Regards, Jason