All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Stefan Haberland" <sth@linux.ibm.com>
Cc: "Heiko Carstens" <hca@linux.ibm.com>,
	"Vasily Gorbik" <gor@linux.ibm.com>,
	"Alexander Gordeev" <agordeev@linux.ibm.com>,
	linux-s390@vger.kernel.org
Subject: Re: [PATCH v7 18/19] s390/dasd: Re-enable discard support for ESE volumes
Date: Sat, 01 Aug 2026 18:46:50 +0000	[thread overview]
Message-ID: <20260801184650.E941B1F00AC4@smtp.kernel.org> (raw)
In-Reply-To: <20260801180033.3679412-19-sth@linux.ibm.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Setting `discard_granularity` to a non-power-of-two value breaks block layer bitwise alignment macros, resulting in misaligned discard chunks that silently fail to release any storage space.
--

--- Patch [18]: [PATCH v7 18/19] s390/dasd: Re-enable discard support for ESE volumes ---
commit 991725ca26feab13c3c8f77dd5e57ee71891a902
Author: Stefan Haberland <sth@linux.ibm.com>

s390/dasd: Re-enable discard support for ESE volumes

This patch re-enables block-layer discard support for ESE ECKD volumes by
routing discard operations to release allocated space (RAS). It introduces
extent-aligned limit constraints and handles discarded ranges at the driver
level.

