From: jbeulich@novell.com
Subject: no need to build certain bits when building non-privileged kernel
Patch-mainline: n/a

--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -680,6 +680,7 @@ config APB_TIMER
 config DMI
 	default y
 	bool "Enable DMI scanning" if EXPERT
+	depends on !XEN_UNPRIVILEGED_GUEST
 	---help---
 	  Enabled scanning of DMI to identify machine quirks. Say Y
 	  here unless you have verified that your setup is not
@@ -761,6 +762,7 @@ config AMD_IOMMU_STATS
 # need this always selected by IOMMU for the VIA workaround
 config SWIOTLB
 	def_bool y if X86_64 || XEN
+	prompt "Software I/O TLB" if XEN_UNPRIVILEGED_GUEST && !XEN_PCIDEV_FRONTEND
 	---help---
 	  Support for software bounce buffers used on x86-64 systems
 	  which don't have a hardware IOMMU (e.g. the current generation
@@ -2014,13 +2016,15 @@ config PCI_GOBIOS
 
 config PCI_GOMMCONFIG
 	bool "MMConfig"
+	depends on !XEN_UNPRIVILEGED_GUEST
 
 config PCI_GODIRECT
 	bool "Direct"
+	depends on !XEN_UNPRIVILEGED_GUEST
 
 config PCI_GOOLPC
 	bool "OLPC XO-1"
-	depends on OLPC
+	depends on OLPC && !XEN_UNPRIVILEGED_GUEST
 
 config PCI_GOXEN_FE
 	bool "Xen PCI Frontend"
@@ -2031,6 +2035,7 @@ config PCI_GOXEN_FE
 
 config PCI_GOANY
 	bool "Any"
+	depends on !XEN_UNPRIVILEGED_GUEST
 
 endchoice
 
@@ -2221,7 +2226,7 @@ endif # X86_32
 
 config AMD_NB
 	def_bool y
-	depends on CPU_SUP_AMD && PCI
+	depends on CPU_SUP_AMD && PCI && !XEN_UNPRIVILEGED_GUEST
 
 source "drivers/pcmcia/Kconfig"
 
--- a/arch/x86/Kconfig.debug
+++ b/arch/x86/Kconfig.debug
@@ -33,6 +33,7 @@ config X86_VERBOSE_BOOTUP
 
 config EARLY_PRINTK
 	bool "Early printk" if EXPERT
+	depends on !XEN_UNPRIVILEGED_GUEST
 	default y
 	---help---
 	  Write kernel log output directly into the VGA buffer or to a serial
--- a/arch/x86/include/mach-xen/asm/swiotlb.h
+++ b/arch/x86/include/mach-xen/asm/swiotlb.h
@@ -1,4 +1,8 @@
 #include_next <asm/swiotlb.h>
 
+#ifndef CONFIG_SWIOTLB
+#define swiotlb_init(verbose) ((void)(verbose))
+#endif
+
 dma_addr_t swiotlb_map_single_phys(struct device *, phys_addr_t, size_t size,
 				   int dir);
--- a/drivers/input/keyboard/Kconfig
+++ b/drivers/input/keyboard/Kconfig
@@ -2,7 +2,7 @@
 # Input core configuration
 #
 menuconfig INPUT_KEYBOARD
-	bool "Keyboards" if EXPERT || !X86
+	bool "Keyboards" if EXPERT || !X86 || XEN_UNPRIVILEGED_GUEST
 	default y
 	help
 	  Say Y here, and a list of supported keyboards will be displayed.
@@ -67,7 +67,7 @@ config KEYBOARD_ATARI
 	  module will be called atakbd.
 
 config KEYBOARD_ATKBD
-	tristate "AT keyboard" if EXPERT || !X86
+	tristate "AT keyboard" if EXPERT || !X86 || XEN_UNPRIVILEGED_GUEST
 	default y
 	select SERIO
 	select SERIO_LIBPS2
