Skip to contentSkip to conversation

KPTI backport to 3.16

DISCUSSION Ben Hutchings 5 participants 14 messages Jan 7, 2018 – Jan 8, 2018 Stable branch

lore
Share & tools
lore
#0 lore raw

I have a backport of KPTI/KAISER to 3.16, based on Hugh Dickins's work for 3.18, some upstream changes between 3.16 and 3.18, and other patches that went into 4.4.75.

I sent this out for review on the stable list after quite minimal testing, but have done more since then. On bare metal (Sandy Bridge, with pcid but not invpcid) it crashes at boot. In fact it reboots without any panic message, suggesting a triple fault, as soon as I apply the patch that turns on CR4.PCIDE, i.e. without KPTI itself.

Using the 'nopcid' kernel parameter gets it to boot but it's somewhat unstable even after that - once I start another kernel build I see programs segfaulting. So I'm guessing I've screwed up some of the TLB stuff.

I'm going to continue investigating this myself before making a release, but would really appreciate any time people can spare to review this patch series.

(I haven't found any such regression in 3.2.98.)

Ben.

Signature · 2 lines
Ben Hutchings
friends: People who know you well, but like you anyway.
#1 lore raw
Quoted 23 lines · Ben Hutchings

I have a backport of KPTI/KAISER to 3.16, based on Hugh Dickins's work for 3.18, some upstream changes between 3.16 and 3.18, and other patches that went into 4.4.75.

I sent this out for review on the stable list after quite minimal testing, but have done more since then. On bare metal (Sandy Bridge, with pcid but not invpcid) it crashes at boot. In fact it reboots without any panic message, suggesting a triple fault, as soon as I apply the patch that turns on CR4.PCIDE, i.e. without KPTI itself.

Using the 'nopcid' kernel parameter gets it to boot but it's somewhat unstable even after that - once I start another kernel build I see programs segfaulting. So I'm guessing I've screwed up some of the TLB stuff.

I'm going to continue investigating this myself before making a release, but would really appreciate any time people can spare to review this patch series.

(I haven't found any such regression in 3.2.98.)

Ben.

Quoted 7 lines

--
Ben Hutchings
friends: People who know you well, but like you anyway.

--
You received this message because you are subscribed to the Google Groups "kaiser-discuss-external" group.
To view this discussion on the web visit https://groups.google.com/a/google.com/d/msgid/kaiser-discuss-external/1515368108.13978.37.camel%40decadent.org.uk.

Hi Ben, I'm not on that "stable list", and don't see where it is archived, so this is the first I've heard of your 3.16 port (which does sound from your description like you've approached it in exactly the right way).

Could you please attach a tarfile of git-format-patches since 3.16.52 that we could look through - that will be easier to manage than downloading 40 mails or whatever - thanks.

Hugh

#2 lore raw

On Sun, 2018-01-07 at 16:05 -0800, Hugh Dickins wrote:
[...]

Quoted 8 lines

Hi Ben, I'm not on that "stable list", and don't see where it is archived, so this is the first I've heard of your 3.16 port (which does sound from your description like you've approached it in exactly the right way).

Could you please attach a tarfile of git-format-patches since 3.16.52 that we could look through - that will be easier to manage than downloading 40 mails or whatever - thanks.

Thanks, they're on the linux-3.16.y-rc branch at:
https://git.kernel.org/pub/scm/linux/kernel/git/bwh/linux-stable-rc.git

Ben.

Signature · 2 lines
Ben Hutchings
This sentence contradicts itself - no actually it doesn't.
#3 lore raw
In reply to Ben Hutchings
Quoted 5 lines · Ben Hutchings

I sent this out for review on the stable list after quite minimal testing, but have done more since then. On bare metal (Sandy Bridge, with pcid but not invpcid) it crashes at boot. In fact it reboots without any panic message, suggesting a triple fault, as soon as I apply the patch that turns on CR4.PCIDE, i.e. without KPTI itself.

My first guess would be something around this stuff:

Quoted 5 lines

commit c7ad5ad297e644601747d6dbee978bf85e14f7bc

Author: Andy Lutomirski <[email protected]>
Date:   Sun Sep 10 17:48:27 2017 -0700

x86/mm/64: Initialize CR4.PCIDE early

But, if you also want to toss a set of binaries up somewhere that I can test I can give them a quick run in the simulator or with a hardware debugger attached. It's been very useful in getting these things debugged, especially when normal debugging techniques fail.

#4 lore raw
Quoted 13 lines · Dave Hansen
Quoted 5 lines · Ben Hutchings

