Skip to contentSkip to conversation

2.6.30 Xen core updates

GIT PULL In review Jeremy Fitzhardinge 5 participants 49 messages Mar 13, 2009 – Mar 17, 2009

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

This series updates the kernel's baseline domU Xen functionality. It's mostly bugfixes, but there are a couple of new Xen-specific drivers.

The series depends on the earlier x86/brk and x86/paravirt patches I posted a couple of days ago.

Thanks,
J

The following changes since commit 6b3933081104945c557d8fe678301cc1bdefdcc8:
Jeremy Fitzhardinge (1):
Merge branch 'push/x86/brk' into HEAD

are available in the git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/jeremy/xen.git push/xen/master

Alex Nixon (1):
Xen: Add virt_to_pfn helper function

Hannes Eder (1):
NULL noise: arch/x86/xen/smp.c

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 (18):
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
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 branches 'push/xen/dev-evtchn', 'push/xen/xenfs' and 'push/xen/sys-hypervisor' into push/xen/control Merge branches 'push/xen/control' and 'push/xen/xenbus' into push/xen/master

 arch/x86/include/asm/required-features.h |    2 +-
 arch/x86/include/asm/xen/page.h          |    3 +-
 arch/x86/xen/enlighten.c                 |   76 ++++-
 arch/x86/xen/mmu.c                       |  116 ++++++--
 arch/x86/xen/mmu.h                       |    3 +
 arch/x86/xen/smp.c                       |    4 +-
 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 +-
 21 files changed, 1269 insertions(+), 107 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
#1 lore raw

PATCH 1/24 xen: disable preempt for leave_lazy_mmu

From: Jeremy Fitzhardinge <[email protected]>

xen_mc_flush() requires preemption to be disabled for its own sanity, so disable it while we're flushing.

---
 arch/x86/xen/mmu.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
arch/x86/xen/mmu.c +2 -0
index 185b547..eceff87 100644
@@ -1812,8 +1812,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 = {
Signature · 1 line
1.6.0.6
#2 lore raw

PATCH 2/24 xen: separate p2m allocation from setting

In reply to Jeremy Fitzhardinge

From: Jeremy Fitzhardinge <[email protected]>

When doing very early p2m setting, we need to separate setting from allocation, so split things up accordingly.

---
 arch/x86/xen/mmu.c |   61 +++++++++++++++++++++++++++++++++++++--------------
 arch/x86/xen/mmu.h |    3 ++
 2 files changed, 47 insertions(+), 17 deletions(-)
arch/x86/xen/mmu.c +44 -17
index eceff87..d534986 100644
@@ -233,47 +233,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)
arch/x86/xen/mmu.h +3 -0
index 24d1b44..da73026 100644
@@ -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);
 
 
Signature · 1 line
1.6.0.6
#3 lore raw

PATCH 3/24 xen: dynamically allocate p2m tables

In reply to Jeremy Fitzhardinge

From: Jeremy Fitzhardinge <[email protected]>

Saves about 128k static object size.

---
 arch/x86/xen/mmu.c |   38 +++++++++++++++++++++++++++++---------
 1 files changed, 29 insertions(+), 9 deletions(-)
arch/x86/xen/mmu.c +29 -9
index d534986..05280b4 100644
@@ -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,18 +179,28 @@ 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)
 {
 	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]);
 	}
@@ -206,12 +212,26 @@ 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);
Signature · 1 line
1.6.0.6
#4 lore raw

PATCH 4/24 xen: split construction of p2m mfn tables from registration

In reply to Jeremy Fitzhardinge

From: Jeremy Fitzhardinge <[email protected]>

Build the p2m_mfn_list_list early with the rest of the p2m table, but register it later when the real shared_info structure is in place.

---
 arch/x86/xen/mmu.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)
arch/x86/xen/mmu.c +6 -1
index 05280b4..2d30b74 100644
@@ -187,7 +187,7 @@ 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;
 
@@ -204,7 +204,10 @@ void xen_setup_mfn_list_list(void)
 		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 =
@@ -238,6 +241,8 @@ void __init xen_build_dynamic_phys_to_machine(void)
 
 		p2m_top[topidx] = &mfn_list[pfn];
 	}
+
+	xen_build_mfn_list_list();
 }
 
 unsigned long get_phys_to_machine(unsigned long pfn)
Signature · 1 line
1.6.0.6
#5 lore raw

PATCH 5/24 xen: clean up xen_load_gdt

In reply to Jeremy Fitzhardinge

From: Jeremy Fitzhardinge <[email protected]>

Makes the logic a bit clearer.

---
 arch/x86/xen/enlighten.c |   15 +++++++++++++--
 1 files changed, 13 insertions(+), 2 deletions(-)
