Received: by 10.223.164.202 with SMTP id h10csp740992wrb; Mon, 6 Nov 2017 14:47:37 -0800 (PST) X-Google-Smtp-Source: ABhQp+R/kXW2XFNgcuOsAlA7mk2nrLzVybCEL5TiTl+Wf4hWK4xPBh7Q31EOGIg/E+vWAhHQ1JLA X-Received: by 10.84.135.3 with SMTP id 3mr15941236pli.147.1510008457441; Mon, 06 Nov 2017 14:47:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510008457; cv=none; d=google.com; s=arc-20160816; b=WaMoIXHyLD5J3p4U4T3P7yz1qLRcdQ3OMDvsywazGfGjTw+COzWWcaxy6MBEQYS0H4 n9a/tfSSpNLhIdwDGtogfPISysd+ohmw/FT+786r+dYAsy0m9IpFZRP1Vg3cXimdKbSX jD/viQ4cXu4dEhQJ3E/BtL48W/Lzjyat/+3yjZ+mCegXELeKfFXCMoaPwdwXvLUNhWwP kV3KWis1O/bKe1YqUkgDGmiKB6G3RlvjNZrAYJF0cEA1CmrqKVobPGXNC7R6cGnChbDv XxW2t3jt1ZNbnfG2f6BwoObOBYLvlzIvNOkASOl7/syLHM7GATLsroYcns6o8TfAV0n3 m02Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=iWowURb+Bv4J2sRyTeTepZ4TqLSzG0ShfPvpuNPZ+Kg=; b=BJhWK+UkDRuHQ+pMWUzJCDs3mzdHnFDVCHPSzcxGW4xPBqLQarU6Va8TuX0Arecx4D r/yayUhP+VmdZ6DDeRqhIxqkAnzfFynRn4/4tCKOqwPVWVlmdcipO/FIe2GCP6eB2jnr QrqZ+yiCgSB4zQzJdZrDpI2O3MSgbfpQ23yCCjdezc9fskgJI5/Rgv5MBPWVeo/Mjz5J nO8Y5+GfhKbc0igR62HTX0Kat/AtWAhwJfhbd+fK9qLsIWPU1K+Mk8v7ko48ozfkTtxj 8Sje1CaIj0jex2RBBqSFQq/XhxA2H8jC3cnlpJcvimsyOFWcmTQfrx8sjsPXm++9hNBj ng5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=DlDPwOu1; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l15si11697981pgr.469.2017.11.06.14.47.24; Mon, 06 Nov 2017 14:47:37 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=DlDPwOu1; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754077AbdKFWaI (ORCPT + 94 others); Mon, 6 Nov 2017 17:30:08 -0500 Received: from mail-oi0-f66.google.com ([209.85.218.66]:43336 "EHLO mail-oi0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750993AbdKFWaG (ORCPT ); Mon, 6 Nov 2017 17:30:06 -0500 Received: by mail-oi0-f66.google.com with SMTP id c77so8772585oig.0 for ; Mon, 06 Nov 2017 14:30:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=iWowURb+Bv4J2sRyTeTepZ4TqLSzG0ShfPvpuNPZ+Kg=; b=DlDPwOu1qp4TIocE0w6fs0dahwxuAXmRGAxnMAZLITJSZcPHmUFabzDH+w+1FbqyYN 7z1Iw0gsJiz+oNxDaCw2qAgAOihHsBmaOIWv5S71Kcj7c3YgfvoL8EEkUjUrw8FbEVjr 7qkTtMy/xH6W6HSzBxjIjRLS0yvHNtmKylLrX9m4D/ffmb7ygzejl6jDvB5nNpZfnWDZ nSC9/+Zzp9g7cXm0Xqr4cLBYLRtmWapQVkPxPArDDQxUF1p948vnuTw7jIgmj8/f5IoX 4sg6q4JJFWf4uGM8NLPgHcJbSc1HTPmLB/wvRaxaliVlSLyGCCgVa8N+HzGzNsUnIslp 9YLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=iWowURb+Bv4J2sRyTeTepZ4TqLSzG0ShfPvpuNPZ+Kg=; b=Jm/i+XD7oZfwDTkt3410ekhYhtWk3wARs87tLRYFvGUAZY6Z6JHvxg51mMvYu1pSaE NHDtqNIYqBO06Xs18bM8uA1JP1CI8zjHqcefuAbQHi4BcmaEpprw1cJyiyi0PpvBzown 0o+6bWMn9qojUbqZQncFTNdJ9hbH6270qPhqahFyLSf2C6hs/SS0OOKhY1ukNvIadPqH 1SY+KZOG1JAMyaM4ogg+WoSFN6QssOHDMsZ7N8imW/tV1pWqhkYpZlgJP3B15HP5k334 g/U1PhyCrRD/7V7Suacnd60va6n1A5wq9hzlK514jHQCYqdFMyabII/6KmXyWrO43020 gn4Q== X-Gm-Message-State: AMCzsaV2k0T4VCEY6GVt48KRMMxLep3sw4gmPjVXY4bv7mODx+VNI4Wa tj4h6TATyjGrpvyX6xJb9nwMVC5R2mEKT0gmqQg= X-Received: by 10.202.172.214 with SMTP id v205mr9448920oie.102.1510007406051; Mon, 06 Nov 2017 14:30:06 -0800 (PST) MIME-Version: 1.0 Received: by 10.168.0.79 with HTTP; Mon, 6 Nov 2017 14:30:05 -0800 (PST) In-Reply-To: <20171102080249.uxxq4ko3cc2wgnbz@dhcp22.suse.cz> References: <20171102063507.25671-1-jaewon31.kim@samsung.com> <20171102080249.uxxq4ko3cc2wgnbz@dhcp22.suse.cz> From: Jaewon Kim Date: Tue, 7 Nov 2017 07:30:05 +0900 Message-ID: Subject: Re: [PATCH] mm: page_ext: allocate page extension though first PFN is invalid To: Michal Hocko Cc: Jaewon Kim , Andrew Morton , vbabka@suse.cz, minchan@kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 2017-11-02 17:02 GMT+09:00 Michal Hocko : > On Thu 02-11-17 15:35:07, Jaewon Kim wrote: >> online_page_ext and page_ext_init allocate page_ext for each section, but >> they do not allocate if the first PFN is !pfn_present(pfn) or >> !pfn_valid(pfn). Then section->page_ext remains as NULL. lookup_page_ext >> checks NULL only if CONFIG_DEBUG_VM is enabled. For a valid PFN, >> __set_page_owner will try to get page_ext through lookup_page_ext. >> Without CONFIG_DEBUG_VM lookup_page_ext will misuse NULL pointer as value >> 0. This incurrs invalid address access. >> >> This is the panic example when PFN 0x100000 is not valid but PFN 0x13FC00 >> is being used for page_ext. section->page_ext is NULL, get_entry returned >> invalid page_ext address as 0x1DFA000 for a PFN 0x13FC00. >> >> <1>[ 11.618085] Unable to handle kernel paging request at virtual address 01dfa014 >> <1>[ 11.618140] pgd = ffffffc0c6dc9000 >> <1>[ 11.618174] [01dfa014] *pgd=0000000000000000, *pud=0000000000000000 >> <4>[ 11.618240] ------------[ cut here ]------------ >> <2>[ 11.618278] Kernel BUG at ffffff80082371e0 [verbose debug info unavailable] >> <0>[ 11.618338] Internal error: Oops: 96000045 [#1] PREEMPT SMP >> <4>[ 11.618381] Modules linked in: >> <4>[ 11.618524] task: ffffffc0c6ec9180 task.stack: ffffffc0c6f40000 >> <4>[ 11.618569] PC is at __set_page_owner+0x48/0x78 >> <4>[ 11.618607] LR is at __set_page_owner+0x44/0x78 >> <4>[ 11.626025] [] __set_page_owner+0x48/0x78 >> <4>[ 11.626071] [] get_page_from_freelist+0x880/0x8e8 >> <4>[ 11.626118] [] __alloc_pages_nodemask+0x14c/0xc48 >> <4>[ 11.626165] [] __do_page_cache_readahead+0xdc/0x264 >> <4>[ 11.626214] [] filemap_fault+0x2ac/0x550 >> <4>[ 11.626259] [] ext4_filemap_fault+0x3c/0x58 >> <4>[ 11.626305] [] __do_fault+0x80/0x120 >> <4>[ 11.626347] [] handle_mm_fault+0x704/0xbb0 >> <4>[ 11.626393] [] do_page_fault+0x2e8/0x394 >> <4>[ 11.626437] [] do_mem_abort+0x88/0x124 >> >> Though the first page is not valid, page_ext could be useful for other >> pages in the section. But checking all PFNs in a section may be time >> consuming job. Let's check each (section count / 16) PFN, then prepare >> page_ext if any PFN is present or valid. And remove the CONFIG_DEBUG_VM in >> lookup_page_ext to avoid panic. > > So I would split this patch into two. First one to address the panic > which sounds like a stable material and then the enhancement which will > most likely need a further discussion. Hello Michal Hocko Thank you for your comment. I think checking Null by erasing #if defined(CONFIG_DEBUG_VM) is the stable material. I wonder if you want me to split and resend the 2 patches, or if you will use this mail thread for the further discussion. Thank you Jaewon Kim > >> Signed-off-by: Jaewon Kim >> --- >> mm/page_ext.c | 29 ++++++++++++++++++++++------- >> 1 file changed, 22 insertions(+), 7 deletions(-) >> >> diff --git a/mm/page_ext.c b/mm/page_ext.c >> index 32f18911deda..bf9c99beb312 100644 >> --- a/mm/page_ext.c >> +++ b/mm/page_ext.c >> @@ -124,7 +124,6 @@ struct page_ext *lookup_page_ext(struct page *page) >> struct page_ext *base; >> >> base = NODE_DATA(page_to_nid(page))->node_page_ext; >> -#if defined(CONFIG_DEBUG_VM) >> /* >> * The sanity checks the page allocator does upon freeing a >> * page can reach here before the page_ext arrays are >> @@ -133,7 +132,6 @@ struct page_ext *lookup_page_ext(struct page *page) >> */ >> if (unlikely(!base)) >> return NULL; >> -#endif >> index = pfn - round_down(node_start_pfn(page_to_nid(page)), >> MAX_ORDER_NR_PAGES); >> return get_entry(base, index); >> @@ -198,7 +196,6 @@ struct page_ext *lookup_page_ext(struct page *page) >> { >> unsigned long pfn = page_to_pfn(page); >> struct mem_section *section = __pfn_to_section(pfn); >> -#if defined(CONFIG_DEBUG_VM) >> /* >> * The sanity checks the page allocator does upon freeing a >> * page can reach here before the page_ext arrays are >> @@ -207,7 +204,6 @@ struct page_ext *lookup_page_ext(struct page *page) >> */ >> if (!section->page_ext) >> return NULL; >> -#endif >> return get_entry(section->page_ext, pfn); >> } >> >> @@ -312,7 +308,17 @@ static int __meminit online_page_ext(unsigned long start_pfn, >> } >> >> for (pfn = start; !fail && pfn < end; pfn += PAGES_PER_SECTION) { >> - if (!pfn_present(pfn)) >> + unsigned long t_pfn = pfn; >> + bool present = false; >> + >> + while (t_pfn < ALIGN(pfn + 1, PAGES_PER_SECTION)) { >> + if (pfn_present(t_pfn)) { >> + present = true; >> + break; >> + } >> + t_pfn = ALIGN(pfn + 1, PAGES_PER_SECTION >> 4); >> + } >> + if (!present) >> continue; >> fail = init_section_page_ext(pfn, nid); >> } >> @@ -391,8 +397,17 @@ void __init page_ext_init(void) >> */ >> for (pfn = start_pfn; pfn < end_pfn; >> pfn = ALIGN(pfn + 1, PAGES_PER_SECTION)) { >> - >> - if (!pfn_valid(pfn)) >> + unsigned long t_pfn = pfn; >> + bool valid = false; >> + >> + while (t_pfn < ALIGN(pfn + 1, PAGES_PER_SECTION)) { >> + if (pfn_valid(t_pfn)) { >> + valid = true; >> + break; >> + } >> + t_pfn = ALIGN(pfn + 1, PAGES_PER_SECTION >> 4); >> + } >> + if (!valid) >> continue; >> /* >> * Nodes's pfns can be overlapping. >> -- >> 2.13.0 > > -- > Michal Hocko > SUSE Labs From 1582940653794529106@xxx Thu Nov 02 08:04:05 +0000 2017 X-GM-THRID: 1582935025480239932 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread