Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp3267824yba; Sun, 28 Apr 2019 22:05:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqyNHDcZxw6Y1tt+oacliXptGZmNT7qvKREDlrn138pP4tG0SJjiwIHxlCx5qtm/lqm7kzY3 X-Received: by 2002:aa7:8a92:: with SMTP id a18mr61755738pfc.218.1556514345711; Sun, 28 Apr 2019 22:05:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556514345; cv=none; d=google.com; s=arc-20160816; b=Bs9B41kwnZ21QXgefOX3xmShDwkId50hjOHkXrncifu2M9KRTmqYu6FDzp3+2Vx596 ToowsINGWfeRpOWtmF2f4K/8PMfNriGfGyBMypv6EZinrMKkx6T/owdrB1jDpvIuzZTU CigN+xxOi/PQ70goYhibChccdW4AyQuYdQJhapE+Rl8xtIUD8yq8Fvdj/UwUJs5mq1GK bouaZzRAEd+Bh2E4aaJshOG8mcZ/zlmq4x05oBaOB17jA3hKDKKHyW4pbBENDQJ7kM7F GLN0Y7vVnrgTQCOfCeURj0iNv4R6e+RmH0kvuG9dzdNrfrpstS5DPgrnZy1gKzVk0D+P Vf1g== 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; bh=1aCdAQ+PbwoetGJTyIjvDNAuBuxsXyFmkshpNNhDcmI=; b=lmxHTN4sTMqfxSZbXvHOnXEiho806tkP/RwTu0Ha8wlGOQgUG3G11n60lhdmyCDlB6 Ar2Zgc2Tcc5OXfcpgblPsKun/Qw1uS5ks0hsSHNNOnncE4XxoWXKcYqDz7BzuMalGxTc ZNP8XJRB2kFlpI0HDeUs31DUpxqzOOhNJyrRHG8Ocg8bQGL0FZ+Wz04tioSvaXd4csYp kigwRodi14J2Y7ruO1o5nj9n6sR8b42CJ/HzVXMrapAWKnNxelNZdS6Rm87IQ0/uRfaQ 0yK/bwC3mPmgSr8y1zNb2QCa/btNFe0fmBjarsMer5qoz73csR6sY2gcaPvFwngfdmGr gGOQ== 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r5si29588682pgp.29.2019.04.28.22.05.29; Sun, 28 Apr 2019 22:05:45 -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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726671AbfD2FEh (ORCPT + 99 others); Mon, 29 Apr 2019 01:04:37 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59392 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725468AbfD2FEg (ORCPT ); Mon, 29 Apr 2019 01:04:36 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 77A4D81F0F; Mon, 29 Apr 2019 05:04:34 +0000 (UTC) Received: from dhcp-128-65.nay.redhat.com (ovpn-12-135.pek2.redhat.com [10.72.12.135]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3A98F1001DF6; Mon, 29 Apr 2019 05:04:14 +0000 (UTC) Date: Mon, 29 Apr 2019 13:04:10 +0800 From: Dave Young To: Pingfan Liu Cc: Matthias Brugger , LKML , Rich Felker , linux-ia64@vger.kernel.org, Julien Thierry , Yangtao Li , Benjamin Herrenschmidt , Palmer Dabbelt , Heiko Carstens , x86@kernel.org, linux-mips@vger.kernel.org, Paul Mackerras , "H. Peter Anvin" , linux-s390@vger.kernel.org, Florian Fainelli , Yoshinori Sato , linux-sh@vger.kernel.org, Michael Ellerman , David Hildenbrand , Russell King , Ingo Molnar , linux-arm-kernel@lists.infradead.org, Catalin Marinas , James Hogan , Fenghua Yu , Will Deacon , linuxppc-dev@lists.ozlabs.org, Ananth N Mavinakayanahalli , Borislav Petkov , Stefan Agner , Thomas Gleixner , Hari Bathini , Jens Axboe , Tony Luck , Baoquan He , Ard Biesheuvel , Robin Murphy , Greg Kroah-Hartman , Ralf Baechle , Thomas Bogendoerfer , Paul Burton , Johannes Weiner , Martin Schwidefsky , Andrew Morton , Logan Gunthorpe , Greg Hackmann , kexec@lists.infradead.org Subject: Re: [PATCHv2] kernel/crash: make parse_crashkernel()'s return value more indicant Message-ID: <20190429050410.GA7982@dhcp-128-65.nay.redhat.com> References: <1556087581-14513-1-git-send-email-kernelfans@gmail.com> <10dc5468-6cd9-85c7-ba66-1dfa5aa922b7@suse.com> <20190428083710.GA11981@dhcp-128-65.nay.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.11.3 (2019-02-01) X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Mon, 29 Apr 2019 05:04:35 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 04/29/19 at 12:48pm, Pingfan Liu wrote: > On Mon, Apr 29, 2019 at 11:04 AM Pingfan Liu wrote: > > > > On Sun, Apr 28, 2019 at 4:37 PM Dave Young wrote: > > > > > > On 04/25/19 at 04:20pm, Pingfan Liu wrote: > > > > On Wed, Apr 24, 2019 at 4:31 PM Matthias Brugger wrote: > > > > > > > > > > > > > > [...] > > > > > > @@ -139,6 +141,8 @@ static int __init parse_crashkernel_simple(char *cmdline, > > > > > > pr_warn("crashkernel: unrecognized char: %c\n", *cur); > > > > > > return -EINVAL; > > > > > > } > > > > > > + if (*crash_size == 0) > > > > > > + return -EINVAL; > > > > > > > > > > This covers the case where I pass an argument like "crashkernel=0M" ? > > > > > Can't we fix that by using kstrtoull() in memparse and check if the return value > > > > > is < 0? In that case we could return without updating the retptr and we will be > > > > > fine. > > > > > > > > > It seems that kstrtoull() treats 0M as invalid parameter, while > > > > simple_strtoull() does not. > > > > > > > > If changed like your suggestion, then all the callers of memparse() > > > > will treats 0M as invalid parameter. This affects many components > > > > besides kexec. Not sure this can be done or not. > > > > > > simple_strtoull is obsolete, move to kstrtoull is the right way. > > > > > > $ git grep memparse|wc > > > 158 950 10479 > > > > > > Except some documentation/tools etc there are still a log of callers > > > which directly use the return value as the ull number without error > > > checking. > > > > > > So it would be good to mark memparse as obsolete as well in > > > lib/cmdline.c, and introduce a new function eg. kmemparse() to use > > > kstrtoull, and return a real error code, and save the size in an > > > argument like &size. Then update X86 crashkernel code to use it. > > > > > Thank for your good suggestion. > > > Go through the v5.0 kernel code, I think it will be a huge job. > > The difference between unsigned long long simple_strtoull(const char > *cp, char **endp, unsigned int base) and int _kstrtoull(const char *s, > unsigned int base, unsigned long long *res) is bigger than expected, > especially the output parameter @res. Many references to > memparse(const char *ptr, char **retptr) rely on @retptr to work. A > typical example from arch/x86/kernel/e820.c > mem_size = memparse(p, &p); > if (p == oldp) > return -EINVAL; > > userdef = 1; > if (*p == '@') { <----------- here > start_at = memparse(p+1, &p); > e820__range_add(start_at, mem_size, E820_TYPE_RAM); > } else if (*p == '#') { > start_at = memparse(p+1, &p); > e820__range_add(start_at, mem_size, E820_TYPE_ACPI); > } else if (*p == '$') { > start_at = memparse(p+1, &p); > e820__range_add(start_at, mem_size, E820_TYPE_RESERVED); > } > > So we need to resolve the prototype of kstrtoull() firstly, and maybe > kstrtouint() etc too. All of them have lots of references in kernel. > > Any idea about this? Not only this place, a lot of other places, I think no hurry to fix them all at one time. As we talked just do it according to previous reply, mark memparse as obsolete, and create a new function to use kstrtoull, and make it used in crashkernel code first. Thanks Dave