Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp1748347rwb; Fri, 13 Jan 2023 17:28:15 -0800 (PST) X-Google-Smtp-Source: AMrXdXt4IM1djlNpuH98tLPB/dWvNYvAa8XCUf8w/6Gv7dg7rSMes/vQvcYEsS7f3CWNazpQRrvl X-Received: by 2002:a05:6402:ea0:b0:46f:68d0:76 with SMTP id h32-20020a0564020ea000b0046f68d00076mr59199933eda.34.1673659695264; Fri, 13 Jan 2023 17:28:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673659695; cv=none; d=google.com; s=arc-20160816; b=Oy/iwRlMgVD1uU3ge+M/dORBM4pYt5wXJj5la8u+HSFa6awYV1e2te8GjLXQILjtkL Xb8KLh+ktGOUh2H1tLMIe+rRnXUnyHd5MSfv3acNmQ54urBxXzucJNUzVy7PTJKMl9bg RZjkk53YbaT/dlzyBbrWGzDsA/2xayi5sfwCzvM8ABp8kf+MMEUkGHJ146FVy+mWc8hE kggj6Wocx3p6Q4pmne/5JFIndLED02dgHFZl6WBd6ZOxFbf8kJGKv9Avwv/3C2v2kOIy CpKVnR+IgmpkS7UOAtJCYVp8Mo9FdkgnKFB7Bpm4Ih5e/4+YKgoCKAD1eFiIpvVnMd+j 4Jow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=CGsJcztlThk4CgsiupU0gvJXFQOv3l5tW0Vt+zlS+z8=; b=miJf0MqxlDyvnITboj/XeYbTvQ/oXkeaJNGjEqOedrZr1FDXU0Ue3aTdOAt/QLEtRg oaZdiQP/q6QTdIrO+s4iA5BSbk3zPY+lTauiiBDX4iNIc46/5jifCPhMIg/CmkfucceV uN7c0BAgi8jP+o1CayhMWoTLqkNidkv3s4PEexe7LGWetgdWyv8hp/e6CfAO9pveG8Vx /3ZK7Df+qVHwKFLtgLzVmuQFZmziFzjAZ6XREAgtm9QsoLEihfDw4onJY5yoSE6ew767 KdZyGTBevHGr4LvqZJRsrv71m/ZLxUM6+5mb3bkRttyJ20nj1lf7YaK5e938NCV1YQ6y a/Wg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=Hvx6VaTN; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u1-20020a50a401000000b0048ee37983a0si22227134edb.178.2023.01.13.17.28.02; Fri, 13 Jan 2023 17:28:15 -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=@infradead.org header.s=bombadil.20210309 header.b=Hvx6VaTN; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231586AbjANAgF (ORCPT + 53 others); Fri, 13 Jan 2023 19:36:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231312AbjANAe1 (ORCPT ); Fri, 13 Jan 2023 19:34:27 -0500 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 260478B510; Fri, 13 Jan 2023 16:34:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=CGsJcztlThk4CgsiupU0gvJXFQOv3l5tW0Vt+zlS+z8=; b=Hvx6VaTNodjdswA1N4v3aC97za 2r69ZOmOduRpIOs585YEe30i7gOTugcSY0v4Mi5PddMA5vCZlIgazqgaAFONcT6Rqa9PU8KdoHtfD NGqh198vGupKa2+bQKtgXOdQneFnxv5Ed1smbzHTX2lAOZMeamxy3l6UDpTfK4gDvi29Iv1EeM0gq /4w/eotHLvYVBoUpUpAYmRJkZLvpUuucPQXe05edlHqBVTqNQ4I7O3XZYDmZTkXpUykyi9PgfotpY INolQKjWlbya2Teto7gIDiyOLkJOuAh/hwE1Fgp4mRtFGsIBzdDhOIZIpX4zP7gsv6Qihes9vID6t Jt+IcsNQ==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pGUUt-004twT-LL; Sat, 14 Jan 2023 00:34:11 +0000 From: Luis Chamberlain To: hch@infradead.org, djwong@kernel.org, song@kernel.org, rafael@kernel.org, gregkh@linuxfoundation.org, viro@zeniv.linux.org.uk, jack@suse.cz, bvanassche@acm.org, ebiederm@xmission.com Cc: mchehab@kernel.org, keescook@chromium.org, p.raghav@samsung.com, linux-fsdevel@vger.kernel.org, kernel@tuxforce.de, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, Luis Chamberlain Subject: [RFC v3 17/24] ksmbd: replace kthread freezing with auto fs freezing Date: Fri, 13 Jan 2023 16:34:02 -0800 Message-Id: <20230114003409.1168311-18-mcgrof@kernel.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230114003409.1168311-1-mcgrof@kernel.org> References: <20230114003409.1168311-1-mcgrof@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: Luis Chamberlain X-Spam-Status: No, score=-4.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE 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 The kernel power management now supports allowing the VFS to handle filesystem freezing freezes and thawing. Take advantage of that and remove the kthread freezing. This is needed so that we properly really stop IO in flight without races after userspace has been frozen. Without this we rely on kthread freezing and its semantics are loose and error prone. The filesystem therefore is in charge of properly dealing with quiescing of the filesystem through its callbacks if it thinks it knows better than how the VFS handles it. The following Coccinelle rule was used as to remove the now superflous freezer calls: spatch --sp-file fs-freeze-cleanup.cocci --in-place --timeout 120 --dir fs/nfs --jobs 12 --use-gitgrep @ remove_set_freezable @ expression time; statement S, S2; expression task, current; @@ ( - set_freezable(); | - if (try_to_freeze()) - continue; | - try_to_freeze(); | - freezable_schedule(); + schedule(); | - freezable_schedule_timeout(time); + schedule_timeout(time); | - if (freezing(task)) { S } | - if (freezing(task)) { S } - else { S2 } | - freezing(current) ) @ remove_wq_freezable @ expression WQ_E, WQ_ARG1, WQ_ARG2, WQ_ARG3, WQ_ARG4; identifier fs_wq_fn; @@ ( WQ_E = alloc_workqueue(WQ_ARG1, - WQ_ARG2 | WQ_FREEZABLE, + WQ_ARG2, ...); | WQ_E = alloc_workqueue(WQ_ARG1, - WQ_ARG2 | WQ_FREEZABLE | WQ_ARG3, + WQ_ARG2 | WQ_ARG3, ...); | WQ_E = alloc_workqueue(WQ_ARG1, - WQ_ARG2 | WQ_ARG3 | WQ_FREEZABLE, + WQ_ARG2 | WQ_ARG3, ...); | WQ_E = alloc_workqueue(WQ_ARG1, - WQ_ARG2 | WQ_ARG3 | WQ_FREEZABLE | WQ_ARG4, + WQ_ARG2 | WQ_ARG3 | WQ_ARG4, ...); | WQ_E = - WQ_ARG1 | WQ_FREEZABLE + WQ_ARG1 | WQ_E = - WQ_ARG1 | WQ_FREEZABLE | WQ_ARG3 + WQ_ARG1 | WQ_ARG3 | fs_wq_fn( - WQ_FREEZABLE | WQ_ARG2 | WQ_ARG3 + WQ_ARG2 | WQ_ARG3 ) | fs_wq_fn( - WQ_FREEZABLE | WQ_ARG2 + WQ_ARG2 ) | fs_wq_fn( - WQ_FREEZABLE + 0 ) ) @ add_auto_flag @ expression E1; identifier fs_type; @@ struct file_system_type fs_type = { .fs_flags = E1 + | FS_AUTOFREEZE , }; Generated-by: Coccinelle SmPL Signed-off-by: Luis Chamberlain --- fs/ksmbd/connection.c | 3 --- fs/ksmbd/transport_tcp.c | 2 -- 2 files changed, 5 deletions(-) diff --git a/fs/ksmbd/connection.c b/fs/ksmbd/connection.c index fd0a288af299..4ed17de1423e 100644 --- a/fs/ksmbd/connection.c +++ b/fs/ksmbd/connection.c @@ -292,9 +292,6 @@ int ksmbd_conn_handler_loop(void *p) conn->last_active = jiffies; while (ksmbd_conn_alive(conn)) { - if (try_to_freeze()) - continue; - kvfree(conn->request_buf); conn->request_buf = NULL; diff --git a/fs/ksmbd/transport_tcp.c b/fs/ksmbd/transport_tcp.c index 4c6bd0b69979..dadb4f306428 100644 --- a/fs/ksmbd/transport_tcp.c +++ b/fs/ksmbd/transport_tcp.c @@ -305,8 +305,6 @@ static int ksmbd_tcp_readv(struct tcp_transport *t, struct kvec *iov_orig, ksmbd_msg.msg_controllen = 0; for (total_read = 0; to_read; total_read += length, to_read -= length) { - try_to_freeze(); - if (!ksmbd_conn_alive(conn)) { total_read = -ESHUTDOWN; break; -- 2.35.1