From patchwork Mon Dec 18 09:57:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nam Cao X-Patchwork-Id: 13496504 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5B925125A7; Mon, 18 Dec 2023 09:57:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="QYB7/wZC"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="2c6pIzvC" From: Nam Cao DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1702893460; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=m8g1705acTr/tgoPBJPCxDzSYFLliwXwTit5yL2vhLY=; b=QYB7/wZCAy3GKkvWhPXPJbjtv5jqKhrH0IhYndaJGvRnNE5S1hUB61ByPMusRDvNNvXgM2 Q42MtKtQcxIyvDOHEYF2bCyRS3fRHM1KxPYBheyoHag0Q60sHOgHrQe4WBs4L4E4anC+yZ XqiLqjsIHSNwrd5uf/LED1uVcwDCIqsepv6Tq0iX/+/+w5S6Ew9QTde2vjoYJDeY+j6Tjs 9VL/bFO4UEd87V4BsklZqXav85aVZRZpD1ecWcON3F/ygKc/m7ezm5g0C7R0qmcFXlFlK/ RYNSGG5Ff4hjhg06dbm+Df+XIta8gHP6ifJnPlez0yxhdqzWqMKtqAyhV/b1qg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1702893460; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=m8g1705acTr/tgoPBJPCxDzSYFLliwXwTit5yL2vhLY=; b=2c6pIzvCC2pWWiknD+IJ9Ed+Cd9zmCRkfZrO1U/2cAVRfSf59hAhENuaciIIH6Edz/mnb5 Z7ATSmsGmX1ghRCA== To: Jaya Kumar , Daniel Vetter , Helge Deller , Antonino Daplas , Andrew Morton , Paul Mundt , linux-fbdev@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Cc: bigeasy@linutronix.de, Nam Cao , stable@vger.kernel.org Subject: [PATCH 1/2] fb: flush deferred work in fb_deferred_io_fsync() Date: Mon, 18 Dec 2023 10:57:30 +0100 Message-Id: In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-fbdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The driver's fsync() is supposed to flush any pending operation to hardware. It is implemented in this driver by cancelling the queued deferred IO first, then schedule it for "immediate execution" by calling schedule_delayed_work() again with delay=0. However, setting delay=0 only means the work is scheduled immediately, it does not mean the work is executed immediately. There is no guarantee that the work is finished after schedule_delayed_work() returns. After this driver's fsync() returns, there can still be pending work. Furthermore, if close() is called by users immediately after fsync(), the pending work gets cancelled and fsync() may do nothing. To ensure that the deferred IO completes, use flush_delayed_work() instead. Write operations to this driver either write to the device directly, or invoke schedule_delayed_work(); so by flushing the workqueue, it can be guaranteed that all previous writes make it to the device. Fixes: 5e841b88d23d ("fb: fsync() method for deferred I/O flush.") Cc: stable@vger.kernel.org Signed-off-by: Nam Cao Reviewed-by: Sebastian Andrzej Siewior --- drivers/video/fbdev/core/fb_defio.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/drivers/video/fbdev/core/fb_defio.c b/drivers/video/fbdev/core/fb_defio.c index 274f5d0fa247..6c8b81c452f0 100644 --- a/drivers/video/fbdev/core/fb_defio.c +++ b/drivers/video/fbdev/core/fb_defio.c @@ -132,11 +132,7 @@ int fb_deferred_io_fsync(struct file *file, loff_t start, loff_t end, int datasy return 0; inode_lock(inode); - /* Kill off the delayed work */ - cancel_delayed_work_sync(&info->deferred_work); - - /* Run it immediately */ - schedule_delayed_work(&info->deferred_work, 0); + flush_delayed_work(&info->deferred_work); inode_unlock(inode); return 0;