Received: by 10.192.165.156 with SMTP id m28csp174178imm; Sun, 15 Apr 2018 20:11:35 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+8IgYP9EevM9RS4GO9S6tW/cm/UUDN1Be6N04cf2uiaq57+D5xFg2l1KFiZ1weid+mvBit X-Received: by 2002:a17:902:9881:: with SMTP id s1-v6mr13825769plp.350.1523848295277; Sun, 15 Apr 2018 20:11:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523848295; cv=none; d=google.com; s=arc-20160816; b=03bPm6epLXDx6bGkP8vMxS5mCIbV2a0505VIF82t+5OAETPTAGPDJRcKLxcL+W9B+Z g4/Nsx6xQxbIIbmSDhyvpND/kTZRamaC1VQe5SSxGfQhrrJ+n0IC66XcN98wsKmr8onk mc9sPRynEQWiTSfbb/vPpRJqWVxFNOCQi7YKVj9HjEiLFCgUHi+JdSw0Re5CA1bREPYt YZXHwvvCjwGstaIjYXOIdOP5aScdLN5oybOBFIg8UhgKrJEdtb4jcqgKr7i7ZN980kIQ DxNteOGEkHGYU7sV2yp+pa1fuymoauh8q7I5D5cnnYMMA21X8iAHH37UOiv/t3sBJFK9 khGg== 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:arc-authentication-results; bh=pK6S6D4g1mDB85M9BZAcFzYRJO0Fj0/FN3QVnxMY/HM=; b=s6aQ/gK0x24su1PvmoAKxqA5QXJqzsZ/CPplJ14EnQpDU3q25uYEFrMBGrc9tuWdMH UKtK7UHAVSS1wkIcjFKoT7HqrdZ5x3MJcF0YmrUA8M7ZQHPIdeBaOSeeybuuXVhKQqlS 6vfgQ6No0BtbnNkL5Ewida4kJq6MvmW7XLSkzHZ7qHjBEpeUSskBC6U0QeIW6cRx3lAK f5C/bDgHs+Ys6ItLJXP+c8huGDSwN67hfqtTp7Gz2WDuItwQmKj5ckHNtqslKmR0l4+x WbD1+9xK1cJzl6Wo0qB/6aKXB75ksXMXcdn4Fox8Be7u2AI/BDolli7zFus0j3d7ydrp Eiyw== 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 v140si8834132pgb.326.2018.04.15.20.10.58; Sun, 15 Apr 2018 20:11:35 -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 S1752775AbeDPDJQ (ORCPT + 99 others); Sun, 15 Apr 2018 23:09:16 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:55690 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752609AbeDPDJO (ORCPT ); Sun, 15 Apr 2018 23:09:14 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 248E0E44B5; Mon, 16 Apr 2018 03:09:14 +0000 (UTC) Received: from dhcp-128-65.nay.redhat.com (ovpn-12-42.pek2.redhat.com [10.72.12.42]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 811D1111DCF7; Mon, 16 Apr 2018 03:09:09 +0000 (UTC) Date: Mon, 16 Apr 2018 11:09:04 +0800 From: Dave Young To: "Lee, Chun-Yi" Cc: linux-efi@vger.kernel.org, Ard Biesheuvel , Takashi Iwai , kexec@lists.infradead.org, linux-kernel@vger.kernel.org, Randy Wright , "Lee, Chun-Yi" , Ingo Molnar , akpm@linux-foundation.org, Vivek Goyal Subject: Re: [PATCH] efi: Fix the size not consistent issue when unmapping memory map Message-ID: <20180416030904.GB26685@dhcp-128-65.nay.redhat.com> References: <20180413062716.8040-1-jlee@suse.com> <20180416025734.GA26685@dhcp-128-65.nay.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180416025734.GA26685@dhcp-128-65.nay.redhat.com> User-Agent: Mutt/1.9.1 (2017-09-22) X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Mon, 16 Apr 2018 03:09:14 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Mon, 16 Apr 2018 03:09:14 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.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 On 04/16/18 at 10:57am, Dave Young wrote: > On 04/13/18 at 02:27pm, Lee, Chun-Yi wrote: > > When using kdump, SOMETIMES the "size not consistent" warning message > > shows up when the crash kernel boots with early_ioremap_debug parameter: > > > > WARNING: CPU: 0 PID: 0 at ../mm/early_ioremap.c:182 early_iounmap+0x4f/0x12c() > > early_iounmap(ffffffffff200180, 00000118) [0] size not consistent 00000120 > > > > The root cause is that the unmapping size of memory map doesn't > > match with the original size when mapping: > > > > in __efi_memmap_init() > > map.map = early_memremap(phys_map, data->size); > > > > in efi_memmap_unmap() > > size = efi.memmap.desc_size * efi.memmap.nr_map; > > early_memunmap(efi.memmap.map, size); > > > > But the efi.memmap.nr_map is from __efi_memmap_init(). The remainder > > of size was discarded when calculating the nr_map: > > map.nr_map = data->size / data->desc_size; > > > > When the original size of memory map region does not equal to the > > result of multiplication. The "size not consistent" warning > > will be triggered. > > > > This issue sometimes was hit by kdump because kexec set the efi map > > size to align with 16 when loading crash kernel image: > > > > in bzImage64_load() > > efi_map_sz = efi_get_runtime_map_size(); > > efi_map_sz = ALIGN(efi_map_sz, 16); > > > > This patch changes the logic in the unmapping function. Using the > > end address of map to calcuate original size. > > > > Thank Randy Wright for his report and testing. And also thank > > Takashi Iwai for his help to trace issue. > > Good catch. The kexec code need to be fixed to use a separate buffer so > avoid the alignment like what kexec-tools did. I can submit a fix for > that. Can you try below code, see if it works? diff --git a/arch/x86/kernel/kexec-bzimage64.c b/arch/x86/kernel/kexec-bzimage64.c index 3182908b7e6c..eaee37c54b7b 100644 --- a/arch/x86/kernel/kexec-bzimage64.c +++ b/arch/x86/kernel/kexec-bzimage64.c @@ -398,11 +398,10 @@ static void *bzImage64_load(struct kimage *image, char *kernel, * little bit simple */ efi_map_sz = efi_get_runtime_map_size(); - efi_map_sz = ALIGN(efi_map_sz, 16); params_cmdline_sz = sizeof(struct boot_params) + cmdline_len + MAX_ELFCOREHDR_STR_LEN; params_cmdline_sz = ALIGN(params_cmdline_sz, 16); - kbuf.bufsz = params_cmdline_sz + efi_map_sz + + kbuf.bufsz = params_cmdline_sz + ALIGN(efi_map_sz, 16)+ sizeof(struct setup_data) + sizeof(struct efi_setup_data); @@ -410,7 +409,7 @@ static void *bzImage64_load(struct kimage *image, char *kernel, if (!params) return ERR_PTR(-ENOMEM); efi_map_offset = params_cmdline_sz; - efi_setup_data_offset = efi_map_offset + efi_map_sz; + efi_setup_data_offset = efi_map_offset + ALIGN(efi_map_sz, 16); /* Copy setup header onto bootparams. Documentation/x86/boot.txt */ setup_header_size = 0x0202 + kernel[0x0201] - setup_hdr_offset;