Received: by 2002:a05:7412:8d11:b0:fa:4934:9f with SMTP id bj17csp526764rdb; Mon, 15 Jan 2024 05:19:56 -0800 (PST) X-Google-Smtp-Source: AGHT+IHhx6BxmvG7dGi9FHA75BJ+RKFcQ0Jm5b8IlcQ2b/UNfxmSxYCGZP/YNRNA7BSXtvQZ1sl7 X-Received: by 2002:ad4:5769:0:b0:681:1201:a523 with SMTP id r9-20020ad45769000000b006811201a523mr8556539qvx.25.1705324795802; Mon, 15 Jan 2024 05:19:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705324795; cv=none; d=google.com; s=arc-20160816; b=W4LqL795OhAKQAYSuwZxi9ESd7JX37+zSZixwOH+8EBghprH8f5n0euMO7gAbQzYhF Ddx6FFPVeC+G45Ei4uflXI4UtNTl1JJDGrIecVo/1wP+DF/ww0cm7Br4XmjDI6RVYkYM 4LbNkQOdfhlENipK6d89wy9TamvWPZbp+nUV+X5iXbvVoq8tOft6OHo4h1AaedmdqMXO jze5xS1D4vUFp+vMozdTXQGNEmE0YEVS2nQz1J+bW7mNxk1q21bVUZ45u/lPdE/pCTNE kUQ27H/S90dMWmc4yQfF9ldHjTyUpXkgO7wtF7uKVcuhV/6oNN526/Wt8cWo5fyDoEbu gn/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=Q0v/N0kXAbnUMy0XtXE3gHSioK80yxhIhWRK0FxbIKw=; fh=cHoPloON7bjP722I6WmJv8Zbx+3xWEPssMYpLtoAQ8s=; b=ZqKFgpG901geACP8byHoj1ylG3PbGqn85i/4zktwBX9iJDl5cDUJfa9ZILI/8HLpiS ea0nGSJG9vfwNkNhwj7/uofmT4eWCegRkXpiXNoLuPdn13C2lIP2UjDU/+j9l02gX7Q3 GsOq8uJwuVDPi2Y6qk/4AwDogm4EXnJ4ECtpSJu0da0Po4QJwKm8RpM5ZYshV2sXTow/ nKuhhIfBZam1LkDZDZ07fxQDR6P+Cjj67NH5HMsG8B0QN47InoGloFezHByE0jrwnJSg 2LW/XachJRn6m/eq5jVzKXibeHszot/WdeE44ijmYxlSlGYcsitGaSslUHYa4Fb6sglE G0XA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=google header.b=bCwzKauS; spf=pass (google.com: domain of linux-kernel+bounces-26013-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-26013-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id a14-20020a0cb34e000000b0067f584b65besi8115465qvf.263.2024.01.15.05.19.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jan 2024 05:19:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-26013-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=google header.b=bCwzKauS; spf=pass (google.com: domain of linux-kernel+bounces-26013-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-26013-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 66ACB1C2192A for ; Mon, 15 Jan 2024 13:19:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C0941168D0; Mon, 15 Jan 2024 13:19:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="bCwzKauS" Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C229915AF6 for ; Mon, 15 Jan 2024 13:19:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-40e8004629bso2593005e9.2 for ; Mon, 15 Jan 2024 05:19:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1705324785; x=1705929585; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=Q0v/N0kXAbnUMy0XtXE3gHSioK80yxhIhWRK0FxbIKw=; b=bCwzKauSqoUAHcrWeskUkjjC1uVaGrYEfkD+QwbJa7by8Ws7H7SzY+RlmkgqfPpvpn xjwe6U69enKFSbdBLzk014iiza9a2tGlMO7bi+VFz//bs4B43YDB3ZL//G+aGoJ/ofjh ZDRZvPYM8muX3M1zd2+nVq0UY20vKm181YpXxUv90QBz0RRsAuBj/pBYiNxlSg3pphpK 7sUkA8L9A89QtaZhkheGyIdPOZxXiFP7+EeT6SQ77SY9/aBQDsCoMrD1PY08p8tHtUyM GSzRKFd7BsK5gwVtBLzNdMBoDkZAlk2YT/q2XxENb59UFcYTrLL51KjjmqH5o1EbGWSx bE6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705324785; x=1705929585; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Q0v/N0kXAbnUMy0XtXE3gHSioK80yxhIhWRK0FxbIKw=; b=f7qmoZ2RELAh0nZBhopYjvCiPM825V/ns8VQvWpf++hpL3jUbIymlPqN9OHg1Vww0E 9l+Co2JpEepIN8JusWVdSM+7aCpZoi68k7FOSSICBQyct02UnBZhXC3o59mL7TwjvlgO Uxv7UUH1CbplbH0ek6q0Z9cgoKG6+s01aVL2Jc11Q6VoV6nuKDTz7/jSigi5u0VoXG51 4eAbr4EdtNZPiIo/kLVymfoRZZ+Z0BAbVQ6GVG+2LBMnodIqejI2kvyfUXM8bXbZc0I3 l6P/VA4LIBE3D4W4VIqFBtZnQlm6ywzYvI0iPDn8d8szXkeIzPc4lmMXmnaKZu/2Bs8x NSIw== X-Gm-Message-State: AOJu0YwxFv93RQ3cefW2Dxd/6+KvwVk6SN0pNAnhCpeoBjgptUboVPwT RD4vbwa/i/kUk/mNom/iBKzh1jCTpUtoEg== X-Received: by 2002:a05:600c:295:b0:40e:5f22:3d1b with SMTP id 21-20020a05600c029500b0040e5f223d1bmr1871631wmk.72.1705324785015; Mon, 15 Jan 2024 05:19:45 -0800 (PST) Received: from ?IPV6:2a10:bac0:b000:7588:7285:c2ff:fedd:7e3a? ([2a10:bac0:b000:7588:7285:c2ff:fedd:7e3a]) by smtp.gmail.com with ESMTPSA id v4-20020a05600c470400b0040e5945307esm16032865wmo.40.2024.01.15.05.19.43 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 15 Jan 2024 05:19:44 -0800 (PST) Message-ID: Date: Mon, 15 Jan 2024 15:19:43 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCHv5 16/16] x86/acpi: Add support for CPU offlining for ACPI MADT wakeup method Content-Language: en-US To: "Kirill A. Shutemov" , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org Cc: "Rafael J. Wysocki" , Peter Zijlstra , Adrian Hunter , Kuppuswamy Sathyanarayanan , Elena Reshetova , Jun Nakajima , Rick Edgecombe , Tom Lendacky , "Kalra, Ashish" , Sean Christopherson , "Huang, Kai" , Baoquan He , kexec@lists.infradead.org, linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org References: <20231222235209.32143-1-kirill.shutemov@linux.intel.com> <20231222235209.32143-17-kirill.shutemov@linux.intel.com> From: Nikolay Borisov In-Reply-To: <20231222235209.32143-17-kirill.shutemov@linux.intel.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 23.12.23 г. 1:52 ч., Kirill A. Shutemov wrote: > MADT Multiprocessor Wakeup structure version 1 brings support of CPU > offlining: BIOS provides a reset vector where the CPU has to jump to > for offlining itself. The new TEST mailbox command can be used to test > whether the CPU offlined itself which means the BIOS has control over > the CPU and can online it again via the ACPI MADT wakeup method. > > Add CPU offling support for the ACPI MADT wakeup method by implementing > custom cpu_die(), play_dead() and stop_this_cpu() SMP operations. > > CPU offlining makes is possible to hand over secondary CPUs over kexec, > not limiting the second kernel to a single CPU. > > The change conforms to the approved ACPI spec change proposal. See the > Link. > > Signed-off-by: Kirill A. Shutemov > Link: https://lore.kernel.org/all/13356251.uLZWGnKmhe@kreacher > --- > arch/x86/include/asm/acpi.h | 2 + > arch/x86/kernel/acpi/Makefile | 2 +- > arch/x86/kernel/acpi/madt_playdead.S | 29 +++++ > arch/x86/kernel/acpi/madt_wakeup.c | 184 ++++++++++++++++++++++++++- > include/acpi/actbl2.h | 15 ++- > 5 files changed, 228 insertions(+), 4 deletions(-) > create mode 100644 arch/x86/kernel/acpi/madt_playdead.S > > diff --git a/arch/x86/include/asm/acpi.h b/arch/x86/include/asm/acpi.h > index 2625b915ae7f..021cafa214c2 100644 > --- a/arch/x86/include/asm/acpi.h > +++ b/arch/x86/include/asm/acpi.h > @@ -81,6 +81,8 @@ union acpi_subtable_headers; > int __init acpi_parse_mp_wake(union acpi_subtable_headers *header, > const unsigned long end); > > +void asm_acpi_mp_play_dead(u64 reset_vector, u64 pgd_pa); > + > /* > * Check if the CPU can handle C2 and deeper > */ > diff --git a/arch/x86/kernel/acpi/Makefile b/arch/x86/kernel/acpi/Makefile > index 8c7329c88a75..37b1f28846de 100644 > --- a/arch/x86/kernel/acpi/Makefile > +++ b/arch/x86/kernel/acpi/Makefile > @@ -4,7 +4,7 @@ obj-$(CONFIG_ACPI) += boot.o > obj-$(CONFIG_ACPI_SLEEP) += sleep.o wakeup_$(BITS).o > obj-$(CONFIG_ACPI_APEI) += apei.o > obj-$(CONFIG_ACPI_CPPC_LIB) += cppc.o > -obj-$(CONFIG_X86_ACPI_MADT_WAKEUP) += madt_wakeup.o > +obj-$(CONFIG_X86_ACPI_MADT_WAKEUP) += madt_wakeup.o madt_playdead.o > > ifneq ($(CONFIG_ACPI_PROCESSOR),) > obj-y += cstate.o > diff --git a/arch/x86/kernel/acpi/madt_playdead.S b/arch/x86/kernel/acpi/madt_playdead.S > new file mode 100644 > index 000000000000..e48049959513 > --- /dev/null > +++ b/arch/x86/kernel/acpi/madt_playdead.S > @@ -0,0 +1,29 @@ > +/* SPDX-License-Identifier: GPL-2.0 */ > +#include > +#include > +#include > +#include > + > + .text > + .align PAGE_SIZE > + > +/* > + * asm_acpi_mp_play_dead() - Hand over control of the CPU to the BIOS > + * > + * rdi: Address of the ACPI MADT MPWK ResetVector > + * rsi: PGD of the identity mapping > + */ > +SYM_FUNC_START(asm_acpi_mp_play_dead) > + /* Turn off global entries. Following CR3 write will flush them. */ > + movq %cr4, %rdx > + andq $~(X86_CR4_PGE), %rdx > + movq %rdx, %cr4 > + > + /* Switch to identity mapping */ > + movq %rsi, %rax > + movq %rax, %cr3 nit: Can't you move directly to cr3 > + > + /* Jump to reset vector */ > + ANNOTATE_RETPOLINE_SAFE > + jmp *%rdi > +SYM_FUNC_END(asm_acpi_mp_play_dead)