From patchwork Tue Jan 17 15:57:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Juergen Gross X-Patchwork-Id: 44722 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1839165wrn; Tue, 17 Jan 2023 08:04:54 -0800 (PST) X-Google-Smtp-Source: AMrXdXtpK07bIa3gtwXnsmwx7CQxwqLnxsoAwjTRA8xpQkq2vIfEAMnXV8yPWuFws3TwvOmNG3kM X-Received: by 2002:a17:90a:4d8e:b0:223:fa53:b368 with SMTP id m14-20020a17090a4d8e00b00223fa53b368mr3891333pjh.34.1673971494005; Tue, 17 Jan 2023 08:04:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673971493; cv=none; d=google.com; s=arc-20160816; b=b7s60iE9sVH6M5XERRggMDd38Lz9t2A8Oug82EzteGIKtI/h3JlNQtpyzQL/JtX1Yf BG/svB1gzpRaeh1US6UtN3mx0bOO8BTAsdzfDTTxi95xSjvhkotw+9pqxzugYJs1NKa1 j6teODLFqyZ22yKNsNIP2orP3ZDpHInb11Tw/6wso5vX17T5LT0r81cKEDClrziZCca5 S2JgMASc8Z+91FxUJQjxIYIOgQTxgrTjH/N4M9ahyWe22q0Uw/Kg0lcmpInd5AowlQkO 1SwPPAcgSasSkRZhZmgzjnHJ7wy2Id36kTCcNyWeLtMzHUB/jX8gAMI+hUK4L0+wnDgp nMfA== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=rpgawVd99OX2fg9gFrA1SwUU/eb0iIN1sOqRSVcIZeg=; b=CAoQkhL6e9C1GNTARKib46xdPTI6Y1UCLqY3pSJMdF4lPnWjF68CipwymH/RFlsWrC nzfkZ0tXJYS1i/AJtYTtRsgbreaizYlyUhblZPqF5rvyM/LoyX0Z5lKY1kvSfGQ1D+UQ yZKY8FXC9p/tbhgJO9FlFRRFm3QpB2UrTFX/K/v4+Hc3w2Acwg9EWwC6fleW/s74VwdM H+nZhmIo4eehkWro/zaPZ/kD2a7NK61GEC0Nxl/8tJ9oE/XUKDlqQkSk0tRfnsu2jiVV jBF/k240CI5pUtfUmqbc+BgBYLxbrXdnMw6SMXH6nCged2kgxIY6j0RtkIvBr/Asi7eC sdlQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=NbvuNjae; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id pc2-20020a17090b3b8200b002299ffe133bsi2988479pjb.172.2023.01.17.08.04.41; Tue, 17 Jan 2023 08:04:53 -0800 (PST) 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=@suse.com header.s=susede1 header.b=NbvuNjae; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230070AbjAQP5f (ORCPT + 99 others); Tue, 17 Jan 2023 10:57:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54484 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229583AbjAQP5b (ORCPT ); Tue, 17 Jan 2023 10:57:31 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD3D82B603; Tue, 17 Jan 2023 07:57:30 -0800 (PST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 73ABD1FE3C; Tue, 17 Jan 2023 15:57:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1673971049; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=rpgawVd99OX2fg9gFrA1SwUU/eb0iIN1sOqRSVcIZeg=; b=NbvuNjaeyuSDWK9T41o1ZE6yenmovxH9xNEbwB5mNsaF1w95I3+NfQR3NVRVbXgKYnOrIb jDY4z0V8u39WRheGZ6pG5ywgN5iPQtMBC5HhRnpufbaWbqgokzdn8cLpsimyBIppRuQMfH O/+P9lWyKRqkYvG7tjuiiPpeTiFfqag= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 1B7D913357; Tue, 17 Jan 2023 15:57:29 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id pi9ZBWnFxmM6XQAAMHmgww (envelope-from ); Tue, 17 Jan 2023 15:57:29 +0000 From: Juergen Gross To: linux-kernel@vger.kernel.org, x86@kernel.org, linux-acpi@vger.kernel.org Cc: Juergen Gross , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , "Rafael J. Wysocki" , Len Brown , =?utf-8?q?Marek_Marczykowski-G=C3=B3recki?= Subject: [PATCH v2] acpi: fix suspend with Xen PV Date: Tue, 17 Jan 2023 16:57:23 +0100 Message-Id: <20230117155724.22940-1-jgross@suse.com> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1755286333375848011?= X-GMAIL-MSGID: =?utf-8?q?1755286333375848011?= Commit f1e525009493 ("x86/boot: Skip realmode init code when running as Xen PV guest") missed one code path accessing real_mode_header, leading to dereferencing NULL when suspending the system under Xen: [ 348.284004] PM: suspend entry (deep) [ 348.289532] Filesystems sync: 0.005 seconds [ 348.291545] Freezing user space processes ... (elapsed 0.000 seconds) done. [ 348.292457] OOM killer disabled. [ 348.292462] Freezing remaining freezable tasks ... (elapsed 0.104 seconds) done. [ 348.396612] printk: Suspending console(s) (use no_console_suspend to debug) [ 348.749228] PM: suspend devices took 0.352 seconds [ 348.769713] ACPI: EC: interrupt blocked [ 348.816077] BUG: kernel NULL pointer dereference, address: 000000000000001c [ 348.816080] #PF: supervisor read access in kernel mode [ 348.816081] #PF: error_code(0x0000) - not-present page [ 348.816083] PGD 0 P4D 0 [ 348.816086] Oops: 0000 [#1] PREEMPT SMP NOPTI [ 348.816089] CPU: 0 PID: 6764 Comm: systemd-sleep Not tainted 6.1.3-1.fc32.qubes.x86_64 #1 [ 348.816092] Hardware name: Star Labs StarBook/StarBook, BIOS 8.01 07/03/2022 [ 348.816093] RIP: e030:acpi_get_wakeup_address+0xc/0x20 Fix that by adding an optional acpi callback allowing to skip setting the wakeup address, as in the Xen PV case this will be handled by the hypervisor anyway. Fixes: f1e525009493 ("x86/boot: Skip realmode init code when running as Xen PV guest") Reported-by: Marek Marczykowski-Górecki Signed-off-by: Juergen Gross Acked-by: Rafael J. Wysocki --- V2: - new approach, avoid calling acpi_get_wakeup_address() --- arch/x86/include/asm/acpi.h | 8 ++++++++ drivers/acpi/sleep.c | 6 +++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/acpi.h b/arch/x86/include/asm/acpi.h index 65064d9f7fa6..8eb74cf386db 100644 --- a/arch/x86/include/asm/acpi.h +++ b/arch/x86/include/asm/acpi.h @@ -14,6 +14,7 @@ #include #include #include +#include #ifdef CONFIG_ACPI_APEI # include @@ -63,6 +64,13 @@ extern int (*acpi_suspend_lowlevel)(void); /* Physical address to resume after wakeup */ unsigned long acpi_get_wakeup_address(void); +static inline bool acpi_skip_set_wakeup_address(void) +{ + return cpu_feature_enabled(X86_FEATURE_XENPV); +} + +#define acpi_skip_set_wakeup_address acpi_skip_set_wakeup_address + /* * Check if the CPU can handle C2 and deeper */ diff --git a/drivers/acpi/sleep.c b/drivers/acpi/sleep.c index 0b557c0d405e..4ca667251272 100644 --- a/drivers/acpi/sleep.c +++ b/drivers/acpi/sleep.c @@ -60,13 +60,17 @@ static struct notifier_block tts_notifier = { .priority = 0, }; +#ifndef acpi_skip_set_wakeup_address +#define acpi_skip_set_wakeup_address() false +#endif + static int acpi_sleep_prepare(u32 acpi_state) { #ifdef CONFIG_ACPI_SLEEP unsigned long acpi_wakeup_address; /* do we have a wakeup address for S2 and S3? */ - if (acpi_state == ACPI_STATE_S3) { + if (acpi_state == ACPI_STATE_S3 && !acpi_skip_set_wakeup_address()) { acpi_wakeup_address = acpi_get_wakeup_address(); if (!acpi_wakeup_address) return -EFAULT;