x86/paravirt: allow preemption while doing lazy mmu update
Subsystems (8)
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
This series allows preemption during lazy mmu updates.
No changes from previous postings, just rebased to a newer tip/master.
The following changes since commit 8c85122f33c5242e2f384b1f9f202f28e6bf4e61:
Ingo Molnar (1):
Merge branch 'core/locking'
are available in the git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/jeremy/xen.git push2/x86/paravirt
Jeremy Fitzhardinge (8):
mm: disable preemption in apply_to_pte_range
x86/paravirt: remove lazy mode in interrupts
x86/pvops: replace arch_enter_lazy_cpu_mode with arch_start_context_switch x86/paravirt: flush pending mmu updates on context switch x86/paravirt: finish change from lazy cpu to context switch start/end x86/paravirt: allow preemption with lazy mmu mode
mm: allow preemption in apply_to_pte_range
x86/paravirt: use percpu_ rather than __get_cpu_var
arch/x86/include/asm/paravirt.h | 22 +++++++------- arch/x86/include/asm/pgtable.h | 2 + arch/x86/include/asm/thread_info.h | 2 + arch/x86/kernel/kvm.c | 2 +- arch/x86/kernel/paravirt.c | 56 ++++++++++++++++------------------- arch/x86/kernel/process_32.c | 2 +- arch/x86/kernel/process_64.c | 2 +- arch/x86/kernel/vmi_32.c | 20 ++++++++---- arch/x86/lguest/boot.c | 16 +++++++--- arch/x86/mm/fault.c | 6 +-- arch/x86/mm/highmem_32.c | 2 - arch/x86/mm/iomap_32.c | 2 - arch/x86/mm/pageattr.c | 14 --------- arch/x86/xen/enlighten.c | 10 ++---- arch/x86/xen/mmu.c | 20 +++++-------- arch/x86/xen/xen-ops.h | 1 - include/asm-frv/pgtable.h | 4 +- include/asm-generic/pgtable.h | 21 +++++++------ kernel/sched.c | 2 +- 19 files changed, 96 insertions(+), 110 deletions(-)
Overall diff:
arch/x86/include/asm/paravirt.h +0 -0
@@ -56,6 +56,7 @@ struct desc_ptr;
struct tss_struct;
struct mm_struct;
struct desc_struct;
+struct task_struct;
/*
* Wrapper type for pointers to code which uses the non-standard
@@ -203,7 +204,8 @@ struct pv_cpu_ops {
void (*swapgs)(void);
- struct pv_lazy_ops lazy_mode;
+ void (*start_context_switch)(struct task_struct *prev);
+ void (*end_context_switch)(struct task_struct *next);
};
struct pv_irq_ops {
@@ -1399,25 +1401,23 @@ enum paravirt_lazy_mode {
};
enum paravirt_lazy_mode paravirt_get_lazy_mode(void); -void paravirt_enter_lazy_cpu(void);
-void paravirt_leave_lazy_cpu(void);
+void paravirt_start_context_switch(struct task_struct *prev); +void paravirt_end_context_switch(struct task_struct *next); +
void paravirt_enter_lazy_mmu(void);
void paravirt_leave_lazy_mmu(void);
-void paravirt_leave_lazy(enum paravirt_lazy_mode mode);
-#define __HAVE_ARCH_ENTER_LAZY_CPU_MODE
-static inline void arch_enter_lazy_cpu_mode(void)
+#define __HAVE_ARCH_START_CONTEXT_SWITCH
+static inline void arch_start_context_switch(struct task_struct *prev) {
- PVOP_VCALL0(pv_cpu_ops.lazy_mode.enter);
+ PVOP_VCALL1(pv_cpu_ops.start_context_switch, prev);
}
-static inline void arch_leave_lazy_cpu_mode(void)
+static inline void arch_end_context_switch(struct task_struct *next) {
- PVOP_VCALL0(pv_cpu_ops.lazy_mode.leave);
+ PVOP_VCALL1(pv_cpu_ops.end_context_switch, next);
}
-void arch_flush_lazy_cpu_mode(void);
-
#define __HAVE_ARCH_ENTER_LAZY_MMU_MODE
static inline void arch_enter_lazy_mmu_mode(void)
{
arch/x86/include/asm/pgtable.h +0 -0
@@ -81,6 +81,8 @@ static inline void __init paravirt_pagetable_setup_done(pgd_t *base)
#define pte_val(x) native_pte_val(x)
#define __pte(x) native_make_pte(x)
+#define arch_end_context_switch(prev) do {} while(0)
+
#endif /* CONFIG_PARAVIRT */
/*
arch/x86/include/asm/thread_info.h +0 -0
@@ -96,6 +96,7 @@ struct thread_info {
#define TIF_DEBUGCTLMSR 25 /* uses thread_struct.debugctlmsr */
#define TIF_DS_AREA_MSR 26 /* uses thread_struct.ds_area_msr */
#define TIF_SYSCALL_FTRACE 27 /* for ftrace syscall instrumentation */
+#define TIF_LAZY_MMU_UPDATES 28 /* task is updating the mmu lazily */
#define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
#define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
@@ -119,6 +120,7 @@ struct thread_info {
#define _TIF_DEBUGCTLMSR (1 << TIF_DEBUGCTLMSR)
#define _TIF_DS_AREA_MSR (1 << TIF_DS_AREA_MSR)
#define _TIF_SYSCALL_FTRACE (1 << TIF_SYSCALL_FTRACE)
+#define _TIF_LAZY_MMU_UPDATES (1 << TIF_LAZY_MMU_UPDATES)
/* work to do in syscall_trace_enter() */
#define _TIF_WORK_SYSCALL_ENTRY \
arch/x86/kernel/kvm.c +0 -0
@@ -195,7 +195,7 @@ static void kvm_leave_lazy_mmu(void)
struct kvm_para_state *state = kvm_para_state(); mmu_queue_flush(state); - paravirt_leave_lazy(paravirt_get_lazy_mode()); + paravirt_leave_lazy_mmu(); state->mode = paravirt_get_lazy_mode(); }
arch/x86/kernel/paravirt.c +0 -0
@@ -246,18 +246,16 @@ static DEFINE_PER_CPU(enum paravirt_lazy_mode, paravirt_lazy_mode) = PARAVIRT_LA
static inline void enter_lazy(enum paravirt_lazy_mode mode) {
- BUG_ON(__get_cpu_var(paravirt_lazy_mode) != PARAVIRT_LAZY_NONE);
- BUG_ON(preemptible());
+ BUG_ON(percpu_read(paravirt_lazy_mode) != PARAVIRT_LAZY_NONE);
- __get_cpu_var(paravirt_lazy_mode) = mode;
+ percpu_write(paravirt_lazy_mode, mode);
}
-void paravirt_leave_lazy(enum paravirt_lazy_mode mode) +static void leave_lazy(enum paravirt_lazy_mode mode) {
- BUG_ON(__get_cpu_var(paravirt_lazy_mode) != mode);
- BUG_ON(preemptible());
+ BUG_ON(percpu_read(paravirt_lazy_mode) != mode);
- __get_cpu_var(paravirt_lazy_mode) = PARAVIRT_LAZY_NONE;
+ percpu_write(paravirt_lazy_mode, PARAVIRT_LAZY_NONE);
}
void paravirt_enter_lazy_mmu(void)
@@ -267,22 +265,36 @@ void paravirt_enter_lazy_mmu(void)
void paravirt_leave_lazy_mmu(void)
{
- paravirt_leave_lazy(PARAVIRT_LAZY_MMU);
+ leave_lazy(PARAVIRT_LAZY_MMU);
}
-void paravirt_enter_lazy_cpu(void)
+void paravirt_start_context_switch(struct task_struct *prev) {
+ BUG_ON(preemptible());
+
+ if (percpu_read(paravirt_lazy_mode) == PARAVIRT_LAZY_MMU) {
+ arch_leave_lazy_mmu_mode();
+ set_ti_thread_flag(task_thread_info(prev), TIF_LAZY_MMU_UPDATES);
+ }
enter_lazy(PARAVIRT_LAZY_CPU); }
-void paravirt_leave_lazy_cpu(void)
+void paravirt_end_context_switch(struct task_struct *next) {
- paravirt_leave_lazy(PARAVIRT_LAZY_CPU);
+ BUG_ON(preemptible());
+
+ leave_lazy(PARAVIRT_LAZY_CPU);
+
+ if (test_and_clear_ti_thread_flag(task_thread_info(next), TIF_LAZY_MMU_UPDATES))
+ arch_enter_lazy_mmu_mode();
}
enum paravirt_lazy_mode paravirt_get_lazy_mode(void) {
- return __get_cpu_var(paravirt_lazy_mode);
+ if (in_interrupt())
+ return PARAVIRT_LAZY_NONE;
+
+ return percpu_read(paravirt_lazy_mode);
}
void arch_flush_lazy_mmu_mode(void)
@@ -290,7 +302,6 @@ void arch_flush_lazy_mmu_mode(void)
preempt_disable();
if (paravirt_get_lazy_mode() == PARAVIRT_LAZY_MMU) {
- WARN_ON(preempt_count() == 1);
arch_leave_lazy_mmu_mode();
arch_enter_lazy_mmu_mode();
}
@@ -298,19 +309,6 @@ void arch_flush_lazy_mmu_mode(void)
preempt_enable();
}-void arch_flush_lazy_cpu_mode(void)
-{
- preempt_disable();
-
- if (paravirt_get_lazy_mode() == PARAVIRT_LAZY_CPU) {
- WARN_ON(preempt_count() == 1);
- arch_leave_lazy_cpu_mode();
- arch_enter_lazy_cpu_mode();
- }
-
- preempt_enable();
-}
-
struct pv_info pv_info = {
.name = "bare hardware", .paravirt_enabled = 0,
@@ -402,10 +400,8 @@ struct pv_cpu_ops pv_cpu_ops = {
.set_iopl_mask = native_set_iopl_mask, .io_delay = native_io_delay,
- .lazy_mode = {
- .enter = paravirt_nop,
- .leave = paravirt_nop,
- },
+ .start_context_switch = paravirt_nop,
+ .end_context_switch = paravirt_nop,
};
struct pv_apic_ops pv_apic_ops = {
arch/x86/kernel/process_32.c +0 -0
@@ -407,7 +407,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
* done before math_state_restore, so the TS bit is up
* to date.
*/
- arch_leave_lazy_cpu_mode();
+ arch_end_context_switch(next_p);
/* If the task has used fpu the last 5 timeslices, just do a full * restore of the math state immediately to avoid the trap; the
arch/x86/kernel/process_64.c +0 -0
@@ -428,7 +428,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
* done before math_state_restore, so the TS bit is up
* to date.
*/
- arch_leave_lazy_cpu_mode();
+ arch_end_context_switch(next_p);
/* * Switch FS and GS.
arch/x86/kernel/vmi_32.c +0 -0
@@ -462,22 +462,28 @@ vmi_startup_ipi_hook(int phys_apicid, unsigned long start_eip,
}
#endif
-static void vmi_enter_lazy_cpu(void)
+static void vmi_start_context_switch(struct task_struct *prev) {
- paravirt_enter_lazy_cpu();
+ paravirt_start_context_switch(prev); vmi_ops.set_lazy_mode(2); }
+static void vmi_end_context_switch(struct task_struct *next) +{
+ vmi_ops.set_lazy_mode(0);
+ paravirt_end_context_switch(next);
+}
+
static void vmi_enter_lazy_mmu(void)
{
paravirt_enter_lazy_mmu();
vmi_ops.set_lazy_mode(1);
}-static void vmi_leave_lazy(void)
+static void vmi_leave_lazy_mmu(void)
{
- paravirt_leave_lazy(paravirt_get_lazy_mode()); vmi_ops.set_lazy_mode(0);
+ paravirt_leave_lazy_mmu();
}
static inline int __init check_vmi_rom(struct vrom_header *rom) @@ -711,14 +717,14 @@ static inline int __init activate_vmi(void)
para_fill(pv_cpu_ops.set_iopl_mask, SetIOPLMask); para_fill(pv_cpu_ops.io_delay, IODelay);
- para_wrap(pv_cpu_ops.lazy_mode.enter, vmi_enter_lazy_cpu,
+ para_wrap(pv_cpu_ops.start_context_switch, vmi_start_context_switch,
set_lazy_mode, SetLazyMode); - para_wrap(pv_cpu_ops.lazy_mode.leave, vmi_leave_lazy, + para_wrap(pv_cpu_ops.end_context_switch, vmi_end_context_switch, set_lazy_mode, SetLazyMode); para_wrap(pv_mmu_ops.lazy_mode.enter, vmi_enter_lazy_mmu, set_lazy_mode, SetLazyMode); - para_wrap(pv_mmu_ops.lazy_mode.leave, vmi_leave_lazy, + para_wrap(pv_mmu_ops.lazy_mode.leave, vmi_leave_lazy_mmu, set_lazy_mode, SetLazyMode); /* user and kernel flush are just handled with different flags to FlushTLB */
arch/x86/lguest/boot.c +0 -0
@@ -147,10 +147,16 @@ static void lazy_hcall(unsigned long call,
/* When lazy mode is turned off reset the per-cpu lazy mode variable and then
* issue the do-nothing hypercall to flush any stored calls. */
-static void lguest_leave_lazy_mode(void)
+static void lguest_leave_lazy_mmu_mode(void)
{
- paravirt_leave_lazy(paravirt_get_lazy_mode()); hcall(LHCALL_FLUSH_ASYNC, 0, 0, 0);
+ paravirt_leave_lazy_mmu();
+}
+
+static void lguest_end_context_switch(struct task_struct *next) +{
+ hcall(LHCALL_FLUSH_ASYNC, 0, 0, 0);
+ paravirt_end_context_switch(next);
}
/*G:033
@@ -1025,8 +1031,8 @@ __init void lguest_init(void)
pv_cpu_ops.write_gdt_entry = lguest_write_gdt_entry; pv_cpu_ops.write_idt_entry = lguest_write_idt_entry; pv_cpu_ops.wbinvd = lguest_wbinvd;
- pv_cpu_ops.lazy_mode.enter = paravirt_enter_lazy_cpu;
- pv_cpu_ops.lazy_mode.leave = lguest_leave_lazy_mode;
+ pv_cpu_ops.start_context_switch = paravirt_start_context_switch;
+ pv_cpu_ops.end_context_switch = lguest_end_context_switch;
/* pagetable management */ pv_mmu_ops.write_cr3 = lguest_write_cr3; @@ -1039,7 +1045,7 @@ __init void lguest_init(void) pv_mmu_ops.read_cr2 = lguest_read_cr2; pv_mmu_ops.read_cr3 = lguest_read_cr3; pv_mmu_ops.lazy_mode.enter = paravirt_enter_lazy_mmu;
- pv_mmu_ops.lazy_mode.leave = lguest_leave_lazy_mode;
+ pv_mmu_ops.lazy_mode.leave = lguest_leave_lazy_mmu_mode;
#ifdef CONFIG_X86_LOCAL_APIC /* apic read/write intercepts */
arch/x86/mm/fault.c +0 -0
@@ -227,12 +227,10 @@ static inline pmd_t *vmalloc_sync_one(pgd_t *pgd, unsigned long address)
if (!pmd_present(*pmd_k)) return NULL;
- if (!pmd_present(*pmd)) {
+ if (!pmd_present(*pmd))
set_pmd(pmd, *pmd_k);
- arch_flush_lazy_mmu_mode();
- } else {
+ else
BUG_ON(pmd_page(*pmd) != pmd_page(*pmd_k));- }
return pmd_k; }
arch/x86/mm/highmem_32.c +0 -0
@@ -87,7 +87,6 @@ void *kmap_atomic_prot(struct page *page, enum km_type type, pgprot_t prot)
vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx); BUG_ON(!pte_none(*(kmap_pte-idx))); set_pte(kmap_pte-idx, mk_pte(page, prot));
- arch_flush_lazy_mmu_mode();
return (void *)vaddr; } @@ -117,7 +116,6 @@ void kunmap_atomic(void *kvaddr, enum km_type type) #endif }
- arch_flush_lazy_mmu_mode(); pagefault_enable(); }
arch/x86/mm/iomap_32.c +0 -0
@@ -41,7 +41,6 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, enum km_type type, pgprot_t prot)
idx = type + KM_TYPE_NR * smp_processor_id(); vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx); set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
- arch_flush_lazy_mmu_mode();
return (void *)vaddr; } @@ -80,7 +79,6 @@ iounmap_atomic(void *kvaddr, enum km_type type) if (vaddr == __fix_to_virt(FIX_KMAP_BEGIN+idx)) kpte_clear_flush(kmap_pte-idx, vaddr);
- arch_flush_lazy_mmu_mode(); pagefault_enable(); }
EXPORT_SYMBOL_GPL(iounmap_atomic);
arch/x86/mm/pageattr.c +0 -0
@@ -844,13 +844,6 @@ static int change_page_attr_set_clr(unsigned long *addr, int numpages,
vm_unmap_aliases();
- /*
- * If we're called with lazy mmu updates enabled, the
- * in-memory pte state may be stale. Flush pending updates to
- * bring them up to date.
- */
- arch_flush_lazy_mmu_mode();
-
cpa.vaddr = addr; cpa.pages = pages; cpa.numpages = numpages; @@ -895,13 +888,6 @@ static int change_page_attr_set_clr(unsigned long *addr, int numpages, } else cpa_flush_all(cache);
- /*
- * If we've been called with lazy mmu updates enabled, then
- * make sure that everything gets flushed out before we
- * return.
- */
- arch_flush_lazy_mmu_mode();
-
out:
return ret; }
arch/x86/xen/enlighten.c +0 -0
@@ -203,10 +203,10 @@ static unsigned long xen_get_debugreg(int reg)
return HYPERVISOR_get_debugreg(reg); }
-void xen_leave_lazy(void)
+static void xen_end_context_switch(struct task_struct *next) {
- paravirt_leave_lazy(paravirt_get_lazy_mode()); xen_mc_flush();
+ paravirt_end_context_switch(next);
}
static unsigned long xen_store_tr(void)
@@ -817,10 +817,8 @@ static const struct pv_cpu_ops xen_cpu_ops __initdata = {
/* Xen takes care of %gs when switching to usermode for us */
.swapgs = paravirt_nop,- .lazy_mode = {
- .enter = paravirt_enter_lazy_cpu,
- .leave = xen_leave_lazy,
- },
+ .start_context_switch = paravirt_start_context_switch,
+ .end_context_switch = xen_end_context_switch,
};
static const struct pv_apic_ops xen_apic_ops __initdata = {
arch/x86/xen/mmu.c +0 -0
@@ -419,10 +419,6 @@ void set_pte_mfn(unsigned long vaddr, unsigned long mfn, pgprot_t flags)
void xen_set_pte_at(struct mm_struct *mm, unsigned long addr,
pte_t *ptep, pte_t pteval)
{
- /* updates to init_mm may be done without lock */
- if (mm == &init_mm)
- preempt_disable();
-
ADD_STATS(set_pte_at, 1); // ADD_STATS(set_pte_at_pinned, xen_page_pinned(ptep)); ADD_STATS(set_pte_at_current, mm == current->mm); @@ -443,9 +439,7 @@ void xen_set_pte_at(struct mm_struct *mm, unsigned long addr, } xen_set_pte(ptep, pteval);
-out:
- if (mm == &init_mm)
- preempt_enable();
+out: return;
}
pte_t xen_ptep_modify_prot_start(struct mm_struct *mm, @@ -1119,10 +1113,8 @@ static void drop_other_mm_ref(void *info)
/* If this cpu still has a stale cr3 reference, then make sure
it has been flushed. */
- if (percpu_read(xen_current_cr3) == __pa(mm->pgd)) {
+ if (percpu_read(xen_current_cr3) == __pa(mm->pgd))
load_cr3(swapper_pg_dir);- arch_flush_lazy_cpu_mode();
- }
}
static void xen_drop_mm_ref(struct mm_struct *mm)
@@ -1135,7 +1127,6 @@ static void xen_drop_mm_ref(struct mm_struct *mm)
load_cr3(swapper_pg_dir); else leave_mm(smp_processor_id()); - arch_flush_lazy_cpu_mode(); } /* Get the "official" set of cpus referring to our pagetable. */ @@ -1819,6 +1810,11 @@ __init void xen_post_allocator_init(void) xen_mark_init_mm_pinned(); }
+static void xen_leave_lazy_mmu(void)
+{
+ xen_mc_flush();
+ paravirt_leave_lazy_mmu();
+}
const struct pv_mmu_ops xen_mmu_ops __initdata = {
.pagetable_setup_start = xen_pagetable_setup_start,
@@ -1893,7 +1889,7 @@ const struct pv_mmu_ops xen_mmu_ops __initdata = {
.lazy_mode = {
.enter = paravirt_enter_lazy_mmu,
- .leave = xen_leave_lazy,
+ .leave = xen_leave_lazy_mmu,
},
.set_fixmap = xen_set_fixmap,arch/x86/xen/xen-ops.h +0 -0
@@ -30,7 +30,6 @@ pgd_t *xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn);
void xen_ident_map_ISA(void);
void xen_reserve_top(void);
-void xen_leave_lazy(void);
void xen_post_allocator_init(void);
char * __init xen_memory_setup(void);
include/asm-frv/pgtable.h +0 -0
@@ -73,8 +73,8 @@ static inline int pte_file(pte_t pte) { return 0; }
#define pgtable_cache_init() do {} while (0)
#define arch_enter_lazy_mmu_mode() do {} while (0)
#define arch_leave_lazy_mmu_mode() do {} while (0)
-#define arch_enter_lazy_cpu_mode() do {} while (0)
-#define arch_leave_lazy_cpu_mode() do {} while (0)
+
+#define arch_start_context_switch(prev) do {} while (0)
#else /* !CONFIG_MMU */ /*****************************************************************************/
include/asm-generic/pgtable.h +0 -0
@@ -280,17 +280,18 @@ static inline void ptep_modify_prot_commit(struct mm_struct *mm,
#endif
/*
- * A facility to provide batching of the reload of page tables with the
- * actual context switch code for paravirtualized guests. By convention,
- * only one of the lazy modes (CPU, MMU) should be active at any given
- * time, entry should never be nested, and entry and exits should always
- * be paired. This is for sanity of maintaining and reasoning about the
- * kernel code.
+ * A facility to provide batching of the reload of page tables and
+ * other process state with the actual context switch code for
+ * paravirtualized guests. By convention, only one of the batched
+ * update (lazy) modes (CPU, MMU) should be active at any given time,
+ * entry should never be nested, and entry and exits should always be
+ * paired. This is for sanity of maintaining and reasoning about the
+ * kernel code. In this case, the exit (end of the context switch) is
+ * in architecture-specific code, and so doesn't need a generic
+ * definition.
*/
-#ifndef __HAVE_ARCH_ENTER_LAZY_CPU_MODE
-#define arch_enter_lazy_cpu_mode() do {} while (0)
-#define arch_leave_lazy_cpu_mode() do {} while (0)
-#define arch_flush_lazy_cpu_mode() do {} while (0)
+#ifndef __HAVE_ARCH_START_CONTEXT_SWITCH
+#define arch_start_context_switch(prev) do {} while (0)
#endif
#ifndef __HAVE_PFNMAP_TRACKING
kernel/sched.c +0 -0
@@ -2804,7 +2804,7 @@ context_switch(struct rq *rq, struct task_struct *prev,
* combine the page table reload and the switch backend into
* one hypercall.
*/
- arch_enter_lazy_cpu_mode();
+ arch_start_context_switch(prev);
if (unlikely(!mm)) {
next->active_mm = oldmm;[GIT PULL] core Xen updates for 2.6.30
In reply to a message not in the archiveThis series updates core domU Xen support.
Changes since last posting:
* rebased to newer tip/master
* addressed hpa's review comments
* little cleanups
Thanks,
J
The following changes since commit 8d336ed83a87149bcae6b872fff1aed8be268342:
Jeremy Fitzhardinge (1):
x86/paravirt: use percpu_ rather than __get_cpu_var
are available in the git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/jeremy/xen.git push2/xen/core
Alex Nixon (1):
Xen: Add virt_to_pfn helper function
Hannes Eder (1):
NULL noise: arch/x86/xen/smp.c
Jeremy Fitzhardinge (15):
xen: disable preempt for leave_lazy_mmu
xen: separate p2m allocation from setting
xen: dynamically allocate p2m tables
xen: split construction of p2m mfn tables from registration
xen: clean up xen_load_gdt
xen: make xen_load_gdt simpler
xen: remove xen_load_gdt debug
xen: reserve i386 Xen pagetables
xen: mask XSAVE from cpuid
xen: add FIX_TEXT_POKE to fixmap
x86-64: remove PGE from must-have feature list
x86-64: non-paravirt systems always has PSE and PGE xen/mmu: some early pagetable cleanups
Revert "x86: create a non-zero sized bm_pte only when needed" xen/mmu: weaken flush_tlb_other test
arch/x86/include/asm/required-features.h | 8 ++- arch/x86/include/asm/xen/page.h | 3 +- arch/x86/mm/ioremap.c | 19 +--- arch/x86/xen/enlighten.c | 76 +++++++++++--- arch/x86/xen/mmu.c | 160 ++++++++++++++++++++++-------- arch/x86/xen/mmu.h | 3 + arch/x86/xen/smp.c | 4 +- arch/x86/xen/xen-ops.h | 2 - 8 files changed, 196 insertions(+), 79 deletions(-)
arch/x86/include/asm/required-features.h +0 -0
@@ -48,9 +48,15 @@
#endif
#ifdef CONFIG_X86_64
+#ifdef CONFIG_PARAVIRT
+/* Paravirtualized systems may not have PSE or PGE available */
#define NEED_PSE 0
+#define NEED_PGE 0
+#else
+#define NEED_PSE (1<<(X86_FEATURE_PSE) & 31)
+#define NEED_PGE (1<<(X86_FEATURE_PGE) & 31)
+#endif
#define NEED_MSR (1<<(X86_FEATURE_MSR & 31))
-#define NEED_PGE (1<<(X86_FEATURE_PGE & 31))
#define NEED_FXSR (1<<(X86_FEATURE_FXSR & 31))
#define NEED_XMM (1<<(X86_FEATURE_XMM & 31))
#define NEED_XMM2 (1<<(X86_FEATURE_XMM2 & 31))
arch/x86/include/asm/xen/page.h +0 -0
@@ -124,7 +124,8 @@ static inline unsigned long mfn_to_local_pfn(unsigned long mfn)
/* VIRT <-> MACHINE conversion */
#define virt_to_machine(v) (phys_to_machine(XPADDR(__pa(v))))
-#define virt_to_mfn(v) (pfn_to_mfn(PFN_DOWN(__pa(v))))
+#define virt_to_pfn(v) (PFN_DOWN(__pa(v)))
+#define virt_to_mfn(v) (pfn_to_mfn(virt_to_pfn(v)))
#define mfn_to_virt(m) (__va(mfn_to_pfn(m) << PAGE_SHIFT))
static inline unsigned long pte_mfn(pte_t pte)
arch/x86/mm/ioremap.c +0 -0
@@ -487,12 +487,7 @@ static int __init early_ioremap_debug_setup(char *str)
early_param("early_ioremap_debug", early_ioremap_debug_setup);
static __initdata int after_paging_init;
-#define __FIXADDR_TOP (-PAGE_SIZE)
-static pte_t bm_pte[(__fix_to_virt(FIX_DBGP_BASE)
- ^ __fix_to_virt(FIX_BTMAP_BEGIN)) >> PMD_SHIFT
- ? PAGE_SIZE / sizeof(pte_t) : 0] __page_aligned_bss;
-#undef __FIXADDR_TOP
-static __initdata pte_t *bm_ptep;
+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
{
@@ -507,8 +502,6 @@ static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
static inline pte_t * __init early_ioremap_pte(unsigned long addr) {
- if (!sizeof(bm_pte))
- return &bm_ptep[pte_index(addr)]; return &bm_pte[pte_index(addr)]; }
@@ -526,14 +519,8 @@ void __init early_ioremap_init(void)
slot_virt[i] = fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i); pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
- if (sizeof(bm_pte)) {
- memset(bm_pte, 0, sizeof(bm_pte));
- pmd_populate_kernel(&init_mm, pmd, bm_pte);
- } else {
- bm_ptep = pte_offset_kernel(pmd, 0);
- if (early_ioremap_debug)
- printk(KERN_INFO "bm_ptep=%p\n", bm_ptep);
- }
+ memset(bm_pte, 0, sizeof(bm_pte));
+ pmd_populate_kernel(&init_mm, pmd, bm_pte);
/* * The boot-ioremap range spans multiple pmds, for which
arch/x86/xen/enlighten.c +0 -0
@@ -168,21 +168,23 @@ static void __init xen_banner(void)
xen_feature(XENFEAT_mmu_pt_update_preserve_ad) ? " (preserve-AD)" : ""); }
+static __read_mostly unsigned int cpuid_leaf1_edx_mask = ~0; +static __read_mostly unsigned int cpuid_leaf1_ecx_mask = ~0; +
static void xen_cpuid(unsigned int *ax, unsigned int *bx,
unsigned int *cx, unsigned int *dx)
{
+ unsigned maskecx = ~0; unsigned maskedx = ~0; /* * Mask out inconvenient features, to try and disable as many * unsupported kernel subsystems as possible. */ - if (*ax == 1) - maskedx = ~((1 << X86_FEATURE_APIC) | /* disable APIC */ - (1 << X86_FEATURE_ACPI) | /* disable ACPI */ - (1 << X86_FEATURE_MCE) | /* disable MCE */ - (1 << X86_FEATURE_MCA) | /* disable MCA */ - (1 << X86_FEATURE_ACC)); /* thermal monitoring */
+ if (*ax == 1) {
+ maskecx = cpuid_leaf1_ecx_mask;
+ maskedx = cpuid_leaf1_edx_mask;
+ }
asm(XEN_EMULATE_PREFIX "cpuid" : "=a" (*ax), @@ -190,9 +192,43 @@ static void xen_cpuid(unsigned int *ax, unsigned int *bx, "=c" (*cx), "=d" (*dx) : "0" (*ax), "2" (*cx)); + + *cx &= maskecx; *dx &= maskedx; }
+static __init void xen_init_cpuid_mask(void)
+{
+ unsigned int ax, bx, cx, dx;
+
+ cpuid_leaf1_edx_mask =
+ ~((1 << X86_FEATURE_MCE) | /* disable MCE */ + (1 << X86_FEATURE_MCA) | /* disable MCA */ + (1 << X86_FEATURE_ACC)); /* thermal monitoring */
+
+ if (!xen_initial_domain())
+ cpuid_leaf1_edx_mask &=
+ ~((1 << X86_FEATURE_APIC) | /* disable local APIC */
+ (1 << X86_FEATURE_ACPI)); /* disable ACPI */
+
+ ax = 1;
+ xen_cpuid(&ax, &bx, &cx, &dx);
+
+ /* cpuid claims we support xsave; try enabling it to see what happens */
+ if (cx & (1 << (X86_FEATURE_XSAVE % 32))) {
+ unsigned long cr4;
+
+ set_in_cr4(X86_CR4_OSXSAVE);
+
+ cr4 = read_cr4();
+
+ if ((cr4 & X86_CR4_OSXSAVE) == 0)
+ cpuid_leaf1_ecx_mask &= ~(1 << (X86_FEATURE_XSAVE % 32));
+
+ clear_in_cr4(X86_CR4_OSXSAVE);
+ }
+}
+
static void xen_set_debugreg(int reg, unsigned long val)
{
HYPERVISOR_set_debugreg(reg, val);@@ -284,12 +320,11 @@ static void xen_set_ldt(const void *addr, unsigned entries)
static void xen_load_gdt(const struct desc_ptr *dtr) {
- unsigned long *frames; unsigned long va = dtr->address; unsigned int size = dtr->size + 1; unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE; + unsigned long frames[pages]; int f;
- struct multicall_space mcs;
/* A GDT can be up to 64k in size, which corresponds to 8192 8-byte entries, or 16 4k pages.. */ @@ -297,19 +332,26 @@ static void xen_load_gdt(const struct desc_ptr *dtr) BUG_ON(size > 65536); BUG_ON(va & ~PAGE_MASK);
- mcs = xen_mc_entry(sizeof(*frames) * pages);
- frames = mcs.args;
-
for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {- frames[f] = arbitrary_virt_to_mfn((void *)va);
+ int level;
+ pte_t *ptep = lookup_address(va, &level);
+ unsigned long pfn, mfn;
+ void *virt;
+
+ BUG_ON(ptep == NULL);
+
+ pfn = pte_pfn(*ptep);
+ mfn = pfn_to_mfn(pfn);
+ virt = __va(PFN_PHYS(pfn));
+
+ frames[f] = mfn;
make_lowmem_page_readonly((void *)va); - make_lowmem_page_readonly(mfn_to_virt(frames[f])); + make_lowmem_page_readonly(virt); }
- MULTI_set_gdt(mcs.mc, frames, size / sizeof(struct desc_struct));
-
- xen_mc_issue(PARAVIRT_LAZY_CPU);
+ if (HYPERVISOR_set_gdt(frames, size / sizeof(struct desc_struct)))
+ BUG();
}
static void load_TLS_descriptor(struct thread_struct *t, @@ -895,6 +937,8 @@ asmlinkage void __init xen_start_kernel(void)
xen_init_irq_ops();
+ xen_init_cpuid_mask();
+
#ifdef CONFIG_X86_LOCAL_APIC /* * set up the basic apic ops.
arch/x86/xen/mmu.c +0 -0
@@ -159,18 +159,14 @@ DEFINE_PER_CPU(unsigned long, xen_current_cr3); /* actual vcpu cr3 */
#define TOP_ENTRIES (MAX_DOMAIN_PAGES / P2M_ENTRIES_PER_PAGE)
/* Placeholder for holes in the address space */
-static unsigned long p2m_missing[P2M_ENTRIES_PER_PAGE] __page_aligned_data =
- { [ 0 ... P2M_ENTRIES_PER_PAGE-1 ] = ~0UL };
+static unsigned long *p2m_missing;
/* Array of pointers to pages containing p2m entries */
-static unsigned long *p2m_top[TOP_ENTRIES] __page_aligned_data =
- { [ 0 ... TOP_ENTRIES - 1] = &p2m_missing[0] };
+static unsigned long **p2m_top;
/* Arrays of p2m arrays expressed in mfns used for save/restore */ -static unsigned long p2m_top_mfn[TOP_ENTRIES] __page_aligned_bss; -
-static unsigned long p2m_top_mfn_list[TOP_ENTRIES / P2M_ENTRIES_PER_PAGE]
- __page_aligned_bss;
+static unsigned long *p2m_top_mfn;
+static unsigned long *p2m_top_mfn_list;
static inline unsigned p2m_top_index(unsigned long pfn)
{
@@ -183,22 +179,35 @@ static inline unsigned p2m_index(unsigned long pfn)
return pfn % P2M_ENTRIES_PER_PAGE; }
+#define SIZE_TOP_MFN sizeof(*p2m_top_mfn) * TOP_ENTRIES
+#define SIZE_TOP_MFN_LIST sizeof(*p2m_top_mfn_list) * \
+ (TOP_ENTRIES / P2M_ENTRIES_PER_PAGE)
+
+RESERVE_BRK(xen_top_mfn, SIZE_TOP_MFN); +RESERVE_BRK(xen_top_mfn_list, SIZE_TOP_MFN_LIST); +
/* Build the parallel p2m_top_mfn structures */ -void xen_setup_mfn_list_list(void)
+static void __init xen_build_mfn_list_list(void)
{
unsigned pfn, idx;+ p2m_top_mfn = extend_brk(SIZE_TOP_MFN, PAGE_SIZE);
+ p2m_top_mfn_list = extend_brk(SIZE_TOP_MFN_LIST, PAGE_SIZE);
+
for (pfn = 0; pfn < MAX_DOMAIN_PAGES; pfn += P2M_ENTRIES_PER_PAGE) {
unsigned topidx = p2m_top_index(pfn);
p2m_top_mfn[topidx] = virt_to_mfn(p2m_top[topidx]);
}- for (idx = 0; idx < ARRAY_SIZE(p2m_top_mfn_list); idx++) {
+ for (idx = 0; idx < (TOP_ENTRIES / P2M_ENTRIES_PER_PAGE); idx++) {
unsigned topidx = idx * P2M_ENTRIES_PER_PAGE;
p2m_top_mfn_list[idx] = virt_to_mfn(&p2m_top_mfn[topidx]);
}+}
+void xen_setup_mfn_list_list(void)
+{
BUG_ON(HYPERVISOR_shared_info == &xen_dummy_shared_info);
HYPERVISOR_shared_info->arch.pfn_to_mfn_frame_list_list =
@@ -206,18 +215,34 @@ void xen_setup_mfn_list_list(void)
HYPERVISOR_shared_info->arch.max_pfn = xen_start_info->nr_pages;
}+#define SIZE_P2M_MISSING sizeof(*p2m_missing) * P2M_ENTRIES_PER_PAGE
+#define SIZE_P2M_TOP sizeof(*p2m_top) * TOP_ENTRIES
+RESERVE_BRK(xen_p2m_missing, SIZE_P2M_MISSING); +RESERVE_BRK(xen_p2m_top, SIZE_P2M_TOP);
+
/* Set up p2m_top to point to the domain-builder provided p2m pages */ void __init xen_build_dynamic_phys_to_machine(void)
{
unsigned long *mfn_list = (unsigned long *)xen_start_info->mfn_list;
unsigned long max_pfn = min(MAX_DOMAIN_PAGES, xen_start_info->nr_pages);
unsigned pfn;+ unsigned i;
+
+ p2m_missing = extend_brk(SIZE_P2M_MISSING, PAGE_SIZE);
+ for(i = 0; i < P2M_ENTRIES_PER_PAGE; i++)
+ p2m_missing[i] = ~0ul;
+
+ p2m_top = extend_brk(SIZE_P2M_TOP, PAGE_SIZE);
+ for(i = 0; i < TOP_ENTRIES; i++)
+ p2m_top[i] = p2m_missing;
for (pfn = 0; pfn < max_pfn; pfn += P2M_ENTRIES_PER_PAGE) {
unsigned topidx = p2m_top_index(pfn);
p2m_top[topidx] = &mfn_list[pfn];
}+
+ xen_build_mfn_list_list();
}
unsigned long get_phys_to_machine(unsigned long pfn)
@@ -233,47 +258,74 @@ unsigned long get_phys_to_machine(unsigned long pfn) }EXPORT_SYMBOL_GPL(get_phys_to_machine);
-static void alloc_p2m(unsigned long **pp, unsigned long *mfnp) +/* install a new p2m_top page */
+bool install_p2mtop_page(unsigned long pfn, unsigned long *p) {
- unsigned long *p;
+ unsigned topidx = p2m_top_index(pfn);
+ unsigned long **pfnp, *mfnp; unsigned i;
- p = (void *)__get_free_page(GFP_KERNEL | __GFP_NOFAIL);
- BUG_ON(p == NULL);
+ pfnp = &p2m_top[topidx];
+ mfnp = &p2m_top_mfn[topidx];
for (i = 0; i < P2M_ENTRIES_PER_PAGE; i++) p[i] = INVALID_P2M_ENTRY;
- if (cmpxchg(pp, p2m_missing, p) != p2m_missing)
- free_page((unsigned long)p);
- else
+ if (cmpxchg(pfnp, p2m_missing, p) == p2m_missing) {
*mfnp = virt_to_mfn(p);+ return true;
+ }
+
+ return false;
}
-void set_phys_to_machine(unsigned long pfn, unsigned long mfn) +static void alloc_p2m(unsigned long pfn)
{
- unsigned topidx, idx;
+ unsigned long *p;
- if (unlikely(xen_feature(XENFEAT_auto_translated_physmap))) {
- BUG_ON(pfn != mfn && mfn != INVALID_P2M_ENTRY);
- return;
- }
+ p = (void *)__get_free_page(GFP_KERNEL | __GFP_NOFAIL);
+ BUG_ON(p == NULL);
+
+ if (!install_p2mtop_page(pfn, p))
+ free_page((unsigned long)p);
+}
+
+/* Try to install p2m mapping; fail if intermediate bits missing */ +bool __set_phys_to_machine(unsigned long pfn, unsigned long mfn) +{
+ unsigned topidx, idx;
if (unlikely(pfn >= MAX_DOMAIN_PAGES)) {
BUG_ON(mfn != INVALID_P2M_ENTRY);
- return;
+ return true;
}
topidx = p2m_top_index(pfn);
if (p2m_top[topidx] == p2m_missing) {
- /* no need to allocate a page to store an invalid entry */
if (mfn == INVALID_P2M_ENTRY)
- return;
- alloc_p2m(&p2m_top[topidx], &p2m_top_mfn[topidx]);
+ return true;
+ return false;
}
idx = p2m_index(pfn);
p2m_top[topidx][idx] = mfn;+
+ return true;
+}
+
+void set_phys_to_machine(unsigned long pfn, unsigned long mfn) +{
+ if (unlikely(xen_feature(XENFEAT_auto_translated_physmap))) {
+ BUG_ON(pfn != mfn && mfn != INVALID_P2M_ENTRY);
+ return;
+ }
+
+ if (unlikely(!__set_phys_to_machine(pfn, mfn))) {
+ alloc_p2m(pfn);
+
+ if (!__set_phys_to_machine(pfn, mfn))
+ BUG();
+ }
}
unsigned long arbitrary_virt_to_mfn(void *vaddr)
@@ -981,7 +1033,7 @@ static __init int xen_mark_pinned(struct mm_struct *mm, struct page *page,
return 0; }
-void __init xen_mark_init_mm_pinned(void)
+static void __init xen_mark_init_mm_pinned(void)
{
xen_pgd_walk(&init_mm, xen_mark_pinned, FIXADDR_TOP);
}
@@ -1261,8 +1313,8 @@ static void xen_flush_tlb_others(const struct cpumask *cpus,
} *args;
struct multicall_space mcs;- BUG_ON(cpumask_empty(cpus));
- BUG_ON(!mm);
+ if (cpumask_empty(cpus))
+ return; /* nothing to do */
mcs = xen_mc_entry(sizeof(*args)); args = mcs.args;
@@ -1429,6 +1481,15 @@ static __init void xen_set_pte_init(pte_t *ptep, pte_t pte) }
#endif
+static void pin_pagetable_pfn(unsigned cmd, unsigned long pfn)
+{
+ struct mmuext_op op;
+ op.cmd = cmd;
+ op.arg1.mfn = pfn_to_mfn(pfn);
+ if (HYPERVISOR_mmuext_op(&op, 1, NULL, DOMID_SELF))
+ BUG();
+}
+
/* Early in boot, while setting up the initial pagetable, assume
everything is pinned. */
static __init void xen_alloc_pte_init(struct mm_struct *mm, unsigned long pfn)
@@ -1437,22 +1498,29 @@ static __init void xen_alloc_pte_init(struct mm_struct *mm, unsigned long pfn)
BUG_ON(mem_map); /* should only be used early */
#endif make_lowmem_page_readonly(__va(PFN_PHYS(pfn)));
+ pin_pagetable_pfn(MMUEXT_PIN_L1_TABLE, pfn);
+}
+
+/* Used for pmd and pud */
+static __init void xen_alloc_pmd_init(struct mm_struct *mm, unsigned long pfn) +{
+#ifdef CONFIG_FLATMEM
+ BUG_ON(mem_map); /* should only be used early */
+#endif
+ make_lowmem_page_readonly(__va(PFN_PHYS(pfn)));
}
/* Early release_pte assumes that all pts are pinned, since there's
only init_mm and anything attached to that is pinned. */
-static void xen_release_pte_init(unsigned long pfn) +static __init void xen_release_pte_init(unsigned long pfn) {
+ pin_pagetable_pfn(MMUEXT_UNPIN_TABLE, pfn); make_lowmem_page_readwrite(__va(PFN_PHYS(pfn))); }
-static void pin_pagetable_pfn(unsigned cmd, unsigned long pfn) +static __init void xen_release_pmd_init(unsigned long pfn) {
- struct mmuext_op op;
- op.cmd = cmd;
- op.arg1.mfn = pfn_to_mfn(pfn);
- if (HYPERVISOR_mmuext_op(&op, 1, NULL, DOMID_SELF))
- BUG();
+ make_lowmem_page_readwrite(__va(PFN_PHYS(pfn)));
}
/* This needs to make sure the new pte page is pinned iff its being @@ -1737,6 +1805,11 @@ __init pgd_t *xen_setup_kernel_pagetable(pgd_t *pgd,
pin_pagetable_pfn(MMUEXT_PIN_L3_TABLE, PFN_DOWN(__pa(swapper_pg_dir)));
+ reserve_early(__pa(xen_start_info->pt_base),
+ __pa(xen_start_info->pt_base +
+ xen_start_info->nr_pt_frames * PAGE_SIZE),
+ "XEN PAGETABLES");
+
return swapper_pg_dir; }
#endif /* CONFIG_X86_64 */
@@ -1764,6 +1837,9 @@ static void xen_set_fixmap(unsigned idx, unsigned long phys, pgprot_t prot) #ifdef CONFIG_X86_LOCAL_APIC
case FIX_APIC_BASE: /* maps dummy local APIC */
#endif
+ case FIX_TEXT_POKE0:
+ case FIX_TEXT_POKE1:
+ /* All local page mappings */
pte = pfn_pte(phys, prot); break;
@@ -1812,8 +1888,10 @@ __init void xen_post_allocator_init(void)
static void xen_leave_lazy_mmu(void)
{
+ preempt_disable(); xen_mc_flush(); paravirt_leave_lazy_mmu();
+ preempt_enable();
}
const struct pv_mmu_ops xen_mmu_ops __initdata = {
@@ -1839,9 +1917,9 @@ const struct pv_mmu_ops xen_mmu_ops __initdata = {
.alloc_pte = xen_alloc_pte_init,
.release_pte = xen_release_pte_init,
- .alloc_pmd = xen_alloc_pte_init,
+ .alloc_pmd = xen_alloc_pmd_init,
.alloc_pmd_clone = paravirt_nop,
- .release_pmd = xen_release_pte_init,
+ .release_pmd = xen_release_pmd_init,
#ifdef CONFIG_HIGHPTE
.kmap_atomic_pte = xen_kmap_atomic_pte,
@@ -1879,8 +1957,8 @@ const struct pv_mmu_ops xen_mmu_ops __initdata = {
.make_pud = PV_CALLEE_SAVE(xen_make_pud),
.set_pgd = xen_set_pgd_hyper,
- .alloc_pud = xen_alloc_pte_init,
- .release_pud = xen_release_pte_init,
+ .alloc_pud = xen_alloc_pmd_init,
+ .release_pud = xen_release_pmd_init,
#endif /* PAGETABLE_LEVELS == 4 */
.activate_mm = xen_activate_mm,
arch/x86/xen/mmu.h +0 -0
@@ -11,6 +11,9 @@ enum pt_level {
};
+bool __set_phys_to_machine(unsigned long pfn, unsigned long mfn); +bool install_p2mtop_page(unsigned long pfn, unsigned long *p); +
void set_pte_mfn(unsigned long vaddr, unsigned long pfn, pgprot_t flags);
arch/x86/xen/smp.c +0 -0
@@ -317,7 +317,7 @@ static int __cpuinit xen_cpu_up(unsigned int cpu)
BUG_ON(rc);
while(per_cpu(cpu_state, cpu) != CPU_ONLINE) {
- HYPERVISOR_sched_op(SCHEDOP_yield, 0);
+ HYPERVISOR_sched_op(SCHEDOP_yield, NULL);
barrier();
}@@ -422,7 +422,7 @@ static void xen_smp_send_call_function_ipi(const struct cpumask *mask)
/* Make sure other vcpus get a chance to run if they need to. */
for_each_cpu(cpu, mask) {
if (xen_vcpu_stolen(cpu)) {
- HYPERVISOR_sched_op(SCHEDOP_yield, 0);
+ HYPERVISOR_sched_op(SCHEDOP_yield, NULL);
break;
}
}arch/x86/xen/xen-ops.h +0 -0
@@ -56,8 +56,6 @@ irqreturn_t xen_debug_interrupt(int irq, void *dev_id);
bool xen_vcpu_stolen(int vcpu);
-void xen_mark_init_mm_pinned(void);
-
void xen_setup_vcpu_info_placement(void);
#ifdef CONFIG_SMP
[GIT PULL] xen domU control interfaces
In reply to a message not in the archiveThis series adds some usermode interfaces for interfacing with Xen from an unprivileged domain:
- Xen support for /sys/hypervisor
- /dev/evtchn, to allow usermode to block on and send events via event channels
- updates to xenfs (/proc/xen)
- updates to the xenbus interface
Thanks,
J
The following changes since commit 627b11ca44b334e201c35bf1a1582dc10efaf4a8:
Jeremy Fitzhardinge (1):
xen/mmu: weaken flush_tlb_other test
are available in the git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/jeremy/xen.git push2/xen/control
Ian Campbell (6):
xen: add irq_from_evtchn
xen: add /dev/xen/evtchn driver
xen: export ioctl headers to userspace
xen: drop kexec bits from /sys/hypervisor since kexec isn't implemented yet
xen: remove suspend_cancel hook
xen: use device model for suspending xenbus devices
Jeremy Fitzhardinge (9):
xen/dev-evtchn: clean up locking in evtchn
xen: add "capabilities" file
xen: add /sys/hypervisor support xen/sys/hypervisor: change writable_pt to features xen/xenbus: export xenbus_dev_changed
Merge branch 'push2/xen/xenbus' into push2/xen/control Merge branch 'push2/xen/dev-evtchn' into push2/xen/control Merge branch 'push2/xen/sys-hypervisor' into push2/xen/control Merge branch 'push2/xen/xenfs' into push2/xen/control
drivers/xen/Kconfig | 20 ++ drivers/xen/Makefile | 4 +- drivers/xen/events.c | 6 + drivers/xen/evtchn.c | 507 +++++++++++++++++++++++++++++++++++++ drivers/xen/manage.c | 9 +- drivers/xen/sys-hypervisor.c | 445 ++++++++++++++++++++++++++++++++ drivers/xen/xenbus/xenbus_probe.c | 61 +---- drivers/xen/xenbus/xenbus_xs.c | 2 + drivers/xen/xenfs/super.c | 19 ++- include/Kbuild | 1 + include/xen/Kbuild | 1 + include/xen/events.h | 3 + include/xen/evtchn.h | 88 +++++++ include/xen/interface/version.h | 3 + include/xen/xenbus.h | 3 +- 15 files changed, 1112 insertions(+), 60 deletions(-) create mode 100644 drivers/xen/evtchn.c create mode 100644 drivers/xen/sys-hypervisor.c create mode 100644 include/xen/Kbuild create mode 100644 include/xen/evtchn.h
PATCH 1/11 xen: add irq_from_evtchn
In reply to a message not in the archiveFrom: Ian Campbell <[email protected]>
Given an evtchn, return the corresponding irq.
--- drivers/xen/events.c | 6 ++++++ include/xen/events.h | 3 +++ 2 files changed, 9 insertions(+), 0 deletions(-)
drivers/xen/events.c +6 -0
@@ -151,6 +151,12 @@ static unsigned int evtchn_from_irq(unsigned irq)return info_for_irq (irq)->evtchn; } +unsigned irq_from_evtchn (unsigned int evtchn) +{ +return evtchn_to_irq[evtchn]; +} +EXPORT_SYMBOL_GPL (irq_from_evtchn); +static enum ipi_vector ipi_from_irq (unsigned irq) {struct irq_info *info =info_for_irq (irq);
include/xen/events.h +3 -0
@@ -53,4 +53,7 @@ bool xen_test_irq_pending(int irq);irq will be disabled so it won't deliver an interrupt. */ void xen_poll_irq (int irq); +/* Determine the IRQ which is bound to an event channel */ +unsigned irq_from_evtchn (unsigned int evtchn); +#endif /* _XEN_EVENTS_H */
Signature · 1 line
1.6.0.6
PATCH 2/11 xen: add /dev/xen/evtchn driver
In reply to a message not in the archiveFrom: Ian Campbell <[email protected]>
This driver is used by application which wish to receive notifications from the hypervisor or other guests via Xen's event channel mechanism. In particular it is used by the xenstore daemon in domain 0.
--- drivers/xen/Kconfig | 10 + drivers/xen/Makefile | 3 +- drivers/xen/evtchn.c | 494 ++++++++++++++++++++++++++++++++++++++++++++++++++ include/xen/evtchn.h | 88 +++++++++ 4 files changed, 594 insertions(+), 1 deletions(-) create mode 100644 drivers/xen/evtchn.c create mode 100644 include/xen/evtchn.h
drivers/xen/Kconfig +10 -0
@@ -18,6 +18,16 @@ config XEN_SCRUB_PAGES secure, but slightly less efficient. If in doubt, say yes. +config XEN_DEV_EVTCHN + tristate "Xen /dev/xen/evtchn device" + depends on XEN + default y + help + The evtchn driver allows a userspace process to triger event + channels and to receive notification of an event channel + firing. + If in doubt, say yes. + config XENFS tristate "Xen filesystem" depends on XEN
drivers/xen/Makefile +2 -1
@@ -4,4 +4,5 @@ obj-y += xenbus/ obj-$(CONFIG_HOTPLUG_CPU) += cpu_hotplug.o obj-$(CONFIG_XEN_XENCOMM) += xencomm.o obj-$(CONFIG_XEN_BALLOON) += balloon.o -obj-$(CONFIG_XENFS) += xenfs/ +obj-$(CONFIG_XEN_DEV_EVTCHN) += evtchn.o +obj-$(CONFIG_XENFS) += xenfs/
drivers/xen/evtchn.c new file +494 -0
494 lines not on this page · raw message
include/xen/evtchn.h new file +88 -0
88 lines not on this page · raw message
Signature · 1 line
1.6.0.6
PATCH 3/11 xen: export ioctl headers to userspace
In reply to a message not in the archiveFrom: Ian Campbell <[email protected]>
--- include/Kbuild | 1 + include/xen/Kbuild | 1 + 2 files changed, 2 insertions(+), 0 deletions(-) create mode 100644 include/xen/Kbuild
include/Kbuild +1 -0
@@ -8,3 +8,4 @@ header-y += mtd/ header-y += rdma/ header-y += video/ header-y += drm/ +header-y += xen/
include/xen/Kbuild new file +1 -0
@@ -0,0 +1 @@ +header-y += evtchn.h
Signature · 1 line
1.6.0.6
PATCH 4/11 xen/dev-evtchn: clean up locking in evtchn
In reply to a message not in the archiveFrom: Jeremy Fitzhardinge <[email protected]>
Define a new per_user_data mutex to serialize bind/unbind operations to prevent them from racing with each other. Fix error returns and don't do a bind while holding a spinlock.
--- drivers/xen/evtchn.c | 37 +++++++++++++++++++++++++------------ 1 files changed, 25 insertions(+), 12 deletions(-)
drivers/xen/evtchn.c +25 -12
@@ -54,6 +54,8 @@#include <asm/xen/hypervisor.h> struct per_user_data { +struct mutex bind_mutex;/* serialize bind/unbind operations */ +/* Notification ring, accessed via /dev/xen/evtchn. */ #define EVTCHN_RING_SIZE (PAGE_SIZE / sizeof(evtchn_port_t))#define EVTCHN_RING_MASK (_i) ((_i)&(EVTCHN_RING_SIZE-1))
@@ -69,7 +71,7 @@ struct per_user_data {/* Who's bound to each port? */ static struct per_user_data *port_user[NR_EVENT_CHANNELS ]; -static DEFINE_SPINLOCK (port_user_lock); +static DEFINE_SPINLOCK (port_user_lock);/* protects port_user[] and ring_prod */ irqreturn_t evtchn_interrupt (int irq,void *data) {
@@ -210,22 +212,24 @@ static ssize_t evtchn_write(struct file *file, const char __user *buf,static int evtchn_bind_to_user (struct per_user_data *u,int port) { -int irq;int rc =0 ; -spin_lock_irq (&port_user_lock); - +/* +* Ports are never reused, so every caller should pass in a +* unique port. +* +* (Locking not necessary because we haven't registered the +* interrupt handler yet, and our caller has already +* serialized bind operations.) +*/ BUG_ON (port_user[port] !=NULL ); - - irq =bind_evtchn_to_irqhandler (port, evtchn_interrupt,IRQF_DISABLED , - u->name, (void *)(unsigned long )port); -if (rc <0 ) - goto fail; - port_user[port] = u; -fail: -spin_unlock_irq (&port_user_lock); + rc =bind_evtchn_to_irqhandler (port, evtchn_interrupt,IRQF_DISABLED , + u->name, (void *)(unsigned long )port); +if (rc >=0 ) + rc =0 ; +return rc; }
@@ -234,6 +238,10 @@ static void evtchn_unbind_from_user(struct per_user_data *u, int port)int irq =irq_from_evtchn (port);unbind_from_irqhandler (irq, (void *)(unsigned long )port); + +/* make sure we unbind the irq handler before clearing the port */ +barrier (); + port_user[port] =NULL ; }
@@ -244,6 +252,9 @@ static long evtchn_ioctl(struct file *file,struct per_user_data *u = file->private_data;void __user *uarg = (void __user *) arg; +/* Prevent bind from racing with unbind */ +mutex_lock (&u->bind_mutex); +switch (cmd) {case IOCTL_EVTCHN_BIND_VIRQ : {struct ioctl_evtchn_bind_virq bind;
@@ -368,6 +379,7 @@ static long evtchn_ioctl(struct file *file, rc = -ENOSYS ;break ; } +mutex_unlock (&u->bind_mutex);return rc; }
@@ -414,6 +426,7 @@ static int evtchn_open(struct inode *inode, struct file *filp)return -ENOMEM ; } +mutex_init (&u->bind_mutex);mutex_init (&u->ring_cons_mutex); filp->private_data = u;
Signature · 1 line
1.6.0.6
PATCH 5/11 xen: add "capabilities" file
In reply to a message not in the archiveThe xenfs capabilities file allows usermode to determine what capabilities the domain has. The only one at present is "control_d" in a privileged domain.
--- drivers/xen/xenfs/super.c | 19 ++++++++++++++++++- 1 files changed, 18 insertions(+), 1 deletions(-)
drivers/xen/xenfs/super.c +18 -1
@@ -20,10 +20,27 @@MODULE_DESCRIPTION ("Xen filesystem" );MODULE_LICENSE ("GPL" ); +static ssize_t capabilities_read (struct file *file,char __user *buf, +size_t size,loff_t *off) +{ +char *tmp ="" ; + +if (xen_initial_domain ()) + tmp ="control_d\n" ; + +return simple_read_from_buffer (buf, size, off, tmp,strlen (tmp)); +} + +static const struct file_operations capabilities_file_ops = { + .read = capabilities_read, +}; +static int xenfs_fill_super (struct super_block *sb,void *data,int silent) {static struct tree_descr xenfs_files[] = { - [2 ] = {"xenbus" , &xenbus_file_ops,S_IRUSR |S_IWUSR }, + [1 ] = {}, + {"xenbus" , &xenbus_file_ops,S_IRUSR |S_IWUSR }, + {"capabilities" , &capabilities_file_ops,S_IRUGO }, {"" }, };
Signature · 1 line
1.6.0.6
PATCH 6/11 xen: add /sys/hypervisor support
In reply to a message not in the archiveFrom: Jeremy Fitzhardinge <[email protected]>
Adds support for Xen info under /sys/hypervisor. Taken from Novell 2.6.27 backport tree.
--- drivers/xen/Kconfig | 10 + drivers/xen/Makefile | 3 +- drivers/xen/sys-hypervisor.c | 475 +++++++++++++++++++++++++++++++++++++++ include/xen/interface/version.h | 3 + 4 files changed, 490 insertions(+), 1 deletions(-) create mode 100644 drivers/xen/sys-hypervisor.c
drivers/xen/Kconfig +10 -0
@@ -41,3 +41,13 @@ config XEN_COMPAT_XENFS a xen platform. If in doubt, say yes. +config XEN_SYS_HYPERVISOR + bool "Create xen entries under /sys/hypervisor" + depends on XEN && SYSFS + select SYS_HYPERVISOR + default y + help + Create entries under /sys/hypervisor describing the Xen + hypervisor environment. When running native or in another + virtual environment, /sys/hypervisor will still be present, + but will have no xen contents.
drivers/xen/Makefile +2 -1
@@ -4,4 +4,5 @@ obj-y += xenbus/ obj-$(CONFIG_HOTPLUG_CPU) += cpu_hotplug.o obj-$(CONFIG_XEN_XENCOMM) += xencomm.o obj-$(CONFIG_XEN_BALLOON) += balloon.o -obj-$(CONFIG_XENFS) += xenfs/ +obj-$(CONFIG_XENFS) += xenfs/ +obj-$(CONFIG_XEN_SYS_HYPERVISOR) += sys-hypervisor.o
drivers/xen/sys-hypervisor.c new file +475 -0
475 lines not on this page · raw message
include/xen/interface/version.h +3 -0
@@ -57,4 +57,7 @@ struct xen_feature_info {/* Declares the features reported by XENVER_get_features. */ #include "features.h" +/* arg == NULL; returns host memory page size. */ +#define XENVER_pagesize 7 +#endif /* __XEN_PUBLIC_VERSION_H__ */
Signature · 1 line
1.6.0.6
PATCH 7/11 xen/sys/hypervisor: change writable_pt to features
In reply to a message not in the archiveFrom: Jeremy Fitzhardinge <[email protected]>
/sys/hypervisor/properties/writable_pt was misnamed. Rename to features, expressed as a bit array in hex.
--- drivers/xen/sys-hypervisor.c | 41 ++++++++++++++++++++++++++--------------- 1 files changed, 26 insertions(+), 15 deletions(-)
drivers/xen/sys-hypervisor.c +26 -15
@@ -293,37 +293,48 @@ static ssize_t pagesize_show(struct hyp_sysfs_attr *attr, char *buffer)HYPERVISOR_ATTR_RO (pagesize); -/* eventually there will be several more features to export */ static ssize_t xen_feature_show (int index,char *buffer) { -int ret = -ENOMEM ; -struct xen_feature_info *info; +ssize_t ret; +struct xen_feature_info info; - info =kmalloc (sizeof (struct xen_feature_info ),GFP_KERNEL ); -if (info) { - info->submap_idx = index; - ret =HYPERVISOR_xen_version (XENVER_get_features, info); -if (!ret) - ret =sprintf (buffer,"%d\n" , info->submap); -kfree (info); - } + info.submap_idx = index; + ret =HYPERVISOR_xen_version (XENVER_get_features, &info); +if (!ret) + ret =sprintf (buffer,"%08x" , info.submap);return ret; } -static ssize_t writable_pt_show (struct hyp_sysfs_attr *attr,char *buffer) +static ssize_t features_show (struct hyp_sysfs_attr *attr,char *buffer) { -return xen_feature_show (XENFEAT_writable_page_tables, buffer); +ssize_t len; +int i; + + len =0 ; +for (i =XENFEAT_NR_SUBMAPS -1 ; i >=0 ; i--) { +int ret =xen_feature_show (i, buffer + len); +if (ret <0 ) { +if (len ==0 ) + len = ret; +break ; + } + len += ret; + } +if (len >0 ) + buffer[len++] ='\n' ; + +return len; } -HYPERVISOR_ATTR_RO (writable_pt); +HYPERVISOR_ATTR_RO (features);static struct attribute *xen_properties_attrs[] = { &capabilities_attr.attr, &changeset_attr.attr, &virtual_start_attr.attr, &pagesize_attr.attr, - &writable_pt_attr.attr, + &features_attr.attr,NULL };
Signature · 1 line
1.6.0.6
PATCH 8/11 xen: drop kexec bits from /sys/hypervisor since kexec isn't implemented yet
In reply to a message not in the archiveFrom: Ian Campbell <[email protected]>
I needed this to compile since there is no kexec yet in pvops kernel
CC drivers/xen/sys-hypervisor.odrivers/xen/sys-hypervisor.c: In function 'hyper_sysfs_init':drivers/xen/sys-hypervisor.c:405: error: 'vmcoreinfo_size_xen' undeclared (first use in this function) drivers/xen/sys-hypervisor.c:405: error: (Each undeclared identifier is reported only once drivers/xen/sys-hypervisor.c:405: error: for each function it appears in.) drivers/xen/sys-hypervisor.c:406: error: implicit declaration of function 'xen_sysfs_vmcoreinfo_init' drivers/xen/sys-hypervisor.c: In function 'hyper_sysfs_exit':drivers/xen/sys-hypervisor.c:433: error: 'vmcoreinfo_size_xen' undeclared (first use in this function) drivers/xen/sys-hypervisor.c:434: error: implicit declaration of function 'xen_sysfs_vmcoreinfo_destroy'
--- drivers/xen/sys-hypervisor.c | 41 ----------------------------------------- 1 files changed, 0 insertions(+), 41 deletions(-)
drivers/xen/sys-hypervisor.c +0 -41
@@ -353,32 +353,6 @@ static void xen_properties_destroy(void)sysfs_remove_group (hypervisor_kobj, &xen_properties_group); } -#ifdef CONFIG_KEXEC - -extern size_t vmcoreinfo_size_xen; -extern unsigned long paddr_vmcoreinfo_xen; - -static ssize_t vmcoreinfo_show (struct hyp_sysfs_attr *attr,char *page) -{ -return sprintf (page,"%lx %zx\n" , - paddr_vmcoreinfo_xen, vmcoreinfo_size_xen); -} - -HYPERVISOR_ATTR_RO (vmcoreinfo); - -static int __init xen_sysfs_vmcoreinfo_init (void ) -{ -return sysfs_create_file (hypervisor_kobj, - &vmcoreinfo_attr.attr); -} - -static void xen_sysfs_vmcoreinfo_destroy (void ) -{ -sysfs_remove_file (hypervisor_kobj, &vmcoreinfo_attr.attr); -} - -#endif -static int __init hyper_sysfs_init (void ) {int ret;
@@ -401,20 +375,9 @@ static int __init hyper_sysfs_init(void) ret =xen_properties_init ();if (ret) goto prop_out; -#ifdef CONFIG_KEXEC -if (vmcoreinfo_size_xen !=0 ) { - ret =xen_sysfs_vmcoreinfo_init (); -if (ret) - goto vmcoreinfo_out; - } -#endif goto out; -#ifdef CONFIG_KEXEC -vmcoreinfo_out: -#endif -xen_properties_destroy (); prop_out:xen_sysfs_uuid_destroy (); uuid_out:
@@ -429,10 +392,6 @@ out: static void __exit hyper_sysfs_exit(void) { -#ifdef CONFIG_KEXEC -if (vmcoreinfo_size_xen !=0 ) -xen_sysfs_vmcoreinfo_destroy (); -#endif xen_properties_destroy ();xen_compilation_destroy ();xen_sysfs_uuid_destroy ();
Signature · 1 line
1.6.0.6
PATCH 9/11 xen: remove suspend_cancel hook
In reply to a message not in the archiveFrom: Ian Campbell <[email protected]>
Remove suspend_cancel hook from xenbus_driver, in preparation for using the device model for suspending.
--- drivers/xen/xenbus/xenbus_probe.c | 23 ----------------------- include/xen/xenbus.h | 1 - 2 files changed, 0 insertions(+), 24 deletions(-)
drivers/xen/xenbus/xenbus_probe.c +0 -23
@@ -689,27 +689,6 @@ static int suspend_dev(struct device *dev, void *data)return 0 ; } -static int suspend_cancel_dev (struct device *dev,void *data) -{ -int err =0 ; -struct xenbus_driver *drv; -struct xenbus_device *xdev; - -DPRINTK ("" ); - -if (dev->driver ==NULL ) -return 0 ; - drv =to_xenbus_driver (dev->driver); - xdev = container_of(dev, struct xenbus_device, dev); -if (drv->suspend_cancel) - err = drv->suspend_cancel (xdev); -if (err) -printk (KERN_WARNING -"xenbus: suspend_cancel %s failed: %i\n" , -dev_name (dev), err); -return 0 ; -} -static int resume_dev (struct device *dev,void *data) {int err;
@@ -777,8 +756,6 @@ EXPORT_SYMBOL_GPL(xenbus_resume);void xenbus_suspend_cancel (void ) {xs_suspend_cancel (); -bus_for_each_dev (&xenbus_frontend.bus,NULL ,NULL , suspend_cancel_dev); -xenbus_backend_resume (suspend_cancel_dev); }EXPORT_SYMBOL_GPL (xenbus_suspend_cancel);
include/xen/xenbus.h +0 -1
@@ -92,7 +92,6 @@ struct xenbus_driver { enum xenbus_state backend_state);int (*remove)(struct xenbus_device *dev);int (*suspend)(struct xenbus_device *dev); -int (*suspend_cancel)(struct xenbus_device *dev);int (*resume)(struct xenbus_device *dev);int (*uevent)(struct xenbus_device *,char **,int ,char *,int );struct device_driver driver;
Signature · 1 line
1.6.0.6
PATCH 10/11 xen: use device model for suspending xenbus devices
In reply to a message not in the archiveFrom: Ian Campbell <[email protected]>
--- drivers/xen/manage.c | 9 ++++----- drivers/xen/xenbus/xenbus_probe.c | 37 +++++++++---------------------------- drivers/xen/xenbus/xenbus_xs.c | 2 ++ include/xen/xenbus.h | 2 +- 4 files changed, 16 insertions(+), 34 deletions(-)
drivers/xen/manage.c +4 -5
@@ -104,9 +104,8 @@ static void do_suspend(void) goto out; } -printk ("suspending xenbus...\n" ); -/* XXX use normal device tree? */ -xenbus_suspend (); +printk (KERN_DEBUG "suspending xenstore...\n" ); +xs_suspend (); err =stop_machine (xen_suspend, &cancelled,cpumask_of (0 ));if (err) {
@@ -116,9 +115,9 @@ static void do_suspend(void)if (!cancelled) {xen_arch_resume (); -xenbus_resume (); +xs_resume (); }else -xenbus_suspend_cancel (); +xs_suspend_cancel ();device_resume (PMSG_RESUME );
drivers/xen/xenbus/xenbus_probe.c +9 -28
@@ -71,6 +71,9 @@ static int xenbus_probe_frontend(const char *type, const char *name);static void xenbus_dev_shutdown (struct device *_dev); +static int xenbus_dev_suspend (struct device *dev,pm_message_t state); +static int xenbus_dev_resume (struct device *dev); +/* If something in array of ids matches this device, return it. */ static const struct xenbus_device_id *match_device (const struct xenbus_device_id *arr,struct xenbus_device *dev)
@@ -188,6 +191,9 @@ static struct xen_bus_type xenbus_frontend = { .remove = xenbus_dev_remove, .shutdown = xenbus_dev_shutdown, .dev_attrs = xenbus_dev_attrs, + + .suspend = xenbus_dev_suspend, + .resume = xenbus_dev_resume, }, };
@@ -669,7 +675,7 @@ static struct xenbus_watch fe_watch = { .callback = frontend_changed, }; -static int suspend_dev (struct device *dev,void *data) +static int xenbus_dev_suspend (struct device *dev,pm_message_t state) {int err =0 ;struct xenbus_driver *drv;
@@ -682,14 +688,14 @@ static int suspend_dev(struct device *dev, void *data) drv =to_xenbus_driver (dev->driver); xdev = container_of(dev, struct xenbus_device, dev);if (drv->suspend) - err = drv->suspend (xdev); + err = drv->suspend (xdev, state);if (err)printk (KERN_WARNING "xenbus: suspend %s failed: %i\n" ,dev_name (dev), err);return 0 ; } -static int resume_dev (struct device *dev,void *data) +static int xenbus_dev_resume (struct device *dev) {int err;struct xenbus_driver *drv;
@@ -734,31 +740,6 @@ static int resume_dev(struct device *dev, void *data)return 0 ; } -void xenbus_suspend (void ) -{ -DPRINTK ("" ); - -bus_for_each_dev (&xenbus_frontend.bus,NULL ,NULL , suspend_dev); -xenbus_backend_suspend (suspend_dev); -xs_suspend (); -} -EXPORT_SYMBOL_GPL (xenbus_suspend); - -void xenbus_resume (void ) -{ -xb_init_comms (); -xs_resume (); -bus_for_each_dev (&xenbus_frontend.bus,NULL ,NULL , resume_dev); -xenbus_backend_resume (resume_dev); -} -EXPORT_SYMBOL_GPL (xenbus_resume); - -void xenbus_suspend_cancel (void ) -{ -xs_suspend_cancel (); -} -EXPORT_SYMBOL_GPL (xenbus_suspend_cancel); -/* A flag to determine if xenstored is 'ready' (i.e. has started) */ int xenstored_ready =0 ;
drivers/xen/xenbus/xenbus_xs.c +2 -0
@@ -673,6 +673,8 @@ void xs_resume(void)struct xenbus_watch *watch;char token[sizeof (watch) *2 +1 ]; +xb_init_comms (); +mutex_unlock (&xs_state.response_mutex);mutex_unlock (&xs_state.request_mutex);up_write (&xs_state.transaction_mutex);
include/xen/xenbus.h +1 -1
@@ -91,7 +91,7 @@ struct xenbus_driver {void (*otherend_changed)(struct xenbus_device *dev,enum xenbus_state backend_state);int (*remove)(struct xenbus_device *dev); -int (*suspend)(struct xenbus_device *dev); +int (*suspend)(struct xenbus_device *dev,pm_message_t state);int (*resume)(struct xenbus_device *dev);int (*uevent)(struct xenbus_device *,char **,int ,char *,int );struct device_driver driver;
Signature · 1 line
1.6.0.6
PATCH 11/11 xen/xenbus: export xenbus_dev_changed
In reply to a message not in the archive--- drivers/xen/xenbus/xenbus_probe.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
drivers/xen/xenbus/xenbus_probe.c +1 -0
@@ -660,6 +660,7 @@ void xenbus_dev_changed(const char *node, struct xen_bus_type *bus)kfree (root); } +EXPORT_SYMBOL_GPL (xenbus_dev_changed);static void frontend_changed (struct xenbus_watch *watch,const char **vec,unsigned int len)
Signature · 1 line
1.6.0.6
[GIT PULL] xen/dom0: core dom0 support
In reply to a message not in the archiveThis series adds core dom0 support for Xen, allowing the kernel to boot as Xen's control domain. It isn't much use on its own (it doesn't result in a booting dom0 kernel), but it lays the foundations for later changes. Native booting is unaffected.
This is largely unchanged from the last posting, other than being rebased to a newer version of tip/master (or, more precisely, the other Xen topic branches which themselves have been rebased).
Thanks,
J
The following changes since commit 627b11ca44b334e201c35bf1a1582dc10efaf4a8:
Jeremy Fitzhardinge (1):
xen/mmu: weaken flush_tlb_other test
are available in the git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/jeremy/xen.git push2/xen/dom0/core
Christophe Saout (1):
paravirtualize IO permission bitmap
Ian Campbell (4):
xen: disable PAT
xen/dom0: Use host E820 map
xen: implement XENMEM_machphys_mapping
xen: clear reserved bits in l3 entries given in the initial pagetables
Jeremy Fitzhardinge (6):
xen dom0: Make hvc_xen console work for dom0. xen/dom0: use _PAGE_IOMAP in ioremap to do machine mappings
xen: allow enable use of VGA console on dom0 xen/dom0: add XEN_DOM0 config option
x86: make /dev/mem mappings _PAGE_IOMAP
x86: don't need "changed" parameter for set_io_bitmap()
Juan Quintela (2):
xen dom0: Initialize xenbus for dom0. xen dom0: Set up basic IO permissions for dom0.
Stephen Tweedie (2):
xen dom0: Add support for the platform_ops hypercall xen mtrr: Add mtrr_ops support for Xen mtrr
arch/x86/include/asm/paravirt.h | 9 ++ arch/x86/include/asm/pat.h | 5 + arch/x86/include/asm/processor.h | 4 + arch/x86/include/asm/xen/hypercall.h | 8 + arch/x86/include/asm/xen/interface.h | 6 +- arch/x86/include/asm/xen/interface_32.h | 5 + arch/x86/include/asm/xen/interface_64.h | 13 +-- arch/x86/include/asm/xen/page.h | 15 +-- arch/x86/kernel/cpu/mtrr/Makefile | 1 + arch/x86/kernel/cpu/mtrr/amd.c | 1 + arch/x86/kernel/cpu/mtrr/centaur.c | 1 + arch/x86/kernel/cpu/mtrr/cyrix.c | 1 + arch/x86/kernel/cpu/mtrr/generic.c | 1 + arch/x86/kernel/cpu/mtrr/main.c | 11 +- arch/x86/kernel/cpu/mtrr/mtrr.h | 5 + arch/x86/kernel/cpu/mtrr/xen.c | 59 ++++++++ arch/x86/kernel/ioport.c | 29 +++- arch/x86/kernel/paravirt.c | 1 + arch/x86/kernel/process.c | 27 +--- arch/x86/mm/pat.c | 7 +- arch/x86/xen/Kconfig | 26 ++++ arch/x86/xen/Makefile | 3 +- arch/x86/xen/enlighten.c | 51 ++++++- arch/x86/xen/mmu.c | 123 ++++++++++++++++- arch/x86/xen/setup.c | 51 ++++++- arch/x86/xen/vga.c | 67 +++++++++ arch/x86/xen/xen-ops.h | 12 ++ drivers/char/hvc_xen.c | 101 +++++++++----- drivers/xen/events.c | 2 +- drivers/xen/xenbus/xenbus_probe.c | 30 ++++- include/xen/events.h | 2 + include/xen/interface/memory.h | 42 ++++++ include/xen/interface/platform.h | 232 +++++++++++++++++++++++++++++++ include/xen/interface/xen.h | 41 ++++++ 34 files changed, 885 insertions(+), 107 deletions(-) create mode 100644 arch/x86/kernel/cpu/mtrr/xen.c create mode 100644 arch/x86/xen/vga.c create mode 100644 include/xen/interface/platform.h
PATCH 1/15 xen dom0: Make hvc_xen console work for dom0.
In reply to a message not in the archiveImpact: Add Xen dom0 console
Use the console hypercalls for dom0 console.
--- drivers/char/hvc_xen.c | 101 ++++++++++++++++++++++++++++++++---------------- drivers/xen/events.c | 2 +- include/xen/events.h | 2 + 3 files changed, 70 insertions(+), 35 deletions(-)
drivers/char/hvc_xen.c +67 -34
@@ -55,7 +55,7 @@ static inline void notify_daemon(void)notify_remote_via_evtchn (xen_start_info->console.domU.evtchn); } -static int write_console (uint32_t vtermno,const char *data,int len) +static int domU_write_console (uint32_t vtermno,const char *data,int len) {struct xencons_interface *intf =xencons_interface ();XENCONS_RING_IDX cons, prod;
@@ -76,7 +76,7 @@ static int write_console(uint32_t vtermno, const char *data, int len)return sent; } -static int read_console (uint32_t vtermno,char *buf,int len) +static int domU_read_console (uint32_t vtermno,char *buf,int len) {struct xencons_interface *intf =xencons_interface ();XENCONS_RING_IDX cons, prod;
@@ -97,28 +97,63 @@ static int read_console(uint32_t vtermno, char *buf, int len)return recv; } -static struct hv_ops hvc_ops = { - .get_chars = read_console, - .put_chars = write_console, +static struct hv_ops domU_hvc_ops = { + .get_chars = domU_read_console, + .put_chars = domU_write_console, .notifier_add = notifier_add_irq, .notifier_del = notifier_del_irq, .notifier_hangup = notifier_hangup_irq, }; -static int __init xen_init (void ) +static int dom0_read_console (uint32_t vtermno,char *buf,int len) +{ +return HYPERVISOR_console_io (CONSOLEIO_read, len, buf); +} + +/* +* Either for a dom0 to write to the system console, or a domU with a +* debug version of Xen +*/ +static int dom0_write_console (uint32_t vtermno,const char *str,int len) +{ +int rc =HYPERVISOR_console_io (CONSOLEIO_write, len, (char *)str); +if (rc <0 ) +return 0 ; + +return len; +} + +static struct hv_ops dom0_hvc_ops = { + .get_chars = dom0_read_console, + .put_chars = dom0_write_console, + .notifier_add = notifier_add_irq, + .notifier_del = notifier_del_irq, + .notifier_hangup = notifier_hangup_irq, +}; + +static int __init xen_hvc_init (void ) {struct hvc_struct *hp; +struct hv_ops *ops; -if (!xen_pv_domain () || -xen_initial_domain () || - !xen_start_info->console.domU.evtchn) -return -ENODEV ; +if (!xen_pv_domain ()) +return -ENODEV ; + +if (xen_initial_domain ()) { + ops = &dom0_hvc_ops; + xencons_irq =bind_virq_to_irq (VIRQ_CONSOLE ,0 ); + }else { +if (!xen_start_info->console.domU.evtchn) +return -ENODEV ; + + ops = &domU_hvc_ops; + xencons_irq =bind_evtchn_to_irq (xen_start_info->console.domU.evtchn); + } - xencons_irq =bind_evtchn_to_irq (xen_start_info->console.domU.evtchn);if (xencons_irq <0 ) xencons_irq =0 ;/* NO_IRQ */ - hp =hvc_alloc (HVC_COOKIE , xencons_irq, &hvc_ops,256 ); + hp =hvc_alloc (HVC_COOKIE , xencons_irq, ops,256 );if (IS_ERR (hp))return PTR_ERR (hp);
@@ -135,7 +170,7 @@ void xen_console_resume(void)rebind_evtchn_irq (xen_start_info->console.domU.evtchn, xencons_irq); } -static void __exit xen_fini(void) +static void __exit xen_hvc_fini(void) {if (hvc)hvc_remove (hvc);
@@ -143,29 +178,24 @@ static void __exit xen_fini(void)static int xen_cons_init (void ) { +struct hv_ops *ops; +if (!xen_pv_domain ())return 0 ; -hvc_instantiate (HVC_COOKIE ,0 , &hvc_ops); + ops = &domU_hvc_ops; +if (xen_initial_domain ()) + ops = &dom0_hvc_ops; + +hvc_instantiate (HVC_COOKIE ,0 , ops); +return 0 ; } -module_init (xen_init); -module_exit (xen_fini); +module_init (xen_hvc_init); +module_exit (xen_hvc_fini);console_initcall (xen_cons_init); -static void raw_console_write (const char *str,int len) -{ -while (len >0 ) { -int rc =HYPERVISOR_console_io (CONSOLEIO_write, len, (char *)str); -if (rc <=0 ) -break ; - - str += rc; - len -= rc; - } -} -#ifdef CONFIG_EARLY_PRINTK static void xenboot_write_console (struct console *console,const char *string,unsigned len)
@@ -173,19 +203,22 @@ static void xenboot_write_console(struct console *console, const char *string,unsigned int linelen, off =0 ;const char *pos; -raw_console_write (string, len); +dom0_write_console (0 , string, len); + +if (xen_initial_domain ()) +return ; -write_console (0 ,"(early) " ,8 ); +domU_write_console (0 ,"(early) " ,8 );while (off < len &&NULL != (pos =strchr (string+off,'\n' ))) { linelen = pos-string+off;if (off + linelen > len)break ; -write_console (0 , string+off, linelen); -write_console (0 ,"\r\n" ,2 ); +domU_write_console (0 , string+off, linelen); +domU_write_console (0 ,"\r\n" ,2 ); off += linelen +1 ; }if (off < len) -write_console (0 , string+off, len-off); +domU_write_console (0 , string+off, len-off); }struct console xenboot_console = {
@@ -197,7 +230,7 @@ struct console xenboot_console = {void xen_raw_console_write (const char *str) { -raw_console_write (str,strlen (str)); +dom0_write_console (0 , str,strlen (str)); }void xen_raw_printk (const char *fmt, ...)
drivers/xen/events.c +1 -1
@@ -404,7 +404,7 @@ static int bind_ipi_to_irq(unsigned int ipi, unsigned int cpu) } -static int bind_virq_to_irq (unsigned int virq,unsigned int cpu) +int bind_virq_to_irq (unsigned int virq,unsigned int cpu) {struct evtchn_bind_virq bind_virq;int evtchn, irq;
include/xen/events.h +2 -0
@@ -12,6 +12,8 @@ int bind_evtchn_to_irqhandler(unsigned int evtchn,irq_handler_t handler, unsigned long irqflags, const char *devname, void *dev_id); +int bind_virq_to_irq (unsigned int virq,unsigned int cpu); + int bind_virq_to_irqhandler(unsigned int virq, unsigned int cpu, irq_handler_t handler, unsigned long irqflags, const char *devname,
Signature · 1 line
1.6.0.6
PATCH 2/15 xen dom0: Initialize xenbus for dom0.
In reply to a message not in the archiveFrom: Juan Quintela <[email protected]>
Impact: initialize Xenbus
Do initial xenbus/xenstore setup in dom0. In dom0 we need to actually allocate the xenstore resources, rather than being given them from outside.
--- drivers/xen/xenbus/xenbus_probe.c | 30 +++++++++++++++++++++++++++++- 1 files changed, 29 insertions(+), 1 deletions(-)
drivers/xen/xenbus/xenbus_probe.c +29 -1
@@ -821,6 +821,7 @@ void xenbus_probe(struct work_struct *unused)static int __init xenbus_probe_init (void ) {int err =0 ; +unsigned long page =0 ;DPRINTK ("" );
@@ -841,7 +842,31 @@ static int __init xenbus_probe_init(void)* Domain0 doesn't have a store_evtchn or store_mfn yet. */ if (xen_initial_domain ()) { -/* dom0 not yet supported */ +struct evtchn_alloc_unbound alloc_unbound; + +/* Allocate Xenstore page */ + page =get_zeroed_page (GFP_KERNEL ); +if (!page) +return -ENOMEM ; + + xen_store_mfn = xen_start_info->store_mfn = +pfn_to_mfn (virt_to_phys ((void *)page) >> +PAGE_SHIFT ); + +/* Next allocate a local port which xenstored can bind to */ + alloc_unbound.dom =DOMID_SELF ; + alloc_unbound.remote_dom =0 ; + + err =HYPERVISOR_event_channel_op (EVTCHNOP_alloc_unbound, + &alloc_unbound); +if (err == -ENOSYS ) + goto out_unreg_front; + +BUG_ON (err); + xen_store_evtchn = xen_start_info->store_evtchn = + alloc_unbound.port; + + xen_store_interface =mfn_to_virt (xen_store_mfn); }else { xenstored_ready =1 ; xen_store_evtchn = xen_start_info->store_evtchn;
@@ -877,6 +902,9 @@ static int __init xenbus_probe_init(void)bus_unregister (&xenbus_frontend.bus); out_error: +if (page !=0 ) +free_page (page); +return err; }
Signature · 1 line
1.6.0.6
PATCH 3/15 xen dom0: Set up basic IO permissions for dom0.
In reply to a message not in the archiveFrom: Juan Quintela <[email protected]>
Impact: set iopl for dom0 kernel; map ISA
Add the direct mapping area for ISA bus access, and enable IO space access for the guest when running as dom0.
--- arch/x86/xen/enlighten.c | 8 ++++++++ arch/x86/xen/mmu.c | 24 ++++++++++++++++++++++++ arch/x86/xen/setup.c | 6 +++++- arch/x86/xen/xen-ops.h | 1 + 4 files changed, 38 insertions(+), 1 deletions(-)
arch/x86/xen/enlighten.c +8 -0
@@ -989,6 +989,7 @@ asmlinkage void __init xen_start_kernel(void)xen_raw_console_write ("mapping kernel into physical memory\n" ); pgd =xen_setup_kernel_pagetable (pgd, xen_start_info->nr_pages); +xen_ident_map_ISA (); init_mm.pgd = pgd;
@@ -998,6 +999,13 @@ asmlinkage void __init xen_start_kernel(void)if (xen_feature (XENFEAT_supervisor_mode_kernel)) pv_info.kernel_rpl =0 ; +if (xen_initial_domain ()) { +struct physdev_set_iopl set_iopl; + set_iopl.iopl =1 ; +if (HYPERVISOR_physdev_op (PHYSDEVOP_set_iopl, &set_iopl) ==-1 ) +BUG (); + } +/* set the limit of our address space */ xen_reserve_top ();
arch/x86/xen/mmu.c +24 -0
@@ -1635,6 +1635,7 @@ static void *m2v(phys_addr_t maddr)return __ka (m2p (maddr)); } +/* Set the page permissions on an identity-mapped pages */ static void set_page_prot (void *addr,pgprot_t prot) {unsigned long pfn =__pa (addr) >>PAGE_SHIFT ;
@@ -1860,6 +1861,29 @@ static void xen_set_fixmap(unsigned idx, unsigned long phys, pgprot_t prot)#endif } +__init void xen_ident_map_ISA (void ) +{ +unsigned long pa; + +/* +* If we're dom0, then linear map the ISA machine addresses into +* the kernel's address space. +*/ +if (!xen_initial_domain ()) +return ; + +xen_raw_printk ("Xen: setup ISA identity maps\n" ); + +for (pa =ISA_START_ADDRESS ; pa <ISA_END_ADDRESS ; pa +=PAGE_SIZE ) { +pte_t pte =mfn_pte (PFN_DOWN (pa),PAGE_KERNEL_IO ); + +if (HYPERVISOR_update_va_mapping (PAGE_OFFSET + pa, pte,0 )) +BUG (); + } + +xen_flush_tlb (); +} +__init void xen_post_allocator_init (void ) { pv_mmu_ops.set_pte = xen_set_pte;
arch/x86/xen/setup.c +5 -1
@@ -51,6 +51,9 @@ char * __init xen_memory_setup(void)* Even though this is normal, usable memory under Xen, reserve * ISA memory anyway because too many things think they can poke * about in there. +* +* In a dom0 kernel, this region is identity mapped with the +* hardware ISA area, so it really is out of bounds. */ e820_add_region (ISA_START_ADDRESS ,ISA_END_ADDRESS -ISA_START_ADDRESS ,E820_RESERVED );
@@ -188,7 +191,8 @@ void __init xen_arch_setup(void) pm_idle = xen_idle; -paravirt_disable_iospace (); +if (!xen_initial_domain ()) +paravirt_disable_iospace ();fiddle_vdso (); }
arch/x86/xen/xen-ops.h +1 -0
@@ -29,6 +29,7 @@ void xen_setup_machphys_mapping(void);pgd_t *xen_setup_kernel_pagetable (pgd_t *pgd,unsigned long max_pfn);void xen_ident_map_ISA (void );void xen_reserve_top (void ); +void xen_ident_map_ISA (void );void xen_post_allocator_init (void );
Signature · 1 line
1.6.0.6
PATCH 4/15 xen dom0: Add support for the platform_ops hypercall
In reply to a message not in the archiveFrom: Stephen Tweedie <[email protected]>
Impact: add hypercall definitions
Minimal changes to get platform ops (renamed dom0_ops on pv_ops) working on pv_ops builds. Pulls in upstream linux-2.6.18-xen.hg's platform.h
--- arch/x86/include/asm/xen/hypercall.h | 8 ++ include/xen/interface/platform.h | 232 ++++++++++++++++++++++++++++++++++ include/xen/interface/xen.h | 2 + 3 files changed, 242 insertions(+), 0 deletions(-) create mode 100644 include/xen/interface/platform.h
arch/x86/include/asm/xen/hypercall.h +8 -0
@@ -45,6 +45,7 @@#include <xen/interface/xen.h> #include <xen/interface/sched.h> #include <xen/interface/physdev.h> +#include <xen/interface/platform.h> /* * The hypercall asms have to meet several constraints:
@@ -282,6 +283,13 @@ HYPERVISOR_set_timer_op(u64 timeout) }static inline int +HYPERVISOR_dom0_op (struct xen_platform_op *platform_op) +{ + platform_op->interface_version =XENPF_INTERFACE_VERSION ; +return _hypercall1 (int, dom0_op, platform_op); +} + +static inline int HYPERVISOR_set_debugreg (int reg,unsigned long value) {return _hypercall2 (int, set_debugreg, reg, value);
include/xen/interface/platform.h new file +232 -0
232 lines not on this page · raw message
include/xen/interface/xen.h +2 -0
@@ -461,6 +461,8 @@ typedef uint8_t xen_domain_handle_t[16];#define __mk_unsigned_long (x) x ## UL#define mk_unsigned_long (x) __mk_unsigned_long(x) +DEFINE_GUEST_HANDLE (uint64_t); +#else /* __ASSEMBLY__ */ /* In assembly code we cannot use C numeric constant suffixes. */
Signature · 1 line
1.6.0.6
PATCH 5/15 xen mtrr: Add mtrr_ops support for Xen mtrr
In reply to a message not in the archiveFrom: Stephen Tweedie <[email protected]>
Impact: add basic MTRR support (enough to get started)
Add a Xen mtrr type, and reorganise mtrr initialisation slightly to allow the mtrr driver to set up num_var_ranges (Xen needs to do this by querying the hypervisor itself.)
Only the boot path is handled for now: we set up a xen-specific mtrr_if and set up the mtrr tables based on hypervisor information, but we don't yet handle mtrr entry add/delete.
--- arch/x86/kernel/cpu/mtrr/Makefile | 1 + arch/x86/kernel/cpu/mtrr/amd.c | 1 + arch/x86/kernel/cpu/mtrr/centaur.c | 1 + arch/x86/kernel/cpu/mtrr/cyrix.c | 1 + arch/x86/kernel/cpu/mtrr/generic.c | 1 + arch/x86/kernel/cpu/mtrr/main.c | 11 +++++-- arch/x86/kernel/cpu/mtrr/mtrr.h | 5 +++ arch/x86/kernel/cpu/mtrr/xen.c | 59 ++++++++++++++++++++++++++++++++++++ 8 files changed, 77 insertions(+), 3 deletions(-) create mode 100644 arch/x86/kernel/cpu/mtrr/xen.c
arch/x86/kernel/cpu/mtrr/Makefile +1 -0
@@ -1,3 +1,4 @@ obj-y := main.o if.o generic.o state.o cleanup.o obj-$(CONFIG_X86_32) += amd.o cyrix.o centaur.o +obj-$(CONFIG_XEN_DOM0) += xen.o
arch/x86/kernel/cpu/mtrr/amd.c +1 -0
@@ -108,6 +108,7 @@ static struct mtrr_ops amd_mtrr_ops = { .get_free_region = generic_get_free_region, .validate_add_page = amd_validate_add_page, .have_wrcomb = positive_have_wrcomb, + .num_var_ranges = common_num_var_ranges, };int __init amd_init_mtrr (void )
arch/x86/kernel/cpu/mtrr/centaur.c +1 -0
@@ -213,6 +213,7 @@ static struct mtrr_ops centaur_mtrr_ops = { .get_free_region = centaur_get_free_region, .validate_add_page = centaur_validate_add_page, .have_wrcomb = positive_have_wrcomb, + .num_var_ranges = common_num_var_ranges, };int __init centaur_init_mtrr (void )
arch/x86/kernel/cpu/mtrr/cyrix.c +1 -0
@@ -263,6 +263,7 @@ static struct mtrr_ops cyrix_mtrr_ops = { .get_free_region = cyrix_get_free_region, .validate_add_page = generic_validate_add_page, .have_wrcomb = positive_have_wrcomb, + .num_var_ranges = common_num_var_ranges, };int __init cyrix_init_mtrr (void )
arch/x86/kernel/cpu/mtrr/generic.c +1 -0
@@ -725,4 +725,5 @@ struct mtrr_ops generic_mtrr_ops = { .set = generic_set_mtrr, .validate_add_page = generic_validate_add_page, .have_wrcomb = generic_have_wrcomb, + .num_var_ranges = common_num_var_ranges, };
arch/x86/kernel/cpu/mtrr/main.c +8 -3
@@ -99,7 +99,7 @@ static int have_wrcomb(void) }/* This function returns the number of variable MTRRs */ -static void __init set_num_var_ranges (void ) +int __init common_num_var_ranges (void ) {unsigned long config =0 , dummy;
@@ -109,7 +109,7 @@ static void __init set_num_var_ranges(void) config =2 ; else if (is_cpu(CYRIX) || is_cpu(CENTAUR)) config =8 ; - num_var_ranges = config &0xff ; +return config &0xff ; }static void __init init_table (void )
@@ -622,12 +622,17 @@ int __initdata changed_by_mtrr_cleanup;void __init mtrr_bp_init (void ) {u32 phys_addr; +init_ifs (); phys_addr =32 ;if (cpu_has_mtrr) { mtrr_if = &generic_mtrr_ops; +#ifdef CONFIG_XEN_DOM0 +xen_init_mtrr (); +#endif + size_or_mask =0xff000000 ;/* 36 bits */ size_and_mask =0x00f00000 ; phys_addr =36 ;
@@ -685,7 +690,7 @@ void __init mtrr_bp_init(void) }if (mtrr_if) { -set_num_var_ranges (); + num_var_ranges = mtrr_if->num_var_ranges ();init_table ();if (use_intel ()) {get_mtrr_state ();
arch/x86/kernel/cpu/mtrr/mtrr.h +5 -0
@@ -41,6 +41,8 @@ struct mtrr_ops {int (*validate_add_page)(unsigned long base,unsigned long size,unsigned int type);int (*have_wrcomb)(void ); + +int (*num_var_ranges)(void ); }; extern int generic_get_free_region(unsigned long base, unsigned long size,
@@ -52,6 +54,8 @@ extern struct mtrr_ops generic_mtrr_ops;extern int positive_have_wrcomb (void ); +extern int __init common_num_var_ranges (void ); +/* library functions for processor-specific routines */ struct set_mtrr_context {unsigned long flags;
@@ -89,6 +93,7 @@ void mtrr_wrmsr(unsigned, unsigned, unsigned);int amd_init_mtrr (void );int cyrix_init_mtrr (void );int centaur_init_mtrr (void ); +void xen_init_mtrr (void );extern int changed_by_mtrr_cleanup;extern int mtrr_cleanup (unsigned address_bits);
arch/x86/kernel/cpu/mtrr/xen.c new file +59 -0
59 lines not on this page · raw message
Signature · 1 line
1.6.0.6
PATCH 6/15 xen: disable PAT
In reply to a message not in the archiveFrom: Ian Campbell <[email protected]>
Impact: disable PAT under Xen
Xen imposes a particular PAT layout on all paravirtual guests which does not match the layout Linux would like to use.
Force PAT to be disabled until this is resolved.
--- arch/x86/include/asm/pat.h | 5 +++++ arch/x86/mm/pat.c | 5 ----- arch/x86/xen/enlighten.c | 3 +++ 3 files changed, 8 insertions(+), 5 deletions(-)
arch/x86/include/asm/pat.h +5 -0
@@ -6,8 +6,13 @@#ifdef CONFIG_X86_PAT extern int pat_enabled; +extern void pat_disable (const char *reason);#else static const int pat_enabled; +static inline void pat_disable (const char *reason) +{ + (void )reason; +}#endif extern void pat_init (void );
arch/x86/mm/pat.c +0 -5
@@ -43,11 +43,6 @@ static int __init nopat(char *str) return 0; }early_param ("nopat" , nopat); -#else -static inline void pat_disable (const char *reason) -{ - (void )reason; -}#endif
arch/x86/xen/enlighten.c +3 -0
@@ -48,6 +48,7 @@#include <asm/pgtable.h> #include <asm/tlbflush.h> #include <asm/reboot.h> +#include <asm/pat.h> #include "xen-ops.h" #include "mmu.h"
@@ -1029,6 +1030,8 @@ asmlinkage void __init xen_start_kernel(void)add_preferred_console ("hvc" ,0 ,NULL ); } +pat_disable ("PAT disabled on Xen" ); +xen_raw_console_write ("about to get started...\n" );/* Start the world */
Signature · 1 line
1.6.0.6
PATCH 7/15 xen/dom0: use _PAGE_IOMAP in ioremap to do machine mappings
In reply to a message not in the archiveImpact: allow Xen domain to map real hardware
In a Xen domain, ioremap operates on machine addresses, not pseudo-physical addresses. We use _PAGE_IOMAP to determine whether a mapping is intended for machine addresses.
--- arch/x86/include/asm/xen/page.h | 8 +--- arch/x86/xen/enlighten.c | 4 ++- arch/x86/xen/mmu.c | 69 +++++++++++++++++++++++++++++++++++++- 3 files changed, 72 insertions(+), 9 deletions(-)
arch/x86/include/asm/xen/page.h +2 -6
@@ -112,13 +112,9 @@ static inline xpaddr_t machine_to_phys(xmaddr_t machine)*/ static inline unsigned long mfn_to_local_pfn (unsigned long mfn) { -extern unsigned long max_mapnr;unsigned long pfn =mfn_to_pfn (mfn); -if ((pfn < max_mapnr) - && !xen_feature (XENFEAT_auto_translated_physmap) - && (get_phys_to_machine (pfn) != mfn)) -return max_mapnr;/* force !pfn_valid() */ -/* XXX fixme; not true with sparsemem */ +if (get_phys_to_machine (pfn) != mfn) +return -1 ;/* force !pfn_valid() */ return pfn; }
arch/x86/xen/enlighten.c +3 -1
@@ -978,7 +978,9 @@ asmlinkage void __init xen_start_kernel(void)/* Prevent unwanted bits from being set in PTEs. */ __supported_pte_mask &= ~_PAGE_GLOBAL; -if (!xen_initial_domain ()) +if (xen_initial_domain ()) + __supported_pte_mask |= _PAGE_IOMAP; +else __supported_pte_mask &= ~(_PAGE_PWT | _PAGE_PCD);/* Don't do the full vcpu_info placement stuff until we have a
arch/x86/xen/mmu.c +67 -2
115 lines not on this page · raw message
Signature · 1 line
1.6.0.6
PATCH 8/15 xen/dom0: Use host E820 map
In reply to a message not in the archiveFrom: Ian Campbell <[email protected]>
Impact: synthesize virtual E820 using real one as template
Unlike the non-paravirt Xen port we do not have distinct psuedo-physical and I/O memory resource-spaces and therefore resources in the two can clash. Fix this by registering a memory map which matches the underlying I/O map. Currently this wastes the memory in the reserved regions. Eventually we should remap this memory to the end of the address space.
--- arch/x86/xen/setup.c | 45 +++++++++++++++++++++++++++++++++++++-- include/xen/interface/memory.h | 29 +++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 3 deletions(-)
arch/x86/xen/setup.c +42 -3
@@ -19,6 +19,7 @@#include <xen/page.h> #include <xen/interface/callback.h> +#include <xen/interface/memory.h> #include <xen/interface/physdev.h> #include <xen/features.h>
@@ -36,16 +37,54 @@ extern void xen_syscall32_target(void);/** * machine_specific_memory_setup - Hook for machine specific memory setup. **/ -char *__init xen_memory_setup (void ) {unsigned long max_pfn = xen_start_info->nr_pages; +unsigned long long mem_end; +int rc; +struct xen_memory_map memmap; +/* +* This is rather large for a stack variable but this early in +* the boot process we know we have plenty slack space. +*/ +struct e820entry map[E820MAX ]; +int op =xen_initial_domain () ? + XENMEM_machine_memory_map : + XENMEM_memory_map; +int i; max_pfn =min (MAX_DOMAIN_PAGES , max_pfn); + mem_end =PFN_PHYS ((u64 )max_pfn); + + memmap.nr_entries =E820MAX ; +set_xen_guest_handle (memmap.buffer, map); + + rc =HYPERVISOR_memory_op (op, &memmap); +if (rc == -ENOSYS ) { + memmap.nr_entries =1 ; + map[0 ].addr =0ULL ; + map[0 ].size = mem_end; +/* 8MB slack (to balance backend allocations). */ + map[0 ].size +=8ULL <<20 ; + map[0 ].type =E820_RAM ; + rc =0 ; + } +BUG_ON (rc); e820.nr_map =0 ; - -e820_add_region (0 ,PFN_PHYS ((u64 )max_pfn),E820_RAM ); +for (i =0 ; i < memmap.nr_entries; i++) { +unsigned long long end = map[i].addr + map[i].size; +if (map[i].type ==E820_RAM ) { +if (map[i].addr > mem_end) +continue ; +if (end > mem_end) { +/* Truncate region to max_mem. */ + map[i].size -= end - mem_end; + } + } +if (map[i].size >0 ) +e820_add_region (map[i].addr, map[i].size, map[i].type); + }/* * Even though this is normal, usable memory under Xen, reserve
include/xen/interface/memory.h +29 -0
@@ -142,4 +142,33 @@ struct xen_translate_gpfn_list { };DEFINE_GUEST_HANDLE_STRUCT (xen_translate_gpfn_list); +/* +* Returns the pseudo-physical memory map as it was when the domain +* was started (specified by XENMEM_set_memory_map). +* arg == addr of struct xen_memory_map. +*/ +#define XENMEM_memory_map 9 +struct xen_memory_map { +/* +* On call the number of entries which can be stored in buffer. On +* return the number of entries which have been stored in +* buffer. +*/ +unsigned int nr_entries; + +/* +* Entries in the buffer are in the same format as returned by the +* BIOS INT 0x15 EAX=0xE820 call. +*/ +GUEST_HANDLE (void ) buffer; +}; +DEFINE_GUEST_HANDLE_STRUCT (xen_memory_map); + +/* +* Returns the real physical memory map. Passes the same structure as +* XENMEM_memory_map. +* arg == addr of struct xen_memory_map. +*/ +#define XENMEM_machine_memory_map 10 +#endif /* __XEN_PUBLIC_MEMORY_H__ */
Signature · 1 line
1.6.0.6
PATCH 9/15 xen: implement XENMEM_machphys_mapping
In reply to a message not in the archiveFrom: Ian Campbell <[email protected]>
Impact: add hypercall definitions
This hypercall allows Xen to specify a non-default location for the machine to physical mapping. This capability is used when running a 32 bit domain 0 on a 64 bit hypervisor to shrink the hypervisor hole to exactly the size required.
--- arch/x86/include/asm/xen/interface.h | 6 +++--- arch/x86/include/asm/xen/interface_32.h | 5 +++++ arch/x86/include/asm/xen/interface_64.h | 13 +------------ arch/x86/include/asm/xen/page.h | 7 ++++--- arch/x86/xen/enlighten.c | 8 +++++++- arch/x86/xen/mmu.c | 15 +++++++++++++++ include/xen/interface/memory.h | 13 +++++++++++++ 7 files changed, 48 insertions(+), 19 deletions(-)
arch/x86/include/asm/xen/interface.h +3 -3
@@ -61,9 +61,9 @@ DEFINE_GUEST_HANDLE(void);#define HYPERVISOR_VIRT_START mk_unsigned_long(__HYPERVISOR_VIRT_START)#endif -#ifndef machine_to_phys_mapping -#define machine_to_phys_mapping ((unsigned long *)HYPERVISOR_VIRT_START) -#endif +#define MACH2PHYS_VIRT_START mk_unsigned_long(__MACH2PHYS_VIRT_START) +#define MACH2PHYS_VIRT_END mk_unsigned_long(__MACH2PHYS_VIRT_END) +#define MACH2PHYS_NR_ENTRIES ((MACH2PHYS_VIRT_END-MACH2PHYS_VIRT_START)>>__MACH2PHYS_SHIFT)/* Maximum number of virtual CPUs in multi-processor guests. */ #define MAX_VIRT_CPUS 32
arch/x86/include/asm/xen/interface_32.h +5 -0
@@ -32,6 +32,11 @@/* And the trap vector is... */ #define TRAP_INSTR "int $0x82" +#define __MACH2PHYS_VIRT_START 0xF5800000 +#define __MACH2PHYS_VIRT_END 0xF6800000 + +#define __MACH2PHYS_SHIFT 2 +/* * Virtual addresses beyond this are not modifiable by guest OSes. The * machine->physical mapping table starts at this address, read-only.
arch/x86/include/asm/xen/interface_64.h +1 -12
@@ -39,18 +39,7 @@#define __HYPERVISOR_VIRT_END 0xFFFF880000000000#define __MACH2PHYS_VIRT_START 0xFFFF800000000000#define __MACH2PHYS_VIRT_END 0xFFFF804000000000 - -#ifndef HYPERVISOR_VIRT_START -#define HYPERVISOR_VIRT_START mk_unsigned_long(__HYPERVISOR_VIRT_START) -#define HYPERVISOR_VIRT_END mk_unsigned_long(__HYPERVISOR_VIRT_END) -#endif - -#define MACH2PHYS_VIRT_START mk_unsigned_long(__MACH2PHYS_VIRT_START) -#define MACH2PHYS_VIRT_END mk_unsigned_long(__MACH2PHYS_VIRT_END) -#define MACH2PHYS_NR_ENTRIES ((MACH2PHYS_VIRT_END-MACH2PHYS_VIRT_START)>>3) -#ifndef machine_to_phys_mapping -#define machine_to_phys_mapping ((unsigned long *)HYPERVISOR_VIRT_START) -#endif +#define __MACH2PHYS_SHIFT 3/* * int HYPERVISOR_set_segment_base(unsigned int which, unsigned long base)
arch/x86/include/asm/xen/page.h +4 -3
@@ -5,6 +5,7 @@#include <linux/types.h> #include <linux/spinlock.h> #include <linux/pfn.h> +#include <linux/mm.h> #include <asm/uaccess.h> #include <asm/page.h>
@@ -35,6 +36,8 @@ typedef struct xpaddr {#define MAX_DOMAIN_PAGES \ ((unsigned long)((u64)CONFIG_XEN_MAX_DOMAIN_MEMORY * 1024 * 1024 * 1024 / PAGE_SIZE)) +extern unsigned long *machine_to_phys_mapping; +extern unsigned int machine_to_phys_order;extern unsigned long get_phys_to_machine (unsigned long pfn);extern void set_phys_to_machine (unsigned long pfn,unsigned long mfn);
@@ -62,10 +65,8 @@ static inline unsigned long mfn_to_pfn(unsigned long mfn)if (xen_feature (XENFEAT_auto_translated_physmap))return mfn; -#if 0 if (unlikely ((mfn >> machine_to_phys_order) !=0 )) -return max_mapnr; -#endif +return ~0 ; pfn =0 ;/*
arch/x86/xen/enlighten.c +7 -1
@@ -62,6 +62,11 @@ DEFINE_PER_CPU(struct vcpu_info, xen_vcpu_info);enum xen_domain_type xen_domain_type =XEN_NATIVE ;EXPORT_SYMBOL_GPL (xen_domain_type); +unsigned long *machine_to_phys_mapping = (void *)MACH2PHYS_VIRT_START ; +EXPORT_SYMBOL (machine_to_phys_mapping); +unsigned int machine_to_phys_order; +EXPORT_SYMBOL (machine_to_phys_order); +struct start_info *xen_start_info;EXPORT_SYMBOL_GPL (xen_start_info);
@@ -913,7 +918,6 @@ static const struct machine_ops __initdata xen_machine_ops = { .emergency_restart = xen_emergency_restart, }; -/* First C function to be called on Xen boot */ asmlinkage void __init xen_start_kernel(void) {
@@ -928,6 +932,8 @@ asmlinkage void __init xen_start_kernel(void)xen_setup_features (); +xen_setup_machphys_mapping (); +/* Install Xen paravirt ops */ pv_info = xen_info; pv_init_ops = xen_init_ops;
arch/x86/xen/mmu.c +15 -0
@@ -57,6 +57,7 @@#include <xen/page.h> #include <xen/interface/xen.h> #include <xen/interface/version.h> +#include <xen/interface/memory.h> #include <xen/hvc-console.h> #include "multicalls.h"
@@ -1749,6 +1750,20 @@ static __init void xen_map_identity_early(pmd_t *pmd, unsigned long max_pfn)set_page_prot (pmd,PAGE_KERNEL_RO ); } +void __init xen_setup_machphys_mapping (void ) +{ +struct xen_machphys_mapping mapping; +unsigned long machine_to_phys_nr_ents; + +if (HYPERVISOR_memory_op (XENMEM_machphys_mapping, &mapping) ==0 ) { + machine_to_phys_mapping = (unsigned long *)mapping.v_start; + machine_to_phys_nr_ents = mapping.max_mfn +1 ; + }else { + machine_to_phys_nr_ents =MACH2PHYS_NR_ENTRIES ; + } + machine_to_phys_order =fls (machine_to_phys_nr_ents -1 ); +} +#ifdef CONFIG_X86_64 static void convert_pfn_mfn (void *v) {
include/xen/interface/memory.h +13 -0
@@ -97,6 +97,19 @@ struct xen_machphys_mfn_list {DEFINE_GUEST_HANDLE_STRUCT (xen_machphys_mfn_list);/* +* Returns the location in virtual address space of the machine_to_phys +* mapping table. Architectures which do not have a m2p table, or which do not +* map it by default into guest address space, do not implement this command. +* arg == addr of xen_machphys_mapping_t. +*/ +#define XENMEM_machphys_mapping 12 +struct xen_machphys_mapping { +unsigned long v_start, v_end;/* Start and end virtual addresses. */ +unsigned long max_mfn;/* Maximum MFN that can be looked up. */ +}; +DEFINE_GUEST_HANDLE_STRUCT (xen_machphys_mapping_t); + +/* * Sets the GPFN at which a particular page appears in the specified guest's * pseudophysical address space. * arg == addr of xen_add_to_physmap_t.
Signature · 1 line
1.6.0.6
PATCH 10/15 xen: clear reserved bits in l3 entries given in the initial pagetables
In reply to a message not in the archiveFrom: Ian Campbell <[email protected]>
Impact: workaround Xen bug in 32-on-64 dom0
In native PAE, the only flag that may be legitimately set in an L3 entry is Present. When Xen grafts the top-level PAE L3 pagetable entries into the L4 pagetable, it must also set the other permissions flags so that the mapped pages are actually accessible.
However, due to a bug in the hypervisor, it validates update to the L3 entries as formal PAE entries, so it will refuse to validate these entries with the extra bits requires for 4-level pagetables.
This patch simply masks the entries back to the bare PAE level, leaving Xen to add whatever bits it feels are necessary.
--- arch/x86/xen/mmu.c | 15 +++++++++++++++ 1 files changed, 15 insertions(+), 0 deletions(-)
arch/x86/xen/mmu.c +15 -0
@@ -1855,6 +1855,7 @@ __init pgd_t *xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn) {pmd_t *kernel_pmd; +int i; max_pfn_mapped = PFN_DOWN(__pa(xen_start_info->pt_base) + xen_start_info->nr_pt_frames * PAGE_SIZE +
@@ -1866,6 +1867,20 @@ __init pgd_t *xen_setup_kernel_pagetable(pgd_t *pgd,xen_map_identity_early (level2_kernel_pgt, max_pfn);memcpy (swapper_pg_dir, pgd,sizeof (pgd_t) *PTRS_PER_PGD ); + +/* +* When running a 32 bit domain 0 on a 64 bit hypervisor a +* pinned L3 (such as the initial pgd here) contains bits +* which are reserved in the PAE layout but not in the 64 bit +* layout. Unfortunately some versions of the hypervisor +* (incorrectly) validate compat mode guests against the PAE +* layout and hence will not allow such a pagetable to be +* pinned by the guest. Therefore we mask off only the PFN and +* Present bits of the supplied L3. +*/ +for (i =0 ; i <PTRS_PER_PGD ; i++) + swapper_pg_dir[i].pgd &= (PTE_PFN_MASK | _PAGE_PRESENT); +set_pgd (&swapper_pg_dir[KERNEL_PGD_BOUNDARY ],__pgd (__pa (level2_kernel_pgt) | _PAGE_PRESENT));
Signature · 1 line
1.6.0.6
PATCH 11/15 xen: allow enable use of VGA console on dom0
In reply to a message not in the archiveImpact: make VGA console work in dom0
Get the information about the VGA console hardware from Xen, and put it into the form the bootloader normally generates, so that the rest of the kernel can deal with VGA as usual.
--- arch/x86/xen/Makefile | 3 +- arch/x86/xen/enlighten.c | 10 ++++++ arch/x86/xen/vga.c | 67 +++++++++++++++++++++++++++++++++++++++++++ arch/x86/xen/xen-ops.h | 11 +++++++ include/xen/interface/xen.h | 39 +++++++++++++++++++++++++ 5 files changed, 129 insertions(+), 1 deletions(-) create mode 100644 arch/x86/xen/vga.c
arch/x86/xen/Makefile +2 -1
@@ -10,4 +10,5 @@ obj-y := enlighten.o setup.o multicalls.o mmu.o irq.o \ grant-table.o suspend.o obj-$(CONFIG_SMP) += smp.o spinlock.o -obj-$(CONFIG_XEN_DEBUG_FS) += debugfs.o +obj-$(CONFIG_XEN_DEBUG_FS) += debugfs.o +obj-$(CONFIG_XEN_DOM0) += vga.o
arch/x86/xen/enlighten.c +10 -0
@@ -1036,6 +1036,16 @@ asmlinkage void __init xen_start_kernel(void)add_preferred_console ("xenboot" ,0 ,NULL );add_preferred_console ("tty" ,0 ,NULL );add_preferred_console ("hvc" ,0 ,NULL ); + + boot_params.screen_info.orig_video_isVGA =0 ; + }else { +const struct dom0_vga_console_info *info = + (void *)((char *)xen_start_info + + xen_start_info->console.dom0.info_off); + +xen_init_vga (info, xen_start_info->console.dom0.info_size); + xen_start_info->console.domU.mfn =0 ; + xen_start_info->console.domU.evtchn =0 ; }pat_disable ("PAT disabled on Xen" );
arch/x86/xen/vga.c new file +67 -0
67 lines not on this page · raw message
arch/x86/xen/xen-ops.h +11 -0
@@ -72,6 +72,17 @@ static inline void xen_smp_init(void) {}#endif +struct dom0_vga_console_info ; + +#ifdef CONFIG_XEN_DOM0 +void xen_init_vga (const struct dom0_vga_console_info *,size_t size); +#else +static inline void xen_init_vga (const struct dom0_vga_console_info *info, +size_t size) +{ +} +#endif +/* Declare an asm function, along with symbols needed to make it inlineable */ #define DECL_ASM (ret, name, ...) \
include/xen/interface/xen.h +39 -0
@@ -449,6 +449,45 @@ struct start_info {int8_t cmd_line[MAX_GUEST_CMDLINE ]; }; +struct dom0_vga_console_info { +uint8_t video_type;/* DOM0_VGA_CONSOLE_??? */ +#define XEN_VGATYPE_TEXT_MODE_3 0x03 +#define XEN_VGATYPE_VESA_LFB 0x23 + +union { +struct { +/* Font height, in pixels. */ +uint16_t font_height; +/* Cursor location (column, row). */ +uint16_t cursor_x, cursor_y; +/* Number of rows and columns (dimensions in characters). */ +uint16_t rows, columns; + } text_mode_3; + +struct { +/* Width and height, in pixels. */ +uint16_t width, height; +/* Bytes per scan line. */ +uint16_t bytes_per_line; +/* Bits per pixel. */ +uint16_t bits_per_pixel; +/* LFB physical address, and size (in units of 64kB). */ +uint32_t lfb_base; +uint32_t lfb_size; +/* RGB mask offsets and sizes, as defined by VBE 1.2+ */ +uint8_t red_pos, red_size; +uint8_t green_pos, green_size; +uint8_t blue_pos, blue_size; +uint8_t rsvd_pos, rsvd_size; + +/* VESA capabilities (offset 0xa, VESA command 0x4f00). */ +uint32_t gbl_caps; +/* Mode attributes (offset 0x0, VESA command 0x4f01). */ +uint16_t mode_attrs; + } vesa_lfb; + } u; +}; +/* These flags are passed in the 'flags' field of start_info_t. */ #define SIF_PRIVILEGED (1<<0)/* Is the domain privileged? */ #define SIF_INITDOMAIN (1<<1)/* Is this the initial control domain? */
Signature · 1 line
1.6.0.6
PATCH 12/15 xen/dom0: add XEN_DOM0 config option
In reply to a message not in the archiveImpact: add Kconfig to enable XEN_DOM0
Allow dom0 to be configured. Requires more patches to do something useful.
--- arch/x86/xen/Kconfig | 26 ++++++++++++++++++++++++++ arch/x86/xen/enlighten.c | 5 +++-- 2 files changed, 29 insertions(+), 2 deletions(-)
arch/x86/xen/Kconfig +26 -0
@@ -36,3 +36,29 @@ config XEN_DEBUG_FS help Enable statistics output and various tuning options in debugfs. Enabling this option may incur a significant performance overhead. + +config XEN_DOM0 + bool "Enable Xen privileged domain support" + depends on XEN && X86_IO_APIC && ACPI + help + The Xen hypervisor requires a privileged domain ("dom0") to + actually manage the machine, provide devices drivers, etc. + This option enables dom0 support. A dom0 kernel can also + run as an unprivileged domU kernel, or a kernel running + native on bare hardware. + +# Dummy symbol since people have come to rely on the PRIVILEGED_GUEST +# name in tools. +config XEN_PRIVILEGED_GUEST + def_bool XEN_DOM0 + +config XEN_PCI_PASSTHROUGH + bool #"Enable support for Xen PCI passthrough devices" + depends on XEN && PCI + help + Enable support for passing PCI devices through to + unprivileged domains. (COMPLETELY UNTESTED) + +config XEN_DOM0_PCI + def_bool y + depends on XEN_DOM0 && PCI
arch/x86/xen/enlighten.c +3 -2
@@ -169,9 +169,10 @@ static void __init xen_banner(void)printk (KERN_INFO "Booting paravirtualized kernel on %s\n" , pv_info.name); -printk (KERN_INFO "Xen version: %d.%d%s%s\n" , +printk (KERN_INFO "Xen version: %d.%d%s%s%s\n" , version >>16 , version &0xffff , extra.extraversion, -xen_feature (XENFEAT_mmu_pt_update_preserve_ad) ?" (preserve-AD)" :"" ); +xen_feature (XENFEAT_mmu_pt_update_preserve_ad) ?" (preserve-AD)" :"" , +xen_initial_domain () ?" (dom0)" :"" ); }static __read_mostly unsigned int cpuid_leaf1_edx_mask = ~0 ;
Signature · 1 line
1.6.0.6
PATCH 13/15 x86: make /dev/mem mappings _PAGE_IOMAP
In reply to a message not in the archiveFrom: Jeremy Fitzhardinge <[email protected]>
Impact: allow hardware to be mapped via /dev/mem
Use _PAGE_IOMAP on /dev/mem mappings.
--- arch/x86/mm/pat.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
arch/x86/mm/pat.c +1 -1
@@ -504,7 +504,7 @@ int free_memtype(u64 start, u64 end)pgprot_t phys_mem_access_prot (struct file *file,unsigned long pfn,unsigned long size,pgprot_t vma_prot) { -return vma_prot; +return __pgprot (pgprot_val (vma_prot) | _PAGE_IOMAP); }#ifdef CONFIG_STRICT_DEVMEM
Signature · 1 line
1.6.0.6
PATCH 14/15 paravirtualize IO permission bitmap
In reply to a message not in the archiveFrom: Christophe Saout <[email protected]>
Impact: make ioperm bitmap work under Xen
A PV Xen guest kernel has no TSS of its own, so the IO permission bitmap must be paravirtualized. This patch adds set_io_bitmap as a paravirt op, and defines a native version which updates the tss, and a Xen version which uses a hypercall.
This is much easier now that 32 and 64-bit use the same code to manage the IO bitmap.
--- arch/x86/include/asm/paravirt.h | 9 +++++++++ arch/x86/include/asm/processor.h | 4 ++++ arch/x86/kernel/ioport.c | 34 ++++++++++++++++++++++++++-------- arch/x86/kernel/paravirt.c | 1 + arch/x86/kernel/process.c | 27 +++++++-------------------- arch/x86/xen/enlighten.c | 16 ++++++++++++++++ 6 files changed, 63 insertions(+), 28 deletions(-)
arch/x86/include/asm/paravirt.h +9 -0
@@ -156,6 +156,8 @@ struct pv_cpu_ops {void (*load_sp0)(struct tss_struct *tss,struct thread_struct *t);void (*set_iopl_mask)(unsigned mask); +void (*set_io_bitmap)(struct thread_struct *thread, +int changed,unsigned long bytes_updated);void (*wbinvd)(void );void (*io_delay)(void );
@@ -996,11 +998,18 @@ static inline void write_idt_entry(gate_desc *dt, int entry, const gate_desc *g) {PVOP_VCALL3 (pv_cpu_ops.write_idt_entry, dt, entry, g); } +static inline void set_iopl_mask (unsigned mask) {PVOP_VCALL1 (pv_cpu_ops.set_iopl_mask, mask); } +static inline void set_io_bitmap (struct thread_struct *thread, +int changed,unsigned long bytes_updated) +{ +PVOP_VCALL3 (pv_cpu_ops.set_io_bitmap, thread, changed, bytes_updated); +} +/* The paravirtualized I/O functions */ static inline void slow_down_io (void ) {
arch/x86/include/asm/processor.h +4 -0
@@ -538,6 +538,9 @@ static inline void native_set_iopl_mask(unsigned mask)#endif } +extern void native_set_io_bitmap (struct thread_struct *thread, +int changed,unsigned long updated_bytes); +static inline void native_load_sp0 (struct tss_struct *tss,struct thread_struct *thread) {
@@ -579,6 +582,7 @@ static inline void load_sp0(struct tss_struct *tss, }#define set_iopl_mask native_set_iopl_mask +#define set_io_bitmap native_set_io_bitmap#endif /* CONFIG_PARAVIRT */ /*
arch/x86/kernel/ioport.c +26 -8
@@ -30,14 +30,31 @@ static void set_bitmap(unsigned long *bitmap, unsigned int base, } } +void native_set_io_bitmap (struct thread_struct *t, +int changed,unsigned long bytes_updated) +{ +struct tss_struct *tss; + +if (!bytes_updated) +return ; + + tss = &__get_cpu_var (init_tss); + +/* Update the TSS: */ +if (t->io_bitmap_ptr) +memcpy (tss->io_bitmap, t->io_bitmap_ptr, bytes_updated); +else +memset (tss->io_bitmap,0xff , bytes_updated); +} +/* * this changes the io permissions bitmap in the current task. */ asmlinkage long sys_ioperm (unsigned long from,unsigned long num,int turn_on) {struct thread_struct *t = ¤t->thread; -struct tss_struct *tss;unsigned int i, max_long, bytes, bytes_updated; +int changed;if ((from + num <= from) || (from + num >IO_BITMAP_BITS ))return -EINVAL ;
@@ -58,16 +75,18 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)memset (bitmap,0xff ,IO_BITMAP_BYTES ); t->io_bitmap_ptr = bitmap;set_thread_flag (TIF_IO_BITMAP ); - } + changed =1 ; + }else + changed =0 ;/* -* do it in the per-thread copy and in the TSS ... +* do it in the per-thread copy * -* Disable preemption via get_cpu() - we must not switch away +* Disable preemption - we must not switch away * because the ->io_bitmap_max value must match the bitmap * contents: */ - tss = &per_cpu (init_tss,get_cpu ()); +preempt_disable ();set_bitmap (t->io_bitmap_ptr, from, num, !turn_on);
@@ -85,10 +104,9 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on) t->io_bitmap_max = bytes; -/* Update the TSS: */ -memcpy (tss->io_bitmap, t->io_bitmap_ptr, bytes_updated); +set_io_bitmap (t, changed, bytes_updated); -put_cpu (); +preempt_enable ();return 0 ; }
arch/x86/kernel/paravirt.c +1 -0
@@ -398,6 +398,7 @@ struct pv_cpu_ops pv_cpu_ops = { .swapgs = native_swapgs, .set_iopl_mask = native_set_iopl_mask, + .set_io_bitmap = native_set_io_bitmap, .io_delay = native_io_delay, .start_context_switch = paravirt_nop,
arch/x86/kernel/process.c +7 -20
@@ -71,16 +71,12 @@ void exit_thread(void)unsigned long *bp = t->io_bitmap_ptr;if (bp) { -struct tss_struct *tss = &per_cpu (init_tss,get_cpu ()); - +preempt_disable (); t->io_bitmap_ptr =NULL ;clear_thread_flag (TIF_IO_BITMAP ); -/* -* Careful, clear this in the TSS too: -*/ -memset (tss->io_bitmap,0xff , t->io_bitmap_max); +set_io_bitmap (t,1 , t->io_bitmap_max); t->io_bitmap_max =0 ; -put_cpu (); +preempt_enable ();kfree (bp); }
@@ -211,19 +207,10 @@ void __switch_to_xtra(struct task_struct *prev_p, struct task_struct *next_p,hard_enable_TSC (); } -if (test_tsk_thread_flag (next_p,TIF_IO_BITMAP )) { -/* -* Copy the relevant range of the IO bitmap. -* Normally this is 128 bytes or less: -*/ -memcpy (tss->io_bitmap, next->io_bitmap_ptr, -max (prev->io_bitmap_max, next->io_bitmap_max)); - }else if (test_tsk_thread_flag (prev_p,TIF_IO_BITMAP )) { -/* -* Clear any possible leftover bits: -*/ -memset (tss->io_bitmap,0xff , prev->io_bitmap_max); - } +if (test_tsk_thread_flag (next_p,TIF_IO_BITMAP ) || +test_tsk_thread_flag (prev_p,TIF_IO_BITMAP )) +set_io_bitmap (next,1 , +max (prev->io_bitmap_max, next->io_bitmap_max)); }int sys_fork (struct pt_regs *regs)
arch/x86/xen/enlighten.c +16 -0
@@ -568,6 +568,21 @@ static void xen_set_iopl_mask(unsigned mask)HYPERVISOR_physdev_op (PHYSDEVOP_set_iopl, &set_iopl); } +static void xen_set_io_bitmap (struct thread_struct *thread, +int changed,unsigned long bytes_updated) +{ +struct physdev_set_iobitmap set_iobitmap; + +if (!changed) +return ; + +set_xen_guest_handle (set_iobitmap.bitmap, + (char *)thread->io_bitmap_ptr); + set_iobitmap.nr_ports = thread->io_bitmap_ptr ?IO_BITMAP_BITS :0 ; +WARN_ON (HYPERVISOR_physdev_op (PHYSDEVOP_set_iobitmap, + &set_iobitmap)); +} +static void xen_io_delay (void ) { }
@@ -861,6 +876,7 @@ static const struct pv_cpu_ops xen_cpu_ops __initdata = { .load_sp0 = xen_load_sp0, .set_iopl_mask = xen_set_iopl_mask, + .set_io_bitmap = xen_set_io_bitmap, .io_delay = xen_io_delay,/* Xen takes care of %gs when switching to usermode for us */
Signature · 1 line
1.6.0.6
PATCH 15/15 x86: don't need "changed" parameter for set_io_bitmap()
In reply to a message not in the archiveFrom: Jeremy Fitzhardinge <[email protected]>
Impact: cleanup
The "changed" parameter isn't really used, so don't bother passing it. (xen_set_io_bitmap can keep track of it for itself, if it wants.)
--- arch/x86/include/asm/paravirt.h | 6 +++--- arch/x86/include/asm/processor.h | 2 +- arch/x86/kernel/ioport.c | 9 +++------ arch/x86/kernel/process.c | 4 ++-- arch/x86/xen/enlighten.c | 5 +---- 5 files changed, 10 insertions(+), 16 deletions(-)
arch/x86/include/asm/paravirt.h +3 -3
@@ -157,7 +157,7 @@ struct pv_cpu_ops {void (*set_iopl_mask)(unsigned mask);void (*set_io_bitmap)(struct thread_struct *thread, -int changed,unsigned long bytes_updated); +unsigned long bytes_updated);void (*wbinvd)(void );void (*io_delay)(void );
@@ -1005,9 +1005,9 @@ static inline void set_iopl_mask(unsigned mask) }static inline void set_io_bitmap (struct thread_struct *thread, -int changed,unsigned long bytes_updated) +unsigned long bytes_updated) { -PVOP_VCALL3 (pv_cpu_ops.set_io_bitmap, thread, changed, bytes_updated); +PVOP_VCALL2 (pv_cpu_ops.set_io_bitmap, thread, bytes_updated); }/* The paravirtualized I/O functions */
arch/x86/include/asm/processor.h +1 -1
@@ -539,7 +539,7 @@ static inline void native_set_iopl_mask(unsigned mask) }extern void native_set_io_bitmap (struct thread_struct *thread, -int changed,unsigned long updated_bytes); +unsigned long updated_bytes);static inline void native_load_sp0 (struct tss_struct *tss,struct thread_struct *thread)
arch/x86/kernel/ioport.c +3 -6
@@ -31,7 +31,7 @@ static void set_bitmap(unsigned long *bitmap, unsigned int base, }void native_set_io_bitmap (struct thread_struct *t, -int changed,unsigned long bytes_updated) +unsigned long bytes_updated) {struct tss_struct *tss;
@@ -54,7 +54,6 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on) {struct thread_struct *t = ¤t->thread;unsigned int i, max_long, bytes, bytes_updated; -int changed;if ((from + num <= from) || (from + num >IO_BITMAP_BITS ))return -EINVAL ;
@@ -75,9 +74,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)memset (bitmap,0xff ,IO_BITMAP_BYTES ); t->io_bitmap_ptr = bitmap;set_thread_flag (TIF_IO_BITMAP ); - changed =1 ; - }else - changed =0 ; + }/* * do it in the per-thread copy
@@ -104,7 +101,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on) t->io_bitmap_max = bytes; -set_io_bitmap (t, changed, bytes_updated); +set_io_bitmap (t, bytes_updated);preempt_enable ();
arch/x86/kernel/process.c +2 -2
@@ -74,7 +74,7 @@ void exit_thread(void)preempt_disable (); t->io_bitmap_ptr =NULL ;clear_thread_flag (TIF_IO_BITMAP ); -set_io_bitmap (t,1 , t->io_bitmap_max); +set_io_bitmap (t, t->io_bitmap_max); t->io_bitmap_max =0 ;preempt_enable ();kfree (bp);
@@ -209,7 +209,7 @@ void __switch_to_xtra(struct task_struct *prev_p, struct task_struct *next_p,if (test_tsk_thread_flag (next_p,TIF_IO_BITMAP ) ||test_tsk_thread_flag (prev_p,TIF_IO_BITMAP )) -set_io_bitmap (next,1 , +set_io_bitmap (next,max (prev->io_bitmap_max, next->io_bitmap_max)); }
arch/x86/xen/enlighten.c +1 -4
@@ -569,13 +569,10 @@ static void xen_set_iopl_mask(unsigned mask) }static void xen_set_io_bitmap (struct thread_struct *thread, -int changed,unsigned long bytes_updated) +unsigned long bytes_updated) {struct physdev_set_iobitmap set_iobitmap; -if (!changed) -return ; -set_xen_guest_handle (set_iobitmap.bitmap, (char *)thread->io_bitmap_ptr); set_iobitmap.nr_ports = thread->io_bitmap_ptr ?IO_BITMAP_BITS :0 ;
Signature · 1 line
1.6.0.6