Skip to contentSkip to conversation

function probe_roms accessing improper addresses

RFC PATCH Randy Wright 5 participants 5 messages Oct 19, 2012 – Oct 23, 2012 2 messages not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

#2 lore raw

I would like to summarize progress I have made on this issue in the past few days, and then appeal for help in evaluating the options. Matthew and H. Peter Anvin, I would appreciate your additional input especially.

The general idea under consideration here is to avoid access to the legacy adapter space. My original rfc patch applied this restriction to all efi_enabled systems. I am modifying this to implement this as a quirk, and the question is how best to activate such a quirk.

Option 1: Activating via Machine Check

I investigated the idea of activating based on encountering a machine check. As an experiment, to avoid boot-time code sequencing issues, I moved the probe_roms call to after the MC handler initialization. However, I ran into prototype firmware issues. As I had suspected might be the case, the access was still treated as fatal by platform firmware and the kernel machine check handler does not get a chance to run. Since I could not resolve this with resources available to me, I had to set this approach aside.

Option 2: Activating via DMI properties

I have written and tested code implementing the following approach. With just a bit of clean-up I could send this as a new patch RFC if it sounds workable.

First, I added a new member to the x86_platform_ops structure:

    int (*legacy_range_accessible)(phys_addr_t);

The default function provided for this operation always returns an indication that access is permitted. If appropriate to the platform, the default function pointer can be replaced at runtime with a function that disallows access. This provides a test by which post-boot code - such as devmem_is_allowed - can query whether access to a particular address should be permitted.

Because this check must occur in a relatively small window between dmi initialization and the call to probe_roms, I added what I think could be a generally useful early quirk check at the end of dmi_scan_machine:

   if (dmi_available)
       dmi_check_system(dmi_early_quirks);

Here, dmi_early_quirks is a typical dmi_system_id array, initially
containing an entry for my prototype system. When matched for the
properties of interest, it calls out via the .callback entry to a new function I named x86_mark_legacy_adapter_range_inaccessible. This function does the following:

a. it replaces the x86_init_resources.probe_roms function pointer with x86_init_noop; and

b. it replaces the above-mentioned legacy_range_accessible callout in the x86_platform_ops structure with a function that disapproves of access to the legacy adapter region.

So in this approach, I don't patch the function probe_roms itself; rather, I entirely avoid calling it.

A specific point on which I'd like to get advice is regarding the policy for accepting a submission based on DMI properties of an unreleased prototype platform. This focuses on the weak point of any "opt-in" type of quirk: if the DMI properties of the product change over the product lifecyle (there's always a version n+1!) then the patch must be amended. But at that point, the modification required is simply altering text string content in a dmi_system_id array.

Option 3: Boot command line activation

| 3. Can it be activated on demand for testing on other platforms? A
| kernel boot command line parameter could be added, for example. How does
| the community feel about adding more of those?

I am considering this option in addition to - not instead of - the automatic activation by the dmi properties, but it remains an area on which I want to get further input before posting a new patch rfc: is it appropriate to include a boot command interface to activate this feature on demand for platforms that don't match via the DMI_MATCH criteria? If new boot command parameters are discouraged, is there a better paradigm for forced activation that I should investigate?

Any other feedback?

--
Randy Wright Hewlett-Packard Company
Phone: (970) 898-0998 Mail: [email protected]

#3 lore raw

I don't think DMI checking is going to work, since (a) as you say, there's a risk that the ID will inadvertantly change over the lifecycle of the machine, and (b) there may be other machines. So if it's not possible to handle this by catching the MCE, I think we have two options:

1) Declare that any x86 hardware supported by Linux *must* support probing in this address region

2) Don't call probe_roms() by default, but leave it up to the graphics drivers. If they can get the rom by any other means then don't call it.

Signature · 1 line
Matthew Garrett | [email protected]
#4 lore raw
Quoted 6 lines · Matthew Garrett

I don't think DMI checking is going to work, since (a) as you say, there's a risk that the ID will inadvertantly change over the lifecycle of the machine, and (b) there may be other machines. So if it's not possible to handle this by catching the MCE, I think we have two options:

Quoted 6 lines

1) Declare that any x86 hardware supported by Linux *must* support probing in this address region

2) Don't call probe_roms() by default, but leave it up to the graphics drivers. If they can get the rom by any other means then don't call it.

Honestly, (1) is the proper option. Hearing that this is a prototype, I would like to say "fix your bloody hardware/firmware"...

The legacy region is special and will always be special, and so any attempts at making it non-special is a losing battle.

-hpa

Signature · 2 lines
H. Peter Anvin, Intel Open Source Technology Center
I work for Intel.  I don't speak on their behalf.
#5 lore raw
In reply to Matthew Garrett

Hi Matthew,

You made some interesting suggestions:

Quoted 2 lines

1) Declare that any x86 hardware supported by Linux *must* support probing in this address region

On the first: one way to be compliant with such a requirement would be to design systems that implement softfail in this particular region. What about a system that hardfails, but on which the resulting machine check can be handled by the kernel machine check handler? Would appropriate re-ordering of the kernel initialization code to support such systems be acceptable?

Also, let me mention a possible amendment to your first idea: what if the mandate that probing be supported were qualified by some attribute that could be indicated in the UEFI environment? For example: instead of just a hole in the UEFI memory map, what if this range was specifically present and typed as EfiUnusableMemory? Another idea for UEFI systems - but one requiring a UEFI specification change - might be adding a UEFI variable that if present, indicates any area not explicitly included and typed in the UEFI memory map (including the legacy adapter region) must be explicitly avoided by an OS.

Quoted 2 lines

2) Don't call probe_roms() by default, but leave it up to the graphics drivers. If they can get the rom by any other means then don't call it.

One the second idea: there are a quite a lot of video drivers in the kernel source tree. Do you have a suggestion for how to evaluate which ones rely on the setup performed by probe_roms?

Signature · 2 lines
Randy Wright            Hewlett-Packard Company
Phone: (970) 898-0998   Mail: [email protected]
#6 lore raw
Quoted 6 lines · Randy Wright

On the first: one way to be compliant with such a requirement would be to design systems that implement softfail in this particular region. What about a system that hardfails, but on which the resulting machine check can be handled by the kernel machine check handler? Would appropriate re-ordering of the kernel initialization code to support such systems be acceptable?

Good question. I don't maintain that code, so I can't really answer it...

Quoted 9 lines

Also, let me mention a possible amendment to your first idea: what if the mandate that probing be supported were qualified by some attribute that could be indicated in the UEFI environment? For example: instead of just a hole in the UEFI memory map, what if this range was specifically present and typed as EfiUnusableMemory? Another idea for UEFI systems - but one requiring a UEFI specification change - might be adding a UEFI variable that if present, indicates any area not explicitly included and typed in the UEFI memory map (including the legacy adapter region) must be explicitly avoided by an OS.

Yeah, I think if it were marked unusable we could probably justify staying away from it.

Quoted 6 lines
Quoted 2 lines

2) Don't call probe_roms() by default, but leave it up to the graphics drivers. If they can get the rom by any other means then don't call it.

One the second idea: there are a quite a lot of video drivers in the kernel source tree. Do you have a suggestion for how to evaluate which ones rely on the setup performed by probe_roms?

Realistically - intel, radeon and nouveau. Basically, anything that calls pci_map_rom() and is under drivers/gpu/drm. I'll look into a patch that does that.

Signature · 1 line
Matthew Garrett | [email protected]