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=-0.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, 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 31250C433DF for ; Thu, 21 May 2020 04:40:04 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E7F9D20738 for ; Thu, 21 May 2020 04:40:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=intel-com.20150623.gappssmtp.com header.i=@intel-com.20150623.gappssmtp.com header.b="bftlGrpv" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E7F9D20738 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 9321480014; Thu, 21 May 2020 00:40:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8E2D880007; Thu, 21 May 2020 00:40:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7F8F180014; Thu, 21 May 2020 00:40:03 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0222.hostedemail.com [216.40.44.222]) by kanga.kvack.org (Postfix) with ESMTP id 67BB980007 for ; Thu, 21 May 2020 00:40:03 -0400 (EDT) Received: from smtpin26.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 27736181AEF1D for ; Thu, 21 May 2020 04:40:03 +0000 (UTC) X-FDA: 76839473886.26.prose35_418e749db38 X-HE-Tag: prose35_418e749db38 X-Filterd-Recvd-Size: 5404 Received: from mail-ej1-f67.google.com (mail-ej1-f67.google.com [209.85.218.67]) by imf49.hostedemail.com (Postfix) with ESMTP for ; Thu, 21 May 2020 04:40:01 +0000 (UTC) Received: by mail-ej1-f67.google.com with SMTP id l21so7267028eji.4 for ; Wed, 20 May 2020 21:40:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=eBtX1BhIv6H5u1g/wTf+6clz1KbfAgNzGVcttWA373A=; b=bftlGrpvKHRdXHGqy/T11STSBYEvsL9Nzi8XjA2bsjOrn3/TudxMpKocwcZsOsuTUi CqLLTV5gtv+CG+2rVQpfvK/GOBJ0pj8PnU/iNahj1zIvd3pSAi+qkJOFuQfftdHPV0BB e9YJ8OrV9UTP0L2AqSnqgx2Af1Vut9xzhhruuEslYbJTI+89Upy5QVT6H6rlETW/ORE5 g6m4gFKWEvz52Nwqb5EA+PAd7SYmxqPcCn2BkpM1J6ze76jLyQKSpIhQ+/P7evvsqz9J nAj6CNysgHeWsOWSJf+XenI0GIGdfoaF4CwfC6WJFhOZBVgzkL08wPcGtH9/1vA2ls8f VqBg== 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=eBtX1BhIv6H5u1g/wTf+6clz1KbfAgNzGVcttWA373A=; b=qsaosjXYfLe3By0+t6ppAiw29yM9kArPnz+dJVU/jGmra0+4bO5pX10H4ggWaIRD7E 9T6TSrNpGdF15RKxpDkLPyLNlP0krCu/M6nwdeOuFYpaI1VXUMhCD9z18LqFmsDrh2YV w6ZU3681O/YtSaxMC4YJMDCioSvL3CEVG6BrcBsmDvt5yngYnSEbnqt/dIWB8sAnjyeB OKYng/5E8cOfP8D63M8295x9D0ghOfveYOiaaF440nt5POKw85bOs4Bvj2V3O6j4oHgG EppGCGVD1dFJIQj+yhCOJD7I3M8F9pAGkRXI/CxU2tDmSyjQcF2x+Sq2+/GdoZBGp1PJ 7idw== X-Gm-Message-State: AOAM530Eu5Ubo+o2i7IVfOgZydE0VhmnTTXWavcZ7swLCfbxuRVxdkK5 LZMl8tm6AHCmTlRN8wlGAeRPe09FlKLFHNK7ddJDYgWw X-Google-Smtp-Source: ABdhPJy2NESD9tmrr3HTnOZP8LoZsyEivlyXTVc6ZGaMysFZHe9qj/CNd6KGxvOcX+mFudxqATX0a57vQI5RWYSzg58= X-Received: by 2002:a17:906:379b:: with SMTP id n27mr1890840ejc.432.1590036000594; Wed, 20 May 2020 21:40:00 -0700 (PDT) MIME-Version: 1.0 References: <159002475918.686697.11844615159862491335.stgit@dwillia2-desk3.amr.corp.intel.com> <20200521022628.GE16070@bombadil.infradead.org> In-Reply-To: From: Dan Williams Date: Wed, 20 May 2020 21:39:49 -0700 Message-ID: Subject: Re: [PATCH v3] /dev/mem: Revoke mappings when a driver claims the region To: Matthew Wilcox Cc: Greg KH , Arnd Bergmann , Ingo Molnar , Kees Cook , Russell King , Andrew Morton , Linux Kernel Mailing List , Linux MM 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 Wed, May 20, 2020 at 9:37 PM Dan Williams wrote: > > On Wed, May 20, 2020 at 7:26 PM Matthew Wilcox wrote: > > > > On Wed, May 20, 2020 at 06:35:25PM -0700, Dan Williams wrote: > > > +static struct inode *devmem_inode; > > > + > > > +#ifdef CONFIG_IO_STRICT_DEVMEM > > > +void revoke_devmem(struct resource *res) > > > +{ > > > + struct inode *inode = READ_ONCE(devmem_inode); > > > + > > > + /* > > > + * Check that the initialization has completed. Losing the race > > > + * is ok because it means drivers are claiming resources before > > > + * the fs_initcall level of init and prevent /dev/mem from > > > + * establishing mappings. > > > + */ > > > + smp_rmb(); > > > + if (!inode) > > > + return; > > > > But we don't need the smp_rmb() here, right? READ_ONCE and WRITE_ONCE > > are a DATA DEPENDENCY barrier (in Documentation/memory-barriers.txt parlance) > > so the smp_rmb() is superfluous ... > > Is it? I did not grok that from Documentation/memory-barriers.txt. > READ_ONCE and WRITE_ONCE are certainly ordered with respect to each > other in the same function, but I thought they still depend on > barriers for smp ordering? > > > > > > + /* > > > + * Use a unified address space to have a single point to manage > > > + * revocations when drivers want to take over a /dev/mem mapped > > > + * range. > > > + */ > > > + inode->i_mapping = devmem_inode->i_mapping; > > > + inode->i_mapping->host = devmem_inode; > > > > umm ... devmem_inode->i_mapping->host doesn't already point to devmem_inode? > > Not if inode is coming from: > > mknod ./newmem c 1 1 > > ...that's the problem that a unified inode solves. You can mknod all > you want, but mapping and mapping->host will point to a common > instance. > > > > > > + > > > + /* publish /dev/mem initialized */ > > > + smp_wmb(); > > > + WRITE_ONCE(devmem_inode, inode); > > > > As above, unnecessary barrier, I think. > > Well, if you're not sure, how sure should I be? I'm pretty sure they are needed, because I need the prior writes to initialize the inode to be fenced before the final write to publish the inode. I don't think WRITE_ONCE() enforces that prior writes have completed.