Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp504862ybl; Tue, 7 Jan 2020 09:53:12 -0800 (PST) X-Google-Smtp-Source: APXvYqwSTwCqpIjjZCmt7uebm2gXzifKkcBH6QN5goVoo6nsbVsQkiH83Km/GfFxxLK9cD9wPDbr X-Received: by 2002:a9d:d0b:: with SMTP id 11mr968830oti.287.1578419592898; Tue, 07 Jan 2020 09:53:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578419592; cv=none; d=google.com; s=arc-20160816; b=b8myqlG8RRv9k9mirO+qNEESckcwUhBC9LSr4D32r8pb6xHSzRrZYGF4KK5N+30aGp Uwpq3yMtYUF69nVl0rTBSEWD1k0UBNbuZjwjdCFgZRPHD1ivHJMtur5igSgNCu7Qdyr/ nzADWwbq3wWu3hKiVx0pHcY0mPGtzesNoeodvB8kkIUNxmhvXTqzCLEAS8v1MqPAyKyD NHAMFj5YtmZjN7TeabccoqalH4Dj+B/bOvTWPRj8zq38FmqWbS3Wm3G49Ge4VxEey1AH TvwiKljSomYN91sCueoNzK0A4gexXQ1CS+pYraLAY14b5/4tVXEWIEZTsqrQlKF5Dofe MLig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=UbVULJcO0KoQ8UyAq3sKxvpp33IhKJl+pej7FZpNELY=; b=jbswQT7YeOv8LHEcBbqSRpsUCh9AEUDhXrWwCEorF8K2zHPosBGOlp7cmDh5VuKY8D qDU4HVxKd2wSPQ+18OrFetUXqejvlPXAFRtVtofkFIj7MQm1Zth5DgUt3wzjUMPyoywf wrKocHpJkYcoV5l2odvkHusXvPdRPX+yryLJ5N8YVeD7LoOl4Xk5ih8Ia+k1dw3tnMuf f4XPHKGnq0yuG2C+t7xadMO6/tAirl/YaR4AWXiV4FgtJkt/NelANUDTZbLeNcLwlUvK WfupXLhvTlCaJMe5Six/fJwQK0O6DEfrFTUiy2ZNUposlWXZgKGLyElgci7VSI5TUpj7 ekhw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=rYlDokC2; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y8si345381oih.141.2020.01.07.09.52.59; Tue, 07 Jan 2020 09:53:12 -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=pass header.i=@linaro.org header.s=google header.b=rYlDokC2; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728507AbgAGRv6 (ORCPT + 99 others); Tue, 7 Jan 2020 12:51:58 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:43582 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728430AbgAGRv6 (ORCPT ); Tue, 7 Jan 2020 12:51:58 -0500 Received: by mail-wr1-f67.google.com with SMTP id d16so372670wre.10 for ; Tue, 07 Jan 2020 09:51:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=UbVULJcO0KoQ8UyAq3sKxvpp33IhKJl+pej7FZpNELY=; b=rYlDokC29xG14NYShebx3kVbcGhDwOlg8dhocTJWxexmpjVOsu48vUbua8LU//f6bV QXKcYKVtch0w36pWBBi5KBYZZhJqSBzBUnX6BZ50N/lqAxIW+rJClvHC/g0EszY77baN 9vyhAz9tU3V6EUBabm8d72cCJQh0LTFFUR5ipoacezcauI0W0hYKreE4PZR4Lvk4KtkC bWW1LeWwABAbufmTvqQrJUiLvwkAQZAzPx85cF5qbX5MJyi1xT63YBL5emVNEBHqPz1I TlzNY++WnMMyNtmQIdHUo6HG7wprzOx+xT2Yy3ZM7SY36t35VZJfHpofJfD9mGsoPmQG Qb0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=UbVULJcO0KoQ8UyAq3sKxvpp33IhKJl+pej7FZpNELY=; b=m0QbUaqaBfjLnr5k/3mW+O910Me7tg9DT5kfT9GetgsbhHbiwkBkO5cIKf2EJGU9gc pEXI0v7Tq1BgMORJw46T8SyxBeHuICKbK8SkpxiqlNQsAyVyK4ueKGeeFUtTv8+zWDLP 925IRwpQRM4zhBa0h2sQABqPwQTGdRWM4klRyHKceHW3Lk7nUDxuHeEA/N6mtO5PHl+H +RRdoQ/vDlXhtN0XhZeoagUqF5k5qd5UJ5y3FC5mNCWUeF1Y23qMchE/ttu6DlQBOgSm EhqGVy5g9xURl4e7jreGx6A35QUcp/HOfl2wlIObrgDc3b0JtZqaTX4/zRdX3y18jc/I 8laQ== X-Gm-Message-State: APjAAAUpvl+OAjEsRCZRP5kVYZhzp/24FN36nt8bHeCD2hn9/cMM1Cjb 90pHn6vKoEtOFY+k1q9D1vJk/YMh3LzJv1IjjsiB4g== X-Received: by 2002:a5d:46c1:: with SMTP id g1mr276481wrs.200.1578419516354; Tue, 07 Jan 2020 09:51:56 -0800 (PST) MIME-Version: 1.0 References: <157835762222.1456824.290100196815539830.stgit@dwillia2-desk3.amr.corp.intel.com> <157835764298.1456824.224151767362114611.stgit@dwillia2-desk3.amr.corp.intel.com> <20200107040415.GA19309@dhcp-128-65.nay.redhat.com> <20200107051919.GC19080@dhcp-128-65.nay.redhat.com> In-Reply-To: <20200107051919.GC19080@dhcp-128-65.nay.redhat.com> From: Ard Biesheuvel Date: Tue, 7 Jan 2020 18:51:45 +0100 Message-ID: Subject: Re: [PATCH v4 4/4] efi: Fix handling of multiple efi_fake_mem= entries To: Dave Young Cc: Dan Williams , Ingo Molnar , Taku Izumi , Michael Weiser , Thomas Gleixner , Ingo Molnar , linux-efi , X86 ML , Linux Kernel Mailing List , Kexec Mailing List Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 7 Jan 2020 at 06:19, Dave Young wrote: > > On 01/06/20 at 08:16pm, Dan Williams wrote: > > On Mon, Jan 6, 2020 at 8:04 PM Dave Young wrote: > > > > > > On 01/06/20 at 04:40pm, Dan Williams wrote: > > > > Dave noticed that when specifying multiple efi_fake_mem= entries only > > > > the last entry was successfully being reflected in the efi memory map. > > > > This is due to the fact that the efi_memmap_insert() is being called > > > > multiple times, but on successive invocations the insertion should be > > > > applied to the last new memmap rather than the original map at > > > > efi_fake_memmap() entry. > > > > > > > > Rework efi_fake_memmap() to install the new memory map after each > > > > efi_fake_mem= entry is parsed. > > > > > > > > This also fixes an issue in efi_fake_memmap() that caused it to litter > > > > emtpy entries into the end of the efi memory map. An empty entry causes > > > > efi_memmap_insert() to attempt more memmap splits / copies than > > > > efi_memmap_split_count() accounted for when sizing the new map. When > > > > that happens efi_memmap_insert() may overrun its allocation, and if you > > > > are lucky will spill over to an unmapped page leading to crash > > > > signature like the following rather than silent corruption: > > > > > > > > BUG: unable to handle page fault for address: ffffffffff281000 > > > > [..] > > > > RIP: 0010:efi_memmap_insert+0x11d/0x191 > > > > [..] > > > > Call Trace: > > > > ? bgrt_init+0xbe/0xbe > > > > ? efi_arch_mem_reserve+0x1cb/0x228 > > > > ? acpi_parse_bgrt+0xa/0xd > > > > ? acpi_table_parse+0x86/0xb8 > > > > ? acpi_boot_init+0x494/0x4e3 > > > > ? acpi_parse_x2apic+0x87/0x87 > > > > ? setup_acpi_sci+0xa2/0xa2 > > > > ? setup_arch+0x8db/0x9e1 > > > > ? start_kernel+0x6a/0x547 > > > > ? secondary_startup_64+0xb6/0xc0 > > > > > > > > Commit af1648984828 "x86/efi: Update e820 with reserved EFI boot > > > > services data to fix kexec breakage" is listed in Fixes: since it > > > > introduces more occurrences where efi_memmap_insert() is invoked after > > > > an efi_fake_mem= configuration has been parsed. Previously the side > > > > effects of vestigial empty entries were benign, but with commit > > > > af1648984828 that follow-on efi_memmap_insert() invocation triggers > > > > efi_memmap_insert() overruns. > > > > > > > > Fixes: 0f96a99dab36 ("efi: Add 'efi_fake_mem' boot option") > > > > Fixes: af1648984828 ("x86/efi: Update e820 with reserved EFI boot services...") > > > > > > A nitpick for the Fixes flags, as I replied in the thread below: > > > https://lore.kernel.org/linux-efi/CAPcyv4jLxqPaB22Ao9oV31Gm=b0+Phty+Uz33Snex4QchOUb0Q@mail.gmail.com/T/#m2bb2dd00f7715c9c19ccc48efef0fcd5fdb626e7 > > > > > > I reproduced two other panics without the patches applied, so this issue > > > is not caused by either of the commits, maybe just drop the Fixes. > > > > Just the "Fixes: af1648984828", right? No objection from me. I'll let > > Ingo say if he needs a resend for that. > > > > The "Fixes: 0f96a99dab36" is valid because the original implementation > > failed to handle the multiple argument case from the beginning. > > Agreed, thanks! > I'll queue this but without the fixes tags. The -stable maintainers are far too trigger happy IMHO, and this really needs careful review before being backported. efi_fake_mem is a debug feature anyway, so I don't see an urgent need to get this fixed retroactively in older kernels.