Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1421515ybl; Fri, 10 Jan 2020 18:22:54 -0800 (PST) X-Google-Smtp-Source: APXvYqwVjeZxleQ8FYHcise81786PXml+1vrJZhQag89yG4z5T6tucPEqGB4guzIdxCXZEmcEwwv X-Received: by 2002:a9d:1b26:: with SMTP id l35mr5269095otl.307.1578709374451; Fri, 10 Jan 2020 18:22:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578709374; cv=none; d=google.com; s=arc-20160816; b=anPTDEJn37ez/9QWn4UxrWBmF2VseiC6y130cUe8+XVvr0sXd4mpj0pCN/haDmqA+H q9dZW19ZwAkC0n5Snkzrhtbni5ZilEkuaiySwtprEeCjq372BMPSwfX8wYhDWPelih6g l6Xs/3jkYR8rQj6AWYl1/Xhj8nYwLcq4dq/11LX6VAUCotMCdLpFRofWATPFUCcbzjvv 7+KdF5z5a7XTPm3TIiBVmfuPGsltZ9Xo0IXdEJjqP/g5FAoqe9GKuTvmgoW4gVmtafzW s+4kMDyqrgC021aQBmltgW/dRnauxi4UKDamkBOAmGI0S0yNpVLDySk6KIUytbaYXaUI tPEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition:mime-version :message-id:subject:cc:to:from:date; bh=Ujqu84n/Dk0GDizy1B0W4l6f8HZMQYSPnwdptFeIUB0=; b=k8TlslSDaqsgYyCZA7h/vjudhK9YJZChp+dkpaHp8D7Aocu2YYqYgduQx/7Z7GPzJM yDqFq6UcpX9Lohf94CJUtpzX5eCHU/zDLCeROSe758+uxuor37Uz1lwpIDX+nFyJoM4W qIxGSJLau7YeZVZ2AztE4htp6pEUCTfLSOgzT4AREA4rW124OSUlkM+fDgZvBctfwtiU ylHK/Mkjp3WFoEPrKn+dPwbPzed2SbqLg9ACkZSLvhFHcJfn8y+uXXaiM1wUMr4Z5Qi/ k3kRviYra5zC0AoSt0lFRx+NI1q47msSskQ7MqnKMceuo2JYkbvx8PpABKvCwxdX1HCO UBiA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e24si2452866otl.62.2020.01.10.18.22.43; Fri, 10 Jan 2020 18:22:54 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728085AbgAKCVy (ORCPT + 99 others); Fri, 10 Jan 2020 21:21:54 -0500 Received: from relay1-d.mail.gandi.net ([217.70.183.193]:45951 "EHLO relay1-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728047AbgAKCVx (ORCPT ); Fri, 10 Jan 2020 21:21:53 -0500 X-Originating-IP: 50.39.173.182 Received: from localhost (50-39-173-182.bvtn.or.frontiernet.net [50.39.173.182]) (Authenticated sender: josh@joshtriplett.org) by relay1-d.mail.gandi.net (Postfix) with ESMTPSA id 19A1B240005; Sat, 11 Jan 2020 02:21:47 +0000 (UTC) Date: Fri, 10 Jan 2020 18:21:45 -0800 From: Josh Triplett To: "Rafael J. Wysocki" , Len Brown , Jonathan Corbet , Arjan van de Ven Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org Subject: [PATCH] acpi: button: Provide option for power button to directly signal init Message-ID: <20200111022145.GA166025@localhost> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Virtual machines and containers often use an ACPI power button event to tell the machine to shut down gracefully. Provide an optional, extremely lightweight way to handle this event by signaling init directly, rather than running a separate daemon (such as acpid or systemd-logind) that adds to startup time and VM image complexity. By default, the power button will continue to notify userspace through the input layer. With the button.power_signal parameter set, the power button will instead send the configured signal to init. (For instance, sending SIGINT will make the power button simulate ctrl-alt-del.) Signed-off-by: Josh Triplett --- Documentation/admin-guide/kernel-parameters.txt | 6 ++++++ drivers/acpi/button.c | 11 +++++++++++ 2 files changed, 17 insertions(+) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index ade4e6ec23e0..bbb598e148f4 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -450,6 +450,12 @@ firmware feature for flushing multiple hpte entries at a time. + button.power_signal= + [ACPI] When the power button is pressed, send this + signal number to the init process. If set to 0 + (default), do not send a signal. + Format: integer + c101= [NET] Moxa C101 synchronous serial card cachesize= [BUGS=X86-32] Override level 2 CPU cache size detection. diff --git a/drivers/acpi/button.c b/drivers/acpi/button.c index b758b45737f5..923259f132d6 100644 --- a/drivers/acpi/button.c +++ b/drivers/acpi/button.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -167,6 +168,10 @@ static unsigned long lid_report_interval __read_mostly = 500; module_param(lid_report_interval, ulong, 0644); MODULE_PARM_DESC(lid_report_interval, "Interval (ms) between lid key events"); +static int power_signal __read_mostly = 0; +module_param(power_signal, int, 0644); +MODULE_PARM_DESC(power_signal, "Power button sends this signal to init"); + /* -------------------------------------------------------------------------- FS Interface (/proc) -------------------------------------------------------------------------- */ @@ -426,6 +431,12 @@ static void acpi_button_notify(struct acpi_device *device, u32 event) if (button->suspended) break; + if (power_signal + && button->type == ACPI_BUTTON_TYPE_POWER) { + kill_cad_pid(power_signal, 1); + break; + } + keycode = test_bit(KEY_SLEEP, input->keybit) ? KEY_SLEEP : KEY_POWER; input_report_key(input, keycode, 1); -- 2.25.0.rc2