Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp6895170rwn; Tue, 13 Sep 2022 10:26:49 -0700 (PDT) X-Google-Smtp-Source: AA6agR74V5jTZ6gcSHQNnMbq8OiMsCArJPKaarj/HcRpGQkiGd8pbZYi+2Y/cQniBTcXGua5knNM X-Received: by 2002:a17:907:2d0b:b0:77c:68a8:a47 with SMTP id gs11-20020a1709072d0b00b0077c68a80a47mr9429546ejc.473.1663090009531; Tue, 13 Sep 2022 10:26:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663090009; cv=none; d=google.com; s=arc-20160816; b=TB/Z4ZAFW8tK7n+rUDxfrA0qYl/ZYZlGmt6MbYie53hHWE589fp9ogapGP5CkxIFG2 pWjaCyrQie2jcxUlqrSi/dRtP57qBBQvJ9z9qWyyzTbavV+oAG5u6BK6oPsQ5dQCCi1d hCkAaFwvB+ABEhdFtq1qNE3FN3/ZqV+4XqhzdCmdleMnevBTkEotx+1dDFP/hGuvBYAv Q6wHitk4ipYp/xJnYKMvxX7UljhxZut52u0RD5xJ9Bms68Jyvx0w7KxCyhArwnepxmYV ZxwOdlfLCY7bfbzP9xhJECGFruMfuPDDcPPBvq88d6rMl9DSRM5TEbejA8gOWQ6/4v/F H0fA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=JBdk5HC7jtMfnm9OV3jZ4ve9jqXhTQvwX4EspHPXhbE=; b=Qiod2sQKeKB2MRX262gHKnaG2CZsjSLORXESYff6Bt4ppfzDgsye7DdK01nU3fz4Uu KxfNTvSlq55JJGV4mKSbclL1U6Mk7yR2vUtQ0+xCdKKsw8vBYf3ODSPxdcX8cuRk/aOX /96fN7AyeOE31HCwKjv5U14o8yf48VZKZOQSUH3HNJT5ZLEdmE6brEPvEUP42LGpwpmn 1XIKTm3otsbpmn/jDZght8GwdDVZgJXzkjLyQbdfSrxLmNkJszP2z3QRwgA6QlxStjNa l671BaO0YF5duUa3iEeHBdtxTc0OmnNmp3f+KZle2Sp3ODb5w6Z1NDz1xjymC181Ziik X82g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=F9agusur; 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=collabora.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qo20-20020a170907213400b0073105e9fb53si8478780ejb.855.2022.09.13.10.26.23; Tue, 13 Sep 2022 10:26:49 -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=@collabora.com header.s=mail header.b=F9agusur; 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=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231244AbiIMQrZ (ORCPT + 99 others); Tue, 13 Sep 2022 12:47:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35644 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230518AbiIMQrJ (ORCPT ); Tue, 13 Sep 2022 12:47:09 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e5ab]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B97F3BD106 for ; Tue, 13 Sep 2022 08:41:12 -0700 (PDT) Received: from [192.168.2.145] (109-252-122-187.nat.spd-mgts.ru [109.252.122.187]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: dmitry.osipenko) by madras.collabora.co.uk (Postfix) with ESMTPSA id 406746601AED; Tue, 13 Sep 2022 16:14:00 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1663082041; bh=IZVMXPsmeNutgy635V9Tli9ZlfJKqiRfXqa1maMjnSY=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=F9agusurEwQkin8/M7bO6ZPajr+EN/VDICq0H+wCZcHg9qm4cCHU/7jvDfDzmwhCy 7hjjiMm0ZsHj7K0YkZbgAKKlu40/x2FaITo80RHDFwtvn7Ly48mX4fUVfuqbVC5837 KzPlF+ir503KeRcpWtlttmU4irfh63cuG1/8GUc6R48ESikyGWBjHSBQeGkxBXnyII +n7vhWUJiz8c4S5EV9XaQk/iuWnQgdFxYjYubdL9QpGdvo/ow3TckA7HerFQt+iOE8 HM0Dbk/TcpxH9lcMf3qJ+nkLqu63LrOoHFLeSNIwM5XFnqo0nDIQozO9e9di3TEJGx Ed+2IW31eycpQ== Message-ID: Date: Tue, 13 Sep 2022 18:13:56 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.1 Subject: Re: [PATCH v3 1/2] kernel/reboot: Add SYS_OFF_MODE_RESTART_PREPARE mode To: Kai-Heng Feng , rafael.j.wysocki@intel.com, lenb@kernel.org Cc: tangmeng , Luis Chamberlain , Petr Mladek , YueHaibing , linux-kernel@vger.kernel.org References: <20220913062042.1977790-1-kai.heng.feng@canonical.com> Content-Language: en-US From: Dmitry Osipenko In-Reply-To: <20220913062042.1977790-1-kai.heng.feng@canonical.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,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 On 9/13/22 09:20, Kai-Heng Feng wrote: > Add SYS_OFF_MODE_RESTART_PREPARE callbacks can be invoked before system > restart. > > This is a preparation for next patch. > > Suggested-by: Dmitry Osipenko > Signed-off-by: Kai-Heng Feng > --- > v3: > - New patch. > > include/linux/reboot.h | 8 ++++++++ > kernel/reboot.c | 17 +++++++++++++++++ > 2 files changed, 25 insertions(+) > > diff --git a/include/linux/reboot.h b/include/linux/reboot.h > index e5d9ef886179c..ba87cdef2335a 100644 > --- a/include/linux/reboot.h > +++ b/include/linux/reboot.h > @@ -105,6 +105,14 @@ enum sys_off_mode { > */ > SYS_OFF_MODE_POWER_OFF, > > + /** > + * @SYS_OFF_MODE_RESTART_PREPARE: > + * > + * Handlers prepare system to be powered off. Handlers are s/powered off/restarted/ > + * allowed to sleep. > + */ > + SYS_OFF_MODE_RESTART_PREPARE, > + > /** > * @SYS_OFF_MODE_RESTART: > * > diff --git a/kernel/reboot.c b/kernel/reboot.c > index 3c35445bf5ad3..3bba88c7ffc6b 100644 > --- a/kernel/reboot.c > +++ b/kernel/reboot.c > @@ -243,6 +243,17 @@ void migrate_to_reboot_cpu(void) > set_cpus_allowed_ptr(current, cpumask_of(cpu)); > } > > +/* > + * Notifier list for kernel code which wants to be called > + * to prepare system for restart. > + */ > +static BLOCKING_NOTIFIER_HEAD(restart_prep_handler_list); > + > +static void do_kernel_restart_prepare(void) > +{ > + blocking_notifier_call_chain(&restart_prep_handler_list, 0, NULL); > +} > + > /** > * kernel_restart - reboot the system > * @cmd: pointer to buffer containing command to execute for restart > @@ -254,6 +265,7 @@ void migrate_to_reboot_cpu(void) > void kernel_restart(char *cmd) > { > kernel_restart_prepare(cmd); > + do_kernel_restart_prepare(); > migrate_to_reboot_cpu(); > syscore_shutdown(); > if (!cmd) > @@ -396,6 +408,11 @@ register_sys_off_handler(enum sys_off_mode mode, > handler->list = &power_off_handler_list; > break; > > + case SYS_OFF_MODE_RESTART_PREPARE: > + handler->list = &restart_prep_handler_list; > + handler->blocking = true; > + break; > + > case SYS_OFF_MODE_RESTART: > handler->list = &restart_handler_list; > break; With the above comment addressed: Reviewed-by: Dmitry Osipenko -- Best regards, Dmitry