linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	stable@vger.kernel.org, Stefan Haberland <sth@linux.ibm.com>,
	Jan Hoeppner <hoeppner@linux.ibm.com>,
	Jens Axboe <axboe@kernel.dk>
Subject: [PATCH 5.10 23/70] s390/dasd: prevent double format of tracks for ESE devices
Date: Tue, 10 May 2022 15:07:42 +0200	[thread overview]
Message-ID: <20220510130733.546385272@linuxfoundation.org> (raw)
In-Reply-To: <20220510130732.861729621@linuxfoundation.org>

From: Stefan Haberland <sth@linux.ibm.com>

commit 71f3871657370dbbaf942a1c758f64e49a36c70f upstream.

For ESE devices we get an error for write operations on an unformatted
track. Afterwards the track will be formatted and the IO operation
restarted.
When using alias devices a track might be accessed by multiple requests
simultaneously and there is a race window that a track gets formatted
twice resulting in data loss.

Prevent this by remembering the amount of formatted tracks when starting
a request and comparing this number before actually formatting a track
on the fly. If the number has changed there is a chance that the current
track was finally formatted in between. As a result do not format the
track and restart the current IO to check.

The number of formatted tracks does not match the overall number of
formatted tracks on the device and it might wrap around but this is no
problem. It is only needed to recognize that a track has been formatted at
all in between.

Fixes: 5e2b17e712cf ("s390/dasd: Add dynamic formatting support for ESE volumes")
Cc: stable@vger.kernel.org # 5.3+
Signed-off-by: Stefan Haberland <sth@linux.ibm.com>
Reviewed-by: Jan Hoeppner <hoeppner@linux.ibm.com>
Link: https://lore.kernel.org/r/20220505141733.1989450-3-sth@linux.ibm.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 drivers/s390/block/dasd.c      |    7 +++++++
 drivers/s390/block/dasd_eckd.c |   19 +++++++++++++++++--
 drivers/s390/block/dasd_int.h  |    2 ++
 3 files changed, 26 insertions(+), 2 deletions(-)

--- a/drivers/s390/block/dasd.c
+++ b/drivers/s390/block/dasd.c
@@ -1462,6 +1462,13 @@ int dasd_start_IO(struct dasd_ccw_req *c
 		if (!cqr->lpm)
 			cqr->lpm = dasd_path_get_opm(device);
 	}
