Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3412134rwa; Tue, 23 Aug 2022 04:28:18 -0700 (PDT) X-Google-Smtp-Source: AA6agR4pl10qSa4+ysA0Wb158fa1obZ/QAAut2lWD2vljEeCzabu/S7NFvZLgnKJMG/w4GdfRFEy X-Received: by 2002:a17:902:da8f:b0:16f:6b6:eed7 with SMTP id j15-20020a170902da8f00b0016f06b6eed7mr23985123plx.85.1661254098541; Tue, 23 Aug 2022 04:28:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661254098; cv=none; d=google.com; s=arc-20160816; b=d26KnCbkJU9/6q7WjHPu6a7n75exf6y7GsT4BShRNc6BKECH/ZJ+QQoy1VTuLIUJw7 u6WOcNsPtazQ3SYneiWX/YFQPr9+ZwikE7jI0oSVDnEpVYoYeNHXkktLs8hlhZquJaPZ h9oOctFNWLzPPE+DbkozWlY+VyjcJyimjckhfebh6G8cIhyfmFQIeCRI+Fo6+JqIuLFz ClL6hiwu5z6ff5IJyN3OYRmdDL35lJ8Ae/Xi/+3tE/HgoSlH05ZATNsOG4H2rH6cvcaA q7u4GTB68K/F1LAVHA2EyDKp3+zcB5opzbdT9W3AVkoRt29cTjzbuaQ7yVGHtVXjNpsV dawQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=110rKKmPU1bQ5SR56qm/mtQL5lQaugblXeo8yIwE5ik=; b=voXUgOB0qvj/QNH1PN5fUDEUAsyvH/za+pBUiKRHYB+3D/LaKZ0iAElbUJplE3BlNw DNyoTPDeeCPA4vgdmN8awb40eAK4iQmzaI/wycB+NfBq5flQ4bXwaWKoL4c83HeJXVak M8lU1mdI9QpCL8oNc0NedO/iOaqKl9yZwx77Uq8DUIrFtfbxDBWAL5WYzDOeTOpRlowc 0Ft4fpGdnnEPdWYwgCMrITkToSKCjCKsRgoefl5cMW93ef/egpE9MEciHNOlzAZ8tiEJ VdKzFPcxXdm/9itg6QSNcyCT60ux88mH+Rusk31pT0ZtkuRKLya+Ct/93zY9RBaUD9PJ bcng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=oTWH3qXG; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t10-20020a1709027fca00b00172d107f2c2si8095451plb.478.2022.08.23.04.28.07; Tue, 23 Aug 2022 04:28:18 -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=@linuxfoundation.org header.s=korg header.b=oTWH3qXG; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354371AbiHWKZ1 (ORCPT + 99 others); Tue, 23 Aug 2022 06:25:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60584 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353594AbiHWKLl (ORCPT ); Tue, 23 Aug 2022 06:11:41 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 79A0F659E; Tue, 23 Aug 2022 01:57:33 -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 ams.source.kernel.org (Postfix) with ESMTPS id 31AE9B81C35; Tue, 23 Aug 2022 08:57:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4FBC4C433D6; Tue, 23 Aug 2022 08:57:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661245050; bh=g8DqRUnEJ1CxvVsgj9EkQ/vTlZZXVk/+ZnUNVFzMwU4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oTWH3qXGndxLwZKcqQcO6s00xh8ORDeOrqsHmantT0UBWy82Qd7J5HwaTl8ui+3aq C5maOMEg1IMWS8T71UNvB37QOeFaDvlSuHWdIKjynIEj44tAK34MolVP3DjVeeIHA9 6pNeKpvDx5zzp3e8mdXJ223X26W3df56c+6okwC8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sergey Senozhatsky , Minchan Kim , Nitin Gupta , Andrew Morton , Sasha Levin Subject: [PATCH 5.15 180/244] zram: do not lookup algorithm in backends table Date: Tue, 23 Aug 2022 10:25:39 +0200 Message-Id: <20220823080105.324990338@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080059.091088642@linuxfoundation.org> References: <20220823080059.091088642@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 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