> diff --git a/drivers/s390/block/dasd.c b/drivers/s390/block/dasd.c
> index 0e01b498b0e8e..cf6a405ee0c75 100644
> --- a/drivers/s390/block/dasd.c
> +++ b/drivers/s390/block/dasd.c
[ ... ]
> @@ -3172,6 +3175,18 @@ static blk_status_t do_dasd_request(struct blk_mq_hw_ctx *hctx,
>  			rc = BLK_STS_RESOURCE;
>  		} else if (PTR_ERR(cqr) == -EINVAL) {
>  			rc = BLK_STS_INVAL;
> +		} else if (PTR_ERR(cqr) == -EOPNOTSUPP) {
> +			/*
> +			 * A discard that covers no whole extent releases
> +			 * nothing. Discard is advisory, so complete it as a
> +			 * benign no-op: the device does support discard, this
> +			 * range just does not align to the large ESE extent
> +			 * granularity. Returning BLK_STS_NOTSUPP would make
> +			 * filesystems treat the device as lacking discard and
> +			 * stop issuing it. Completed after the lock is dropped.
> +			 */
> +			rc = BLK_STS_OK;
> +			complete_noop = true;

[Severity: High]
Does this code silently drop all discard requests without actually freeing
any space, when combined with the non-power-of-two discard_granularity?

If discard_granularity is not a power of two, the block layer splits the
discard bio into misaligned chunks. The CCW builder will then reject every
chunk with -EOPNOTSUPP because they don't cover a full extent. This handler
intercepts the error and completes it as BLK_STS_OK, causing user space tools
like fstrim to report success while no space is released.

> diff --git a/drivers/s390/block/dasd_eckd.c b/drivers/s390/block/dasd_eckd.c
> index 27833c6d7ddf3..57e927926be1a 100644
> --- a/drivers/s390/block/dasd_eckd.c
> +++ b/drivers/s390/block/dasd_eckd.c
[ ... ]
> +static struct dasd_ccw_req *
> +dasd_eckd_build_cp_discard(struct dasd_device *device, struct dasd_block *block,
> +			   struct request *req, sector_t first_trk,
> +			   sector_t last_trk, unsigned int first_offs,
> +			   unsigned int last_offs, unsigned int blk_per_trk)
> +{
[ ... ]
> +	/*
> +	 * RAS releases whole extents. Only release extents that lie entirely
> +	 * within the (now whole-track) discard range by rounding inward to extent
> +	 * boundaries - an extent shared with a live allocation must never be
> +	 * released. If no whole extent is covered there is nothing to release
> +	 * safely (e.g. a sub-extent discard, unavoidable with large extents), so
> +	 * reject the request rather than release too much.
> +	 */
> +	first_ext_trk = roundup(first_trk, trks_per_ext);
> +	/* one past the last whole extent inside the range (exclusive) */
> +	last_ext_end = rounddown(last_trk + 1, trks_per_ext);
> +	if (first_ext_trk >= last_ext_end)
> +		return ERR_PTR(-EOPNOTSUPP);

[Severity: High]
Does this safety check reject all the chunks generated by the block layer?

Because the block layer splits the discard bio into unaligned chunks based on
the corrupted math from discard_granularity, dasd_eckd_build_cp_discard()
determines that no single chunk covers a full hardware extent. It rejects every
chunk with -EOPNOTSUPP, leading to the silent failure described above.

[ ... ]
> @@ -7723,6 +7782,51 @@ static unsigned int dasd_eckd_max_sectors(struct dasd_block *block)
>  	return DASD_ECKD_MAX_BLOCKS << block->s2b_shift;
>  }
>  
> +/*
> + * Discard on ECKD releases space through RAS, which works on whole extents.
> + * Advertise extent granularity so the block layer only sends extent-aligned
> + * discards (avoiding partially specified extents), and only for volumes on ESE
> + * hardware. Non-ESE devices are left without discard limits.
> + */
> +static void dasd_eckd_disc_limits(struct dasd_block *block,
> +				  struct queue_limits *lim)
> +{
[ ... ]
> +	/*
> +	 * ext_bytes is the hardware extent size and is not a power of two, so
> +	 * the block layer's power-of-two round_up()/round_down() alignment
> +	 * helpers compute it only approximately. That is a hint, not a
> +	 * correctness requirement: RAS safety is enforced in the CCW builder,
> +	 * which rounds the range inward to whole extents and rejects a request
> +	 * that covers no whole extent, so a misaligned range is never
> +	 * over-released. At worst a few sub-extent discards are declined.
> +	 */
> +	lim->discard_granularity = ext_bytes;

[Severity: High]
Will setting discard_granularity to a non-power-of-two value break the block
layer's bitwise alignment calculations?

The block layer's alignment macros, such as round_down() and round_up()
(defined in include/linux/math.h), strictly require a power of two because
they use bitwise AND masking.

When applied to non-power-of-two values, they calculate incorrect, unaligned
results. For example, round_down(BIO_MAX_SIZE, 15482880) calculates
1048576 & ~15482879, returning exactly 1MB instead of 0.

This is the root cause of the broken discards, as it causes the block layer
to compute completely unaligned boundaries instead of an approximation.

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

  reply	other threads:[~2026-08-01 18:46 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-01 18:00 [PATCH v7 00/19] s390/dasd: ESE thin-provisioning performance improvements Stefan Haberland
2026-08-01 18:00 ` [PATCH v7 01/19] s390/dasd: Do not complete a failed ESE read as successful Stefan Haberland
2026-08-01 18:30   ` sashiko-bot
2026-08-01 18:00 ` [PATCH v7 02/19] s390/dasd: Propagate partial completion length across ERP recovery Stefan Haberland
2026-08-01 18:21   ` sashiko-bot
2026-08-01 18:00 ` [PATCH v7 03/19] s390/dasd: Guard sysfs discipline callbacks against unallocated private data Stefan Haberland
2026-08-01 18:29   ` sashiko-bot
2026-08-01 18:00 ` [PATCH v7 04/19] s390/dasd: Snapshot intrc before freeing the request block Stefan Haberland
2026-08-01 18:18   ` sashiko-bot
2026-08-01 18:00 ` [PATCH v7 05/19] s390/dasd: Optimize max blocks per request for track alignment Stefan Haberland
2026-08-01 18:05   ` sashiko-bot
2026-08-01 18:00 ` [PATCH v7 06/19] s390/dasd: Use GFP_KERNEL in dasd_alloc_device() Stefan Haberland
2026-08-01 18:15   ` sashiko-bot
2026-08-01 18:00 ` [PATCH v7 07/19] s390/dasd: Add defines for the Extended Address Volume track address Stefan Haberland
2026-08-01 18:05   ` sashiko-bot
2026-08-01 18:00 ` [PATCH v7 08/19] s390/dasd: Add infrastructure for ESE full-track write Stefan Haberland
2026-08-01 18:21   ` sashiko-bot
2026-08-01 18:00 ` [PATCH v7 09/19] s390/dasd: Add range-based format-track collision detection Stefan Haberland
2026-08-01 18:23   ` sashiko-bot
2026-08-01 18:00 ` [PATCH v7 10/19] s390/dasd: Extend prepare_itcw() to support WRITE_FULL_TRACK Stefan Haberland
2026-08-01 18:28   ` sashiko-bot
2026-08-01 18:00 ` [PATCH v7 11/19] s390/dasd: Add dasd_eckd_build_cp_tpm_writefulltrack() Stefan Haberland
2026-08-01 18:17   ` sashiko-bot
2026-08-01 18:00 ` [PATCH v7 12/19] s390/dasd: Use WRITE_FULL_TRACK in ESE format handler Stefan Haberland
2026-08-01 18:33   ` sashiko-bot
2026-08-01 18:00 ` [PATCH v7 13/19] s390/dasd: Add full_track_bias to control fulltrack write mode Stefan Haberland
2026-08-01 18:20   ` sashiko-bot
2026-08-01 18:00 ` [PATCH v7 14/19] s390/dasd: Derive adaptive ESE fulltrack heuristic from ft_bias Stefan Haberland
2026-08-01 18:17   ` sashiko-bot
2026-08-01 18:00 ` [PATCH v7 15/19] s390/dasd: Stamp a format label into newly formatted volumes Stefan Haberland
2026-08-01 18:26   ` sashiko-bot
2026-08-01 18:00 ` [PATCH v7 16/19] s390/dasd: Detect ESE volumes from the on-disk format label Stefan Haberland
2026-08-01 18:39   ` sashiko-bot
2026-08-01 18:00 ` [PATCH v7 17/19] s390/dasd: Report ESE capability and format mode at device online Stefan Haberland
2026-08-01 18:22   ` sashiko-bot
2026-08-01 18:00 ` [PATCH v7 18/19] s390/dasd: Re-enable discard support for ESE volumes Stefan Haberland
2026-08-01 18:46   ` sashiko-bot [this message]
2026-08-01 18:00 ` [PATCH v7 19/19] s390/dasd: Read cached unit address and LSS in the CCW build path Stefan Haberland
2026-08-01 18:50   ` 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=20260801184650.E941B1F00AC4@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.