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=-5.3 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,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 21B0DC433E7 for ; Thu, 15 Oct 2020 00:09:45 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 5B27D21D81 for ; Thu, 15 Oct 2020 00:09:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b="VY1qyIeC" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5B27D21D81 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 8513A6B0062; Wed, 14 Oct 2020 20:09:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 741F36B0068; Wed, 14 Oct 2020 20:09:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5B7656B006E; Wed, 14 Oct 2020 20:09:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0062.hostedemail.com [216.40.44.62]) by kanga.kvack.org (Postfix) with ESMTP id 1BA916B0062 for ; Wed, 14 Oct 2020 20:09:43 -0400 (EDT) Received: from smtpin05.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 928BE181AEF00 for ; Thu, 15 Oct 2020 00:09:42 +0000 (UTC) X-FDA: 77372226204.05.light04_5a09d7627210 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin05.hostedemail.com (Postfix) with ESMTP id 7A5341826B6A6 for ; Thu, 15 Oct 2020 00:09:42 +0000 (UTC) X-HE-Tag: light04_5a09d7627210 X-Filterd-Recvd-Size: 6096 Received: from mail-qk1-f193.google.com (mail-qk1-f193.google.com [209.85.222.193]) by imf47.hostedemail.com (Postfix) with ESMTP for ; Thu, 15 Oct 2020 00:09:41 +0000 (UTC) Received: by mail-qk1-f193.google.com with SMTP id f21so1028061qko.5 for ; Wed, 14 Oct 2020 17:09:41 -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=Y6msn1IS1sMiP8SWrNTJEptn2sxyZEO/WJDZzqLs3Vtpf+lexmcYAAbu1DMkZw2JiN k/QWCk9Zqw/zqme5aVQR5IdR8ivlpTk+abPYnadNAdKcfdHYhLaT3nkuasiKANPMXy8I onqQwnHiuaHhqZVQ33jLo5rddn0KnPHCMliDny6huPbmOPf52XOZnj+Db5FhJdbT7Lh1 HuVEzXLQU/kETGFnQYbZitssgAMjLY9cgYMK3y9O1v+segBkQwxn8Gm0jVx3VWBm+1JK rda6BOdqKcBcdw+7kOBF0rnMRCxAQ/bqJksrexG8i68OqCvFlGlPVdE5Cl/IlZpkwbj3 Qa+w== X-Gm-Message-State: AOAM533/p0HEhp6XhqzrR17xw+TJAUzgUmUT23H/H00kQaSoDvay8SpA uuY9G7qo2u63gkaz0andhZPxNg== X-Google-Smtp-Source: ABdhPJz1YpfemWgv6ITHdO1cDHAUR6b7J4qWqW/ErSGbJ1yD3QFJwI22cUMtAvpN9oIOH7a/n3cIYg== 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) 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, 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