Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp1645994rwb; Sun, 14 Aug 2022 08:38:28 -0700 (PDT) X-Google-Smtp-Source: AA6agR7tTZg7dduPmiwDT96Ocv4jzvb4cCliuwWThjX4gFHaKjDk/tGn6XJKEWMpaOZWi9NRthZe X-Received: by 2002:a05:6402:28ca:b0:43b:5235:f325 with SMTP id ef10-20020a05640228ca00b0043b5235f325mr11114920edb.320.1660491508200; Sun, 14 Aug 2022 08:38:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660491508; cv=none; d=google.com; s=arc-20160816; b=pdPnLpWekZ4iRUd3mjfNsmT7SLo1s+phMwO+dKTvhyXE7uBRM1+k9NKv0za77X06Xn Bxyx9bjvgb17lqbki5K/NulSMuQVGrwDab6ybYQGwhKNm2ULiiW7nlo63eg8R9LeYLo9 LJiuTEXJpBuh8woo6/OMZpGSIEjHrP22unyen6QVTKGZhCFRF6diAhmyGhE8Yek80tv2 GY7f3DY5aXEiMGgsWvHoTmOLwY3jnPvuPjGgZlEJYhglJ0+x/X55K0Vj/mvEo6Z+0pXm 9NL0QsAaCBV3rb1J1V57KyciGjxJ55otZxCabBrmImN15I4lrJIZ10PGG4m+468Bnikw T9Xw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=110rKKmPU1bQ5SR56qm/mtQL5lQaugblXeo8yIwE5ik=; b=eYfdegJ8PE0vTfumoHPuebN4M/X9OGqxf3aSA/F40jKrmE/2baLt7Oa2DKSz0Z27Sf Dl7Z8HFHkG081wx2O/hdg+zfnVON4ky/8HJvdaoQy3PfdCfgwvc1T0afvM0Gwg0dlZKH R6vaRr73+/oqj2qNC/c35U1L3rbRjdrTT/OQ3ZeEQtUGJ9IECPq6xaGvN2T49ry07dSL Frksyz4PCxY29tELX8YaCjMRlNRWxLp1edmMs06cEk/JlGTHHmIrHdd/tPJg90xn6FGC Zl4WByu2X9QcftQEw+bBXQ57bMehQ3TaU5ypTBIdI0WHkoGL//FFpuJygMnHBMzfADHp clDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Z5MoRlyb; 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 he33-20020a1709073da100b0072f0a99a61asi6424569ejc.617.2022.08.14.08.38.03; Sun, 14 Aug 2022 08:38:28 -0700 (PDT) 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=@kernel.org header.s=k20201202 header.b=Z5MoRlyb; 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 S239990AbiHNPaD (ORCPT + 99 others); Sun, 14 Aug 2022 11:30:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39172 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240250AbiHNP2t (ORCPT ); Sun, 14 Aug 2022 11:28:49 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 73BC7BE2F; Sun, 14 Aug 2022 08:28:48 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 09BC560C22; Sun, 14 Aug 2022 15:28:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 71F6EC433B5; Sun, 14 Aug 2022 15:28:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1660490927; bh=g8DqRUnEJ1CxvVsgj9EkQ/vTlZZXVk/+ZnUNVFzMwU4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Z5MoRlybv6MRbDBLD0zS5cytc1wLqXfJcPK5UcTgcZ9mpZuzLYWLgSoU94HRfJk4j I3VPdU3rLfjZ6mlFoNc6vg9+qPp+1rNKUKVWvr3uz5Aq2OO7MpZDjNc3KW+/wd2XrA Q5Ssktw/8t5oxCRD1j0N+PePBq432s+37+nozdoJCFrRfN4whdT5k9mi683dmiaVTJ c7XWpagkgVwe41pCjH1nsznnKbjqcUjRFMA9S6mhy6COlNmgoIgkwNbh9o97RGHapJ Pnk1F//z8NKpWYMlpNuB1d/0lbXhMR2KMdy8S7OSAPRHWXejLhrLVALimWHQwn3Eee VjR83DBmiyrrw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Sergey Senozhatsky , Minchan Kim , Nitin Gupta , Andrew Morton , Sasha Levin , axboe@kernel.dk, linux-block@vger.kernel.org Subject: [PATCH AUTOSEL 5.19 27/64] zram: do not lookup algorithm in backends table Date: Sun, 14 Aug 2022 11:24:00 -0400 Message-Id: <20220814152437.2374207-27-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220814152437.2374207-1-sashal@kernel.org> References: <20220814152437.2374207-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 From: Sergey Senozhatsky [ Upstream commit dc89997264de565999a1cb55db3f295d3a8e457b ] Always use crypto_has_comp() so that crypto can lookup module, call usermodhelper to load the modules, wait for usermodhelper to finish and so on. Otherwise crypto will do all of these steps under CPU hot-plug lock and this looks like too much stuff to handle under the CPU hot-plug lock. Besides this can end up in a deadlock when usermodhelper triggers a code path that attempts to lock the CPU hot-plug lock, that zram already holds. An example of such deadlock: - path A. zram grabs CPU hot-plug lock, execs /sbin/modprobe from crypto and waits for modprobe to finish disksize_store zcomp_create __cpuhp_state_add_instance __cpuhp_state_add_instance_cpuslocked zcomp_cpu_up_prepare crypto_alloc_base crypto_alg_mod_lookup call_usermodehelper_exec wait_for_completion_killable do_wait_for_common schedule - path B. async work kthread that brings in scsi device. It wants to register CPUHP states at some point, and it needs the CPU hot-plug lock for that, which is owned by zram. async_run_entry_fn scsi_probe_and_add_lun scsi_mq_alloc_queue blk_mq_init_queue blk_mq_init_allocated_queue blk_mq_realloc_hw_ctxs __cpuhp_state_add_instance __cpuhp_state_add_instance_cpuslocked mutex_lock schedule - path C. modprobe sleeps, waiting for all aync works to finish. load_module do_init_module async_synchronize_full async_synchronize_cookie_domain schedule [senozhatsky@chromium.org: add comment] Link: https://lkml.kernel.org/r/20220624060606.1014474-1-senozhatsky@chromium.org Link: https://lkml.kernel.org/r/20220622023501.517125-1-senozhatsky@chromium.org Signed-off-by: Sergey Senozhatsky Cc: Minchan Kim Cc: Nitin Gupta Signed-off-by: Andrew Morton Signed-off-by: Sasha Levin --- drivers/block/zram/zcomp.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/drivers/block/zram/zcomp.c b/drivers/block/zram/zcomp.c index 052aa3f65514..0916de952e09 100644 --- a/drivers/block/zram/zcomp.c +++ b/drivers/block/zram/zcomp.c @@ -63,12 +63,6 @@ static int zcomp_strm_init(struct zcomp_strm *zstrm, struct zcomp *comp) bool zcomp_available_algorithm(const char *comp) { - int i; - - i = sysfs_match_string(backends, comp); - if (i >= 0) - return true; - /* * Crypto does not ignore a trailing new line symbol, * so make sure you don't supply a string containing @@ -217,6 +211,11 @@ struct zcomp *zcomp_create(const char *compress) struct zcomp *comp; int error; + /* + * Crypto API will execute /sbin/modprobe if the compression module + * is not loaded yet. We must do it here, otherwise we are about to + * call /sbin/modprobe under CPU hot-plug lock. + */ if (!zcomp_available_algorithm(compress)) return ERR_PTR(-EINVAL); -- 2.35.1