From patchwork Sun Jan 29 08:28:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 49946 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1664824wrn; Sun, 29 Jan 2023 00:43:01 -0800 (PST) X-Google-Smtp-Source: AK7set/DxnjZzuWhSrn1FR+BEKozQq+ZysQrsCtENz6rL+/CKpyX4lCo1MuAvM+wPHMEcvyUS/fl X-Received: by 2002:a17:90b:4f46:b0:22c:1211:89c0 with SMTP id pj6-20020a17090b4f4600b0022c121189c0mr15593032pjb.30.1674981781386; Sun, 29 Jan 2023 00:43:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674981781; cv=none; d=google.com; s=arc-20160816; b=bUuHcA9j30FuV7Vrz0KsVUX4dRb/nEEny9oXdrKsfDmRCZ/1D8AZkWUZb//Ze2X1jT 3x8N5FqIvtnVGi20z/2KFNsj8tjcl4ilnwCFUO9FU+TOT9UtKL3tY3P/Ve8VqqxaF/Qn X6YfrdYpfNi5SDaEDddSbt52Owsoixrw8WQZCE0mFYvIXH3qJzD7AvX5oedkFm++E8kE /3DugvoR42qvY2ltY+CWzwhDWO4RT7gMUi/9pLZPIx+7TAHvicGnfkUhrEMVfTx+OMsM 3Br4SpBzGQKNYwNEys0DLm9PbxzwKKgQpqjnNtMyw/JI2Phz8S5L6ve3+3ZiD5xwNIRY vsgg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature:dkim-signature; bh=L4YFbahCifwwNGpSJHPlW/1QYyuaOZX6D/eqp4s/nSE=; b=nw2c5VIvzw3eRS+lErr2AAt2OQeh64K4oyoABAwmegD+0ciImF0NS4GshqSwPTmFC9 K8xRclo2GhUBa2czuYdSJHipN89iez9E6CAniHXxBxRDIhFlFnSy2k6CgkUb8czadW/Y pXrQ8zK9YpgPofWcj45zBKXzdzXiOxFjIq5id4BhW2PMXMUZYPCOjR6oPTa5wmUXvRM7 JJmC0aqTr346mysLHcFeYat1OfpdFzRsH5mKlGdMexEZRGQJjOztucxc8mOrBh97MXLx 9nNawWQV7xl/nXkdwd2UhQVueYdmL+2NUzLgW1qEswmQ3LC4CVZoVEbalf56xcltDDmb WZFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=wG9LqxUv; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=aJBBaFkc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n28-20020a638f1c000000b0049f478df3b8si5991704pgd.702.2023.01.29.00.42.45; Sun, 29 Jan 2023 00:43:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=wG9LqxUv; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=aJBBaFkc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230223AbjA2I3F (ORCPT + 99 others); Sun, 29 Jan 2023 03:29:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34416 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229519AbjA2I3E (ORCPT ); Sun, 29 Jan 2023 03:29:04 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 368AE21A36; Sun, 29 Jan 2023 00:29:03 -0800 (PST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id C930D1FF23; Sun, 29 Jan 2023 08:29:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1674980941; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=L4YFbahCifwwNGpSJHPlW/1QYyuaOZX6D/eqp4s/nSE=; b=wG9LqxUvn0B/3NHh1jHP/DoBhhKWeNXg0z3EtQdDzFKIJ6udcKBLL9F453m2TvdUm5UkhA vi7asR++R59lfDNP1p7wEq2iqKQBETkedxDmFGhVdWeEKWbq3ORhRT0IZKbEwsAT936s3M k6lVJiF4qfSQe09Gqq7Y5amEmIs6NZA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1674980941; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=L4YFbahCifwwNGpSJHPlW/1QYyuaOZX6D/eqp4s/nSE=; b=aJBBaFkcPkCwOvnJtKzzHHF0OO4DfuMnGxxAePMlyPH8O4ShKDis4hsX0+3HG3cknLFRgR mNdTtl6HwqapEhBw== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id A34E813918; Sun, 29 Jan 2023 08:29:01 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id IV42J00u1mO3SQAAMHmgww (envelope-from ); Sun, 29 Jan 2023 08:29:01 +0000 From: Takashi Iwai To: Helge Deller Cc: linux-fbdev@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Patrik Jakobsson , Thomas Zimmermann Subject: [PATCH v2] fbdev: Fix invalid page access after closing deferred I/O devices Date: Sun, 29 Jan 2023 09:28:56 +0100 Message-Id: <20230129082856.22113-1-tiwai@suse.de> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756345696446968461?= X-GMAIL-MSGID: =?utf-8?q?1756345696446968461?= When a fbdev with deferred I/O is once opened and closed, the dirty pages still remain queued in the pageref list, and eventually later those may be processed in the delayed work. This may lead to a corruption of pages, hitting an Oops. This patch makes sure to cancel the delayed work and clean up the pageref list at closing the device for addressing the bug. A part of the cleanup code is factored out as a new helper function that is called from the common fb_release(). Reviewed-by: Patrik Jakobsson Cc: Signed-off-by: Takashi Iwai Tested-by: Miko Larsson Reviewed-by: Thomas Zimmermann --- v1->v2: Fix build error without CONFIG_FB_DEFERRED_IO drivers/video/fbdev/core/fb_defio.c | 10 +++++++++- drivers/video/fbdev/core/fbmem.c | 4 ++++ include/linux/fb.h | 1 + 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/drivers/video/fbdev/core/fb_defio.c b/drivers/video/fbdev/core/fb_defio.c index c730253ab85c..583cbcf09446 100644 --- a/drivers/video/fbdev/core/fb_defio.c +++ b/drivers/video/fbdev/core/fb_defio.c @@ -313,7 +313,7 @@ void fb_deferred_io_open(struct fb_info *info, } EXPORT_SYMBOL_GPL(fb_deferred_io_open); -void fb_deferred_io_cleanup(struct fb_info *info) +void fb_deferred_io_release(struct fb_info *info) { struct fb_deferred_io *fbdefio = info->fbdefio; struct page *page; @@ -327,6 +327,14 @@ void fb_deferred_io_cleanup(struct fb_info *info) page = fb_deferred_io_page(info, i); page->mapping = NULL; } +} +EXPORT_SYMBOL_GPL(fb_deferred_io_release); + +void fb_deferred_io_cleanup(struct fb_info *info) +{ + struct fb_deferred_io *fbdefio = info->fbdefio; + + fb_deferred_io_release(info); kvfree(info->pagerefs); mutex_destroy(&fbdefio->lock); diff --git a/drivers/video/fbdev/core/fbmem.c b/drivers/video/fbdev/core/fbmem.c index 3a6c8458eb8d..ab3545a00abc 100644 --- a/drivers/video/fbdev/core/fbmem.c +++ b/drivers/video/fbdev/core/fbmem.c @@ -1454,6 +1454,10 @@ __releases(&info->lock) struct fb_info * const info = file->private_data; lock_fb_info(info); +#if IS_ENABLED(CONFIG_FB_DEFERRED_IO) + if (info->fbdefio) + fb_deferred_io_release(info); +#endif if (info->fbops->fb_release) info->fbops->fb_release(info,1); module_put(info->fbops->owner); diff --git a/include/linux/fb.h b/include/linux/fb.h index 96b96323e9cb..73eb1f85ea8e 100644 --- a/include/linux/fb.h +++ b/include/linux/fb.h @@ -662,6 +662,7 @@ extern int fb_deferred_io_init(struct fb_info *info); extern void fb_deferred_io_open(struct fb_info *info, struct inode *inode, struct file *file); +extern void fb_deferred_io_release(struct fb_info *info); extern void fb_deferred_io_cleanup(struct fb_info *info); extern int fb_deferred_io_fsync(struct file *file, loff_t start, loff_t end, int datasync);