linux-efi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ard Biesheuvel <ard.biesheuvel@linaro.org>
To: Hans de Goede <hdegoede@redhat.com>
Cc: linux-efi <linux-efi@vger.kernel.org>,
	Matthew Garrett <matthewgarrett@google.com>,
	Ingo Molnar <mingo@kernel.org>, Andy Lutomirski <luto@kernel.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Arvind Sankar <nivedita@alum.mit.edu>,
	Matthew Garrett <mjg59@google.com>
Subject: Re: [PATCH v2 21/21] efi: Allow disabling PCI busmastering on bridges during boot
Date: Wed, 4 Mar 2020 22:59:30 +0100	[thread overview]
Message-ID: <CAKv+Gu-JLm_W-Zdtg=Bea5mmyyCkhMtz9Py=ybwGmP8W9Ck1pA@mail.gmail.com> (raw)
In-Reply-To: <de8c1023-c637-263b-b5d0-2a71ddb24d6e@redhat.com>

On Wed, 4 Mar 2020 at 19:49, Hans de Goede <hdegoede@redhat.com> wrote:
>
> Hi,
>
> On 3/4/20 7:26 PM, Ard Biesheuvel wrote:
> > On Wed, 4 Mar 2020 at 11:39, Hans de Goede <hdegoede@redhat.com> wrote:
> >>
> >> Hi,
> >>
> >> On 2/6/20 3:35 PM, Ard Biesheuvel wrote:
> >>> On Thu, 6 Feb 2020 at 14:31, Hans de Goede <hdegoede@redhat.com> wrote:
> >>>>
> >>>> Hi,
> >>>>
> >>>> On 12/18/19 6:01 PM, Ard Biesheuvel wrote:
> >>>>> From: Matthew Garrett <matthewgarrett@google.com>
> >>>>>
> >>>>> Add an option to disable the busmaster bit in the control register on
> >>>>> all PCI bridges during the invocation of ExitBootServices() and passing
> >>>>> control to the runtime kernel. System firmware may configure the IOMMU
> >>>>> to prevent malicious PCI devices from being able to attack the OS via DMA.
> >>>>> However, since firmware can't guarantee that the OS is IOMMU-aware, it
> >>>>> will tear down IOMMU configuration when ExitBootServices() is called.
> >>>>> This leaves a window between where a hostile device could still cause
> >>>>> damage before Linux configures the IOMMU again.
> >>>>>
> >>>>> If CONFIG_EFI_DISABLE_PCI_DMA is enabled or the "efi=disable_pci_dma"
> >>>>> command line argument is passed, the EFI stub will clear the busmaster
> >>>>> bit on all PCI bridges before ExitBootServices() completes. This will
> >>>>> prevent any malicious PCI devices from being able to perform DMA until
> >>>>> the kernel reenables busmastering after configuring the IOMMU.
> >>>>>
> >>>>> This option is disabled when in EFI mixed mode environments (ie, 64-bit
> >>>>> kernels with a 32-bit EFI implementation), given that the use of EFI
> >>>>> events is not supported in this case.
> >>>>>
> >>>>> This option may cause failures with some poorly behaved hardware and
> >>>>> should not be enabled without testing. The kernel commandline options
> >>>>> "efi=disable_pci_dma" or "efi=no_disable_pci_dma" may be used to
> >>>>> override the default.
> >>>>>
> >>>>> Co-developed-by: Matthew Garrett <mjg59@google.com>
> >>>>> Signed-off-by: Matthew Garrett <mjg59@google.com>
> >>>>> [ardb: use EFI events to defer DMA disabling to the end of ExitBootServices()]
> >>>>> Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
> >>>>
> >>>> I guess this might not be the latest version of this patch, but
> >>>> this does seem to be the thread where most discussion on it
> >>>> has happened.
> >>>>
> >>>> My personal kernel tree atm consists of v5.5 + efi/next + my own patches
> >>>> and yesterday I noticed that will not boot on a Lenovo X1 7th gen connected
> >>>> to a Lenovo thunderbolt 3 gen 2 dock.
> >>>>
> >>>> My first hunch was that I have CONFIG_EFI_DISABLE_PCI_DMA=y and that that
> >>>> was causing it and indeed that is the problem.
> >>>>
> >>>> So as (somewhat) expected CONFIG_EFI_DISABLE_PCI_DMA=y indeed stops the kernel
> >>>> from booting on some systems.
> >>>>
> >>>> When I hit this problem the efistub prints 2 messages and then the system
> >>>> just hangs:
> >>>>
> >>>> exit_boot() failed!
> >>>> efi_main() failed!
> >>>>
> >>>> When I boot the system without it being connected to the thunderbolt dock
> >>>> then efi=disable_pci_dma works fine.
> >>>>
> >>>> Let me know if I can do anything to help and getting booting while
> >>>> connected to the dock to work with efi=disable_pci_dma.
> >>>>
> >>>
> >>> Thanks Hans.
> >>>
> >>> Can you run the UEFI shell on this system? If so, could you share the
> >>> output of devtree, both in the docked and the undocked states?
> >>>
> >>> That should help us pinpoint which device is throwing an error at
> >>> ExitBootServices() time due to its driver having been disconnected.
> >>
> >> Sorry for being slow to respond. Attached are the outputs of devtree in
> >> both states. Not sure if the list will accept this, but you should
> >> get a direct copy.
> >>
> >
> > Interesting. The only difference that UEFI seems to know about in
> > terms of device hierarchy is a XHCI controller with a Realtek USB NIC
> > attached.
> >
> > Could you try unloading the driver for that manually, or disconnecting
> > it? Or disconnect the whole thing from the shell?
>
> How would I go about that / do that ?
>
> > If just unloading the realtek driver does not make a difference, but
> > unload/disconnecting the xhci makes it work, it is likely that it this
> > feature will break a lot of systems.
>
> Notice that it is not just the XHCI controller which gets added though,
> there also is an extra PCI-e switch added to the route to the XHCI controller,
> I've attached both docked and undocked lspci output under Linux. I guess
> this might be transparent from a UEFI pov though.
>

