Received: by 10.192.165.148 with SMTP id m20csp476551imm; Fri, 27 Apr 2018 02:11:23 -0700 (PDT) X-Google-Smtp-Source: AB8JxZq69lWd2jY+xXQePPsImoVVB9Fg0EKxwnZDP/GaFX+RJ8RrDdIiOceahJNsWxI8BO301luD X-Received: by 2002:a17:902:784c:: with SMTP id e12-v6mr1578503pln.60.1524820283779; Fri, 27 Apr 2018 02:11:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524820283; cv=none; d=google.com; s=arc-20160816; b=LY2l/vOJ7QGGZXzxurFu/a5QKef9/4da4JOqVN34ln42jMGBuqlJa2L0O1rJnWSYVt Su9oyztab8coayPQMIteJ3lHjuaPDlBhNc8Y11M993kfqt3hsQaXODtxl33cfTsU7aHE dAQLzHsvJnbZrATngoOVO+ZqDl2MyFOXyzrA1TssXgNLiAANd3d3pcFoRA4jp9T3KY2B osomEjN/gAbnID0DwUJpjbU7ckAs3cqBnodStyVXi1KyNsoLZx5KRhJMFK85o9vqHXkq HYdEqCdsZm+2V0sDLRwHQ5HFVpJu41wgjH2WWyqtR95boHuqghOlBufomFHZ6W96DAgF vaqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:subject:cc:to:from:date:user-agent:message-id :arc-authentication-results; bh=qdiNZvj+798lkVxMGhuTDcQ6N3DaA1DqKVT5Lt01Q4I=; b=peTuoCfM6i94FG2vEBtEqGkMBFICyW65OTLlWpb09/Bkp7DdbCaVpxWXlg89GtK7n0 MOdiW3231wJUN8woYjp7cqj97pRYnuBtC7lUbEfqtolktcYU0EBhm5i8uWfxxrxum2yO DGur6HI2lHgrwSc6X0cKrhIYYpGAeZYGJLcMzN/mrNeIXb8yE6dzFyR/6JnAspOCOUOl wo7QZLNOzLDpx4X0mM2lMc0jBf3zQOeMFOBcmjZC6MVav/lly4rCAGbrIJgfZe8UeS9v OhIDD45hjXxcGPZqHlEJM/+1xBNJsHYE7e45eU4rRHSTFEsq/8muUTk+7cPAK62qXpXU TBAw== 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 2-v6si914820pld.596.2018.04.27.02.11.07; Fri, 27 Apr 2018 02:11:23 -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 S932442AbeD0JJ5 (ORCPT + 99 others); Fri, 27 Apr 2018 05:09:57 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:52978 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932282AbeD0JJy (ORCPT ); Fri, 27 Apr 2018 05:09:54 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3EB33EC004; Fri, 27 Apr 2018 09:09:54 +0000 (UTC) Received: from localhost (ovpn-12-63.pek2.redhat.com [10.72.12.63]) by smtp.corp.redhat.com (Postfix) with ESMTP id 77214215CDCB; Fri, 27 Apr 2018 09:09:53 +0000 (UTC) X-Mailbox-Line: From dyoung@redhat.com Fri Apr 27 17:00:45 2018 Message-Id: <20180427090045.583830252@redhat.com> User-Agent: quilt/0.65 Date: Fri, 27 Apr 2018 17:00:38 +0800 From: dyoung@redhat.com To: kexec@lists.infradead.org, linux-kernel@vger.kernel.org Cc: bhe@redhat.com, yinghai@kernel.org, akpm@linux-foundation.org, dyoung@redhat.com, vgoyal@redhat.com Subject: [PATCH 2/2] kdump: round up the total memory size to 128M for crashkernel reservation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline; filename=kdump-crashkernel-roundup-total-mem.patch In-Reply-To: <20180427090045.532014306@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Fri, 27 Apr 2018 09:09:54 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Fri, 27 Apr 2018 09:09:54 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'dyoung@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The total memory size we get in kernel is usually slightly less than 2G with a 2G memory module machine. The main reason is bios/firmware reserve some area it will not export all memory as usable to Linux. 2G memory X86 kvm guest test result of the total_mem value: UEFI boot with ovmf: 0x7ef10000 Legacy boot kvm guest: 0x7ff7cc00 This is also a problem on arm64 UEFI booted system according to my test. Thus for example crashkernel=1G-2G:128M, if we have a 1G memory machine, we get total size 1023M from firmware then it will not fall into 1G-2G thus no memory reserved. User will never know that, it is hard to let user to know the exact total value we get in kernel An option is to use dmi/smbios to get physical memory size, but it's not reliable as well. According to Prarit hardware vendors sometimes screw this up. Thus round up total size to 128M to workaround this problem. Signed-off-by: Dave Young --- kernel/crash_core.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) --- linux-x86.orig/kernel/crash_core.c +++ linux-x86/kernel/crash_core.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -41,6 +42,15 @@ static int __init parse_crashkernel_mem( unsigned long long *crash_base) { char *cur = cmdline, *tmp; + unsigned long long total_mem = system_ram; + + /* + * Firmware sometimes reserves some memory regions for it's own use. + * so we get less than actual system memory size. + * Workaround this by round up the total size to 128M which is + * enough for most test cases. + */ + total_mem = roundup(total_mem, SZ_128M); /* for each entry of the comma-separated list */ do { @@ -85,13 +95,13 @@ static int __init parse_crashkernel_mem( return -EINVAL; } cur = tmp; - if (size >= system_ram) { + if (size >= total_mem) { pr_warn("crashkernel: invalid size\n"); return -EINVAL; } /* match ? */ - if (system_ram >= start && system_ram < end) { + if (total_mem >= start && total_mem < end) { *crash_size = size; break; }