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=-3.9 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 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 8C04BC433DF for ; Thu, 15 Oct 2020 07:55:53 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D69ED22243 for ; Thu, 15 Oct 2020 07:55:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=ffwll.ch header.i=@ffwll.ch header.b="HQSl5QWf" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D69ED22243 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ffwll.ch Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 3FDC56B005C; Thu, 15 Oct 2020 03:55:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3AF526B0068; Thu, 15 Oct 2020 03:55:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2766C6B006E; Thu, 15 Oct 2020 03:55:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0135.hostedemail.com [216.40.44.135]) by kanga.kvack.org (Postfix) with ESMTP id EEEA76B005C for ; Thu, 15 Oct 2020 03:55:51 -0400 (EDT) Received: from smtpin27.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 76EA0180AD806 for ; Thu, 15 Oct 2020 07:55:51 +0000 (UTC) X-FDA: 77373400902.27.heart48_4b0f8c727212 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin27.hostedemail.com (Postfix) with ESMTP id 559353D668 for ; Thu, 15 Oct 2020 07:55:51 +0000 (UTC) X-HE-Tag: heart48_4b0f8c727212 X-Filterd-Recvd-Size: 6427 Received: from mail-ot1-f65.google.com (mail-ot1-f65.google.com [209.85.210.65]) by imf06.hostedemail.com (Postfix) with ESMTP for ; Thu, 15 Oct 2020 07:55:50 +0000 (UTC) Received: by mail-ot1-f65.google.com with SMTP id m11so2062838otk.13 for ; Thu, 15 Oct 2020 00:55:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=SKpQn0FDypcCkXIOygWWNsNfWX2lsbxOB8uCbMksAIA=; b=HQSl5QWfcvPbV2pGTi/CgSYNE6yrm43VcrDZdZgXfpSEZAPIWhWUaC3Z9+19ZGIOT/ L1FwUAUuyIWjzwGqR/YpO/MiPOAvkTi9v6qcb2Wcm3bTcyjMzBlJxDT1/tZLBuBLm3mU NDzd8Hc1lCeymtif5yx0kEE4DAlngk2j4kC84= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=SKpQn0FDypcCkXIOygWWNsNfWX2lsbxOB8uCbMksAIA=; b=AWrMuRk+FZSqKCVUXz1ujKG3/s0rtX2OBng1Jm/Qq4aKlRO1xhWtADIhw1fAO4ukiI wB+Zo5JaRbmlCuOPdeybpucwYWXpblvx+a3Et6vMH1kWQl2dEVxLI0VMYiTngG5xxO6E KyNLdDwlW2ZJ1LFtKz350IIAVe6wFJbQn3jTYC3YzkckjQJvta+0YDwHQY0nQxJzjxis VYDgl/M/UZWOKsabe18Zn9rGCpAnx8H+4MMvklHQLie6ZQY7cQQ8Tl7yy5K2IxxeXnHm MwRQ/6jfN9VT/rcKYL9/phNgv9CyPr8puM8BFvxdQ1K0QfmYKwCU6aa+zsD/6rm8PvK3 ARoA== X-Gm-Message-State: AOAM532UJOar9TGkZpdd7sCNTmsNEDjYSgWnAqDXKsNmX2MTwlQEUDds GebFDdPuo6aUGx1JUunubGqC1C2pdo1teVNrg72a63Mb78YlRObi X-Google-Smtp-Source: ABdhPJxdSyalRqLRcx8/tcfIkmtSxIfRSiuYpFEh1r0/JAJixM8EE3XAGRAgngn5UADgaJioF6PuXkNghwu1P0DfUPk= X-Received: by 2002:a05:6830:8b:: with SMTP id a11mr1751471oto.303.1602748549701; Thu, 15 Oct 2020 00:55:49 -0700 (PDT) MIME-Version: 1.0 References: <20201009075934.3509076-1-daniel.vetter@ffwll.ch> <20201009075934.3509076-15-daniel.vetter@ffwll.ch> <20201009123109.GO5177@ziepe.ca> <20201009143209.GS5177@ziepe.ca> <20201015000939.GD6763@ziepe.ca> In-Reply-To: From: Daniel Vetter Date: Thu, 15 Oct 2020 09:55:38 +0200 Message-ID: Subject: Re: [PATCH v2 14/17] resource: Move devmem revoke code to resource framework To: Jason Gunthorpe Cc: Dan Williams , 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?SsOpcsO0bWUgR2xpc3Nl?= , Jan Kara , Arnd Bergmann , Greg Kroah-Hartman , David Hildenbrand , "Rafael J. Wysocki" Content-Type: text/plain; charset="UTF-8" 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 Thu, Oct 15, 2020 at 9:52 AM Daniel Vetter wrote: > > On Thu, Oct 15, 2020 at 2:09 AM Jason Gunthorpe wrote: > > > > 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 > > Indeed this changed with the sm_read_barrier_depends() removal a year > ago. Before that READ_ONCE and rcu_dereference where not actually the > same. I guess I'll throw a patch on top to switch that over too. Actually 2019 landed just the clean-up, the read change landed in 2017 already: commit 76ebbe78f7390aee075a7f3768af197ded1bdfbb Author: Will Deacon Date: Tue Oct 24 11:22:47 2017 +0100 locking/barriers: Add implicit smp_read_barrier_depends() to READ_ONCE() Cheers, Daniel -- Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch