Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp481109ybm; Wed, 22 May 2019 06:35:44 -0700 (PDT) X-Google-Smtp-Source: APXvYqwdDCMspcG78LRQPNgm+9Ib+SuYg5M1QEGtngUcxDKhTF3w7/+96SOX8yTmGOrVxk9IHokz X-Received: by 2002:a63:5014:: with SMTP id e20mr88675868pgb.2.1558532144781; Wed, 22 May 2019 06:35:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558532144; cv=none; d=google.com; s=arc-20160816; b=M08ZIiHC9hoS+UnH9ge4UB8IcT0dKiIpFOuViyBKl3wLlDuJA7qTDJ9Bcb7mpakTDD M8qkASIzRJdbujNhZwwldv120RmUGH096jrjHwIUwSh+wDLNZnlR1UDT1trZZVTRYqYf QZJy3tmsfWR0YXYVugLg1S0mHstafoOl9JECkrN/UmHQGEO12+x9v1n3BWQLUfPFbuGf FMcbR7YDa0eIGm6Nj8JvTt6SzFU6dRk+8tEVb1AM/wePRx47gjiDVgQFaATp5g8THJdR fYxf1fMcIC3c7NA0Qr1toi+mk1OPQMCR1TEe2a50tcEFUVEpeeYnslcKETcjCGXhc8KD kNEA== 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=14QlJRJWq59KvU1Q1jnmbY57wwH1e/15veo4ydyj84A=; b=B2LIlzhvQR3N1zHXOFoWZsbL7qJ0GDFuN51f6dddtEtKd4fY5dghuopC2ER3+nGPMP vurTzFU0uz3qNK73Pwmg29MGQx14xDENXNyMxFEJrBZhkEZyu6YE899jXTcukfYmHxCs rA0eMFXul0WVTeTUl7RH47G2+IrVeZB7oJy40YpsL5dV1ZactAeYbnOM9SW67L4CyEo4 oVqxvkR66zOVIlyrYkA3I9CE0tL4vtYLeEO3PX34WEXyHLNbz5bxA73ib+sW0c7pOyDV HdeR75D528ySbUWHbHH/7P3EA30G3B8zZxL8YafM+jOy+dJTRWym1jQ+WLwZx1kg7Gxv 283w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ANWmTjXE; 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 f14si26530523pln.71.2019.05.22.06.35.29; Wed, 22 May 2019 06:35:44 -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=ANWmTjXE; 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 S1729424AbfEVNeO (ORCPT + 99 others); Wed, 22 May 2019 09:34:14 -0400 Received: from mail-lj1-f196.google.com ([209.85.208.196]:32824 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727975AbfEVNeN (ORCPT ); Wed, 22 May 2019 09:34:13 -0400 Received: by mail-lj1-f196.google.com with SMTP id w1so2140024ljw.0; Wed, 22 May 2019 06:34:11 -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=14QlJRJWq59KvU1Q1jnmbY57wwH1e/15veo4ydyj84A=; b=ANWmTjXEV7vN5ajAq35aQmfEnGb1lfHDTKS9vcAfD7TqDmiPMKGmFHDpu8SfXJYXq8 P1zclsfr0+W2tMYsQgHLynYBe5GXBKdEJGu29wCdW1IM2XAWmoiBVd3fKV5/fVhy9Jj3 wcrWrFnW/T2urGVTL2RrhN54W1g08Eax+h2f5Yapc7/LczXL9Ef/4TZmPNSRGyxC4tpw Gc5iUxd79nA/y6Pi1nYcYfM62awXNmUJv6ag6W1xWfWP077Jhw5PbvdH0XNL0r3SrpNl TYgfY3SDqqFd01Mikcndfyo2UMlz+hqtdHhvshSpdx4AD1H4SZ6mQLaKiCt3yFOpoW4/ C6aA== 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=14QlJRJWq59KvU1Q1jnmbY57wwH1e/15veo4ydyj84A=; b=qnPxDK8xHS/rIMwzFf+gzp1tMoL5n/C1sZ/Z2nwes9hq/o0mFDQiJq9oSBI4b1tiQS S/a6iUvMwpicawGpPrxRdcWHhe+c4atJhS0Uf3YHOnbBH8UtRvqYPmYF3LnH3cd8rn3m DITQS2ZTLBWVYyu96gdFKjCFcTHCfpTK5y4XBW8GOTNXPIWtgaGZKaszFVzPzUsPGTNQ tH0Ai3s/KlBqb6PFhhjXHgyjafvw4RKy2QtGzGxlmihYlmzqC1u1NUP/20sKLpFLWFj5 S4B33Od+sqbXEMrISVwpaVqARQ5X/mR/T9rplmCa5lPrLA4gSo2ZEv+n/jjCYFeMSSfT H94w== X-Gm-Message-State: APjAAAUELRJUZRbwA2Zv4Tt/wiqD8rivsml9ssrueF6U1IIfASbpCMp1 NAHxdBXg3CS15Y5Y5j6mM4gt8H0mEVw= X-Received: by 2002:a2e:9b46:: with SMTP id o6mr7891853ljj.76.1558532050686; Wed, 22 May 2019 06:34:10 -0700 (PDT) Received: from mobilestation ([83.220.237.191]) by smtp.gmail.com with ESMTPSA id j14sm5496504lfb.76.2019.05.22.06.34.08 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 22 May 2019 06:34:09 -0700 (PDT) Date: Wed, 22 May 2019 16:34:04 +0300 From: Serge Semin To: Geert Uytterhoeven Cc: Mike Rapoport , Ralf Baechle , Paul Burton , James Hogan , 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 , "Maciej W. Rozycki" Subject: Re: [PATCH 04/12] mips: Reserve memory for the kernel image resources Message-ID: <20190522133402.duhybxf66oubx6ng@mobilestation> References: <20190423224748.3765-1-fancer.lancer@gmail.com> <20190423224748.3765-5-fancer.lancer@gmail.com> <20190521155309.GB24470@rapoport-lnx> <20190522080802.GA31930@rapoport-lnx> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20180716 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello folks, On Wed, May 22, 2019 at 10:14:47AM +0200, Geert Uytterhoeven wrote: > Hi Mike, > > On Wed, May 22, 2019 at 10:08 AM Mike Rapoport wrote: > > On Wed, May 22, 2019 at 09:47:04AM +0200, Geert Uytterhoeven wrote: > > > On Tue, May 21, 2019 at 5:53 PM Mike Rapoport wrote: > > > > On Tue, May 21, 2019 at 04:56:39PM +0200, Geert Uytterhoeven wrote: > > > > > 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 > > > > > [...] > > > > > > > > > > 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 > > > > > > 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. > > > > > > Yes, by prom_free_prom_memory(), as pointed out by Serge. > > > > I wonder how other MIPS variants would react to the fact that the memory > > below the kernel is not reserved ;-) > > Exactly... > > Looks like at least arch/mips/dec/prom/memory.c needs a similar but\ > more complicated fix, due to declance handling... > The problem might be fixed there by the next patch: --- diff --git a/arch/mips/dec/prom/memory.c b/arch/mips/dec/prom/memory.c index 5073d2ed78bb..5a0c734b5d04 100644 --- a/arch/mips/dec/prom/memory.c +++ b/arch/mips/dec/prom/memory.c @@ -91,29 +91,14 @@ void __init prom_meminit(u32 magic) pmax_setup_memory_region(); else rex_setup_memory_region(); -} - -void __init prom_free_prom_memory(void) -{ - unsigned long end; - - /* - * Free everything below the kernel itself but leave - * the first page reserved for the exception handlers. - */ #if IS_ENABLED(CONFIG_DECLANCE) /* - * Leave 128 KB reserved for Lance memory for - * IOASIC DECstations. + * Reserve 128 KB for Lance memory for IOASIC DECstations. * * XXX: save this address for use in dec_lance.c? */ if (IOASIC) - end = __pa(&_text) - 0x00020000; - else + memblock_reserve(__pa_symbol(&_text), 0x00020000); #endif - end = __pa(&_text); - - free_init_pages("unused PROM memory", PAGE_SIZE, end); } --- Didn't wanna use prom_FREE_prom_memory to actually reserve a memory chunk, so I moved the reservation into the prom_meminit() method. Regarding the first page for the exception handlers. We don't need to reserve it here, since it is already done in arch/mips/kernel/traps.c . Regards, -Sergey > > 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