Yeah, what matters is drivers that are actually called when the EFI
stub calls ExitBootServices(), and looking at the dump, the XHCI
driver and the Realtek driver are the only ones that stand out to me
(and the Realtek one is probably the only 3rd party driver, so that
one looks the most suspect to me)

  reply	other threads:[~2020-03-04 21:59 UTC|newest]

Thread overview: 87+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-18 17:01 [PATCH v2 00/21] efi/x86: confine type unsafe casting to mixed mode Ard Biesheuvel
2019-12-18 17:01 ` [PATCH v2 01/21] efi/libstub: remove unused __efi_call_early() macro Ard Biesheuvel
2019-12-18 17:01 ` [PATCH v2 02/21] efi/x86: rename efi_is_native() to efi_is_mixed() Ard Biesheuvel
2019-12-18 17:01 ` [PATCH v2 03/21] efi/libstub: use a helper to iterate over a EFI handle array Ard Biesheuvel
2019-12-18 17:01 ` [PATCH v2 04/21] efi/libstub: extend native protocol definitions with mixed_mode aliases Ard Biesheuvel
2019-12-18 17:01 ` [PATCH v2 05/21] efi/libstub: distinguish between native/mixed not 32/64 bit Ard Biesheuvel
2019-12-18 17:01 ` [PATCH v2 06/21] efi/libstub/x86: use mixed mode helpers to populate efi_config Ard Biesheuvel
2019-12-18 17:01 ` [PATCH v2 07/21] efi/libstub: drop explicit 32/64-bit protocol definitions Ard Biesheuvel
2019-12-18 17:01 ` [PATCH v2 08/21] efi/libstub: use stricter typing for firmware function pointers Ard Biesheuvel
2019-12-18 17:01 ` [PATCH v2 09/21] efi/libstub: annotate firmware routines as __efiapi Ard Biesheuvel
2019-12-18 17:01 ` [PATCH v2 10/21] efi/libstub/x86: avoid thunking for native firmware calls Ard Biesheuvel
2019-12-21 21:22   ` Hans de Goede
2019-12-22 12:02     ` Ard Biesheuvel
2019-12-22 12:37       ` Ard Biesheuvel
2019-12-22 12:46       ` Andy Lutomirski
2019-12-22 15:29         ` Ard Biesheuvel
2019-12-22 21:12           ` Arvind Sankar
2019-12-22 21:25             ` Ard Biesheuvel
2019-12-23 11:49       ` Hans de Goede
2019-12-23 12:00         ` Ard Biesheuvel
2019-12-18 17:01 ` [PATCH v2 11/21] efi/libstub: get rid of 'sys_table_arg' macro parameter Ard Biesheuvel
2019-12-18 17:01 ` [PATCH v2 12/21] efi/libstub: unify the efi_char16_printk implementations Ard Biesheuvel
2019-12-18 17:01 ` [PATCH v2 13/21] efi/libstub/x86: drop __efi_early() export of efi_config struct Ard Biesheuvel
2019-12-24 19:34   ` Hans de Goede
2019-12-25 14:42     ` Ard Biesheuvel
2019-12-27 22:44       ` Hans de Goede
2019-12-27 22:51         ` Ard Biesheuvel
2019-12-31 23:04   ` Arvind Sankar
2020-01-01 18:13     ` Ard Biesheuvel
2020-01-01 19:08       ` Arvind Sankar
2020-01-02  7:33         ` Ard Biesheuvel
2020-01-02 14:06           ` Arvind Sankar
2020-01-02 15:20             ` Ard Biesheuvel
2020-01-02 15:51               ` Arvind Sankar
2020-01-02 15:58                 ` Ard Biesheuvel
2020-01-02 16:28                   ` Ard Biesheuvel
2020-01-02 16:59                     ` Ard Biesheuvel
2020-01-02 17:26                       ` Arvind Sankar
2020-01-02 17:30                         ` Ard Biesheuvel
2020-01-02 17:41                           ` Arvind Sankar
2020-01-02 17:48                             ` Ard Biesheuvel
2020-01-02 18:10                               ` Arvind Sankar
2020-01-02 18:38                                 ` Ard Biesheuvel
2020-01-03 14:16                                   ` Arvind Sankar
2020-01-03 14:23                                     ` Ard Biesheuvel
2020-01-02 18:38                               ` Arvind Sankar
2020-01-02 16:59                     ` Arvind Sankar
2020-01-02 17:03                       ` Ard Biesheuvel
2020-01-02 17:21                         ` Arvind Sankar
2019-12-18 17:01 ` [PATCH v2 14/21] efi/libstub: drop sys_table_arg from printk routines Ard Biesheuvel
2019-12-18 17:01 ` [PATCH v2 15/21] efi/libstub: remove 'sys_table_arg' from all function prototypes Ard Biesheuvel
2019-12-18 17:01 ` [PATCH v2 16/21] efi/libstub: drop protocol argument from efi_call_proto() macro Ard Biesheuvel
2019-12-18 17:01 ` [PATCH v2 17/21] efi/libstub: drop 'table' argument from efi_table_attr() macro Ard Biesheuvel
2019-12-18 17:01 ` [PATCH v2 18/21] efi/libstub: use 'func' not 'f' as macro parameter Ard Biesheuvel
2019-12-31 16:51   ` Arvind Sankar
2019-12-31 17:06     ` Ard Biesheuvel
2019-12-31 17:36       ` Arvind Sankar
2019-12-18 17:01 ` [PATCH v2 19/21] efi/libstub: tidy up types and names of global cmdline variables Ard Biesheuvel
2019-12-18 17:01 ` [PATCH v2 20/21] efi/libstub: import type definitions for creating and signalling events Ard Biesheuvel
2019-12-18 17:01 ` [PATCH v2 21/21] efi: Allow disabling PCI busmastering on bridges during boot Ard Biesheuvel
2019-12-19  2:50   ` Andy Lutomirski
2019-12-19 13:17     ` Ard Biesheuvel
2019-12-19 20:04       ` Matthew Garrett
2019-12-19 20:04   ` Matthew Garrett
2019-12-20  7:06     ` Ard Biesheuvel
2019-12-20  7:17       ` Andy Lutomirski
2019-12-20  8:11         ` Ard Biesheuvel
2019-12-20 19:41           ` Arvind Sankar
2020-01-02 14:46             ` Laszlo Ersek
2020-01-02 15:40               ` Ard Biesheuvel
2019-12-20 20:43       ` Matthew Garrett
2019-12-21 16:44         ` Ard Biesheuvel
2019-12-21 21:24           ` Matthew Garrett
2019-12-21 22:54             ` Arvind Sankar
2019-12-23 14:02               ` Ard Biesheuvel
2019-12-23 15:46                 ` Arvind Sankar
2019-12-23 15:58                   ` Ard Biesheuvel
2019-12-23 16:12                     ` Arvind Sankar
2019-12-23 20:57                   ` Matthew Garrett
2020-02-06 14:30   ` Hans de Goede
2020-02-06 14:35     ` Ard Biesheuvel
2020-03-04 10:38       ` Hans de Goede
2020-03-04 18:26         ` Ard Biesheuvel
2020-03-04 18:49           ` Hans de Goede
2020-03-04 21:59             ` Ard Biesheuvel [this message]
2019-12-19 11:12 ` [PATCH v2 00/21] efi/x86: confine type unsafe casting to mixed mode Hans de Goede
2019-12-19 13:22   ` Ard Biesheuvel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAKv+Gu-JLm_W-Zdtg=Bea5mmyyCkhMtz9Py=ybwGmP8W9Ck1pA@mail.gmail.com' \
    --to=ard.biesheuvel@linaro.org \
    --cc=hdegoede@redhat.com \
    --cc=linux-efi@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=matthewgarrett@google.com \
    --cc=mingo@kernel.org \
    --cc=mjg59@google.com \
    --cc=nivedita@alum.mit.edu \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).