Skip to contentSkip to conversation

x86, amd_ucode: Support multiple container files appended together

PATCH Boris Ostrovsky 3 participants 7 messages Jun 26, 2014 – Jun 27, 2014

lore
Share & tools
lore
#0 lore raw

On 06/26/2014 11:03 AM, Aravind Gopalakrishnan wrote:

On 6/26/2014 8:14 AM, Boris Ostrovsky wrote:

+ /*
+ * Multiple container file support:
+ * 1. check if this container file has equiv_cpu_id match
+ * 2. If not, fast-fwd to next container file
+ */
+ while ( offset < bufsize )
+ {
+ error = install_equiv_cpu_table(mc_amd, buf, &offset);
+
+ if ( !error &&
+ find_equiv_cpu_id(mc_amd->equiv_cpu_table, current_cpu_id,
+ &equiv_cpu_id) )
+ break;
+
+ /*
+ * Could happen as we advance 'offset' early
+ * in install_equiv_cpu_table
+ */
+ if ( offset > bufsize )
+ {
+ printk(KERN_ERR "microcode: Microcode buffer
overrun\n");
+ return -EINVAL;
+ }
+
+ error = container_fast_forward(buf, bufsize -
offset, &offset);
+ if ( error )
+ {
+ printk(KERN_ERR "microcode: CPU%d incorrect or
corrupt container file\n"
+ "microcode: Failed to update patch level. "
+ "Current lvl:%#x\n", cpu,
uci->cpu_sig.rev);
+ goto out;
+ }
+ }
+

I just realized that I don't understand something: if you have two merged container files, both having an entry for current processor in the equivalence table but only the second file having the actual patch (or at least the patch with higher version), will we get to load that patch?

We will not come across such a situation:
One container has patch files for families 10h,11h,12h,14h and the other has patches for 15h.
So there will be an equiv_cpu_id match in (at least and) only *one* of the containers.
(If there ever are patches for 16h, then I suspect it will have a separate container of it's own. So there will not be any clashes with older containers)

Besides, the patches themselves are not incremental, i.e; If there is a newer patch, then it handles all errata/bugs that were handled by the previous patch and then some.
Which means, you will not have a container that has two patches for the same processor.
So, *strictly speaking*, even the loop to get_ucode_from_buffer_amd() till the end of buffer is not necessary once we
have already applied a patch.

But, to change this behavior now will need more logic rework..

I don't think there is a whole lot of work/testing (especially since I am not the one doing it ;-)) --- you just need to skip header and equivalence table of the next container.

if ( mpbuf->type != UCODE_UCODE_TYPE )

{
    if ( *(const uint32_t *)buf == UCODE_MAGIC )
    {
        struct mpbhdr *mpbuf = (const struct mpbhdr *)&buf[2]; // or [1]?
        *offset += mpbuf->len + CONT_HDR_SIZE + 4;  // I think 4, to skip MAGIC
                                                    // and next word.
        // Now we've fast-forwarded past header and eq. table
        return 0; // or, goto beginning?
    }
}

Will that work?

Then again, if it works fine right now, would we really want to change this behavior?

Thanks,
-Aravind.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#1 lore raw
Quoted 47 lines · Boris Ostrovsky

+
+ error = container_fast_forward(buf, bufsize -
offset, &offset);
+ if ( error )
+ {
+ printk(KERN_ERR "microcode: CPU%d incorrect
or corrupt container file\n"
+ "microcode: Failed to update patch
level. "
+ "Current lvl:%#x\n", cpu,
uci->cpu_sig.rev);
+ goto out;
+ }
+ }
+

I just realized that I don't understand something: if you have two merged container files, both having an entry for current processor in the equivalence table but only the second file having the actual patch (or at least the patch with higher version), will we get to load that patch?

We will not come across such a situation:
One container has patch files for families 10h,11h,12h,14h and the other has patches for 15h.
So there will be an equiv_cpu_id match in (at least and) only *one* of the containers.
(If there ever are patches for 16h, then I suspect it will have a separate container of it's own. So there will not be any clashes with older containers)

Besides, the patches themselves are not incremental, i.e; If there is a newer patch, then it handles all errata/bugs that were handled by the previous patch and then some. Which means, you will not have a container that has two patches for the same processor.
So, *strictly speaking*, even the loop to get_ucode_from_buffer_amd() till the end of buffer is not necessary once we
have already applied a patch.

But, to change this behavior now will need more logic rework..

Quoted 7 lines

I don't think there is a whole lot of work/testing (especially since I am not the one doing it ;-)) --- you just need to skip header and equivalence table of the next container.

if ( mpbuf->type != UCODE_UCODE_TYPE )

{
     if ( *(const uint32_t *)buf == UCODE_MAGIC )
     {
         struct mpbhdr *mpbuf = (const struct mpbhdr *)&buf[2]; // or [1]?

Neither will work as we will need to first advance buf 4 bytes.. (but I get your point) Regardless, this is not necessary.
Let me clarify (below)

Quoted 8 lines
         *offset += mpbuf->len + CONT_HDR_SIZE + 4;  // I think 4, to skip MAGIC
                                                     // and next word.
         // Now we've fast-forwarded past header and eq. table
         return 0; // or, goto beginning?
     }
}

Will that work?

But we don't actually need to parse the second container for reasons given in the previous thread.

Example scenarios-
1. Order of containers in initrd: f15h container, container for remaining families.
- equiv_cpu_id match for first container (surely you are on a f15h model)
- parse this container, find correct patch and try to apply
- No need to parse second container as it will not have patches for
f15h.
- no match for 1st container, but match on 2nd, then current
processor is in set [f10h,f14h]
- parse this container, find correct patch and try to apply
- no match on both.
- borked containers. So, abort.

2. Order of containers: container for families from f10h-f14h; container for f15h
- equiv_cpu_id match for 1st container (surely you are on some family
in the set of [f10h, f14h])
- Parse container, find patch, try to apply
- No need to parse second container as it will not have patches for
f10h-f14h
- found match on 2nd, then current processor is a f15h model,
- parse container, find patch, try to apply
- no match
- borked container. So abort.

The process(,scripts) to create containers ensure that we only have patches for f10h-f14h on 'microcode_amd.bin' and patches for f15h models (could be different model/stepping values) on microcode_amd_fam15h.bin

So it is safe to assume that we we only have a matching equiv_id in only one of the containers.

-Aravind.

#2 lore raw
Quoted 95 lines · Aravind Gopalakrishnan
Quoted 47 lines · Boris Ostrovsky

+
+ error = container_fast_forward(buf, bufsize -
offset, &offset);
+ if ( error )
+ {
+ printk(KERN_ERR "microcode: CPU%d incorrect
or corrupt container file\n"
+ "microcode: Failed to update patch
level. "
+ "Current lvl:%#x\n", cpu,
uci->cpu_sig.rev);
+ goto out;
+ }
+ }
+

I just realized that I don't understand something: if you have two merged container files, both having an entry for current processor in the equivalence table but only the second file having the actual patch (or at least the patch with higher version), will we get to load that patch?

We will not come across such a situation:
One container has patch files for families 10h,11h,12h,14h and the other has patches for 15h.
So there will be an equiv_cpu_id match in (at least and) only *one* of the containers.
(If there ever are patches for 16h, then I suspect it will have a separate container of it's own. So there will not be any clashes with older containers)

Besides, the patches themselves are not incremental, i.e; If there is a newer patch, then it handles all errata/bugs that were handled by the previous patch and then some. Which means, you will not have a container that has two patches for the same processor.
So, *strictly speaking*, even the loop to get_ucode_from_buffer_amd() till the end of buffer is not necessary once we
have already applied a patch.

But, to change this behavior now will need more logic rework..

Quoted 8 lines

I don't think there is a whole lot of work/testing (especially since I am not the one doing it ;-)) --- you just need to skip header and equivalence table of the next container.

if ( mpbuf->type != UCODE_UCODE_TYPE )

{
     if ( *(const uint32_t *)buf == UCODE_MAGIC )
     {
         struct mpbhdr *mpbuf = (const struct mpbhdr *)&buf[2]; // or 

[1]?

Neither will work as we will need to first advance buf 4 bytes.. (but I get your point) Regardless, this is not necessary.
Let me clarify (below)

Quoted 9 lines
         *offset += mpbuf->len + CONT_HDR_SIZE + 4;  // I think 4, to 
skip MAGIC
                                                     // and next word.
         // Now we've fast-forwarded past header and eq. table
         return 0; // or, goto beginning?
     }
}

Will that work?

But we don't actually need to parse the second container for reasons given in the previous thread.

Example scenarios-
1. Order of containers in initrd: f15h container, container for remaining families.
- equiv_cpu_id match for first container (surely you are on a f15h
model)
- parse this container, find correct patch and try to apply
- No need to parse second container as it will not have patches
for f15h.
- no match for 1st container, but match on 2nd, then current
processor is in set [f10h,f14h]
- parse this container, find correct patch and try to apply
- no match on both.
- borked containers. So, abort.

2. Order of containers: container for families from f10h-f14h; container for f15h
- equiv_cpu_id match for 1st container (surely you are on some
family in the set of [f10h, f14h])
- Parse container, find patch, try to apply
- No need to parse second container as it will not have patches
for f10h-f14h
- found match on 2nd, then current processor is a f15h model,
- parse container, find patch, try to apply
- no match
- borked container. So abort.

Quoted 4 lines

The process(,scripts) to create containers ensure that we only have patches for f10h-f14h on 'microcode_amd.bin' and patches for f15h models (could be different model/stepping values) on microcode_amd_fam15h.bin

So it is safe to assume that we we only have a matching equiv_id in only one of the containers.

The trouble is that if I have two files in my hands, both called microcode_amd_fam15h.bin, I don't know which one is the more up-to-date (would be nice to have a tool to print file info).

Of course, one can argue that in that case I shouldn't be using neither but HW makes its own verification of patches so in principle trying both should be safe (provided that SW tries not to load older revision).

-boris

#3 lore raw
Quoted 11 lines · Boris Ostrovsky
Quoted 6 lines

The process(,scripts) to create containers ensure that we only have patches for f10h-f14h on 'microcode_amd.bin' and patches for f15h models (could be different model/stepping values) on microcode_amd_fam15h.bin

So it is safe to assume that we we only have a matching equiv_id in only one of the containers.

The trouble is that if I have two files in my hands, both called microcode_amd_fam15h.bin, I don't know which one is the more up-to-date (would be nice to have a tool to print file info).

Of course, one can argue that in that case I shouldn't be using neither but HW makes its own verification of patches so in principle trying both should be safe (provided that SW tries not to load older revision).

Hmm, yeah... But this is a pretty contrived case and I'm still not completely convinced this is something we should handle.. Here are my thoughts:
- If such a case arises, one can just pull the latest containers which are published
- here:
https://git.kernel.org/cgit/linux/kernel/git/firmware/linux-firmware.git/tree/amd-ucode

- and here: http://www.amd64.org/microcode.html
- distros also keep themselves updated by pulling the binaries from
above links
- We can add documentation notes stating to the effect that users(sysadmins) are better off not concatenating two containers of same processor family.
- It won't break anything, but you just might end up on a
not-so-latest microcode patch level
- And also point to above links to resolve such deadlock situations
- If you would still prefer that we handle this case, then we probably should not do it as you described.
- The proper way would be to go back to the start of the 1st while loop.
- Because we can go back to find_equiv_cpu_id() and take things
from there again..
- So, more logic rework..
(I'm ok with re-working the code, but do let me know if this a case we
should care for..)

Thanks,
-Aravind.

#4 lore raw
Quoted 19 lines · Aravind Gopalakrishnan
Quoted 11 lines · Boris Ostrovsky
Quoted 6 lines

The process(,scripts) to create containers ensure that we only have patches for f10h-f14h on 'microcode_amd.bin' and patches for f15h models (could be different model/stepping values) on microcode_amd_fam15h.bin

So it is safe to assume that we we only have a matching equiv_id in only one of the containers.

The trouble is that if I have two files in my hands, both called microcode_amd_fam15h.bin, I don't know which one is the more up-to-date (would be nice to have a tool to print file info).

Of course, one can argue that in that case I shouldn't be using neither but HW makes its own verification of patches so in principle trying both should be safe (provided that SW tries not to load older revision).

Hmm, yeah... But this is a pretty contrived case and I'm still not completely convinced this is something we should handle.. Here are my thoughts:
- If such a case arises, one can just pull the latest containers which
are published
- here:
https://git.kernel.org/cgit/linux/kernel/git/firmware/linux-firmware.git/tree/amd-ucode

Quoted 7 lines

- and here: http://www.amd64.org/microcode.html
- distros also keep themselves updated by pulling the binaries from
above links
- We can add documentation notes stating to the effect that users(sysadmins) are better off not concatenating two containers of same processor family.
- It won't break anything, but you just might end up on a
not-so-latest microcode patch level

AFAIK the code always picks the latest version of the patch.

Quoted 10 lines

- And also point to above links to resolve such deadlock situations
- If you would still prefer that we handle this case, then we probably should not do it as you described.
- The proper way would be to go back to the start of the 1st while
loop.
- Because we can go back to find_equiv_cpu_id() and take things
from there again..
- So, more logic rework..
(I'm ok with re-working the code, but do let me know if this a case
we should care for..)

I think it's worth doing.

-boris

#5 lore raw
In reply to Boris Ostrovsky
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 26.06.14 at 22:00, <[email protected]> wrote:

The trouble is that if I have two files in my hands, both called microcode_amd_fam15h.bin, I don't know which one is the more up-to-date (would be nice to have a tool to print file info).

Of course, one can argue that in that case I shouldn't be using neither but HW makes its own verification of patches so in principle trying both should be safe (provided that SW tries not to load older revision).

I think we should focus on getting things to work with realistic blobs, i.e. such that distros and their tools would generate. If you update a respective package, it'll be clear which blob is the latest, and there's generally not going to be two blobs for the same family put on a single system. People obtaining ucode blobs manually from elsewhere should know what they're doing and not try to paste together two of them targeting the same family.

Jan

#6 lore raw
Quoted 8 lines · Jan Beulich
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 26.06.14 at 22:00, <[email protected]> wrote:

The trouble is that if I have two files in my hands, both called microcode_amd_fam15h.bin, I don't know which one is the more up-to-date (would be nice to have a tool to print file info).

Of course, one can argue that in that case I shouldn't be using neither but HW makes its own verification of patches so in principle trying both should be safe (provided that SW tries not to load older revision).

Quoted 7 lines

I think we should focus on getting things to work with realistic blobs, i.e. such that distros and their tools would generate. If you update a respective package, it'll be clear which blob is the latest, and there's generally not going to be two blobs for the same family put on a single system. People obtaining ucode blobs manually from elsewhere should know what they're doing and not try to paste together two of them targeting the same family.

Ok.

I only mention this scenario because I myself needed to deal with this (on more than one occasion, in fact) when I had two containers and didn't know which one is which.

-boris