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.3 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,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 68308C2BB85 for ; Tue, 14 Apr 2020 18:09:25 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4120420767 for ; Tue, 14 Apr 2020 18:09:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="M1eZZ84J"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b="HUV9qAl0" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4120420767 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Qxv6VKA9cQNH0HV2UmoiPQ1cnDTV9PW6vigQN7SWN3c=; b=M1eZZ84Ju9JkWz B1Cn3DYXijno/88OY5wXDydS+5qLL6opNumyuuPduORlBl4GekoP2zrhe2D/Ou9qKaa2dxVuq9PLh 2D3WJxAtpLefQ0WcXeLwMalmxcHLmcF8Qr5/NTGkICyJxz02iffj/VWVV80RPWsHDUtQ6oL3DEEgW G1KE1pTWQ9w3f+E+ht1emtDKCdJQwgtopoMthvdeZSbFM1V4Pf0DhYeQewYSngrVnRw9VMbV/NfOD Dd3Zh1AFdSaWQAV99sFPD8Uc31/hzlxqr+PcSKMV1P+ks6t8CvC24CXzyMywimSLf6rgausd6Vjcl BtqYaWblZyRBVg9Nnxaw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jOPzv-00017G-VN; Tue, 14 Apr 2020 18:09:23 +0000 Received: from mail-qk1-x741.google.com ([2607:f8b0:4864:20::741]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jOPzn-00014g-OD for linux-arm-kernel@lists.infradead.org; Tue, 14 Apr 2020 18:09:22 +0000 Received: by mail-qk1-x741.google.com with SMTP id o19so7023229qkk.5 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=MVSmne47Y4U9eIDKPqMOWZw1eGgm+XZRFu55Of55V1tscGx/O7x3rskg4fhX3XhrFl JtcHOWNceeHNEKvQLmr9+1OYA7fruphVt1nWKQlfBEAztJN7T5WwlByQw5gZYy7jKQFq X4FcuR29cJLuw7pKnd0w45tHRPaEG7LH0enFnRCJKl9xEGIEcZcAomo4MjkoKEqqFlpM fktXd/EaBvoC4qqTCBxczrWANR18fU3ieA3IhLtjY6g4v96GlFXCXViQ9jTPzEGRL8zA xvtwqDHmzJOjNc4qMjOAceqdEBJS1B/0+R/492Duu4Rj3pNNcn4cfDug46UfK6FjU36H Yf7g== X-Gm-Message-State: AGi0PuZ/feIl9zK+/VV9HamHlb6g4GkJ45sCoVfa8UipSXm7ZSEk+U5k hiWNCcSg7YNZ2I2b/vUyZH9AVGiHjE58TA== 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 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-Disposition: inline In-Reply-To: <20200414170252.714402-2-jean-philippe@linaro.org> User-Agent: Mutt/1.9.4 (2018-02-28) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200414_110916_005979_69EDE271 X-CRM114-Status: GOOD ( 14.87 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, kevin.tian@intel.com, jacob.jun.pan@linux.intel.com, Andrew Morton , Arnd Bergmann , Greg Kroah-Hartman , linux-pci@vger.kernel.org, joro@8bytes.org, Jonathan.Cameron@huawei.com, robin.murphy@arm.com, Christoph Hellwig , linux-mm@kvack.org, iommu@lists.linux-foundation.org, Dimitri Sivanich , catalin.marinas@arm.com, zhangfei.gao@linaro.org, xuzaibo@huawei.com, will@kernel.org, christian.koenig@amd.com, linux-arm-kernel@lists.infradead.org, baolu.lu@linux.intel.com Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel