Linux s390 Architecture development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Stefan Haberland" <sth@linux.ibm.com>
Cc: "Alexander Gordeev" <agordeev@linux.ibm.com>,
	"Vasily Gorbik" <gor@linux.ibm.com>,
	linux-s390@vger.kernel.org, "Heiko Carstens" <hca@linux.ibm.com>
Subject: Re: [PATCH v3 08/13] s390/dasd: Derive adaptive ESE fulltrack heuristic from ft_bias
Date: Thu, 23 Jul 2026 14:09:37 +0000	[thread overview]
Message-ID: <20260723140937.CE3011F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260723134743.672413-9-sth@linux.ibm.com>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:

New issues:
- [High] Writing to the `full_track_bias` sysfs attribute triggers a NULL pointer dereference if the DASD device is offline or has no discipline assigned.
- [High] The adaptive heuristic FSM state and configuration variables are modified concurrently without synchronization, leading to permanent state corruption.

Pre-existing issues:
- [High] The condition in `dasd_release_space()` incorrectly uses `&&` instead of `||`, breaking validation and evaluating a NULL function pointer for non-ESE disciplines.
--

--- Patch [8]: [PATCH v3 08/13] s390/dasd: Derive adaptive ESE fulltrack heuristic from ft_bias ---
commit 6212107d38eb431780604d50fae290b46a53ceff
Author: Stefan Haberland <sth@linux.ibm.com>

s390/dasd: Derive adaptive ESE fulltrack heuristic from ft_bias

Turn the middle of the ft_bias range (1..99) into an adaptive heuristic
that switches between fulltrack write (ft1) and plain write ft0 depending
on how sparse the device still is. A state machine measures the NRF rate
in short ft0 probe windows and flips back to ft1 when it is high.

