Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp596019rdh; Thu, 26 Oct 2023 10:15:38 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFq6qXak83v1hZ8JSEC/GE5ZVdL3862eGaG93pJv/Ztsbi25yYl46I0UTtwSCBo8zwDCfZ6 X-Received: by 2002:a25:2083:0:b0:d7e:8175:4fa9 with SMTP id g125-20020a252083000000b00d7e81754fa9mr17474805ybg.4.1698340537901; Thu, 26 Oct 2023 10:15:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698340537; cv=none; d=google.com; s=arc-20160816; b=n/RC+9lFASa/clQaTxEGD8p9rpEJjghCnbMEjX2kfDCig/CnvuD9mQqXZk9FQxb16y HBDqWFSvoreABXbF3PjcCIY9tbDHKSTi85hQXGSm0mttrCB8AaSBKUsMp3geej+HrFhZ GazuAagNKAwRJBNSpanII0uvpWNaTFlqf7nyKDEEh1uufSWmrqFBt6didgzKkMz3wmW/ m5dWaeeqUrIcU+0CbN6zzZ7UKsGTw6pbZ5xiiECD8MncFpvIYlUo+xjFpYe8og7GKp23 ZJxzJdudvhXEllgfCTemGJ/xZIxcuFemoStsVU4yPcY2iuzLiLiETCfVufnXYe6Xg+LJ +45A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version; bh=bZD7yo5afZmJgLuHdARVWhCjB+D2lkK9+KNf2QkQwr0=; fh=8fqis6mEA0tknCgcmcO7Bpwk2rjF1C/ezVI22NbANXI=; b=yMAkKB10ydwpSFi9KF3CNCbxcHyGTbEC4pNEB5w8o2AtP/kfPMZJ3H4Eblgnb7Jd9r uArOWfJB6WtPdpqTDrwT0/3L7e+A8ILtqVnlKwhz2PfV3hQcpakJKvVqzchmGz6pnXla lulgk35dHb7j39nuk852Z4rFQh8v7QXCyxU9P0VE2qanpMn4sMc0Su2dhtiHj844bfVq SoFKAEN88YEiRKJYvnC4/90hC3gaKUhHve80TKHlLROpbl9Y4FoO08m+5FED+E47Fgvk LjTG+2BYeJDZiINb1f21SKzMrgEZTRnYp5WNZfQWS2UXaBjUL4QhxgZ3yFIxxROYln2U VjCQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id u127-20020a256085000000b00da0ef5982c3si3176ybb.447.2023.10.26.10.15.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Oct 2023 10:15:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id E666B822D02A; Thu, 26 Oct 2023 10:15:33 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231140AbjJZRPc convert rfc822-to-8bit (ORCPT + 99 others); Thu, 26 Oct 2023 13:15:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229668AbjJZRPb (ORCPT ); Thu, 26 Oct 2023 13:15:31 -0400 Received: from mail-oo1-f46.google.com (mail-oo1-f46.google.com [209.85.161.46]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4F55C10A; Thu, 26 Oct 2023 10:15:29 -0700 (PDT) Received: by mail-oo1-f46.google.com with SMTP id 006d021491bc7-5841a3ffd50so174549eaf.1; Thu, 26 Oct 2023 10:15:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698340528; x=1698945328; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Up6fdmcUMJ09KM7otXvgcP25XHUs8+A2jrqzwBf5Mfw=; b=GiZ70PA//Xb3hmuuc+VT3V7pxaaof34F/5fMS8rWBdcbqGEQ09fUpNX5M+9u13swjo AVlP5M1cN5o0dqYpvhF687Q/9DXKAuijwgEmltQisUZr8vBFzCDyFrkFn9sBe6sVXx1K JM8IxmcEpwHlAWDQXpjVptWThqCgTmPcE5WeLUGd2IplYDDooQ7CzGzGArBgcV6Niwzg PT4x+UPsbmffQGP+FbOpyyB3cjI9ZKL++vaLOizvJk5gd6z6lmduwQTQ5ymQ8GS0mdf2 o4R8JWVtkP1m60lfuNaD1xioYvClnxYWbH9FwManStM+rJK5ycHsq8JvvThCcLHGjq+O TIdQ== X-Gm-Message-State: AOJu0YyK7d17qm9+wpIr949ehtbEJZvgBI7KxTwMby7tAIpTRPpbU72B /WDZX7CEclvh/91/lRD19iuwnOsQ5QtWzOnt8qE= X-Received: by 2002:a4a:d68a:0:b0:584:1080:f0a5 with SMTP id i10-20020a4ad68a000000b005841080f0a5mr75517oot.1.1698340528546; Thu, 26 Oct 2023 10:15:28 -0700 (PDT) MIME-Version: 1.0 References: <20231026170330.4657-1-mario.limonciello@amd.com> <20231026170330.4657-2-mario.limonciello@amd.com> In-Reply-To: <20231026170330.4657-2-mario.limonciello@amd.com> From: "Rafael J. Wysocki" Date: Thu, 26 Oct 2023 19:15:17 +0200 Message-ID: Subject: Re: [PATCH v2 1/2] x86: Enable x2apic during resume from suspend if used previously To: Mario Limonciello Cc: Peter Zijlstra , Ingo Molnar , Thomas Gleixner , Borislav Petkov , "maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)" , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Dave Hansen , "H . Peter Anvin" , "Rafael J . Wysocki" , Len Brown , Pavel Machek , David Woodhouse , Sandipan Das , "open list:PERFORMANCE EVENTS SUBSYSTEM" , "open list:PERFORMANCE EVENTS SUBSYSTEM" , "open list:SUSPEND TO RAM" , "open list:ACPI" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS autolearn=no 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-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Thu, 26 Oct 2023 10:15:34 -0700 (PDT) On Thu, Oct 26, 2023 at 7:03 PM Mario Limonciello wrote: > > If x2apic was enabled during boot with parallel startup > it will be needed during resume from suspend to ram as well. > > Store whether to enable into the smpboot_control global variable > and during startup re-enable it if necessary. > > This fixes resume from suspend on workstation CPUs with x2apic > enabled. > > It will also work on systems with one maxcpus=1 but still using > x2apic since x2apic is also re-enabled in lapic_resume(). > > Cc: stable@vger.kernel.org # 6.5 > Fixes: 0c7ffa32dbd6 ("x86/smpboot/64: Implement arch_cpuhp_init_parallel_bringup() and enable it") > Signed-off-by: Mario Limonciello Acked-by: Rafael J. Wysocki > --- > v1->v2: > * Clarify it's in workstations in commit message > * Fix style issues in comment and curly braces > --- > arch/x86/include/asm/smp.h | 1 + > arch/x86/kernel/acpi/sleep.c | 13 +++++++++---- > arch/x86/kernel/head_64.S | 15 +++++++++++++++ > 3 files changed, 25 insertions(+), 4 deletions(-) > > diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h > index c31c633419fe..86584ffaebc3 100644 > --- a/arch/x86/include/asm/smp.h > +++ b/arch/x86/include/asm/smp.h > @@ -190,6 +190,7 @@ extern unsigned long apic_mmio_base; > #endif /* !__ASSEMBLY__ */ > > /* Control bits for startup_64 */ > +#define STARTUP_ENABLE_X2APIC 0x40000000 > #define STARTUP_READ_APICID 0x80000000 > > /* Top 8 bits are reserved for control */ > diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c > index 6dfecb27b846..10d8921b4bb8 100644 > --- a/arch/x86/kernel/acpi/sleep.c > +++ b/arch/x86/kernel/acpi/sleep.c > @@ -11,6 +11,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -129,12 +130,16 @@ int x86_acpi_suspend_lowlevel(void) > */ > current->thread.sp = (unsigned long)temp_stack + sizeof(temp_stack); > /* > - * Ensure the CPU knows which one it is when it comes back, if > - * it isn't in parallel mode and expected to work that out for > - * itself. > + * Ensure x2apic is re-enabled if necessary and the CPU knows which > + * one it is when it comes back, if it isn't in parallel mode and > + * expected to work that out for itself. > */ > - if (!(smpboot_control & STARTUP_PARALLEL_MASK)) > + if (smpboot_control & STARTUP_PARALLEL_MASK) { > + if (x2apic_enabled()) > + smpboot_control |= STARTUP_ENABLE_X2APIC; > + } else { > smpboot_control = smp_processor_id(); > + } > #endif > initial_code = (unsigned long)wakeup_long64; > saved_magic = 0x123456789abcdef0L; > diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S > index ea6995920b7a..300901af9fa3 100644 > --- a/arch/x86/kernel/head_64.S > +++ b/arch/x86/kernel/head_64.S > @@ -237,9 +237,14 @@ SYM_INNER_LABEL(secondary_startup_64_no_verify, SYM_L_GLOBAL) > * CPU number is encoded in smpboot_control. > * > * Bit 31 STARTUP_READ_APICID (Read APICID from APIC) > + * Bit 30 STARTUP_ENABLE_X2APIC (Enable X2APIC mode) > * Bit 0-23 CPU# if STARTUP_xx flags are not set > */ > movl smpboot_control(%rip), %ecx > + > + testl $STARTUP_ENABLE_X2APIC, %ecx > + jnz .Lenable_x2apic > + > testl $STARTUP_READ_APICID, %ecx > jnz .Lread_apicid > /* > @@ -249,6 +254,16 @@ SYM_INNER_LABEL(secondary_startup_64_no_verify, SYM_L_GLOBAL) > andl $(~STARTUP_PARALLEL_MASK), %ecx > jmp .Lsetup_cpu > > +.Lenable_x2apic: > + /* Enable X2APIC if disabled */ > + mov $MSR_IA32_APICBASE, %ecx > + rdmsr > + testl $X2APIC_ENABLE, %eax > + jnz .Lread_apicid_msr > + orl $X2APIC_ENABLE, %eax > + wrmsr > + jmp .Lread_apicid_msr > + > .Lread_apicid: > /* Check whether X2APIC mode is already enabled */ > mov $MSR_IA32_APICBASE, %ecx > -- > 2.34.1 >