Skip to content

Conversation

@opsiff
Copy link
Member

@opsiff opsiff commented Mar 24, 2025

mainline inclusion
from mainline-v6.8-rc1
category: bugfix

Notify () handlers, like GPE handlers, are only allowed to run on CPU0
now out of the concern that they might trigger an SMM trap leading to
memory corruption. Namely, in some cases, SMM code might corrupt memory
if not run on CPU0.

However, Notify () handlers are registered by kernel code and they
are not likely to evaluate AML that would trigger an SMM trap. In
fact, many of them don't even evaluate any AML at all and even if
they do, that AML may as well be evaluated in other code paths. In
other words, they are not special from the AML evaluation perspective,
so there is no real reason to treat them in any special way.

Accordingly, allow Notify () handlers, unlike GPE handlers, to be
executed by all CPUs in the system.

Also adjust the allocation of the "notify" workqueue to allow multiple
handlers to be executed at the same time, because they need not be
serialized.

Signed-off-by: Rafael J. Wysocki [email protected]
Reviewed-by: Andy Shevchenko [email protected]
(cherry picked from commit e2ffcda)
Signed-off-by: Wentao Guan [email protected]

Summary by Sourcery

Allow Notify() handlers to run on all CPUs, as they are not special from the AML evaluation perspective and do not need to be serialized. Adjust the allocation of the "notify" workqueue to allow multiple handlers to be executed at the same time.

Bug Fixes:

  • Allow Notify () handlers to run on all CPUs.
  • Adjust the allocation of the "notify" workqueue to allow multiple handlers to be executed at the same time.

icojb25 and others added 4 commits March 24, 2025 10:23
mainline inclusion
from mainline-v6.7-rc1
category: misc

Fix up four places where there is no empty line after declarations of
local variables in a function (as per the kernel coding style).

Signed-off-by: Jonathan Bergh <[email protected]>
[ rjw: Subject and changelog edits ]
Signed-off-by: Rafael J. Wysocki <[email protected]>
(cherry picked from commit a1da3b7)
Signed-off-by: Wentao Guan <[email protected]>
mainline inclusion
from mainline-v6.8-rc1
category: misc

Reduce the number of checks and goto labels related to error handling
in acpi_os_execute() and drop the status local variable, which turns
out to be redundant, from it.

No intentional functional impact.

Signed-off-by: Rafael J. Wysocki <[email protected]>
Reviewed-by: Andy Shevchenko <[email protected]>
(cherry picked from commit 392829e)
Signed-off-by: Wentao Guan <[email protected]>
mainline inclusion
from mainline-v6.8-rc1
category: misc

Replace the 3-branch if () statement used for selecting the target
workqueue in acpi_os_execute() with a switch () one that is more
suitable for this purpose and carry out the work item initialization
before it to avoid code duplication.

No intentional functional impact.

Signed-off-by: Rafael J. Wysocki <[email protected]>
Reviewed-by: Andy Shevchenko <[email protected]>
(cherry picked from commit 3f3a259)
Signed-off-by: Wentao Guan <[email protected]>
mainline inclusion
from mainline-v6.8-rc1
category: bugfix

Notify () handlers, like GPE handlers, are only allowed to run on CPU0
now out of the concern that they might trigger an SMM trap leading to
memory corruption.  Namely, in some cases, SMM code might corrupt memory
if not run on CPU0.

However, Notify () handlers are registered by kernel code and they
are not likely to evaluate AML that would trigger an SMM trap.  In
fact, many of them don't even evaluate any AML at all and even if
they do, that AML may as well be evaluated in other code paths.  In
other words, they are not special from the AML evaluation perspective,
so there is no real reason to treat them in any special way.

Accordingly, allow Notify () handlers, unlike GPE handlers, to be
executed by all CPUs in the system.

Also adjust the allocation of the "notify" workqueue to allow multiple
handlers to be executed at the same time, because they need not be
serialized.

Signed-off-by: Rafael J. Wysocki <[email protected]>
Reviewed-by: Andy Shevchenko <[email protected]>
(cherry picked from commit e2ffcda)
Signed-off-by: Wentao Guan <[email protected]>
@sourcery-ai
Copy link

sourcery-ai bot commented Mar 24, 2025

Reviewer's Guide by Sourcery

This pull request modifies the ACPI subsystem to allow Notify handlers to run on all CPUs, addressing concerns about unnecessary restrictions. It also adjusts the notify workqueue to enable concurrent execution of multiple handlers.

