Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp1172582ybm; Tue, 21 May 2019 09:41:26 -0700 (PDT) X-Google-Smtp-Source: APXvYqwgkv0nCikOAF+jPwq4+DY/eUW9gDhkzpRMkO2mDzLb2wt6858DvJuUJufE5iGPs5wye2ry X-Received: by 2002:a63:7909:: with SMTP id u9mr77311829pgc.223.1558456886137; Tue, 21 May 2019 09:41:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558456886; cv=none; d=google.com; s=arc-20160816; b=ahrGQhvGtdR7osOBbH5cprUZHWp9uOQuhy4iKPI+7gTD4G6UJRXRPHHmCIBoGF251C zhTbkLAKHx09N16RPFV7ayripl8Cfr9rcNLWcZcvX3c3BBNisTGBGWO8PZfzMaJeimlF 6Xwncuq8pI5aE9DNiXZzuM58RJUor5euFh+NE+2BrCAAGm78ANdpV1xqeP7VkilQFdzx 4NFyVGLn33r5p8AYmoOAUiPcs2f0kO71qESIyi3P9mG7TUhENpNUX0x2+WVDQhHIYCJl 94Bt04Id9hiogbIeKAUSwzUDAYwVwmLA+x6dslEciqhjHNSKXaWFWaWubWKe4+XkM/Sb y4qQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=ZevjsTq/5oCWSC9Ugeppy6ZBh126nny81ksWozxVUrk=; b=S/xGIrpDq/Mx0H0nDiyEv86NGEnKAkqVQ5eLhdAVohu4YSpe00lGhihPgJloXyUD+3 fwum3R++BjznCXABgxL9OkIVaro6b65fT35Rc1OJIU8Vwtv88qruxQ/E4sMUt+LTAXio ulh9BxLL2y3BKP7TwRNXyF5XNrgYYgKZIBXBANOkKkH3gWAOlsps6USrkP7F6FcjHYVx UY8M2BqrlvdGDY6HQp/Ds/WONomu/siqKI1pomw0yCsIrGQ5zAyIW5O4tzDu+aCIq0AL svdIiOtN19EajXpQw3lBoPUyWCM7Of7lT6B6XExKoh71sQ4Niu5JaQ4gEwKUXBgI4gt8 d6gw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=tvm1JOL0; 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=QUARANTINE 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 67si22533742plf.382.2019.05.21.09.41.10; Tue, 21 May 2019 09:41:26 -0700 (PDT) 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=tvm1JOL0; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728807AbfEUQjj (ORCPT + 99 others); Tue, 21 May 2019 12:39:39 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:43100 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727946AbfEUQji (ORCPT ); Tue, 21 May 2019 12:39:38 -0400 Received: by mail-wr1-f68.google.com with SMTP id r4so19358886wro.10; Tue, 21 May 2019 09:39:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=ZevjsTq/5oCWSC9Ugeppy6ZBh126nny81ksWozxVUrk=; b=tvm1JOL0YFWgJB2+atKjWCcbVwD4q5BDf1EVnyAQpEkMWlsQG4wtnp9tBwH7P2pfkV pnEPwkecXt/Q0zov15HYfF8O++JY9wNFfHixPe0cg3YD30/WZD47SCfzr20PiSlJL3Qz M0lPkOFuUa1JajSby9MlWGpRQqNgfI+gSCQnGyeO4PuJAkHjwcsULhw5qM2ZvUGcBfmo 2pXiHxZlTU7HvT2Ky3SDWlzGbEFy8CvY3fAJESkOshc2TcEMxxHktpX8ET0v6Ic5+kxz uqgredhrpIsMI6grhTL78lcyqcJkDr46KynQ32GPij15/sfqrmT5so3yW3f8iG83y8ZG cNYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=ZevjsTq/5oCWSC9Ugeppy6ZBh126nny81ksWozxVUrk=; b=GosShyVFW40h8Ky/7VGTIOOMgNBW8AU5dbESTL2vlMjWiG4O4iUdBDo3QKmAHVQ4R3 3gZJ/nSRTw0vh+mAOjq9KYQ4D/6pFAbmR9fJyuvyre3o5dsHE2pHgIpbEwKuGQla74n+ +fn57RcI23su+ItnRAY0ktbK97T3ztgdImEsZI30Rux8O69T2iNsk8I65fmEifiDolKy YX8Rgjp8A1Jmk+tBQFQtE1jDIWAwE0WHSR1YRVZk1Uac8qoyRZ1ELAQhNVkmt/srPItF 6gLBp6bMXrFx2+xhhOLfxd7PxMPs+da4yRrXL2peN6hK84Dc9dsPgGJA3taWwIBGyxa5 Maww== X-Gm-Message-State: APjAAAVi1BbWxn1y1VbH5UBZYgUpMqmrOCXf9TWOVpJFyJmpoSU8t7wO R+IzdYpAKUo6jekD5/9/Ukw= X-Received: by 2002:adf:94a5:: with SMTP id 34mr52115482wrr.275.1558456776368; Tue, 21 May 2019 09:39:36 -0700 (PDT) Received: from mobilestation ([31.13.144.82]) by smtp.gmail.com with ESMTPSA id w13sm3560134wmk.0.2019.05.21.09.39.32 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 21 May 2019 09:39:35 -0700 (PDT) Date: Tue, 21 May 2019 19:39:30 +0300 From: Serge Semin To: Mike Rapoport Cc: Geert Uytterhoeven , Ralf Baechle , Paul Burton , James Hogan , Matt Redfearn , Andrew Morton , Michal Hocko , Greg Kroah-Hartman , Thomas Bogendoerfer , Huacai Chen , Stefan Agner , Stephen Rothwell , Alexandre Belloni , Juergen Gross , linux-mips@vger.kernel.org, Linux Kernel Mailing List , Atsushi Nemoto Subject: Re: [PATCH 04/12] mips: Reserve memory for the kernel image resources Message-ID: <20190521163928.yo75uskjachtw2nt@mobilestation> References: <20190423224748.3765-1-fancer.lancer@gmail.com> <20190423224748.3765-5-fancer.lancer@gmail.com> <20190521155309.GB24470@rapoport-lnx> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190521155309.GB24470@rapoport-lnx> User-Agent: NeoMutt/20180716 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello Geert, Mike On Tue, May 21, 2019 at 06:53:10PM +0300, Mike Rapoport wrote: > Hi Geert, > > On Tue, May 21, 2019 at 04:56:39PM +0200, Geert Uytterhoeven wrote: > > Hi Serge, > > > > On Wed, Apr 24, 2019 at 12:50 AM Serge Semin wrote: > > > The reserved_end variable had been used by the bootmem_init() code > > > to find a lowest limit of memory available for memmap blob. The original > > > code just tried to find a free memory space higher than kernel was placed. > > > This limitation seems justified for the memmap ragion search process, but > > > I can't see any obvious reason to reserve the unused space below kernel > > > seeing some platforms place it much higher than standard 1MB. Moreover > > > the RELOCATION config enables it to be loaded at any memory address. > > > So lets reserve the memory occupied by the kernel only, leaving the region > > > below being free for allocations. After doing this we can now discard the > > > code freeing a space between kernel _text and VMLINUX_LOAD_ADDRESS symbols > > > since it's going to be free anyway (unless marked as reserved by > > > platforms). > > > > > > Signed-off-by: Serge Semin > > > > This is now commit b93ddc4f9156205e ("mips: Reserve memory for the kernel > > image resources") in v5.2-rc1, which causes rbtx4927 to crash during boot: > > > > VFS: Mounted root (nfs filesystem) on device 0:13. > > devtmpfs: mounted > > BUG: Bad page state in process swapper pfn:00001 > > page:804b7820 refcount:0 mapcount:-128 mapping:00000000 index:0x1 > > flags: 0x0() > > raw: 00000000 00000100 00000200 00000000 00000001 00000000 ffffff7f 00000000 > > page dumped because: nonzero mapcount > > Modules linked in: > > CPU: 0 PID: 1 Comm: swapper Not tainted > > 5.2.0-rc1-rbtx4927-00468-g3c05ea3d4077b756-dirty #137 > > Stack : 00000000 10008400 8040dd2c 87c1b974 8044af63 8040dd2c > > 00000001 804a3490 > > 00000001 81000000 0030f231 80148558 00000003 10008400 > > 87c1dd80 7599ee13 > > 00000000 00000000 804b0000 00000000 00000007 00000000 > > 00000085 00000000 > > 62722d31 00000084 804b0000 39347874 00000000 804b7820 > > 8040cef8 81000010 > > 00000001 00000007 00000001 81000000 00000008 8021de24 > > 00000000 804a0000 > > ... > > Call Trace: > > [<8010adec>] show_stack+0x74/0x104 > > [<801a5e44>] bad_page+0x130/0x138 > > [<801a654c>] free_pcppages_bulk+0x17c/0x3b0 > > [<801a789c>] free_unref_page+0x40/0x68 > > [<801120f4>] free_init_pages+0xec/0x104 > > [<803bdde8>] free_initmem+0x10/0x58 > > [<803bdb8c>] kernel_init+0x20/0x100 > > [<801057c8>] ret_from_kernel_thread+0x14/0x1c > > Disabling lock debugging due to kernel taint > > BUG: Bad page state in process swapper pfn:00002 > > [...] > > The root cause of the problem most likely is in prom_free_prom_memory() method of arch/mips/txx9/generic/setup.c: void __init prom_free_prom_memory(void) { unsigned long saddr = PAGE_SIZE; unsigned long eaddr = __pa_symbol(&_text); if (saddr < eaddr) free_init_pages("prom memory", saddr, eaddr); } As you can see the txx9 platform tries to free a memory which isn't reserved and set free from the very beginning due to the patch above. So as soon as you remove the free_init_pages("prom memory", ...) the problem shall be fixed. Could you try it and send a result to us whether it helped? Regards, -Sergey > > CONFIG_RELOCATABLE is not set, so the only relevant part is the > > change quoted below. > > > > > --- a/arch/mips/kernel/setup.c > > > +++ b/arch/mips/kernel/setup.c > > > @@ -371,7 +371,6 @@ static void __init bootmem_init(void) > > > > > > static void __init bootmem_init(void) > > > { > > > - unsigned long reserved_end; > > > phys_addr_t ramstart = PHYS_ADDR_MAX; > > > int i; > > > > > > @@ -382,10 +381,10 @@ static void __init bootmem_init(void) > > > * will reserve the area used for the initrd. > > > */ > > > init_initrd(); > > > - reserved_end = (unsigned long) PFN_UP(__pa_symbol(&_end)); > > > > > > - memblock_reserve(PHYS_OFFSET, > > > - (reserved_end << PAGE_SHIFT) - PHYS_OFFSET); > > > + /* Reserve memory occupied by kernel. */ > > > + memblock_reserve(__pa_symbol(&_text), > > > + __pa_symbol(&_end) - __pa_symbol(&_text)); > > > > > > /* > > > * max_low_pfn is not a number of pages. The number of pages > > > > With some debug code added: > > > > Determined physical RAM map: > > memory: 08000000 @ 00000000 (usable) > > bootmem_init:390: PHYS_OFFSET = 0x0 > > bootmem_init:391: __pa_symbol(&_text) = 0x100000 > > bootmem_init:392: __pa_symbol(&_end) = 0x4b77c8 > > bootmem_init:393: PFN_UP(__pa_symbol(&_end)) = 0x4b8 > > Have you tried adding memblock=debug to the command line? > Not sure it'll help, but still :) > > > Hence the old code reserved 1 MiB extra at the beginning. > > > > Note that the new code also dropped the rounding up of the memory block > > size to a multiple of PAGE_SIZE. I'm not sure the latter actually > > matters or not. > > I'd say that bad page state for pfn 1 is caused by "freeing" the first 1M. > > > Do you have a clue? Thanks! > > > > Gr{oetje,eeting}s, > > > > Geert > > > > -- > > Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org > > > > In personal conversations with technical people, I call myself a hacker. But > > when I'm talking to journalists I just say "programmer" or something like that. > > -- Linus Torvalds > > > > -- > Sincerely yours, > Mike. >