From patchwork Fri Dec 22 23:51:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kirill A. Shutemov" X-Patchwork-Id: 18490 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2483:b0:fb:cd0c:d3e with SMTP id q3csp1394502dyi; Fri, 22 Dec 2023 15:54:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IFlDlX0ddHIo+fXkHMCzrb+EkHyVGfZWQtPjWAiZ1l4FvngeTNjlHIhufHA9ItzOn7lP0QZ X-Received: by 2002:a05:6e02:158a:b0:35f:db22:1409 with SMTP id m10-20020a056e02158a00b0035fdb221409mr3312887ilu.62.1703289256122; Fri, 22 Dec 2023 15:54:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703289256; cv=none; d=google.com; s=arc-20160816; b=x7o7nSO5WrOOAsSjkcwn8N8Iba/+cJp6J2b0/UtzOr0hW8jybylx9ssp2PQLO+5iBG XwpwklA7TL05OaybioM+M28IlS1Rkia/jJn5Kydw867cpdzUtdJLyDWt1FdXs8gHl6yF 05psrYqJBCRer/RVjmbtv/pMFG1q9+UPT+UaP/DCe709/Zj6ML+k6xy5XaBCWqf9FXyd uAvuQbEve3sYIWM4J5oQLnF07iQb/ab92Yzc9mGHC06KwiffQuw2396MO3X8q5ZBlZrG 8eJTOGdgN/ZIdULA0z3C0WosZyYjTYDR5ODKV3rgTEOJyMOArKJ+x+BuaL7GsmtDlMDl oUPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=3f28dh2u/k+DabH/BWzqDPIqrdhOsXHeik+UjBmKmMA=; fh=OvJRnOqsMTm9XoNmEwebcqh9Ud7yh1CTeKAP84ols98=; b=KWXsEFE25pY1vGi0iOO2Els81oyh269uJghoiL4BcXhwh2dvJI+1J0KyjUx/5Zfe8i p90q4Pm58VPmXONcvXwQb0QrKek6mT7PYx1dGDsCfLUoePjYipvX7vvIsu0yRpO07A6M uQkNOfIiElMC9rROApbYYXvP0Emt3p+2LbqNamYlKKI/zfmdubECSsHQ6rz1fl24w/ui CykIrIBiAQftnzgy7Onj14XfSrhQ+KaYLW0aWT13a3ps7i+zSeDeZ8xWyrONNaxRB/4R OI60Bas+qvxpa+OJwBvBg4QE9SKxL/P10vNnoeZS1Zy5/vj/yHrZbb9yPK7waFC2qrFR yGCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=kgYKaR1j; spf=pass (google.com: domain of linux-kernel+bounces-10131-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-10131-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id s4-20020a170902ea0400b001d41642e478si2267693plg.620.2023.12.22.15.54.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Dec 2023 15:54:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-10131-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=kgYKaR1j; spf=pass (google.com: domain of linux-kernel+bounces-10131-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-10131-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 5ACA3B244D7 for ; Fri, 22 Dec 2023 23:53:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 232D93AC26; Fri, 22 Dec 2023 23:52:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="kgYKaR1j" X-Original-To: linux-kernel@vger.kernel.org Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E1A67364AB for ; Fri, 22 Dec 2023 23:52:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1703289143; x=1734825143; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=lC8VqpK006M7KJvsmEQF8yIYvSloGRgCLRBPKk6F5TE=; b=kgYKaR1jvJZAlmbnVFoOcTcac7gZ6bth0EWa03IFQeJByBkRBVjZ69aF pl7dorpPhNrnC3CtQ6xTRR9TxqYcpQaLs5UzYV3NMLL4K43Z/jQEFEEVe T0h+YW7wZum5OqL45qvizrb30iP+w+R5Df44dvvWQpfxdNAh0OlrhqN0t ykqpKNL/QF5bl+3Yxm8mDEvxCAJUmOJSddWNRrASVp+D3VZsy+ANxhk2D n0OMi/nS3wvAsmOEUdYDGBsHCljDMTGBO1kT+U4v1dXHB3khm+PE3GHYM zjPaGwqGHOotAK3uurnOcE7ghchZg1Xxi7wdJogdDY1PclenKv5z4Wq2d Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10932"; a="395063295" X-IronPort-AV: E=Sophos;i="6.04,297,1695711600"; d="scan'208";a="395063295" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Dec 2023 15:52:20 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10932"; a="900622987" X-IronPort-AV: E=Sophos;i="6.04,297,1695711600"; d="scan'208";a="900622987" Received: from jeroenke-mobl.ger.corp.intel.com (HELO box.shutemov.name) ([10.249.35.180]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Dec 2023 15:52:14 -0800 Received: by box.shutemov.name (Postfix, from userid 1000) id D01FE10945B; Sat, 23 Dec 2023 02:52:11 +0300 (+03) From: "Kirill A. Shutemov" To: 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, "Kirill A. Shutemov" Subject: [PATCHv5 00/16] x86/tdx: Add kexec support Date: Sat, 23 Dec 2023 02:51:52 +0300 Message-ID: <20231222235209.32143-1-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.41.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1786028235188188442 X-GMAIL-MSGID: 1786028235188188442 The patchset adds bits and pieces to get kexec (and crashkernel) work on TDX guest. The last patch implements CPU offlining according to the approved ACPI spec change poposal[1]. It unlocks kexec with all CPUs visible in the target kernel. It requires BIOS-side enabling. If it missing we fallback to booting 2nd kernel with single CPU. Please review. I would be glad for any feedback. [1] https://lore.kernel.org/all/13356251.uLZWGnKmhe@kreacher v5: - Rename smp_ops.crash_play_dead to smp_ops.stop_this_cpu and use it in stop_this_cpu(); - Split off enc_kexec_stop_conversion() from enc_kexec_unshare_mem(); - Introduce kernel_ident_mapping_free(); - Add explicit include for alternatives and stringify. - Add barrier() after setting conversion_allowed to false; - Mark cpu_hotplug_offline_disabled __ro_after_init; - Print error if failed to hand over CPU to BIOS; - Update comments and commit messages; v4: - Fix build for !KEXEC_CORE; - Cleaner ATLERNATIVE use; - Update commit messages and comments; - Add Reviewed-bys; v3: - Rework acpi_mp_crash_stop_other_cpus() to avoid invoking hotplug state machine; - Free page tables if reset vector setup failed; - Change asm_acpi_mp_play_dead() to pass reset vector and PGD as arguments; - Mark acpi_mp_* variables as static and __ro_after_init; - Use u32 for apicid; - Disable CPU offlining if reset vector setup failed; - Rename madt.S -> madt_playdead.S; - Mark tdx_kexec_unshare_mem() as static; - Rebase onto up-to-date tip/master; - Whitespace fixes; - Reorder patches; - Add Reviewed-bys; - Update comments and commit messages; v2: - Rework how unsharing hook ups into kexec codepath; - Rework kvmclock_disable() fix based on Sean's; - s/cpu_hotplug_not_supported()/cpu_hotplug_disable_offlining()/; - use play_dead_common() to implement acpi_mp_play_dead(); - cond_resched() in tdx_shared_memory_show(); - s/target kernel/second kernel/; - Update commit messages and comments; Kirill A. Shutemov (16): x86/acpi: Extract ACPI MADT wakeup code into a separate file x86/apic: Mark acpi_mp_wake_* variables as __ro_after_init cpu/hotplug: Add support for declaring CPU offlining not supported cpu/hotplug, x86/acpi: Disable CPU offlining for ACPI MADT wakeup x86/kvm: Do not try to disable kvmclock if it was not enabled x86/kexec: Keep CR4.MCE set during kexec for TDX guest x86/mm: Make x86_platform.guest.enc_status_change_*() return errno x86/mm: Return correct level from lookup_address() if pte is none x86/tdx: Account shared memory x86/tdx: Convert shared memory back to private on kexec x86/mm: Make e820_end_ram_pfn() cover E820_TYPE_ACPI ranges x86/acpi: Rename fields in acpi_madt_multiproc_wakeup structure x86/acpi: Do not attempt to bring up secondary CPUs in kexec case x86/smp: Add smp_ops.stop_this_cpu() callback x86/mm: Introduce kernel_ident_mapping_free() x86/acpi: Add support for CPU offlining for ACPI MADT wakeup method arch/x86/Kconfig | 7 + arch/x86/coco/core.c | 1 - arch/x86/coco/tdx/tdx.c | 204 ++++++++++++++++++- arch/x86/hyperv/ivm.c | 9 +- arch/x86/include/asm/acpi.h | 7 + arch/x86/include/asm/init.h | 3 + arch/x86/include/asm/pgtable_types.h | 1 + arch/x86/include/asm/smp.h | 1 + arch/x86/include/asm/x86_init.h | 6 +- arch/x86/kernel/acpi/Makefile | 11 +- arch/x86/kernel/acpi/boot.c | 86 +------- arch/x86/kernel/acpi/madt_playdead.S | 29 +++ arch/x86/kernel/acpi/madt_wakeup.c | 292 +++++++++++++++++++++++++++ arch/x86/kernel/crash.c | 6 + arch/x86/kernel/e820.c | 9 +- arch/x86/kernel/kvmclock.c | 12 +- arch/x86/kernel/process.c | 20 +- arch/x86/kernel/reboot.c | 25 ++- arch/x86/kernel/relocate_kernel_64.S | 5 + arch/x86/kernel/x86_init.c | 4 +- arch/x86/mm/ident_map.c | 73 +++++++ arch/x86/mm/mem_encrypt_amd.c | 8 +- arch/x86/mm/pat/set_memory.c | 17 +- include/acpi/actbl2.h | 19 +- include/linux/cc_platform.h | 10 - include/linux/cpu.h | 2 + kernel/cpu.c | 12 +- 27 files changed, 724 insertions(+), 155 deletions(-) create mode 100644 arch/x86/kernel/acpi/madt_playdead.S create mode 100644 arch/x86/kernel/acpi/madt_wakeup.c