Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp212383pxu; Thu, 15 Oct 2020 01:51:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxgmhdBGe6nNqREoisi4/DK9zUp0yxktBCkNWY3QSdmAbLiYDfcvrhIYXDfnhbsFUKkFF25 X-Received: by 2002:a17:906:a454:: with SMTP id cb20mr3395691ejb.137.1602751873086; Thu, 15 Oct 2020 01:51:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602751873; cv=none; d=google.com; s=arc-20160816; b=F7FfWev56V6mm0C/rpgBTuIF+G8yUeJvvo9qxiZvynnTsWX3XeP1Thl2IZNvVJ5hYk rbxx2qFvn0ThdrKDPplEoc94MwAe20N+8+mLnZqZ27S28RHSh/1dKHXLMOviF/lLGL7x DO2kFgs4FGOj4ElqumsZB1dc7x3UXyx56KEBXs9niYDfRtlcIhhodKI5BBXUshmzrihe N/jx1hBz+t/gcvZEMMtlGWlPNqJVE6Vf5Cd0xpvruPMIpUbPpYyWlorM8+Cm5l7jRGf8 ymRP+d8nRMBtNj5k/4Fs/yVWrTuxIseXby7DkIrAW52GxrsOTsYbtm7/nbDBWeX+NXRY ZZWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=D7q4upZx4LUmHy2sbcBxGXxr7CK8polpuI+TBJh2iFg=; b=bkJjBpP90GR/lF5sQi7WcgHiaXSaS8gMDvhh1FmOnP96yUC+ge18iDsR2VFOmWpgmD vXPG7UHdR5P4CpGWahgzleKdtWE2k1WJ9d8yUYoBO9At/gLqIngAcC6QoGs8QWV0yGch 5YFBDyVN+VH4ywrUHvcPP+7O2c9RJjOvxsRRinVo0YbdvDaxHUofVtd5ep6eYnBWEl/A N0o/gLRbd4IAYQ4P1Qs59WcnJqIDjeyGKaKl4ZF7z3R2KZBrQV7VRYbduhUoaS66oMsb OmkjrzZYG/I9yBpz86Ac75jJZ3+fpZLCBKod7xNCl6/baY1ZwvrsPxWWxcdwEH1zRD1A S3LQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ziepe.ca header.s=google header.b=VY1qyIeC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id lv16si1693245ejb.305.2020.10.15.01.50.50; Thu, 15 Oct 2020 01:51:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@ziepe.ca header.s=google header.b=VY1qyIeC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388693AbgJOB3s (ORCPT + 99 others); Wed, 14 Oct 2020 21:29:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49022 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732280AbgJOB3j (ORCPT ); Wed, 14 Oct 2020 21:29:39 -0400 Received: from mail-qk1-x741.google.com (mail-qk1-x741.google.com [IPv6:2607:f8b0:4864:20::741]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A780C00215B for ; Wed, 14 Oct 2020 17:09:42 -0700 (PDT) Received: by mail-qk1-x741.google.com with SMTP id b69so1009115qkg.8 for ; Wed, 14 Oct 2020 17:09:42 -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=D7q4upZx4LUmHy2sbcBxGXxr7CK8polpuI+TBJh2iFg=; b=VY1qyIeCcrX28JfPsmo/gMmvUMC4KhNWUx2AWTC7SFuNhKKNC7E5pi4i351EUrbB2J iQEeEBv2iqbPt4yG9cu9z6JKaTTcI0uH0ifbEwEuYd7uQ+JCfqlrCKPwMTRONzTIq1+2 r10P6EtGAwdMqLqGZOKON3zvZUuPyniSm0E4b9X4QVYcKPq5x9sxgp/64dd/q9ifg4bh 6h21xPcqmh90YO0WNB5wNN8lxy2kzpTs2joeQm0QgPxqx6k5VPT8scnHtsXoGOHGppiW EBkQ8XI+pghayLloQzkOY+ZWhXI0lRPbg5OXZafpWC/LHi0yuGDtirCrwS4LepbltR1w 8p9g== 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=D7q4upZx4LUmHy2sbcBxGXxr7CK8polpuI+TBJh2iFg=; b=Wp4r1JomYZ7wx9LuoU0aVVLOWf88mYRejtN/27jwCXuJ3UC68FtKhrFfr0BZjdiNrn ISsNezT2kFjXCSgIf6v1BiBNT1LfsJ71x11UTRIOTVXT1DcbxafO/WrLxtZnG5GQr5HY LB1mwvlLh3yVmUCPYDEUly2s7v9YNwgRRgfSKZBH4RGahDnF49E5j0WRDZBFYcWINCQ8 mkI84QfA3cPnz/z1Rmmb7enTHBu4WJ/WvCauuEPspnttkGLNB7OYbwRxnzjgVZLuvppV MRh11ZjRlHuELD5fPNM8b/+kISvkiD/WzeaRE1NDRCgQGsfi3/tOuF3nX3J/TE1Knf7T 0V3A== X-Gm-Message-State: AOAM530KD8tX6K00Na0qvv8rlkzhS0Jg2/UlbgUzABXAKocLlTjBbZMy rOfQxEKcU6A8RdUWlZ6mvb/f+w== X-Received: by 2002:a05:620a:2e3:: with SMTP id a3mr1513988qko.117.1602720581354; Wed, 14 Oct 2020 17:09:41 -0700 (PDT) Received: from ziepe.ca ([142.177.128.188]) by smtp.gmail.com with ESMTPSA id y44sm525252qtb.50.2020.10.14.17.09.40 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 14 Oct 2020 17:09:40 -0700 (PDT) Received: from jgg by jggl.ziepe.ca with local (Exim 4.90_1) (envelope-from ) id 1kSqpv-0002GP-8c; Wed, 14 Oct 2020 21:09:39 -0300 Date: Wed, 14 Oct 2020 21:09:39 -0300 From: Jason Gunthorpe To: Dan Williams Cc: Daniel Vetter , DRI Development , LKML , KVM list , Linux MM , Linux ARM , linux-samsung-soc , "open list:DMA BUFFER SHARING FRAMEWORK" , linux-s390 , Daniel Vetter , Kees Cook , Andrew Morton , John Hubbard , =?utf-8?B?SsOpcsO0bWU=?= Glisse , Jan Kara , Arnd Bergmann , Greg Kroah-Hartman , David Hildenbrand , "Rafael J. Wysocki" Subject: Re: [PATCH v2 14/17] resource: Move devmem revoke code to resource framework Message-ID: <20201015000939.GD6763@ziepe.ca> References: <20201009075934.3509076-1-daniel.vetter@ffwll.ch> <20201009075934.3509076-15-daniel.vetter@ffwll.ch> <20201009123109.GO5177@ziepe.ca> <20201009143209.GS5177@ziepe.ca> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Oct 09, 2020 at 11:28:54AM -0700, Dan Williams wrote: > On Fri, Oct 9, 2020 at 7:32 AM Jason Gunthorpe wrote: > > > > On Fri, Oct 09, 2020 at 04:24:45PM +0200, Daniel Vetter wrote: > > > On Fri, Oct 9, 2020 at 2:31 PM Jason Gunthorpe wrote: > > > > > > > > On Fri, Oct 09, 2020 at 09:59:31AM +0200, Daniel Vetter wrote: > > > > > > > > > +struct address_space *iomem_get_mapping(void) > > > > > +{ > > > > > + return iomem_inode->i_mapping; > > > > > > > > This should pair an acquire with the release below > > > > > > > > > + /* > > > > > + * Publish /dev/mem initialized. > > > > > + * Pairs with smp_load_acquire() in revoke_iomem(). > > > > > + */ > > > > > + smp_store_release(&iomem_inode, inode); > > > > > > > > However, this seems abnormal, initcalls rarely do this kind of stuff > > > > with global data.. > > > > > > > > The kernel crashes if this fs_initcall is raced with > > > > iomem_get_mapping() due to the unconditional dereference, so I think > > > > it can be safely switched to a simple assignment. > > > > > > Ah yes I checked this all, but forgot to correctly annotate the > > > iomem_get_mapping access. For reference, see b34e7e298d7a ("/dev/mem: > > > Add missing memory barriers for devmem_inode"). > > > > Oh yikes, so revoke_iomem can run concurrently during early boot, > > tricky. > > It runs early because request_mem_region() can run before fs_initcall. > Rather than add an unnecessary lock just arrange for the revoke to be > skipped before the inode is initialized. The expectation is that any > early resource reservations will block future userspace mapping > attempts. Actually, on this point a simple WRITE_ONCE/READ_ONCE pairing is OK, Paul once explained that the pointer chase on the READ_ONCE side is required to be like an acquire - this is why rcu_dereference is just READ_ONCE Jason