Martins3 / loongson-dune

:zap: Process virtualization based on KVM. More useable, stable and practical than Stanford Dune.
20 stars 3 forks source link

kernel mode : tlb #5

Open Martins3 opened 3 years ago

Martins3 commented 3 years ago

TLB need special attention

  1. should we copy TLB used in host to guest mode ?

    Copy code from tlb.c is error-prone

    • sharing global variable with mips kvm maybe disturb kvm

      We shouldn't remove request related code

    • [ ] vz:requests and remote tlb flush

      We shouldn't remove mode related code

    • [ ] vz_vcpu::mode , check it's corresponding code in the kvm and find all the code
Martins3 commented 3 years ago
Martins3 commented 3 years ago

GuestID

The optional ‘GuestID’ field (GuestCtl1ID or GuestCtl1_RID ) represents a unique identifier for Root and all Guest Virtual Address spaces. Each Guest’s address space is identified by a unique non-zero GuestID.

Direct root-mode access is described by GuestCtl0_DRG in Table 4.2. In the absence of this feature, root would have to probe the Root TLB with GPA, and subsequently read on match to obtain the RPA. If a miss occurs, then root must walk the guest shadow page tables in memory. Otherwise, with direct access, a miss will result in a hardware pagewalk, assuming a hardware pagewalker is supported. :book: VZ manual 4.5.1

Guest TLB Interface:

if (Instruction or Load or Store)
   GuestTLB.Key[GuestID] = GuestCtl1ID
endif
GuestTLB.Key[ASID] = Guest.EntryHiASID

martins3: great!!!. DRG used for open option tdp

In an implementation supporting GuestID (GuestCtl0G1=1), matching of guest TLB entries includes comparison of the TLB entry GuestID with the Root GuestID control field, GuestCtl1_RID.

Martins3 commented 3 years ago
Martins3 commented 3 years ago

My presumption about why after migration to a new CPU, it's necessary to clear the stale guest TLB entry in it.

Martins3 commented 3 years ago

:book: VZ manual : TLBGWI

if IsCoprocessorEnabled(0) then
if (Config3VZ = 0) then
SignalException(ReservedInstruction, 0)
break
endif
i ← Guest.Index
if (Config4IE >= 2) then
Guest.TLB[i]hardware_invalid ← 0
if ( EntryHIEHINV=1 ) then
Guest.TLB[i]hardware_invalid ← 1
endif
endif
Guest.TLB[i]Mask ← Guest.PageMaskMask
Guest.TLB[i]R ← Guest.EntryHiR
Guest.TLB[i]VPN2 ← Guest.EntryHiVPN2 and not Guest.PageMaskMask # Impl dependent
Guest.TLB[i]ASID ← Guest.EntryHiASID
Guest.TLB[i]G ← Guest.EntryLo1G and Guest.EntryLo0G
Guest.TLB[i]PFN1 ← Guest.EntryLo1PFN and not Guest.PageMaskMask # Impl dependent
Guest.TLB[i]C1 ← Guest.EntryLo1C
Guest.TLB[i]D1 ← Guest.EntryLo1D
Guest.TLB[i]V1 ← Guest.EntryLo1V
Guest.TLB[i]PFN0 ← Guest.EntryLo0PFN and not Guest.PageMaskMask # Impl dependent
Guest.TLB[i]C0 ← Guest.EntryLo0C
Guest.TLB[i]D0 ← Guest.EntryLo0D
Guest.TLB[i]V0 ← Guest.EntryLo0V
if (GuestCtl0G1) then
Guest.TLB[i]GuestID ← GuestCtl1RID
endif
else
SignalException(CoprocessorUnusable, 0)
endif
Martins3 commented 3 years ago

The implementation of a GuestID is recommended.Implementation complexity can be minimized by reducing the GuestID to 1 bit.

Martins3 commented 3 years ago

GuestCtl1 register implemented. Set by hardware.
:book: vz manual table 5.2

Martins3 commented 3 years ago

RID 23..16 Root control GuestID. Used by root TLB operations, and when GuestCtl0_DRG=1 in root mode. :book: vz manual table 5.4

Martins3 commented 3 years ago