Skip to content

Commit 9843b03

Browse files
sanjaylcaralfbaechle
authored andcommitted
KVM/MIPS32: KVM Guest kernel support.
Both Guest kernel and Guest Userspace execute in UM. The memory map is as follows: Guest User address space: 0x00000000 -> 0x40000000 Guest Kernel Unmapped: 0x40000000 -> 0x60000000 Guest Kernel Mapped: 0x60000000 -> 0x80000000 - Guest Usermode virtual memory is limited to 1GB. Signed-off-by: Sanjay Lal <sanjayl@kymasys.com> Cc: kvm@vger.kernel.org Cc: linux-mips@linux-mips.org Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
1 parent 669e846 commit 9843b03

File tree

7 files changed

+52
-3
lines changed

7 files changed

+52
-3
lines changed

arch/mips/include/asm/mach-generic/spaces.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,21 @@
2020
#endif
2121

2222
#ifdef CONFIG_32BIT
23-
23+
#ifdef CONFIG_KVM_GUEST
24+
#define CAC_BASE _AC(0x40000000, UL)
25+
#else
2426
#define CAC_BASE _AC(0x80000000, UL)
27+
#endif
2528
#define IO_BASE _AC(0xa0000000, UL)
2629
#define UNCAC_BASE _AC(0xa0000000, UL)
2730

2831
#ifndef MAP_BASE
32+
#ifdef CONFIG_KVM_GUEST
33+
#define MAP_BASE _AC(0x60000000, UL)
34+
#else
2935
#define MAP_BASE _AC(0xc0000000, UL)
3036
#endif
37+
#endif
3138

3239
/*
3340
* Memory above this physical address will be considered highmem.

arch/mips/include/asm/processor.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,16 @@ extern unsigned int vced_count, vcei_count;
4444
#define SPECIAL_PAGES_SIZE PAGE_SIZE
4545

4646
#ifdef CONFIG_32BIT
47+
#ifdef CONFIG_KVM_GUEST
48+
/* User space process size is limited to 1GB in KVM Guest Mode */
49+
#define TASK_SIZE 0x3fff8000UL
50+
#else
4751
/*
4852
* User space process size: 2GB. This is hardcoded into a few places,
4953
* so don't change it unless you know what you are doing.
5054
*/
5155
#define TASK_SIZE 0x7fff8000UL
56+
#endif
5257

5358
#ifdef __KERNEL__
5459
#define STACK_TOP_MAX TASK_SIZE

arch/mips/include/asm/uaccess.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@
2323
*/
2424
#ifdef CONFIG_32BIT
2525

26-
#define __UA_LIMIT 0x80000000UL
26+
#ifdef CONFIG_KVM_GUEST
27+
#define __UA_LIMIT 0x40000000UL
28+
#else
29+
#define __UA_LIMIT 0x80000000UL
30+
#endif
2731

2832
#define __UA_ADDR ".word"
2933
#define __UA_LA "la"
@@ -55,8 +59,13 @@ extern u64 __ua_limit;
5559
* address in this range it's the process's problem, not ours :-)
5660
*/
5761

62+
#ifdef CONFIG_KVM_GUEST
63+
#define KERNEL_DS ((mm_segment_t) { 0x80000000UL })
64+
#define USER_DS ((mm_segment_t) { 0xC0000000UL })
65+
#else
5866
#define KERNEL_DS ((mm_segment_t) { 0UL })
5967
#define USER_DS ((mm_segment_t) { __UA_LIMIT })
68+
#endif
6069

6170
#define VERIFY_READ 0
6271
#define VERIFY_WRITE 1

arch/mips/kernel/binfmt_elfo32.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,11 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
4848
__res; \
4949
})
5050

51+
#ifdef CONFIG_KVM_GUEST
52+
#define TASK32_SIZE 0x3fff8000UL
53+
#else
5154
#define TASK32_SIZE 0x7fff8000UL
55+
#endif
5256
#undef ELF_ET_DYN_BASE
5357
#define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
5458

arch/mips/kernel/cevt-r4k.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ int c0_compare_int_usable(void)
118118
unsigned int delta;
119119
unsigned int cnt;
120120

121+
#ifdef CONFIG_KVM_GUEST
122+
return 1;
123+
#endif
124+
121125
/*
122126
* IP7 already pending? Try to clear it by acking the timer.
123127
*/

arch/mips/kernel/traps.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1713,7 +1713,12 @@ void __init trap_init(void)
17131713
ebase = (unsigned long)
17141714
__alloc_bootmem(size, 1 << fls(size), 0);
17151715
} else {
1716-
ebase = CKSEG0;
1716+
#ifdef CONFIG_KVM_GUEST
1717+
#define KVM_GUEST_KSEG0 0x40000000
1718+
ebase = KVM_GUEST_KSEG0;
1719+
#else
1720+
ebase = CKSEG0;
1721+
#endif
17171722
if (cpu_has_mips_r2)
17181723
ebase += (read_c0_ebase() & 0x3ffff000);
17191724
}

arch/mips/mti-malta/malta-time.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,21 @@ static void __init estimate_frequencies(void)
7676
unsigned int count, start;
7777
unsigned int giccount = 0, gicstart = 0;
7878

79+
#if defined (CONFIG_KVM_GUEST) && defined (CONFIG_KVM_HOST_FREQ)
80+
unsigned int prid = read_c0_prid() & 0xffff00;
81+
82+
/*
83+
* XXXKYMA: hardwire the CPU frequency to Host Freq/4
84+
*/
85+
count = (CONFIG_KVM_HOST_FREQ * 1000000) >> 3;
86+
if ((prid != (PRID_COMP_MIPS | PRID_IMP_20KC)) &&
87+
(prid != (PRID_COMP_MIPS | PRID_IMP_25KF)))
88+
count *= 2;
89+
90+
mips_hpt_frequency = count;
91+
return;
92+
#endif
93+
7994
local_irq_save(flags);
8095

8196
/* Start counter exactly on falling edge of update flag. */

0 commit comments

Comments
 (0)