Skip to content

fix(virtio-scmi): report v3.1 clock attributes and extended clock names - #454

Open
agicy wants to merge 2 commits into
syswonder:devfrom
agicy:luanlai/virtio-scmi-extended-name
Open

agicy wants to merge 2 commits into
syswonder:devfrom
agicy:luanlai/virtio-scmi-extended-name

Conversation

@agicy

@agicy agicy commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Summary

Two fixes in the virtio-SCMI clock protocol implementation:

  • fix(virtio-scmi): correct CLOCK_NAME_GET message id — CLOCK_NAME_GET is 0x8 (SCMI/Linux), not 0x9; the mis-numbered CLOCK_CONFIG_GET moves to 0xB.
  • fix(virtio-scmi): report v3.1 clock attributes and extended names — return the 24-byte CLOCK_ATTRIBUTES payload with clock_enable_latency = 0 and set BIT(29) (SUPPORTS_EXTENDED_NAMES), so Linux >= 5.19 fetches the full clock name through CLOCK_NAME_GET.

Fixes #453.

Motivation

hvisor-tool reported only the 16-byte SCMI short name, so every guest clock name was truncated to 15 characters. On RK3588, clk_i2s0_8ch_tx_src and clk_i2s0_8ch_tx_frac both become clk_i2s0_8ch_tx. The guest clock core rejects the second registration of that name, so the guest does not merely show duplicates: it loses the second clock (-EEXIST, see Verification).

Fixing that exposed two defects in the same path:

  1. SCMI_CLOCK_MSG_NAME_GET was declared as 0x9 while SCMI and Linux use 0x8. Enabling BIT(29) alone would send 0x8 into handle_clock_config_get(), whose 12-byte request check rejects the 8-byte name request and returns SCMI_ERR_PARAMS without writing a response. The guest would then see a zero-length completion and wait VIRTIO_MAX_RX_TIMEOUT_MS (60 s) per clock. Measured through the real dispatcher before the id fix:

    DISPATCH 0x8    rc=-2 written=0
    
  2. Linux 5.19+ reads clock_enable_latency from CLOCK_ATTRIBUTES whenever the protocol major version is >= 2. hvisor-tool sent 20 bytes instead of 24, so the kernel copied 20 bytes and used the remaining 4 bytes of its receive buffer as the latency value.

Verification

Host harness: the real scmi/clock.c and scmi_core.c are compiled together, only ioctl() and log_log() are stubbed, and requests go through virtio_scmi_clock_handle_req() so the dispatcher is exercised. The ioctl stub mirrors the kernel module, which always reports parent_id = -1.

Check before after
dispatch of message id 0x8 rc=-2, written=0 rc=0, written=76
CLOCK_ATTRIBUTES payload 20 bytes 24 bytes
attributes (production) 0x00000001 0x20000001
clock_enable_latency stale buffer 0
CLOCK_NAME_GET result never reached flags 0, clk_i2s0_8ch_tx_src

Captured frame after the fix:

03 50 d0 08 | 00 00 00 00 | 01 00 00 20 | "clk_i2s0_8ch_tx\0" | 00 00 00 00  (32 bytes)

Commands:

Command Result
make -C hvisor-tool/tools ARCH=arm64 VIRTIO_SCMI=y ... pass
make -C hvisor-tool/tools ARCH=arm64 VIRTIO_SCMI=n ... pass
clang-format 23.1.5 --dry-run --Werror (format workflow pin) pass
typos --config _typos.toml pass
Host harness above pass
QEMU qemu-gicv3 zone lifecycle regression pass
QEMU zone0: SCMI clock ioctls against real DT clocks pass
Guest-side clk_summary check -EEXIST, clock dropped

The zone0 run adds two fixed-clock nodes with long clock-output-names to the
hvisor_virtio_device node of the QEMU zone0 DT, then queries the kernel module
directly with a small static aarch64 tool:

clocks = <&clk_scmi_a>, <&clk_scmi_b>;   /* clk_i2s0_8ch_tx_src / _frac */

PROBE clock_count=2
PROBE attr[0] rc=0 short="clk_i2s0_8ch_tx_src"  enabled=0 parent=4294967295
PROBE name[0] rc=0 full="clk_i2s0_8ch_tx_src"
PROBE attr[1] rc=0 short="clk_i2s0_8ch_tx_frac" enabled=0 parent=4294967295
PROBE name[1] rc=0 full="clk_i2s0_8ch_tx_frac"
PROBE DONE

This confirms the name source end to end up to the kernel module: the DT clocks are enumerated and their full names are returned. It also confirms that parent_id is always -1, i.e. the short-name path never sets bit 28.

QEMU run (hvisor built from this branch, guest kernel and zone0 DT from the standard qemu-gicv3 image, hvisor.ko + hvisor from this branch):

insmod hvisor.ko                      -> hvisor init done
virtio start virtio_cfg.json          -> daemon up
zone start zone1-linux.json           -> ZONE_CMD_DONE
zone shutdown -id 1                   -> zone 1 has been shutdown
daemon pid before/after shutdown      -> 66 / 66
Kernel panic / BUG / unable to handle -> 0
poweroff                              -> reboot: Power down

The guest-side clk_summary check ran on a QEMU qemu-gicv3 zone1 guest (Linux 7.3.5, CONFIG_ARM_SCMI_TRANSPORT_VIRTIO=y), with the two fixed-clock nodes from the zone0 DT exposed through the zone1 device tree:

firmware {
    scmi {
        compatible = "arm,scmi-virtio";
        protocol@14 { reg = <0x14>; #clock-cells = <0x01>; };
    };
};
before (dev SCMI code):
  scmi-clocks scmi_dev.2: error -EEXIST: failed to register clk 'clk_i2s0_8ch_tx'
  scmi-clocks scmi_dev.2: failed to register clock 1

after (this branch):
   clk_i2s0_8ch_tx_frac                0  ...  Y
   clk_i2s0_8ch_tx_src                 0  ...  Y
   clk24mhz                            0  ...  Y

The zone1 guest also needs the per-queue virtio-console workers: the single-threaded console on dev stalls this guest before user space, which is why the earlier zone0-only probe could not be extended to a guest. The extra SCMI IRQ also had to move off 79 (any IRQ other than the three the guest's virtio-mmio nodes use works here); both are fixture issues, not part of this change.

Risks and Limitations

  • The CLOCK_ATTRIBUTES payload grows from 20 to 24 bytes.
    • Linux 5.15 - 5.17: 20-byte struct; msg_fetch_response() copies min(requested, available), so the extra 4 bytes are ignored.
    • Linux 5.18: 24-byte struct, but it reads the latency field only when the response is long enough to contain it; it now receives 0.
    • Linux 5.19+: 24-byte struct, reads the field when the protocol major version is >= 2; it now receives 0 ("unknown").
  • Extended names require Linux >= 5.19 (first kernel with SUPPORTS_EXTENDED_NAMES in the clock protocol). Older guests keep the 15-character name; they are not made worse.

@agicy
agicy requested review from li041 and peikachu November 26, 2026 13:28
@github-actions github-actions Bot added the bug Something isn't working label Nov 26, 2026
@agicy
agicy requested a review from ForeverYolo November 28, 2026 04:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SCMI clock names are truncated to 15 characters and colliding clocks fail to register

1 participant