Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp293066pxu; Thu, 15 Oct 2020 04:15:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxzIsyLytSVWm6jCLd9VDfj+ERxAgxx2mrWbtPxubiPTmPwJSXNT5U3YqHqj3uoi7kGkN/g X-Received: by 2002:a17:906:3650:: with SMTP id r16mr3804069ejb.419.1602760552359; Thu, 15 Oct 2020 04:15:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602760552; cv=none; d=google.com; s=arc-20160816; b=E37xCQ+jiLmWl7XGHgFfKXbuRFI9oF+WMJ1HSoEv81SLePZfM/EwrhNI1wdepsSpQu TG22Q7KYgH/LjQAZF+uC2Snc3Z33DCHRvmdfdtq4TXenAfT0eQlqPaFvBKGBAe2ibIZ2 TEhRgBoq86AfcX5jeaPKpCk/zLus4nrYEvr2EZiE58dfYM1lUOox0eFjPoFqo/BzjMU7 pJBw1WYoe19WFmJXqHwW7b3dvtzbgSU9p1Y/5k9ty+EKP55wsWZYMHvRM9MyHowSypNp kbyO+oIVoKoEcBDRyUNOTdRTzU1J0pgBQKA6zB8n0rh2/zqKeqiyMUim9DXEjAS/T2f2 XMxw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=SKpQn0FDypcCkXIOygWWNsNfWX2lsbxOB8uCbMksAIA=; b=p/ABJQqNZisjPNk14CdDkVapuZpfeJsBvJWU7DEhcpDh7KT/mhAerxPBTmnp9jQU85 Ac8ChhOtXLITC8gOUb9Oa5i5/YHDcJNKkSaTl/zunAfo7Un3511xNZKGuK8V4P9qdwQf QRdZvD0rT2ng1KHIEEBkuHLIyCLEPZiF5tLsl0VX3hxpqQClokf7gpYHIk4nZc7DGnzt dpJy8lkjYt79gyWCB5CFHfKKb/8Hn0xOd8dsmHxqmw8qrbU+HepTumpiINoCwDo68TeB km7JDmP1xSZ5DyJMut03dBUoy+LK0Cg1AcWU0RSvlBkHURAB7H8QQv04WmGv2vSK/r00 XF7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=HQSl5QWf; 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 r6si1806618eji.73.2020.10.15.04.15.29; Thu, 15 Oct 2020 04:15:52 -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=@ffwll.ch header.s=google header.b=HQSl5QWf; 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 S1729948AbgJOHzv (ORCPT + 99 others); Thu, 15 Oct 2020 03:55:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52518 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729842AbgJOHzv (ORCPT ); Thu, 15 Oct 2020 03:55:51 -0400 Received: from mail-ot1-x341.google.com (mail-ot1-x341.google.com [IPv6:2607:f8b0:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5C57CC0613D2 for ; Thu, 15 Oct 2020 00:55:50 -0700 (PDT) Received: by mail-ot1-x341.google.com with SMTP id d28so2139358ote.1 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=ssQqAVTdb0W0EeHHmmz17Qcbfc3qRrnytKylK2T/VEifDCA1K3iXhBqtOkclif049M M4Tg6LiQ7hGKNW9gkhs0tn8oOLWB5tr39nfxoEC7TxEZRkJpXPWkk0gsrJYRoCrYUALw 1bFVxEeZGppcr3IAAfSCwFmFJsmG/IZcUOLnHtFtQRM3ciBG5g9CYsdmJPTvqicHq+cc 7O38O2c6qEMMRa5OqK4191bc66KSSdfJPtFyafUrYegURwUmJK+WAYG6ZM/vk6C/uzIe LuEOVHjoY0kt/Jg9TztoZz7oS27OoPY/kG+SkojofEJ6Y+KOwJlBwOmIVOL34XULNc7S n8OQ== X-Gm-Message-State: AOAM531CQL6Z44dU43DvNODX4HZjOqqZ98q01Y2qjwQUUhTvykmaPzy/ QQNv5lvwMWHkdIn5pHRy2IrN2qPQAA7p48UDxUj6iw== 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" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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