+	/*
+	 * remember the amount of formatted tracks to prevent double format on
+	 * ESE devices
+	 */
+	if (cqr->block)
+		cqr->trkcount = atomic_read(&cqr->block->trkcount);
+
 	if (cqr->cpmode == 1) {
 		rc = ccw_device_tm_start(device->cdev, cqr->cpaddr,
 					 (long) cqr, cqr->lpm);
--- a/drivers/s390/block/dasd_eckd.c
+++ b/drivers/s390/block/dasd_eckd.c
@@ -3026,13 +3026,24 @@ static int dasd_eckd_format_device(struc
 }
 
 static bool test_and_set_format_track(struct dasd_format_entry *to_format,
-				      struct dasd_block *block)
+				      struct dasd_ccw_req *cqr)
 {
+	struct dasd_block *block = cqr->block;
 	struct dasd_format_entry *format;
 	unsigned long flags;
 	bool rc = false;
 
 	spin_lock_irqsave(&block->format_lock, flags);
+	if (cqr->trkcount != atomic_read(&block->trkcount)) {
+		/*
+		 * The number of formatted tracks has changed after request
+		 * start and we can not tell if the current track was involved.
+		 * To avoid data corruption treat it as if the current track is
+		 * involved
+		 */
+		rc = true;
+		goto out;
+	}
 	list_for_each_entry(format, &block->format_list, list) {
 		if (format->track == to_format->track) {
 			rc = true;
@@ -3052,6 +3063,7 @@ static void clear_format_track(struct da
 	unsigned long flags;
 
 	spin_lock_irqsave(&block->format_lock, flags);
+	atomic_inc(&block->trkcount);
 	list_del_init(&format->list);
 	spin_unlock_irqrestore(&block->format_lock, flags);
 }
@@ -3113,8 +3125,11 @@ dasd_eckd_ese_format(struct dasd_device
 	}
 	format->track = curr_trk;
 	/* test if track is already in formatting by another thread */
-	if (test_and_set_format_track(format, block))
+	if (test_and_set_format_track(format, cqr)) {
+		/* this is no real error so do not count down retries */
+		cqr->retries++;
 		return ERR_PTR(-EEXIST);
+	}
 
 	fdata.start_unit = curr_trk;
 	fdata.stop_unit = curr_trk;
--- a/drivers/s390/block/dasd_int.h
+++ b/drivers/s390/block/dasd_int.h
@@ -188,6 +188,7 @@ struct dasd_ccw_req {
 	void (*callback)(struct dasd_ccw_req *, void *data);
 	void *callback_data;
 	unsigned int proc_bytes;	/* bytes for partial completion */
+	unsigned int trkcount;		/* count formatted tracks */
 };
 
 /*
@@ -575,6 +576,7 @@ struct dasd_block {
 
 	struct list_head format_list;
 	spinlock_t format_lock;
+	atomic_t trkcount;
 };
 
 struct dasd_attention_data {



  parent reply	other threads:[~2022-05-10 13:55 UTC|newest]

Thread overview: 81+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-10 13:07 [PATCH 5.10 00/70] 5.10.115-rc1 review Greg Kroah-Hartman
2022-05-10 13:07 ` [PATCH 5.10 01/70] MIPS: Fix CP0 counter erratum detection for R4k CPUs Greg Kroah-Hartman
2022-05-10 13:07 ` [PATCH 5.10 02/70] parisc: Merge model and model name into one line in /proc/cpuinfo Greg Kroah-Hartman
2022-05-10 13:07 ` [PATCH 5.10 03/70] ALSA: hda/realtek: Add quirk for Yoga Duet 7 13ITL6 speakers Greg Kroah-Hartman
2022-05-10 13:07 ` [PATCH 5.10 04/70] ALSA: fireworks: fix wrong return count shorter than expected by 4 bytes Greg Kroah-Hartman
2022-05-10 13:07 ` [PATCH 5.10 05/70] mmc: sdhci-msm: Reset GCC_SDCC_BCR register for SDHC Greg Kroah-Hartman
2022-05-10 13:07 ` [PATCH 5.10 06/70] mmc: core: Set HS clock speed before sending HS CMD13 Greg Kroah-Hartman
2022-05-10 13:07 ` [PATCH 5.10 07/70] gpiolib: of: fix bounds check for gpio-reserved-ranges Greg Kroah-Hartman
2022-05-10 13:07 ` [PATCH 5.10 08/70] KVM: x86/svm: Account for family 17h event renumberings in amd_pmc_perf_hw_id Greg Kroah-Hartman
2022-05-10 13:07 ` [PATCH 5.10 09/70] iommu/vt-d: Calculate mask for non-aligned flushes Greg Kroah-Hartman
2022-05-10 13:07 ` [PATCH 5.10 10/70] drm/amd/display: Avoid reading audio pattern past AUDIO_CHANNELS_COUNT Greg Kroah-Hartman
2022-05-10 13:07 ` [PATCH 5.10 11/70] Revert "SUNRPC: attempt AF_LOCAL connect on setup" Greg Kroah-Hartman
2022-05-10 13:07 ` [PATCH 5.10 12/70] firewire: fix potential uaf in outbound_phy_packet_callback() Greg Kroah-Hartman
2022-05-10 13:07 ` [PATCH 5.10 13/70] firewire: remove check of list iterator against head past the loop body Greg Kroah-Hartman
2022-05-10 13:07 ` [PATCH 5.10 14/70] firewire: core: extend card->lock in fw_core_handle_bus_reset Greg Kroah-Hartman
2022-05-10 13:07 ` [PATCH 5.10 15/70] net: stmmac: disable Split Header (SPH) for Intel platforms Greg Kroah-Hartman
2022-05-10 13:07 ` [PATCH 5.10 16/70] genirq: Synchronize interrupt thread startup Greg Kroah-Hartman
2022-05-10 13:07 ` [PATCH 5.10 17/70] ASoC: da7219: Fix change notifications for tone generator frequency Greg Kroah-Hartman
2022-05-10 13:07 ` [PATCH 5.10 18/70] ASoC: wm8958: Fix change notifications for DSP controls Greg Kroah-Hartman
2022-05-10 13:07 ` [PATCH 5.10 19/70] ASoC: meson: Fix event generation for AUI ACODEC mux Greg Kroah-Hartman
2022-05-10 13:07 ` [PATCH 5.10 20/70] ASoC: meson: Fix event generation for G12A tohdmi mux Greg Kroah-Hartman
2022-05-10 13:07 ` [PATCH 5.10 21/70] ASoC: meson: Fix event generation for AUI CODEC mux Greg Kroah-Hartman
2022-05-10 13:07 ` [PATCH 5.10 22/70] s390/dasd: fix data corruption for ESE devices Greg Kroah-Hartman
2022-05-10 13:07 ` Greg Kroah-Hartman [this message]
2022-05-10 13:07 ` [PATCH 5.10 24/70] s390/dasd: Fix read for ESE with blksize < 4k Greg Kroah-Hartman
2022-05-10 13:07 ` [PATCH 5.10 25/70] s390/dasd: Fix read inconsistency for ESE DASD devices Greg Kroah-Hartman
2022-05-10 13:07 ` [PATCH 5.10 26/70] can: grcan: grcan_close(): fix deadlock Greg Kroah-Hartman
2022-05-10 13:07 ` [PATCH 5.10 27/70] can: isotp: remove re-binding of bound socket Greg Kroah-Hartman
2022-05-10 13:07 ` [PATCH 5.10 28/70] can: grcan: use ofdev->dev when allocating DMA memory Greg Kroah-Hartman
2022-05-10 13:07 ` [PATCH 5.10 29/70] can: grcan: grcan_probe(): fix broken system id check for errata workaround needs Greg Kroah-Hartman
2022-05-10 13:07 ` [PATCH 5.10 30/70] can: grcan: only use the NAPI poll budget for RX Greg Kroah-Hartman
2022-05-10 13:07 ` [PATCH 5.10 31/70] nfc: replace improper check device_is_registered() in netlink related functions Greg Kroah-Hartman
2022-05-10 13:07 ` [PATCH 5.10 32/70] nfc: nfcmrvl: main: reorder destructive operations in nfcmrvl_nci_unregister_dev to avoid bugs Greg Kroah-Hartman
2022-05-10 13:07 ` [PATCH 5.10 33/70] NFC: netlink: fix sleep in atomic bug when firmware download timeout Greg Kroah-Hartman
2022-05-10 13:07 ` [PATCH 5.10 34/70] gpio: pca953x: fix irq_stat not updated when irq is disabled (irq_mask not set) Greg Kroah-Hartman
2022-05-10 13:07 ` [PATCH 5.10 35/70] hwmon: (adt7470) Fix warning on module removal Greg Kroah-Hartman
2022-05-10 13:07 ` [PATCH 5.10 36/70] ASoC: dmaengine: Restore NULL prepare_slave_config() callback Greg Kroah-Hartman
2022-05-10 13:07 ` [PATCH 5.10 37/70] net/mlx5e: Fix trust state reset in reload Greg Kroah-Hartman
2022-05-10 13:07 ` [PATCH 5.10 38/70] net/mlx5e: Dont match double-vlan packets if cvlan is not set Greg Kroah-Hartman
2022-05-10 13:07 ` [PATCH 5.10 39/70] net/mlx5e: CT: Fix queued up restore put() executing after relevant ft release Greg Kroah-Hartman
2022-05-10 13:07 ` [PATCH 5.10 40/70] net/mlx5e: Fix the calling of update_buffer_lossy() API Greg Kroah-Hartman
2022-05-10 13:08 ` [PATCH 5.10 41/70] net/mlx5: Avoid double clear or set of sync reset requested Greg Kroah-Hartman
2022-05-10 13:08 ` [PATCH 5.10 42/70] selftests/seccomp: Dont call read() on TTY from background pgrp Greg Kroah-Hartman
2022-05-10 13:08 ` [PATCH 5.10 43/70] RDMA/siw: Fix a condition race issue in MPA request processing Greg Kroah-Hartman
2022-05-10 13:08 ` [PATCH 5.10 44/70] NFSv4: Dont invalidate inode attributes on delegation return Greg Kroah-Hartman
2022-05-10 13:08 ` [PATCH 5.10 45/70] net: ethernet: mediatek: add missing of_node_put() in mtk_sgmii_init() Greg Kroah-Hartman
2022-05-10 13:08 ` [PATCH 5.10 46/70] net: dsa: mt7530: add missing of_node_put() in mt7530_setup() Greg Kroah-Hartman
2022-05-10 13:08 ` [PATCH 5.10 47/70] net: stmmac: dwmac-sun8i: add missing of_node_put() in sun8i_dwmac_register_mdio_mux() Greg Kroah-Hartman
2022-05-10 13:08 ` [PATCH 5.10 48/70] net: cpsw: add missing of_node_put() in cpsw_probe_dt() Greg Kroah-Hartman
2022-05-10 13:08 ` [PATCH 5.10 49/70] net: emaclite: Add error handling for of_address_to_resource() Greg Kroah-Hartman
2022-05-10 13:08 ` [PATCH 5.10 50/70] hinic: fix bug of wq out of bound access Greg Kroah-Hartman
2022-05-10 13:08 ` [PATCH 5.10 51/70] selftests: mirror_gre_bridge_1q: Avoid changing PVID while interface is operational Greg Kroah-Hartman
2022-05-10 13:08 ` [PATCH 5.10 52/70] bnxt_en: Fix possible bnxt_open() failure caused by wrong RFS flag Greg Kroah-Hartman
2022-05-10 13:08 ` [PATCH 5.10 53/70] bnxt_en: Fix unnecessary dropping of RX packets Greg Kroah-Hartman
2022-05-10 13:08 ` [PATCH 5.10 54/70] selftests: ocelot: tc_flower_chains: specify conform-exceed action for policer Greg Kroah-Hartman
2022-05-10 13:08 ` [PATCH 5.10 55/70] smsc911x: allow using IRQ0 Greg Kroah-Hartman
2022-05-10 13:08 ` [PATCH 5.10 56/70] btrfs: always log symlinks in full mode Greg Kroah-Hartman
2022-05-10 13:08 ` [PATCH 5.10 57/70] net: igmp: respect RCU rules in ip_mc_source() and ip_mc_msfilter() Greg Kroah-Hartman
2022-05-10 13:08 ` [PATCH 5.10 58/70] kvm: x86/cpuid: Only provide CPUID leaf 0xA if host has architectural PMU Greg Kroah-Hartman
2022-05-10 13:08 ` [PATCH 5.10 59/70] net/mlx5: Fix slab-out-of-bounds while reading resource dump menu Greg Kroah-Hartman
2022-05-10 13:08 ` [PATCH 5.10 60/70] x86/kvm: Preserve BSP MSR_KVM_POLL_CONTROL across suspend/resume Greg Kroah-Hartman
2022-05-10 13:08 ` [PATCH 5.10 61/70] KVM: x86: Do not change ICR on write to APIC_SELF_IPI Greg Kroah-Hartman
2022-05-10 13:08 ` [PATCH 5.10 62/70] KVM: x86/mmu: avoid NULL-pointer dereference on page freeing bugs Greg Kroah-Hartman
2022-05-10 13:08 ` [PATCH 5.10 63/70] KVM: LAPIC: Enable timer posted-interrupt only when mwait/hlt is advertised Greg Kroah-Hartman
2022-05-10 13:08 ` [PATCH 5.10 64/70] rcu: Fix callbacks processing time limit retaining cond_resched() Greg Kroah-Hartman
2022-05-10 13:08 ` [PATCH 5.10 65/70] rcu: Apply callbacks processing time limit only on softirq Greg Kroah-Hartman
2022-05-10 13:08 ` [PATCH 5.10 66/70] block-map: add __GFP_ZERO flag for alloc_page in function bio_copy_kern Greg Kroah-Hartman
2022-05-10 13:08 ` [PATCH 5.10 67/70] dm: interlock pending dm_io and dm_wait_for_bios_completion Greg Kroah-Hartman
2022-05-10 13:08 ` [PATCH 5.10 68/70] PCI: aardvark: Clear all MSIs at setup Greg Kroah-Hartman
2022-05-10 13:08 ` [PATCH 5.10 69/70] PCI: aardvark: Fix reading MSI interrupt number Greg Kroah-Hartman
2022-05-10 13:08 ` [PATCH 5.10 70/70] mmc: rtsx: add 74 Clocks in power on flow Greg Kroah-Hartman
2022-05-10 17:25 ` [PATCH 5.10 00/70] 5.10.115-rc1 review Florian Fainelli
2022-05-10 18:06 ` Pavel Machek
2022-05-10 18:38 ` Fox Chen
2022-05-10 20:44 ` Sudip Mukherjee
2022-05-12 13:32   ` Greg Kroah-Hartman
2022-05-10 22:43 ` Shuah Khan
2022-05-11  1:12 ` Guenter Roeck
2022-05-11  1:57 ` Samuel Zou
2022-05-11  5:50 ` Naresh Kamboju
2022-05-11 10:05 ` Sudip Mukherjee

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=20220510130733.546385272@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=axboe@kernel.dk \
    --cc=hoeppner@linux.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --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;
as well as URLs for NNTP newsgroup(s).