Bug 963 - Module-level code issues
Summary: Module-level code issues
Status: RESOLVED FIXED
Alias: None
Product: ACPICA
Classification: Unclassified
Component: Core/Interpreter (show other bugs)
Version: unspecified
Hardware: All Any-All
: P1 major
Assignee: Lv Zheng
URL:
Keywords:
: 763 (view as bug list)
Depends on:
Blocks:
 
Reported: 2012-06-20 10:44 PDT by Bob Moore
Modified: 2018-02-09 12:50 PST (History)
7 users (show)

See Also:


Attachments
acpi dump 4.9.3-200 for acpi errors (873.85 KB, text/plain)
2017-01-17 20:25 PST, mrh
Details
dmidecode for comment #13 (23.37 KB, text/plain)
2017-01-17 20:35 PST, mrh
Details
acpidump for Eurocom Commander (574.43 KB, text/plain)
2017-02-10 19:56 PST, Adam Van Ymeren
Details
dmidecode for Eurocom Commander, same machine as attachmetn 1087 (15.17 KB, text/plain)
2017-02-10 19:57 PST, Adam Van Ymeren
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Bob Moore 2012-06-20 10:44:44 PDT
There are still some issues pertaining to the support of the technically illegal "module-level code". This is executable AML code that appears outside of any control method.

1) Forward references are not supported.
2) Only a limited subset of AML opcodes are supported.

The solution to these issues may require some large changes to the table loading mechanism.

A possible solution may be something like this:

Execute the entire “root” of the table as a single, large control method. Would perform one or two load passes, then an execute pass. The main difference from a regular method would be that all objects that are created are permanent.

After this, the table would be "loaded" into the namespace, and all of the module-level code will have been executed.

This provides a general-purpose solution that solves the problems above.
Comment 1 Lv Zheng 2015-02-09 19:31:12 PST
IMO, this bug implies the divergent handling of TermList between Linux AML parser and Windows AML parser.

Let me ask several questions about this:

1. IMO, there is no forward reference in AML.
   We can identify that Windows doesn't support forward reference in Method.
   My question is do we support forward reference in module level code?
2. There are several TermList related AML syntax:
     AMLCode := DefBlockHeader TermList
     DefScope := ScopeOp PkgLength NameString TermList
     DefMethod := MethodOp PkgLength NameString MethodFlags TermList
     DefElse := Nothing | <ElseOp PkgLength TermList>
     DefIfElse := IfOp PkgLength Predicate TermList DefElse
     DefWhile := WhileOp PkgLength Predicate TermList
   I can see ACPICA supports module level code for If/Else/While TermList.
   And we know for Method, TermList needn't to be descent parsed.
   But for Scope, what should we do?
   I can even see an issue in iASL which doesn't allow module level code to be compiled in Scope.
   Is there any limitation for doing so for Scope?

Thanks and best regards
-Lv
Comment 2 Bob Moore 2015-02-17 10:35:43 PST
The bottom line is that ACPICA parser performs a two-pass parse for ACPI tables (DSDT/SSDT), while ignoring control methods.

Individual control methods are only parsed once, so forward references are not supported.

I'm not sure if any of this is in the actual ACPI spec.
Comment 3 Lv Zheng 2015-02-24 18:35:24 PST
According to the spec, where TermList is defined, we should also parse the module level code once. There is no explicit definition in the AML spec that the module level code should be parsed twice. If we took the AML spec as the "priori" concepts, then the 2-pass parsing might be the "posteriori" errpr resulted from the bug fixes.
We parsed the module level code twice because of the bug that we didn't support TermList or any list of terms in the ParseLoop correctly, which made the possible module level execution impossible.
Comment 4 Lv Zheng 2015-02-24 18:46:49 PST
IMO, the new direction is worthy of try.
We could do the following things to avoid regressions:
1. fix TermList parsing in the parser component, by doing so, most of the module level code will be executed in the first-pass parsing.
2. add an option for the second-pass parsing.
3. test the whole ASLTS with second-pass parsing disabled and figure out the cases that cannot be supported by this mode. IMO, only limited forward reference in the module level code cannot be supported in this mode. Some of them may because of the "SimpleName"/"SuperName"/"Opcode types" support issue in ACPICA.
4. re-validate the cases on Windows to figure out which mode is the the way Windows is parsing the module level code.
Comment 5 Lv Zheng 2015-03-08 22:20:17 PDT
*** Bug 763 has been marked as a duplicate of this bug. ***
Comment 6 Lv Zheng 2015-04-16 18:32:03 PDT
Hi, Bob

I did following experiments:

1. In acpiexec
Move address space handler initialization before acpi_load_tables().
Combine 2 load pass into 1 execute pass.
Make AcpiPsLinkModuleCode() and AcpiNsExecModuleCodeList() no-op.
With some efforts around the WalkState->MethodNode and ACPI_PARSE_MODULE_LEVEL, everything works.
So this is not a big issue for ACPICA.