> diff --git a/drivers/s390/block/dasd_devmap.c b/drivers/s390/block/dasd_devmap.c
> index 035c022255b68..c587817f5cf9e 100644
> --- a/drivers/s390/block/dasd_devmap.c
> +++ b/drivers/s390/block/dasd_devmap.c
[ ... ]
> @@ -1660,7 +1660,7 @@ static ssize_t full_track_bias_store(struct device *dev,
>  		return -ENODEV;
>  
>  	device->ft_bias = val;
> -	device->fulltrack = val ? 1 : 0;
> +	dasd_ft_bias_apply(device);

[Severity: High]
Is it possible for device->discipline to be NULL when the device is offline?

If a user writes to the full_track_bias sysfs attribute while the device is
offline, dasd_ft_bias_apply() calls dasd_ese_adaptive(device) which directly
dereferences device->discipline->is_ese:

drivers/s390/block/dasd_int.h:dasd_ese_adaptive() {
    return device->discipline->is_ese &&
           device->discipline->is_ese(device) && ...
}

Could this result in a NULL pointer dereference during the sysfs write?

>  
>  	dasd_put_device(device);
>  	return count;
[ ... ]
> diff --git a/drivers/s390/block/dasd_eckd.c b/drivers/s390/block/dasd_eckd.c
> index c10fe20e7d3ff..8b5f592b04d95 100644
> --- a/drivers/s390/block/dasd_eckd.c
> +++ b/drivers/s390/block/dasd_eckd.c
[ ... ]
> @@ -3201,6 +3208,65 @@ static void clear_format_track(struct dasd_format_entry *format,
>  	spin_unlock_irqrestore(&block->format_lock, flags);
>  }
>  
> +/*
> + * Adaptive ft_bias heuristic, called once per IO from dasd_eckd_build_cp().
> + * Probes the device formatting state by briefly switching to ft0 and measuring
> + * the NRF rate; parameters are derived from ft_bias.
> + */
> +static void dasd_ese_heuristic_tick(struct dasd_device *basedev)
> +{
> +	int ios, nrf, rate;
> +
> +	if (atomic_inc_return(&basedev->ese_io_cnt) < (int)basedev->ese_probe_interval)
> +		return;
> +
> +	/*
> +	 * One wins the race to evaluate, the rest see ios == 0 after the
> +	 * xchg and return early, preventing redundant state transitions.
> +	 */
> +	ios = atomic_xchg(&basedev->ese_io_cnt, 0);
> +	if (ios <= 0)
> +		return;
> +
> +	switch (basedev->ese_probe_state) {
> +	case DASD_ESE_HEU_FT1_ACTIVE:
> +		/* Start ft0 probe window, reset NRF counter for clean measurement */
> +		basedev->fulltrack          = 0;
> +		basedev->ese_probe_state    = DASD_ESE_HEU_PROBING;

[Severity: High]
Is there a race condition here between this state update and a concurrent
sysfs write to full_track_bias?

If a sysfs write occurs concurrently with a block I/O request executing
dasd_ese_heuristic_tick(), the I/O thread might read DASD_ESE_HEU_FT1_ACTIVE.

If the sysfs thread then updates ft_bias (for example, to 100) and forces
fulltrack = 1 via dasd_ft_bias_apply(), the I/O thread could subsequently
overwrite fulltrack = 0 and change the FSM state. 

Since ft_bias is now 100, dasd_ese_adaptive() will evaluate to false for
future I/Os, meaning the heuristic tick is never called again and fulltrack
remains stuck at 0. Does this need synchronization to prevent permanently
locking the heuristic in the wrong state?

> +		basedev->ese_probe_interval = basedev->ese_heu_probe_window;
> +		atomic_set(&basedev->ese_nrf_window, 0);
> +		break;

[Severity: High]
This is a pre-existing issue, but looking at dasd_release_space() in
drivers/s390/block/dasd_ioctl.c:

    if (!device->discipline->is_ese && !device->discipline->is_ese(device))
        return -ENOTSUPP;

Does this condition incorrectly use && instead of ||? 

If the discipline does not define the is_ese callback (such as for FBA
devices), the first half evaluates to true. Because of the &&, it then
evaluates the second half, which calls the NULL function pointer. Could an
ioctl invoking dasd_release_space() on such a device cause a kernel panic?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260723134743.672413-1-sth@linux.ibm.com?part=8

  reply	other threads:[~2026-07-23 14:09 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-23 13:47 [PATCH v3 00/13] s390/dasd: ESE thin-provisioning performance improvements Stefan Haberland
2026-07-23 13:47 ` [PATCH v3 01/13] s390/dasd: Optimize max blocks per request for track alignment Stefan Haberland
2026-07-23 13:58   ` sashiko-bot
2026-07-23 13:47 ` [PATCH v3 02/13] s390/dasd: Add infrastructure for ESE full-track write Stefan Haberland
2026-07-23 14:11   ` sashiko-bot
2026-07-23 13:47 ` [PATCH v3 03/13] s390/dasd: Add range-based format-track collision detection Stefan Haberland
2026-07-23 14:13   ` sashiko-bot
2026-07-23 13:47 ` [PATCH v3 04/13] s390/dasd: Extend prepare_itcw() to support WRITE_FULL_TRACK Stefan Haberland
2026-07-23 14:25   ` sashiko-bot
2026-07-23 13:47 ` [PATCH v3 05/13] s390/dasd: Add dasd_eckd_build_cp_tpm_writefulltrack() Stefan Haberland
2026-07-23 14:14   ` sashiko-bot
2026-07-23 13:47 ` [PATCH v3 06/13] s390/dasd: Use WRITE_FULL_TRACK in ESE format handler Stefan Haberland
2026-07-23 14:13   ` sashiko-bot
2026-07-23 13:47 ` [PATCH v3 07/13] s390/dasd: Add full_track_bias sysfs attribute to control fulltrack write mode Stefan Haberland
2026-07-23 14:16   ` sashiko-bot
2026-07-23 13:47 ` [PATCH v3 08/13] s390/dasd: Derive adaptive ESE fulltrack heuristic from ft_bias Stefan Haberland
2026-07-23 14:09   ` sashiko-bot [this message]
2026-07-23 13:47 ` [PATCH v3 09/13] s390/dasd: Stamp a format label into newly formatted volumes Stefan Haberland
2026-07-23 14:09   ` sashiko-bot
2026-07-23 13:47 ` [PATCH v3 10/13] s390/dasd: Detect ESE volumes from the on-disk format label Stefan Haberland
2026-07-23 14:19   ` sashiko-bot
2026-07-23 13:47 ` [PATCH v3 11/13] s390/dasd: Report ESE capability and format mode at device online Stefan Haberland
2026-07-23 14:14   ` sashiko-bot
2026-07-23 13:47 ` [PATCH v3 12/13] s390/dasd: Re-enable discard support for ESE volumes Stefan Haberland
2026-07-23 14:30   ` sashiko-bot
2026-07-23 13:47 ` [PATCH v3 13/13] s390/dasd: Read cached unit address and LSS in the CCW build path Stefan Haberland
2026-07-23 14:35   ` sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260723140937.CE3011F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=agordeev@linux.ibm.com \
    --cc=gor@linux.ibm.com \
    --cc=hca@linux.ibm.com \
    --cc=linux-s390@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=sth@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox