From: Martin Schwidefsky <schwidefsky@de.ibm.com>
To: linux-kernel@vger.kernel.org, linux-s390@vger.kernel.org
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>,
Stefan Haberland <stefan.haberland@de.ibm.com>,
Martin Schwidefsky <schwidefsky@de.ibm.com>
Subject: [patch 23/32] [PATCH] dasd: fix online/offline race
Date: Wed, 24 Feb 2010 09:44:53 +0100 [thread overview]
Message-ID: <20100224084451.956294578@de.ibm.com> (raw)
In-Reply-To: 20100224084430.193562869@de.ibm.com
[-- Attachment #1: 122-dasd-onoff-race.diff --]
[-- Type: text/plain, Size: 4266 bytes --]
From: Stefan Haberland <stefan.haberland@de.ibm.com>
Setting a DASD online and offline in quick succession may cause
a kernel panic or let the chhccwdev command wait forever.
The Online process is split into two parts. After the first part
is finished the offline process may be called. This may result
in a situation where the second online processing part tries to
set the DASD offline as well.
Use a mutex to protect online and offline against each other.
Also correct some checking.
Signed-off-by: Stefan Haberland <stefan.haberland@de.ibm.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
---
drivers/s390/block/dasd.c | 22 ++++++++++++++--------
drivers/s390/block/dasd_genhd.c | 1 +
drivers/s390/block/dasd_int.h | 1 +
3 files changed, 16 insertions(+), 8 deletions(-)
Index: quilt-2.6/drivers/s390/block/dasd.c
===================================================================
--- quilt-2.6.orig/drivers/s390/block/dasd.c 2010-02-24 09:28:13.000000000 +0100
+++ quilt-2.6/drivers/s390/block/dasd.c 2010-02-24 09:44:27.000000000 +0100
@@ -20,6 +20,7 @@
#include <linux/buffer_head.h>
#include <linux/hdreg.h>
#include <linux/async.h>
+#include <linux/mutex.h>
#include <asm/ccwdev.h>
#include <asm/ebcdic.h>
@@ -112,6 +113,7 @@
INIT_WORK(&device->restore_device, do_restore_device);
device->state = DASD_STATE_NEW;
device->target = DASD_STATE_NEW;
+ mutex_init(&device->state_mutex);
return device;
}
@@ -484,10 +486,8 @@
if (rc)
device->target = device->state;
- if (device->state == device->target) {
+ if (device->state == device->target)
wake_up(&dasd_init_waitq);
- dasd_put_device(device);
- }
/* let user-space know that the device status changed */
kobject_uevent(&device->cdev->dev.kobj, KOBJ_CHANGE);
@@ -502,7 +502,9 @@
static void do_kick_device(struct work_struct *work)
{
struct dasd_device *device = container_of(work, struct dasd_device, kick_work);
+ mutex_lock(&device->state_mutex);
dasd_change_state(device);
+ mutex_unlock(&device->state_mutex);
dasd_schedule_device_bh(device);
dasd_put_device(device);
}
@@ -539,18 +541,19 @@
void dasd_set_target_state(struct dasd_device *device, int target)
{
dasd_get_device(device);
+ mutex_lock(&device->state_mutex);
/* If we are in probeonly mode stop at DASD_STATE_READY. */
if (dasd_probeonly && target > DASD_STATE_READY)
target = DASD_STATE_READY;
if (device->target != target) {
- if (device->state == target) {
+ if (device->state == target)
wake_up(&dasd_init_waitq);
- dasd_put_device(device);
- }
device->target = target;
}
if (device->state != device->target)
dasd_change_state(device);
+ mutex_unlock(&device->state_mutex);
+ dasd_put_device(device);
}
/*
@@ -1692,7 +1695,6 @@
cqr, rc);
} else {
cqr->stopclk = get_clock();
- rc = 1;
}
break;
default: /* already finished or clear pending - do nothing */
@@ -2170,9 +2172,13 @@
static int dasd_open(struct block_device *bdev, fmode_t mode)
{
struct dasd_block *block = bdev->bd_disk->private_data;
- struct dasd_device *base = block->base;
+ struct dasd_device *base;
int rc;
+ if (!block)
+ return -ENODEV;
+
+ base = block->base;
atomic_inc(&block->open_count);
if (test_bit(DASD_FLAG_OFFLINE, &base->flags)) {
rc = -ENODEV;
Index: quilt-2.6/drivers/s390/block/dasd_genhd.c
===================================================================
--- quilt-2.6.orig/drivers/s390/block/dasd_genhd.c 2010-02-24 09:28:13.000000000 +0100
+++ quilt-2.6/drivers/s390/block/dasd_genhd.c 2010-02-24 09:44:27.000000000 +0100
@@ -88,6 +88,7 @@
if (block->gdp) {
del_gendisk(block->gdp);
block->gdp->queue = NULL;
+ block->gdp->private_data = NULL;
put_disk(block->gdp);
block->gdp = NULL;
}
Index: quilt-2.6/drivers/s390/block/dasd_int.h
===================================================================
--- quilt-2.6.orig/drivers/s390/block/dasd_int.h 2010-02-24 09:28:13.000000000 +0100
+++ quilt-2.6/drivers/s390/block/dasd_int.h 2010-02-24 09:44:27.000000000 +0100
@@ -368,6 +368,7 @@
/* Device state and target state. */
int state, target;
+ struct mutex state_mutex;
int stopped; /* device (ccw_device_start) was stopped */
/* reference count. */
next prev parent reply other threads:[~2010-02-24 8:47 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-02-24 8:44 [patch 00/32] s390 patch queue for 2.6.34 Martin Schwidefsky
2010-02-24 8:44 ` [patch 01/32] [PATCH] uaccess: implement strict user copy checks Martin Schwidefsky
2010-02-24 8:44 ` [patch 02/32] [PATCH] adapt text to cu3088-removal Martin Schwidefsky
2010-02-24 8:44 ` [patch 03/32] [PATCH] cio: consolidate workqueues Martin Schwidefsky
2010-02-24 8:44 ` [patch 04/32] [PATCH] cio: introduce cio_settle Martin Schwidefsky
2010-02-24 8:44 ` [patch 05/32] [PATCH] cio: wait for channel report Martin Schwidefsky
2010-02-24 8:44 ` [patch 06/32] [PATCH] cio: make wait_events interruptible Martin Schwidefsky
2010-02-24 8:44 ` [patch 07/32] [PATCH] use inline assembly contraints available with gcc 3.3.3 Martin Schwidefsky
2010-02-24 8:44 ` [patch 08/32] [PATCH] zfcpdump: remove cross arch dump support Martin Schwidefsky
2010-02-24 8:44 ` [patch 09/32] [PATCH] smp: rename and add lowcore defines Martin Schwidefsky
2010-02-24 8:44 ` [patch 10/32] [PATCH] smp: always reboot on cpu 0 Martin Schwidefsky
2010-02-24 8:44 ` [patch 11/32] [PATCH] qdio: account processed SBAL during queue scan Martin Schwidefsky
2010-02-24 8:44 ` [patch 12/32] [PATCH] qdio: optimize cache line usage of struct qdio_irq Martin Schwidefsky
2010-02-24 8:44 ` [patch 13/32] [PATCH] add MACHINE_IS_LPAR flag Martin Schwidefsky
2010-02-24 8:44 ` [patch 14/32] [PATCH] sysinfo: fix SYSIB 3,2,2 structure Martin Schwidefsky
2010-02-24 8:44 ` [patch 15/32] [PATCH] spinlock: check virtual cpu running status Martin Schwidefsky
2010-02-24 8:44 ` [patch 16/32] [PATCH] smp: rework sigp code Martin Schwidefsky
2010-02-24 8:44 ` [patch 17/32] [PATCH] Replace ENOTSUPP usage with EOPNOTSUPP Martin Schwidefsky
2010-02-24 8:44 ` [patch 18/32] [PATCH] free_initmem: reduce code duplication Martin Schwidefsky
2010-02-24 8:44 ` [patch 19/32] [PATCH] ccw_device_notify: improve return codes Martin Schwidefsky
2010-02-24 8:44 ` [patch 20/32] [PATCH] Cleanup struct _lowcore usage and defines Martin Schwidefsky
2010-02-24 8:44 ` [patch 21/32] [PATCH] bug: use relative pointers in bug table entries Martin Schwidefsky
2010-02-24 8:44 ` [patch 22/32] [PATCH] use kprobes_built_in() in mm/fault code Martin Schwidefsky
2010-02-24 8:44 ` Martin Schwidefsky [this message]
2010-02-24 8:44 ` [patch 24/32] [PATCH] add z9-ec/z10 instruction to kernel disassembler Martin Schwidefsky
2010-02-24 8:44 ` [patch 25/32] [PATCH] seq_file: convert drivers/s390/ Martin Schwidefsky
2010-02-24 8:44 ` [patch 26/32] [PATCH] codepage conversion of kernel parameter line Martin Schwidefsky
2010-02-24 8:44 ` [patch 27/32] [PATCH] Define new s390 ELF note sections in elf.h Martin Schwidefsky
2010-02-24 8:44 ` [patch 28/32] [PATCH] add support for compressed kernels Martin Schwidefsky
2010-02-24 8:44 ` [patch 29/32] [PATCH] correct vdso version string Martin Schwidefsky
2010-02-24 8:45 ` [patch 30/32] [PATCH] dasd: fix refcounting Martin Schwidefsky
2010-02-24 8:45 ` [patch 31/32] [PATCH] dasd: correct offline processing Martin Schwidefsky
2010-02-24 8:45 ` [patch 32/32] [PATCH] cio: trigger subchannel event at resume time Martin Schwidefsky
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=20100224084451.956294578@de.ibm.com \
--to=schwidefsky@de.ibm.com \
--cc=heiko.carstens@de.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=stefan.haberland@de.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