arch/x86/xen/enlighten.c +13 -2
index 70b355d..5776dc2 100644
@@ -301,10 +301,21 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
 	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));
Signature · 1 line
1.6.0.6
#6 lore raw

PATCH 6/24 xen: make xen_load_gdt simpler

In reply to Jeremy Fitzhardinge

From: Jeremy Fitzhardinge <[email protected]>

Remove use of multicall machinery which is unused (gdt loading is never performance critical). This removes the implicit use of percpu variables, which simplifies understanding how the percpu code's use of load_gdt interacts with this code.

---
 arch/x86/xen/enlighten.c |   14 ++++++--------
 1 files changed, 6 insertions(+), 8 deletions(-)
arch/x86/xen/enlighten.c +6 -8
index 5776dc2..48b399b 100644
@@ -284,12 +284,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,9 +296,6 @@ 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++) {
 		int level;
 		pte_t *ptep = lookup_address(va, &level);
@@ -314,13 +310,15 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
 
 		frames[f] = mfn;
 
+		printk("xen_load_gdt: %d va=%p mfn=%lx pfn=%lx va'=%p\n",
+		       f, (void *)va, mfn, pfn, virt);
+
 		make_lowmem_page_readonly((void *)va);
 		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,
Signature · 1 line
1.6.0.6
#7 lore raw

PATCH 7/24 xen: remove xen_load_gdt debug

In reply to Jeremy Fitzhardinge

From: Jeremy Fitzhardinge <[email protected]>

Don't need the noise.

---
 arch/x86/xen/enlighten.c |    3 ---
 1 files changed, 0 insertions(+), 3 deletions(-)
arch/x86/xen/enlighten.c +0 -3
index 48b399b..75b7a0f 100644
@@ -310,9 +310,6 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
 
 		frames[f] = mfn;
 
-		printk("xen_load_gdt: %d va=%p mfn=%lx pfn=%lx va'=%p\n",
-		       f, (void *)va, mfn, pfn, virt);
-
 		make_lowmem_page_readonly((void *)va);
 		make_lowmem_page_readonly(virt);
 	}
Signature · 1 line
1.6.0.6
#8 lore raw

PATCH 8/24 xen: reserve i386 Xen pagetables

In reply to Jeremy Fitzhardinge

From: Jeremy Fitzhardinge <[email protected]>

Make sure the Xen-provided pagetables are reserved on x86-32.

---
 arch/x86/xen/mmu.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
arch/x86/xen/mmu.c +5 -0
index 2d30b74..065fe8d 100644
@@ -1789,6 +1789,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 */
Signature · 1 line
1.6.0.6
#9 lore raw

PATCH 9/24 NULL noise: arch/x86/xen/smp.c

In reply to Jeremy Fitzhardinge

From: Hannes Eder <[email protected]>

Fix this sparse warnings:
arch/x86/xen/smp.c:316:52: warning: Using plain integer as NULL pointer arch/x86/xen/smp.c:421:60: warning: Using plain integer as NULL pointer

---
 arch/x86/xen/smp.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
arch/x86/xen/smp.c +2 -2
index 8d47056..304d832 100644
@@ -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;
 		}
 	}
Signature · 1 line
1.6.0.6
#10 lore raw

PATCH 10/24 xen: mask XSAVE from cpuid

In reply to Jeremy Fitzhardinge

From: Jeremy Fitzhardinge <[email protected]>

Xen leaves XSAVE set in cpuid, but doesn't allow cr4.OSXSAVE to be set. This confuses the kernel and it ends up crashing on an xsetbv instruction.

At boot time, try to set cr4.OSXSAVE, and mask XSAVE out of cpuid it we can't. This will produce a spurious error from Xen, but allows us to support XSAVE if/when Xen does.

This also factors out the cpuid mask decisions to boot time.

---
 arch/x86/xen/enlighten.c |   50 ++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 44 insertions(+), 6 deletions(-)
arch/x86/xen/enlighten.c +44 -6
index 75b7a0f..da33e0c 100644
@@ -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);
@@ -901,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.
Signature · 1 line
1.6.0.6
#11 lore raw

Re: [Xen-devel] [PATCH 10/24] xen: mask XSAVE from cpuid

Quoted 10 lines
Quoted 1 line
Quoted 1 line

Jeremy Fitzhardinge <[email protected]> 13.03.09 09:11 >>>

From: Jeremy Fitzhardinge <[email protected]>

Xen leaves XSAVE set in cpuid, but doesn't allow cr4.OSXSAVE to be set. This confuses the kernel and it ends up crashing on an xsetbv instruction.

At boot time, try to set cr4.OSXSAVE, and mask XSAVE out of cpuid it we can't. This will produce a spurious error from Xen, but allows us to support XSAVE if/when Xen does.

