From patchwork Sat Mar 19 16:11:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tim Gardner X-Patchwork-Id: 1607372 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=Hvdljd73; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KLQqQ63sCz9sFh for ; Sun, 20 Mar 2022 03:11:30 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1nVbfn-0001yx-Ld; Sat, 19 Mar 2022 16:11:23 +0000 Received: from smtp-relay-internal-0.internal ([10.131.114.225] helo=smtp-relay-internal-0.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1nVbfg-0001v7-Ow for kernel-team@lists.ubuntu.com; Sat, 19 Mar 2022 16:11:16 +0000 Received: from mail-pj1-f69.google.com (mail-pj1-f69.google.com [209.85.216.69]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 7E1223F221 for ; Sat, 19 Mar 2022 16:11:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1647706276; bh=/P0LVtw30atun7VHvh+PO+g/XD0n81vf8WuXI63IIxw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Hvdljd735/IxoSP8NUvMR8vxBxa2MfX7DdnTf/5sqdDU7uXimHK80DOKyJFRRcmA6 Av+vneppSqkAdbkIT7AKR9BsWcqIvBKrLRyPtGKmYhz3+iCBsWHu3lQU9Fv1oXWmlR lEcA73v6a/0I0D4g93cncACocgbqx6ZyxZNtl32LxA8NWAJYaIERPEZFd9lzQd7qlu cmaFBzoG0nqhrA7QuVpB2NmIzAXiFig7qwmzfJo37OrnyY6DH20n3zPWVTkMfH+N8c Fk/RBMUdgXmxbxLPaCHjmqXC3cl/AjxnVDA9zfBAndcjeBKJi73H6ooyvJ57QnNTCG Rpcve7I9kUBBw== Received: by mail-pj1-f69.google.com with SMTP id mm2-20020a17090b358200b001bf529127dfso6603263pjb.6 for ; Sat, 19 Mar 2022 09:11:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/P0LVtw30atun7VHvh+PO+g/XD0n81vf8WuXI63IIxw=; b=nH86WUdbIPqnXab4RG+qjujiMepMHGCXD0n3k+tTP+4ApGN0eFt1WcqyGtn0rhWcyF XAqbSvrcHuj/jwuJK8TJAmYqIHS0UUvUaOr3s+j56h8AZaug8+pklAKt3dIwAkaG8ykO XYGay5Kf/gTpcNtuahg1wLt/GtG1nk1O4L0NKU3ULeCK9AtCY30xweiziUlPrzC2E6C+ zS/HvQNuXZilsZ/h/n1ST1cy79qOM8zTbcOvh+xAzWuUsNwIATmpyfJULSg/E0Js1Wun yG6gNf8UFZlr2KjAzM3FTG9JEumGDnfgIs9S/pykmBZr+FtKXkJfOvtoaiGeuz7yiFSK nRxA== X-Gm-Message-State: AOAM533WTkw0TAAV07KWDjiYO4fjjPt8/+lDF5QK3b7dQakheDCjH6jE FZedcIzFOHqBXTcZ9mEnFdX65QE14geuDn8OC1g156GPUwJoOtIrI2bjMCQPmhIahl6ex75gg64 XGRkTE/W7wlQ7cYs5/JbrtEqaMuGGm+7AFqcx6eUc7Q== X-Received: by 2002:a05:6a00:1d03:b0:4fa:7710:7b1b with SMTP id a3-20020a056a001d0300b004fa77107b1bmr7065029pfx.29.1647706274739; Sat, 19 Mar 2022 09:11:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzA+DHZmCnN01JKps6IcxSdRZZzBmJAUksoh1C/3tlODzAJ1fpqSrj0yb+TF1wOrvDGJLIk6w== X-Received: by 2002:a05:6a00:1d03:b0:4fa:7710:7b1b with SMTP id a3-20020a056a001d0300b004fa77107b1bmr7065006pfx.29.1647706274432; Sat, 19 Mar 2022 09:11:14 -0700 (PDT) Received: from localhost.localdomain ([69.163.84.166]) by smtp.gmail.com with ESMTPSA id ml16-20020a17090b361000b001c6c9141b0csm3284667pjb.45.2022.03.19.09.11.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Mar 2022 09:11:13 -0700 (PDT) From: Tim Gardner To: kernel-team@lists.ubuntu.com Subject: [PATCH 2/2][Impish/linux-aws] PM: hibernate: Honour ACPI hardware signature by default for virtual guests Date: Sat, 19 Mar 2022 10:11:02 -0600 Message-Id: <20220319161102.16408-5-tim.gardner@canonical.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220319161102.16408-1-tim.gardner@canonical.com> References: <20220319161102.16408-1-tim.gardner@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: David Woodhouse BugLink: https://bugs.launchpad.net/bugs/1965002 The ACPI specification says that OSPM should refuse to restore from hibernate if the hardware signature changes, and should boot from scratch. However, real BIOSes often vary the hardware signature in cases where we *do* want to resume from hibernate, so Linux doesn't follow the spec by default. However, in a virtual environment there's no reason for the VMM to vary the hardware signature *unless* it wants to trigger a clean reboot as defined by the ACPI spec. So enable the check by default if a hypervisor is detected. Signed-off-by: David Woodhouse Signed-off-by: Rafael J. Wysocki (cherry picked from commit f6c46b1d62f8ffbf2cf6eb43ab0d277bd3f7e948 linux-next) Signed-off-by: Tim Gardner --- arch/x86/kernel/acpi/sleep.c | 23 +++++++++++++++++++++-- drivers/acpi/sleep.c | 11 +++-------- include/linux/acpi.h | 2 +- 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c index 1e97f944b47d..3b7f4cdbf2e0 100644 --- a/arch/x86/kernel/acpi/sleep.c +++ b/arch/x86/kernel/acpi/sleep.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include "../../realmode/rm/wakeup.h" @@ -140,9 +141,9 @@ static int __init acpi_sleep_setup(char *str) acpi_realmode_flags |= 4; #ifdef CONFIG_HIBERNATION if (strncmp(str, "s4_hwsig", 8) == 0) - acpi_check_s4_hw_signature(1); + acpi_check_s4_hw_signature = 1; if (strncmp(str, "s4_nohwsig", 10) == 0) - acpi_check_s4_hw_signature(0); + acpi_check_s4_hw_signature = 0; #endif if (strncmp(str, "nonvs", 5) == 0) acpi_nvs_nosave(); @@ -160,3 +161,21 @@ static int __init acpi_sleep_setup(char *str) } __setup("acpi_sleep=", acpi_sleep_setup); + +#if defined(CONFIG_HIBERNATION) && defined(CONFIG_HYPERVISOR_GUEST) +static int __init init_s4_sigcheck(void) +{ + /* + * If running on a hypervisor, honour the ACPI specification + * by default and trigger a clean reboot when the hardware + * signature in FACS is changed after hibernation. + */ + if (acpi_check_s4_hw_signature == -1 && + !hypervisor_is_type(X86_HYPER_NATIVE)) + acpi_check_s4_hw_signature = 1; + + return 0; +} +/* This must happen before acpi_init() which is a subsys initcall */ +arch_initcall(init_s4_sigcheck); +#endif diff --git a/drivers/acpi/sleep.c b/drivers/acpi/sleep.c index f9fea16fcf71..ccf8c6b6eb23 100644 --- a/drivers/acpi/sleep.c +++ b/drivers/acpi/sleep.c @@ -873,12 +873,7 @@ static inline void acpi_sleep_syscore_init(void) {} #ifdef CONFIG_HIBERNATION static unsigned long s4_hardware_signature; static struct acpi_table_facs *facs; -static int sigcheck = -1; /* Default behaviour is just to warn */ - -void __init acpi_check_s4_hw_signature(int check) -{ - sigcheck = check; -} +int acpi_check_s4_hw_signature = -1; /* Default behaviour is just to warn */ static int acpi_hibernation_begin(pm_message_t stage) { @@ -1005,7 +1000,7 @@ static void acpi_sleep_hibernate_setup(void) hibernation_set_ops(old_suspend_ordering ? &acpi_hibernation_ops_old : &acpi_hibernation_ops); sleep_states[ACPI_STATE_S4] = 1; - if (!sigcheck) + if (!acpi_check_s4_hw_signature) return; acpi_get_table(ACPI_SIG_FACS, 1, (struct acpi_table_header **)&facs); @@ -1017,7 +1012,7 @@ static void acpi_sleep_hibernate_setup(void) */ s4_hardware_signature = facs->hardware_signature; - if (sigcheck > 0) { + if (acpi_check_s4_hw_signature > 0) { /* * If we're actually obeying the ACPI specification * then the signature is written out as part of the diff --git a/include/linux/acpi.h b/include/linux/acpi.h index 61ef008de002..b5a051a4c2c6 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h @@ -502,7 +502,7 @@ acpi_status acpi_release_memory(acpi_handle handle, struct resource *res, int acpi_resources_are_enforced(void); #ifdef CONFIG_HIBERNATION -void __init acpi_check_s4_hw_signature(int check); +extern int acpi_check_s4_hw_signature; #endif #ifdef CONFIG_PM_SLEEP