On 07/16/2015 11:11 AM, Ashwin Chaugule wrote:
On 16 July 2015 at 12:57, Al Stone al.stone@linaro.org wrote:
The existing BAD_MADT_ENTRY macro only checks that the size of the data structure for an MADT subtable matches the length entry in the subtable. This is, unfortunately, not reliable. Nor, as it turns out, does it have anything to do with what the length should be in any particular table.
We introduce the bad_madt_entry() function that uses a data set to do some basic sanity checks on any given MADT subtable. Over time, as the spec changes, we should just be able to add entries to the data set to reflect the changes.
What the data set captures is the allowed MADT subtable length for each type of subtable, for each revision of the specification. While there is a revision number in the MADT that we should be able to use to figure out the proper subtable length, it was not changed when subtables did. And, while there is a major and minor revision in the FADT that could also help, it was not always changed as the subtables changed either. So, the data set captures for each published version of the ACPI spec what the FADT revisions numbers should be, the corresponding MADT revision number, and the subtable types and lengths that were defined at that time.
The sanity checks done are: -- is the length non-zero? -- is the subtable type defined/allowed for the revision of the FADT we're using? -- is the subtable type defined/allowed for the revision of the MADT we're using? -- is the length entry what it should be for this revision of the MADT and FADT?
These checks are more thorough than the previous macro provided, and are now insulated from data structure size changes by ACPICA, which have been the source of other patches in the past.
Now that the bad_madt_entry() function is available, we add code to also invoke it before any subtable handlers are called to use the info in the subtable. Subsequent patches will remove the use of the BAD_MADT_ENTRY macro which is now redundant as a result. Any ACPI functions that use acpi_parse_madt_entries() will always have all of the MADT subtables checked from now on.
Signed-off-by: Al Stone al.stone@linaro.org
drivers/acpi/tables.c | 241 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 241 insertions(+)
diff --git a/drivers/acpi/tables.c b/drivers/acpi/tables.c index 2e19189..5e0415c 100644 --- a/drivers/acpi/tables.c +++ b/drivers/acpi/tables.c @@ -214,6 +214,245 @@ void acpi_table_print_madt_entry(struct acpi_subtable_header *header) } }
+/*
- The Long, Sad, True Story of the MADT
- or
- What does bad_madt_entry() actually do?
- Once upon a time in ACPI 1.0, there was the MADT. It was a nice table,
- and it had two subtables all of its own. But, it was also a pretty
- busy table, too, so over time the MADT gathered up other nice little
- subtables. By the time ACPI 6.0 came around, the MADT had 16 of the
- little guys.
- Now, the MADT kept a little counter around for the subtables. In fact,
- it kept two counters: one was the revision level, which was supposed to
- change when new subtables came to be, or as the ones already around grew
- up. The second counter was a type number, because the MADT needed a unique
- type for each subtable so he could tell them apart. But, sometimes the
- MADT got so busy, he forgot to increment the revision level when he needed
- to. Fortunately, the type counter kept increasing since that's the only
- way the MADT could find each little subtable. It just wouldn't do to have
- every subtable called Number 6.
- In the next valley over, a castle full of wizards was watching the MADT
- and made a pact to keep their own counter. Every time the MADT found a
- new subtable, or a subtable grew up, the wizards promised they would
- increment their counter. Well, wizards being the forgetful sort, they
- didn't alway do that. And, since there quite a lot of them, they
- couldn't always remember who was supposed to keep track of the MADT,
- especially if dinner was coming up soon. Their counter was called the
- spec version.
- Every now and then, the MADT would gather up all its little subtables
- and take them in to the cobbler to get new boots. This was a very, very
- meticulous cobbler, so every time they came, he wrote down all the boot
- sizes for all of the little subtables. The cobbler would ask each subtable
- for its length, check that against his careful notes, and then go get the
- right boots. Sometimes, a little subtable would change a bit, and their
- length did not match what the cobbler had written down. If the wizards
- or the MADT had incremented their counters, the cobbler would breath a
- sigh of relief and write down the new length as the right one. But, if
- none of the counters had changed, this would make the cobbler very, very
- mad. He couldn't tell if he had the right size boots or not for the
- little subtable. He would have to *guess* and this really bugged him.
- Well, when the cobbler got mad like this, he would go into hiding. He
- would not make or sell any boots. He would not go out at all. Pretty
- soon, the coffee shop would have to close because the cobbler wasn't
- coming by twice a day any more. Then the grocery store would have to
- close because he wouldn't eat much. After a while, everyone would panic
- and have to move from the village and go live with all their relatives
- (usually the ones they didn't like very much).
- Eventually, the cobbler would work his way out of his bad mood, and
- open up his boot business again. Then, everyone else could move back
- to the village and restart their lives, too.
- Fortunately, we have been able to collect up all the cobbler's careful
- notes (and we wrote them down below). We'll have to keep checking these
- notes over time, too, just as the cobbler does. But, in the meantime,
- we can avoid the panic and the reboot since we can make sure that each
- subtable is doing okay. And that's what bad_madt_entry() does.
Best thing I've read in the kernel in a loong time! Please bring some of that coffee to LCU in Sept! :)
When I read about castles and wizards here, I thought you'd include - Sorry Mario but the princess is in another castle. - in there somewhere. But honestly what you've done is way better.
Cheers, Ashwin.
Thanks :).
I'm still not sure whether to leave it in or not, but I definitely enjoyed writing it.