As pointed out on an earlier thread, it seems inappropriate to do probing like this when there is a cpuid feature flag (osxsave) that can be used to determine whether XSAVE can be used. And even without that flag, simply reading CR4 and checking whether osxsave is set there would suffice. This is under the assumption that Xen's to-be-done implementation of XSAVE support would match that of FXSAVE (Xen turns its support on unconditionally and for all [pv] guests).

Jan

#12 lore raw

Re: [Xen-devel] [PATCH 10/24] xen: mask XSAVE from cpuid

Quoted 7 lines · Jan Beulich

As pointed out on an earlier thread, it seems inappropriate to do probing like this when there is a cpuid feature flag (osxsave) that can be used to determine whether XSAVE can be used. And even without that flag, simply reading CR4 and checking whether osxsave is set there would suffice. This is under the assumption that Xen's to-be-done implementation of XSAVE support would match that of FXSAVE (Xen turns its support on unconditionally and for all [pv] guests).

I didn't want to make too many assumptions about how Xen's XSAVE support would look. In particular, I thought it might virtualize the state of OSXSAVE to give the guest the honour of appearing to enable it. A guest kernel may get confused if it starts with OSXSAVE set, as it may use it to control its own init logic.

J

#13 lore raw

Re: [Xen-devel] [PATCH 10/24] xen: mask XSAVE from cpuid

Quoted 11 lines · Jeremy Fitzhardinge
Quoted 9 lines · Jan Beulich

As pointed out on an earlier thread, it seems inappropriate to do probing like this when there is a cpuid feature flag (osxsave) that can be used to
determine whether XSAVE can be used. And even without that flag, simply reading CR4 and checking whether osxsave is set there would suffice. This is under the assumption that Xen's to-be-done implementation
of XSAVE support would match that of FXSAVE (Xen turns its support on unconditionally and for all [pv] guests).

Quoted 5 lines

I didn't want to make too many assumptions about how Xen's XSAVE support would look. In particular, I thought it might virtualize the state of OSXSAVE to give the guest the honour of appearing to enable it. A guest kernel may get confused if it starts with OSXSAVE set, as it may use it to control its own init logic.

That wouldn't be an issue if you use the *native* CPUID to look for OSXSAVE early on, since such virtualization would only be visible though the PV interface, right?

It seems cleaner than probing, to be sure...

-hpa

Signature · 2 lines
H. Peter Anvin, Intel Open Source Technology Center
I work for Intel.  I don't speak on their behalf.
#14 lore raw

Re: [Xen-devel] [PATCH 10/24] xen: mask XSAVE from cpuid

Quoted 21 lines · H. Peter Anvin
Quoted 12 lines · Jeremy Fitzhardinge
Quoted 10 lines · Jan Beulich

As pointed out on an earlier thread, it seems inappropriate to do probing like this when there is a cpuid feature flag (osxsave) that can be used to
determine whether XSAVE can be used. And even without that flag, simply reading CR4 and checking whether osxsave is set there would suffice. This is under the assumption that Xen's to-be-done implementation
of XSAVE support would match that of FXSAVE (Xen turns its support on unconditionally and for all [pv] guests).

Quoted 6 lines

I didn't want to make too many assumptions about how Xen's XSAVE support would look. In particular, I thought it might virtualize the state of OSXSAVE to give the guest the honour of appearing to enable it. A guest kernel may get confused if it starts with OSXSAVE set, as it may use it to control its own init logic.

Quoted 6 lines

That wouldn't be an issue if you use the *native* CPUID to look for OSXSAVE early on, since such virtualization would only be visible though the PV interface, right?

It seems cleaner than probing, to be sure...

Well, at the moment the problem is that cpuid (both PV and native) show XSAVE, but Xen prevents cr4.OSXSAVE from being set, crashing the kernel. There's now a patch in Xen to mask XSAVE in CPUID, so that guests don't try to use it; the patch in the kernel is just to support non-bleeding-edge versions of Xen.

There have been some patches floating around for Xen support of XSAVE, but I think there are some issues with the variable-sized CPU context and save/restore/migrate, so they've been put on the backburner until there's a real need for them. I haven't looked at them, but I wouldn't have assumed that Xen would necessarily set OSXSAVE for itself, or require guests to do so (if a guest can make do with a simpler CPU context structure, then that might be simpler for things like cross-architecture migration, etc). I think that the only safe assumption is that XSAVE is available iff cpuid.XSAVE is set, modulo the bug mentioned above.

I guess if we support XSAVE for any vcpu, all the pcpus must have OSXSAVE set, and we rely on the fact that the XSAVE format is compatible with FXSAVE where they overlap. But I really don't know what happens when guests use xsetbv and how that might be virtualized/paravirtualized.

J

#15 lore raw

