From: Hugh Dickins <hughd@google.com>
To: Miklos Szeredi <miklos@szeredi.hu>
Cc: Michal Suchanek <hramrach@centrum.cz>,
Andreas Dilger <adilger@dilger.ca>, Jiri Kosina <jkosina@suse.cz>,
Ric Wheeler <ricwheeler@gmail.com>,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
David Howells <dhowells@redhat.com>, Ian Kent <ikent@redhat.com>,
Jeff Moyer <jmoyer@redhat.com>,
Christoph Hellwig <hch@infradead.org>,
Eric Paris <eparis@redhat.com>,
Andrew Morton <akpm@linux-foundation.org>,
James Morris <jmorris@namei.org>,
Serge Hallyn <serge.hallyn@ubuntu.com>
Subject: Re: [PATCH] tmpfs: implement generic xattr support
Date: Thu, 12 May 2011 09:52:04 -0700 (PDT) [thread overview]
Message-ID: <alpine.LSU.2.00.1105120929190.2735@sister.anvils> (raw)
In-Reply-To: <87oc38m31z.fsf@tucsk.pomaz.szeredi.hu>
On Thu, 12 May 2011, Miklos Szeredi wrote:
> Miklos Szeredi <miklos@szeredi.hu> writes:
>
> >>> + info = SHMEM_I(dentry->d_inode);
> >>> +
> >>> + spin_lock(&dentry->d_inode->i_lock);
> >>
> >> Not important, but I suggest you use info->lock throughout for this,
> >> instead of dentry->d_inode->i_lock: in each case you need "info" for
> >> info->xattr_list (and don't need "inode" at all I think), so info->lock
> >> seems appropriate, and may be in the same cacheline once I make
> >> shmem_inode_info smaller. But don't worry if you'd prefer to leave
> >> it.
> >
> > Makes sense. I updated the locking.
>
> This uncovered a nasty bug lurking in there: the "info" area, including
> lock and xattr_list, may be overwritten by inline symlinks. Because
> xattr_list is near the end, this wasn't noticed with casual testing, but
> info->lock would immediately Oops on getxattr for symlinks.
Yikes, I'd completely forgotten about those inline symlinks:
many thanks for reminding me.
>
> I propose the following solution. It results in slightly less space for
> inline symlinks, but correct operation for xattrs. Does the anonymous
> union/struct solution look acceptable?
You're being conscientious to minimize the space reduction, and I wonder
if I'm being sloppy about it: but I think I'd prefer you to keep it simple
and just make a union of the i_direct[SHMEM_NR_DIRECT] array and the inline
symlink buffer. That does waste space that was occasionally being put to
use before, but saves us from embarrassment next time we forget about the
inline symlinks.
I intend to be removing that i_direct array very soon: I guess I'll want
to kmalloc for short symlinks then, certainly not overlaying over what
fields are left: so you'd be moving in that direction if you just reuse
the i_direct area now.
Hugh
>
> Thanks,
> Miklos
>
> Index: linux-2.6/include/linux/shmem_fs.h
> ===================================================================
> --- linux-2.6.orig/include/linux/shmem_fs.h 2011-05-12 15:59:08.000000000 +0200
> +++ linux-2.6/include/linux/shmem_fs.h 2011-05-12 15:58:25.000000000 +0200
> @@ -11,15 +11,39 @@
>
> struct shmem_inode_info {
> spinlock_t lock;
> - unsigned long flags;
> - unsigned long alloced; /* data pages alloced to file */
> - unsigned long swapped; /* subtotal assigned to swap */
> - unsigned long next_index; /* highest alloced index + 1 */
> - struct shared_policy policy; /* NUMA memory alloc policy */
> - struct page *i_indirect; /* top indirect blocks page */
> - swp_entry_t i_direct[SHMEM_NR_DIRECT]; /* first blocks */
> - struct list_head swaplist; /* chain of maybes on swap */
> - struct list_head xattr_list; /* list of shmem_xattr */
> +
> + /* list of shmem_xattr */
> + struct list_head xattr_list;
> +
> + union {
> + char inline_symlink[0];
> +
> + /* Members not used by inline symlinks: */
> + struct {
> + unsigned long flags;
> +
> + /* data pages alloced to file */
> + unsigned long alloced;
> +
> + /* subtotal assigned to swap */
> + unsigned long swapped;
> +
> + /* highest alloced index + 1 */
> + unsigned long next_index;
> +
> + /* NUMA memory alloc policy */
> + struct shared_policy policy;
> +
> + /* top indirect blocks page */
> + struct page *i_indirect;
> +
> + /* first blocks */
> + swp_entry_t i_direct[SHMEM_NR_DIRECT];
> +
> + /* chain of maybes on swap */
> + struct list_head swaplist;
> + };
> + };
> struct inode vfs_inode;
> };
>
> Index: linux-2.6/mm/shmem.c
> ===================================================================
> --- linux-2.6.orig/mm/shmem.c 2011-05-12 15:59:08.000000000 +0200
> +++ linux-2.6/mm/shmem.c 2011-05-12 15:50:10.000000000 +0200
> @@ -2029,9 +2029,9 @@ static int shmem_symlink(struct inode *d
>
> info = SHMEM_I(inode);
> inode->i_size = len-1;
> - if (len <= (char *)inode - (char *)info) {
> + if (len <= (char *)inode - info->inline_symlink) {
> /* do it inline */
> - memcpy(info, symname, len);
> + memcpy(info->inline_symlink, symname, len);
> inode->i_op = &shmem_symlink_inline_operations;
> } else {
> error = shmem_getpage(inode, 0, &page, SGP_WRITE, NULL);
> @@ -2057,7 +2057,7 @@ static int shmem_symlink(struct inode *d
>
> static void *shmem_follow_link_inline(struct dentry *dentry, struct nameidata *nd)
> {
> - nd_set_link(nd, (char *)SHMEM_I(dentry->d_inode));
> + nd_set_link(nd, SHMEM_I(dentry->d_inode)->inline_symlink);
> return NULL;
> }
next prev parent reply other threads:[~2011-05-12 16:52 UTC|newest]
Thread overview: 73+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-04-12 15:00 Unionmount status? Michal Suchanek
2011-04-12 20:31 ` Ric Wheeler
2011-04-12 21:36 ` Michal Suchanek
2011-04-13 14:18 ` Jiri Kosina
2011-04-13 15:13 ` Michal Suchanek
2011-04-14 8:38 ` Miklos Szeredi
2011-04-14 9:48 ` Sedat Dilek
2011-04-14 9:58 ` Miklos Szeredi
2011-04-15 11:22 ` Michal Suchanek
2011-04-15 11:31 ` Miklos Szeredi
2011-04-15 11:51 ` Michal Suchanek
2011-04-15 12:29 ` Miklos Szeredi
2011-04-15 12:34 ` Michal Suchanek
2011-04-15 12:48 ` Miklos Szeredi
2011-04-15 21:48 ` Hugh Dickins
2011-04-15 22:18 ` Andreas Dilger
2011-04-18 13:31 ` Michal Suchanek
2011-04-19 20:04 ` [PATCH] tmpfs: implement generic xattr support Miklos Szeredi
2011-04-20 2:18 ` Phillip Lougher
2011-04-20 13:43 ` Miklos Szeredi
2011-04-21 6:59 ` Michal Suchanek
2011-04-21 9:08 ` Miklos Szeredi
2011-04-21 10:59 ` Michal Suchanek
2011-04-21 14:58 ` Jordi Pujol
2011-04-21 15:22 ` Michal Suchanek
2011-04-21 15:43 ` Michal Suchanek
2011-04-21 17:26 ` Miklos Szeredi
2011-04-21 19:17 ` Michal Suchanek
2011-04-20 16:00 ` Serge E. Hallyn
2011-05-12 4:20 ` Hugh Dickins
2011-05-12 7:52 ` Michal Suchanek
2011-05-12 12:27 ` Miklos Szeredi
2011-05-12 14:00 ` Miklos Szeredi
2011-05-12 16:52 ` Hugh Dickins [this message]
2011-04-18 13:34 ` Unionmount status? Michal Suchanek
2011-04-18 13:37 ` Michal Suchanek
2011-04-13 17:26 ` Ric Wheeler
2011-04-13 18:58 ` Michal Suchanek
2011-04-13 19:11 ` Ric Wheeler
2011-04-13 19:47 ` Michal Suchanek
2011-04-14 4:50 ` Ian Kent
2011-04-14 9:32 ` Michal Suchanek
2011-04-14 9:40 ` Miklos Szeredi
2011-04-14 13:21 ` Ric Wheeler
2011-04-14 14:54 ` Michal Suchanek
2011-04-15 16:31 ` Ric Wheeler
2011-04-14 19:14 ` David Howells
2011-06-29 9:39 ` Union mount and overlayfs bake off? Ric Wheeler
2011-06-29 11:40 ` Michal Suchanek
2011-06-29 10:17 ` David Howells
2011-06-30 12:44 ` Miklos Szeredi
2011-07-10 8:28 ` Union mount and lockdep design issues Ric Wheeler
2011-07-10 13:48 ` Peter Zijlstra
2011-07-11 8:35 ` Michal Suchanek
2011-07-11 11:01 ` David Howells
2011-07-11 12:00 ` Peter Zijlstra
2011-07-11 13:36 ` Michal Suchanek
2011-07-11 13:50 ` Ian Kent
2011-07-11 16:17 ` Michal Suchanek
2011-07-11 17:23 ` Ian Kent
2011-07-11 18:08 ` Michal Suchanek
2011-07-12 8:30 ` Miklos Szeredi
2011-07-12 9:58 ` Michal Suchanek
2011-07-12 11:45 ` Miklos Szeredi
2011-07-12 18:49 ` Michal Suchanek
2011-07-13 9:49 ` Miklos Szeredi
2011-07-13 12:02 ` David Howells
2011-07-13 13:20 ` Miklos Szeredi
2011-07-14 0:57 ` David Howells
2011-07-11 13:54 ` David Howells
2011-07-11 14:02 ` Peter Zijlstra
2011-07-11 14:50 ` [PATCH 1/2] VFS: Pass mount flags to sget() David Howells
2011-07-11 14:50 ` [PATCH 2/2] union-mount: Duplicate the i_{, dir_}mutex lock classes and use for upper layer David Howells
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=alpine.LSU.2.00.1105120929190.2735@sister.anvils \
--to=hughd@google.com \
--cc=adilger@dilger.ca \
--cc=akpm@linux-foundation.org \
--cc=dhowells@redhat.com \
--cc=eparis@redhat.com \
--cc=hch@infradead.org \
--cc=hramrach@centrum.cz \
--cc=ikent@redhat.com \
--cc=jkosina@suse.cz \
--cc=jmorris@namei.org \
--cc=jmoyer@redhat.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=miklos@szeredi.hu \
--cc=ricwheeler@gmail.com \
--cc=serge.hallyn@ubuntu.com \
/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
all inboxes | Powered by JetHome®