From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-yw1-f180.google.com (mail-yw1-f180.google.com [209.85.128.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D5B33426D24 for ; Wed, 13 May 2026 12:51:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778676715; cv=none; b=PlmG9biCQRDACkPbgSFo5fFO+hWiKd4g7iUxQ4ROji2ZfQwx0QD8MoxOk8RVs8OJEN7WzqL9GX1jIyh56XcgjvohNstXmHBRpJYqHVmTA7Hs2H/tG/1ZaX5NY7ftYg7r6Are1jvJXBbBqfWVG7yLJEsLTEFJBIjWelii2ykbbfU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778676715; c=relaxed/simple; bh=q1ZzCv3qy931Od931muGLANVwooKhx0f1Vn6rfQqN0s=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=HD/hDgizTHOreVMtCfq+5xSh5IZNtXZznAcrPtIsKAQm7cRzN4PPJsvRQAt+eWZZTMTv4xNQjtzhdW3DVs1LthC5I3IDbtwjekx7S7j0bVXBMLwQF+6L98CHbbRn9EC7GqKTz3LM5gX9zUC9rk99R2rG9d1OdnAi96J9eTLQmIs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.com; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.128.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-yw1-f180.google.com with SMTP id 00721157ae682-7bf02533706so62111467b3.0 for ; Wed, 13 May 2026 05:51:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778676713; x=1779281513; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:reply-to:user-agent:mime-version:date :message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=Fmqp9pIMfFQVUOf0gODDSHc+R5Yka09MdAc/3G4zwFg=; b=FeLX+iB5GCPy7G/gzpD26BzHFlvvziAksIjtYHELIWuJzSaxTsZFLj5FM6kF7jEPlZ 5qej8KPrOs9Lxkp5y4LxbjyPKEGYcu/b/iiMA4A1tKCHnwB4aHMsp98N7bUC/UQvUEwI s5KTt8rY8jdAPyLZivpMpNATLnAw/fBFd32qguPktNKbr+b3YDcn2ndbjciI3MX9urIv uGOEcjlIEqF2XfOWUDMuqsSjJrL+wcM8L7UAl3B70nnJsCaGQJISXv+OrGnUzcMXgjFD 9B86tf6HmdVDb4hfnKzYwAy2sFHTT376QdofeyzGiS5elZT7e554epipoMAJGbvJJY9+ 0NHw== X-Forwarded-Encrypted: i=1; AFNElJ+tRBig1Bj+w3Q0223aep26YUA3ZeMs66EzZmkFENnDIWvqq7jTEIxXKVP2EnEdnYyXlFrXL/2GnAixB84=@vger.kernel.org X-Gm-Message-State: AOJu0YwaYhwJdO6QL7JK1gkheic9YgFz30tTc+ZF3ED3r7JHUTe+uQyU MMVovE5SiRbxMVmk3e7otWiYU3buZG8NHO7iputAG/bi9iey8SlPaukR X-Gm-Gg: Acq92OFf3gZiyWUkMhS1V/1hAx70bykRew1wlnbjJnBA8adL8QRSwZ2JvCjnt7SYACG uvqZBMbJThtPqsP5Bjo/hYorvKAvOjVkIhOrJb7vTXpYUI3sg+smdqZ0OtwNosBOBxJaq1IMyHD Y+8SNJjLNpU5dBaEbDshft9AlMNXnP0geREgGnB01K2q0NeLBHsvrX9rEBgqvLtu0O0pQptO5hp uZacKNDyDhzN7UhoUKv9GjQ+1dHAXv29b2FQTr2KTQeeLvSetUrLrpDkJUm467+rCAcZ5W+lUmQ jAYT2dGBgrIFwtx3k9xhiTpZIGK+q2uw8z6xaX5Q0TTy/YW2cLVzpMaZbmm5Nsutcb3NgaVFufS 5UJduRXxm4V0GeECmiHIsWEsYBMTtvg0w391aYO+RKeJfQT9I11TcVLPjOYINNpDs+vMl7FdluD i2TTIVfbvFI3HljNy+6bicb55DaDtuneBCTZcxTitczM66vX1I7qxn/tShWLA+Gbg= X-Received: by 2002:a05:690c:7407:b0:7bd:5cc4:1962 with SMTP id 00721157ae682-7c6dd0af4e6mr22242187b3.48.1778676712899; Wed, 13 May 2026 05:51:52 -0700 (PDT) Received: from [10.68.32.41] (bba-217-164-201-253.alshamil.net.ae. [217.164.201.253]) by smtp.gmail.com with ESMTPSA id 00721157ae682-7bd6686fbcdsm177353557b3.40.2026.05.13.05.51.50 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 13 May 2026 05:51:52 -0700 (PDT) Message-ID: Date: Wed, 13 May 2026 16:51:47 +0400 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Reply-To: efremov@linux.com Subject: Re: [PATCH] floppy: force media-change checks when clearing events To: Cen Zhang , axboe@kernel.dk Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, baijiaju1990@gmail.com References: <20260506010248.3275696-1-zzzccc427@gmail.com> Content-Language: en-US, ru-RU From: "Denis Efremov (Oracle)" In-Reply-To: <20260506010248.3275696-1-zzzccc427@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Hello, On 06/05/2026 05:02, Cen Zhang wrote: > floppy_open() tries to make blocking read/write opens perform a fresh > media-change check by clearing drive_state[drive].last_checked before > calling disk_check_media_change(). That timestamp is also updated by > disk_change() when another FDC operation observes that the disk-change > line is clear. > > The worker path that calls disk_change() is not serialized by the > floppy_mutex/open_lock pair held by floppy_open(). A worker can therefore > store a recent jiffies value after floppy_open() stores zero and before the > synchronous disk_check_media_change() call reaches floppy_check_events(). > The checkfreq throttle can then treat the media-change state as fresh and > skip the hardware poll that the open path explicitly tried to force. Thanks for the report and patch. The race you describe is real. However, the proposed fix introduces a regression on the close path that I don't think we can take as-is. > > Use the block layer's clearing mask instead of a racy timestamp sentinel. > When DISK_EVENT_MEDIA_CHANGE is being synchronously cleared, bypass the > checkfreq throttle and poll the drive. Periodic event checks still use > last_checked to avoid unnecessary polling, and floppy_open() no longer > needs to write last_checked itself. bdev_release() unconditionally calls disk_flush_events(disk, DISK_EVENT_MEDIA_CHANGE); on every final fput() of a block device. disk_flush_events() is not a no-op. I'm afraid that after this patch every close of /dev/fd0 (or any floppy partition) forces a synchronous FDC poll. > > Signed-off-by: Cen Zhang > --- > drivers/block/floppy.c | 5 +++-- > 1 file changed, 3 insertions(+), 2 deletions(-) > > diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c > index 92e446a643712..7217db0b907b3 100644 > --- a/drivers/block/floppy.c > +++ b/drivers/block/floppy.c > @@ -4051,7 +4051,6 @@ static int floppy_open(struct gendisk *disk, blk_mode_t mode) > fdc_state[FDC(drive)].rawcmd = 2; > if (!(mode & BLK_OPEN_NDELAY)) { > if (mode & (BLK_OPEN_READ | BLK_OPEN_WRITE)) { > - drive_state[drive].last_checked = 0; > clear_bit(FD_OPEN_SHOULD_FAIL_BIT, > &drive_state[drive].flags); > if (disk_check_media_change(disk)) > @@ -4092,7 +4091,9 @@ static unsigned int floppy_check_events(struct gendisk *disk, > test_bit(FD_VERIFY_BIT, &drive_state[drive].flags)) > return DISK_EVENT_MEDIA_CHANGE; > > - if (time_after(jiffies, drive_state[drive].last_checked + drive_params[drive].checkfreq)) { > + if ((clearing & DISK_EVENT_MEDIA_CHANGE) || > + time_after(jiffies, drive_state[drive].last_checked + > + drive_params[drive].checkfreq)) { > if (lock_fdc(drive)) > return 0; > poll_drive(false, 0); For v2 I think we should avoid using the block-layer clearing mask as a force-poll signal. We can make floppy_open() do the forced open-time poll directly under lock_fdc(), then let disk_check_media_change() observe the resulting state. This code pattern is already lives in FDPOLLDRVSTAT/FDFMTBEG handling branches. Denis