Monday, August 22, 2016

I should change communication region to execute rtems with jailhouse.

I should change communication region to execute rtems with jailhouse, because patched rtems use communication region after 0x900000. jailhouse use 0x100000.

I change communication region base to 0x900000
at inmate.h :

And I reserve 0x900000 for communication region at each example demo file for test.
apic-demo.c :
pci-demo.c :

It is executed successfully. So I checked patched rtems whether it reserves 0x900000 for communication region.

but I cannot find that. Gedare Bloom said :

I believe RTEMS stays in real mode, and we do not have any MMU support
code in place. One thing to check is the "memory map" of the linked
executable in startup/linkcmds, which specifies how the ELF file is
loaded into memory. The mentioned address should be reserved for
something, or else it would possibly get assigned to another area and
you may have some data corruption problem.

I should check linkcmds to reserve communication region.

Friday, August 19, 2016

Final report of GSOC 2016 : RTEMS improvemt for Jailhouse hypervisor

Introduction and Project idea
 Jailhouse and RTEMS are open source project.
Jailhouse(https://github.com/siemens/jailhouse) is Linux-based partitioning hypervisor. 
initial version of Jailhouse developed x86 BSP. RTEMS also support x86, RTEMS can be easily as Jailhouse “inmate”. But Jailhouse needs required step for porting. The project aims to Integration, Merging, Fixup of existing support for Jailhouse and port support for other architectures (ARM). Other specifics of the project can be obtained from my proposal.

Status of Work Done
the work is divided into 2 part of bsp and starting jailhouse. And the individual bsps have 4 steps for being patched.

1) x86 : It is completed about 50 %

 (a) booting rtems for jailhouse.
   jailhouse use 0x000f0000 for start16addr ( it should move to jailhouse.cfg )
   pc386.cfg :


   jailhouse doesn't support video.
   start.S :
  
  jailhouse doesn't use local segment descriptor and A20
  start16.S :
 
 jailhouse starts inmate at 0x10000c to start of 32 bit code. and stack pointer address is 0xe0000
  start16.S :
 
   when rtems bsp reset on jailhouse, rtems just halt.


 jailhouse allocate 8Mb memory for rtems inmate cell.
 bspgetworkarea.c :


 
 (b) change pci port
   jailhouse only uses polled serial 1 and use 115200 baud rate.

   conscfg.c :

   last of bsp_console_select, end of libbsp/shared/console_select.c :
   
 (c) change lagacy pic(8259a) to apic(x2apic) to support timer and network.
 
Jailhouse non-root cells must use the xAPIC as minimum but should use
the x2APIC for best performance. 
When wanting to use x2apic, you need to enable it in the APIC BASE MSR. The BIOS may or may not have done this already on real hardware. Jailhouse behaves like a BIOS here in that it does enable x2apic when Linux was using it as well. So you just leave the APIC BASE MSR untouched and can even access the APIC in both ways then (memory mapped or via rdmsr/wrmsr) - Jailhouse maps one on the other.

in irq.c : you should remove all lagacy pic control things and add ioapic like


  for IOAPIC, bsae address is 0xfec00000
  irq.h : ( it should move to ioapic.h )
 
  in irq_asm.S, ack x2apic irq
 
 
in ldsgs.S, 8259a must not be used.

 
Work left: 
 (a) I should change config of jailhouse to execute rtems on jailhouse to test.
 (b) in patch files, rtems was patched to use early printk.
 (c)  In my cace, I use x408 port for pm timer but it can be changed by cases. I should check more.
 (d) rtems use e100, I have only e1000 device. It may change e100 to e1000.

2) arm : I couldn't start this part.


The workflow
The workflow in this project is important because you allow sufficient hardware support to execute jailhouse on qemu. When it comes to hardware spec to execute jailhouse successfully, you should use latest linux on native not vmware or qemu and latest version of qemu. For porting apic to RTEMS, latest qemu is required. A detailed explanation of this follows 

