From patchwork Wed Jul 11 09:02:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 141693 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp37092ljj; Wed, 11 Jul 2018 02:02:53 -0700 (PDT) X-Google-Smtp-Source: AAOMgpe2IaeB5Agaj+bAsUqwICC1mRUX8FsW8hk/pPXGbCJAYc4oi4S9DUna52u3RgbWuml9/e2f X-Received: by 2002:a17:902:8b8c:: with SMTP id ay12-v6mr27845683plb.74.1531299772912; Wed, 11 Jul 2018 02:02:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531299772; cv=none; d=google.com; s=arc-20160816; b=rGADeragW4a6GPi1NUocU89AufwORa3IvfskkQVyBUJvqzZGMWtzuxp8Rzh+MNkdOv yFcH/DtLp9FFXtCNHK3KkDEsd8frvr5FR9OF/+X7mLMKnhVFc/orqyc0/SHVbAzpp5FZ H24DfuHR42G7Y3Et3TUt23NNQV15cPPl/BWdswPEn8BpoTUAPgj0/JbKfyqK0853jzJu yuSpggL5cPGzBNPAtirJpeAeipEOTG5JwlTvA8A5zYKZZnfsO0UIuT9tA6aM68B26yAI C3sKIqxaQyOoTqs+S/DjMr1M6B0QPn5Tuk3S30YJ3tomtMk6b0xQNhpiE9Sak1bYS4C+ qo7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=B1+MiTcjlOOPmNGd8vzzwOHp7KxdoXoZzDJ83zJl9Ps=; b=dY8tFqv3YAuLVMad7qmX2WM0yeqFRZS8pCGn4BEWZSUGodfhGHxW7fOLMLI2yX+0Vz AYS+JaFnfX89d9fkNFpw+3s17WWhbzbkeirPLzZSeiwuvz2gg3esy7/OGugjs7d/ryrI 4bs5I7iFVQbLoUZgiCzpM8JAn5IgSFwAaiMlpfXeDDN17D9DeNBpmID3Vg6u+YNuhzBj X5taNbeutYCKoUgIC3AwXaiPkesOkTEtYqcdZ7sl/ouJ5e2gQi9x4QZUikOZgXwtT9Ni Hc8oF3h9CzsHt/qVIGxNlPqiCU5yIlmo20+yZ/xQknkZuN28ptEOzq0FO9hFZvA++H/I Y0lw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Tkz9Oax9; 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 y2-v6si20684383pff.117.2018.07.11.02.02.52; Wed, 11 Jul 2018 02:02:52 -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; dkim=pass header.i=@linaro.org header.s=google header.b=Tkz9Oax9; 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 S1732433AbeGKJGH (ORCPT + 22 others); Wed, 11 Jul 2018 05:06:07 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:35377 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732366AbeGKJGF (ORCPT ); Wed, 11 Jul 2018 05:06:05 -0400 Received: by mail-wr1-f66.google.com with SMTP id a3-v6so8098134wrt.2 for ; Wed, 11 Jul 2018 02:02:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=B1+MiTcjlOOPmNGd8vzzwOHp7KxdoXoZzDJ83zJl9Ps=; b=Tkz9Oax9WQgrqkCmqcnLMK3oszC3KI+g9BDmy0LIHWq3O453e5BXcvCvCDJ2A+iP63 UtxSdVQthB51jMTIkyc3veXe+CjMyOxumqixgytyoLaRad7H16Pehx+20kZu6kZaFWP5 omUiQVfpDDHzcvFN7xZ7osPjZCSFHVw6E1cVY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=B1+MiTcjlOOPmNGd8vzzwOHp7KxdoXoZzDJ83zJl9Ps=; b=PLkga24zKsatcELxdyNcq70baAez0mjWfbDxIY12tZfk5rgW+onbZKU/9sigZcxFS5 PDcnumtMdW1BFB5JmQiBQsP2u5eWivhFQakz0V6iB1kmBuJPT8GmLHSSDJ2GyjJWWqbw +08LRgJYE11dlbg/mabpjl0zJitdeFZyv84Uh/MVuz4ytLZDe/W6Ag7oYWXkBGUmLWR+ xX14TaFuXVlfnt0J457eNEJ+1jxpfr5jZRPKGYGAr0nrz0XCDNjhSgz+nQzqKUcxGCLK akDjikWhy6YPcC/ChhAv8b7QNCEJSpZ1PboAawHwnep3e1jWQckyuRDzvd8PvPGRaw7e Dz3g== X-Gm-Message-State: AOUpUlGNu+B6fOtd1qSZsCCXNkUS+ezpEK98hONFpoP9dsu4JDWMv1OC oKtrk0IAlhGTK9HkhD272TAvU5+oLrc= X-Received: by 2002:adf:a691:: with SMTP id t17-v6mr4270797wrc.57.1531299767394; Wed, 11 Jul 2018 02:02:47 -0700 (PDT) Received: from localhost.localdomain (33.153.69.91.rev.sfr.net. [91.69.153.33]) by smtp.gmail.com with ESMTPSA id y203-v6sm2327953wme.42.2018.07.11.02.02.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Jul 2018 02:02:46 -0700 (PDT) From: Ard Biesheuvel To: linux-efi@vger.kernel.org, Ingo Molnar , Thomas Gleixner Cc: Ard Biesheuvel , linux-kernel@vger.kernel.org Subject: [PATCH 1/1] efi/x86: remove pointless call to PciIo->Attributes() Date: Wed, 11 Jul 2018 11:02:35 +0200 Message-Id: <20180711090235.9327-2-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180711090235.9327-1-ard.biesheuvel@linaro.org> References: <20180711090235.9327-1-ard.biesheuvel@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When it was first introduced, the EFI stub code that copies the contents of PCI option ROMs originally only intended to do so if the EFI_PCI_IO_ATTRIBUTE_EMBEDDED_ROM attribute was *not* set. The reason was that the UEFI spec permits PCI option ROM images to be provided by the platform directly, rather than via the ROM BAR, and in this case, the OS can only access them at runtime if they are preserved at boot time by copying them from the areas described by PciIo->RomImage and PciIo->RomSize. However, it implemented this check erroneously, as can be seen in commit dd5fc854de5fd ("EFI: Stash ROMs if they're not in the PCI BAR"): if (!attributes & EFI_PCI_IO_ATTRIBUTE_EMBEDDED_ROM) continue; and given that the numeric value of EFI_PCI_IO_ATTRIBUTE_EMBEDDED_ROM is 0x4000, this condition never becomes true, and so the option ROMs were copied unconditionally. This was spotted and 'fixed' by commit 886d751a2ea99a160 ("x86, efi: correct precedence of operators in setup_efi_pci"), but inadvertently inverted the logic at the same time, defeating the purpose of the code, since it now only preserves option ROM images that can be read from the ROM BAR as well. Unsurprisingly, this broke some systems, and so the check was removed entirely in commit 739701888f5d ("x86, efi: remove attribute check from setup_efi_pci"). It is debatable whether this check should have been included in the first place, since the option ROM image provided to the UEFI driver by the firmware may be different from the one that is actually present in the card's flash ROM, and so whatever PciIo->RomImage points at should be preferred regardless of whether the attribute is set. As this was the only use of the attributes field, we can remove the call to PciIo->Attributes() entirely, which is especially nice because its prototype involves uint64_t type by-value arguments which the EFI mixed mode has trouble dealing with. Tested-by: Wilfried Klaebe Tested-by: Hans de Goede Signed-off-by: Ard Biesheuvel --- arch/x86/boot/compressed/eboot.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) -- 2.17.1 diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c index e57665b4ba1c..e98522ea6f09 100644 --- a/arch/x86/boot/compressed/eboot.c +++ b/arch/x86/boot/compressed/eboot.c @@ -114,18 +114,12 @@ __setup_efi_pci(efi_pci_io_protocol_t *pci, struct pci_setup_rom **__rom) struct pci_setup_rom *rom = NULL; efi_status_t status; unsigned long size; - uint64_t attributes, romsize; + uint64_t romsize; void *romimage; - status = efi_call_proto(efi_pci_io_protocol, attributes, pci, - EfiPciIoAttributeOperationGet, 0ULL, - &attributes); - if (status != EFI_SUCCESS) - return status; - /* - * Some firmware images contain EFI function pointers at the place where the - * romimage and romsize fields are supposed to be. Typically the EFI + * Some firmware images contain EFI function pointers at the place where + * the romimage and romsize fields are supposed to be. Typically the EFI * code is mapped at high addresses, translating to an unrealistically * large romsize. The UEFI spec limits the size of option ROMs to 16 * MiB so we reject any ROMs over 16 MiB in size to catch this.