Sequence diagram for ACPI Notify Handler Execution

sequenceDiagram
  participant Kernel
  participant ACPI Subsystem
  participant Notify Handler

  activate Kernel
  Kernel->>ACPI Subsystem: acpi_os_execute(OSL_NOTIFY_HANDLER, function, context)
  activate ACPI Subsystem
  ACPI Subsystem->>kacpi_notify_wq: queue_work(kacpi_notify_wq, &dpc->work)
  activate kacpi_notify_wq
  kacpi_notify_wq->>Notify Handler: acpi_os_execute_deferred(work)
  activate Notify Handler
  Notify Handler->>ACPI Subsystem: function(context)
  deactivate Notify Handler
  deactivate kacpi_notify_wq
  ACPI Subsystem-->>Kernel: AE_OK
  deactivate ACPI Subsystem
  deactivate Kernel
Loading

Sequence diagram for ACPI GPE Handler Execution

sequenceDiagram
  participant Kernel
  participant ACPI Subsystem
  participant GPE Handler

  activate Kernel
  Kernel->>ACPI Subsystem: acpi_os_execute(OSL_GPE_HANDLER, function, context)
  activate ACPI Subsystem
  ACPI Subsystem->>kacpid_wq: queue_work_on(0, kacpid_wq, &dpc->work)
  activate kacpid_wq
  kacpid_wq->>GPE Handler: acpi_os_execute_deferred(work)
  activate GPE Handler
  GPE Handler->>ACPI Subsystem: function(context)
  deactivate GPE Handler
  deactivate kacpid_wq
  ACPI Subsystem-->>Kernel: AE_OK
  deactivate ACPI Subsystem
  deactivate Kernel
Loading

Updated class diagram for acpi_os_execute

classDiagram
  class acpi_os_execute {
    +acpi_status acpi_os_execute(acpi_execute_type type, acpi_osd_exec_callback function, void *context)
  }
  note for acpi_os_execute "Notify handlers can now run on all CPUs"
Loading

File-Level Changes

Change Details Files
Allowed Notify handlers to run on all CPUs and adjusted the allocation of the notify workqueue to allow multiple handlers to be executed concurrently.
  • Modified acpi_os_execute to allow OSL_NOTIFY_HANDLER to be executed by all CPUs.
  • Adjusted the allocation of the kacpi_notify_wq workqueue to allow multiple handlers to be executed at the same time by changing the last argument of alloc_workqueue from 1 to 0.
drivers/acpi/osl.c

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @opsiff - I've reviewed your changes - here's some feedback:

Overall Comments:

  • The removal of status and goto out_thread seems like a significant change; can you confirm it's intended and doesn't introduce regressions?
  • Consider adding a comment explaining why queue_work_on(0, ...) is still needed for OSL_GPE_HANDLER.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@deepin-ci-robot
Copy link

deepin pr auto review

代码审查意见:

  1. acpi_os_execute函数中,移除了不必要的变量status,简化了错误处理逻辑。这是一个好的改动,因为它减少了代码的复杂性和潜在的错误点。

  2. acpi_os_execute函数中,将queue_workqueue_work_on的调用移到了switch语句中,这提高了代码的可读性和可维护性。

  3. acpi_os_execute函数中,移除了goto语句,改用return语句直接返回错误状态。这是一个好的改动,因为它简化了错误处理逻辑,避免了多层嵌套的goto语句。

  4. acpi_os_initialize函数中,将kacpi_notify_wqalloc_workqueue调用中的参数从1改为0,这可能是为了减少工作队列的并发性。需要确认这一改动是否符合系统的设计要求。

  5. acpi_os_prepare_sleepacpi_os_prepare_extended_sleep函数中,移除了不必要的变量rc,简化了代码。这是一个好的改动,因为它减少了代码的复杂性和潜在的错误点。

  6. acpi_cpu_flags acpi_os_acquire_lock函数中,移除了不必要的变量flags,简化了代码。这是一个好的改动,因为它减少了代码的复杂性和潜在的错误点。

总体来说,代码的改动提高了代码的可读性和可维护性,简化了错误处理逻辑,并且没有引入新的问题。

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from opsiff. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@opsiff opsiff merged commit 66df5ca into deepin-community:linux-6.6.y Mar 24, 2025
5 of 7 checks passed
@opsiff
Copy link
Member Author

opsiff commented Mar 24, 2025

在HUAWEI MateBook d14 YTGZ model上测试通过

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants