All of lore.kernel.org
 help / color / mirror / Atom feed
From: "SU Hang" <darcy.sh@antgroup.com>
To: seanjc@google.com
Cc: "SU Hang" <darcy.sh@antgroup.com>, <drjones@redhat.com>,
	<kvm@vger.kernel.org>, <pbonzini@redhat.com>, <thuth@redhat.com>
Subject: Re: [kvm-unit-tests PATCH 2/2] x86: replace `int 0x20` with `syscall`
Date: Wed, 27 Apr 2022 17:27:00 +0800	[thread overview]
Message-ID: <20220427092700.98464-1-darcy.sh@antgroup.com> (raw)
In-Reply-To: <YmbFN6yKwnLDRdr8@google.com>

> Why?
We are implementing a para-virtualization hypervisor, which doesn't allow guest
to trigger soft interrupt > 0x20(but `int 0x80` works fine), so I want to
replace `int 0x20` with a more common `syscall`.


> it's do_ring3() should really be rolled into this framework.
Yes, it is worth working on it, I'll do it in my part-time.


> no existing test verifies that KVM injects #UD on SYSCALL without EFER.SCE
> set, though it would be nice to add one.
I am also interested in it, maybe do it later.


> > + wrmsr(MSR_STAR, ((u64)(USER_CS32 << 16) | KERNEL_CS) << 32);
> It doesn't matter at this time because this framework doesn't ses SYSRET, but
> this should be USER_CS or USER_CS64.
Oops, intel SDM vol.3 <chap 5.8.8> says:
"""
When SYSRET transfers control to 64-bit mode user code using REX.W, the
processor gets the privilege level 3 target code segment, instruction pointer,
          stack segment, and flags as follows:
    • Target code segment — Reads a non-NULL selector from IA32_STAR[63:48] + 16.
    • Stack segment — IA32_STAR[63:48] + 8.
"""

Since the value of USER_CS is 0x4b in 64 bit mode, SS register points to 0x53 =
0x4b + 8, (offset is 0x50) But `gdt + offset(0x50)` hasn't been setup(so does DS
register).
> refs: https://gitlab.com/kvm-unit-tests/kvm-unit-tests/-/blob/master/lib/x86/desc.c#L34
> refs: https://gitlab.com/kvm-unit-tests/kvm-unit-tests/-/blob/master/x86/syscall.c#L68

Linux also does so, the reason is to reuse user segment descriptor in both 32/64 bit.
> refs1: https://github.com/torvalds/linux/blob/46cf2c613f4b10eb12f749207b0fd2c1bfae3088/arch/x86/kernel/cpu/common.c#L1942
> refs2: https://github.com/torvalds/linux/blob/46cf2c613f4b10eb12f749207b0fd2c1bfae3088/arch/x86/include/asm/segment.h#L211
> refs3: https://github.com/torvalds/linux/blob/46cf2c613f4b10eb12f749207b0fd2c1bfae3088/arch/x86/kernel/cpu/common.c#L216

> And a concrete reason not to apply this patch: it causes the nVMX #AC test to fail:
It's awkward, some KUT test cases results diffs on my different machines, which
makes me don't know which result I could trust, so I only pay attention to the
test cases that I care about. I'll keep an eye on the rest cases in the
future.

  parent reply	other threads:[~2022-04-27  9:51 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-24  7:09 [kvm-unit-tests PATCH 1/2] x86: replace `push` `pop` with callee-clobbered list SU Hang
2022-04-24  7:09 ` [kvm-unit-tests PATCH 2/2] x86: replace `int 0x20` with `syscall` SU Hang
2022-04-25 15:58   ` Sean Christopherson
2022-04-27  1:07     ` Sean Christopherson
2022-04-27  9:27     ` SU Hang [this message]
2022-04-28 15:58       ` Sean Christopherson

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=20220427092700.98464-1-darcy.sh@antgroup.com \
    --to=darcy.sh@antgroup.com \
    --cc=drjones@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    --cc=thuth@redhat.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.