Re: [Xen-devel] [PATCH 10/24] xen: mask XSAVE from cpuid

Quoted 26 lines · On Sun, 15 Mar 2009 14:03:10 -0700 Jeremy Fitzhardinge <[email protected]> wrote:
Quoted 25 lines · H. Peter Anvin
Quoted 12 lines · Jeremy Fitzhardinge
Quoted 10 lines · Jan Beulich

As pointed out on an earlier thread, it seems inappropriate to do probing like this when there is a cpuid feature flag (osxsave) that can be used to
determine whether XSAVE can be used. And even without that flag, simply reading CR4 and checking whether osxsave is set there would suffice. This is under the assumption that Xen's to-be-done implementation
of XSAVE support would match that of FXSAVE (Xen turns its support on unconditionally and for all [pv] guests).

Quoted 6 lines

I didn't want to make too many assumptions about how Xen's XSAVE support would look. In particular, I thought it might virtualize the state of OSXSAVE to give the guest the honour of appearing to enable it. A guest kernel may get confused if it starts with OSXSAVE set, as it may use it to control its own init logic.

That wouldn't be an issue if you use the *native* CPUID to look for OSXSAVE early on, since such virtualization would only be visible though the PV interface, right?

Quoted 8 lines
Quoted 2 lines

It seems cleaner than probing, to be sure...

Well, at the moment the problem is that cpuid (both PV and native) show XSAVE, but Xen prevents cr4.OSXSAVE from being set, crashing the kernel. There's now a patch in Xen to mask XSAVE in CPUID, so that guests don't try to use it; the patch in the kernel is just to support non-bleeding-edge versions of Xen.

This is indicative of something that might be a huge bug in Xen:
Xen should never ever pass through CPUID bits it does not know. If Xen does not honor that, there is a fundamental and eternally recurring problem.... every time something new gets introduced Xen likely breaks.

Signature · 3 lines
Arjan van de Ven 	Intel Open Source Technology Centre
For development, discussion and tips for power savings, 
visit http://www.lesswatts.org
#16 lore raw

Re: [Xen-devel] [PATCH 10/24] xen: mask XSAVE from cpuid

Quoted 5 lines · Arjan van de Ven

This is indicative of something that might be a huge bug in Xen:
Xen should never ever pass through CPUID bits it does not know. If Xen does not honor that, there is a fundamental and eternally recurring problem.... every time something new gets introduced Xen likely breaks.

Yes, I'd agree; Xen should whitelist cpu capabilities rather than blacklist them. Jan expressed the opposite opinion (on the grounds that it precludes using features which don't require special OS or hypervisor support without Xen modifications). But if its just a matter of sticking a bit into a mask, its easy and quick to roll a new version of Xen (esp since it can generally be done before CPUs with the new feature get into people's hands).

J

#17 lore raw

Re: [Xen-devel] [PATCH 10/24] xen: mask XSAVE from cpuid

Quoted 11 lines · On Sun, 15 Mar 2009 17:05:26 -0700 Jeremy Fitzhardinge <[email protected]> wrote:
Quoted 5 lines · Arjan van de Ven

This is indicative of something that might be a huge bug in Xen:
Xen should never ever pass through CPUID bits it does not know. If Xen does not honor that, there is a fundamental and eternally recurring problem.... every time something new gets introduced Xen likely breaks.

Yes, I'd agree; Xen should whitelist cpu capabilities rather than blacklist them. Jan expressed the opposite opinion (on the grounds that it precludes using features which don't require special OS or hypervisor support without Xen modifications).

Well.. pretty much all new instructions need Xen modifications due to the need to be emulate to deal with traps/vmexits/etc right? So I don't quite see many cpuid bits that would NOT involve some Xen modification or another ;)

Signature · 3 lines
Arjan van de Ven 	Intel Open Source Technology Centre
For development, discussion and tips for power savings, 
visit http://www.lesswatts.org
#18 lore raw

Re: [Xen-devel] [PATCH 10/24] xen: mask XSAVE from cpuid

Quoted 6 lines · Arjan van de Ven

Well.. pretty much all new instructions need Xen modifications due to the need to be emulate to deal with traps/vmexits/etc right? So I don't quite see many cpuid bits that would NOT involve some Xen modification or another ;)

There are going to be a very small number which need only userspace support. However, there will be absolutely no way for Xen to know this a priori.

-hpa

Signature · 2 lines
H. Peter Anvin, Intel Open Source Technology Center
I work for Intel.  I don't speak on their behalf.
#19 lore raw

Re: [Xen-devel] [PATCH 10/24] xen: mask XSAVE from cpuid

In reply to Arjan van de Ven
Quoted 5 lines
Quoted 1 line
Quoted 1 line

Arjan van de Ven <[email protected]> 16.03.09 01:09 >>>

