Re: [PATCH v2 1/4] platform/x86: dell: dcdbas: Actually wait for the host control SMI

From: Andy Shevchenko

Date: Tue Nov 17 2026 - 02:57:53 EST


On Mon, Nov 16, 2026 at 12:40:49PM -0800, Rosen Penev wrote:
> For SMI types 2 and 3, host_control_smi() writes the command status as
> -1, raises the SMI and then waits for the BIOS to change the status:
>
> while (apm_cmd->status == ESM_STATUS_CMD_UNSUCCESSFUL) {
>
> apm_cmd->status is a plain memory read, and neither outb() nor inb()
> tells the compiler that memory may have changed, so the compiler
> assumes status is still -1. The loop then has no side effects and its
> return value is not used, so it is removed entirely: in the generated
> code, the read of the control port is followed directly by the return.
> The kernel goes on to power off right after raising the host control
> SMI, without waiting for the BIOS to accept it.
>
> The type 1 wait polls the APM status port instead, in a loop that
> counts down TIMEOUT_USEC_SHORT_SEMA_BLOCKING iterations and relies on
> each inb() taking about a microsecond.
>
> Convert both waits to read_poll_timeout_atomic(), using READ_ONCE() for
> the status in memory and inb() for the status port, 1us apart for up to
> TIMEOUT_USEC_SHORT_SEMA_BLOCKING microseconds as the name suggests, and
> return its error. That is -ETIMEDOUT rather than -ETIME, but both
> callers ignore the return value. With the delay plus the port read, the
> type 1 worst-case wait grows from about 10ms to about 20ms, which only
> matters when the BIOS never answers.
>
> This removes the last users of num_ticks and EXPIRED_TIMER.

...

> + ret = read_poll_timeout_atomic(inb, cmd_status,
> + cmd_status != ESM_STATUS_CMD_UNSUCCESSFUL,
> + 1, TIMEOUT_USEC_SHORT_SEMA_BLOCKING,
> + false, PCAT_APM_STATUS_PORT);

readx_poll_timeout_atomic() is your friend.

...

> + ret = read_poll_timeout_atomic(READ_ONCE, cmd_status,
> + cmd_status != ESM_STATUS_CMD_UNSUCCESSFUL,
> + 1, TIMEOUT_USEC_SHORT_SEMA_BLOCKING,
> + false, apm_cmd->status);

In the similar way.

--
With Best Regards,
Andy Shevchenko