mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Huang, Kai" <kai.huang@intel.com>
To: "Hansen, Dave" <dave.hansen@intel.com>,
	"bp@alien8.de" <bp@alien8.de>,
	"peterz@infradead.org" <peterz@infradead.org>,
	"hpa@zytor.com" <hpa@zytor.com>,
	"mingo@redhat.com" <mingo@redhat.com>,
	"tglx@linutronix.de" <tglx@linutronix.de>,
	"David.Kaplan@amd.com" <David.Kaplan@amd.com>,
	"kirill.shutemov@linux.intel.com"
	<kirill.shutemov@linux.intel.com>
Cc: "Edgecombe, Rick P" <rick.p.edgecombe@intel.com>,
	"seanjc@google.com" <seanjc@google.com>,
	"x86@kernel.org" <x86@kernel.org>,
	"dyoung@redhat.com" <dyoung@redhat.com>,
	"sagis@google.com" <sagis@google.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"Williams, Dan J" <dan.j.williams@intel.com>,
	"Thomas.Lendacky@amd.com" <Thomas.Lendacky@amd.com>,
	"pbonzini@redhat.com" <pbonzini@redhat.com>,
	"Ashish.Kalra@amd.com" <Ashish.Kalra@amd.com>,
	"Yamahata, Isaku" <isaku.yamahata@intel.com>,
	"bhe@redhat.com" <bhe@redhat.com>,
	"nik.borisov@suse.com" <nik.borisov@suse.com>
Subject: Re: [PATCH v6 2/5] x86/kexec: do unconditional WBINVD for bare-metal in relocate_kernel()
Date: Tue, 10 Sep 2024 09:52:49 +0000	[thread overview]
Message-ID: <8b9ddac38a612a7ecee7511c657ba0bf84660d3b.camel@intel.com> (raw)
In-Reply-To: <LV3PR12MB9265900A6564C22E9F6666ED949A2@LV3PR12MB9265.namprd12.prod.outlook.com>