Well.. pretty much all new instructions need Xen modifications due to the need to be emulate to deal with traps/vmexits/etc right? So I don't quite see many cpuid bits that would NOT involve some Xen modification or another ;)

No, new (user-mode accessible) instructions represent precisely the kind of extension that do not require hypervisor (or OS) awareness (see SSE2 etc, AES, FMA). New registers otoh are examples of where awareness is needed (SSE, AVX), as would be new privileged instructions.

Jan

#20 lore raw

Re: [Xen-devel] [PATCH 10/24] xen: mask XSAVE from cpuid

Quoted 9 lines · On Mon, 16 Mar 2009 14:16:32 +0000 "Jan Beulich" <[email protected]> wrote:
Quoted 5 lines
Quoted 1 line
Quoted 1 line

Arjan van de Ven <[email protected]> 16.03.09 01:09 >>>

Well.. pretty much all new instructions need Xen modifications due to the need to be emulate to deal with traps/vmexits/etc right? So I don't quite see many cpuid bits that would NOT involve some Xen modification or another ;)

No, new (user-mode accessible) instructions represent precisely the kind of extension that do not require hypervisor (or OS) awareness (see SSE2 etc, AES, FMA).

so Xen doesn't need to handle a case where the kernel does AES on uncached IO memory ?

Signature · 3 lines
Arjan van de Ven 	Intel Open Source Technology Centre
For development, discussion and tips for power savings, 
visit http://www.lesswatts.org
#21 lore raw

Re: [Xen-devel] [PATCH 10/24] xen: mask XSAVE from cpuid

In reply to Jan Beulich
Quoted 10 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line

Arjan van de Ven <[email protected]> 16.03.09 01:09 >>>

Well.. pretty much all new instructions need Xen modifications due to the need to be emulate to deal with traps/vmexits/etc right? So I don't quite see many cpuid bits that would NOT involve some Xen modification or another ;)

No, new (user-mode accessible) instructions represent precisely the kind of extension that do not require hypervisor (or OS) awareness (see SSE2 etc, AES, FMA). New registers otoh are examples of where awareness is needed (SSE, AVX), as would be new privileged instructions.

Whey would another hypothetical FP register extension need Xen support once it gets proper XSAVE support? I can't think of a reason why (assuming XSAVE support) it would need to know of a new kind of FP register or similar. They very likely won't appear in any instructions that need mmio. Or are you worried about the real mode emulator?

-Andi

Signature · 1 line
[email protected] -- Speaking for myself only.
#22 lore raw

Re: [Xen-devel] [PATCH 10/24] xen: mask XSAVE from cpuid

Quoted 12 lines · Andi Kleen
Quoted 9 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line

Arjan van de Ven <[email protected]> 16.03.09 01:09 >>>

Well.. pretty much all new instructions need Xen modifications due to the need to be emulate to deal with traps/vmexits/etc right? So I don't quite see many cpuid bits that would NOT involve some Xen modification or another ;)

No, new (user-mode accessible) instructions represent precisely the kind of extension that do not require hypervisor (or OS) awareness (see SSE2 etc, AES, FMA). New registers otoh are examples of where awareness is needed (SSE, AVX), as would be new privileged instructions.

Quoted 7 lines

Whey would another hypothetical FP register extension need Xen support once it gets proper XSAVE support? I can't think of a reason why (assuming XSAVE support) it would need to know of a new kind of FP register or similar. They very likely won't appear in any instructions that need mmio. Or are you worried about the real mode emulator?

The point is YOU DON'T KNOW. In particular, there might be new traps, there might be new state, there might be new MSRs, there might be new control bits... anything. Therefore, you cannot blindly pass the bit on, even though XSAVE solves one part of the problem.

-hpa

Signature · 2 lines
H. Peter Anvin, Intel Open Source Technology Center
I work for Intel.  I don't speak on their behalf.
#23 lore raw

Re: [Xen-devel] [PATCH 10/24] xen: mask XSAVE from cpuid

Quoted 4 lines

The point is YOU DON'T KNOW. In particular, there might be new traps, there might be new state, there might be new MSRs, there might be new control bits... anything. Therefore, you cannot blindly pass the bit on, even though XSAVE solves one part of the problem.

I think what will happen if you don't expose it is that there will be always hypervisors which are behind and applications/OS will end up doing probing for opcodes instead of trusting CPUID bits.

Probably not what you intended.

-Andi

Signature · 1 line
[email protected] -- Speaking for myself only.
#24 lore raw

Re: [Xen-devel] [PATCH 10/24] xen: mask XSAVE from cpuid

Quoted 11 lines · Andi Kleen
Quoted 4 lines

