Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

acpi_tables: fix the access_size of GenericAddress #38

Merged
merged 1 commit into from
Jun 27, 2024

Conversation

Lencerf
Copy link
Contributor

@Lencerf Lencerf commented Jun 26, 2024

Summary of the PR

Without the fix, the code gives
1 for Byte access
2 for Word access
4 for Dword access
8 for QWord access.

However, As per ACPI 6.4 spec Sec.5.2.3.2 [1], the access_size should be
1 for Byte access
2 for Word access
3 for Dword access
4 for QWord access.

The fix takes QEMU's implementation[2] as a reference. A related patch[3] has been merged into crosvm.

[1] https://uefi.org/htmlspecs/ACPI_Spec_6_4_html/05_ACPI_Software_Programming_Model/ACPI_Software_Programming_Model.html#generic-address-structure-gas

[2] https://github.com/qemu/qemu/blob/6a4180af9686830d88c387baab6d79563ce42a15/hw/acpi/erst.c#L218

[3] https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5394229

Requirements

Before submitting your PR, please make sure you addressed the following
requirements:

  • All commits in this PR have Signed-Off-By trailers (with
    git commit -s), and the commit message has max 60 characters for the
    summary and max 75 characters for each description line.
  • All added/changed functionality has a corresponding unit/integration
    test.
  • All added/changed public-facing functionality has entries in the "Upcoming
    Release" section of CHANGELOG.md (if no such section exists, please create one).
  • Any newly added unsafe code is properly documented.

rbradford
rbradford previously approved these changes Jun 26, 2024
src/sdt.rs Outdated
@@ -25,7 +25,7 @@ impl GenericAddress {
address_space_id: 1,
register_bit_width: 8 * core::mem::size_of::<T>() as u8,
register_bit_offset: 0,
access_size: core::mem::size_of::<T>() as u8,
access_size: core::mem::size_of::<T>().trailing_zeros() as u8 + 1,
Copy link
Collaborator

@rbradford rbradford Jun 26, 2024

Choose a reason for hiding this comment

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

I'm not sure I would have done it like this instead i'd have had an enum for the access sizes and then mapped the byte length into that and then made it #[repr(u8)] and used that. But this trailing_zeros solution does match QEMU.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How about the following?

        let access_size = match core::mem::size_of::<T>() {
            1 => 1,
            2 => 2,
            4 => 3,
            8 => 4,
            _ => 0,
        };

If it looks fine, the next question is, since this is a public API and there is no way to return an error, in the _ case, should we silently set it to 0 (Undefined (legacy reasons)), or just panic?

Copy link
Collaborator

Choose a reason for hiding this comment

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

How about the following?

        let access_size = match core::mem::size_of::<T>() {
            1 => 1,
            2 => 2,
            4 => 3,
            8 => 4,
            _ => 0,
        };

If it looks fine, the next question is, since this is a public API and there is no way to return an error, in the _ case, should we silently set it to 0 (Undefined (legacy reasons)), or just panic?

Sounds good - you can put that as a method on GenericAddress. Use unreachable!() to panic for unsupported types.

For now I don't think this needs to be public so it can be a private method.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Please review the new commit.

sboeuf
sboeuf previously approved these changes Jun 26, 2024
Copy link
Collaborator

@sboeuf sboeuf left a comment

Choose a reason for hiding this comment

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

LGTM

Without the fix, the code gives
    1 for Byte access
    2 for Word access
    4 for Dword access
    8 for QWord access.

However, As per ACPI 6.4 spec Sec.5.2.3.2 [1], the access_size should
be
    1 for Byte access
    2 for Word access
    3 for Dword access
    4 for QWord access.

[1] https://uefi.org/htmlspecs/ACPI_Spec_6_4_html/05_ACPI_Software_Programming_Model/ACPI_Software_Programming_Model.html#generic-address-structure-gas

Signed-off-by: Changyuan Lyu <changyuanl@google.com>
@Lencerf Lencerf dismissed stale reviews from sboeuf and rbradford via e017b19 June 26, 2024 17:04
@Lencerf Lencerf requested a review from rbradford June 26, 2024 20:10
Copy link
Collaborator

@rbradford rbradford left a comment

Choose a reason for hiding this comment

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

Great! And a unit test! :-)

@rbradford rbradford requested a review from sboeuf June 26, 2024 20:29
@rbradford rbradford merged commit e268627 into rust-vmm:main Jun 27, 2024
14 checks passed
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.

3 participants