On Tue, 2024-09-10 at 02:46 +0000, Kaplan, David wrote:
> [AMD Official Use Only - AMD Internal Distribution Only]
> 
> > -----Original Message-----
> > From: Huang, Kai <kai.huang@intel.com>
> > Sent: Monday, September 9, 2024 9:42 PM
> > To: Kaplan, David <David.Kaplan@amd.com>; Hansen, Dave
> > <dave.hansen@intel.com>; bp@alien8.de; tglx@linutronix.de;
> > peterz@infradead.org; mingo@redhat.com; hpa@zytor.com;
> > kirill.shutemov@linux.intel.com
> > Cc: x86@kernel.org; linux-kernel@vger.kernel.org; pbonzini@redhat.com;
> > seanjc@google.com; Williams, Dan J <dan.j.williams@intel.com>; Lendacky,
> > Thomas <Thomas.Lendacky@amd.com>; Edgecombe, Rick P
> > <rick.p.edgecombe@intel.com>; Yamahata, Isaku
> > <isaku.yamahata@intel.com>; Kalra, Ashish <Ashish.Kalra@amd.com>;
> > bhe@redhat.com; nik.borisov@suse.com; sagis@google.com; Dave Young
> > <dyoung@redhat.com>
> > Subject: Re: [PATCH v6 2/5] x86/kexec: do unconditional WBINVD for bare-
> > metal in relocate_kernel()
> > 
> > Caution: This message originated from an External Source. Use proper
> > caution when opening attachments, clicking links, or responding.
> > 
> > 
> > > > --- a/arch/x86/kernel/machine_kexec_64.c
> > > > +++ b/arch/x86/kernel/machine_kexec_64.c
> > > > @@ -322,16 +322,9 @@ void machine_kexec_cleanup(struct kimage
> > *image)
> > > > void machine_kexec(struct kimage *image)  {
> > > >          unsigned long page_list[PAGES_NR];
> > > > -       unsigned int host_mem_enc_active;
> > > >          int save_ftrace_enabled;
> > > >          void *control_page;
> > > > 
> > > > -       /*
> > > > -        * This must be done before load_segments() since if call depth
> > tracking
> > > > -        * is used then GS must be valid to make any function calls.
> > > > -        */
> > > > -       host_mem_enc_active =
> > > > cc_platform_has(CC_ATTR_HOST_MEM_ENCRYPT);
> > > > -
> > > 
> > > Functionally the patch looks fine.  I would suggest keeping some form of
> > this comment though, because the limitation about not being able to make
> > function calls after load_segments() is arguably non-obvious and this
> > comment served as a warning for future modifications in this area.
> > 
> > Yeah this makes sense.  Thanks.
> > 
> > I think we can add some text to the existing comment of load_segments() to
> > call out this.  Allow me to dig into more about call depth tracking to
> > understand it better -- relocate_kernel() after load_segments() seems to be a
> > real function call and I want to know how does it interact with call depth
> > tracking.
> 
> That one is explicitly ignored, see skip_addr() in arch/x86/kernel/callthunks.c
> 

That was I thought too.  Thanks for pointing out.

How about below?

--- a/arch/x86/kernel/machine_kexec_64.c
+++ b/arch/x86/kernel/machine_kexec_64.c
@@ -351,6 +351,11 @@ void machine_kexec(struct kimage *image)
         *
         * I take advantage of this here by force loading the
         * segments, before I zap the gdt with an invalid value.
+        *
+        * Note this resets GS to 0.  Don't make any function call after
+        * here since call depth tracking uses per-cpu variables to
+        * operate (relocate_kernel is explicitly ignored by call depth
+        * tracking).
         */

Btw, it would be very helpful if you can help to verify this patch doesn't break
call depth tracking in your environment.  Thanks!

  reply	other threads:[~2024-09-10  9:52 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-09  8:06 [PATCH v6 0/5] TDX host: kexec() support Kai Huang
2024-09-09  8:06 ` [PATCH v6 1/5] x86/kexec: do unconditional WBINVD for bare-metal in stop_this_cpu() Kai Huang
2024-09-09  8:06 ` [PATCH v6 2/5] x86/kexec: do unconditional WBINVD for bare-metal in relocate_kernel() Kai Huang
2024-09-09 13:56   ` Kaplan, David
2024-09-10  2:42     ` Huang, Kai
2024-09-10  2:46       ` Kaplan, David
2024-09-10  9:52         ` Huang, Kai [this message]
2024-09-12  2:21           ` Kaplan, David
2024-09-12 10:38             ` Huang, Kai
2024-09-09  8:06 ` [PATCH v6 3/5] x86/virt/tdx: Make module initializatiton state immutable in reboot notifier Kai Huang
2024-09-09  8:06 ` [PATCH v6 4/5] x86/kexec: Reset TDX private memory on platforms with TDX erratum Kai Huang
2024-09-09  8:06 ` [PATCH v6 5/5] x86/virt/tdx: Remove the !KEXEC_CORE dependency Kai Huang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8b9ddac38a612a7ecee7511c657ba0bf84660d3b.camel@intel.com \
    --to=kai.huang@intel.com \
    --cc=Ashish.Kalra@amd.com \
    --cc=David.Kaplan@amd.com \
    --cc=Thomas.Lendacky@amd.com \
    --cc=bhe@redhat.com \
    --cc=bp@alien8.de \
    --cc=dan.j.williams@intel.com \
    --cc=dave.hansen@intel.com \
    --cc=dyoung@redhat.com \
    --cc=hpa@zytor.com \
    --cc=isaku.yamahata@intel.com \
    --cc=kirill.shutemov@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=nik.borisov@suse.com \
    --cc=pbonzini@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rick.p.edgecombe@intel.com \
    --cc=sagis@google.com \
    --cc=seanjc@google.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®