The point is YOU DON'T KNOW. In particular, there might be new traps, there might be new state, there might be new MSRs, there might be new control bits... anything. Therefore, you cannot blindly pass the bit on, even though XSAVE solves one part of the problem.

I think what will happen if you don't expose it is that there will be always hypervisors which are behind and applications/OS will end up doing probing for opcodes instead of trusting CPUID bits.

Probably not what you intended.

Probing for opcodes is even more harmful, though. But yes, we don't have a good answer to this, and I believe we *can't* have a good answer to this either -- we could architect the CPUID instruction a bit differently, but that doesn't account for the various needs of differnent hypervisors.

Hypervisor vendors can of course make this easier by making their CPUID code pluggable so the end user can "hotfix" upgrade it without upgrading the hypervisor (which makes a lot of them nervous.)

-hpa

Signature · 2 lines
H. Peter Anvin, Intel Open Source Technology Center
I work for Intel.  I don't speak on their behalf.
#25 lore raw

Re: [Xen-devel] [PATCH 10/24] xen: mask XSAVE from cpuid

In reply to Andi Kleen
Quoted 6 lines · On Tue, 17 Mar 2009 12:56:21 +0100 Andi Kleen <[email protected]> wrote:
Quoted 5 lines

The point is YOU DON'T KNOW. In particular, there might be new traps, there might be new state, there might be new MSRs, there might be new control bits... anything. Therefore, you cannot blindly pass the bit on, even though XSAVE solves one part of the problem.

Quoted 6 lines

I think what will happen if you don't expose it is that there will be always hypervisors which are behind and applications/OS will end up doing probing for opcodes instead of trusting CPUID bits.

Probably not what you intended.

well the choice fundamentally is
1) Have correct applications work, even though you might not always get all new features that the hardware could have done.. at the expense that someone who wants to do horrible things can
2) Have all latest features always there, but break correctly written apps/oses every 2 years.

I'd go for option 1 any day of the week, hands down. Esp if the "cpu cloaking" kind of things really disable the instructions... but even without.

Signature · 3 lines
Arjan van de Ven 	Intel Open Source Technology Centre
For development, discussion and tips for power savings, 
visit http://www.lesswatts.org
#26 lore raw

Re: [Xen-devel] [PATCH 10/24] xen: mask XSAVE from cpuid

Quoted 6 lines

well the choice fundamentally is
1) Have correct applications work, even though you might not always get all new features that the hardware could have done.. at the expense that someone who wants to do horrible things can
2) Have all latest features always there, but break correctly written apps/oses every 2 years.

I'm not sure there will be that much breakage. It seems more like a theoretical danger.

Quoted 4 lines

I'd go for option 1 any day of the week, hands down. Esp if the "cpu cloaking" kind of things really disable the instructions... but even without.

With cpu cloaking and disabling unknown instructions it would be fine to go conservative. But that's not what is being proposed.

-Andi

Signature · 1 line
[email protected] -- Speaking for myself only.
#27 lore raw

Re: [Xen-devel] [PATCH 10/24] xen: mask XSAVE from cpuid

In reply to Andi Kleen
Quoted 14 lines
Quoted 1 line
Quoted 1 line

Andi Kleen <[email protected]> 17.03.09 00:59 >>>

Quoted 10 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line

Arjan van de Ven <[email protected]> 16.03.09 01:09 >>>

Well.. pretty much all new instructions need Xen modifications due to the need to be emulate to deal with traps/vmexits/etc right? So I don't quite see many cpuid bits that would NOT involve some Xen modification or another ;)

No, new (user-mode accessible) instructions represent precisely the kind of extension that do not require hypervisor (or OS) awareness (see SSE2 etc, AES, FMA). New registers otoh are examples of where awareness is needed (SSE, AVX), as would be new privileged instructions.

Quoted 6 lines

Whey would another hypothetical FP register extension need Xen support once it gets proper XSAVE support? I can't think of a reason why (assuming XSAVE support) it would need to know of a new kind of FP register or similar. They very likely won't appear in any instructions that need mmio. Or are you worried about the real mode emulator?

No, properly coded xsave support will (hopefully) make user-visible context extensions transparent to hypervisor and OS. But I was giving a general example here, and the change from xmm to ymm registers is one that does need hypervisor (and OS) changes.

Jan

#28 lore raw

Re: [Xen-devel] [PATCH 10/24] xen: mask XSAVE from cpuid

Quoted 4 lines

No, properly coded xsave support will (hopefully) make user-visible context extensions transparent to hypervisor and OS. But I was giving a general example here, and the change from xmm to ymm registers is one that does need hypervisor (and OS) changes.

Again except for XSAVE support it doesn't, does it?

-Andi

#29 lore raw

Re: [Xen-devel] [PATCH 10/24] xen: mask XSAVE from cpuid

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

