Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2595326yba; Sun, 7 Apr 2019 23:58:17 -0700 (PDT) X-Google-Smtp-Source: APXvYqwYpONGwjUKrK6upLS62uOWEbRhuhdU/2Fqhad4gJiFgXBX26F2VVzOXi5I9VwcBFkPzmEh X-Received: by 2002:a63:7e10:: with SMTP id z16mr20075747pgc.40.1554706697469; Sun, 07 Apr 2019 23:58:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554706697; cv=none; d=google.com; s=arc-20160816; b=uv/pOsfyJpITD1/kIASOcQGCLmg3hzhn310+g/0KYATw1ZaHM8W6ctlQ63ih56jRww q9cXJnDHfCXSMhptfJWemyq7Qm/TuILxseMptpd/G+pVgYHv/d4Nxi+TOCWhxkm7aou2 6QigzerxdvMYoKboxQB+aIXLuqnJKLkvQhxQJ/MQkzC1og9KyoIjFubg0ri1kABllZZb fF4/+dA+F2lM7nQ8Svrr+BoZX3CJTYGtV7ngU/bCmeWFMGS2ilgrP7et5ipHbM1j0Z3W SlIa8PhMeV971jhKTa4Td1yracPpyhC6am8ljCRDVgupMCTkhMXk41AZEg9qnu+Kef4l m87w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:user-agent:in-reply-to :content-disposition:mime-version:references:subject:cc:to:from:date; bh=JX4NsSEWMKIZq8QXWZQA15wAIG4xjcde0E0JzTiwd0k=; b=EMETAEsjnBJdLpEQhQQTY3p6h7kelC2oW7Qez25oI5YsfNSNCbaQeaaY6yiFbPhFKB Ole2hFjsVgiZHZXs8BYPEp1309rldyDe368ELMY13E5gVbzaMa+lOPJ6R4Fa2tCEWwQc 9lbVJzJgx9lxvTf63o0jnBWTLI720ZzQ9xn4Yn56Rhjhhucv7dVbUZIddjxNwpyJ7Yez 5/Ps96YdiOwTvZAyp80NgxQqMNyPDNU5AaOFPGVC0V7wO7Rq3vT7xjgjyw2jis+l/z1m netaHbVDVVdrO/now9soeVtNSSzjaWQTijS/ce6Mq86dxOsAml0TYDsoH80HDTYQDr9s BvRQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x4si25205729plr.406.2019.04.07.23.58.02; Sun, 07 Apr 2019 23:58:17 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726253AbfDHG51 (ORCPT + 99 others); Mon, 8 Apr 2019 02:57:27 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:46884 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725854AbfDHG51 (ORCPT ); Mon, 8 Apr 2019 02:57:27 -0400 Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x386n87W101022 for ; Mon, 8 Apr 2019 02:57:25 -0400 Received: from e06smtp07.uk.ibm.com (e06smtp07.uk.ibm.com [195.75.94.103]) by mx0a-001b2d01.pphosted.com with ESMTP id 2rr0a53emt-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 08 Apr 2019 02:57:25 -0400 Received: from localhost by e06smtp07.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 8 Apr 2019 07:57:23 +0100 Received: from b06cxnps3075.portsmouth.uk.ibm.com (9.149.109.195) by e06smtp07.uk.ibm.com (192.168.101.137) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Mon, 8 Apr 2019 07:57:17 +0100 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x386vGwj61669536 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 8 Apr 2019 06:57:16 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B39554C052; Mon, 8 Apr 2019 06:57:16 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7B0BD4C04E; Mon, 8 Apr 2019 06:57:14 +0000 (GMT) Received: from rapoport-lnx (unknown [9.148.206.109]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTPS; Mon, 8 Apr 2019 06:57:14 +0000 (GMT) Date: Mon, 8 Apr 2019 09:57:12 +0300 From: Mike Rapoport To: Chen Zhou Cc: catalin.marinas@arm.com, will.deacon@arm.com, akpm@linux-foundation.org, ard.biesheuvel@linaro.org, takahiro.akashi@linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kexec@lists.infradead.org, linux-mm@kvack.org, wangkefeng.wang@huawei.com Subject: Re: [PATCH 2/3] arm64: kdump: support more than one crash kernel regions References: <20190403030546.23718-1-chenzhou10@huawei.com> <20190403030546.23718-3-chenzhou10@huawei.com> <20190403112929.GA7715@rapoport-lnx> <20190404144408.GA6433@rapoport-lnx> <783b8712-ddb1-a52b-81ee-0c6a216e5b7d@huawei.com> <4b188535-c12d-e05b-9154-2c2d580f903b@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4b188535-c12d-e05b-9154-2c2d580f903b@huawei.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-TM-AS-GCONF: 00 x-cbid: 19040806-0028-0000-0000-0000035E5F11 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19040806-0029-0000-0000-0000241D77B5 Message-Id: <20190408065711.GA8403@rapoport-lnx> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-04-08_04:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1904080064 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On Fri, Apr 05, 2019 at 11:47:27AM +0800, Chen Zhou wrote: > Hi Mike, > > On 2019/4/5 10:17, Chen Zhou wrote: > > Hi Mike, > > > > On 2019/4/4 22:44, Mike Rapoport wrote: > >> Hi, > >> > >> On Wed, Apr 03, 2019 at 09:51:27PM +0800, Chen Zhou wrote: > >>> Hi Mike, > >>> > >>> On 2019/4/3 19:29, Mike Rapoport wrote: > >>>> On Wed, Apr 03, 2019 at 11:05:45AM +0800, Chen Zhou wrote: > >>>>> After commit (arm64: kdump: support reserving crashkernel above 4G), > >>>>> there may be two crash kernel regions, one is below 4G, the other is > >>>>> above 4G. > >>>>> > >>>>> Crash dump kernel reads more than one crash kernel regions via a dtb > >>>>> property under node /chosen, > >>>>> linux,usable-memory-range = > >>>>> > >>>>> Signed-off-by: Chen Zhou > >>>>> --- > >>>>> arch/arm64/mm/init.c | 37 +++++++++++++++++++++++++------------ > >>>>> include/linux/memblock.h | 1 + > >>>>> mm/memblock.c | 40 ++++++++++++++++++++++++++++++++++++++++ > >>>>> 3 files changed, 66 insertions(+), 12 deletions(-) > >>>>> > >>>>> diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c > >>>>> index ceb2a25..769c77a 100644 > >>>>> --- a/arch/arm64/mm/init.c > >>>>> +++ b/arch/arm64/mm/init.c > >>>>> @@ -64,6 +64,8 @@ EXPORT_SYMBOL(memstart_addr); > >>>>> phys_addr_t arm64_dma_phys_limit __ro_after_init; > >>>>> > >>>>> #ifdef CONFIG_KEXEC_CORE > >>>>> +# define CRASH_MAX_USABLE_RANGES 2 > >>>>> + > >>>>> static int __init reserve_crashkernel_low(void) > >>>>> { > >>>>> unsigned long long base, low_base = 0, low_size = 0; > >>>>> @@ -346,8 +348,8 @@ static int __init early_init_dt_scan_usablemem(unsigned long node, > >>>>> const char *uname, int depth, void *data) > >>>>> { > >>>>> struct memblock_region *usablemem = data; > >>>>> - const __be32 *reg; > >>>>> - int len; > >>>>> + const __be32 *reg, *endp; > >>>>> + int len, nr = 0; > >>>>> > >>>>> if (depth != 1 || strcmp(uname, "chosen") != 0) > >>>>> return 0; > >>>>> @@ -356,22 +358,33 @@ static int __init early_init_dt_scan_usablemem(unsigned long node, > >>>>> if (!reg || (len < (dt_root_addr_cells + dt_root_size_cells))) > >>>>> return 1; > >>>>> > >>>>> - usablemem->base = dt_mem_next_cell(dt_root_addr_cells, ®); > >>>>> - usablemem->size = dt_mem_next_cell(dt_root_size_cells, ®); > >>>>> + endp = reg + (len / sizeof(__be32)); > >>>>> + while ((endp - reg) >= (dt_root_addr_cells + dt_root_size_cells)) { > >>>>> + usablemem[nr].base = dt_mem_next_cell(dt_root_addr_cells, ®); > >>>>> + usablemem[nr].size = dt_mem_next_cell(dt_root_size_cells, ®); > >>>>> + > >>>>> + if (++nr >= CRASH_MAX_USABLE_RANGES) > >>>>> + break; > >>>>> + } > >>>>> > >>>>> return 1; > >>>>> } > >>>>> > >>>>> static void __init fdt_enforce_memory_region(void) > >>>>> { > >>>>> - struct memblock_region reg = { > >>>>> - .size = 0, > >>>>> - }; > >>>>> - > >>>>> - of_scan_flat_dt(early_init_dt_scan_usablemem, ®); > >>>>> - > >>>>> - if (reg.size) > >>>>> - memblock_cap_memory_range(reg.base, reg.size); > >>>>> + int i, cnt = 0; > >>>>> + struct memblock_region regs[CRASH_MAX_USABLE_RANGES]; > >>>>> + > >>>>> + memset(regs, 0, sizeof(regs)); > >>>>> + of_scan_flat_dt(early_init_dt_scan_usablemem, regs); > >>>>> + > >>>>> + for (i = 0; i < CRASH_MAX_USABLE_RANGES; i++) > >>>>> + if (regs[i].size) > >>>>> + cnt++; > >>>>> + else > >>>>> + break; > >>>>> + if (cnt) > >>>>> + memblock_cap_memory_ranges(regs, cnt); > >>>> > >>>> Why not simply call memblock_cap_memory_range() for each region? > >>> > >>> Function memblock_cap_memory_range() removes all memory type ranges except specified range. > >>> So if we call memblock_cap_memory_range() for each region simply, there will be no usable-memory > >>> on kdump capture kernel. > >> > >> Thanks for the clarification. > >> I still think that memblock_cap_memory_ranges() is overly complex. > >> > >> How about doing something like this: > >> > >> Cap the memory range for [min(regs[*].start, max(regs[*].end)] and then > >> removing the range in the middle? > > > > Yes, that would be ok. But that would do one more memblock_cap_memory_range operation. > > That is, if there are n regions, we need to do (n + 1) operations, which doesn't seem to > > matter. > > > > I agree with you, your idea is better. > > > > Thanks, > > Chen Zhou > > Sorry, just ignore my previous reply, I got that wrong. > > I think it carefully, we can cap the memory range for [min(regs[*].start, max(regs[*].end)] > firstly. But how to remove the middle ranges, we still can't use memblock_cap_memory_range() > directly and the extra remove operation may be complex. > > For more than one regions, i think add a new memblock_cap_memory_ranges() may be better. > Besides, memblock_cap_memory_ranges() is also applicable for one region. > > How about replace memblock_cap_memory_range() with memblock_cap_memory_ranges()? arm64 is the only user of both MEMBLOCK_NOMAP and memblock_cap_memory_range() and I don't expect other architectures will use these interfaces. It seems that capping the memory for arm64 crash kernel the way I've suggested can be implemented in fdt_enforce_memory_region(). If we'd ever need such functionality elsewhere or CRASH_MAX_USABLE_RANGES will need to grow we'll rethink the solution. > Thanks, > Chen Zhou -- Sincerely yours, Mike.