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.8 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 3092AC43467 for ; Fri, 9 Oct 2020 14:25:00 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id BA40C222BA for ; Fri, 9 Oct 2020 14:24:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=ffwll.ch header.i=@ffwll.ch header.b="YLM0g/4o" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BA40C222BA 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 1C694940009; Fri, 9 Oct 2020 10:24:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 177A1940007; Fri, 9 Oct 2020 10:24:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 03F3F940009; Fri, 9 Oct 2020 10:24:58 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0032.hostedemail.com [216.40.44.32]) by kanga.kvack.org (Postfix) with ESMTP id C83F6940007 for ; Fri, 9 Oct 2020 10:24:58 -0400 (EDT) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 66EBF181AE869 for ; Fri, 9 Oct 2020 14:24:58 +0000 (UTC) X-FDA: 77352608676.07.legs93_5814741271e1 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin07.hostedemail.com (Postfix) with ESMTP id 485951803F9A1 for ; Fri, 9 Oct 2020 14:24:58 +0000 (UTC) X-HE-Tag: legs93_5814741271e1 X-Filterd-Recvd-Size: 5059 Received: from mail-oi1-f194.google.com (mail-oi1-f194.google.com [209.85.167.194]) by imf50.hostedemail.com (Postfix) with ESMTP for ; Fri, 9 Oct 2020 14:24:57 +0000 (UTC) Received: by mail-oi1-f194.google.com with SMTP id u17so10394728oie.3 for ; Fri, 09 Oct 2020 07:24:57 -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=4j8VU4wpGDl6YV4vbFDWVWHEZCZz4TBGhbt0uuUGdBg=; b=YLM0g/4oQLD0hu/Oa87scm3scHf+vbiPkLbDqUAnyXk3ER+QRam40zaijXvFBD6PRA nzSbXcW7hn805lQbe6AX68hG76VYbA+coTzGsCT/QWJIzeeROcYpI8QHsxV9QNKX8ew0 Dn833fe+dPzpkngPWmhP7pgAZbKyHIAe+x52Q= 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=4j8VU4wpGDl6YV4vbFDWVWHEZCZz4TBGhbt0uuUGdBg=; b=ev3jwRuPgSWeRpCAUSr0zpg9YjYUwv4PEfIJRoxFMokevosmZnTSZDQkhVRoolCcZK LNNp4OB2wtAZBGPviYzUZ7d7ifXGd8qe91T5cydm1aOw1seGLW2QdWtSkSlFXWmfzFJi tUBUcjMZL4GpQ+IrH2mW6vFHJ3fp/VCOgOYNrHFcnXI40LxR2ixFUX7AipfuZjGiLP4w Ho9XUv4Vu1ea1YuBS/vBc/sMH0JRyn7BqZVCfv8eTbKWr1e8cQ81aLcu13pprxwgU/e/ MvSwCgWkbaHfSxuPePAsCGDaJijLxPuvUSRWiiG0eJfAu9UwchuH6nvmElzEGJLsLm/7 qnjg== X-Gm-Message-State: AOAM532IM9kOgyFItSI4MHE9wJfJ8SkNz6rdKEZ2wybXJNnGdDJvxkb7 SyZ/o0lKZjNGzzJpkUEKcKc6VAfYmBIcG7DnLRdX1w== X-Google-Smtp-Source: ABdhPJyHxT/6NZr88G54H2j+X8AAqjyafUNpDVmVkQQPYeZ/EXQjiOmXOOdqJRKMWvSSWVU71sVuY9YK0QkcwCetmpo= X-Received: by 2002:aca:6083:: with SMTP id u125mr2688783oib.14.1602253497033; Fri, 09 Oct 2020 07:24:57 -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> In-Reply-To: <20201009123109.GO5177@ziepe.ca> From: Daniel Vetter Date: Fri, 9 Oct 2020 16:24:45 +0200 Message-ID: Subject: Re: [PATCH v2 14/17] resource: Move devmem revoke code to resource framework To: Jason Gunthorpe Cc: DRI Development , LKML , KVM list , Linux MM , Linux ARM , linux-samsung-soc , "open list:DMA BUFFER SHARING FRAMEWORK" , linux-s390 , Daniel Vetter , Kees Cook , Dan Williams , 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 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"). The reasons for the annotations is that iomem requests can happen fairly early, way before fs_initcalls happen. That means revoke_iomem needs to check for that and bail out if we race - nothing bad can happen since userspace isn't running at this point anyway. And apparently it needs to be a full acquire fence since we don't just write a value, but need a barrier for the struct stuff. Now iomem_get_mapping otoh can only be called after userspace is up & running, so way after all the fs_initcalls are guaranteed to have fininshed. Hence we don't really need anything there. But I expect the kernel race checker thing to complain, plus that then gives me a good spot to explain why we can't race and don't have to check for a NULL iomem_inode. I'll add that in v3. -Daniel -- Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch