From: Andy Lutomirski <luto@amacapital.net>
To: Ricardo Neri <ricardo.neri-calderon@linux.intel.com>
Cc: Andy Lutomirski <luto@kernel.org>,
Brendan Shanks <bshanks@codeweavers.com>,
Andreas Rammhold <andi@notmuch.email>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
X86 ML <x86@kernel.org>, "H. Peter Anvin" <hpa@zytor.com>,
"Eric W. Biederman" <ebiederm@xmission.com>,
Sergey Senozhatsky <sergey.senozhatsky@gmail.com>,
Babu Moger <Babu.Moger@amd.com>,
Kefeng Wang <wangkefeng.wang@huawei.com>,
Jason Yan <yanaijie@huawei.com>,
LKML <linux-kernel@vger.kernel.org>
Subject: Re: umip: AMD Ryzen 3900X, pagefault after emulate SLDT/SIDT instruction
Date: Wed, 20 May 2020 18:16:37 -0700 [thread overview]
Message-ID: <AD88C928-85A9-482C-9EE9-19A82343075A@amacapital.net> (raw)
In-Reply-To: <20200521005605.GA11955@ranerica-svr.sc.intel.com>
> On May 20, 2020, at 5:55 PM, Ricardo Neri <ricardo.neri-calderon@linux.intel.com> wrote:
>
> On Tue, May 19, 2020 at 05:54:53PM -0700, Andy Lutomirski wrote:
>>> On Tue, May 19, 2020 at 12:43 PM Ricardo Neri
>>> <ricardo.neri-calderon@linux.intel.com> wrote:
>>>
>>> On Tue, May 19, 2020 at 11:56:40AM -0700, Brendan Shanks wrote:
>>>>
>>>>> On May 19, 2020, at 7:38 AM, Andreas Rammhold <andi@notmuch.email> wrote:
>>>>>
>>>>> Hi,
>>>>>
>>>>> I've been running into a weird problem with UMIP on a current Ryzen
>>>>> 3900x with kernel 5.6.11 where a process receives a page fault after the
>>>>> kernel handled the SLDT (or SIDT) instruction (emulation).
>>>>>
>>>>> The program I am running is run through WINE in 32bit mode and tries to
>>>>> figure out if it is running in a VMWare machine by comparing the results
>>>>> of SLDT against well known constants (basically as shown in the
>>>>> [example] linked below).
>>>>>
>>>>> In dmesg I see the following log lines:
>>>>>> [99970.004756] umip: Program.exe[3080] ip:4373fb sp:32f3e0: SIDT instruction cannot be used by applications.
>>>>>> [99970.004757] umip: Program.exe[3080] ip:4373fb sp:32f3e0: For now, expensive software emulation returns the result.
>>>>>> [99970.004758] umip: Program.exe[3080] ip:437415 sp:32f3e0: SLDT instruction cannot be used by applications.
>>>>>
>>>>> Following that the process terminates with a page fault:
>>>>>> Unhandled exception: page fault on read access to 0xffffffff in 32-bit code (0x0000000000437415).
>>>>>
>>>>> Assembly at that address:
>>>>>> 0x0000000000437415: sldt 0xffffffe8(%ebp)
>>>>>
>>>>> Running the same executable on the exact same kernel (and userland) but
>>>>> on a Intel i7-8565U doesn't crash at this point. I am guessing the
>>>>> emulation is supposed to do something different on AMD CPUs?
>>>
>>> I am surprised you don't see it on the Intel processor. Maybe it does
>>> not have UMIP. Do you see umip when you do
>>>
>>> $ grep umip /proc/cpuinfo
>>>
>>> ?
>>>>>
>>>>> On the Ryzen the code executes successfully after setting CONFIG_X86_UMIP=n.
>>>>
>>>> Hi Andreas,
>>>>
>>>> The problem is that the kernel does not emulate/spoof the SLDT instruction, only SGDT, SIDT, and SMSW.
>>>> SLDT and STR weren't thought to be commonly used, so emulation/spoofing wasn’t added.
>>>> In the last few months I have seen reports of one or two (32-bit) Windows games that use SLDT though.
>>>> Can you share more information about the application you’re running?
>>>>
>>>> Maybe the best path is to add kernel emulation/spoofing for SLDT and STR on 32 and 64-bit, just to cover all the cases. It should be a pretty simple patch, I’ll start working on it.
>>>
>>> I have a patch for this already that I wrote for testing purposes:
>>>
>>> https://github.com/ricardon/tip/commit/1692889cb3f8accb523d44b682458e234b93be50
>>>
>>> Perhaps it can be used as a starting point? Not sure what the spoofing
>>> value should be, though. Perhaps 0?
>>
>> Possibly SLDT should return nonzero if there's an LDT.
>
> I guess the value should be in the same hole of the x86_64 memory map,
> right? Currently sgdt and sidt return 0xfffffffffffe0000 and
> 0xffffffffffff0000, respectively.
As far as I’m concerned, it makes no difference whether it’s a hole in the memory map. But sure.
>
> Thanks and BR,
> Ricardo
next prev parent reply other threads:[~2020-05-21 1:16 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-19 14:38 umip: AMD Ryzen 3900X, pagefault after emulate SLDT/SIDT instruction Andreas Rammhold
2020-05-19 18:56 ` Brendan Shanks
2020-05-19 19:43 ` Ricardo Neri
2020-05-20 0:54 ` Andy Lutomirski
2020-05-21 0:56 ` Ricardo Neri
2020-05-21 1:16 ` Andy Lutomirski [this message]
2020-05-20 1:04 ` andi
2020-05-23 2:17 ` Andreas Rammhold
2020-05-26 13:33 ` Ricardo Neri
2020-05-28 11:36 ` Andreas Rammhold
2020-05-20 1:08 ` andi
2020-05-23 2:21 ` andi
2020-05-20 0:17 ` H. Peter Anvin
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=AD88C928-85A9-482C-9EE9-19A82343075A@amacapital.net \
--to=luto@amacapital.net \
--cc=Babu.Moger@amd.com \
--cc=andi@notmuch.email \
--cc=bp@alien8.de \
--cc=bshanks@codeweavers.com \
--cc=ebiederm@xmission.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@kernel.org \
--cc=mingo@redhat.com \
--cc=ricardo.neri-calderon@linux.intel.com \
--cc=sergey.senozhatsky@gmail.com \
--cc=tglx@linutronix.de \
--cc=wangkefeng.wang@huawei.com \
--cc=x86@kernel.org \
--cc=yanaijie@huawei.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).