All of lore.kernel.org
 help / color / mirror / Atom feed
From: ebiederm@xmission.com (Eric W. Biederman)
To: "Hatayama\, Daisuke" <d.hatayama@jp.fujitsu.com>
Cc: "'gregkh\@linuxfoundation.org'" <gregkh@linuxfoundation.org>,
	"'tj\@kernel.org'" <tj@kernel.org>, "Okajima\,
	Toshiyuki" <toshi.okajima@jp.fujitsu.com>,
	"linux-kernel\@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"'ebiederm\@aristanetworks.com'" <ebiederm@aristanetworks.com>
Subject: Re: [CFT][PATCH] kernfs: Correct kernfs directory seeks.
Date: Mon, 04 Jun 2018 21:02:46 -0500	[thread overview]
Message-ID: <87h8mihtx5.fsf@xmission.com> (raw)
In-Reply-To: <87sh62k3vk.fsf@xmission.com> (Eric W. Biederman's message of "Mon, 04 Jun 2018 09:44:47 -0500")

ebiederm@xmission.com (Eric W. Biederman) writes:

> "Hatayama, Daisuke" <d.hatayama@jp.fujitsu.com> writes:
>
>>> Can you test this and please verify it fixes your issue?
>>
>> I tried this patch on top of v4.17 but the system fails to boot
>> without detecting root disks by dracut like this:
[snip]

>> OTOH, there's no issue on the pure v4.17 kernel.
>>
>> As above, ls /sys/module looks apparently good. But I guess any part of
>> behavior of getdentries() on sysfs must have changed, affecting the disk
>> detection...
>
> I haven't been able to reproduce this yet.  My test system boots fine.
> Which fedora are you testing on?

I reproduced something similar and fedora 28.  So I think I have found
and fixed the issue.  I believe I simply reversed the test at the end of
kernfs_dir_pos. AKA "<" instead of ">".

I am going to see if I can test my changes more throughly on this side
and then repost.



>>>  fs/kernfs/dir.c | 109
>>> ++++++++++++++++++++++++++++++++++----------------------
>>>  1 file changed, 67 insertions(+), 42 deletions(-)
>>> 
>>> diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c
>>> index 89d1dc19340b..8148b5fec48d 100644
>>> --- a/fs/kernfs/dir.c
>>> +++ b/fs/kernfs/dir.c
>>> @@ -1584,53 +1584,75 @@ static int kernfs_dir_fop_release(struct inode *inode,
>>> struct file *filp)
>>>  	return 0;
>>>  }
>>> 
>>> +static struct kernfs_node *kernfs_dir_next(struct kernfs_node *pos)
>>> +{
>>> +	struct rb_node *node = rb_next(&pos->rb);
>>> +	return node ? rb_to_kn(node) : NULL;
>>> +}
>>> +
>>>  static struct kernfs_node *kernfs_dir_pos(const void *ns,
>>> -	struct kernfs_node *parent, loff_t hash, struct kernfs_node *pos)
>>> +	struct kernfs_node *parent, loff_t off, struct kernfs_node *saved)
>>>  {
>>> -	if (pos) {
>>> -		int valid = kernfs_active(pos) &&
>>> -			pos->parent == parent && hash == pos->hash;
>>> -		kernfs_put(pos);
>>> -		if (!valid)
>>> -			pos = NULL;
>>> -	}
>>> -	if (!pos && (hash > 1) && (hash < INT_MAX)) {
>>> -		struct rb_node *node = parent->dir.children.rb_node;
>>> -		while (node) {
>>> -			pos = rb_to_kn(node);
>>> -
>>> -			if (hash < pos->hash)
>>> -				node = node->rb_left;
>>> -			else if (hash > pos->hash)
>>> -				node = node->rb_right;
>>> -			else
>>> -				break;
>>> +	struct kernfs_node *pos;
>>> +	struct rb_node *node;
>>> +	unsigned int hash;
>>> +	const char *name = "";
>>> +
>>> +	/* Is off a valid name hash? */
>>> +	if ((off < 2) || (off >= INT_MAX))
>>> +		return NULL;
>>> +	hash = off;
>>> +
>>> +	/* Is the saved position usable? */
>>> +	if (saved) {
>>> +		/* Proper parent and hash? */
>>> +		if ((parent != saved->parent) || (saved->hash != hash)) {
>>> +			saved = NULL;
>>
>> name is uninitialized in this path.
>
> It is.  name is initialized to "" see above.
>
>>> +		} else {
>>> +			if (kernfs_active(saved))
>>> +				return saved;
>>> +			name = saved->name;
>>>  		}
>>>  	}
>>> -	/* Skip over entries which are dying/dead or in the wrong namespace
>>> */
>>> -	while (pos && (!kernfs_active(pos) || pos->ns != ns)) {
>>> -		struct rb_node *node = rb_next(&pos->rb);
>>> -		if (!node)
>>> -			pos = NULL;
>>> +
>>> +	/* Find the closest pos to the hash we are looking for */
>>> +	pos = NULL;
>>> +	node = parent->dir.children.rb_node;
>>> +	while (node) {
>>> +		int result;
>>> +
>>> +		pos = rb_to_kn(node);
>>> +		result = kernfs_name_compare(hash, name, ns, pos);
>>> +		if (result < 0)
>>> +			node = node->rb_left;
>>> +		else if (result > 0)
>>> +			node = node->rb_right;
>>>  		else
>>> -			pos = rb_to_kn(node);
>>> +			break;
>>>  	}
>>> +
>>> +	/* Ensure pos is at or beyond the target position */
>>> +	if (pos && (kernfs_name_compare(hash, name, ns, pos) < 0))
                                                    ^^^^^^^^^^^^^^^^
                                          should be > 0
>>> +		pos = kernfs_dir_next(pos);
>>> +

Eric

  reply	other threads:[~2018-06-05  2:03 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-28 12:54 [RESEND PATCH v2] kernfs: fix dentry unexpected skip Hatayama, Daisuke
2018-05-28 13:08 ` Hatayama, Daisuke
2018-05-29 16:26 ` 'tj@kernel.org'
2018-06-01  9:25   ` Hatayama, Daisuke
2018-06-01 17:07     ` 'tj@kernel.org'
2018-06-04  9:46       ` Hatayama, Daisuke
2018-06-02 17:25 ` Eric W. Biederman
2018-06-03 18:51   ` [CFT][PATCH] kernfs: Correct kernfs directory seeks Eric W. Biederman
2018-06-04  9:34     ` Hatayama, Daisuke
2018-06-04 14:44       ` Eric W. Biederman
2018-06-05  2:02         ` Eric W. Biederman [this message]
2018-06-05  5:52           ` Hatayama, Daisuke
2018-06-05  5:45         ` Hatayama, Daisuke
2018-06-05 15:31           ` Eric W. Biederman
2018-06-05 15:42             ` 'tj@kernel.org'
2018-06-05 17:47               ` Eric W. Biederman
2018-06-07 18:36                 ` Al Viro

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=87h8mihtx5.fsf@xmission.com \
    --to=ebiederm@xmission.com \
    --cc=d.hatayama@jp.fujitsu.com \
    --cc=ebiederm@aristanetworks.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tj@kernel.org \
    --cc=toshi.okajima@jp.fujitsu.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.