Received: by 2002:a05:7412:8521:b0:e2:908c:2ebd with SMTP id t33csp1038471rdf; Sat, 4 Nov 2023 04:29:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH6zawa7q0+K15zFx/iIHAuj/DyRzLOcwHviO9tdhkQr4EUuWI7MHmGptL11/uE+EhniZDk X-Received: by 2002:a17:902:b489:b0:1cc:be6b:80fa with SMTP id y9-20020a170902b48900b001ccbe6b80famr749810plr.12.1699097396267; Sat, 04 Nov 2023 04:29:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1699097396; cv=none; d=google.com; s=arc-20160816; b=E/5mBzJteWdj2Kw6R73oyXiO0xNsMKl/FQuVoGHIJPUQcIQI7Js63i8pTJ6lndr/aB KhHlnVWhSMXHX2XFTVSMfb/sb85t+WZMrMkI8Nwl3oftLIS6rKCJyIMKKtM8lY9mS2xA ZpFPacmvWrMcq4CD/Z5haZH+GNYLTpGdIteA7t+AbxNfXPZbHYnPLwALvMRe9zzO8SfG qVMHgQ4ZjGVThNEhliJMnZsOJ8dJ7t0TYBeesPvaHgoOfQX3Jcr9XLvC07gkvCQl4DzM yXQI8C6ELPtQhUTcKYksJhUNdUAeD0CoyBb3oaHQ0Nn6TEhaL9qcK7uXS67g/HsvbIxv 34KQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:message-id:content-transfer-encoding :mime-version:subject:date:from:dkim-signature; bh=t+6zJdGHyECEncy3qb8nDT15x1yVtXmPrh3yujdkLwM=; fh=x+RsuWN3ti9Ce4MFt005HUD9NuYhcahL6VPYaciRZdE=; b=tFAAiDRY0tOUfMyXa9rQ7qGXeY+9AxmGGDvN4a7pYUmUEBnep2A1TCWRVmM3Vm6b3n xN++Sz4Jz4b3Inpd9S8QfgBh1WXenvmjJTOBA2Sezh7rI54enGp5XBWXIRQ9fFMj1Z6f PuuVwGyImX3eR6IcQzYMA5MqAe4HKw8RMfmtwZne3KgrVp83G9bQ0uiS8dwCDxIng0J7 eg1CVQ7lCeisw6O7vcCmJeuLsXu3pTnMoI35cbERmKvhJ0Wqdi1u2/vTq94V2VC1IdYs xf5JgfTipdounEFIhmbShxWnZtf2L8CswZi/rGvz4flgCCUDEHkcrgNE84d8tSg96xJI Bkyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@weissschuh.net header.s=mail header.b=J22UjRvy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id c4-20020a170903234400b001c9b2013393si3742517plh.230.2023.11.04.04.29.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 Nov 2023 04:29:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@weissschuh.net header.s=mail header.b=J22UjRvy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 961BE8053C68; Sat, 4 Nov 2023 04:29:53 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232103AbjKDL3o (ORCPT + 99 others); Sat, 4 Nov 2023 07:29:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48084 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231741AbjKDL3n (ORCPT ); Sat, 4 Nov 2023 07:29:43 -0400 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 831891AA for ; Sat, 4 Nov 2023 04:29:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1699097377; bh=5CLEWlb/FZJQNq94xbAoxDHDCfPn4Oh7tFwFnTmNzCA=; h=From:Date:Subject:To:Cc:From; b=J22UjRvyVrsMWv1cyfJRtYIix0l/Q07ZPxnVR4jpGsIvaVjRAZ+Eqj9sKpjQrGkw2 rsjJElGmnnc9UozwXJm3bVY8vjiG/UGdUuqQNLCX6tdl0++AXIJM/5bhFWx3lh1S7C yErA/DsDL1HWWRqjvhVbopjJy90ZLIJ0nHZP/BXU= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Sat, 04 Nov 2023 12:29:30 +0100 Subject: [PATCH RFC] misc/pvpanic: add support for normal shutdowns MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Message-Id: <20231104-pvpanic-shutdown-v1-1-5ee7c9b3e301@weissschuh.net> X-B4-Tracking: v=1; b=H4sIABkrRmUC/6tWKk4tykwtVrJSqFYqSi3LLM7MzwNyDHUUlJIzE vPSU3UzU4B8JSMDI2NDQwMT3YKygsS8zGTd4ozSkpT88jxd07REY4tEC3PLxBRDJaC2gqLUtMw KsJHRSkFuzkqxtbUA2om/xmcAAAA= To: Arnd Bergmann , Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org, Zhangjin Wu , Willy Tarreau , Yuan Tan , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=ed25519-sha256; t=1699097376; l=3120; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=5CLEWlb/FZJQNq94xbAoxDHDCfPn4Oh7tFwFnTmNzCA=; b=Z9wMVem+r2d/PaEOBigYC8TqCp8MBn4xEDV9ZrtDPTaxeozFZP3MzKlUIPjqvbgeAUMUoNLXM V8XzLOrG74OCLqHvnXYOvBoSggaQYWan0soq1piXeGPD/IF8IiIoNME X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Sat, 04 Nov 2023 04:29:53 -0700 (PDT) Shutdown requests are normally hardware dependent. By extending pvpanic to also handle shutdown requests, guests can submit such requests with an easily implementable and cross-platform mechanism. Signed-off-by: Thomas Weißschuh --- The corresponding patch to qemu has also been submitted[0]. General discussions about the feature should happen on the other thread. [0] https://lore.kernel.org/qemu-devel/20231104-pvpanic-shutdown-v1-0-02353157891b@t-8ch.de/ --- drivers/misc/pvpanic/pvpanic.c | 19 +++++++++++++++++-- include/uapi/misc/pvpanic.h | 1 + 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/drivers/misc/pvpanic/pvpanic.c b/drivers/misc/pvpanic/pvpanic.c index 305b367e0ce3..d7d807f5e47a 100644 --- a/drivers/misc/pvpanic/pvpanic.c +++ b/drivers/misc/pvpanic/pvpanic.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -74,6 +75,13 @@ static struct notifier_block pvpanic_panic_nb = { .priority = INT_MAX, }; +static int pvpanic_sys_off(struct sys_off_data *data) +{ + pvpanic_send_event(PVPANIC_SHUTDOWN); + + return NOTIFY_DONE; +} + static void pvpanic_remove(void *param) { struct pvpanic_instance *pi_cur, *pi_next; @@ -152,7 +160,7 @@ int devm_pvpanic_probe(struct device *dev, void __iomem *base) return -ENOMEM; pi->base = base; - pi->capability = PVPANIC_PANICKED | PVPANIC_CRASH_LOADED; + pi->capability = PVPANIC_PANICKED | PVPANIC_CRASH_LOADED | PVPANIC_SHUTDOWN; /* initlize capability by RDPT */ pi->capability &= ioread8(base); @@ -168,12 +176,18 @@ int devm_pvpanic_probe(struct device *dev, void __iomem *base) } EXPORT_SYMBOL_GPL(devm_pvpanic_probe); +static struct sys_off_handler *sys_off_handler; + static int pvpanic_init(void) { INIT_LIST_HEAD(&pvpanic_list); spin_lock_init(&pvpanic_lock); atomic_notifier_chain_register(&panic_notifier_list, &pvpanic_panic_nb); + sys_off_handler = register_sys_off_handler(SYS_OFF_MODE_POWER_OFF, SYS_OFF_PRIO_DEFAULT, + pvpanic_sys_off, NULL); + if (IS_ERR(sys_off_handler)) + sys_off_handler = NULL; return 0; } @@ -182,6 +196,7 @@ module_init(pvpanic_init); static void pvpanic_exit(void) { atomic_notifier_chain_unregister(&panic_notifier_list, &pvpanic_panic_nb); - + if (sys_off_handler) + unregister_sys_off_handler(sys_off_handler); } module_exit(pvpanic_exit); diff --git a/include/uapi/misc/pvpanic.h b/include/uapi/misc/pvpanic.h index 54b7485390d3..82fc618bfbcf 100644 --- a/include/uapi/misc/pvpanic.h +++ b/include/uapi/misc/pvpanic.h @@ -5,5 +5,6 @@ #define PVPANIC_PANICKED (1 << 0) #define PVPANIC_CRASH_LOADED (1 << 1) +#define PVPANIC_SHUTDOWN (1 << 2) #endif /* __PVPANIC_H__ */ --- base-commit: 90b0c2b2edd1adff742c621e246562fbefa11b70 change-id: 20231104-pvpanic-shutdown-5fa38a879ad1 Best regards, -- Thomas Weißschuh