STEP-1:  install jailhouse and start example non-root cell on jailhouse.

STEP-2:  patch rtems-4.11 with origin patch files to test files.

STEP-3:  patch master rtems with origin patch.

in my proposal, I would use rtems-4.11 to execute patched rtems on jailhouse. bacause master rtems has lots of different with rtems-4.11, I change my workflow to patch master rtems.

there are many changes. rtems-4.11 uses 8259s pci but master rtems uses 8259a. cpu.h is removed. clock timer functions are changed. 

in pcibios.c of patch files, many functions are changed but master rtems use already same codes alread changed.

Explanation:
STEP-1: 

I wrote a instruction at this blog before.


jailhouse is still being developed. when you execute qemu with kvm options, there are different between when I executed jailhouse 2 month before and now. you can use iommu, intremap=on by using qemu 2.7.0-rc3. then you can see all of specifications is satisfied distincted from not using iommu,intremap=on.


STEP 2:

I wrote a instruction at this blog before.


STEP 3:

I worte a the strategy of patching rtems at this blog before


rtems-jailhouse-wonjun is my repository to patch rtems for jailhouse.

I am still working to execute rtems as inmate on jailhouse.
I am modifying jailhouse inmate/lib files to change communication address for rtems.
( 0x100000 to 0x900000 )

jailhouse-wonjun is my repository to execute rtems as inmate

Thank you for patient reading.

Wednesday, August 17, 2016

refactoring patch files and where rtems should be modified for jailhouse.

I got 5 patch files from Jan.
0001-RTEMS-Jailhouse-port-1st-batch-including.patch
0002-Add-PCI-management-using-port-I-O.patch
0003-Fix-build-problem-missing-defines-in-cpu.h.patch
0004-Add-IOAPIC-for-PCI-interrupts-and-networking-with-e1.patch
0005-Generalize-some-HW-interfaces-for-Qemu-and-real-HW-e.patch

I should patch 4 points, booting rtems, timer ( select timer and calibrate ), pci ( uart ), networking.

And I should write test code to test whether patched rtems works successfully.

1. booting rtems.

I add jailhouse BSP variant. instead of modifying the make/custom/pc386.cfg file (patch 0001), a new jailhouse.cfg would be added that sets the build rules as needed for jailhouse.

for example

jailhouse.cfg :
   start16addr=0x00097c00 -> 0x000f0000



2. pci

in 0001 patch, patched rtems supports early printk() with no malloc
bsp_start_default() function is modified ( i386/pc386/startup/bspstart.c )

patched rtems is removed _IBMPC_initVideo because jailhouse dosn't support video  (start.S)


3. timer ( select timer and calibrate )
I also add local apic timer option for clock driver. There appears to be conflicting definitions for some of the APIC macros between libbsp/i386/shared/irq/apic.h and the changes made for jailhouse.

because jailhouse non-root cells must use the xAPIC as minimum but should use the x2APIC for best performance, I add local apic option to use x2apic.

pc386/configure.ac :

#define CLOCK_DRIVER_USE_LAPIC $CLOCK_DRIVER_USE_LAPIC
RTEMS_BSPOPTS_SET([CLOCK_DRIVER_USE_LAPIC,[*],[0])
RTEMS_BSPOPTS_HELP([CLOCK_DRIVER_USE_LAPIC],
[ if enabled, the clock driver will be set for jailhouse and use x2apic,
  it is not completed yet.
]

jailhouse use APIC Timers per tick and TSC/APIC Timer ratio to calibrate timer.
I patch ckinit.c file

add function

static void calibrate_pmtimer(void)
> calibrate apic timer / tsc cycle per tick using pm timer


set address and port address for jailhouse

Comm-region/PM-Timer port. ( 0x90000/0x608 )


4. networking
 ....


5. test

I am writing test code divided into three stages.

1) pci - check whether printk function works successfully or not.
2) timer - check ioapic and lapic
3) networking