Page MenuHomeFreeBSD

tpm: crb: Improve ACPI control and buffer addresses
Needs ReviewPublic

Authored by kbowling on Fri, Sep 18, 7:05 AM.
Tags
None
Referenced Files
Unknown Object (File)
Fri, Sep 18, 9:34 AM
Unknown Object (File)
Fri, Sep 18, 9:27 AM
Unknown Object (File)
Fri, Sep 18, 9:24 AM
Unknown Object (File)
Fri, Sep 18, 8:13 AM
Unknown Object (File)
Fri, Sep 18, 8:12 AM
Subscribers

Details

Summary
The TPM2 ControlAddress identifies the control area, not necessarily a
PTP locality block.  Hyper-V exposes a start-method-7 control area at the
beginning of its ACPI memory resource, with command and response buffers
in separate reserved memory pages.  Assuming control registers are at
resource + 0x40 instead writes CANCEL as LOC_CTRL and fails attach.

Map the control area using ControlAddress and map buffers using their
reported physical addresses.  Reuse the resource mapping for contained
ranges and track ownership of independent mappings for cleanup.  Request
locality only when the resource contains the preceding 64-byte PTP header.
Keep the existing Pluton notification callbacks and locality behavior for
that layout.  Control, locality, and buffer accesses use their respective
mappings directly, without the tpm_bus accessor class.

Bound transfers by the mapped buffer sizes and TPM_BUFSIZE.  Clamp an
overstated buffer that starts within the ACPI resource to its remaining
extent, while requiring room for a complete response header.  Keep strict
control-area bounds and the shared-buffer size consistency check.

Write locality and state requests directly and wait for the corresponding
CTRL_REQ bit to clear.  The old ready wait instead tested the fatal-status
bit in CTRL_STS.  Enter ready state before reading buffer configuration,
and check fatal status again before reading a response, while locality
is still held.  Retain common error cleanup and diagnose attach-time idle
transition failures without replacing an earlier error.

These layouts and register semantics are defined by TCG ACPI 1.5 Table 7
and PC Client PTP 1.03 sections 5.5.3.1, 5.5.3.4, and 5.5.3.5.

Validation: a Windows Server 2025 Hyper-V FreeBSD guest attached and
passed manufacturer queries, 700 GetRandom/PCR_Read pairs, concurrent
clients, five detach/reattach cycles, and device suspend/resume
with entropy harvesting active.

MFC after:      2 weeks
Test Plan

Needs Pluton testing

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

I copied the existing pattern, but instead let's invert this and use bus_space_read_8 everywhere except i386 (for MFC).

CC @bnovkov, IIRC he has an AMD machine with ControlArea outside of the device range that should be functional after this.