From: Dan Williams <dan.j.williams@intel.com>
To: Matthew Wilcox <willy@infradead.org>
Cc: Greg KH <gregkh@linuxfoundation.org>,
Arnd Bergmann <arnd@arndb.de>, Ingo Molnar <mingo@redhat.com>,
Kees Cook <keescook@chromium.org>,
Russell King <linux@arm.linux.org.uk>,
Andrew Morton <akpm@linux-foundation.org>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
Linux MM <linux-mm@kvack.org>
Subject: Re: [PATCH v2] /dev/mem: Revoke mappings when a driver claims the region
Date: Tue, 19 May 2020 12:36:15 -0700 [thread overview]
Message-ID: <CAPcyv4jgjoLqsV+aHGJwGXbCSwbTnWLmog5-rxD2i31vZ2rDNQ@mail.gmail.com> (raw)
In-Reply-To: <20200519184634.GZ16070@bombadil.infradead.org>
On Tue, May 19, 2020 at 11:46 AM Matthew Wilcox <willy@infradead.org> wrote:
>
> On Tue, May 19, 2020 at 12:03:06AM -0700, Dan Williams wrote:
> > +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;
>
> Which wmb() is this pairing with?
>
> > +static int devmem_init_inode(void)
> > +{
> > + static struct vfsmount *devmem_vfs_mount;
> > + static int devmem_fs_cnt;
> > + struct inode *inode;
> > + int rc;
> > +
> > + rc = simple_pin_fs(&devmem_fs_type, &devmem_vfs_mount, &devmem_fs_cnt);
> > + if (rc < 0) {
> > + pr_err("Cannot mount /dev/mem pseudo filesystem: %d\n", rc);
> > + return rc;
> > + }
> > +
> > + inode = alloc_anon_inode(devmem_vfs_mount->mnt_sb);
> > + if (IS_ERR(inode)) {
> > + rc = PTR_ERR(inode);
> > + pr_err("Cannot allocate inode for /dev/mem: %d\n", rc);
> > + simple_release_fs(&devmem_vfs_mount, &devmem_fs_cnt);
> > + return rc;
> > + }
> > +
> > + /* publish /dev/mem initialized */
> > + WRITE_ONCE(devmem_inode, inode);
> > + smp_wmb();
> > +
> > + return 0;
>
> ... is that this one? I don't see what it's guarding against. Surely if
> it's needed to ensure that the writes to 'inode' have happened before
> the write of the inode pointer, the smp_wmb() needs to be before the
> WRITE_ONCE, not after it?
Whoops, yes. Thanks for the catch.
prev parent reply other threads:[~2020-05-19 19:36 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-19 7:03 [PATCH v2] /dev/mem: Revoke mappings when a driver claims the region Dan Williams
2020-05-19 12:11 ` Greg KH
2020-05-19 18:27 ` Dan Williams
2020-05-20 5:44 ` Greg KH
2020-05-19 18:46 ` Matthew Wilcox
2020-05-19 19:36 ` Dan Williams [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAPcyv4jgjoLqsV+aHGJwGXbCSwbTnWLmog5-rxD2i31vZ2rDNQ@mail.gmail.com \
--to=dan.j.williams@intel.com \
--cc=akpm@linux-foundation.org \
--cc=arnd@arndb.de \
--cc=gregkh@linuxfoundation.org \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux@arm.linux.org.uk \
--cc=mingo@redhat.com \
--cc=willy@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).