mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Tina Zhang <zhang_wei@open-hieco.net>
To: Jim Mattson <jmattson@google.com>
Cc: Sean Christopherson <seanjc@google.com>,
	kvm@vger.kernel.org, Paolo Bonzini <pbonzini@redhat.com>,
	Shuah Khan <shuah@kernel.org>,
	zhouyanjing@hygon.cn, linux-kselftest@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v5 3/8] KVM: nSVM: Track fresh hardware DecodeAssist bytes
Date: Sat, 5 Sep 2026 22:02:50 +0800	[thread overview]
Message-ID: <aeb97d5c-d4aa-4b5c-aeae-dcc6aacfdf1b@open-hieco.net> (raw)
In-Reply-To: <CALMp9eTUv+4v3jT7w3T8XoQmoSwkEjx6LHr39oJ9k8QNiQnyUA@mail.gmail.com>



On 9/5/2026 7:42 AM, Jim Mattson wrote:
> On Mon, Aug 24, 2026 at 5:40 AM Tina Zhang <zhang_wei@open-hieco.net> wrote:
>>
>> VMCB02 instruction bytes are valid only for the hardware VM-Exit that
>> populated them.  Track whether VMCB02 contains instruction bytes for the
>> data #PF or #NPF currently being reflected to L1 so that stale bytes are
>> not copied to VMCB12.
>>
>> Clear the VMCB02 instruction-byte fields and freshness state before each
>> nested run.  Mark the bytes as fresh only when a data #PF or #NPF came
> 
> By "nested run," do you mean "emulated VMRUN"? IIUC, that's when the
> bytes and freshness are cleared.

Yes, I meant when KVM prepares VMCB02 after emulating L1's VMRUN. The 
same helper is also used when restoring nested state. I'll reword the 
commit message to make that clear.


>> +static void nested_svm_clear_insn_bytes(struct vmcb *vmcb)
>> +{
>> +       vmcb->control.insn_len = 0;
>> +       memset(vmcb->control.insn_bytes, 0,
>> +              sizeof(vmcb->control.insn_bytes));
>> +}
> 
> Is it necessary to clear the bytes? The APM says, "All other
> intercepts clear bits 7:0 in this field to zero (to indicate an
> invalid condition); implementations may leave the other bytes
> untouched."
> 
> Are you concerned about leaking bytes from unreflected VM-exits handled by L0?

No, clearing the entire byte array isn't necessary.  VMCB02 is private 
to L0, and insn_len determines whether the bytes are valid and how many
bytes may be copied to VMCB12.  Setting insn_len to zero is sufficient
and matches the behavior allowed by the APM. I'll drop the memset().


>> -int nested_svm_exit_handled(struct vcpu_svm *svm)
>> +int nested_svm_exit_handled(struct vcpu_svm *svm, bool from_hardware)
> 
> I don't think 'from_hardware' is necessary. The two callsites where
> from_hardware is false are for opcode exits, and will be ruled out by
> the check for nested_svm_vmexit_has_insn_bytes(svm->vmcb). If you drop
> this extra parameter, there will be less churn.

Agreed. Both non-hardware callsites set an opcode exit code before 
calling nested_svm_exit_handled(), so nested_svm_vmexit_has_insn_bytes() 
will reject them.  I'll drop the from_hardware parameter from 
nested_svm_exit_handled() and restore its callers.

Thanks,
Tina


  reply	other threads:[~2026-09-05 14:03 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-24 12:39 [PATCH v5 0/8] KVM: nSVM: Enable DecodeAssists for nested guests Tina Zhang
2026-08-24 12:39 ` [PATCH v5 1/8] KVM: x86: Add helper to provide intercept linear addresses Tina Zhang
2026-09-04 22:34   ` Jim Mattson
2026-09-06  0:57     ` Tina Zhang
2026-08-24 12:39 ` [PATCH v5 2/8] KVM: nSVM: Synthesize DecodeAssists EXITINFO for emulated intercepts Tina Zhang
2026-09-04 23:07   ` Jim Mattson
2026-09-06  2:24     ` Tina Zhang
2026-09-06 16:29       ` Jim Mattson
2026-08-24 12:39 ` [PATCH v5 3/8] KVM: nSVM: Track fresh hardware DecodeAssist bytes Tina Zhang
2026-09-04 23:42   ` Jim Mattson
2026-09-05 14:02     ` Tina Zhang [this message]
2026-08-24 12:39 ` [PATCH v5 4/8] KVM: nSVM: Propagate hardware DecodeAssist bytes to VMCB12 Tina Zhang
2026-09-04 23:58   ` Jim Mattson
2026-09-06  2:45     ` Tina Zhang
2026-08-24 12:39 ` [PATCH v5 5/8] KVM: nSVM: Use emulator bytes for synthesized nested #NPF Tina Zhang
2026-09-05  0:17   ` Jim Mattson
2026-09-06  5:33     ` Tina Zhang
2026-08-24 12:39 ` [PATCH v5 6/8] KVM: nSVM: Fetch missing DecodeAssist bytes for synthesized #NPF/#PF Tina Zhang
2026-09-05  0:39   ` Jim Mattson
2026-09-06  6:40     ` Tina Zhang
2026-09-06 16:33       ` Jim Mattson
2026-09-10  0:51         ` Sean Christopherson
2026-08-24 12:39 ` [PATCH v5 7/8] KVM: nSVM: Advertise DecodeAssists to L1 Tina Zhang
2026-09-05  0:44   ` Jim Mattson
2026-08-24 12:39 ` [PATCH v5 8/8] KVM: selftests: Add nested SVM DecodeAssists test Tina Zhang
2026-09-03  2:41 ` [PATCH v5 0/8] KVM: nSVM: Enable DecodeAssists for nested guests Tina Zhang

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=aeb97d5c-d4aa-4b5c-aeae-dcc6aacfdf1b@open-hieco.net \
    --to=zhang_wei@open-hieco.net \
    --cc=jmattson@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    --cc=shuah@kernel.org \
    --cc=zhouyanjing@hygon.cn \
    /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®