I sent this out for review on the stable list after quite minimal testing, but have done more since then. On bare metal (Sandy Bridge, with pcid but not invpcid) it crashes at boot. In fact it reboots without any panic message, suggesting a triple fault, as soon as I apply the patch that turns on CR4.PCIDE, i.e. without KPTI itself.

My first guess would be something around this stuff:

Quoted 4 lines

commit c7ad5ad297e644601747d6dbee978bf85e14f7bc

Author: Andy Lutomirski <[email protected]>
Date:   Sun Sep 10 17:48:27 2017 -0700
Quoted 6 lines
Quoted 1 line

x86/mm/64: Initialize CR4.PCIDE early

But, if you also want to toss a set of binaries up somewhere that I can test I can give them a quick run in the simulator or with a hardware debugger attached. It's been very useful in getting these things debugged, especially when normal debugging techniques fail.

This is with the full patch set applied (and a fix for NMI handling that wasn't in 3.16.53-rc1):
https://www.decadent.org.uk/ben/tmp/linux-image-3.16.52_3.16.52-50_amd64.deb

Ben.

Signature · 2 lines
Ben Hutchings
This sentence contradicts itself - no actually it doesn't.
#5 lore raw
Quoted 3 lines · Ben Hutchings

This is with the full patch set applied (and a fix for NMI handling that wasn't in 3.16.53-rc1):
https://www.decadent.org.uk/ben/tmp/linux-image-3.16.52_3.16.52-50_amd64.deb

Hi Ben (and others)

I tried this on a ThinkPad X230 (Ivy Bridge CPU, i7 3520M, so pcid but not invpcid) on full UEFI mode and it doesn't boot at all. grub-efi loads the kernel and initrd, but I don't have any message after “Loading initial ramdisk” (even with debug earlyprintk=vga).

I've also tried with nopcid/pcid=no but it doesn't change anything.

I've tried maxcpus=1 and it does work so maybe backporting 375074cc736a could help (I can take a look today).

Regards,

Signature · 1 line
Yves-Alexis
#6 lore raw
Quoted 11 lines · Yves-Alexis Perez
Quoted 3 lines · Ben Hutchings

This is with the full patch set applied (and a fix for NMI handling that wasn't in 3.16.53-rc1):
https://www.decadent.org.uk/ben/tmp/linux-image-3.16.52_3.16.52-50_amd64.deb

Hi Ben (and others)

I tried this on a ThinkPad X230 (Ivy Bridge CPU, i7 3520M, so pcid but not invpcid) on full UEFI mode and it doesn't boot at all. grub-efi loads the kernel and initrd, but I don't have any message after “Loading initial ramdisk” (even with debug earlyprintk=vga).

If you boot with EFI you need to use earlyprintk=efi.

Ben.

Quoted 6 lines

I've also tried with nopcid/pcid=no but it doesn't change anything.

I've tried maxcpus=1 and it does work so maybe backporting 375074cc736a could help (I can take a look today).

Regards,

Signature · 2 lines
Ben Hutchings
This sentence contradicts itself - no actually it doesn't.
#7 lore raw
Quoted 6 lines · Ben Hutchings
Quoted 4 lines

I tried this on a ThinkPad X230 (Ivy Bridge CPU, i7 3520M, so pcid but not invpcid) on full UEFI mode and it doesn't boot at all. grub-efi loads the kernel and initrd, but I don't have any message after “Loading initial ramdisk” (even with debug earlyprintk=vga).

If you boot with EFI you need to use earlyprintk=efi.

Thanks! With that, I can see the last few log lines before it hangs:

Kernel/User page tables isolation: enabled
[…]
bootconsole [earlyefi0] disabled

and then nothing.

Also I must have done something wrong earlier today, because when booting with
'nopcid' it does work (which is consistent with other people tests, afaict).

Regards,

Signature · 1 line
Yves-Alexis
#8 lore raw
Quoted 11 lines · Yves-Alexis Perez
Quoted 5 lines · Ben Hutchings
Quoted 4 lines

I tried this on a ThinkPad X230 (Ivy Bridge CPU, i7 3520M, so pcid but not invpcid) on full UEFI mode and it doesn't boot at all. grub-efi loads the kernel and initrd, but I don't have any message after “Loading initial ramdisk” (even with debug earlyprintk=vga).

If you boot with EFI you need to use earlyprintk=efi.

Thanks! With that, I can see the last few log lines before it hangs:

Kernel/User page tables isolation: enabled
[…]
bootconsole [earlyefi0] disabled

Does "earlyprintk=efi,keep" help get more out to the console?

Quoted 2 lines

Also I must have done something wrong earlier today, because when booting with
'nopcid' it does work (which is consistent with other people tests, afaict).

If I had to guess, I'd say we're probably putting a PCID value into the low bits of CR3 before we've _enabled_ PCID support in the CPU.

#9 lore raw
In reply to Yves-Alexis Perez
Quoted 4 lines · Yves-Alexis Perez
Quoted 3 lines · Ben Hutchings

This is with the full patch set applied (and a fix for NMI handling that wasn't in 3.16.53-rc1):
https://www.decadent.org.uk/ben/tmp/linux-image-3.16.52_3.16.52-50_amd64.deb

I booted this. It crashes in *secondary* CPU startup when it sets CR4.PCIDE while still in 32-bit protected mode. That's illegal.

Plain 3.16 doesn't do this:

https://git.kernel.org/pub/scm/linux/kernel/git/daveh/x86-kaiser.git/tree/arch/x86/kernel/head_64.S?h=v3.16

Quoted 3 lines
	/* Enable PAE mode and PGE */
	movl	$(X86_CR4_PAE | X86_CR4_PGE), %ecx
	movq	%rcx, %cr4

So I suspect the "Enable PAE and PGE" area is wrong.

#10 lore raw
In reply to Ben Hutchings

Ben,

Quoted 9 lines · Ben Hutchings

I have a backport of KPTI/KAISER to 3.16, based on Hugh Dickins's work for 3.18, some upstream changes between 3.16 and 3.18, and other patches that went into 4.4.75.

I sent this out for review on the stable list after quite minimal testing, but have done more since then. On bare metal (Sandy Bridge, with pcid but not invpcid) it crashes at boot. In fact it reboots without any panic message, suggesting a triple fault, as soon as I apply the patch that turns on CR4.PCIDE, i.e. without KPTI itself.

I've seen this as well with my 3.13 tree. As soon as PCID is set on the first (non-boot) CPU, the kernel reboots. Note that it seems to work fine with maxcpus=1.

I've checked the other versions, your 3.2 doesn't have this issue and Hugh's 3.18 doesn't have it either. After some bisecting, I found that the problem was introduced in 3.15 by:
cda846f101fb ('x86, realmode: read cr4 and EFER from kernel for 64-bit trampoline')
and then later fixed again in 4.0 by:
375074cc736a ('x86: Clean up cr4 manipulation')

I've backported 375074cc736a to 3.13 which seems to fix this particular issue but I'm still seeing userspace segfaults.

FWIW:
My tree: https://code.launchpad.net/~juergh/+git/linux-pti
pti/3.13 is my 3.13 tree, pti/3.2.97-bwh and pti/3.16.52-bwh are yours and pti/3.18.72 is Hugh's.

...Juerg

Quoted 13 lines

Using the 'nopcid' kernel parameter gets it to boot but it's somewhat unstable even after that - once I start another kernel build I see programs segfaulting. So I'm guessing I've screwed up some of the TLB stuff.

I'm going to continue investigating this myself before making a release, but would really appreciate any time people can spare to review this patch series.

(I haven't found any such regression in 3.2.98.)

Ben.

#11 lore raw
Quoted 13 lines · Juerg Haefliger

Ben,

Quoted 9 lines · Ben Hutchings

I have a backport of KPTI/KAISER to 3.16, based on Hugh Dickins's work for 3.18, some upstream changes between 3.16 and 3.18, and other patches that went into 4.4.75.

I sent this out for review on the stable list after quite minimal testing, but have done more since then. On bare metal (Sandy Bridge, with pcid but not invpcid) it crashes at boot. In fact it reboots without any panic message, suggesting a triple fault, as soon as I apply the patch that turns on CR4.PCIDE, i.e. without KPTI itself.

Quoted 3 lines

I've seen this as well with my 3.13 tree. As soon as PCID is set on the first (non-boot) CPU, the kernel reboots. Note that it seems to work fine with maxcpus=1.

I see, this makes sense.

Quoted 7 lines

I've checked the other versions, your 3.2 doesn't have this issue and Hugh's 3.18 doesn't have it either. After some bisecting, I found that the problem was introduced in 3.15 by:
cda846f101fb ('x86, realmode: read cr4 and EFER from kernel for 64-bit trampoline')
and then later fixed again in 4.0 by:
375074cc736a ('x86: Clean up cr4 manipulation')

Thanks! This plus obvious changes to the patches using {clear,set}_in_cr4() gets me a kernel that boots on the SNB system.

Quoted 2 lines

I've backported 375074cc736a to 3.13 which seems to fix this particular issue but I'm still seeing userspace segfaults.

With the above changes I'm not seeing any user-space segfaults either (so far).

Quoted 4 lines

FWIW:
My tree: https://code.launchpad.net/~juergh/+git/linux-pti
pti/3.13 is my 3.13 tree, pti/3.2.97-bwh and pti/3.16.52-bwh are yours and pti/3.18.72 is Hugh's.

I've just pushed 3.16.53-rc2 to
https://git.kernel.org/pub/scm/linux/kernel/git/bwh/linux-stable-rc.git

Ben.

Signature · 2 lines
Ben Hutchings
This sentence contradicts itself - no actually it doesn't.
#12 lore raw
Quoted 28 lines · Ben Hutchings
Quoted 13 lines · Juerg Haefliger

Ben,

Quoted 9 lines · Ben Hutchings

I have a backport of KPTI/KAISER to 3.16, based on Hugh Dickins's work for 3.18, some upstream changes between 3.16 and 3.18, and other patches that went into 4.4.75.

I sent this out for review on the stable list after quite minimal testing, but have done more since then. On bare metal (Sandy Bridge, with pcid but not invpcid) it crashes at boot. In fact it reboots without any panic message, suggesting a triple fault, as soon as I apply the patch that turns on CR4.PCIDE, i.e. without KPTI itself.

Quoted 3 lines

I've seen this as well with my 3.13 tree. As soon as PCID is set on the first (non-boot) CPU, the kernel reboots. Note that it seems to work fine with maxcpus=1.

I see, this makes sense.

Quoted 7 lines

I've checked the other versions, your 3.2 doesn't have this issue and Hugh's 3.18 doesn't have it either. After some bisecting, I found that the problem was introduced in 3.15 by:
cda846f101fb ('x86, realmode: read cr4 and EFER from kernel for 64-bit trampoline')
and then later fixed again in 4.0 by:
375074cc736a ('x86: Clean up cr4 manipulation')

Quoted 2 lines

Thanks! This plus obvious changes to the patches using {clear,set}_in_cr4() gets me a kernel that boots on the SNB system.

Do you have debs I could run some tests against?

Quoted 5 lines
Quoted 2 lines

I've backported 375074cc736a to 3.13 which seems to fix this particular issue but I'm still seeing userspace segfaults.

With the above changes I'm not seeing any user-space segfaults either (so far).

Hmm... I was hoping you did ;-) Bummer. I've added the TLB flushing patches to 3.13 that you backported from 3.18 (plus some dependencies) but I'm still seeing segfaults.

...Juerg

Quoted 10 lines
Quoted 4 lines

FWIW:
My tree: https://code.launchpad.net/~juergh/+git/linux-pti
pti/3.13 is my 3.13 tree, pti/3.2.97-bwh and pti/3.16.52-bwh are yours and pti/3.18.72 is Hugh's.

I've just pushed 3.16.53-rc2 to
https://git.kernel.org/pub/scm/linux/kernel/git/bwh/linux-stable-rc.git

Ben.

#13 lore raw
Quoted 30 lines · Juerg Haefliger
Quoted 28 lines · Ben Hutchings
Quoted 13 lines · Juerg Haefliger

Ben,

Quoted 9 lines · Ben Hutchings

I have a backport of KPTI/KAISER to 3.16, based on Hugh Dickins's work for 3.18, some upstream changes between 3.16 and 3.18, and other patches that went into 4.4.75.

I sent this out for review on the stable list after quite minimal testing, but have done more since then. On bare metal (Sandy Bridge, with pcid but not invpcid) it crashes at boot. In fact it reboots without any panic message, suggesting a triple fault, as soon as I apply the patch that turns on CR4.PCIDE, i.e. without KPTI itself.

Quoted 3 lines

I've seen this as well with my 3.13 tree. As soon as PCID is set on the first (non-boot) CPU, the kernel reboots. Note that it seems to work fine with maxcpus=1.

I see, this makes sense.

Quoted 7 lines

I've checked the other versions, your 3.2 doesn't have this issue and Hugh's 3.18 doesn't have it either. After some bisecting, I found that the problem was introduced in 3.15 by:
cda846f101fb ('x86, realmode: read cr4 and EFER from kernel for 64-bit trampoline')
and then later fixed again in 4.0 by:
375074cc736a ('x86: Clean up cr4 manipulation')

Quoted 4 lines
Quoted 2 lines

Thanks! This plus obvious changes to the patches using {clear,set}_in_cr4() gets me a kernel that boots on the SNB system.

Do you have debs I could run some tests against?

[...]

Here you go:
https://www.decadent.org.uk/ben/tmp/linux-image-3.16.53-rc2_3.16.53-rc2-53_amd64.deb

Ben.

Signature · 2 lines
Ben Hutchings
This sentence contradicts itself - no actually it doesn't.