[haiku-commits] Change in ...haiku[master]: [WIP] GSoC 2019: Implementing PCID in x86_64

  • From: Gerrit <review@xxxxxxxxxxxxxxxxxxx>
  • To: waddlesplash <waddlesplash@xxxxxxxxx>, haiku-commits@xxxxxxxxxxxxx
  • Date: Thu, 4 Apr 2019 11:05:19 +0000

From FullPlus <whois.zihan.yang@xxxxxxxxx>:

FullPlus has uploaded this change for review. ( 
https://review.haiku-os.org/c/haiku/+/1353


Change subject: [WIP] GSoC 2019: Implementing PCID in x86_64
......................................................................

[WIP] GSoC 2019: Implementing PCID in x86_64

This patch is a draft proposal for GSoC 2019 project.

NOTE: the code changes in this patch is rather primitive and might not even
      pass the compilation. It is just an illustration of the potential, and
      could change significantly in the future.

For now, the idea is to mimick linux for a dual paga table solution,
then apply PCID for acceleration. When PCID is enabled, we have the last
12 bits of CR3 register to specify a PCID number, so that writing to CR3
register no longer causes a full TLB flush.

For the dual page table part, we allocate an extra top-level PML4 page
for each X86VMTranslationMap64Bit, which contains just limited kernel
mappings. This translation map is per-process from my point of view, so
we are able to implement dual page table for every process.

To mitigate potential side-channel attack, we should allocate different
PCID for user-space and kernel-space tasks. Splitting the PCID into 2 parts
is feasible, one from [0 - 2047], and the other from [2048 - 4096]. Upon
each switch from user space to kernel space, we set the bit 11 to 0, and
when leaving kernel space to user space, we set the bit 11 to 1. This means
the kernel will always use PCID range [0 - 2047] and user space will get
the remaining [2048 - 4096].

Since PCID is limited, we might not want to allocate a new PCID for every
new process, as it would soon run out (maybe not in Haiku?). Instead, we
could still take a per-cpu strategy that each CPU could allow at most 6 PCID
at the same time (Although if the programs in Haiku would not reach to
thousand level, we could try to allocate new PCID for each program as well).

The code change regarding to this patch involves:
* Every syscall entry and interrupt entry specified by MSR
* Every possible place that will return to user space
* Every time we are creating a new translation map
* Every context switch when we need to switch to another thread

Please correct me if I misunderstant anything.

Signed-off-by: Zihan Yang <whois.zihan.yang@xxxxxxxxx>
---
M headers/os/kernel/OS.h
M src/system/kernel/arch/x86/64/interrupts.S
M src/system/kernel/arch/x86/arch_thread.cpp
M src/system/kernel/arch/x86/paging/64bit/X86PagingMethod64Bit.cpp
M src/system/kernel/arch/x86/paging/64bit/X86PagingMethod64Bit.h
M src/system/kernel/arch/x86/paging/64bit/X86PagingStructures64Bit.h
M src/system/kernel/arch/x86/paging/64bit/X86VMTranslationMap64Bit.cpp
M src/system/libroot/os/area.c
8 files changed, 108 insertions(+), 2 deletions(-)



  git pull ssh://git.haiku-os.org/haiku refs/changes/53/1353/1
--
To view, visit https://review.haiku-os.org/c/haiku/+/1353
To unsubscribe, or for help writing mail filters, visit 
https://review.haiku-os.org/settings

Gerrit-Project: haiku
Gerrit-Branch: master
Gerrit-Change-Id: I078b6c293f024cb92d3b7d938ed1450ea8109af7
Gerrit-Change-Number: 1353
Gerrit-PatchSet: 1
Gerrit-Owner: FullPlus <whois.zihan.yang@xxxxxxxxx>
Gerrit-MessageType: newchange

Other related posts:

  • » [haiku-commits] Change in ...haiku[master]: [WIP] GSoC 2019: Implementing PCID in x86_64 - Gerrit