Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp2573550ybl; Sun, 2 Feb 2020 01:36:28 -0800 (PST) X-Google-Smtp-Source: APXvYqwuIuf5cW1wRBLa4VkISmbBoFS1f51/n9vdrWeqm2Yb6zaXM2TddJFQv0iuq/R23lZAF2uI X-Received: by 2002:aca:1108:: with SMTP id 8mr11742907oir.127.1580636188152; Sun, 02 Feb 2020 01:36:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580636188; cv=none; d=google.com; s=arc-20160816; b=QhFed0WSnbiYHk7UqeEh/G5+7+tb8h1btnpZWBxuK6pYz6fkpGXWXHCzGU2akUNDUw g6BxwIileDVxfyNQdEyReF/YR/gEF5akcwor4nw8DNq1daCcZzaRKdFfTEzmZSMM8T1j b4w+xuBvr4pdyznsyFi0mLi62N5XjyK75xfPaYyxVj4t+tpnQ8y3o7ZhVH2bsafT3YLs yzn7mRCpvTSDXkUySOBwHPeQ6FjB2u/MKAELhuTuNO1xaSxw8o3mObqwCnuDoONNyiOc 9QkCfuwuhigDqUa9pCnJddZfLu9TaT4daGjJz7cTWS8MUM7Tcqc05mAN5N4Lhaa5BdzP vf7g== 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-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=S2yNcMg/flOTRtk/fmlPvWyglwu5z2BGKORhR/l6zcs=; b=lB4JmWW3vORjCM4YkC/iK7V94q7IWfTNT0Uk/TFd4OcHEqkH+VOKYs9tTyGHXjouN0 31uYkCPI0X5GwiP72WYS4r0MBupPEkt1AFMRYPx6lzTDaf2iJcPLZRxZgzivgpK1l8LK LTs1yoL97M8GP/P0RoABRemkAKw4qe2dvTZgAcMN5CbR2piNYBFNjXJamv7xxToDiTss 74W6YiI1DFgbPxxgc+LJq5DgUJje2uk1PaWLHTv/mbminAzvei6qrv5CLNz2FIhWCJWA qOVvN/FbZisBnRZHAeASBJNOLFCNN+lS3xD5zpmJMz0DftBV9zKXny0O85DEbKUWLKT5 FQ8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=eV69YJm3; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f4si7071841oto.169.2020.02.02.01.36.16; Sun, 02 Feb 2020 01:36:28 -0800 (PST) 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; dkim=fail header.i=@gmail.com header.s=20161025 header.b=eV69YJm3; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726881AbgBBJer (ORCPT + 99 others); Sun, 2 Feb 2020 04:34:47 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:42148 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725962AbgBBJeq (ORCPT ); Sun, 2 Feb 2020 04:34:46 -0500 Received: by mail-wr1-f68.google.com with SMTP id k11so14045293wrd.9; Sun, 02 Feb 2020 01:34:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=S2yNcMg/flOTRtk/fmlPvWyglwu5z2BGKORhR/l6zcs=; b=eV69YJm3Pgc4+O8vxHRxe7KVsw1/7h+hj2J0CkCzcuPv9TCzN3w5ACzJ2REvw8PfsU 0H7D4ASAuFxlXKzVpiDZk6wC+JpHgNX+I0EzLoDdeH7d9I3ohuX3NgaUtiIc1DouMZd9 8hDSMvmrrPWSf0U0omrLQRKy6R6Sgm4uVmS5S/hIZuFVqeov8fl386Ds0qZT2V995VHn nflpplGzfq0efDyhMAL8JvfYuqHCRIaHsYDGyUkE1X5xnP9FmQ9KR8qMEZd95aF/0hSF 2QMa35nRkUMRrnlZE72+fLb67L8xG0mBnWMhHZUFrieN800n+uK3B0Q7RAtPjMN/LCU5 vKOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition :content-transfer-encoding:in-reply-to:user-agent; bh=S2yNcMg/flOTRtk/fmlPvWyglwu5z2BGKORhR/l6zcs=; b=qCIzmmYsADr21KozMxnRJ5zhIZlsHRW+JCan5Ek5MY7d1jKHvwXbRUF83ZMJqS7YsP VlCowc9j2cniKvsDb4Fg2G/K7s5XhpgGwAibj9HBZZt78XPvUjEUFiN88HrR1l4CkHl8 8OvwjHI1LQ5JKgqm/n0/+eMngVddx4viMIh5L8Kv7DROa2EEsSLhzgYo3P4DZurAX1Yn HAbdCrckkovfc/KWMlFyrPSS0Ba5M93Ei5Ws5erivDY9HjQ40+W56I4Tzd9F5Xn5+dQK fANdR88T049LjMnnlQMmQZ37JS7QnrLCBYqJngOfZ8+L7R+0PhRy8xXzdlzi5aLQ+uYP J3Mw== X-Gm-Message-State: APjAAAUW299L93lSrw9xYdfEIWhkS7i6kuFebaxAAiFJcPBmWVpfcNfi AdJUGvhhUSBFiK/r81b/0P8= X-Received: by 2002:a5d:5088:: with SMTP id a8mr4258636wrt.162.1580636084657; Sun, 02 Feb 2020 01:34:44 -0800 (PST) Received: from gmail.com (54033286.catv.pool.telekom.hu. [84.3.50.134]) by smtp.gmail.com with ESMTPSA id f207sm19962533wme.9.2020.02.02.01.34.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Feb 2020 01:34:44 -0800 (PST) Date: Sun, 2 Feb 2020 10:34:42 +0100 From: Ingo Molnar To: Ard Biesheuvel Cc: linux-efi@vger.kernel.org, x86@kernel.org, dan.j.williams@intel.com, jrg.otte@gmail.com, torvalds@linux-foundation.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] efi/x86: fix boot regression on systems with invalid memmap entries Message-ID: <20200202093442.GB72728@gmail.com> References: <20200201233304.18322-1-ardb@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20200201233304.18322-1-ardb@kernel.org> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org * Ard Biesheuvel wrote: > In efi_clean_memmap(), we do a pass over the EFI memory map to remove > bogus entries that may be returned on certain systems. > > Commit 1db91035d01aa8bf ("efi: Add tracking for dynamically allocated > memmaps") refactored this code to pass the input to efi_memmap_install() > via a temporary struct on the stack, which is populated using an > initializer which inadvertently defines the value of its size field > in terms of its desc_size field, which value cannot be relied upon yet > in the initializer itself. > > Fix this by using efi.memmap.desc_size instead, which is where we get > the value for desc_size from in the first place. > > Tested-by: Dan Williams > Signed-off-by: Ard Biesheuvel > --- > arch/x86/platform/efi/efi.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/arch/x86/platform/efi/efi.c b/arch/x86/platform/efi/efi.c > index 59f7f6d60cf6..ae923ee8e2b4 100644 > --- a/arch/x86/platform/efi/efi.c > +++ b/arch/x86/platform/efi/efi.c > @@ -308,7 +308,7 @@ static void __init efi_clean_memmap(void) > .phys_map = efi.memmap.phys_map, > .desc_version = efi.memmap.desc_version, > .desc_size = efi.memmap.desc_size, > - .size = data.desc_size * (efi.memmap.nr_map - n_removal), > + .size = efi.memmap.desc_size * (efi.memmap.nr_map - n_removal), > .flags = 0, > }; Applied, and I also added: Reported-by: J?rg Otte Tested-by: J?rg Otte I presumptively added the J?rg's Tested-by tag: won't send the commit to Linus if he still has trouble booting the laptop. I'm still amazed GCC doesn't warn about this pattern - why? BTW., could we please also organize such assignments vertically as well: .phys_map = efi.memmap.phys_map, .desc_version = efi.memmap.desc_version, .desc_size = efi.memmap.desc_size, .size = efi.memmap.desc_size * (efi.memmap.nr_map - n_removal), .flags = 0, (See the patch below.) Had we done that earlier the weird pattern would have stuck out a lot more: .phys_map = efi.memmap.phys_map, .desc_version = efi.memmap.desc_version, .desc_size = efi.memmap.desc_size, .size = data.desc_size * (efi.memmap.nr_map - n_removal), .flags = 0, BTW., is there a reason "struct efi_memory_map" doesn't embedd a "struct efi_memory_map_data"? Or is efi_memory_map firmware ABI? If they shared the structure then copying would be easier. Thanks, Ingo Signed-off-by: Ingo Molnar arch/x86/platform/efi/efi.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/arch/x86/platform/efi/efi.c b/arch/x86/platform/efi/efi.c index ae923ee8e2b4..293c47f9cb39 100644 --- a/arch/x86/platform/efi/efi.c +++ b/arch/x86/platform/efi/efi.c @@ -305,11 +305,11 @@ static void __init efi_clean_memmap(void) if (n_removal > 0) { struct efi_memory_map_data data = { - .phys_map = efi.memmap.phys_map, - .desc_version = efi.memmap.desc_version, - .desc_size = efi.memmap.desc_size, - .size = efi.memmap.desc_size * (efi.memmap.nr_map - n_removal), - .flags = 0, + .phys_map = efi.memmap.phys_map, + .desc_version = efi.memmap.desc_version, + .desc_size = efi.memmap.desc_size, + .size = efi.memmap.desc_size * (efi.memmap.nr_map - n_removal), + .flags = 0, }; pr_warn("Removing %d invalid memory map entries.\n", n_removal);