Received: by 10.192.165.148 with SMTP id m20csp459150imm; Fri, 4 May 2018 00:30:09 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqdYrcp5V19v2sGD2eM2T/3otdqoXorhm/YTaRmXlBMBxn+FndAOtPwTIoriOiZCWpjqy2Q X-Received: by 2002:a17:902:2a43:: with SMTP id i61-v6mr27367687plb.54.1525419009511; Fri, 04 May 2018 00:30:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525419009; cv=none; d=google.com; s=arc-20160816; b=DZgVVlWvzeuhzlcfNoB5ltf4nKjnC6DXRwDiz+L1J51Li96hDCHyOFJ80ynrqQoFpW wTWzwbCzkVCUchMvCCEXZSZIwuNVOWvNbglzrpqYlvFKKsrebEGJ4UYACbkP4Z6dltub 56febISMMsmGi5rggaTp/aJhWMPN+zYflFfVX1r/QhaOdT2Qa6g2IpGkhmwVAD3M8E/o hFsUwp1znKuH3Imwu0rRO9F0PyXXZYsZ6qukT74K40Q3/VsBhQ+lh5s/aF4b3ecrbgaj 9cRQxrTrb0SeZ8Yh0AcsQnK9a00rg5X0bGoL8LEg6+45sObUsnC4JJJ5uipRwP6TYtot jmiQ== 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=+SC5ns5RzXBnRMk+Ky0j/GqjFdVrZZCMnKrr9ggtKLg=; b=dlwZ2obiVxiRXvwYDV/XD2hzyfVolhg89mxeCEWl4ezvvoQF4jbe/z8z1QBTHgxd8x GpJYDb/6hunibxOWMj582zYoXYUR33yULr9avKx2+adLf+E/Q2688DURVe+ZnrGj0IoS MTS657IF8TExgbsN0iMRziOffAr0uyZL58kv4/St0Fgm9966x2PQTm035/HbihedIMaf e4MA46JM1oS5MsCad8J6QscHGLj96rg/YGk2dw43Jkf7n1uF943N6Av6XLomhP3DD0FF /sA8CPs7t6yRAqI0qnuPynRET30GwXsHq+8IQ/IDkCr0rFNPeLs456hj8Xnd7UowAmaJ i+Bg== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b123si15363050pfb.189.2018.05.04.00.29.54; Fri, 04 May 2018 00:30:09 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751477AbeEDH3b (ORCPT + 99 others); Fri, 4 May 2018 03:29:31 -0400 Received: from smtp.nue.novell.com ([195.135.221.5]:34180 "EHLO smtp.nue.novell.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751262AbeEDH33 (ORCPT ); Fri, 4 May 2018 03:29:29 -0400 Received: from linux-l9pv.suse (unknown.telstraglobal.net [134.159.103.118]) by smtp.nue.novell.com with ESMTP (TLS encrypted); Fri, 04 May 2018 09:29:24 +0200 Date: Fri, 4 May 2018 15:29:16 +0800 From: joeyli To: Ard Biesheuvel Cc: "Lee, Chun-Yi" , linux-efi@vger.kernel.org, Linux Kernel Mailing List , Takashi Iwai , Vivek Goyal , Ingo Molnar Subject: Re: [PATCH] efi: Fix the size not consistent issue when unmapping memory map Message-ID: <20180504072916.GR4235@linux-l9pv.suse> References: <20180502061724.25833-1-jlee@suse.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Ard, On Thu, May 03, 2018 at 02:05:51PM +0200, Ard Biesheuvel wrote: > On 2 May 2018 at 08:17, 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); > > > > Dave Young's a841aa83d patch fixed kexec issue. On UEFI side, this > > patch changes the logic in the unmapping function. Using the end > > address of map to calcuate original size. > > > > Why do we still need this patch? I.e., in which circumstances will > efi_memory_map_data::size assume a value that is rounded up or > otherwise incorrect? > There have no other case except kexec. But I think that it's better to sync mapping/unmapping size between __efi_memmap_init() and efi_memmap_unmap(). Thanks Joey Lee > > Thank Randy Wright for his report and testing. And also thank > > Takashi Iwai for his help to trace issue. > > > > Cc: Ard Biesheuvel > > Cc: Takashi Iwai > > Cc: Vivek Goyal > > Cc: Ingo Molnar > > Tested-by: Randy Wright > > Signed-off-by: "Lee, Chun-Yi" > > --- > > drivers/firmware/efi/memmap.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/drivers/firmware/efi/memmap.c b/drivers/firmware/efi/memmap.c > > index 5fc7052..1f592d8 100644 > > --- a/drivers/firmware/efi/memmap.c > > +++ b/drivers/firmware/efi/memmap.c > > @@ -121,7 +121,7 @@ void __init efi_memmap_unmap(void) > > if (!efi.memmap.late) { > > unsigned long size; > > > > - size = efi.memmap.desc_size * efi.memmap.nr_map; > > + size = efi.memmap.map_end - efi.memmap.map; > > early_memunmap(efi.memmap.map, size); > > } else { > > memunmap(efi.memmap.map); > > -- > > 2.10.2 > >