--- a/drivers/input/serio/Kconfig
+++ b/drivers/input/serio/Kconfig
@@ -2,7 +2,7 @@
 # Input core configuration
 #
 config SERIO
-	tristate "Serial I/O support" if EXPERT || !X86
+	tristate "Serial I/O support" if EXPERT || !X86 || XEN_UNPRIVILEGED_GUEST
 	default y
 	help
 	  Say Yes here if you have any input device that uses serial I/O to
@@ -19,7 +19,7 @@ config SERIO
 if SERIO
 
 config SERIO_I8042
-	tristate "i8042 PC Keyboard controller" if EXPERT || !X86
+	tristate "i8042 PC Keyboard controller" if EXPERT || !X86 || XEN_UNPRIVILEGED_GUEST
 	default y
 	depends on !PARISC && (!ARM || ARCH_SHARK || FOOTBRIDGE_HOST) && \
 		   (!SUPERH || SH_CAYMAN) && !M68K && !BLACKFIN
--- a/drivers/pci/Kconfig
+++ b/drivers/pci/Kconfig
@@ -74,7 +74,7 @@ config PARAVIRT_XEN_PCIDEV_FRONTEND
 
 config XEN_PCIDEV_FRONTEND
 	def_bool y
-	prompt "Xen PCI Frontend" if X86_64
+	prompt "Xen PCI Frontend" if X86_64 && !XEN_UNPRIVILEGED_GUEST
 	depends on PCI && XEN && (PCI_GOXEN_FE || PCI_GOANY || X86_64)
 	select HOTPLUG
 	help
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -745,7 +745,7 @@ config FB_UVESA
 
 config FB_VESA
 	bool "VESA VGA graphics support"
-	depends on (FB = y) && X86
+	depends on (FB = y) && X86 && !XEN_UNPRIVILEGED_GUEST
 	select FB_CFB_FILLRECT
 	select FB_CFB_COPYAREA
 	select FB_CFB_IMAGEBLIT
--- a/drivers/xen/Kconfig
+++ b/drivers/xen/Kconfig
@@ -18,7 +18,8 @@ config XEN_PRIVILEGED_GUEST
 	  Support for privileged operation (domain 0)
 
 config XEN_UNPRIVILEGED_GUEST
-	def_bool !XEN_PRIVILEGED_GUEST
+	def_bool y
+	depends on !XEN_PRIVILEGED_GUEST
 	select PM
 	select SUSPEND
 
@@ -277,6 +278,7 @@ config XEN_USB_FRONTEND_HCD_PM
 
 config XEN_GRANT_DEV
 	tristate "User-space granted page access driver"
+	depends on XEN_BACKEND != n
 	default XEN_PRIVILEGED_GUEST
 	help
 	  Device for accessing (in user-space) pages that have been granted
--- a/drivers/xen/balloon/balloon.c
+++ b/drivers/xen/balloon/balloon.c
@@ -640,6 +640,9 @@ void balloon_update_driver_allowance(lon
 	bs.driver_pages += delta;
 	balloon_unlock(flags);
 }
+EXPORT_SYMBOL_GPL(balloon_update_driver_allowance);
+
+#if defined(CONFIG_XEN_BACKEND) || defined(CONFIG_XEN_BACKEND_MODULE)
 
 #ifdef CONFIG_XEN
 static int dealloc_pte_fn(
@@ -748,6 +751,7 @@ struct page **alloc_empty_pages_and_page
 	pagevec = NULL;
 	goto out;
 }
