Re: [PATCH kernel] KVM: SVM: Fix function name in comment

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Sep 21, 2022, Nikunj A. Dadhania wrote:
> On 20/09/22 14:18, Alexey Kardashevskiy wrote:
> > On 13/9/22 16:38, Sean Christopherson wrote:
> >> I want to avoid relying on the APM's arbitrary "Type B" classification.  Having to
> >> dig up and look at a manual to understand something that's conceptually quite simple
> >> is frustrating.  Providing references to "Type B" and the table in the changelog is
> >> definitely welcome, e.g. so that someone who wants more details/background can easily
> >> find that info via  via git blame.  
> 
> How about the following:
> 
>       Save states are classified into three types (APM Volume 2: Table B-3. Swap Types)

If we do end up with a verbose comment, don't bother with the volume+table details,
it will inevitably become stale, even if that takes a few years.

What I would take verbatim is the blurb on the classification being determined
by "how it is handled by hardware during a world switch", which is the most
important details from KVM's perspective.

I don't necessarily dislike the idea of capturing the types in a comment, but I
also don't think there's a whole lot of value added in doing so.  E.g. without the
full table, it doesn't help verify the correctness of the code.

I'm fine either way though, it's not that large of a comment and it will likely
prove helpful to someone at some point in time.

> 
>       A: VM-Enter:

So this really should be VMRUN, since the table here is specifically covering
VMRUN behavior, not KVM's broader VM-Enter sequence.  As mentioned earlier in the
thread, VM-Enter/VM-Exit is preferred when talking about the sequence, but in this
case the table is documenting hardware behavior that is specific to VMRUN.

Hrm, and I know that same earlier comment said "on VM-Exit" is preferred, but since
this is again specifically talking about the hardware concept of VMEXIT, it's
probably best to use that terminology for the table.

The short comment I proposed used "on VM-Exit" because it didn't dive as far into
the details of hardware's view of things.

> Host state are saved in host save area

Hmm, I like the APM's approach of avoiding the question of whether or not "Host
state" is plural, i.e. omit the "are" (versus "is"?).

>          VM-Exit: Host state are restored

s/restored/loaded

Doesn't matter as much here, but when KVM is doing the "saving" for type-B,
"restored" can become misleading as KVM isn't strictly required to save its
current state.

> automatically from host save area

s/automatically//

KVM could also "automatically" load state on exit, and there's also no need to
further qualify that hardware loads are "automatic".  Hardware either loads state
or it doesn't, e.g. there's no knob that lets KVM say "don't load this state".

>       B: VM-Enter: Host state are _not_ saved to host save area, KVM needs to save 
>                    required states manually in the host save area

Drop the KVM line, i.e. keep the "table" purely about the types, and leave the
"KVM needs to handle type-B" til the end.  E.g. the "manually" part is arguably
wrong depending on how VMSAVE is classified.

>          VM-Exit: Host state are restored automatically from host save area
> 
>       C: VM-Enter: Host state are _not_ saved to host save area.
>          VM-Exit: Host state are initialized to default(reset) values.

Please align the comments after the colon, makes it easier on the eyes

>       Manually save state(type-B) that is loaded unconditionally by hardware on 

The "save state(type-B)" reads a little odd, maybe "save type-B state"?  And the
"unconditionally" can be dropped (see "automatically" above), as can the "SEV-ES
guests" blurb since this is SEV-ES specific code.  Hmm, though it might be worth
throwing in a "for SEV-ES guests" in the intro?

>       VM-Exit for SEV-ES guests, but is not saved via VMRUN or VMSAVE (performed 
>       by common SVM code).

Hmm, the comma should be after VMRUN, since type-B state is _all_ state that isn't
saved by hardware VMRUN, whereas the key point of this last blurb is to call out
that KVM already saves a subset of type-B state via VMSAVE.

All in all, this?

	/*
	 * All host state for SEV-ES guests is categorized into three swap types
	 * based on how it is handled by hardware during a world switch:
	 *
	 * A: VMRUN:   Host state saved in host save area
         *    VMEXIT:  Host state loaded from host save area
	 *
	 * B: VMRUN:   Host state _NOT_ saved in host save area
         *    VMEXIT:  Host state loaded from host save area
	 *
	 * C: VMRUN:   Host state _NOT_ saved in host save area
         *    VMEXIT:  Host state initialized to default(reset) values
	 *
	 * Manually save type-B state, i.e. state that is loaded by VMEXIT but
	 * isn't saved by VMRUN, that isn't already saved by VMSAVE (performed
	 * by common SVM code).
	 */



[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux