Received: by 2002:a05:7412:40d:b0:e2:908c:2ebd with SMTP id 13csp265839rdf; Tue, 21 Nov 2023 01:59:14 -0800 (PST) X-Google-Smtp-Source: AGHT+IGiKb6geYEc5nA8ftUgeupHY0LoHMIqKdbq5JevulK3gucJfzh2bSSB5rmP3XOZIEShR6ks X-Received: by 2002:a17:90a:6c21:b0:280:aa7b:fbe8 with SMTP id x30-20020a17090a6c2100b00280aa7bfbe8mr8672215pjj.32.1700560754306; Tue, 21 Nov 2023 01:59:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700560754; cv=none; d=google.com; s=arc-20160816; b=HfLtziT3pXKSTCwp3+Mu4j7xpWEDdNGGCbbx0oOk8WIKdCfDn4DBlfufGNLubFfMAl ri2L2zMx6dhOKUxBhZDsb/ee7RMii0JZST7Qr4pGTV9i2d3oV41TKSohwb1JhuJR9+tc g4V/W4mlKuWCaeopVZ6V6pT/5gg3IOr91QVqCeJNvGjSzzh92X+I22TSFCsdaX0xNuqk md5/0nfn9kh0VDCctGGUsRSy70jm9crry7NLpgPKIGMWimFRH50FfQobZd1DAUCjpKma O/lufqiIIWea5m4EiW+dDVwvy4NzTOmb9vChP34UPcpb92/QF9W/b8IPW3e7kbqhxaKJ ipGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=j5GiGOD/TygrTZWliWILROsm5fNAq0jRmFN7PMkZBnY=; fh=f4SnCP18GcvdWICWlZ/o9/0mE+7famEFm5zezDEmU9w=; b=VXLDG6+aWCTozGge1kPbQDMUeCnVEDFdzrHL6tVby9xxmElVKqAzWRhrz0YoCovumu sQ9y6r+F8U9idd1Vy0xzSfqcB19LJ9N6oQ4T2R1si/q68hDxdaNoBjHV35cFaarz10pR KEbhsT9LSv7JsyRuLY1/KAvvIucueCINcQrp6ElmEQuxAo3tmc410HTWIp9Msn6kTf4y UIIUM0X7LyNEDvdtbVoAjoDKoD8viSJFk6kgYu+1ZH7A9/FSM2dkz2eKubcF9Re9IABP KisMVkr5gbRGa6lsQkNsTjFjdjFgFb8tECGFI+GjWN2MDDHKDdPVVcpCE09Sq9Q5K1XD jduw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=DMqNUu+p; 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=intel.com Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id mj12-20020a17090b368c00b00284eb6ee925si7028046pjb.92.2023.11.21.01.59.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Nov 2023 01:59:14 -0800 (PST) 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; dkim=pass header.i=@intel.com header.s=Intel header.b=DMqNUu+p; 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=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 2F2D380E0708; Tue, 21 Nov 2023 01:59:13 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233540AbjKUJ7N (ORCPT + 99 others); Tue, 21 Nov 2023 04:59:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49650 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231923AbjKUJ7L (ORCPT ); Tue, 21 Nov 2023 04:59:11 -0500 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 74A85F4 for ; Tue, 21 Nov 2023 01:59:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1700560748; x=1732096748; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=XyEy7zmHBwf6sIUIxjVHPKFIhUo8sYFFxrT0V70k+g8=; b=DMqNUu+p5GaxM1RuBR8UfcoFTeSQHUgh0nMqnGDkRxbydhB115EJca8F XQ5HQJ7phxkZj1q+s4HRZa1IHaYKP4RyXNxpZ/Xn9I8vVZO2vlg17Oo5y kUGzf08MW9HZz+749NaKOLtKbXXZWpKGsyC9faWTQwe6UHBGlE5c3BZYk uJ2/R+KTT4lw5eJ3Uu220y0msGgfTxc4IkPHwDm9DiDwb56YXWQggGY+D ofiY9HXM4TidWne/nqIZECRseSluu2N3ktRYG7IAujuFKOiitet4vq4Gj L8WvEiVXNrj6rWvbdDjaX9HWLOGox2okBh3rnY4t5GQHrTVzFtATXGS3C g==; X-IronPort-AV: E=McAfee;i="6600,9927,10900"; a="376841393" X-IronPort-AV: E=Sophos;i="6.04,215,1695711600"; d="scan'208";a="376841393" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Nov 2023 01:59:07 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10900"; a="766586766" X-IronPort-AV: E=Sophos;i="6.04,215,1695711600"; d="scan'208";a="766586766" Received: from ikosarev-mobl1.ger.corp.intel.com (HELO box.shutemov.name) ([10.252.40.84]) by orsmga002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Nov 2023 01:59:02 -0800 Received: by box.shutemov.name (Postfix, from userid 1000) id BFF8510A36E; Tue, 21 Nov 2023 12:58:59 +0300 (+03) Date: Tue, 21 Nov 2023 12:58:59 +0300 From: "kirill.shutemov@linux.intel.com" To: "Huang, Kai" Cc: "tglx@linutronix.de" , "mingo@redhat.com" , "x86@kernel.org" , "bp@alien8.de" , "dave.hansen@linux.intel.com" , "Edgecombe, Rick P" , "Reshetova, Elena" , "Nakajima, Jun" , "rafael@kernel.org" , "peterz@infradead.org" , "linux-kernel@vger.kernel.org" , "sathyanarayanan.kuppuswamy@linux.intel.com" , "Hunter, Adrian" , "thomas.lendacky@amd.com" , "ashish.kalra@amd.com" , "kexec@lists.infradead.org" , "seanjc@google.com" , "bhe@redhat.com" , "linux-coco@lists.linux.dev" Subject: Re: [PATCHv3 10/14] x86/tdx: Convert shared memory back to private on kexec Message-ID: <20231121095859.36xiltn2gwgyxmwy@box.shutemov.name> References: <20231115120044.8034-1-kirill.shutemov@linux.intel.com> <20231115120044.8034-11-kirill.shutemov@linux.intel.com> <8277e9a1df4c3fd968edf670b0aa7dc1dd50dcf8.camel@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <8277e9a1df4c3fd968edf670b0aa7dc1dd50dcf8.camel@intel.com> X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE 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-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 21 Nov 2023 01:59:13 -0800 (PST) On Tue, Nov 21, 2023 at 03:46:41AM +0000, Huang, Kai wrote: > > > > > +static atomic_t conversions_in_progress; > > +static bool conversion_allowed = true; > > > > [...] > > > /* Used while preparing memory map entries for second kernel */ > > struct crash_memmap_data { > > @@ -107,6 +108,9 @@ void native_machine_crash_shutdown(struct pt_regs *regs) > > > > crash_smp_send_stop(); > > > > + if (cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT)) > > + x86_platform.guest.enc_kexec_unshare_mem(true); > > + > > cpu_emergency_disable_virtualization(); > > > > /* > > diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c > > index 830425e6d38e..9fb302562bfd 100644 > > --- a/arch/x86/kernel/reboot.c > > +++ b/arch/x86/kernel/reboot.c > > @@ -12,6 +12,7 @@ > > #include > > #include > > #include > > +#include > > #include > > #include > > #include > > @@ -31,6 +32,7 @@ > > #include > > #include > > #include > > +#include > > > > /* > > * Power off function, if any > > @@ -716,6 +718,9 @@ static void native_machine_emergency_restart(void) > > > > void native_machine_shutdown(void) > > { > > + if (cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT) && kexec_in_progress) > > + x86_platform.guest.enc_kexec_unshare_mem(false); > > + > > /* Stop the cpus and apics */ > > #ifdef CONFIG_X86_IO_APIC > > /* > > In native_machine_crash_shutdown() the "unshare" is called after > crash_smp_send_stop(), but here it's called before the stop_other_cpus(). > > I am wondering if you call "unshare" after stop_other_cpus(), can we guarantee > there's only one cpu running in both normal and crash kexec in which case you > might be able to get rid of the "conversions_in_progress" and > "conversion_allowed" above? For normal kexec we need to keep other CPUs going so they can finish conversion cleanly and get us to the known state. Note that the conversion is not atomic wrt preemption. In crash scenario we do the best effort: detect if we race with conversion and report. We cannot really wait for conversions to finish: we get into crash path with IRQs disabled and in generally unknown state. -- Kiryl Shutsemau / Kirill A. Shutemov