+EXPORT_SYMBOL_GPL(alloc_empty_pages_and_pagevec);
 
 void free_empty_pages_and_pagevec(struct page **pagevec, int nr_pages)
 {
@@ -768,6 +772,9 @@ void free_empty_pages_and_pagevec(struct
 
 	schedule_work(&balloon_worker);
 }
+EXPORT_SYMBOL_GPL(free_empty_pages_and_pagevec);
+
+#endif /* CONFIG_XEN_BACKEND */
 
 void balloon_release_driver_page(struct page *page)
 {
@@ -781,10 +788,6 @@ void balloon_release_driver_page(struct 
 
 	schedule_work(&balloon_worker);
 }
-
-EXPORT_SYMBOL_GPL(balloon_update_driver_allowance);
-EXPORT_SYMBOL_GPL(alloc_empty_pages_and_pagevec);
-EXPORT_SYMBOL_GPL(free_empty_pages_and_pagevec);
 EXPORT_SYMBOL_GPL(balloon_release_driver_page);
 
 MODULE_LICENSE("Dual BSD/GPL");
--- a/drivers/xen/console/console.c
+++ b/drivers/xen/console/console.c
@@ -45,7 +45,6 @@
 #include <linux/init.h>
 #include <linux/console.h>
 #include <linux/sysrq.h>
-#include <linux/screen_info.h>
 #include <linux/vt.h>
 #include <xen/interface/xen.h>
 #include <xen/interface/event_channel.h>
@@ -242,6 +241,7 @@ static int __init xen_console_init(void)
 }
 console_initcall(xen_console_init);
 
+#ifdef CONFIG_XEN_PRIVILEGED_GUEST
 /*** Useful function for console debugging -- goes straight to Xen. ***/
 int xprintk(const char *fmt, ...)
 {
@@ -259,6 +259,7 @@ int xprintk(const char *fmt, ...)
 
 	return 0;
 }
+#endif
 
 /*** Forcibly flush console data before dying. ***/
 void xencons_force_flush(void)
@@ -283,6 +284,9 @@ void xencons_force_flush(void)
 }
 
 
+#ifdef CONFIG_XEN_PRIVILEGED_GUEST
+#include <linux/screen_info.h>
+
 void __init dom0_init_screen_info(const struct dom0_vga_console_info *info, size_t size)
 {
 	/* This is drawn from a dump from vgacon:startup in
@@ -338,6 +342,7 @@ void __init dom0_init_screen_info(const 
 		break;
 	}
 }
+#endif
 
 
 /******************** User-space console driver (/dev/console) ************/
--- a/drivers/xen/console/xencons_ring.c
+++ b/drivers/xen/console/xencons_ring.c
@@ -89,7 +89,11 @@ static irqreturn_t handle_input(int irq,
 	return IRQ_HANDLED;
 }
 
-int xencons_ring_init(void)
+int
+#ifndef CONFIG_PM_SLEEP
+__init
+#endif
+xencons_ring_init(void)
 {
 	int irq;
 
--- a/drivers/xen/core/evtchn.c
+++ b/drivers/xen/core/evtchn.c
@@ -1892,6 +1892,7 @@ void evtchn_register_pirq(int irq)
 				      "fasteoi");
 }
 