2. In Linux
I tried to move address space handler initialization before acpi_load_tables().
But kernel panic can be obeserved during boot.
I tried to move the acpi_load_tables() to a later initialization step before acpi_initialize_objects(), then graphics driver seems not working any more. We need to filter out which namespace nodes are referenced during acpi_early_init() and acpi_bus_init().

So this seems to be a big issue for ACPICA OSPM users.

Do you know any historical Linux reasons the load parsing is implemented in such a way.

Thanks and best regards
-Lv
Comment 7 Lv Zheng 2016-02-05 22:12:05 PST
You can find the required fixes here:
https://github.com/acpica/acpica/pull/120
Comment 8 Lv Zheng 2016-06-29 02:33:28 PDT
Fixes are updated here:
https://github.com/acpica/acpica/pull/134

Thanks
-Lv
Comment 9 Lv Zheng 2016-09-02 01:07:55 PDT
Upstreamed on top of the lock fixes.
So re-close it.
Comment 10 Lv Zheng 2016-12-11 23:12:13 PST
Linking Linux kernel bug here:
https://bugzilla.kernel.org/show_bug.cgi?id=189931

Re-opening as this option is not enabled.
Comment 11 Lv Zheng 2016-12-11 23:16:37 PST
Linking Linux kernel bug here:
https://bugzilla.kernel.org/show_bug.cgi?id=153541
Comment 12 Lv Zheng 2016-12-22 18:12:13 PST
There is still no OSPM enabling this fix.
So re-open it.

The issue is blocked by the following bug:
https://bugs.acpica.org/show_bug.cgi?id=1333

Thanks
Lv
Comment 13 Lv Zheng 2017-01-15 21:29:09 PST
Linking a kernel bug here:
https://bugzilla.kernel.org/show_bug.cgi?id=192621

Thanks
Comment 14 mrh 2017-01-17 20:25:51 PST
Created attachment 1080 [details]
acpi dump 4.9.3-200 for acpi errors

Fatal errors occur in Kernel 4.9.3 that did not occur with 4.8.15 and earlier
Comment 15 mrh 2017-01-17 20:35:47 PST
Created attachment 1081 [details]
dmidecode for comment #13

These issues occurred with Kernel 4.9.3 and where not present in kernel 4.8.15 or earlier. See comment #13 above
Comment 16 Adam Van Ymeren 2017-02-10 19:56:39 PST
Created attachment 1087 [details]
acpidump for Eurocom Commander

acpidump that parses with fatal errors as describe in kernel bug here.

https://bugzilla.kernel.org/show_bug.cgi?id=192621
Comment 17 Adam Van Ymeren 2017-02-10 19:57:30 PST
Created attachment 1088 [details]
dmidecode for Eurocom Commander, same machine as attachmetn 1087
Comment 18 Bob Moore 2017-03-13 12:17:33 PDT
Lv,
Can we close this one?
Comment 19 Adam Van Ymeren 2017-05-30 09:40:37 PDT
It looks like module level code is still disabled by default.

https://github.com/acpica/acpica/blob/master/source/include/acpixf.h#L312

Are there plans to enable this by default eventually?
Comment 20 Lv Zheng 2017-06-25 23:49:21 PDT
New report here:
https://bugzilla.kernel.org/show_bug.cgi?id=196165
Comment 21 Bob Moore 2017-07-28 13:09:17 PDT
so, can this be closed?
Comment 22 Anton Kochkov 2017-08-12 10:56:01 PDT
From the explanation I understand that now instead of breaking changes the 
"package" pull request would not be merged, but the issue was solved in a different, slighter way:

"The pull request doesn't fix the problem while the fix is already upstreamed.
The upstreamed fix just cannot be enabled as it is blocked by the issue fixed by the PR.
However the PR wouldn't be accepted by ACPICA upstream.
It's been planning to do a slighter change to still treat in-package name string as object reference."

But at the same time it is still disabled in master. So, what exactly preventing from enabling it, if it's fixed? Or there are still some problems with it? If yes - why to urge to close this issue?
Comment 23 Lv Zheng 2017-10-17 00:22:59 PDT
New report here:
https://bugzilla.kernel.org/show_bug.cgi?id=197207

Thanks
Lv
Comment 24 Erik Kaneda 2018-01-05 14:58:09 PST
New bug report here:
https://bugzilla.kernel.org/show_bug.cgi?id=198051

Fixing module-level code could fix this issue.
Comment 25 Erik Kaneda 2018-01-23 10:13:51 PST
(In reply to erik.schmauss from comment #24)
> New bug report here:
> https://bugzilla.kernel.org/show_bug.cgi?id=198051
> 
> Fixing module-level code could fix this issue.

This bug reveals issues in forward referencing of package elements.
Comment 26 Erik Kaneda 2018-01-23 10:17:38 PST
Linking kernel bugzilla:
https://bugzilla.kernel.org/show_bug.cgi?id=198515

This is a module-level code issue and doesn't involve forward references of package elements.
Comment 27 Bob Moore 2018-02-09 12:50:00 PST
ACPICA version 20180209:

We believe that all of the various issues in this report are resolved in 20180209.

The new architecture for the module-level code is now the default.