Andi Kleen <[email protected]> 17.03.09 11:48 >>>

No, properly coded xsave support will (hopefully) make user-visible context extensions transparent to hypervisor and OS. But I was giving a general example here, and the change from xmm to ymm registers is one that does need hypervisor (and OS) changes.

Again except for XSAVE support it doesn't, does it?

No, it shouldn't (minus the valid comments hpa added in another reply).

Jan

#30 lore raw

PATCH 11/24 xen: add FIX_TEXT_POKE to fixmap

In reply to Jeremy Fitzhardinge

From: Jeremy Fitzhardinge <[email protected]>

FIX_TEXT_POKE[01] are used to map kernel addresses, so they're mapping pfns, not mfns.

---
 arch/x86/xen/mmu.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
arch/x86/xen/mmu.c +3 -0
index 065fe8d..8969353 100644
@@ -1821,6 +1821,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;
 
Signature · 1 line
1.6.0.6
#31 lore raw

PATCH 12/24 x86-64: remove PGE from must-have feature list

In reply to Jeremy Fitzhardinge

From: Jeremy Fitzhardinge <[email protected]>

PGE may not be available when running paravirtualized, so test the cpuid bit before using it.

---
 arch/x86/include/asm/required-features.h |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
arch/x86/include/asm/required-features.h +1 -1
index d5cd6c5..a4737dd 100644
@@ -50,7 +50,7 @@
 #ifdef CONFIG_X86_64
 #define NEED_PSE	0
 #define NEED_MSR	(1<<(X86_FEATURE_MSR & 31))
-#define NEED_PGE	(1<<(X86_FEATURE_PGE & 31))
+#define NEED_PGE	0
 #define NEED_FXSR	(1<<(X86_FEATURE_FXSR & 31))
 #define NEED_XMM	(1<<(X86_FEATURE_XMM & 31))
 #define NEED_XMM2	(1<<(X86_FEATURE_XMM2 & 31))
Signature · 1 line
1.6.0.6
#32 lore raw

Re: [PATCH 12/24] x86-64: remove PGE from must-have feature list

Quoted 15 lines · Jeremy Fitzhardinge

From: Jeremy Fitzhardinge <[email protected]>

PGE may not be available when running paravirtualized, so test the cpuid bit before using it.

---
 arch/x86/include/asm/required-features.h |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
arch/x86/include/asm/required-features.h +0 -0
index d5cd6c5..a4737dd 100644

arch/x86/include/asm/required-features.h line 56

Quoted 8 lines
arch/x86/include/asm/required-features.h +1 -1
@@ -50,7 +50,7 @@
 #ifdef CONFIG_X86_64
 #define NEED_PSE	0
 #define NEED_MSR	(1<<(X86_FEATURE_MSR & 31))
-#define NEED_PGE	(1<<(X86_FEATURE_PGE & 31))
+#define NEED_PGE	0
 #define NEED_FXSR	(1<<(X86_FEATURE_FXSR & 31))
 #define NEED_XMM	(1<<(X86_FEATURE_XMM & 31))
 #define NEED_XMM2	(1<<(X86_FEATURE_XMM2 & 31))

This should be conditionalized on CONFIG_PARAVIRT, since doing this removes real-hardware optimimizations.

-hpa

Signature · 2 lines
H. Peter Anvin, Intel Open Source Technology Center
I work for Intel.  I don't speak on their behalf.
#33 lore raw

Re: [PATCH 12/24] x86-64: remove PGE from must-have feature list

Quoted 7 lines · H. Peter Anvin
Quoted 7 lines
arch/x86/include/asm/required-features.h +0 -1
@@ -50,7 +50,7 @@
 #ifdef CONFIG_X86_64
 #define NEED_PSE	0
 #define NEED_MSR	(1<<(X86_FEATURE_MSR & 31))
-#define NEED_PGE	(1<<(X86_FEATURE_PGE & 31))
Quoted 9 lines

arch/x86/include/asm/required-features.h line 56

Quoted 5 lines
arch/x86/include/asm/required-features.h +1 -0
+#define NEED_PGE	0
 #define NEED_FXSR	(1<<(X86_FEATURE_FXSR & 31))
 #define NEED_XMM	(1<<(X86_FEATURE_XMM & 31))
 #define NEED_XMM2	(1<<(X86_FEATURE_XMM2 & 31))

This should be conditionalized on CONFIG_PARAVIRT, since doing this removes real-hardware optimimizations.

OK. Can do the same for PSE.

J

#34 lore raw

PATCH 13/24 Xen: Add virt_to_pfn helper function

In reply to Jeremy Fitzhardinge

From: Alex Nixon <[email protected]>

---
 arch/x86/include/asm/xen/page.h |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
