Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp3974773rwd; Tue, 23 May 2023 00:56:09 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4D8fmPuCc9wakLawnFNHnKkb5e84rQuysXBRx5R2J2gL46wiT2yXfFtVCZNykzRtYuOa1d X-Received: by 2002:a17:902:dac3:b0:1ae:501:e233 with SMTP id q3-20020a170902dac300b001ae0501e233mr17851259plx.7.1684828569318; Tue, 23 May 2023 00:56:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684828569; cv=none; d=google.com; s=arc-20160816; b=sTenSzsiCu5k5PtiLolVEDaII8VkfOP6KJbHWGdibzWjZz07MaYmr0sEUDYfVZULy1 uwIeRIUhQblOzhMR8nN8WsZSkeIcq9BlkPEiS4N0b7wDkhPblY+5Md69IwauqLwuQgPI i8a9OSnb4wlGiaEoJs8tUEdH3YMlxZuYuTBb5DEhkfBDb0ZQ7hYu/UlZLtxP04l97sdW AnOxIzWq+prKf1rBFj7PUsUtAv50r4vhQ4KA1NwKIphUIaW/ZjY101sHCCFhExlV6sSY ONSfbDTlDal61S+q/s6X6pZ92ITFGp58hIcOE8iutFctOoTsmznw+UhkdvXvxm5S5ICD G5Bw== 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=jZRF33U9/i0WwWhIXhCPDfpLuiH0EpaeKjfubU+/NSk=; b=uD3UKzCzl2LSZmb9NAouoVNmtUvMXxrRMP+RzEf64RjlZDxNbbUYB3BSejHKnxwgai J22k6ew7a/CJe0uyT747mgj9HPdls06KfDcYtfiRuV8XbcUVlKORPrK4ql1cyGLLypJm 23zcdYawEKe776N6DgXXNvfzmY8VIVhczameHZpoVOyvv648P2DtEfFT8ayBuzBcBt3R CQBvPFKUXr/jSdST7QTJ0i+pFmZf589kAfnObt+LISFXCIVh3UFC0gNyOWUVdRaRpte/ Mv8tkwLrTQH0/BhGm4oCnNGZHwTEa7mMXFEoc2HsTn7UjjXSjB/LKOTt3T67jfktXZ4H tr0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=dkBi+PBt; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m1-20020a170902db0100b001aafeb7d2f2si248849plx.287.2023.05.23.00.55.56; Tue, 23 May 2023 00:56:09 -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=@infradead.org header.s=bombadil.20210309 header.b=dkBi+PBt; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235695AbjEWHqb (ORCPT + 99 others); Tue, 23 May 2023 03:46:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41674 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235164AbjEWHqD (ORCPT ); Tue, 23 May 2023 03:46:03 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 99FF6118; Tue, 23 May 2023 00:46:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=jZRF33U9/i0WwWhIXhCPDfpLuiH0EpaeKjfubU+/NSk=; b=dkBi+PBtwIHBctSBmpUW7XDd+E SZnvGvAWk+dfSf4TqHZf6neGTK+SWpj/1rwAZ/uVDABZ51wxkIIOCagDjD7Wk2mN57Jd6czkFJczK jI9At/MpPQIaTOhOp6y6bbjvNTtiOJw+hFlzMMOF5eXAqSCdw3yBhVvEiBI/jnSvSSrUlCvSJdU2O WD8XEvIPyY+Er3vLaIcd++xXWU5fPpKpaFpEwJIuNxZRH6qkZeLIh5V2xdgF0M36L6i6mcZrFzNrh huurPNkzH3UiIUIgv5RRefgXFJx8OJ6RYFQA+otrqgq7EUuMpCkgy/iIRwqwcVZ96KqY9LFT1AMzO Jr7ztCNQ==; Received: from [2001:4bb8:188:23b2:6ade:85c9:530f:6eb0] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1q1MiK-009GWl-20; Tue, 23 May 2023 07:45:49 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Greg Kroah-Hartman , "Rafael J. Wysocki" , Mike Snitzer , Joern Engel , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Pavel Machek , dm-devel@redhat.com, linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, linux-mtd@lists.infradead.org, linux-pm@vger.kernel.org Subject: [PATCH 04/24] PM: hibernate: move finding the resume device out of software_resume Date: Tue, 23 May 2023 09:45:15 +0200 Message-Id: <20230523074535.249802-5-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230523074535.249802-1-hch@lst.de> References: <20230523074535.249802-1-hch@lst.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Spam-Status: No, score=-4.1 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,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED 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 software_resume can be called either from an init call in the boot code, or from sysfs once the system has finished booting, and the two invocation methods this can't race with each other. For the latter case we did just parse the suspend device manually, while the former might not have one. Split software_resume so that the search only happens for the boot case, which also means the special lockdep nesting annotation can go away as the system transition mutex can be taken a little later and doesn't have the sysfs locking nest inside it. Signed-off-by: Christoph Hellwig --- kernel/power/hibernate.c | 80 ++++++++++++++++++++-------------------- 1 file changed, 39 insertions(+), 41 deletions(-) diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c index 78696aa04f5ca3..45e24b02cd50b6 100644 --- a/kernel/power/hibernate.c +++ b/kernel/power/hibernate.c @@ -907,7 +907,7 @@ int hibernate_quiet_exec(int (*func)(void *data), void *data) } EXPORT_SYMBOL_GPL(hibernate_quiet_exec); -static int find_resume_device(void) +static int __init find_resume_device(void) { if (!strlen(resume_file)) return -ENOENT; @@ -942,53 +942,16 @@ static int find_resume_device(void) return 0; } -/** - * software_resume - Resume from a saved hibernation image. - * - * This routine is called as a late initcall, when all devices have been - * discovered and initialized already. - * - * The image reading code is called to see if there is a hibernation image - * available for reading. If that is the case, devices are quiesced and the - * contents of memory is restored from the saved image. - * - * If this is successful, control reappears in the restored target kernel in - * hibernation_snapshot() which returns to hibernate(). Otherwise, the routine - * attempts to recover gracefully and make the kernel return to the normal mode - * of operation. - */ static int software_resume(void) { int error; - /* - * If the user said "noresume".. bail out early. - */ - if (noresume || !hibernation_available()) - return 0; - - /* - * name_to_dev_t() below takes a sysfs buffer mutex when sysfs - * is configured into the kernel. Since the regular hibernate - * trigger path is via sysfs which takes a buffer mutex before - * calling hibernate functions (which take system_transition_mutex) - * this can cause lockdep to complain about a possible ABBA deadlock - * which cannot happen since we're in the boot code here and - * sysfs can't be invoked yet. Therefore, we use a subclass - * here to avoid lockdep complaining. - */ - mutex_lock_nested(&system_transition_mutex, SINGLE_DEPTH_NESTING); - - if (!swsusp_resume_device) { - error = find_resume_device(); - if (error) - goto Unlock; - } - pm_pr_dbg("Hibernation image partition %d:%d present\n", MAJOR(swsusp_resume_device), MINOR(swsusp_resume_device)); pm_pr_dbg("Looking for hibernation image.\n"); + + mutex_lock(&system_transition_mutex); error = swsusp_check(false); if (error) goto Unlock; @@ -1035,7 +998,39 @@ static int software_resume(void) goto Finish; } -late_initcall_sync(software_resume); +/** + * software_resume_initcall - Resume from a saved hibernation image. + * + * This routine is called as a late initcall, when all devices have been + * discovered and initialized already. + * + * The image reading code is called to see if there is a hibernation image + * available for reading. If that is the case, devices are quiesced and the + * contents of memory is restored from the saved image. + * + * If this is successful, control reappears in the restored target kernel in + * hibernation_snapshot() which returns to hibernate(). Otherwise, the routine + * attempts to recover gracefully and make the kernel return to the normal mode + * of operation. + */ +static int __init software_resume_initcall(void) +{ + /* + * If the user said "noresume".. bail out early. + */ + if (noresume || !hibernation_available()) + return 0; + + if (!swsusp_resume_device) { + int error = find_resume_device(); + + if (error) + return error; + } + + return software_resume(); +} +late_initcall_sync(software_resume_initcall); static const char * const hibernation_modes[] = { @@ -1176,6 +1171,9 @@ static ssize_t resume_store(struct kobject *kobj, struct kobj_attribute *attr, char *name; dev_t res; + if (!hibernation_available()) + return 0; + if (len && buf[len-1] == '\n') len--; name = kstrndup(buf, len, GFP_KERNEL); -- 2.39.2