From: Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>
To: Minchan Kim <minchan@kernel.org>
Cc: zhouxianrong <zhouxianrong@tom.com>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
ngupta@vflare.org, sergey.senozhatsky.work@gmail.com,
zhouxianrong <zhouxianrong@huawei.com>
Subject: Re: [PATCH] zsmalloc: fix linking bug in init_zspage
Date: Mon, 13 Aug 2018 19:55:36 +0900 [thread overview]
Message-ID: <20180813105536.GA435@jagdpanzerIV> (raw)
In-Reply-To: <20180813060549.GB64836@rodete-desktop-imager.corp.google.com>
On (08/13/18 15:05), Minchan Kim wrote:
> > From: zhouxianrong <zhouxianrong@huawei.com>
> >
> > The last partial object in last subpage of zspage should not be linked
> > in allocation list. Otherwise it could trigger BUG_ON explicitly at
> > function zs_map_object. But it happened rarely.
>
> Could you be more specific? What case did you see the problem?
> Is it a real problem or one founded by review?
[..]
> > Signed-off-by: zhouxianrong <zhouxianrong@huawei.com>
> > ---
> > mm/zsmalloc.c | 2 ++
> > 1 file changed, 2 insertions(+)
> >
> > diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c
> > index 8d87e973a4f5..24dd8da0aa59 100644
> > --- a/mm/zsmalloc.c
> > +++ b/mm/zsmalloc.c
> > @@ -1040,6 +1040,8 @@ static void init_zspage(struct size_class *class, struct zspage *zspage)
> > * Reset OBJ_TAG_BITS bit to last link to tell
> > * whether it's allocated object or not.
> > */
> > + if (off > PAGE_SIZE)
> > + link -= class->size / sizeof(*link);
> > link->next = -1UL << OBJ_TAG_BITS;
> > }
> > kunmap_atomic(vaddr);
Hmm. This can be a real issue. Unless I'm missing something.
So... I might be wrong, but the way I see the bug report is:
When we link objects during zspage init, we do the following:
while ((off += class->size) < PAGE_SIZE) {
link->next = freeobj++ << OBJ_TAG_BITS;
link += class->size / sizeof(*link);
}
Note that we increment the link first, link += class->size / sizeof(*link),
and check for the offset only afterwards. So by the time we break out of
the while-loop the link *might* point to the partial object which starts at
the last page of zspage, but *never* ends, because we don't have next_page
in current zspage. So that's why that object should not be linked in,
because it's not a valid allocates object - we simply don't have space
for it anymore.
zspage [ page 1 ][ page 2 ]
...............................link
[..###]
therefore the last object must be "link - 1" for such cases.
I think, the following change can also do the trick:
while ((off + class->size) < PAGE_SIZE) {
link->next = freeobj++ << OBJ_TAG_BITS;
link += class->size / sizeof(*link);
off += class->size;
}
Once again, I might be wrong on this.
Any thoughts?
-ss
next prev parent reply other threads:[~2018-08-13 10:52 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-10 0:28 [PATCH] zsmalloc: fix linking bug in init_zspage zhouxianrong
2018-08-13 6:05 ` Minchan Kim
2018-08-13 10:55 ` Sergey Senozhatsky [this message]
2018-08-14 0:24 ` Minchan Kim
2018-08-14 0:51 ` Sergey Senozhatsky
2018-08-16 0:10 ` zhouxianrong
2018-08-16 3:46 ` Minchan Kim
2018-08-16 6:25 ` reply:Re: " zhouxianrong
-- strict thread matches above, loose matches on Subject: below --
2018-08-09 13:53 zhouxianrong
2018-08-09 14:41 ` Vlastimil Babka
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=20180813105536.GA435@jagdpanzerIV \
--to=sergey.senozhatsky.work@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=minchan@kernel.org \
--cc=ngupta@vflare.org \
--cc=zhouxianrong@huawei.com \
--cc=zhouxianrong@tom.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;
as well as URLs for NNTP newsgroup(s).