Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751463AbdILUnl (ORCPT ); Tue, 12 Sep 2017 16:43:41 -0400 Received: from mail-wr0-f194.google.com ([209.85.128.194]:35429 "EHLO mail-wr0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750941AbdILUnj (ORCPT ); Tue, 12 Sep 2017 16:43:39 -0400 X-Google-Smtp-Source: ADKCNb4fRghGXMTo7DUbk9Q64nK3M1hDmV2JeQ3xoSnBE+hO40fmhjMfsWyelwRqyM9aCnXKl5gPbA== Date: Tue, 12 Sep 2017 22:43:06 +0200 From: Alexandru Moise <00moses.alexander00@gmail.com> To: linux-kernel@vger.kernel.org, khandual@linux.vnet.ibm.com, akpm@linux-foundation.org, mhocko@suse.com, aarcange@redhat.com, minchan@kernel.org, hillf.zj@alibaba-inc.com, shli@fb.com, rppt@linux.vnet.ibm.com, kirill.shutemov@linux.intel.com, mgorman@techsingularity.net, rientjes@google.com, riel@redhat.com, linux-mm@kvack.org Subject: [PATCH] mm, hugetlb, soft_offline: save compound page order before page migration Message-ID: <20170912204306.GA12053@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.9.0 (2017-09-02) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1322 Lines: 46 This fixes a bug in madvise() where if you'd try to soft offline a hugepage via madvise(), while walking the address range you'd end up, using the wrong page offset due to attempting to get the compound order of a former but presently not compound page, due to dissolving the huge page (since c3114a8). Signed-off-by: Alexandru Moise <00moses.alexander00@gmail.com> --- mm/madvise.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/mm/madvise.c b/mm/madvise.c index 21261ff0466f..25bade36e9ca 100644 --- a/mm/madvise.c +++ b/mm/madvise.c @@ -625,18 +625,26 @@ static int madvise_inject_error(int behavior, { struct page *page; struct zone *zone; + unsigned int order; if (!capable(CAP_SYS_ADMIN)) return -EPERM; - for (; start < end; start += PAGE_SIZE << - compound_order(compound_head(page))) { + + for (; start < end; start += PAGE_SIZE << order) { int ret; ret = get_user_pages_fast(start, 1, 0, &page); if (ret != 1) return ret; + /* + * When soft offlining hugepages, after migrating the page + * we dissolve it, therefore in the second loop "page" will + * no longer be a compound page, and order will be 0. + */ + order = compound_order(compound_head(page)); + if (PageHWPoison(page)) { put_page(page); continue; -- 2.14.1