arch/x86/include/asm/xen/page.h +2 -1
index 1a918dd..018a0a4 100644
@@ -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)
Signature · 1 line
1.6.0.6
#35 lore raw

PATCH 14/24 xen: add irq_from_evtchn

In reply to Jeremy Fitzhardinge

From: 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
index 30963af..1cd2a0e 100644
@@ -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
index 0d5f1ad..e68d59a 100644
@@ -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
#36 lore raw

PATCH 15/24 xen: add /dev/xen/evtchn driver

In reply to Jeremy Fitzhardinge

From: 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
index 526187c..1bbb910 100644
@@ -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
index ff8accc..1567639 100644
@@ -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/
\ No newline at end of file
+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
#37 lore raw

PATCH 16/24 xen: export ioctl headers to userspace

In reply to Jeremy Fitzhardinge

From: 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
index d8c3e3c..fe36acc 100644
@@ -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
new file mode 100644
index 0000000..4e65c16
@@ -0,0 +1 @@
+header-y += evtchn.h
Signature · 1 line
1.6.0.6
#38 lore raw

PATCH 17/24 xen/dev-evtchn: clean up locking in evtchn

In reply to Jeremy Fitzhardinge

From: 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
index 517b9ee..af03195 100644
@@ -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
#39 lore raw

PATCH 18/24 xen: add "capabilities" file

In reply to Jeremy Fitzhardinge

The 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
index 515741a..6559e0c 100644
@@ -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
#40 lore raw

PATCH 19/24 xen: add /sys/hypervisor support

In reply to Jeremy Fitzhardinge

From: 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
index 526187c..88bca1c 100644
@@ -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.
\ No newline at end of file
drivers/xen/Makefile +2 -1
index ff8accc..f3603a3 100644
@@ -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/
\ No newline at end of file
+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
index 453235e..e8b6519 100644
@@ -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
#41 lore raw

PATCH 20/24 xen/sys/hypervisor: change writable_pt to features

In reply to Jeremy Fitzhardinge

From: 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
index cb29d1c..1267d6f 100644
@@ -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
#42 lore raw

PATCH 21/24 xen: drop kexec bits from /sys/hypervisor since kexec isn't implemented yet

In reply to Jeremy Fitzhardinge

From: Ian Campbell <[email protected]>

I needed this to compile since there is no kexec yet in pvops kernel
CC drivers/xen/sys-hypervisor.o
drivers/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
index 1267d6f..88a60e0 100644
@@ -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
#43 lore raw

PATCH 22/24 xen: remove suspend_cancel hook

In reply to Jeremy Fitzhardinge

From: 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
index 773d1cf..bd20361 100644
@@ -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
index f87f961..0836772 100644
@@ -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
#44 lore raw

Re: [Xen-devel] [PATCH 22/24] xen: remove suspend_cancel hook

Quoted 8 lines
Quoted 1 line
Quoted 1 line

Jeremy Fitzhardinge <[email protected]> 13.03.09 09:11 >>>

From: Ian Campbell <[email protected]>

Remove suspend_cancel hook from xenbus_driver, in preparation for using the device model for suspending.

Does that mean that there are no intentions to ever support the accelerator stuff found in the 2.6.18-based Xenified Linux tree? That was the apparent only user of the cancel hook...

Jan

#45 lore raw

Re: [Xen-devel] [PATCH 22/24] xen: remove suspend_cancel hook

Quoted 4 lines · Jan Beulich

Does that mean that there are no intentions to ever support the accelerator stuff found in the 2.6.18-based Xenified Linux tree? That was the apparent only user of the cancel hook...

I don't have any immediate plan to merge it myself, but I'm sure we can either add this back or otherwise work out how to implement it in the pvops kernel.

J

#46 lore raw

PATCH 23/24 xen: use device model for suspending xenbus devices

In reply to Jeremy Fitzhardinge

From: 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
index 3ccd348..0489ea2 100644
@@ -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
index bd20361..4649213 100644
@@ -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
index e325eab..eab33f1 100644
@@ -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
index 0836772..b9763ba 100644
@@ -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
#47 lore raw

Re: [Xen-devel] [PATCH 23/24] xen: use device model for suspendingxenbus devices

Quoted 1 line
Quoted 1 line
Quoted 1 line

Jeremy Fitzhardinge <[email protected]> 13.03.09 09:11 >>>

Shouldn't this also include removing the explicit calls to gnttab_{suspend,resume}() in favor of making gnttab a sysdev?

Jan

#48 lore raw

PATCH 24/24 xen/xenbus: export xenbus_dev_changed

In reply to Jeremy Fitzhardinge
---
 drivers/xen/xenbus/xenbus_probe.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
drivers/xen/xenbus/xenbus_probe.c +1 -0
index 4649213..d42e25d 100644
@@ -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