Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp354462rdb; Thu, 1 Feb 2024 10:16:26 -0800 (PST) X-Google-Smtp-Source: AGHT+IF6HV/Z5gDQ0Iw1Y4k8tLR97stOVyeq9Y4fni6bjFZXmzVLTIl6PH4YSdELS6boqPd/CoNh X-Received: by 2002:a17:906:d7a8:b0:a32:b376:48d8 with SMTP id pk8-20020a170906d7a800b00a32b37648d8mr2400864ejb.18.1706811386376; Thu, 01 Feb 2024 10:16:26 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706811386; cv=pass; d=google.com; s=arc-20160816; b=sP1dm1i+0NJWjAGzkMNUxD/CBaA1j+N9p/iKhdVLv4dxJJfZVoBKAJUaGWarjhr0wc fPex3R43B7TN2efO8E4NmUeHBk2rfQf03q6yMohvWDduKvnuDWp90ZVnh7SD/dXH570a d5SctxATB4C2cLO/PZSLnDBNeWoILP1209cV247FQtG5lxrh1eSBD+2dH+xTaQJoKO2/ GYARlkxntZz/4+ZETPOaz8QINV1kqAZ6vVlSqEd8sUXUhX5WBoip8X6TavcU7XdmsXzH Vx3/ZMmDZW0PfDT1DgCPrcs0aJBbzV8CK8zX/4eOuMlG7hctGSrlpUtKhs1gMLt3lSp7 Ik2g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:from:date:dkim-signature; bh=w3bJHlfiyyoRtJVNK4y7yVspCL/rIevJHw8MZ2yGkTg=; fh=FFPpsi3sUqjrO+heWUpW4JHndd+drBKfDMmEf/hxh5Q=; b=i7wc5wfWBOx2VW8ps1aElJDK4ql8duHjkCC/Kn3oN6IF97xhlrabIT+etlq3ixMFBE /K/nv4iAkk4JsH290dyO1ClG1phz8mZAr9heqf8H/fy0/TOha35llTru5LnAWTy3xmyB XyciBvmbefnYC0DMnOdEF3WW/BtK3CFbYyYDWobumU5jSmvA66PLlRAh7ygHOXsLZQO9 itHvVdgtpeP5qMG6dbLS+YAFA24lb8Kn9cxMsNGy0EGcRtTRP3KlXYu7nEXKK97bDlRn tDDKEbM8HJWZf1VtKV64S2Gk5QFBsnKniwUP3hvVv2LSwS4oX9xnFYj/gSH2EDUmCkUW Gy/g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=nb8AG3X2; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-48327-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-48327-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=1; AJvYcCWoayUQtuVPCEoffd7D7QyZH60gwT8009YHlcLhBAuUhGVByGm5iIDL0x6m7cOUmT8L30C3U91cb6Sdup5xEUA6zUM/84XwIdGieGuFug== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id f14-20020a170906084e00b00a35dea0b1e8si38010ejd.69.2024.02.01.10.16.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 10:16:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-48327-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=nb8AG3X2; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-48327-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-48327-linux.lists.archive=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 am.mirrors.kernel.org (Postfix) with ESMTPS id ED05D1F272F9 for ; Thu, 1 Feb 2024 14:39:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id ED6485F466; Thu, 1 Feb 2024 14:39:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="nb8AG3X2" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.11]) (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 871085D460 for ; Thu, 1 Feb 2024 14:39:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.11 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706798348; cv=none; b=eVyjuji70UclazqU531VaOwiQYoPkf7NrMBI4BpJgHcBubKyQ/BA0sKdNsDt4LdFCc6i4i2vxUZ2A3gTDbxDZ40Kc/Kz9Jfr6ujBUktcjNsS1csMJ1hi4yReMhR7ztmKXyhBeoBU4+p5CtY2L2CzSWOBROzBOrvQ0dvagd52ke0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706798348; c=relaxed/simple; bh=DU4icRwi3TNyBbtjNR34RkFqYSFJ8gRYgLp/MM3e20c=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=o4HH4ErJ8x162DAcCpd4tZQmFhbA8N7WiBXuCgymAuRtxpVQcJmVEgXi4xCnB7vnqaeoAFqW2FfGkUQRNQGRpH/VWonvSxtdw9eRA9HMFcepFVzavheq17nrKSp9QwnTGxNogblTUJY1Psj2LLZqOK9OWGau2xxSNur29N5+Iuo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=nb8AG3X2; arc=none smtp.client-ip=192.198.163.11 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=1706798346; x=1738334346; h=date:from:to:cc:subject:message-id:references: mime-version:content-transfer-encoding:in-reply-to; bh=DU4icRwi3TNyBbtjNR34RkFqYSFJ8gRYgLp/MM3e20c=; b=nb8AG3X21UYdtVJ3Fv4Z19FtbU2uucGf/tUan4CrOxeyib7p0OCJFIpw 4IleUkQsiWXCARzWqOSzcISIdvEvj7t7lMBn0Q6T0Wxz/+1XFxD/FRJma +hurLdenQQnnKwdxkFQaZuhhbFYm7HzB/MghNhzB+4Oo9QbyRin6gh2r8 0iVPuVK+dMVbhPXSVf11SsdGkY+gcO1sqrI7w3/zJyIDzqzDeO6yVKbO5 +EST48fjEbrAI3zrISpmH0FSY+lXBHtzy8LzGCo6eSjEMP5rdz8C69F45 290KYGoD6GL6DvgE8krdu2+khX3umtqGsI687ZnZ91XjwFMK+LmeBr9Pz A==; X-IronPort-AV: E=McAfee;i="6600,9927,10969"; a="10561070" X-IronPort-AV: E=Sophos;i="6.05,234,1701158400"; d="scan'208";a="10561070" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Feb 2024 06:39:06 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10969"; a="932190575" X-IronPort-AV: E=Sophos;i="6.05,234,1701158400"; d="scan'208";a="932190575" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 01 Feb 2024 06:39:02 -0800 Received: by black.fi.intel.com (Postfix, from userid 1000) id D78C1A23; Thu, 1 Feb 2024 16:39:00 +0200 (EET) Date: Thu, 1 Feb 2024 16:39:00 +0200 From: "Kirill A. Shutemov" To: "Huang, Kai" Cc: Dave Hansen , linux-kernel@vger.kernel.org, x86@kernel.org, tglx@linutronix.de, bp@alien8.de, mingo@redhat.com, hpa@zytor.com, luto@kernel.org, peterz@infradead.org, thomas.lendacky@amd.com, chao.gao@intel.com, bhe@redhat.com, nik.borisov@suse.com, pbonzini@redhat.com Subject: Re: [PATCH 3/4] x86/kexec(): Reset TDX private memory on platforms with TDX erratum Message-ID: References: <12a927df-e437-40ff-ba4d-ceca5446c5b1@intel.com> <0c990c7d-4df9-45c1-8c03-980d9842b963@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <0c990c7d-4df9-45c1-8c03-980d9842b963@intel.com> On Thu, Feb 01, 2024 at 10:22:18PM +0800, Huang, Kai wrote: > > > On 1/02/2024 6:03 am, Kirill A. Shutemov wrote: > > On Wed, Jan 31, 2024 at 01:21:39PM -0800, Dave Hansen wrote: > > > > #ifdef CONFIG_KEXEC_JUMP > > > > if (image->preserve_context) > > > > save_processor_state(); > > > > + else > > > > + tdx_reset_memory(); > > > > +#else > > > > + tdx_reset_memory(); > > > > #endif > > > > > > Wow, that's awfully hard to read. I really wish folks' gag reflex would > > > kick in when they see stuff like this to get them to spend an additional > > > 15 seconds to turn this into: > > > > > > if (IS_ENABLED(CONFIG_KEXEC_JUMP) && image->preserve_context) > > > save_processor_state(); > > > else > > > tdx_reset_memory(); > > > > save_processor_state() is declared under CONFIG_PM_SLEEP, so I guess your > > variant might break build in some cases without updated suspend.h. > > I tried. If I turn off both SUSPEND and HIBERNATION in the Kconfig I got > build error: > > arch/x86/kernel/machine_kexec_64.c:325:17: error: implicit declaration of > function ‘save_processor_state’ [-Werror=implicit-function-declaration] > 325 | save_processor_state(); > | ^~~~~~~~~~~~~~~~~~~~ Moving save_processor_state() declaration outside all defines would do the trick. Something like the patch below. But finding the right spot for the move can be tricky. I don't particular like where I moved it. diff --git a/include/linux/suspend.h b/include/linux/suspend.h index ef503088942d..1c17059df039 100644 --- a/include/linux/suspend.h +++ b/include/linux/suspend.h @@ -201,6 +201,9 @@ struct platform_s2idle_ops { void (*end)(void); }; +void save_processor_state(void); +void restore_processor_state(void); + #ifdef CONFIG_SUSPEND extern suspend_state_t pm_suspend_target_state; extern suspend_state_t mem_sleep_current; @@ -491,8 +494,6 @@ static inline int is_hibernate_resume_dev(dev_t dev) { return 0; } extern struct mutex system_transition_mutex; #ifdef CONFIG_PM_SLEEP -void save_processor_state(void); -void restore_processor_state(void); /* kernel/power/main.c */ extern int register_pm_notifier(struct notifier_block *nb); -- Kiryl Shutsemau / Kirill A. Shutemov