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: 180234 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:24d3:b0:fb:cd0c:d3e with SMTP id r19csp1132978dyi; Mon, 18 Dec 2023 01:58:29 -0800 (PST) X-Google-Smtp-Source: AGHT+IHWjaVNtg7UZ+EIF6w2KOcrCAPp+eVIqmSbKHpKrUKBNzNaNzrWqJgZm86GMFFtRuFraqwI X-Received: by 2002:a05:6a20:7488:b0:185:a762:9179 with SMTP id p8-20020a056a20748800b00185a7629179mr21291522pzd.1.1702893509750; Mon, 18 Dec 2023 01:58:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702893509; cv=none; d=google.com; s=arc-20160816; b=hBMPValRZzDLDvyVHmMdOl7BxgWVuwFeLrEln0kp2dvQ3zwe+Fh/ejfEihqWwRf3Qu PHBcmHgI6MlFcNCFOiE8LNWegAQmZgTF9lcnods+/NmxtNQvwtwlIl9AK25EjsMSkwEF ZrhaIUU2aGQZxnAqoIpjHYzzEQImJa575a3yKPhQBgDYLcKQ6bTuueYkiHCbvFVVMkjJ GmAtVxA+15SXjjI5pHPoAa74zAB1EI9QmI9YR0Z5YQSFmBMi4N/K1ml9LWGI/s9ElHdt Qb7s7ko89ChNWnzQOUW+0ZutxLCmdfNpKMnaiRw5xGb4NEP9OX0CE0ZRw2w3idnrLCbt YqYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:dkim-signature:dkim-signature:from; bh=m8g1705acTr/tgoPBJPCxDzSYFLliwXwTit5yL2vhLY=; fh=mLUD1bUxZ6OJm/C/kpm8OdrFZ/dBXWuaVFyXdNF6ZIQ=; b=etcYAcWhKmWlHSZzrK7wNfe/glT22LOZ60CY7PsOjqxMhoUae1dv4Zo3AGTqtAwDxy EZx6uetWgOCjNGUXJOP22C8OfNUEB+Sfl75GQbU6M+iOnOI8Vzg4hQn0rA9pJ9KRJV1+ qMb+vQSmXZC7xeKE6fgoDKTwiNZNgQSHuUw0RLeskv9Dy13621qt+FKFX+TE4Ui/ZXaA +RHzAs/ilJDHC+FwM2p5mnXRYbU1WfPRyZEcbekCfyG36y/QkwrtfQj60rfeR/spNsvc /2vMFbj9xtIWpZ6FAyz/pXO9rXbgAoE4nln92WNyUz0vCGr1WCIvzD79DeDLTh74tS5H 3Ztw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="QYB7/wZC"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=2c6pIzvC; spf=pass (google.com: domain of linux-kernel+bounces-3279-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-3279-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id c22-20020a056a000ad600b006ce5357405fsi17576433pfl.9.2023.12.18.01.58.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 01:58:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-3279-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="QYB7/wZC"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=2c6pIzvC; spf=pass (google.com: domain of linux-kernel+bounces-3279-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-3279-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 8E9ECB21EE1 for ; Mon, 18 Dec 2023 09:58:27 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EDCD913AC4; Mon, 18 Dec 2023 09:57:52 +0000 (UTC) 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" X-Original-To: linux-kernel@vger.kernel.org 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 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-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785613264854921007 X-GMAIL-MSGID: 1785613264854921007 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; From patchwork Mon Dec 18 09:57:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nam Cao X-Patchwork-Id: 180235 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:24d3:b0:fb:cd0c:d3e with SMTP id r19csp1133002dyi; Mon, 18 Dec 2023 01:58:32 -0800 (PST) X-Google-Smtp-Source: AGHT+IF/bmfuRyh/AnJ0fbs3tboZ1DnxC+92u5a5ZkWEvqsZdkQzDpvGyJSOzPpPk9JuDEL8cZJb X-Received: by 2002:a05:620a:7e8:b0:77e:fba3:4f10 with SMTP id k8-20020a05620a07e800b0077efba34f10mr14587654qkk.102.1702893512391; Mon, 18 Dec 2023 01:58:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702893512; cv=none; d=google.com; s=arc-20160816; b=JXo7T7VXnCN9F5KgWdLREHymDpbnWlZuub7xre9w4Pna+0IHd0kMjLjpygb3shcKpt lRYQXNp09phufNiBJREftQv/A1Bo3+dNW66Vr/MIFREuQgYhQdqcChg/I40Jt/jPa0O+ WoGnczPNWNeJhOreMyZuT4COaWQFTk6DbkoZn8xJicUyNbWiq830LrOiwKA45z5imSO4 sTh6CNhjX+k55rRlN5k3HBwhjn2VKG0PcE0cvwvqUY7UOG6NbeVgB4sHGESlsXO52dG3 0b7QJpFNtTE8FtUoInJnGr7PCpyd1bur+awVmFbGe52IVPEjbAXhGcQA67qKnAChhBnn ft4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:dkim-signature:dkim-signature:from; bh=VQgbUD/9nx5mi5GS7bnC72VqZMbKoUb8rPJa0pNUbQg=; fh=mLUD1bUxZ6OJm/C/kpm8OdrFZ/dBXWuaVFyXdNF6ZIQ=; b=qIlbkjyMuYapk+PSijMuAxE3liH496q53QzViiAdEbJTdWkyYCzd/HTVmC/6+h0vrx hp8XbYGsiY92F0aTHrzu/mY7G9JdgQbdQv3nrYF9i8+uBE3AJq/Qm0ogOG6xCBAlytGT +mHFzYXS8SwGKU4TFdk79FrSVq4A0GzJSRgynuA5je/j/4xwidI0SqKYJBQ5D9V5e1GK L5MUDEGTJAzrY8NdhjevvLCC1fhlVkyLbfTdws47POuFfHWmO8BNyP609IRqI0y7wYVU KYrPdjYW9eLsypGfRgthmcaWMQ79ZBQ7wt/YP6N4H16MAMpk2xIzDXs1W2YHlhqLUpy1 ySdw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Kkxi3zSo; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel+bounces-3280-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-3280-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id b25-20020a05620a119900b00780ea2cf996si1612124qkk.463.2023.12.18.01.58.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 01:58:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-3280-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Kkxi3zSo; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel+bounces-3280-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-3280-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 329E91C229FC for ; Mon, 18 Dec 2023 09:58:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9F03513ADD; Mon, 18 Dec 2023 09:57:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Kkxi3zSo"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="faqY/3zT" X-Original-To: linux-kernel@vger.kernel.org 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 5B96F125AD; 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 From: Nam Cao DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1702893461; 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=VQgbUD/9nx5mi5GS7bnC72VqZMbKoUb8rPJa0pNUbQg=; b=Kkxi3zSonUFc6y94k8nGCK8agXTv2WfFgXRqzSp3Kk+EiUi7x+4dK3FUjlcRqGkqKnqrdG kb8BZYzCINHtS1fVRyZf7x+513wa1htBnuxQmfHW+ipRyBldeMol/tQQjK6WMkAxuB3x6K x8B+X5gwp697Y88VxGi60b4L/rUbzzD+8ILa8C+86UpcVy922Z+CjbUOPVqhCRDMcCDu0I 6H4/oeqWUo/2lr6tyNgT+jEndcAWIYt4FDNOfX3cSQKyo5trqc6JMZGTffcRRBnajXkN4r estX+xLS1zqN2YQaL4H1thIpODq6P2R9DzFsGaaBWsuXXA+2hNhFi/W0S98fWw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1702893461; 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=VQgbUD/9nx5mi5GS7bnC72VqZMbKoUb8rPJa0pNUbQg=; b=faqY/3zT2f1RnxKjUVyMNBjYHnbagbsIJ2OtxRfsf+0e6/fXqcPT1MzTJJJRoZZvDJzJid B41FU8hSdvRtjnAA== 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 2/2] fb: flush deferred IO before closing Date: Mon, 18 Dec 2023 10:57:31 +0100 Message-Id: In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785613267801774769 X-GMAIL-MSGID: 1785613267801774769 When framebuffer gets closed, the queued deferred IO gets cancelled. This can cause some last display data to vanish. This is problematic for users who send a still image to the framebuffer, then close the file: the image may never appear. To ensure none of display data get lost, flush the queued deferred IO first before closing. Another possible solution is to delete the cancel_delayed_work_sync() instead. The difference is that the display may appear some time after closing. However, the clearing of page mapping after this needs to be removed too, because the page mapping is used by the deferred work. It is not completely obvious whether it is okay to not clear the page mapping. For a patch intended for stable trees, go with the simple and obvious solution. Fixes: 60b59beafba8 ("fbdev: mm: Deferred IO support") Cc: stable@vger.kernel.org Signed-off-by: Nam Cao Reviewed-by: Sebastian Andrzej Siewior --- drivers/video/fbdev/core/fb_defio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/video/fbdev/core/fb_defio.c b/drivers/video/fbdev/core/fb_defio.c index 6c8b81c452f0..1ae1d35a5942 100644 --- a/drivers/video/fbdev/core/fb_defio.c +++ b/drivers/video/fbdev/core/fb_defio.c @@ -313,7 +313,7 @@ static void fb_deferred_io_lastclose(struct fb_info *info) struct page *page; int i; - cancel_delayed_work_sync(&info->deferred_work); + flush_delayed_work(&info->deferred_work); /* clear out the mapping that we setup */ for (i = 0 ; i < info->fix.smem_len; i += PAGE_SIZE) {