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 33B11C2BB85 for ; Tue, 14 Apr 2020 18:09:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1523420656 for ; Tue, 14 Apr 2020 18:09:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b="HUV9qAl0" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2503393AbgDNSJS (ORCPT ); Tue, 14 Apr 2020 14:09:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44714 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1731265AbgDNSJO (ORCPT ); Tue, 14 Apr 2020 14:09:14 -0400 Received: from mail-qk1-x744.google.com (mail-qk1-x744.google.com [IPv6:2607:f8b0:4864:20::744]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 78322C061A0C for ; Tue, 14 Apr 2020 11:09:14 -0700 (PDT) Received: by mail-qk1-x744.google.com with SMTP id v7so14388347qkc.0 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=V2b+iEeQfV52QVRsOoTeNKTWNEPGssSGgypAU6U1lXq49aPmYghwLUThFKtqdmiUHF n3Y1BiOioqh69A1XTLOgmOCnxFJ93qMDbzKVGkkfrudoGsJfL0kfNI9w8MiQKj1eOWls D1TXddo7O51NH07A7SEg//DEuVEUBJ2q53clonTC/6bqnR0MD0KFeDkXvyREMYY7oTaZ Er8nk3m95B7Cm6Oy6DOB578UdG5Q0FHMuvd2QIUDNu+Y9eFvn+26Jas/LmFO9u5BQKjx T7EWiKaLoLX0Jb1Fv8hKwttrIuGfBzScDUhcmINnrpO4Tn8OxQpAM/yhrbV9VN1bVGzF Hh0w== X-Gm-Message-State: AGi0PuYJ7o+2HTFkC+U4nfg6TO6BlvDMoalCNt1hEYIeggY8/JYolcGC dyCU75tpoCgkDZ8lFxMX/c10iQ== 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) Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.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 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.1 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, 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 1F05BC2BA19 for ; Tue, 14 Apr 2020 18:09:19 +0000 (UTC) Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (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 DDF6E20767 for ; Tue, 14 Apr 2020 18:09:18 +0000 (UTC) Authentication-Results: mail.kernel.org; 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 DDF6E20767 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=iommu-bounces@lists.linux-foundation.org Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id B46A186EC9; Tue, 14 Apr 2020 18:09:18 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id SLFVgWrw5ELA; Tue, 14 Apr 2020 18:09:17 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by whitealder.osuosl.org (Postfix) with ESMTP id 707E686E6A; Tue, 14 Apr 2020 18:09:17 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 581B7C1D7F; Tue, 14 Apr 2020 18:09:17 +0000 (UTC) Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by lists.linuxfoundation.org (Postfix) with ESMTP id 732FEC1D7D for ; Tue, 14 Apr 2020 18:09:15 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 691EF21519 for ; Tue, 14 Apr 2020 18:09:15 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id vzMqfobhadC7 for ; Tue, 14 Apr 2020 18:09:14 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mail-qk1-f195.google.com (mail-qk1-f195.google.com [209.85.222.195]) by silver.osuosl.org (Postfix) with ESMTPS id A0C6521080 for ; Tue, 14 Apr 2020 18:09:14 +0000 (UTC) Received: by mail-qk1-f195.google.com with SMTP id l25so14347285qkk.3 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=fm1k17JIMAjNZ+MiYlrwRHd544ZJvZg9dKLiJV/x3aADc+lGQn5AOBXvuVgLARrEKc t+YhOdHu3dW4/klRmpb5Rg9JX0UC9LAOnJpu0CbiyBifg8c+/1/bp12svpLfydP+MB4F fdVFGOMJ9YpWd55gwe6mFehKmrIMx3Xxk3j1ixh+Lar9sfh6uPaXRidANevpCB+Cjyok C9jLcCaMuD2SVrBtoi6BDCB1GejC9YKjdpM0/oBBAAKx4iBSp/DOVP9luTeJQ1oxsjoy P1xTZsj4EkJ4YYtW2gdGnomFQqEQgNWVEhn6iZBgNJVElH9tgb3H4gx91UHZH4nWZSBp Qblw== X-Gm-Message-State: AGi0PuaHnudZz7TKct2OP3zcRdqMTCUslJ8atPlGSFmdx7wXfyY1ZEMD 48VQzkunoMb2Eo/ipYAy0KRZlA== 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) Cc: devicetree@vger.kernel.org, kevin.tian@intel.com, Andrew Morton , Arnd Bergmann , Greg Kroah-Hartman , linux-pci@vger.kernel.org, robin.murphy@arm.com, linux-mm@kvack.org, iommu@lists.linux-foundation.org, Dimitri Sivanich , catalin.marinas@arm.com, zhangfei.gao@linaro.org, will@kernel.org, christian.koenig@amd.com, linux-arm-kernel@lists.infradead.org X-BeenThere: iommu@lists.linux-foundation.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Development issues for Linux IOMMU support List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: iommu-bounces@lists.linux-foundation.org Sender: "iommu" 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 _______________________________________________ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu 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