+#ifdef CONFIG_PCI_MSI
 int evtchn_map_pirq(int irq, int xen_pirq)
 {
 	if (irq < 0) {
@@ -1957,6 +1958,7 @@ int evtchn_map_pirq(int irq, int xen_pir
 	}
 	return index_from_irq(irq) ? irq : -EINVAL;
 }
+#endif
 
 int evtchn_get_xen_pirq(int irq)
 {
--- a/drivers/xen/core/gnttab.c
+++ b/drivers/xen/core/gnttab.c
@@ -521,8 +521,6 @@ static inline unsigned int max_nr_grant_
 
 #ifdef CONFIG_XEN
 
-static DEFINE_SEQLOCK(gnttab_dma_lock);
-
 #ifdef CONFIG_X86
 static int map_pte_fn(pte_t *pte, struct page *pmd_page,
 		      unsigned long addr, void *data)
@@ -592,6 +590,10 @@ static int gnttab_map(unsigned int start
 	return 0;
 }
 
+#if defined(CONFIG_XEN_BACKEND) || defined(CONFIG_XEN_BACKEND_MODULE)
+
+static DEFINE_SEQLOCK(gnttab_dma_lock);
+
 static void gnttab_page_free(struct page *page, unsigned int order)
 {
 	BUG_ON(order);
@@ -725,6 +727,8 @@ void __gnttab_dma_map_page(struct page *
 	} while (unlikely(read_seqretry(&gnttab_dma_lock, seq)));
 }
 
+#endif /* CONFIG_XEN_BACKEND */
+
 #ifdef __HAVE_ARCH_PTE_SPECIAL
 
 static unsigned int GNTMAP_pte_special;
--- a/drivers/xen/privcmd/Makefile
+++ b/drivers/xen/privcmd/Makefile
@@ -1,3 +1,3 @@
-
-obj-y	+= privcmd.o
-obj-$(CONFIG_COMPAT)	+= compat_privcmd.o
+priv-$(CONFIG_COMPAT) := compat_privcmd.o
+obj-y := privcmd.o
+obj-$(CONFIG_XEN_PRIVILEGED_GUEST) += $(priv-y)
--- a/drivers/xen/privcmd/privcmd.c
+++ b/drivers/xen/privcmd/privcmd.c
@@ -39,6 +39,9 @@ static inline void _privcmd_hcall(bool s
 static struct proc_dir_entry *privcmd_intf;
 static struct proc_dir_entry *capabilities_intf;
 
+#ifndef CONFIG_XEN_PRIVILEGED_GUEST
+#define HAVE_ARCH_PRIVCMD_MMAP
+#endif
 #ifndef HAVE_ARCH_PRIVCMD_MMAP
 static int enforce_singleshot_mapping_fn(pte_t *pte, struct page *pmd_page,
 					 unsigned long addr, void *data)
@@ -86,12 +89,14 @@ static long privcmd_ioctl(struct file *f
 {
 	long ret;
 	void __user *udata = (void __user *) data;
+#ifdef CONFIG_XEN_PRIVILEGED_GUEST
 	unsigned long i, addr, nr, nr_pages;
 	struct mmapbatch_ctxt mbc;
 	struct mm_struct *mm = current->mm;
 	struct vm_area_struct *vma;
 	LIST_HEAD(pagelist);
 	struct list_head *l, *l2;
+#endif
 
 	switch (cmd) {
 	case IOCTL_PRIVCMD_HYPERCALL: {
@@ -119,6 +124,8 @@ static long privcmd_ioctl(struct file *f
 	}
 	break;
 
+#ifdef CONFIG_XEN_PRIVILEGED_GUEST
+
 	case IOCTL_PRIVCMD_MMAP: {
 #define MMAP_NR_PER_PAGE \
 	(unsigned long)((PAGE_SIZE - sizeof(*l)) / sizeof(*msg))
@@ -448,6 +455,8 @@ static long privcmd_ioctl(struct file *f
 	}
 	break;
 
+#endif /* CONFIG_XEN_PRIVILEGED_GUEST */
+
 	default:
 		ret = -EINVAL;
 		break;
@@ -486,7 +495,9 @@ static const struct file_operations priv
 	.open = nonseekable_open,
 	.llseek = no_llseek,
 	.unlocked_ioctl = privcmd_ioctl,
+#ifdef CONFIG_XEN_PRIVILEGED_GUEST
 	.mmap = privcmd_mmap,
+#endif
 };
 
 static int capabilities_read(char *page, char **start, off_t off,
--- a/drivers/xen/xenbus/xenbus_comms.c
+++ b/drivers/xen/xenbus/xenbus_comms.c
@@ -52,12 +52,12 @@
 
 static int xenbus_irq;
 
-static DECLARE_WORK(probe_work, xenbus_probe);
-
 static DECLARE_WAIT_QUEUE_HEAD(xb_waitq);
 
 static irqreturn_t wake_waiting(int irq, void *unused)
 {
+#ifdef CONFIG_XEN_PRIVILEGED_GUEST
+	static DECLARE_WORK(probe_work, xenbus_probe);
 	int old, new;
 
 	old = atomic_read(&xenbus_xsd_state);
@@ -85,6 +85,7 @@ static irqreturn_t wake_waiting(int irq,
 		schedule_work(&probe_work);
 
 wake:
+#endif
 	wake_up(&xb_waitq);
 	return IRQ_HANDLED;
 }
--- a/drivers/xen/xenbus/xenbus_probe.c
+++ b/drivers/xen/xenbus/xenbus_probe.c
@@ -92,7 +92,11 @@ static unsigned long xen_store_mfn;
 
 extern struct mutex xenwatch_mutex;
 
-static BLOCKING_NOTIFIER_HEAD(xenstore_chain);
+static
+#ifdef CONFIG_XEN_UNPRIVILEGED_GUEST
+__initdata
+#endif
+BLOCKING_NOTIFIER_HEAD(xenstore_chain);
 
 #if defined(CONFIG_XEN) || defined(MODULE)
 static void wait_for_devices(struct xenbus_driver *xendrv);
@@ -1084,7 +1088,13 @@ static void xenbus_reset_state(void)
 }
 #endif
 
-void xenbus_probe(struct work_struct *unused)
+void
+#if defined(CONFIG_XEN_UNPRIVILEGED_GUEST)
+__init
+#elif defined(MODULE)
+__devinit
+#endif
+xenbus_probe(struct work_struct *unused)
 {
 	BUG_ON(!is_xenstored_ready());
 
--- a/drivers/xen/xenbus/xenbus_probe_backend.c
+++ b/drivers/xen/xenbus/xenbus_probe_backend.c
@@ -324,7 +324,7 @@ subsys_initcall(xenbus_probe_backend_ini
 
 #else
 
-void xenbus_backend_bus_register(void)
+void __init xenbus_backend_bus_register(void)
 {
 	xenbus_backend.error = bus_register(&xenbus_backend.bus);
 	if (xenbus_backend.error)
@@ -332,7 +332,7 @@ void xenbus_backend_bus_register(void)
 			   xenbus_backend.error);
 }
 
-void xenbus_backend_device_register(void)
+void __init xenbus_backend_device_register(void)
 {
 	if (xenbus_backend.error)
 		return;
--- a/drivers/xen/xenbus/xenbus_xs.c
+++ b/drivers/xen/xenbus/xenbus_xs.c
@@ -953,7 +953,13 @@ static int xenbus_thread(void *unused)
 	return 0;
 }
 
-int xs_init(void)
+int
+#ifndef MODULE
+__init
+#else
+__devinit
+#endif
+xs_init(void)
 {
 	struct task_struct *task;
 
--- a/fs/compat_ioctl.c
+++ b/fs/compat_ioctl.c
@@ -1483,7 +1483,7 @@ static long do_ioctl_trans(int fd, unsig
 		return do_video_stillpicture(fd, cmd, argp);
 	case VIDEO_SET_SPU_PALETTE:
 		return do_video_set_spu_palette(fd, cmd, argp);
-#ifdef CONFIG_XEN
+#ifdef CONFIG_XEN_PRIVILEGED_GUEST
 	case IOCTL_PRIVCMD_MMAP_32:
 	case IOCTL_PRIVCMD_MMAPBATCH_32:
 	case IOCTL_PRIVCMD_MMAPBATCH_V2_32:
--- a/include/xen/gnttab.h
+++ b/include/xen/gnttab.h
@@ -106,7 +106,11 @@ void gnttab_grant_foreign_transfer_ref(g
 				       unsigned long pfn);
 
 int gnttab_copy_grant_page(grant_ref_t ref, struct page **pagep);
+#if defined(CONFIG_XEN_BACKEND) || defined(CONFIG_XEN_BACKEND_MODULE)
 void __gnttab_dma_map_page(struct page *page);
+#else
+#define __gnttab_dma_map_page __gnttab_dma_unmap_page
+#endif
 static inline void __gnttab_dma_unmap_page(struct page *page)
 {
 }
