From patchwork Fri Sep 6 08:09:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Toshiki Fukasawa X-Patchwork-Id: 11134693 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E756814ED for ; Fri, 6 Sep 2019 08:17:07 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A671F2082C for ; Fri, 6 Sep 2019 08:17:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A671F2082C Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=vx.jp.nec.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id AE7C96B0003; Fri, 6 Sep 2019 04:17:06 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id A980F6B0006; Fri, 6 Sep 2019 04:17:06 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 988626B0007; Fri, 6 Sep 2019 04:17:06 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0199.hostedemail.com [216.40.44.199]) by kanga.kvack.org (Postfix) with ESMTP id 77A146B0003 for ; Fri, 6 Sep 2019 04:17:06 -0400 (EDT) Received: from smtpin15.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with SMTP id 575DF55F90 for ; Fri, 6 Sep 2019 08:17:05 +0000 (UTC) X-FDA: 75903790410.15.stamp75_77e90e835fe33 X-Spam-Summary: 2,0,0,af5bac2879e06dcb,d41d8cd98f00b204,t-fukasawa@vx.jp.nec.com,::dan.j.williams@intel.com:linux-kernel@vger.kernel.org:akpm@linux-foundation.org:mhocko@kernel.org:adobriyan@gmail.com:hch@lst.de:longman@redhat.com:sfr@canb.auug.org.au:mst@redhat.com:n-horiguchi@ah.jp.nec.com:j-nomura@ce.jp.nec.com:t-fukasawa@vx.jp.nec.com,RULES_HIT:10:41:355:379:582:800:960:967:973:988:989:1152:1260:1261:1277:1311:1313:1314:1345:1437:1513:1515:1516:1518:1521:1535:1544:1593:1594:1605:1711:1730:1747:1777:1792:2198:2199:2393:2525:2553:2559:2563:2682:2685:2693:2859:2901:2933:2937:2939:2942:2945:2947:2951:2954:3022:3138:3139:3140:3141:3142:3369:3865:3866:3867:3870:3871:3872:3874:3934:3936:3938:3941:3944:3947:3950:3953:3956:3959:4117:4321:5007:6117:6119:6120:6238:6261:6611:6742:7901:7903:8603:8660:8957:9025:9163:9165:10004:10399:11026:11232:11473:11658:11914:12043:12296:12297:12438:12517:12519:12555:12679:12740:12895:12986:13148:13161:13229:13230:13870:14096:14097:14181:14721:21063 :21080:2 X-HE-Tag: stamp75_77e90e835fe33 X-Filterd-Recvd-Size: 6652 Received: from tyo161.gate.nec.co.jp (tyo161.gate.nec.co.jp [114.179.232.161]) by imf09.hostedemail.com (Postfix) with ESMTP for ; Fri, 6 Sep 2019 08:17:03 +0000 (UTC) Received: from mailgate02.nec.co.jp ([114.179.233.122]) by tyo161.gate.nec.co.jp (8.15.1/8.15.1) with ESMTPS id x868GoAD017898 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Fri, 6 Sep 2019 17:16:50 +0900 Received: from mailsv02.nec.co.jp (mailgate-v.nec.co.jp [10.204.236.94]) by mailgate02.nec.co.jp (8.15.1/8.15.1) with ESMTP id x868Gn8O006386; Fri, 6 Sep 2019 17:16:49 +0900 Received: from mail01b.kamome.nec.co.jp (mail01b.kamome.nec.co.jp [10.25.43.2]) by mailsv02.nec.co.jp (8.15.1/8.15.1) with ESMTP id x868F0sx023285; Fri, 6 Sep 2019 17:16:49 +0900 Received: from bpxc99gp.gisp.nec.co.jp ([10.38.151.152] [10.38.151.152]) by mail02.kamome.nec.co.jp with ESMTP id BT-MMP-8242729; Fri, 6 Sep 2019 17:09:54 +0900 Received: from BPXM20GP.gisp.nec.co.jp ([10.38.151.212]) by BPXC24GP.gisp.nec.co.jp ([10.38.151.152]) with mapi id 14.03.0439.000; Fri, 6 Sep 2019 17:09:54 +0900 From: Toshiki Fukasawa To: "linux-mm@kvack.org" , "dan.j.williams@intel.com" CC: "linux-kernel@vger.kernel.org" , "akpm@linux-foundation.org" , "mhocko@kernel.org" , "adobriyan@gmail.com" , "hch@lst.de" , "longman@redhat.com" , "sfr@canb.auug.org.au" , "mst@redhat.com" , Naoya Horiguchi , Junichi Nomura , Toshiki Fukasawa Subject: [RFC PATCH v2] mm: initialize struct pages reserved by ZONE_DEVICE driver. Thread-Topic: [RFC PATCH v2] mm: initialize struct pages reserved by ZONE_DEVICE driver. Thread-Index: AQHVZIp2xk1cU6nEkk+ez7kL5reVFA== Date: Fri, 6 Sep 2019 08:09:52 +0000 Message-ID: <20190906081027.15477-1-t-fukasawa@vx.jp.nec.com> Accept-Language: ja-JP, en-US Content-Language: ja-JP X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.34.125.135] MIME-Version: 1.0 X-TM-AS-MML: disable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: A kernel panic is observed during reading /proc/kpage{cgroup,count,flags} for first few pfns allocated by pmem namespace: BUG: unable to handle page fault for address: fffffffffffffffe [ 114.495280] #PF: supervisor read access in kernel mode [ 114.495738] #PF: error_code(0x0000) - not-present page [ 114.496203] PGD 17120e067 P4D 17120e067 PUD 171210067 PMD 0 [ 114.496713] Oops: 0000 [#1] SMP PTI [ 114.497037] CPU: 9 PID: 1202 Comm: page-types Not tainted 5.3.0-rc1 [ 114.497621] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.11.0-0-g63451fca13-prebuilt.qemu-project.org 04/01/2014 [ 114.498706] RIP: 0010:stable_page_flags+0x27/0x3f0 [ 114.499142] Code: 82 66 90 66 66 66 66 90 48 85 ff 0f 84 d1 03 00 00 41 54 55 48 89 fd 53 48 8b 57 08 48 8b 1f 48 8d 42 ff 83 e2 01 48 0f 44 c7 <48> 8b 00 f6 c4 02 0f 84 57 03 00 00 45 31 e4 48 8b 55 08 48 89 ef [ 114.500788] RSP: 0018:ffffa5e601a0fe60 EFLAGS: 00010202 [ 114.501373] RAX: fffffffffffffffe RBX: ffffffffffffffff RCX: 0000000000000000 [ 114.502009] RDX: 0000000000000001 RSI: 00007ffca13a7310 RDI: ffffd07489000000 [ 114.502637] RBP: ffffd07489000000 R08: 0000000000000001 R09: 0000000000000000 [ 114.503270] R10: 0000000000000000 R11: 0000000000000000 R12: 0000000000240000 [ 114.503896] R13: 0000000000080000 R14: 00007ffca13a7310 R15: ffffa5e601a0ff08 [ 114.504530] FS: 00007f0266c7f540(0000) GS:ffff962dbbac0000(0000) knlGS:0000000000000000 [ 114.505245] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 114.505754] CR2: fffffffffffffffe CR3: 000000023a204000 CR4: 00000000000006e0 [ 114.506401] Call Trace: [ 114.506660] kpageflags_read+0xb1/0x130 [ 114.507051] proc_reg_read+0x39/0x60 [ 114.507387] vfs_read+0x8a/0x140 [ 114.507686] ksys_pread64+0x61/0xa0 [ 114.508021] do_syscall_64+0x5f/0x1a0 [ 114.508372] entry_SYSCALL_64_after_hwframe+0x44/0xa9 [ 114.508844] RIP: 0033:0x7f0266ba426b The first few pages of ZONE_DEVICE expressed as the range (altmap->base_pfn) to (altmap->base_pfn + altmap->reserve) are skipped by struct page initialization. Some pfn walkers like /proc/kpage{cgroup, count, flags} can't handle these uninitialized struct pages, which causes the error. In previous discussion, Dan seemed to have concern that the struct page area of some pages indicated by vmem_altmap->reserve may not be allocated. (See https://lore.kernel.org/lkml/CAPcyv4i5FjTOnPbXNcTzvt+e6RQYow0JRQwSFuxaa62LSuvzHQ@mail.gmail.com/) However, arch_add_memory() called by devm_memremap_pages() allocates struct page area for pages containing addresses in the range (res.start) to (res.start + resource_size(res)), which include the pages indicated by vmem_altmap->reserve. If I read correctly, it is allocated as requested at least on x86_64. Also, memmap_init_zone() initializes struct pages in the same range. So I think the struct pages should be initialized. Signed-off-by: Toshiki Fukasawa Cc: stable@vger.kernel.org --- Changes since rev 1: Instead of avoiding uninitialized pages on the pfn walker side, we initialize struct pages. mm/page_alloc.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 9c91949..6d180ae 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -5846,8 +5846,7 @@ void __meminit memmap_init_zone(unsigned long size, int nid, unsigned long zone, #ifdef CONFIG_ZONE_DEVICE /* - * Honor reservation requested by the driver for this ZONE_DEVICE - * memory. We limit the total number of pages to initialize to just + * We limit the total number of pages to initialize to just * those that might contain the memory mapping. We will defer the * ZONE_DEVICE page initialization until after we have released * the hotplug lock. @@ -5856,8 +5855,6 @@ void __meminit memmap_init_zone(unsigned long size, int nid, unsigned long zone, if (!altmap) return; - if (start_pfn == altmap->base_pfn) - start_pfn += altmap->reserve; end_pfn = altmap->base_pfn + vmem_altmap_offset(altmap); } #endif