add kstrndup
Subsystems (24)
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH 1/44 add kstrndup
Add a kstrndup function, modelled on strndup. Like strndup this returns a string copied into its own allocated memory, but it copies no more than the specified number of bytes from the source.
Remove private strndup() from irda code.
--- include/linux/string.h | 1 + mm/util.c | 28 +++++++++++++++++++++++++--- net/irda/irias_object.c | 43 +++++-------------------------------------- 3 files changed, 31 insertions(+), 41 deletions(-)
===================================================================
include/linux/string.h +1 -0
@@ -105,6 +105,7 @@ extern void * memchr(const void *,int,__#endif extern char *kstrdup (const char *s,gfp_t gfp); +extern char *kstrndup (const char *s,size_t len,gfp_t gfp);extern void *kmemdup (const void *src,size_t len,gfp_t gfp);#ifdef __cplusplus
===================================================================
mm/util.c +25 -3
@@ -18,9 +18,8 @@ void *__kzalloc(size_t size, gfp_t flags }EXPORT_SYMBOL (__kzalloc); -/* +/** * kstrdup - allocate space for and copy an existing string -* * @s: the string to duplicate * @gfp: the GFP mask used in the kmalloc() call when allocating memory */
@@ -39,6 +38,30 @@ char *kstrdup(const char *s, gfp_t gfp)return buf; }EXPORT_SYMBOL (kstrdup); + +/** +* kstrndup - allocate space for and copy an existing string +* @s: the string to duplicate +* @max: read at most @max chars from @s +* @gfp: the GFP mask used in the kmalloc() call when allocating memory +*/ +char *kstrndup (const char *s,size_t max,gfp_t gfp) +{ +size_t len; +char *buf; + +if (!s) +return NULL ; + + len =strnlen (s, max); + buf =kmalloc_track_caller (len+1 , gfp); +if (buf) { +memcpy (buf, s, len); + buf[len] ='\0' ; + } +return buf; +} +EXPORT_SYMBOL (kstrndup);/** * kmemdup - duplicate region of memory
@@ -60,7 +83,6 @@ EXPORT_SYMBOL(kmemdup);/* * strndup_user - duplicate an existing string from user space -* * @s: The string to duplicate * @n: Maximum number of bytes to copy, including the trailing NUL. */
===================================================================
net/irda/irias_object.c +5 -38
79 lines not on this page · raw message
PATCH 2/44 add argv_split()
In reply to a message not in the archiveargv_split() is a helper function which takes a string, splits it at whitespace, and returns a NULL-terminated argv vector. This is deliberately simple - it does no quote processing of any kind.
[ Seems to me that this is something which is already being done in
the kernel, but I couldn't find any other implementations, either to steal or replace. Keep an eye out. ]
--- include/linux/string.h | 3 + lib/Makefile | 2 lib/argv_split.c | 106 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 110 insertions(+), 1 deletion(-)
===================================================================
include/linux/string.h +3 -0
@@ -108,6 +108,9 @@ extern char *kstrndup(const char *s, sizextern char *kstrndup (const char *s,size_t len,gfp_t gfp);extern void *kmemdup (const void *src,size_t len,gfp_t gfp); +extern char **argv_split (gfp_t gfp,const char *str,int *argcp); +extern void argv_free (char **argv); + #ifdef __cplusplus }#endif
===================================================================
lib/Makefile +1 -1
@@ -5,7 +5,7 @@ lib-y := ctype.o string.o vsprintf.o cmd lib-y := ctype.o string.o vsprintf.o cmdline.o \ rbtree.o radix-tree.o dump_stack.o \ idr.o int_sqrt.o bitmap.o extable.o prio_tree.o \ - sha1.o irq_regs.o reciprocal_div.o + sha1.o irq_regs.o reciprocal_div.o argv_split.o lib-$(CONFIG_MMU) += ioremap.o lib-$(CONFIG_SMP) += cpumask.o
===================================================================
lib/argv_split.c new file +106 -0
106 lines not on this page · raw message
PATCH 3/44 usermodehelper: split setup from execution
In reply to a message not in the archiveRather than having hundreds of variations of call_usermodehelper for various pieces of usermode state which could be set up, split the info allocation and initialization from the actual process execution.
This means the general pattern becomes:
info = call_usermodehelper_setup(path, argv, envp); /* basic state */
call_usermodehelper_<SET EXTRA STATE>(info, stuff...); /* extra state */
call_usermodehelper_exec(info, wait); /* run process and free info */
This patch introduces wrappers for all the existing calling styles for call_usermodehelper_*, but folds their implementations into one.
--- include/linux/kmod.h | 44 +++++++++- kernel/kmod.c | 207 ++++++++++++++++++++++++++++++++++---------------- 2 files changed, 184 insertions(+), 67 deletions(-)
===================================================================
include/linux/kmod.h +41 -3
@@ -36,13 +36,51 @@ static inline int request_module(const c #define try_then_request_module(x, mod...) ((x) ?: (request_module(mod), (x)))struct key ; -extern int call_usermodehelper_keys (char *path,char *argv[],char *envp[], -struct key *session_keyring,int wait); +struct file ; +struct subprocess_info ; + +/* Allocate a subprocess_info structure */ +struct subprocess_info *call_usermodehelper_setup (char *path, +char **argv,char **envp); + +/* Set various pieces of state into the subprocess_info structure */ +void call_usermodehelper_setkeys (struct subprocess_info *info, +struct key *session_keyring); +int call_usermodehelper_stdinpipe (struct subprocess_info *sub_info, +struct file **filp); +void call_usermodehelper_setcleanup (struct subprocess_info *info, +void (*cleanup)(char **argv,char **envp)); + +/* Actually execute the sub-process */ +int call_usermodehelper_exec (struct subprocess_info *info,int wait); + +/* Free the subprocess_info. This is only needed if you're not going +to call call_usermodehelper_exec */ +void call_usermodehelper_freeinfo (struct subprocess_info *info);static inline int call_usermodehelper (char *path,char **argv,char **envp,int wait) { -return call_usermodehelper_keys (path, argv, envp,NULL , wait); +struct subprocess_info *info; + + info =call_usermodehelper_setup (path, argv, envp); +if (info ==NULL ) +return -ENOMEM ; +return call_usermodehelper_exec (info, wait); +} + +static inline int +call_usermodehelper_keys (char *path,char **argv,char **envp, +struct key *session_keyring,int wait) +{ +struct subprocess_info *info; + + info =call_usermodehelper_setup (path, argv, envp); +if (info ==NULL ) +return -ENOMEM ; + +call_usermodehelper_setkeys (info, session_keyring); +return call_usermodehelper_exec (info, wait); }extern void usermodehelper_init (void );
===================================================================
kernel/kmod.c +143 -64
253 lines not on this page · raw message
PATCH 4/44 Add common orderly_poweroff()
In reply to a message not in the archiveVarious pieces of code around the kernel want to be able to trigger an orderly poweroff. This pulls them together into a single implementation.
By default the poweroff command is /sbin/poweroff, but it can be set via sysctl: kernel/poweroff_cmd. This is split at whitespace, so it can include command-line arguments.
This patch replaces four other instances of invoking either "poweroff" or "shutdown -h now": two sbus drivers, and acpi thermal management.
sparc64 has its own "powerd"; still need to determine whether it should be replaced by orderly_poweroff().
--- drivers/acpi/thermal.c | 24 +--------------- drivers/sbus/char/bbc_envctrl.c | 5 +-- drivers/sbus/char/envctrl.c | 7 +--- include/linux/reboot.h | 5 +++ kernel/sys.c | 58 +++++++++++++++++++++++++++++++++++++++ kernel/sysctl.c | 10 ++++++ 6 files changed, 79 insertions(+), 30 deletions(-)
===================================================================
drivers/acpi/thermal.c +2 -22
@@ -40,6 +40,7 @@#include <linux/jiffies.h> #include <linux/kmod.h> #include <linux/seq_file.h> +#include <linux/reboot.h> #include <asm/uaccess.h> #include <acpi/acpi_bus.h>
@@ -59,7 +60,6 @@#define ACPI_THERMAL_NOTIFY_CRITICAL 0xF0#define ACPI_THERMAL_NOTIFY_HOT 0xF1#define ACPI_THERMAL_MODE_ACTIVE 0x00 -#define ACPI_THERMAL_PATH_POWEROFF "/sbin/poweroff"#define ACPI_THERMAL_MAX_ACTIVE 10#define ACPI_THERMAL_MAX_LIMIT_STR_LEN 65
@@ -419,26 +419,6 @@ static int acpi_thermal_get_devices(strureturn 0 ; } -static int acpi_thermal_call_usermode (char *path) -{ -char *argv[2 ] = {NULL ,NULL }; -char *envp[3 ] = {NULL ,NULL ,NULL }; - - -if (!path) -return -EINVAL ; - - argv[0 ] = path; - -/* minimal command environment */ - envp[0 ] ="HOME=/" ; - envp[1 ] ="PATH=/sbin:/bin:/usr/sbin:/usr/bin" ; - -call_usermodehelper (argv[0 ], argv, envp,0 ); - -return 0 ; -} -static int acpi_thermal_critical (struct acpi_thermal *tz) {if (!tz || !tz->trips.critical.flags.valid)
@@ -456,7 +436,7 @@ static int acpi_thermal_critical(structacpi_bus_generate_event (tz->device,ACPI_THERMAL_NOTIFY_CRITICAL , tz->trips.critical.flags.enabled); -acpi_thermal_call_usermode (ACPI_THERMAL_PATH_POWEROFF ); +orderly_poweroff (true);return 0 ; }
===================================================================
drivers/sbus/char/bbc_envctrl.c +2 -3
@@ -7,6 +7,7 @@#include <linux/kthread.h> #include <linux/delay.h> #include <linux/kmod.h> +#include <linux/reboot.h> #include <asm/oplib.h> #include <asm/ebus.h>
@@ -170,8 +171,6 @@ static void do_envctrl_shutdown(struct bstatic void do_envctrl_shutdown (struct bbc_cpu_temperature *tp) {static int shutting_down =0 ; -static char *envp[] = {"HOME=/" ,"TERM=linux" ,"PATH=/sbin:/usr/sbin:/bin:/usr/bin" ,NULL }; -char *argv[] = {"/sbin/shutdown" ,"-h" ,"now" ,NULL };char *type ="???" ;s8 val =-1 ;
@@ -195,7 +194,7 @@ static void do_envctrl_shutdown(struct bprintk (KERN_CRIT "kenvctrld: Shutting down the system now.\n" ); shutting_down =1 ; -if (call_usermodehelper ("/sbin/shutdown" , argv, envp,0 ) <0 ) +if (orderly_poweroff (true) <0 )printk (KERN_CRIT "envctrl: shutdown execution failed\n" ); }
===================================================================
drivers/sbus/char/envctrl.c +2 -5
@@ -26,6 +26,7 @@#include <linux/ioport.h> #include <linux/miscdevice.h> #include <linux/kmod.h> +#include <linux/reboot.h> #include <asm/ebus.h> #include <asm/uaccess.h>
@@ -966,10 +967,6 @@ static void envctrl_do_shutdown(void)static void envctrl_do_shutdown (void ) {static int inprog =0 ; -static char *envp[] = { -"HOME=/" ,"TERM=linux" ,"PATH=/sbin:/usr/sbin:/bin:/usr/bin" ,NULL }; -char *argv[] = { -"/sbin/shutdown" ,"-h" ,"now" ,NULL };int ret;if (inprog !=0 )
@@ -977,7 +974,7 @@ static void envctrl_do_shutdown(void) inprog =1 ;printk (KERN_CRIT "kenvctrld: WARNING: Shutting down the system now.\n" ); - ret =call_usermodehelper ("/sbin/shutdown" , argv, envp,0 ); + ret =orderly_poweroff (true);if (ret <0 ) {printk (KERN_CRIT "kenvctrld: WARNING: system shutdown failed!\n" ); inprog =0 ;/* unlikely to succeed, but we could try again */
===================================================================
include/linux/reboot.h +5 -0
@@ -67,6 +67,11 @@ extern void kernel_power_off(void);void ctrl_alt_del (void ); +#define POWEROFF_CMD_PATH_LEN 256 +extern char poweroff_cmd[POWEROFF_CMD_PATH_LEN ]; + +extern int orderly_poweroff (bool force); +/* * Emergency restart, callable from an interrupt handler. */
===================================================================
kernel/sys.c +58 -0
61 lines not on this page · raw message
===================================================================
kernel/sysctl.c +10 -0
@@ -45,6 +45,7 @@#include <linux/syscalls.h> #include <linux/nfs_fs.h> #include <linux/acpi.h> +#include <linux/reboot.h> #include <asm/uaccess.h> #include <asm/processor.h>
@@ -707,6 +708,15 @@ static ctl_table kern_table[] = { .proc_handler = &proc_dointvec, },#endif + { + .ctl_name = CTL_UNNUMBERED, + .procname = "poweroff_cmd", + .data = &poweroff_cmd, + .maxlen = POWEROFF_CMD_PATH_LEN, + .mode = 0644, + .proc_handler = &proc_dostring, + .strategy = &sysctl_string, + }, { .ctl_name = 0 } };
PATCH 5/44 usermodehelper: Tidy up waiting
In reply to a message not in the archiveRather than using a tri-state integer for the wait flag in call_usermodehelper_exec, define a proper enum, and use that. I've preserved the integer values so that any callers I've missed should still work OK.
--- arch/i386/mach-voyager/voyager_thread.c | 2 +- arch/x86_64/kernel/mce.c | 2 +- drivers/macintosh/therm_pm72.c | 3 ++- drivers/macintosh/windfarm_core.c | 3 ++- drivers/net/hamradio/baycom_epp.c | 2 +- drivers/pnp/pnpbios/core.c | 2 +- fs/ocfs2/heartbeat.c | 2 +- include/linux/kmod.h | 12 +++++++++--- kernel/cpuset.c | 2 +- kernel/kmod.c | 29 +++++++++++++++++------------ kernel/sys.c | 2 +- lib/kobject_uevent.c | 2 +- net/bridge/br_stp_if.c | 2 +- security/keys/request_key.c | 3 ++- 14 files changed, 41 insertions(+), 27 deletions(-)
===================================================================
arch/i386/mach-voyager/voyager_thread.c +1 -1
@@ -52,7 +52,7 @@ execute(const char *string) NULL, }; -if ((ret =call_usermodehelper (argv[0 ], argv, envp,1 )) !=0 ) { +if ((ret =call_usermodehelper (argv[0 ], argv, envp,UMH_WAIT_PROC )) !=0 ) {printk (KERN_ERR "Voyager failed to run \"%s\": %i\n" , string, ret); }
===================================================================
arch/x86_64/kernel/mce.c +1 -1
@@ -174,7 +174,7 @@ static void do_mce_trigger(void)if (events !=atomic_read (&mce_logged) && trigger[0 ]) {/* Small race window, but should be harmless. */ atomic_set (&mce_logged, events); -call_usermodehelper (trigger, trigger_argv,NULL ,-1 ); +call_usermodehelper (trigger, trigger_argv,NULL ,UMH_NO_WAIT ); } }
===================================================================
drivers/macintosh/therm_pm72.c +2 -1
@@ -1770,7 +1770,8 @@ static int call_critical_overtemp(void)"PATH=/sbin:/usr/sbin:/bin:/usr/bin" , NULL }; -return call_usermodehelper (critical_overtemp_path, argv, envp,0 ); +return call_usermodehelper (critical_overtemp_path, + argv, envp,UMH_WAIT_EXEC ); }
===================================================================
drivers/macintosh/windfarm_core.c +2 -1
@@ -80,7 +80,8 @@ int wf_critical_overtemp(void)"PATH=/sbin:/usr/sbin:/bin:/usr/bin" , NULL }; -return call_usermodehelper (critical_overtemp_path, argv, envp,0 ); +return call_usermodehelper (critical_overtemp_path, + argv, envp,UMH_WAIT_EXEC ); }EXPORT_SYMBOL_GPL (wf_critical_overtemp);
===================================================================
drivers/net/hamradio/baycom_epp.c +1 -1
@@ -320,7 +320,7 @@ static int eppconfig(struct baycom_statesprintf (portarg,"%ld" , bc->pdev->port->base);printk (KERN_DEBUG "%s: %s -s -p %s -m %s\n" , bc_drvname, eppconfig_path, portarg, modearg); -return call_usermodehelper (eppconfig_path, argv, envp,1 ); +return call_usermodehelper (eppconfig_path, argv, envp,UMH_WAIT_PROC ); }/* ---------------------------------------------------------------------- */
===================================================================
drivers/pnp/pnpbios/core.c +1 -1
@@ -147,7 +147,7 @@ static int pnp_dock_event(int dock, stru info->location_id, info->serial, info->capabilities); envp[i] =NULL ; - value =call_usermodehelper (argv [0 ], argv, envp,0 ); + value =call_usermodehelper (argv [0 ], argv, envp,UMH_WAIT_EXEC );kfree (buf);kfree (envp);return 0 ;
===================================================================
fs/ocfs2/heartbeat.c +1 -1
@@ -209,7 +209,7 @@ void ocfs2_stop_heartbeat(struct ocfs2_s envp[1 ] ="PATH=/sbin:/bin:/usr/sbin:/usr/bin" ; envp[2 ] =NULL ; - ret =call_usermodehelper (argv[0 ], argv, envp,1 ); + ret =call_usermodehelper (argv[0 ], argv, envp,UMH_WAIT_PROC );if (ret <0 )mlog_errno (ret); }
===================================================================
include/linux/kmod.h +9 -3
@@ -51,15 +51,21 @@ void call_usermodehelper_setcleanup(struvoid call_usermodehelper_setcleanup (struct subprocess_info *info,void (*cleanup)(char **argv,char **envp)); +enum umh_wait { +UMH_NO_WAIT =-1 ,/* don't wait at all */ +UMH_WAIT_EXEC =0 ,/* wait for the exec, but not the process */ +UMH_WAIT_PROC =1 ,/* wait for the process to complete */ +}; +/* Actually execute the sub-process */ -int call_usermodehelper_exec (struct subprocess_info *info,int wait); +int call_usermodehelper_exec (struct subprocess_info *info,enum umh_wait wait);/* Free the subprocess_info. This is only needed if you're not going to call call_usermodehelper_exec */ void call_usermodehelper_freeinfo (struct subprocess_info *info);static inline int -call_usermodehelper (char *path,char **argv,char **envp,int wait) +call_usermodehelper (char *path,char **argv,char **envp,enum umh_wait wait) {struct subprocess_info *info;
@@ -71,7 +77,7 @@ call_usermodehelper(char *path, char **astatic inline int call_usermodehelper_keys (char *path,char **argv,char **envp, -struct key *session_keyring,int wait) +struct key *session_keyring,enum umh_wait wait) {struct subprocess_info *info;
===================================================================
kernel/cpuset.c +1 -1
@@ -516,7 +516,7 @@ static void cpuset_release_agent(const c envp[i++] ="PATH=/sbin:/bin:/usr/sbin:/usr/bin" ; envp[i] =NULL ; -call_usermodehelper (argv[0 ], argv, envp,0 ); +call_usermodehelper (argv[0 ], argv, envp,UMH_WAIT_EXEC );kfree (pathbuf); }
===================================================================
kernel/kmod.c +17 -12
@@ -119,7 +119,7 @@ struct subprocess_info {char **argv;char **envp;struct key *ring; -int wait; +enum umh_wait wait;int retval;struct file *stdin;void (*cleanup)(char **argv,char **envp);
@@ -225,7 +225,7 @@ static int wait_for_helper(void *data) sub_info->retval = ret; } -if (sub_info->wait <0 ) +if (sub_info->wait ==UMH_NO_WAIT )call_usermodehelper_freeinfo (sub_info);else complete (sub_info->complete);
@@ -238,26 +238,31 @@ static void __call_usermodehelper(structstruct subprocess_info *sub_info = container_of(work, struct subprocess_info, work);pid_t pid; -int wait = sub_info->wait; +enum umh_wait wait = sub_info->wait;/* CLONE_VFORK: wait until the usermode helper has execve'd * successfully We need the data structures to stay around * until that is done. */ -if (wait) +if (wait ==UMH_WAIT_PROC || wait ==UMH_NO_WAIT ) pid =kernel_thread (wait_for_helper, sub_info,CLONE_FS |CLONE_FILES |SIGCHLD );else pid =kernel_thread (____call_usermodehelper, sub_info,CLONE_VFORK |SIGCHLD ); -if (wait <0 ) -return ; - -if (pid <0 ) { +switch (wait) { +case UMH_NO_WAIT : +break ; + +case UMH_WAIT_PROC : +if (pid >0 ) +break ; sub_info->retval = pid; +/* FALLTHROUGH */ + +case UMH_WAIT_EXEC :complete (sub_info->complete); - }else if (!wait) -complete (sub_info->complete); + } }/**
@@ -359,7 +364,7 @@ EXPORT_SYMBOL(call_usermodehelper_stdinp* (ie. it runs with full root capabilities). */ int call_usermodehelper_exec (struct subprocess_info *sub_info, -int wait) +enum umh_wait wait) {DECLARE_COMPLETION_ONSTACK (done);int retval;
@@ -378,7 +383,7 @@ int call_usermodehelper_exec(struct subp sub_info->wait = wait;queue_work (khelper_wq, &sub_info->work); -if (wait <0 )/* task has freed sub_info */ +if (wait ==UMH_NO_WAIT )/* task has freed sub_info */ return 0 ;wait_for_completion (&done); retval = sub_info->retval;
===================================================================
kernel/sys.c +1 -1
@@ -2318,7 +2318,7 @@ int orderly_poweroff(bool force)call_usermodehelper_setcleanup (info, argv_cleanup); - ret =call_usermodehelper_exec (info,-1 ); + ret =call_usermodehelper_exec (info,UMH_NO_WAIT ); out:if (ret && force) {
===================================================================
lib/kobject_uevent.c +1 -1
@@ -208,7 +208,7 @@ int kobject_uevent_env(struct kobject *k argv [0 ] = uevent_helper; argv [1 ] = (char *)subsystem; argv [2 ] =NULL ; -call_usermodehelper (argv[0 ], argv, envp,0 ); +call_usermodehelper (argv[0 ], argv, envp,UMH_WAIT_EXEC ); } exit:
===================================================================
net/bridge/br_stp_if.c +1 -1
@@ -125,7 +125,7 @@ static void br_stp_start(struct net_bridchar *argv[] = {BR_STP_PROG , br->dev->name,"start" ,NULL };char *envp[] = {NULL }; - r =call_usermodehelper (BR_STP_PROG , argv, envp,1 ); + r =call_usermodehelper (BR_STP_PROG , argv, envp,UMH_WAIT_PROC );if (r ==0 ) { br->stp_enabled =BR_USER_STP ;printk (KERN_INFO "%s: userspace STP started\n" , br->dev->name);
===================================================================
security/keys/request_key.c +2 -1
@@ -108,7 +108,8 @@ static int call_sbin_request_key(struct argv[i] =NULL ;/* do it */ - ret =call_usermodehelper_keys (argv[0 ], argv, envp, keyring,1 ); + ret =call_usermodehelper_keys (argv[0 ], argv, envp, keyring, +UMH_WAIT_PROC ); error_link:key_put (keyring);
PATCH 6/44 use elfnote.h to generate vsyscall notes.
In reply to a message not in the archiveUse existing elfnote.h to generate vsyscall notes, rather than doing it locally. Changes elfnote.h a bit to suit, since this is the first asm user, and it wasn't quite right.
--- arch/i386/kernel/vsyscall-note.S | 23 ++++++----------------- include/linux/elfnote.h | 22 +++++++++++++++------- 2 files changed, 21 insertions(+), 24 deletions(-)
===================================================================
arch/i386/kernel/vsyscall-note.S +6 -17
@@ -3,23 +3,12 @@ * Here we can supply some information useful to userland. */ -#include <linux/uts.h> #include <linux/version.h> +#include <linux/elfnote.h> -#define ASM_ELF_NOTE_BEGIN(name, flags, vendor, type) \ - .section name, flags; \ - .balign 4; \ - .long 1f - 0f; /* name length */ \ - .long 3f - 2f; /* data length */ \ - .long type; /* note type */ \ -0: .asciz vendor; /* vendor name */ \ -1: .balign 4; \ -2: - -#define ASM_ELF_NOTE_END \ -3: .balign 4; /* pad out section */ \ - .previous - - ASM_ELF_NOTE_BEGIN(".note.kernel-version", "a", UTS_SYSNAME, 0) +/* Ideally this would use UTS_NAME, but using a quoted string here + doesn't work. Remember to change this when changing the + kernel's name. */ +ELFNOTE_START(Linux, 0, "a") .long LINUX_VERSION_CODE - ASM_ELF_NOTE_END +ELFNOTE_END
===================================================================
include/linux/elfnote.h +15 -7
@@ -38,17 +38,25 @@* e.g. ELFNOTE(XYZCo, 42, .asciz, "forty-two") * ELFNOTE(XYZCo, 12, .long, 0xdeadbeef) */ -#define ELFNOTE(name, type, desctype, descdata) \ -.pushsection .note.name, "",@note ; \ - .align 4 ; \ +#define ELFNOTE_START(name, type, flags) \ +.pushsection .note.name, flags,@note ; \ + .balign 4 ; \ .long 2f - 1f /* namesz */ ; \ - .long 4f - 3f /* descsz */ ; \ + .long 4484f - 3f /* descsz */ ; \ .long type ; \ 1:.asciz #name ; \ -2:.align 4 ; \ -3:desctype descdata ; \ -4:.align 4 ; \ +2:.balign 4 ; \ +3: + +#define ELFNOTE_END \ +4484:.balign 4 ; \ .popsection ; + +#define ELFNOTE (name, type, desc) \ + ELFNOTE_START(name, type, "") \ + desc ; \ + ELFNOTE_END +#else /* !__ASSEMBLER__ */ #include <linux/elf.h> /*
PATCH 7/44 paravirt: add an "mm" argument to alloc_pt
In reply to a message not in the archiveIt's useful to know which mm is allocating a pagetable. Xen uses this to determine whether the pagetable being added to is pinned or not.
--- arch/i386/kernel/vmi.c | 2 +- arch/i386/mm/init.c | 2 +- arch/i386/mm/pageattr.c | 2 +- include/asm-i386/paravirt.h | 8 ++++---- include/asm-i386/pgalloc.h | 6 +++--- 5 files changed, 10 insertions(+), 10 deletions(-)
===================================================================
arch/i386/kernel/vmi.c +1 -1
@@ -361,7 +361,7 @@ static void *vmi_kmap_atomic_pte(struct }#endif -static void vmi_allocate_pt (u32 pfn) +static void vmi_allocate_pt (struct mm_struct *mm,u32 pfn) {vmi_set_page_type (pfn,VMI_PAGE_L1 ); vmi_ops.allocate_page (pfn,VMI_PAGE_L1 ,0 ,0 ,0 );
===================================================================
arch/i386/mm/init.c +1 -1
@@ -87,7 +87,7 @@ static pte_t * __init one_page_table_iniif (!(pmd_val (*pmd) & _PAGE_PRESENT)) {pte_t *page_table = (pte_t *)alloc_bootmem_low_pages (PAGE_SIZE ); -paravirt_alloc_pt (__pa (page_table) >>PAGE_SHIFT ); +paravirt_alloc_pt (&init_mm,__pa (page_table) >>PAGE_SHIFT );set_pmd (pmd,__pmd (__pa (page_table) | _PAGE_TABLE));BUG_ON (page_table !=pte_offset_kernel (pmd,0 )); }
===================================================================
arch/i386/mm/pageattr.c +1 -1
@@ -60,7 +60,7 @@ static struct page *split_large_page(uns address =__pa (address); addr = address &LARGE_PAGE_MASK ; pbase = (pte_t *)page_address (base); -paravirt_alloc_pt (page_to_pfn (base)); +paravirt_alloc_pt (&init_mm,page_to_pfn (base));for (i =0 ; i <PTRS_PER_PTE ; i++, addr +=PAGE_SIZE ) {set_pte (&pbase[i],pfn_pte (addr >>PAGE_SHIFT , addr == address ? prot : ref_prot));
===================================================================
include/asm-i386/paravirt.h +4 -4
@@ -173,7 +175,7 @@ struct paravirt_ops unsigned long va);/* Hooks for allocating/releasing pagetable pages */ -void (*alloc_pt)(u32 pfn); +void (*alloc_pt)(struct mm_struct *mm,u32 pfn);void (*alloc_pd)(u32 pfn);void (*alloc_pd_clone)(u32 pfn,u32 clonepfn,u32 start,u32 count);void (*release_pt)(u32 pfn);
@@ -738,9 +746,9 @@ static inline void flush_tlb_others(cpumPVOP_VCALL3 (flush_tlb_others, &cpumask, mm, va); } -static inline void paravirt_alloc_pt (unsigned pfn) -{ -PVOP_VCALL1 (alloc_pt, pfn); +static inline void paravirt_alloc_pt (struct mm_struct *mm,unsigned pfn) +{ +PVOP_VCALL2 (alloc_pt, mm, pfn); }static inline void paravirt_release_pt (unsigned pfn) {
===================================================================
include/asm-i386/pgalloc.h +3 -3
@@ -7,7 +7,7 @@#ifdef CONFIG_PARAVIRT #include <asm/paravirt.h> #else -#define paravirt_alloc_pt (pfn) do { } while (0) +#define paravirt_alloc_pt (mm, pfn) do { } while (0)#define paravirt_alloc_pd (pfn) do { } while (0)#define paravirt_alloc_pd (pfn) do { } while (0)#define paravirt_alloc_pd_clone (pfn, clonepfn, start, count) do { } while (0)
@@ -17,13 +17,13 @@#define pmd_populate_kernel (mm, pmd, pte) \ do { \ - paravirt_alloc_pt(__pa(pte) >> PAGE_SHIFT); \ + paravirt_alloc_pt(mm, __pa(pte) >> PAGE_SHIFT); \ set_pmd(pmd, __pmd(_PAGE_TABLE + __pa(pte))); \ } while (0)#define pmd_populate (mm, pmd, pte) \ do { \ - paravirt_alloc_pt(page_to_pfn(pte)); \ + paravirt_alloc_pt(mm, page_to_pfn(pte)); \ set_pmd(pmd, __pmd(_PAGE_TABLE + \ ((unsigned long long)page_to_pfn(pte) << \ (unsigned long long) PAGE_SHIFT))); \
PATCH 8/44 paravirt: add a hook for once the allocator is ready
In reply to a message not in the archiveAdd a hook so that the paravirt backend knows when the allocator is ready. This is useful for the obvious reason that the allocator is available, but the other side-effect of having the bootmem allocator available is that each page now has an associated "struct page".
--- arch/i386/kernel/setup.c | 2 ++ include/asm-i386/paravirt.h | 8 ++++++++ include/asm-i386/setup.h | 4 ++++ 3 files changed, 14 insertions(+)
===================================================================
arch/i386/kernel/setup.c +2 -0
@@ -611,6 +611,8 @@ void __init setup_arch(char **cmdline_p)* NOTE: at this point the bootmem allocator is fully available. */ +paravirt_post_allocator_init (); +dmi_scan_machine ();#ifdef CONFIG_X86_GENERICARCH
===================================================================
include/asm-i386/paravirt.h +8 -0
@@ -52,6 +52,8 @@ struct paravirt_ops/* Basic arch-specific setup */ void (*arch_setup)(void );char *(*memory_setup)(void ); +void (*post_allocator_init)(void ); +void (*init_IRQ)(void );void (*time_init)(void );
@@ -669,6 +671,12 @@ static inline void setup_secondary_clock }#endif +static inline void paravirt_post_allocator_init (void ) +{ +if (paravirt_ops.post_allocator_init) + (*paravirt_ops.post_allocator_init)(); +} +static inline void paravirt_pagetable_setup_start (pgd_t *base) {if (paravirt_ops.pagetable_setup_start)
===================================================================
include/asm-i386/setup.h +4 -0
@@ -79,6 +79,10 @@ void __init add_memory_region(unsigned lextern unsigned long init_pg_tables_end; +#ifndef CONFIG_PARAVIRT +#define paravirt_post_allocator_init () do {} while (0) +#endif +#endif /* __ASSEMBLY__ */ #endif /* __KERNEL__ */
PATCH 9/44 paravirt: increase IRQ limit
In reply to a message not in the archiveWhen running with CONFIG_PARAVIRT, we may want lots of IRQs even if there's no IO APIC.
--- include/asm-i386/mach-default/irq_vectors_limits.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
===================================================================
include/asm-i386/mach-default/irq_vectors_limits.h +1 -1
@@ -1,7 +1,7 @@#ifndef _ASM_IRQ_VECTORS_LIMITS_H#define _ASM_IRQ_VECTORS_LIMITS_H -#ifdef CONFIG_X86_IO_APIC +#if defined(CONFIG_X86_IO_APIC ) || defined(CONFIG_PARAVIRT )#define NR_IRQS 224# if (224 >=32 *NR_CPUS )# define NR_IRQ_VECTORS NR_IRQS
PATCH 10/44 paravirt: unstatic leave_mm
In reply to a message not in the archiveMake globally leave_mm visible, specifically so that Xen can use it to shoot-down lazy uses of cr3.
--- arch/i386/kernel/smp.c | 5 +++-- include/asm-i386/mmu_context.h | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-)
===================================================================
include/asm-i386/mmu_context.h +2 -0
@@ -31,6 +31,8 @@ static inline void enter_lazy_tlb(structper_cpu (cpu_tlbstate, cpu).state =TLBSTATE_LAZY ;#endif } + +void leave_mm (unsigned long cpu); static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
===================================================================
arch/i386/kernel/smp.c +3 -2
@@ -22,6 +22,7 @@#include <asm/mtrr.h> #include <asm/tlbflush.h> +#include <asm/mmu_context.h> #include <mach_apic.h> /*
@@ -249,13 +250,13 @@ static DEFINE_SPINLOCK(tlbstate_lock);static DEFINE_SPINLOCK (tlbstate_lock);/* -* We cannot call mmdrop() because we are in interrupt context, +* We cannot call mmdrop() because we are in interrupt context, * instead update mm->cpu_vm_mask. * * We need to reload %cr3 since the page tables may be going * away from under us.. */ -static inline void leave_mm (unsigned long cpu) +void leave_mm (unsigned long cpu) {if (per_cpu (cpu_tlbstate, cpu).state ==TLBSTATE_OK )BUG ();
PATCH 11/44 paravirt: unstatic smp_store_cpu_info
In reply to a message not in the archiveParavirt implementations need to store cpu info when bringing up cpus.
--- arch/i386/kernel/smpboot.c | 2 +- include/asm-i386/smp.h | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-)
===================================================================
include/asm-i386/smp.h +2 -0
@@ -129,6 +132,8 @@ extern void __cpu_die(unsigned int cpu);extern void __cpu_die (unsigned int cpu);extern unsigned int num_processors; +void __cpuinit smp_store_cpu_info (int id); +#endif /* !__ASSEMBLY__ */ #else /* CONFIG_SMP */
===================================================================
arch/i386/kernel/smpboot.c +1 -1
@@ -148,7 +148,7 @@ void __init smp_alloc_memory(void)* a given CPU */ -static void __cpuinit smp_store_cpu_info (int id) +void __cpuinit smp_store_cpu_info (int id) {struct cpuinfo_x86 *c = cpu_data + id;
PATCH 12/44 paravirt: make siblingmap functions visible
In reply to a message not in the archiveParavirt implementations need to set the sibling map on new cpus.
--- arch/i386/kernel/smpboot.c | 6 ++---- include/asm-i386/smp.h | 3 +++ 2 files changed, 5 insertions(+), 4 deletions(-)
===================================================================
include/asm-i386/smp.h +3 -0
@@ -43,9 +43,12 @@ extern u8 x86_cpu_to_apicid[];#define cpu_physical_id (cpu) x86_cpu_to_apicid[cpu] +extern void set_cpu_sibling_map (int cpu); +#ifdef CONFIG_HOTPLUG_CPU extern void cpu_exit_clear (void );extern void cpu_uninit (void ); +extern void remove_siblinginfo (int cpu);#endif struct smp_ops
===================================================================
arch/i386/kernel/smpboot.c +2 -4
@@ -308,8 +308,7 @@ cpumask_t cpu_coregroup_map(int cpu)/* representing cpus for which sibling maps can be computed */ static cpumask_t cpu_sibling_setup_map; -static inline void -set_cpu_sibling_map (int cpu) +void set_cpu_sibling_map (int cpu) {int i;struct cpuinfo_x86 *c = cpu_data;
@@ -1157,8 +1156,7 @@ void __init native_smp_prepare_boot_cpu( }#ifdef CONFIG_HOTPLUG_CPU -static void -remove_siblinginfo (int cpu) +void remove_siblinginfo (int cpu) {int sibling;struct cpuinfo_x86 *c = cpu_data;
PATCH 13/44 paravirt: export __supported_pte_mask
In reply to a message not in the archive__supported_pte_mask is needed when constructing pte values. Xen device drivers need to do this to make mappings of foreign pages (ie, pages granted to us by other domains).
--- arch/i386/mm/init.c | 1 + 1 file changed, 1 insertion(+)
===================================================================
arch/i386/mm/init.c +1 -0
@@ -473,6 +473,7 @@ void zap_low_mappings (void)static int disable_nx__initdata =0 ;u64 __supported_pte_mask__read_mostly = ~_PAGE_NX; +EXPORT_SYMBOL_GPL (__supported_pte_mask);/* * noexec = on|off
PATCH 14/44 Allocate and free vmalloc areas
In reply to a message not in the archiveAllocate/release a chunk of vmalloc address space:
alloc_vm_area reserves a chunk of address space, and makes sure all the pagetables are constructed for that address range - but no pages.
free_vm_area releases the address space range.
--- include/linux/vmalloc.h | 4 +++ mm/vmalloc.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+)
===================================================================
include/linux/vmalloc.h +4 -0
@@ -69,6 +69,10 @@ extern int map_vm_area(struct vm_struct struct page ***pages);extern void unmap_vm_area (struct vm_struct *area); +/* Allocate/destroy a 'vmalloc' VM area. */ +extern struct vm_struct *alloc_vm_area (size_t size); +extern void free_vm_area (struct vm_struct *area); +/* * Internals. Dont't use.. */
===================================================================
mm/vmalloc.c +53 -0
56 lines not on this page · raw message
PATCH 15/44 paravirt: helper to disable all IO space
In reply to a message not in the archiveIn a virtual environment, device drivers such as legacy IDE will waste quite a lot of time probing for their devices which will never appear. This helper function allows a paravirt implementation to lay claim to the whole iomem and ioport space, thereby disabling all device drivers trying to claim IO resources.
--- arch/i386/kernel/paravirt.c | 35 +++++++++++++++++++++++++++++++++++ include/asm-i386/paravirt.h | 1 + 2 files changed, 36 insertions(+)
===================================================================
arch/i386/kernel/paravirt.c +35 -0
@@ -227,6 +227,41 @@ static int __init print_banner(void)return 0 ; }core_initcall (print_banner); + +static struct resource reserve_ioports = { + .start =0 , + .end =IO_SPACE_LIMIT , + .name ="paravirt-ioport" , + .flags =IORESOURCE_IO |IORESOURCE_BUSY , +}; + +static struct resource reserve_iomem = { + .start =0 , + .end =-1 , + .name ="paravirt-iomem" , + .flags =IORESOURCE_MEM |IORESOURCE_BUSY , +}; + +/* +* Reserve the whole legacy IO space to prevent any legacy drivers +* from wasting time probing for their hardware. This is a fairly +* brute-force approach to disabling all non-virtual drivers. +* +* Note that this must be called very early to have any effect. +*/ +int paravirt_disable_iospace (void ) +{ +int ret; + + ret =request_resource (&ioport_resource, &reserve_ioports); +if (ret ==0 ) { + ret =request_resource (&iomem_resource, &reserve_iomem); +if (ret) +release_resource (&reserve_ioports); + } + +return ret; +}struct paravirt_ops paravirt_ops = { .name ="bare hardware" ,
===================================================================
include/asm-i386/paravirt.h +1 -0
@@ -262,6 +262,7 @@ unsigned paravirt_patch_insns(void *siteunsigned paravirt_patch_insns (void *site,unsigned len,const char *start,const char *end); +int paravirt_disable_iospace (void );/* * This generates an indirect call based on the operation type number.
PATCH 16/44 Add a sched_clock paravirt_op
In reply to a message not in the archiveThe tsc-based get_scheduled_cycles interface is not a good match for Xen's runstate accounting, which reports everything in nanoseconds.
This patch replaces this interface with a sched_clock interface, which matches both Xen and VMI's requirements.
In order to do this, we:
1. replace get_scheduled_cycles with sched_clock
2. hoist cycles_2_ns into a common header
3. update vmi accordingly
One thing to note: because sched_clock is implemented as a weak function in kernel/sched.c, we must define a real function in order to override this weak binding. This means the usual paravirt_ops technique of using an inline function won't work in this case.
--- arch/i386/kernel/paravirt.c | 2 +- arch/i386/kernel/tsc.c | 23 +++++++++++++++-------- arch/i386/kernel/vmi.c | 2 +- arch/i386/kernel/vmiclock.c | 8 ++++---- include/asm-i386/paravirt.h | 7 +++++-- include/asm-i386/timer.h | 32 +++++++++++++++++++++++++++++++- include/asm-i386/vmi_time.h | 2 +- 7 files changed, 58 insertions(+), 18 deletions(-)
===================================================================
arch/i386/kernel/paravirt.c +1 -1
@@ -268,7 +268,7 @@ struct paravirt_ops paravirt_ops = { .write_msr = native_write_msr_safe, .read_tsc = native_read_tsc, .read_pmc = native_read_pmc, - .get_scheduled_cycles = native_read_tsc, + .sched_clock = native_sched_clock, .get_cpu_khz = native_calculate_cpu_khz, .load_tr_desc = native_load_tr_desc, .set_ldt = native_set_ldt,
===================================================================
arch/i386/kernel/tsc.c +15 -8
@@ -83,7 +83,7 @@ static inline int check_tsc_unstable(voi* * [email protected] "math is hard, lets go shopping!" */ -static unsigned long cyc2ns_scale__read_mostly ; +unsigned long cyc2ns_scale__read_mostly ;#define CYC2NS_SCALE_FACTOR 10/* 2^10, carefully chosen */
@@ -92,15 +92,10 @@ static inline void set_cyc2ns_scale(unsi cyc2ns_scale = (1000000 <<CYC2NS_SCALE_FACTOR )/cpu_khz; } -static inline unsigned long long cycles_2_ns (unsigned long long cyc) -{ -return (cyc * cyc2ns_scale) >>CYC2NS_SCALE_FACTOR ; -} -/* * Scheduler clock - returns current time in nanosec units. */ -unsigned long long sched_clock (void ) +unsigned long long native_sched_clock (void ) {unsigned long long this_offset;
@@ -112,11 +107,23 @@ unsigned long long sched_clock(void)return (jiffies_64 -INITIAL_JIFFIES ) * (1000000000 /HZ );/* read the Time Stamp Counter: */ -get_scheduled_cycles (this_offset); +rdtscll (this_offset);/* return the value in ns */ return cycles_2_ns (this_offset); } + +/* We need to define a real function for sched_clock, to override the +weak default version */ +#ifdef CONFIG_PARAVIRT +unsigned long long sched_clock (void ) +{ +return paravirt_sched_clock (); +} +#else +unsigned long long sched_clock (void ) + __attribute__((alias ("native_sched_clock" ))); +#endif unsigned long native_calculate_cpu_khz (void ) {
===================================================================
arch/i386/kernel/vmi.c +1 -1
@@ -891,7 +891,7 @@ static inline int __init activate_vmi(vo paravirt_ops.setup_boot_clock = vmi_time_bsp_init; paravirt_ops.setup_secondary_clock = vmi_time_ap_init;#endif - paravirt_ops.get_scheduled_cycles = vmi_get_sched_cycles; + paravirt_ops.sched_clock = vmi_sched_clock; paravirt_ops.get_cpu_khz = vmi_cpu_khz;/* We have true wallclock functions; disable CMOS clock sync */
===================================================================
arch/i386/kernel/vmiclock.c +4 -4
@@ -64,10 +64,10 @@ int vmi_set_wallclock(unsigned long now)return 0 ; } -/* paravirt_ops.get_scheduled_cycles = vmi_get_sched_cycles */ -unsigned long long vmi_get_sched_cycles (void ) -{ -return vmi_timer_ops.get_cycle_counter (VMI_CYCLES_AVAILABLE ); +/* paravirt_ops.sched_clock = vmi_sched_clock */ +unsigned long long vmi_sched_clock (void ) +{ +return cycles_2_ns (vmi_timer_ops.get_cycle_counter (VMI_CYCLES_AVAILABLE )); }/* paravirt_ops.get_cpu_khz = vmi_cpu_khz */
===================================================================
include/asm-i386/paravirt.h +5 -2
@@ -116,7 +116,7 @@ struct paravirt_opsu64 (*read_tsc)(void);u64 (*read_pmc)(void); -u64 (*get_scheduled_cycles)(void); +unsigned long long (*sched_clock)(void );unsigned long (*get_cpu_khz)(void );/* Segment descriptor handling */
@@ -573,7 +573,10 @@ static inline u64 paravirt_read_tsc(void#define rdtscll (val) (val = paravirt_read_tsc()) -#define get_scheduled_cycles (val) (val = paravirt_ops.get_scheduled_cycles()) +static inline unsigned long long paravirt_sched_clock (void ) +{ + return PVOP_CALL0(unsigned long long, sched_clock); +}#define calculate_cpu_khz () (paravirt_ops.get_cpu_khz())#define write_tsc (val1,val2) wrmsr(0x10, val1, val2)
===================================================================
include/asm-i386/timer.h +31 -1
@@ -15,8 +15,38 @@ extern int recalibrate_cpu_khz(void);extern int recalibrate_cpu_khz (void );#ifndef CONFIG_PARAVIRT -#define get_scheduled_cycles (val) rdtscll(val)#define calculate_cpu_khz () native_calculate_cpu_khz()#endif +/* Accellerators for sched_clock() +* convert from cycles(64bits) => nanoseconds (64bits) +* basic equation: +* ns = cycles / (freq / ns_per_sec) +* ns = cycles * (ns_per_sec / freq) +* ns = cycles * (10^9 / (cpu_khz * 10^3)) +* ns = cycles * (10^6 / cpu_khz) +* +* Then we use scaling math (suggested by [email protected]) to get: +* ns = cycles * (10^6 * SC / cpu_khz) / SC +* ns = cycles * cyc2ns_scale / SC +* +* And since SC is a constant power of two, we can convert the div +* into a shift. +* +* We can use khz divisor instead of mhz to keep a better percision, since +* cyc2ns_scale is limited to 10^6 * 2^10, which fits in 32 bits. +* ([email protected]) +* +* [email protected] "math is hard, lets go shopping!" +*/ +extern unsigned long cyc2ns_scale__read_mostly ; + +#define CYC2NS_SCALE_FACTOR 10/* 2^10, carefully chosen */ + +static inline unsigned long long cycles_2_ns (unsigned long long cyc) +{ +return (cyc * cyc2ns_scale) >>CYC2NS_SCALE_FACTOR ; +} + +#endif
===================================================================
include/asm-i386/vmi_time.h +1 -1
@@ -49,7 +49,7 @@ extern void __init vmi_time_init(void);extern void __init vmi_time_init (void );extern unsigned long vmi_get_wallclock (void );extern int vmi_set_wallclock (unsigned long now); -extern unsigned long long vmi_get_sched_cycles (void ); +extern unsigned long long vmi_sched_clock (void );extern unsigned long vmi_cpu_khz (void );#ifdef CONFIG_X86_LOCAL_APIC
PATCH 17/44 Add nosegneg capability to the vsyscall page notes
In reply to a message not in the archiveAdd the "nosegneg" fake capabilty to the vsyscall page notes. This is used by the runtime linker to select a glibc version which then disables negative-offset accesses to the thread-local segment via %gs. These accesses require emulation in Xen (because segments are truncated to protect the hypervisor address space) and avoiding them provides a measurable performance boost.
--- arch/i386/kernel/vsyscall-note.S | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)
===================================================================
arch/i386/kernel/vsyscall-note.S +28 -0
@@ -12,3 +12,31 @@ ELFNOTE_START(Linux, 0, "a") ELFNOTE_START(Linux, 0, "a") .long LINUX_VERSION_CODE ELFNOTE_END + +#ifdef CONFIG_XEN + +/* + * Add a special note telling glibc's dynamic linker a fake hardware + * flavor that it will use to choose the search path for libraries in the + * same way it uses real hardware capabilities like "mmx". + * We supply "nosegneg" as the fake capability, to indicate that we + * do not like negative offsets in instructions using segment overrides, + * since we implement those inefficiently. This makes it possible to + * install libraries optimized to avoid those access patterns in someplace + * like /lib/i686/tls/nosegneg. Note that an /etc/ld.so.conf.d/file + * corresponding to the bits here is needed to make ldconfig work right. + * It should contain: + * hwcap 1 nosegneg + * to match the mapping of bit to name that we give here. + */ + +/* Bit used for the pseudo-hwcap for non-negative segments. We use + bit 1 to avoid bugs in some versions of glibc when bit 0 is + used; the choice is otherwise arbitrary. */ +#define VDSO_NOTE_NONEGSEG_BIT 1 + +ELFNOTE_START(GNU, 2, "a") + .long 1, 1<<VDSO_NOTE_NONEGSEG_BIT /* ncaps, mask */ + .byte VDSO_NOTE_NONEGSEG_BIT; .asciz "nosegneg" /* bit, name */ +ELFNOTE_END +#endif
PATCH 18/44 xen: Add Xen interface header files
In reply to a message not in the archiveAdd Xen interface header files. These are taken fairly directly from the Xen tree, but somewhat rearranged to suit the kernel's conventions.
Define macros and inline functions for doing hypercalls into the hypervisor.
--- include/asm-i386/xen/hypercall.h | 395 +++++++++++++++++++++++++++++ include/asm-i386/xen/hypervisor.h | 72 +++++ include/asm-i386/xen/interface.h | 188 +++++++++++++ include/xen/interface/elfnote.h | 133 +++++++++ include/xen/interface/event_channel.h | 195 ++++++++++++++ include/xen/interface/features.h | 43 +++ include/xen/interface/grant_table.h | 301 ++++++++++++++++++++++ include/xen/interface/io/blkif.h | 94 ++++++ include/xen/interface/io/console.h | 23 + include/xen/interface/io/netif.h | 158 +++++++++++ include/xen/interface/io/ring.h | 260 +++++++++++++++++++ include/xen/interface/io/xenbus.h | 44 +++ include/xen/interface/io/xs_wire.h | 87 ++++++ include/xen/interface/memory.h | 145 ++++++++++ include/xen/interface/physdev.h | 145 ++++++++++ include/xen/interface/sched.h | 77 +++++ include/xen/interface/vcpu.h | 154 +++++++++++ include/xen/interface/version.h | 60 ++++ include/xen/interface/xen.h | 447 +++++++++++++++++++++++++++++++++ 19 files changed, 3021 insertions(+)
===================================================================
include/asm-i386/xen/hypercall.h new file +395 -0
@@ -0,0 +1,395 @@ +/****************************************************************************** +* hypercall.h +* +* Linux-specific hypervisor handling. +* +* Copyright (c) 2002-2004, K A Fraser +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License version 2 +* as published by the Free Software Foundation; or, when distributed +* separately from the Linux kernel or incorporated into other +* software packages, subject to the following license: +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this source file (the "Software"), to deal in the Software without +* restriction, including without limitation the rights to use, copy, modify, +* merge, publish, distribute, sublicense, and/or sell copies of the Software, +* and to permit persons to whom the Software is furnished to do so, subject to +* the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +* IN THE SOFTWARE. +*/ + +#ifndef __HYPERCALL_H__ +#define __HYPERCALL_H__ + +#include <linux/errno.h> +#include <linux/string.h> + +#include <xen/interface/xen.h> +#include <xen/interface/sched.h> +#include <xen/interface/physdev.h> + +extern struct {char _entry[32 ]; } hypercall_page[]; + +#define _hypercall0 (type, name) \ +({ \ + long __res; \ + asm volatile ( \ + "call %[call]" \ + : "=a" (__res) \ + : [call] "m" (hypercall_page[__HYPERVISOR_##name]) \ + : "memory" ); \ + (type)__res; \ +}) + +#define _hypercall1 (type, name, a1) \ +({ \ + long __res, __ign1; \ + asm volatile ( \ + "call %[call]" \ + : "=a" (__res), "=b" (__ign1) \ + : "1" ((long)(a1)), \ + [call] "m" (hypercall_page[__HYPERVISOR_##name]) \ + : "memory" ); \ + (type)__res; \ +}) + +#define _hypercall2 (type, name, a1, a2) \ +({ \ + long __res, __ign1, __ign2; \ + asm volatile ( \ + "call %[call]" \ + : "=a" (__res), "=b" (__ign1), "=c" (__ign2) \ + : "1" ((long)(a1)), "2" ((long)(a2)), \ + [call] "m" (hypercall_page[__HYPERVISOR_##name]) \ + : "memory" ); \ + (type)__res; \ +}) + +#define _hypercall3 (type, name, a1, a2, a3) \ +({ \ + long __res, __ign1, __ign2, __ign3; \ + asm volatile ( \ + "call %[call]" \ + : "=a" (__res), "=b" (__ign1), "=c" (__ign2), \ + "=d" (__ign3) \ + : "1" ((long)(a1)), "2" ((long)(a2)), \ + "3" ((long)(a3)), \ + [call] "m" (hypercall_page[__HYPERVISOR_##name]) \ + : "memory" ); \ + (type)__res; \ +}) + +#define _hypercall4 (type, name, a1, a2, a3, a4) \ +({ \ + long __res, __ign1, __ign2, __ign3, __ign4; \ + asm volatile ( \ + "call %[call]" \ + : "=a" (__res), "=b" (__ign1), "=c" (__ign2), \ + "=d" (__ign3), "=S" (__ign4) \ + : "1" ((long)(a1)), "2" ((long)(a2)), \ + "3" ((long)(a3)), "4" ((long)(a4)), \ + [call] "m" (hypercall_page[__HYPERVISOR_##name]) \ + : "memory" ); \ + (type)__res; \ +}) + +#define _hypercall5 (type, name, a1, a2, a3, a4, a5) \ +({ \ + long __res, __ign1, __ign2, __ign3, __ign4, __ign5; \ + asm volatile ( \ + "call %[call]" \ + : "=a" (__res), "=b" (__ign1), "=c" (__ign2), \ + "=d" (__ign3), "=S" (__ign4), "=D" (__ign5) \ + : "1" ((long)(a1)), "2" ((long)(a2)), \ + "3" ((long)(a3)), "4" ((long)(a4)), \ + "5" ((long)(a5)), \ + [call] "m" (hypercall_page[__HYPERVISOR_##name]) \ + : "memory" ); \ + (type)__res; \ +}) + +static inline int +HYPERVISOR_set_trap_table (struct trap_info *table) +{ +return _hypercall1 (int, set_trap_table, table); +} + +static inline int +HYPERVISOR_mmu_update (struct mmu_update *req,int count, +int *success_count,domid_t domid) +{ +return _hypercall4 (int, mmu_update, req, count, success_count, domid); +} + +static inline int +HYPERVISOR_mmuext_op (struct mmuext_op *op,int count, +int *success_count,domid_t domid) +{ +return _hypercall4 (int, mmuext_op, op, count, success_count, domid); +} + +static inline int +HYPERVISOR_set_gdt (unsigned long *frame_list,int entries) +{ +return _hypercall2 (int, set_gdt, frame_list, entries); +} + +static inline int +HYPERVISOR_stack_switch (unsigned long ss,unsigned long esp) +{ +return _hypercall2 (int, stack_switch, ss, esp); +} + +static inline int +HYPERVISOR_set_callbacks (unsigned long event_selector, +unsigned long event_address, +unsigned long failsafe_selector, +unsigned long failsafe_address) +{ +return _hypercall4 (int, set_callbacks, + event_selector, event_address, + failsafe_selector, failsafe_address); +} + +static inline int +HYPERVISOR_fpu_taskswitch (int set) +{ +return _hypercall1 (int, fpu_taskswitch, set); +} + +static inline int +HYPERVISOR_sched_op (int cmd,unsigned long arg) +{ +return _hypercall2 (int, sched_op, cmd, arg); +} + +static inline long +HYPERVISOR_set_timer_op (u64 timeout) +{ +unsigned long timeout_hi = (unsigned long )(timeout>>32 ); +unsigned long timeout_lo = (unsigned long )timeout; +return _hypercall2 (long, set_timer_op, timeout_lo, timeout_hi); +} + +static inline int +HYPERVISOR_set_debugreg (int reg,unsigned long value) +{ +return _hypercall2 (int, set_debugreg, reg, value); +} + +static inline unsigned long +HYPERVISOR_get_debugreg (int reg) +{ + return _hypercall1(unsigned long, get_debugreg, reg); +} + +static inline int +HYPERVISOR_update_descriptor (u64 ma,u64 desc) +{ +return _hypercall4 (int, update_descriptor, ma, ma>>32 , desc, desc>>32 ); +} + +static inline int +HYPERVISOR_memory_op (unsigned int cmd,void *arg) +{ +return _hypercall2 (int, memory_op, cmd, arg); +} + +static inline int +HYPERVISOR_multicall (void *call_list,int nr_calls) +{ +return _hypercall2 (int, multicall, call_list, nr_calls); +} + +static inline int +HYPERVISOR_update_va_mapping (unsigned long va,pte_t new_val, +unsigned long flags) +{ +unsigned long pte_hi =0 ; +#ifdef CONFIG_X86_PAE + pte_hi = new_val.pte_high; +#endif +return _hypercall4 (int, update_va_mapping, va, + new_val.pte_low, pte_hi, flags); +} + +static inline int +HYPERVISOR_event_channel_op (int cmd,void *arg) +{ +int rc =_hypercall2 (int, event_channel_op, cmd, arg); +if (unlikely (rc == -ENOSYS )) { +struct evtchn_op op; + op.cmd = cmd; +memcpy (&op.u, arg,sizeof (op.u)); + rc =_hypercall1 (int, event_channel_op_compat, &op); +memcpy (arg, &op.u,sizeof (op.u)); + } +return rc; +} + +static inline int +HYPERVISOR_xen_version (int cmd,void *arg) +{ +return _hypercall2 (int, xen_version, cmd, arg); +} + +static inline int +HYPERVISOR_console_io (int cmd,int count,char *str) +{ +return _hypercall3 (int, console_io, cmd, count, str); +} + +static inline int +HYPERVISOR_physdev_op (int cmd,void *arg) +{ +int rc =_hypercall2 (int, physdev_op, cmd, arg); +if (unlikely (rc == -ENOSYS )) { +struct physdev_op op; + op.cmd = cmd; +memcpy (&op.u, arg,sizeof (op.u)); + rc =_hypercall1 (int, physdev_op_compat, &op); +memcpy (arg, &op.u,sizeof (op.u)); + } +return rc; +} + +static inline int +HYPERVISOR_grant_table_op (unsigned int cmd,void *uop,unsigned int count) +{ +return _hypercall3 (int, grant_table_op, cmd, uop, count); +} + +static inline int +HYPERVISOR_update_va_mapping_otherdomain (unsigned long va,pte_t new_val, +unsigned long flags,domid_t domid) +{ +unsigned long pte_hi =0 ; +#ifdef CONFIG_X86_PAE + pte_hi = new_val.pte_high; +#endif +return _hypercall5 (int, update_va_mapping_otherdomain, va, + new_val.pte_low, pte_hi, flags, domid); +} + +static inline int +HYPERVISOR_vm_assist (unsigned int cmd,unsigned int type) +{ +return _hypercall2 (int, vm_assist, cmd, type); +} + +static inline int +HYPERVISOR_vcpu_op (int cmd,int vcpuid,void *extra_args) +{ +return _hypercall3 (int, vcpu_op, cmd, vcpuid, extra_args); +} + +static inline int +HYPERVISOR_suspend (unsigned long srec) +{ +return _hypercall3 (int, sched_op, SCHEDOP_shutdown, + SHUTDOWN_suspend, srec); +} + +static inline int +HYPERVISOR_nmi_op (unsigned long op,unsigned long arg) +{ +return _hypercall2 (int, nmi_op, op, arg); +} + +static inline void +MULTI_update_va_mapping (struct multicall_entry *mcl,unsigned long va, +pte_t new_val,unsigned long flags) +{ + mcl->op = __HYPERVISOR_update_va_mapping; + mcl->args[0 ] = va; +#ifdef CONFIG_X86_PAE + mcl->args[1 ] = new_val.pte_low; + mcl->args[2 ] = new_val.pte_high; +#else + mcl->args[1 ] = new_val.pte_low; + mcl->args[2 ] =0 ; +#endif + mcl->args[3 ] = flags; +} + +static inline void +MULTI_grant_table_op (struct multicall_entry *mcl,unsigned int cmd, +void *uop,unsigned int count) +{ + mcl->op = __HYPERVISOR_grant_table_op; + mcl->args[0 ] = cmd; + mcl->args[1 ] = (unsigned long )uop; + mcl->args[2 ] = count; +} + +static inline void +MULTI_update_va_mapping_otherdomain (struct multicall_entry *mcl,unsigned long va, +pte_t new_val,unsigned long flags, +domid_t domid) +{ + mcl->op = __HYPERVISOR_update_va_mapping_otherdomain; + mcl->args[0 ] = va; +#ifdef CONFIG_X86_PAE + mcl->args[1 ] = new_val.pte_low; + mcl->args[2 ] = new_val.pte_high; +#else + mcl->args[1 ] = new_val.pte_low; + mcl->args[2 ] =0 ; +#endif + mcl->args[3 ] = flags; + mcl->args[4 ] = domid; +} + +static inline void +MULTI_update_descriptor (struct multicall_entry *mcl,u64 maddr, +struct desc_struct desc) +{ + mcl->op = __HYPERVISOR_update_descriptor; + mcl->args[0 ] = maddr; + mcl->args[1 ] = maddr >>32 ; + mcl->args[2 ] = desc.a; + mcl->args[3 ] = desc.b; +} + +static inline void +MULTI_memory_op (struct multicall_entry *mcl,unsigned int cmd,void *arg) +{ + mcl->op = __HYPERVISOR_memory_op; + mcl->args[0 ] = cmd; + mcl->args[1 ] = (unsigned long )arg; +} + +static inline void +MULTI_mmu_update (struct multicall_entry *mcl,struct mmu_update *req, +int count,int *success_count,domid_t domid) +{ + mcl->op = __HYPERVISOR_mmu_update; + mcl->args[0 ] = (unsigned long )req; + mcl->args[1 ] = count; + mcl->args[2 ] = (unsigned long )success_count; + mcl->args[3 ] = domid; +} + +static inline void +MULTI_mmuext_op (struct multicall_entry *mcl,struct mmuext_op *op,int count, +int *success_count,domid_t domid) +{ + mcl->op = __HYPERVISOR_mmuext_op; + mcl->args[0 ] = (unsigned long )op; + mcl->args[1 ] = count; + mcl->args[2 ] = (unsigned long )success_count; + mcl->args[3 ] = domid; +} +#endif /* __HYPERCALL_H__ */
===================================================================
include/asm-i386/xen/hypervisor.h new file +72 -0
72 lines not on this page · raw message
===================================================================
include/asm-i386/xen/interface.h new file +188 -0
188 lines not on this page · raw message
===================================================================
include/xen/interface/elfnote.h new file +133 -0
133 lines not on this page · raw message
===================================================================
include/xen/interface/event_channel.h new file +195 -0
195 lines not on this page · raw message
===================================================================
include/xen/interface/features.h new file +43 -0
43 lines not on this page · raw message
===================================================================
include/xen/interface/grant_table.h new file +301 -0
301 lines not on this page · raw message
===================================================================
include/xen/interface/io/blkif.h new file +94 -0
94 lines not on this page · raw message
===================================================================
include/xen/interface/io/console.h new file +23 -0
@@ -0,0 +1,23 @@ +/****************************************************************************** +* console.h +* +* Console I/O interface for Xen guest OSes. +* +* Copyright (c) 2005, Keir Fraser +*/ + +#ifndef __XEN_PUBLIC_IO_CONSOLE_H__ +#define __XEN_PUBLIC_IO_CONSOLE_H__ + +typedef uint32_t XENCONS_RING_IDX ; + +#define MASK_XENCONS_IDX (idx, ring) ((idx) & (sizeof(ring)-1)) + +struct xencons_interface { +char in[1024 ]; +char out[2048 ]; +XENCONS_RING_IDX in_cons, in_prod; +XENCONS_RING_IDX out_cons, out_prod; +}; + +#endif /* __XEN_PUBLIC_IO_CONSOLE_H__ */
===================================================================
include/xen/interface/io/netif.h new file +158 -0
158 lines not on this page · raw message
===================================================================
include/xen/interface/io/ring.h new file +260 -0
260 lines not on this page · raw message
===================================================================
include/xen/interface/io/xenbus.h new file +44 -0
44 lines not on this page · raw message
===================================================================
include/xen/interface/io/xs_wire.h new file +87 -0
87 lines not on this page · raw message
===================================================================
include/xen/interface/memory.h new file +145 -0
145 lines not on this page · raw message
===================================================================
include/xen/interface/physdev.h new file +145 -0
145 lines not on this page · raw message
===================================================================
include/xen/interface/sched.h new file +77 -0
77 lines not on this page · raw message
===================================================================
include/xen/interface/vcpu.h new file +154 -0
154 lines not on this page · raw message
===================================================================
include/xen/interface/version.h new file +60 -0
60 lines not on this page · raw message
===================================================================
include/xen/interface/xen.h new file +447 -0
426 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Part of the diff is not shown here. View the raw message.
PATCH 19/44 xen: Core Xen implementation
In reply to a message not in the archiveThis patch is a rollup of all the core pieces of the Xen implementation, including:
- booting and setup
- pagetable setup
- privileged instructions
- segmentation
- interrupt flags
- upcalls
- multicall batching
BOOTING AND SETUP
The vmlinux image is decorated with ELF notes which tell the Xen domain builder what the kernel's requirements are; the domain builder then constructs the address space accordingly and starts the kernel.
Xen has its own entrypoint for the kernel (contained in an ELF note). The ELF notes are set up by xen-head.S, which is included into head.S. In principle it could be linked separately, but it seems to provoke lots of binutils bugs.
Because the domain builder starts the kernel in a fairly sane state (32-bit protected mode, paging enabled, flat segments set up), there's not a lot of setup needed before starting the kernel proper. The main steps are:
1. Install the Xen paravirt_ops, which is simply a matter of a structure assignment.
2. Set init_mm to use the Xen-supplied pagetables (analogous to the head.S generated pagetables in a native boot).
3. Reserve address space for Xen, since it takes a chunk at the top of the address space for its own use.
4. Call start_kernel()
PAGETABLE SETUP
Once we hit the main kernel boot sequence, it will end up calling back via paravirt_ops to set up various pieces of Xen specific state. One of the critical things which requires a bit of extra care is the construction of the initial init_mm pagetable. Because Xen places tight constraints on pagetables (an active pagetable must always be valid, and must always be mapped read-only to the guest domain), we need to be careful when constructing the new pagetable to keep these constraints in mind. It turns out that the easiest way to do this is use the initial Xen-provided pagetable as a template, and then just insert new mappings for memory where a mapping doesn't already exist.
This means that during pagetable setup, it uses a special version of xen_set_pte which ignores any attempt to remap a read-only page as read-write (since Xen will map its own initial pagetable as RO), but lets other changes to the ptes happen, so that things like NX are set properly.
PRIVILEGED INSTRUCTIONS AND SEGMENTATION
When the kernel runs under Xen, it runs in ring 1 rather than ring 0. This means that it is more privileged than user-mode in ring 3, but it still can't run privileged instructions directly. Non-performance critical instructions are dealt with by taking a privilege exception and trapping into the hypervisor and emulating the instruction, but more performance-critical instructions have their own specific paravirt_ops. In many cases we can avoid having to do any hypercalls for these instructions, or the Xen implementation is quite different from the normal native version.
The privileged instructions fall into the broad classes of:
Segmentation: setting up the GDT and the GDT entries, LDT,
TLS and so on. Xen doesn't allow the GDT to be directly modified; all GDT updates are done via hypercalls where the new entries can be validated. This is important because Xen uses segment limits to prevent the guest kernel from damaging the hypervisor itself.
Traps and exceptions: Xen uses a special format for trap entrypoints,
so when the kernel wants to set an IDT entry, it needs to be converted to the form Xen expects. Xen sets int 0x80 up specially so that the trap goes straight from userspace into the guest kernel without going via the hypervisor. sysenter isn't supported.
Kernel stack: The esp0 entry is extracted from the tss and provided to
Xen.
TLB operations: the various TLB calls are mapped into corresponding
Xen hypercalls.
Control registers: all the control registers are privileged. The most
important is cr3, which points to the base of the current pagetable, and we handle it specially.
Another instruction we treat specially is CPUID, even though its not privileged. We want to control what CPU features are visible to the rest of the kernel, and so CPUID ends up going into a paravirt_op. Xen implements this mainly to disable the ACPI and APIC subsystems.
INTERRUPT FLAGS
Xen maintains its own separate flag for masking events, which is contained within the per-cpu vcpu_info structure. Because the guest kernel runs in ring 1 and not 0, the IF flag in EFLAGS is completely ignored (and must be, because even if a guest domain disables interrupts for itself, it can't disable them overall).
(A note on terminology: "events" and interrupts are effectively synonymous. However, rather than using an "enable flag", Xen uses a "mask flag", which blocks event delivery when it is non-zero.)
There are paravirt_ops for each of cli/sti/save_fl/restore_fl, which are implemented to manage the Xen event mask state. The only thing worth noting is that when events are unmasked, we need to explicitly see if there's a pending event and call into the hypervisor to make sure it gets delivered.
UPCALLS
Xen needs a couple of upcall (or callback) functions to be implemented by each guest. One is the event upcalls, which is how events (interrupts, effectively) are delivered to the guests. The other is the failsafe callback, which is used to report errors in either reloading a segment register, or caused by iret. These are implemented in i386/kernel/entry.S so they can jump into the normal iret_exc path when necessary.
MULTICALL BATCHING
Xen provides a multicall mechanism, which allows multiple hypercalls to be issued at once in order to mitigate the cost of trapping into the hypervisor. This is particularly useful for context switches, since the 4-5 hypercalls they would normally need (reload cr3, update TLS, maybe update LDT) can be reduced to one. This patch implements a generic batching mechanism for hypercalls, which gets used in many places in the Xen code.
--- arch/i386/Makefile | 3 arch/i386/kernel/entry.S | 71 +++ arch/i386/kernel/head.S | 5 arch/i386/kernel/vmlinux.lds.S | 1 arch/i386/xen/Makefile | 1 arch/i386/xen/enlighten.c | 745 ++++++++++++++++++++++++++++++++++++++ arch/i386/xen/features.c | 29 + arch/i386/xen/multicalls.c | 89 ++++ arch/i386/xen/multicalls.h | 45 ++ arch/i386/xen/setup.c | 97 ++++ arch/i386/xen/xen-head.S | 36 + arch/i386/xen/xen-ops.h | 31 + include/asm-i386/irq.h | 1 include/asm-i386/xen/hypercall.h | 18 include/xen/features.h | 23 + include/xen/page.h | 179 +++++++++ 16 files changed, 1373 insertions(+), 1 deletion(-)
===================================================================
arch/i386/Makefile +3 -0
@@ -93,6 +93,9 @@ mcore-$(CONFIG_X86_ES7000) := mach-defau mcore-$(CONFIG_X86_ES7000) := mach-default core-$(CONFIG_X86_ES7000) := arch/i386/mach-es7000/ +# Xen paravirtualization support +core-$(CONFIG_XEN) += arch/i386/xen/ + # default subarch .h files mflags-y += -Iinclude/asm-i386/mach-default
===================================================================
arch/i386/kernel/entry.S +71 -0
77 lines not on this page · raw message
===================================================================
arch/i386/kernel/head.S +4 -1
@@ -504,7 +504,8 @@ ENTRY(_stext) /* * BSS section */ -.section ".bss.page_aligned","w" +.section ".bss.page_aligned","wa" + .align PAGE_SIZE_asm ENTRY(swapper_pg_dir) .fill 1024,4,0 ENTRY(empty_zero_page)
@@ -529,6 +530,8 @@ fault_msg: fault_msg: .ascii "Int %d: CR2 %p err %p EIP %p CS %p flags %p\n" .asciz "Stack: %p %p %p %p %p %p %p %p\n" + +#include "../xen/xen-head.S" /* * The IDT and GDT 'descriptors' are a strange 48-bit object
===================================================================
arch/i386/kernel/vmlinux.lds.S +1 -0
@@ -88,6 +88,7 @@ SECTIONS . = ALIGN(4096); .data.page_aligned : AT(ADDR(.data.page_aligned) - LOAD_OFFSET) { + *(.data.page_aligned) *(.data.idt) }
===================================================================
arch/i386/xen/Makefile new file +1 -0
@@ -0,0 +1,1 @@ +obj-y := enlighten.o setup.o features.o multicalls.o
===================================================================
arch/i386/xen/enlighten.c new file +745 -0
745 lines not on this page · raw message
===================================================================
arch/i386/xen/features.c new file +29 -0
@@ -0,0 +1,29 @@ +/****************************************************************************** +* features.c +* +* Xen feature flags. +* +* Copyright (c) 2006, Ian Campbell, XenSource Inc. +*/ +#include <linux/types.h> +#include <linux/cache.h> +#include <linux/module.h> +#include <asm/xen/hypervisor.h> +#include <xen/features.h> + +u8 xen_features[XENFEAT_NR_SUBMAPS *32 ]__read_mostly ; +EXPORT_SYMBOL_GPL (xen_features); + +void xen_setup_features (void ) +{ +struct xen_feature_info fi; +int i, j; + +for (i =0 ; i <XENFEAT_NR_SUBMAPS ; i++) { + fi.submap_idx = i; +if (HYPERVISOR_xen_version (XENVER_get_features, &fi) <0 ) +break ; +for (j =0 ; j <32 ; j++) + xen_features[i *32 + j] = !!(fi.submap &1 <<j); + } +}
===================================================================
arch/i386/xen/multicalls.c new file +89 -0
89 lines not on this page · raw message
===================================================================
arch/i386/xen/multicalls.h new file +45 -0
45 lines not on this page · raw message
===================================================================
arch/i386/xen/setup.c new file +97 -0
97 lines not on this page · raw message
===================================================================
arch/i386/xen/xen-head.S new file +36 -0
@@ -0,0 +1,36 @@ +/* Xen-specific pieces of head.S, intended to be included in the right + place in head.S */ + +#ifdef CONFIG_XEN + +#include <linux/elfnote.h> +#include <asm/boot.h> +#include <xen/interface/elfnote.h> + +ENTRY(startup_xen) + movl %esi,xen_start_info + cld + movl $(init_thread_union+THREAD_SIZE),%esp + jmp xen_start_kernel + +.pushsection ".bss.page_aligned" + .align PAGE_SIZE_asm +ENTRY(hypercall_page) + .skip 0x1000 +.popsection + + ELFNOTE(Xen, XEN_ELFNOTE_GUEST_OS, .asciz "linux") + ELFNOTE(Xen, XEN_ELFNOTE_GUEST_VERSION, .asciz "2.6") + ELFNOTE(Xen, XEN_ELFNOTE_XEN_VERSION, .asciz "xen-3.0") + ELFNOTE(Xen, XEN_ELFNOTE_VIRT_BASE, .long __PAGE_OFFSET) + ELFNOTE(Xen, XEN_ELFNOTE_ENTRY, .long startup_xen) + ELFNOTE(Xen, XEN_ELFNOTE_HYPERCALL_PAGE, .long hypercall_page) + ELFNOTE(Xen, XEN_ELFNOTE_FEATURES, .asciz "!writable_page_tables|pae_pgdir_above_4gb") +#ifdef CONFIG_X86_PAE + ELFNOTE(Xen, XEN_ELFNOTE_PAE_MODE, .asciz "yes") +#else + ELFNOTE(Xen, XEN_ELFNOTE_PAE_MODE, .asciz "no") +#endif + ELFNOTE(Xen, XEN_ELFNOTE_LOADER, .asciz "generic") + +#endif /*CONFIG_XEN */
===================================================================
arch/i386/xen/xen-ops.h new file +31 -0
@@ -0,0 +1,31 @@ +#ifndef XEN_OPS_H +#define XEN_OPS_H + +#include <linux/init.h> +#include <linux/clocksource.h> + +DECLARE_PER_CPU(struct vcpu_info *, xen_vcpu); +DECLARE_PER_CPU(unsigned long, xen_cr3); + +extern struct start_info *xen_start_info; +extern struct shared_info *HYPERVISOR_shared_info; + +char *__init xen_memory_setup (void ); +void __init xen_arch_setup (void ); +void __init xen_init_IRQ (void ); + +unsigned long xen_cpu_khz (void ); +void __init xen_time_init (void ); +unsigned long xen_get_wallclock (void ); +int xen_set_wallclock (unsigned long time); +cycle_t xen_clocksource_read (void ); + +DECLARE_PER_CPU(enum paravirt_lazy_mode, xen_lazy_mode); + +static inline unsigned xen_get_lazy_mode (void ) +{ +return x86_read_percpu (xen_lazy_mode); +} + + +#endif /* XEN_OPS_H */
===================================================================
include/asm-i386/irq.h +1 -0
@@ -41,6 +41,7 @@ extern void fixup_irqs(cpumask_t map);extern void fixup_irqs (cpumask_t map);#endif +unsigned int do_IRQ (struct pt_regs *regs);void init_IRQ (void );void __init native_init_IRQ (void );
===================================================================
include/asm-i386/xen/hypercall.h +18 -0
@@ -392,4 +392,22 @@ MULTI_mmuext_op(struct multicall_entry * mcl->args[2 ] = (unsigned long )success_count; mcl->args[3] = domid; } + +static inline void +MULTI_set_gdt (struct multicall_entry *mcl,unsigned long *frames,int entries) +{ + mcl->op = __HYPERVISOR_set_gdt; + mcl->args[0 ] = (unsigned long )frames; + mcl->args[1 ] = entries; +} + +static inline void +MULTI_stack_switch (struct multicall_entry *mcl, +unsigned long ss,unsigned long esp) +{ + mcl->op = __HYPERVISOR_stack_switch; + mcl->args[0 ] = ss; + mcl->args[1 ] = esp; +} +#endif /* __HYPERCALL_H__ */
===================================================================
include/xen/features.h new file +23 -0
@@ -0,0 +1,23 @@ +/****************************************************************************** +* features.h +* +* Query the features reported by Xen. +* +* Copyright (c) 2006, Ian Campbell +*/ + +#ifndef __XEN_FEATURES_H__ +#define __XEN_FEATURES_H__ + +#include <xen/interface/features.h> + +void xen_setup_features (void ); + +extern u8 xen_features[XENFEAT_NR_SUBMAPS *32 ]; + +static inline int xen_feature (int flag) +{ +return xen_features[flag]; +} + +#endif /* __ASM_XEN_FEATURES_H__ */
===================================================================
include/xen/page.h new file +179 -0
179 lines not on this page · raw message
PATCH 20/44 xen: virtual mmu
In reply to a message not in the archiveXen pagetable handling, including the machinery to implement direct pagetables.
Xen presents the real CPU's pagetables directly to guests, with no added shadowing or other layer of abstraction. Naturally this means the hypervisor must maintain close control over what the guest can put into the pagetable.
When the guest modifies the pte/pmd/pgd, it must convert its domain-specific notion of a "physical" pfn into a global machine frame number (mfn) before inserting the entry into the pagetable. Xen will check to make sure the domain is allowed to create a mapping of the given mfn.
Xen also requires that all mappings the guest has of its own active pagetable are read-only. This is relatively easy to implement in Linux because all pagetables share the same pte pages for kernel mappings, so updating the pte in one pagetable will implicitly update the mapping in all pagetables.
Normally a pagetable becomes active when you point to it with cr3 (or the Xen equivalent), but when you do so, Xen must check the whole pagetable for correctness, which is clearly a performance problem.
Xen solves this with pinning which keeps a pagetable effectively active even if its currently unused, which means that all the normal update rules are enforced. This means that it need not revalidate the pagetable when loading cr3.
This patch has a first-cut implementation of pinning, but it is more fully implemented in a later patch.
--- arch/i386/xen/Makefile | 2 arch/i386/xen/enlighten.c | 30 ++- arch/i386/xen/mmu.c | 420 +++++++++++++++++++++++++++++++++++++++++++++ arch/i386/xen/mmu.h | 47 +++++ 4 files changed, 494 insertions(+), 5 deletions(-)
===================================================================
arch/i386/xen/Makefile +1 -1
@@ -1,1 +1,1 @@ obj-y := enlighten.o setup.o features.o -obj-y := enlighten.o setup.o features.o multicalls.o +obj-y := enlighten.o setup.o features.o multicalls.o mmu.o
===================================================================
arch/i386/xen/enlighten.c +26 -4
@@ -39,6 +39,7 @@#include <asm/pgtable.h> #include "xen-ops.h" +#include "mmu.h" #include "multicalls.h" EXPORT_SYMBOL_GPL (hypercall_page);
@@ -579,11 +580,9 @@ static __init void xen_pagetable_setup_d* Should be set_fixmap(), but shared_info is a machine * address with no corresponding pseudo-phys address. */ -#if 0 set_pte_mfn (fix_to_virt (FIX_PARAVIRT_BOOTMAP ),PFN_DOWN (xen_start_info->shared_info),PAGE_KERNEL ); -#endif HYPERVISOR_shared_info = (struct shared_info *)fix_to_virt (FIX_PARAVIRT_BOOTMAP );
@@ -592,9 +591,7 @@ static __init void xen_pagetable_setup_d HYPERVISOR_shared_info = (struct shared_info *)__va (xen_start_info->shared_info); -#if 0 xen_pgd_pin (base); -#endif xen_vcpu_setup (smp_processor_id ()); }
@@ -690,6 +687,31 @@ static const struct paravirt_ops xen_par .release_pd = xen_release_pd, .release_pt = xen_release_pt, + .set_pte = xen_set_pte, + .set_pte_at = xen_set_pte_at, + .set_pmd = xen_set_pmd, + + .pte_val = xen_pte_val, + .pgd_val = xen_pgd_val, + + .make_pte = xen_make_pte, + .make_pgd = xen_make_pgd, + +#ifdef CONFIG_X86_PAE + .set_pte_atomic = xen_set_pte_atomic, + .set_pte_present = xen_set_pte_at, + .set_pud = xen_set_pud, + .pte_clear = xen_pte_clear, + .pmd_clear = xen_pmd_clear, + + .make_pmd = xen_make_pmd, + .pmd_val = xen_pmd_val, +#endif /* PAE */ + + .activate_mm = xen_activate_mm, + .dup_mmap = xen_dup_mmap, + .exit_mmap = xen_exit_mmap, + .set_lazy_mode = xen_set_lazy_mode, };
===================================================================
arch/i386/xen/mmu.c new file +420 -0
420 lines not on this page · raw message
===================================================================
arch/i386/xen/mmu.h new file +47 -0
47 lines not on this page · raw message
PATCH 21/44 xen: event channels
In reply to a message not in the archiveXen implements interrupts in terms of event channels. Each guest domain gets 1024 event channels which can be used for a variety of purposes, such as Xen timer events, inter-domain events, inter-processor events (IPI) or for real hardware IRQs.
Within the kernel, we map the event channels to IRQs, and implement the whole interrupt handling using a Xen irq_chip.
Rather than setting NR_IRQ to 1024 under PARAVIRT in order to accomodate Xen, we create a dynamic mapping between event channels and IRQs. Ideally, Linux will eventually move towards dynamically allocating per-irq structures, and we can use a 1:1 mapping between event channels and irqs.
--- arch/i386/xen/Makefile | 3 arch/i386/xen/enlighten.c | 1 arch/i386/xen/events.c | 511 +++++++++++++++++++++++++++++++++++++++++++++ include/xen/events.h | 28 ++ 4 files changed, 542 insertions(+), 1 deletion(-)
===================================================================
arch/i386/xen/Makefile +2 -1
@@ -1,1 +1,2 @@ obj-y := enlighten.o setup.o features.o -obj-y := enlighten.o setup.o features.o multicalls.o mmu.o +obj-y := enlighten.o setup.o features.o multicalls.o mmu.o \ + events.o
===================================================================
arch/i386/xen/enlighten.c +1 -0
@@ -593,6 +593,7 @@ static const struct paravirt_ops xen_par .memory_setup = xen_memory_setup, .arch_setup = xen_arch_setup, + .init_IRQ = xen_init_IRQ, .cpuid = xen_cpuid,
===================================================================
arch/i386/xen/events.c new file +511 -0
511 lines not on this page · raw message
===================================================================
include/xen/events.h new file +28 -0
@@ -0,0 +1,28 @@ +#ifndef _XEN_EVENTS_H +#define _XEN_EVENTS_H + +#include <linux/irq.h> + +int bind_evtchn_to_irqhandler (unsigned int evtchn, +irqreturn_t (*handler)(int ,void *), +unsigned long irqflags,const char *devname, +void *dev_id); +int bind_virq_to_irqhandler (unsigned int virq,unsigned int cpu, +irqreturn_t (*handler)(int ,void *), +unsigned long irqflags,const char *devname,void *dev_id); + +/* +* Common unbind function for all event sources. Takes IRQ to unbind from. +* Automatically closes the underlying event channel (even for bindings +* made with bind_evtchn_to_irqhandler()). +*/ +void unbind_from_irqhandler (unsigned int irq,void *dev_id); + +static inline void notify_remote_via_evtchn (int port) +{ +struct evtchn_send send = { .port = port }; + (void )HYPERVISOR_event_channel_op (EVTCHNOP_send, &send); +} + +extern void notify_remote_via_irq (int irq); +#endif /* _XEN_EVENTS_H */
PATCH 22/44 xen: time implementation
In reply to a message not in the archiveXen maintains a base clock which measures nanoseconds since system boot. This is provided to guests via a shared page which contains a base time in ns, a tsc timestamp at that point and tsc frequency parameters. Guests can compute the current time by reading the tsc and using it to extrapolate the current time from the basetime. The hypervisor makes sure that the frequency parameters are updated regularly, paricularly if the tsc changes rate or stops.
This is implemented as a clocksource, so the interface to the rest of the kernel is a simple clocksource which simply returns the current time directly in nanoseconds.
Xen also provides a simple timer mechanism, which allows a timeout to be set in the future. When that time arrives, a timer event is sent to the guest. There are two timer interfaces:
- An old one which also delivers a stream of (unused) ticks at 100Hz, and on the same event, the actual timer events. The 100Hz ticks cause a lot of spurious wakeups, but are basically harmless.
- The new timer interface doesn't have the 100Hz ticks, and can also fail if the specified time is in the past.
This code presents the Xen timer as a clockevent driver, and uses the new interface by preference.
--- arch/i386/xen/Makefile | 2 arch/i386/xen/enlighten.c | 6 arch/i386/xen/time.c | 407 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 414 insertions(+), 1 deletion(-)
===================================================================
arch/i386/xen/Makefile +1 -1
@@ -1,2 +1,2 @@ obj-y := enlighten.o setup.o features.o obj-y := enlighten.o setup.o features.o multicalls.o mmu.o \ - events.o + events.o time.o
===================================================================
arch/i386/xen/enlighten.c +6 -0
@@ -609,6 +609,12 @@ static const struct paravirt_ops xen_par .arch_setup = xen_arch_setup, .init_IRQ = xen_init_IRQ, + .time_init = xen_time_init, + .set_wallclock = xen_set_wallclock, + .get_wallclock = xen_get_wallclock, + .get_cpu_khz = xen_cpu_khz, + .sched_clock = xen_clocksource_read, + .cpuid = xen_cpuid, .set_debugreg = xen_set_debugreg,
===================================================================
arch/i386/xen/time.c new file +407 -0
407 lines not on this page · raw message
PATCH 23/44 xen: configuration
In reply to a message not in the archivePut config options for Xen after the core pieces are in place.
--- arch/i386/Kconfig | 2 ++ arch/i386/xen/Kconfig | 11 +++++++++++ 2 files changed, 13 insertions(+)
===================================================================
arch/i386/Kconfig +2 -0
@@ -221,6 +221,8 @@ config PARAVIRT under a hypervisor, improving performance significantly. However, when run without a hypervisor the kernel is theoretically slower. If in doubt, say N. + +source "arch/i386/xen/Kconfig" config VMI bool "VMI Paravirt-ops support"
===================================================================
arch/i386/xen/Kconfig new file +11 -0
@@ -0,0 +1,11 @@ +# +# This Kconfig describes xen options +# + +config XEN + bool "Enable support for Xen hypervisor" + depends on PARAVIRT && X86_CMPXCHG && X86_TSC && !(PREEMPT || SMP || NEED_MULTIPLE_NODES) + help + This is the Linux Xen port. Enabling this will allow the + kernel to boot in a paravirtualized environment under the + Xen hypervisor.
PATCH 24/44 xen: add pinned page flag
In reply to a message not in the archiveAdd a new definition for PG_owner_priv_1 to define PG_pinned on Xen pagetable pages.
--- include/linux/page-flags.h | 5 +++++ 1 file changed, 5 insertions(+)
===================================================================
include/linux/page-flags.h +5 -0
@@ -93,6 +93,7 @@/* PG_owner_priv_1 users should have descriptive aliases */ #define PG_checked PG_owner_priv_1/* Used by some filesystems */ +#define PG_pinned PG_owner_priv_1/* Xen pinned pagetable */ #if (BITS_PER_LONG >32 )/*
@@ -170,6 +171,10 @@ static inline void SetPageUptodate(struc#define PageChecked (page) test_bit(PG_checked, &(page)->flags)#define SetPageChecked (page) set_bit(PG_checked, &(page)->flags)#define ClearPageChecked (page) clear_bit(PG_checked, &(page)->flags) + +#define PagePinned (page) test_bit(PG_pinned, &(page)->flags) +#define SetPagePinned (page) set_bit(PG_pinned, &(page)->flags) +#define ClearPagePinned (page) clear_bit(PG_pinned, &(page)->flags)#define PageReserved (page) test_bit(PG_reserved, &(page)->flags)#define SetPageReserved (page) set_bit(PG_reserved, &(page)->flags)
PATCH 25/44 xen: Complete pagetable pinning
In reply to a message not in the archiveXen requires all active pagetables to be marked read-only. When the base of the pagetable is loaded into %cr3, the hypervisor validates the entire pagetable and only allows the load to proceed if it all checks out.
This is pretty slow, so to mitigate this cost Xen has a notion of pinned pagetables. Pinned pagetables are pagetables which are considered to be active even if no processor's cr3 is pointing to is. This means that it must remain read-only and all updates are validated by the hypervisor. This makes context switches much cheaper, because the hypervisor doesn't need to revalidate the pagetable each time.
This also adds a new paravirt hook which is called during setup once the zones and memory allocator have been initialized. When the init_mm pagetable is first built, the struct page array does not yet exist, and so there's nowhere to put he init_mm pagetable's PG_pinned flags. Once the zones are initialized and the struct page array exists, we can set the PG_pinned flags for those pages.
This patch also adds the Xen support for pte pages allocated out of highmem (highpte) by implementing xen_kmap_atomic_pte.
--- arch/i386/xen/enlighten.c | 107 ++++++++++++---- arch/i386/xen/mmu.c | 286 ++++++++++++++++++++++++++++----------------- arch/i386/xen/mmu.h | 2 arch/i386/xen/xen-ops.h | 2 4 files changed, 265 insertions(+), 132 deletions(-)
===================================================================
arch/i386/xen/enlighten.c +79 -28
@@ -21,6 +21,9 @@#include <linux/sched.h> #include <linux/bootmem.h> #include <linux/module.h> +#include <linux/mm.h> +#include <linux/page-flags.h> +#include <linux/highmem.h> #include <xen/interface/xen.h> #include <xen/interface/physdev.h>
@@ -500,32 +503,59 @@ static void xen_write_cr3(unsigned long } } +/* Early in boot, while setting up the initial pagetable, assume +everything is pinned. */ +static void xen_alloc_pt_init (struct mm_struct *mm,u32 pfn) +{ +BUG_ON (mem_map);/* should only be used early */ +make_lowmem_page_readonly (__va (PFN_PHYS (pfn))); +} + +/* This needs to make sure the new pte page is pinned iff its being +attached to a pinned pagetable. */ static void xen_alloc_pt (struct mm_struct *mm,u32 pfn) { -/* XXX pfn isn't necessarily a lowmem page */ -make_lowmem_page_readonly (__va (PFN_PHYS (pfn))); -} - -static void xen_alloc_pd (u32 pfn) -{ -make_lowmem_page_readonly (__va (PFN_PHYS (pfn))); -} - -static void xen_release_pd (u32 pfn) -{ -make_lowmem_page_readwrite (__va (PFN_PHYS (pfn))); -} - +struct page *page =pfn_to_page (pfn); + +if (PagePinned (virt_to_page (mm->pgd))) { +SetPagePinned (page); + +if (!PageHighMem (page)) +make_lowmem_page_readonly (__va (PFN_PHYS (pfn))); +else +/* make sure there are no stray mappings of +this page */ +kmap_flush_unused (); + } +} + +/* This should never happen until we're OK to use struct page */ static void xen_release_pt (u32 pfn) { -make_lowmem_page_readwrite (__va (PFN_PHYS (pfn))); -} - -static void xen_alloc_pd_clone (u32 pfn,u32 clonepfn, -u32 start,u32 count) -{ -xen_alloc_pd (pfn); -} +struct page *page =pfn_to_page (pfn); + +if (PagePinned (page)) { +if (!PageHighMem (page)) +make_lowmem_page_readwrite (__va (PFN_PHYS (pfn))); + } +} + +#ifdef CONFIG_HIGHPTE +static void *xen_kmap_atomic_pte (struct page *page,enum km_type type) +{ +pgprot_t prot =PAGE_KERNEL ; + +if (PagePinned (page)) + prot =PAGE_KERNEL_RO ; + +if (0 &&PageHighMem (page)) +printk ("mapping highpte %lx type %d prot %s\n" , +page_to_pfn (page), type, + (unsigned long )pgprot_val (prot) & _PAGE_RW ?"WRITE" :"READ" ); + +return kmap_atomic_prot (page, type, prot); +} +#endif static __init void xen_pagetable_setup_start (pgd_t *base) {
@@ -553,7 +583,7 @@ static __init void xen_pagetable_setup_smemcpy (pmd, (void *)pgd_page_vaddr (xen_pgd[i]),PAGE_SIZE ); -xen_alloc_pd (PFN_DOWN (__pa (pmd))); +make_lowmem_page_readonly (pmd);set_pgd (&base[i],__pgd (1 +__pa (pmd))); }else
@@ -574,6 +604,10 @@ static __init void xen_pagetable_setup_sstatic __init void xen_pagetable_setup_done (pgd_t *base) { +/* This will work as long as patching hasn't happened yet +(which it hasn't) */ + paravirt_ops.alloc_pt = xen_alloc_pt; +if (!xen_feature (XENFEAT_auto_translated_physmap)) {/* * Create a mapping for the shared info page.
@@ -591,7 +625,19 @@ static __init void xen_pagetable_setup_d HYPERVISOR_shared_info = (struct shared_info *)__va (xen_start_info->shared_info); -xen_pgd_pin (base); +/* Actually pin the pagetable down, but we can't set PG_pinned +yet because the page structures don't exist yet. */ + { +struct mmuext_op op; +#ifdef CONFIG_X86_PAE + op.cmd =MMUEXT_PIN_L3_TABLE ; +#else + op.cmd =MMUEXT_PIN_L3_TABLE ; +#endif + op.arg1.mfn =pfn_to_mfn (PFN_DOWN (__pa (base))); +if (HYPERVISOR_mmuext_op (&op,1 ,NULL ,DOMID_SELF )) +BUG (); + }xen_vcpu_setup (smp_processor_id ()); }
@@ -608,6 +654,7 @@ static const struct paravirt_ops xen_par .memory_setup = xen_memory_setup, .arch_setup = xen_arch_setup, .init_IRQ = xen_init_IRQ, + .post_allocator_init = xen_mark_init_mm_pinned, .time_init = xen_time_init, .set_wallclock = xen_set_wallclock,
@@ -688,11 +735,15 @@ static const struct paravirt_ops xen_par .pagetable_setup_start = xen_pagetable_setup_start, .pagetable_setup_done = xen_pagetable_setup_done, - .alloc_pt = xen_alloc_pt, - .alloc_pd = xen_alloc_pd, - .alloc_pd_clone = xen_alloc_pd_clone, - .release_pd = xen_release_pd, + .alloc_pt = xen_alloc_pt_init, .release_pt = xen_release_pt, + .alloc_pd = paravirt_nop, + .alloc_pd_clone = paravirt_nop, + .release_pd = paravirt_nop, + +#ifdef CONFIG_HIGHPTE + .kmap_atomic_pte = xen_kmap_atomic_pte, +#endif .set_pte = xen_set_pte, .set_pte_at = xen_set_pte_at,
===================================================================
arch/i386/xen/mmu.c +183 -103
382 lines not on this page · raw message
===================================================================
arch/i386/xen/mmu.h +1 -1
@@ -15,7 +15,7 @@ void xen_exit_mmap(struct mm_struct *mm)void xen_exit_mmap (struct mm_struct *mm);void xen_pgd_pin (pgd_t *pgd); -void xen_pgd_unpin (pgd_t *pgd); +//void xen_pgd_unpin(pgd_t *pgd); #ifdef CONFIG_X86_PAE unsigned long long xen_pte_val (pte_t );
===================================================================
arch/i386/xen/xen-ops.h +2 -0
@@ -20,6 +20,8 @@ int xen_set_wallclock(unsigned long timeint xen_set_wallclock (unsigned long time);cycle_t xen_clocksource_read (void ); +void xen_mark_init_mm_pinned (void ); + DECLARE_PER_CPU(enum paravirt_lazy_mode, xen_lazy_mode);static inline unsigned xen_get_lazy_mode (void )
PATCH 26/44 xen: ignore RW mapping of RO pages in pagetable_init
In reply to a message not in the archiveWhen setting up the initial pagetable, which includes mappings of all low physical memory, ignore a mapping which tries to set the RW bit on an RO pte. An RO pte indicates a page which is part of the current pagetable, and so it cannot be allowed to become RW.
Once xen_pagetable_setup_done is called, set_pte reverts to its normal behaviour.
--- arch/i386/xen/enlighten.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-)
===================================================================
arch/i386/xen/enlighten.c +25 -2
@@ -501,7 +501,7 @@ static void xen_write_cr3(unsigned long/* Early in boot, while setting up the initial pagetable, assume everything is pinned. */ -static void xen_alloc_pt_init (struct mm_struct *mm,u32 pfn) +static __init void xen_alloc_pt_init (struct mm_struct *mm,u32 pfn) {BUG_ON (mem_map);/* should only be used early */ make_lowmem_page_readonly (__va (PFN_PHYS (pfn)));
@@ -553,9 +553,31 @@ static void *xen_kmap_atomic_pte(struct }#endif +static __init pte_t mask_rw_pte (pte_t *ptep,pte_t pte) +{ +/* If there's an existing pte, then don't allow _PAGE_RW to be set */ +if (pte_val_ma (*ptep) & _PAGE_PRESENT) + pte =__pte_ma (((pte_val_ma (*ptep) & _PAGE_RW) | ~_PAGE_RW) & +pte_val_ma (pte)); + +return pte; +} + +/* Init-time set_pte while constructing initial pagetables, which +doesn't allow RO pagetable pages to be remapped RW */ +static __init void xen_set_pte_init (pte_t *ptep,pte_t pte) +{ + pte =mask_rw_pte (ptep, pte); + +xen_set_pte (ptep, pte); +} +static __init void xen_pagetable_setup_start (pgd_t *base) {pgd_t *xen_pgd = (pgd_t *)xen_start_info->pt_base; + +/* special set_pte for pagetable initialization */ + paravirt_ops.set_pte = xen_set_pte_init; init_mm.pgd = base;/*
@@ -603,6 +625,7 @@ static __init void xen_pagetable_setup_d/* This will work as long as patching hasn't happened yet (which it hasn't) */ paravirt_ops.alloc_pt = xen_alloc_pt; + paravirt_ops.set_pte = xen_set_pte;if (!xen_feature (XENFEAT_auto_translated_physmap)) {/*
@@ -741,7 +764,7 @@ static const struct paravirt_ops xen_par .kmap_atomic_pte = xen_kmap_atomic_pte, #endif - .set_pte = xen_set_pte, + .set_pte = NULL, /* see xen_pagetable_setup_* */ .set_pte_at = xen_set_pte_at, .set_pmd = xen_set_pmd,
PATCH 27/44 xen: Account for stolen time
In reply to a message not in the archiveThis patch accounts for the stolen from our VCPUs. Stolen time is time where a vcpu is runnable and could be running, but all available physical CPUs are being used for something else.
This accounting gets run on each timer interrupt, just as a way to get it run relatively often, and when interesting things are going on. Stolen time is not really used by much in the kernel; it is reported in /proc/stats, and that's about it.
--- arch/i386/xen/time.c | 161 ++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 151 insertions(+), 10 deletions(-)
===================================================================
arch/i386/xen/time.c +151 -10
@@ -11,6 +11,7 @@#include <linux/interrupt.h> #include <linux/clocksource.h> #include <linux/clockchips.h> +#include <linux/kernel_stat.h> #include <asm/xen/hypervisor.h> #include <asm/xen/hypercall.h>
@@ -25,6 +26,7 @@/* Xen may fire a timer up to this many ns early */ #define TIMER_SLOP 100000 +#define NS_PER_TICK (1000000000LL / HZ)/* These are perodically updated in shared_info, and then copied here. */ struct shadow_time_info {
@@ -37,6 +39,139 @@ struct shadow_time_info { static DEFINE_PER_CPU(struct shadow_time_info, shadow_time); +/* runstate info updated by Xen */ +static DEFINE_PER_CPU(struct vcpu_runstate_info, runstate); + +/* snapshots of runstate info */ +static DEFINE_PER_CPU(struct vcpu_runstate_info, runstate_snapshot); + +/* unused ns of stolen and blocked time */ +static DEFINE_PER_CPU(u64, residual_stolen); +static DEFINE_PER_CPU(u64, residual_blocked); + +/* return an consistent snapshot of 64-bit time/counter value */ +static u64 get64 (const u64 *p) +{ +u64 ret; + +if (BITS_PER_LONG <64 ) { +u32 *p32 = (u32 *)p; +u32 h, l; + +/* +* Read high then low, and then make sure high is +* still the same; this will only loop if low wraps +* and carries into high. +* XXX some clean way to make this endian-proof? +*/ +do { + h = p32[1 ]; +barrier (); + l = p32[0 ]; +barrier (); + }while (p32[1 ] != h); + + ret = (((u64 )h) <<32 ) | l; + }else + ret = *p; + +return ret; +} + +/* +* Runstate accounting +*/ +static void get_runstate_snapshot (struct vcpu_runstate_info *res) +{ +u64 state_time; +struct vcpu_runstate_info *state; + +preempt_disable (); + + state = &__get_cpu_var (runstate); + +/* +* The runstate info is always updated by the hypervisor on +* the current CPU, so there's no need to use anything +* stronger than a compiler barrier when fetching it. +*/ +do { + state_time =get64 (&state->state_entry_time); +barrier (); + *res = *state; +barrier (); + }while (get64 (&state->state_entry_time) != state_time); + +preempt_enable (); +} + +static void setup_runstate_info (int cpu) +{ +struct vcpu_register_runstate_memory_area area; + + area.addr.v = &per_cpu (runstate, cpu); + +if (HYPERVISOR_vcpu_op (VCPUOP_register_runstate_memory_area, + cpu, &area)) +BUG (); +} + +static void do_stolen_accounting (void ) +{ +struct vcpu_runstate_info state; +struct vcpu_runstate_info *snap; +s64 blocked, runnable, offline, stolen; +cputime_t ticks; + +get_runstate_snapshot (&state); + +WARN_ON (state.state != RUNSTATE_running); + + snap = &__get_cpu_var (runstate_snapshot); + +/* work out how much time the VCPU has not been runn*ing* */ + blocked = state.time[RUNSTATE_blocked] - snap->time[RUNSTATE_blocked]; + runnable = state.time[RUNSTATE_runnable] - snap->time[RUNSTATE_runnable]; + offline = state.time[RUNSTATE_offline] - snap->time[RUNSTATE_offline]; + + *snap = state; + +/* Add the appropriate number of ticks of stolen time, +including any left-overs from last time. Passing NULL to +account_steal_time accounts the time as stolen. */ + stolen = runnable + offline +__get_cpu_var (residual_stolen); + +if (stolen <0 ) + stolen =0 ; + + ticks =0 ; +while (stolen >=NS_PER_TICK ) { + ticks++; + stolen -=NS_PER_TICK ; + } +__get_cpu_var (residual_stolen) = stolen; +account_steal_time (NULL , ticks); + +/* Add the appropriate number of ticks of blocked time, +including any left-overs from last time. Passing idle to +account_steal_time accounts the time as idle/wait. */ + blocked +=__get_cpu_var (residual_blocked); + +if (blocked <0 ) + blocked =0 ; + + ticks =0 ; +while (blocked >=NS_PER_TICK ) { + ticks++; + blocked -=NS_PER_TICK ; + } +__get_cpu_var (residual_blocked) = blocked; +account_steal_time (idle_task (smp_processor_id ()), ticks); +} + + + +/* Get the CPU speed from Xen */ unsigned long xen_cpu_khz (void ) {u64 cpu_khz =1000000ULL <<32 ;
@@ -56,12 +191,10 @@ unsigned long xen_cpu_khz(void)* Reads a consistent set of time-base values from Xen, into a shadow data * area. */ -static void get_time_values_from_xen (void ) +static unsigned get_time_values_from_xen (void ) {struct vcpu_time_info *src;struct shadow_time_info *dst; - -preempt_disable ();/* src is shared memory with the hypervisor, so we need to make sure we get a consistent snapshot, even in the face of
@@ -79,7 +212,7 @@ static void get_time_values_from_xen(voirmb ();/* test version after fetching data */ }while ((src->version &1 ) | (dst->version ^ src->version)); -preempt_enable (); +return dst->version; }/*
@@ -123,7 +256,7 @@ static u64 get_nsec_offset(struct shadowstatic u64 get_nsec_offset (struct shadow_time_info *shadow) {u64 now, delta; -rdtscll (now); + now =native_read_tsc (); delta = now - shadow->tsc_timestamp;return scale_delta (delta, shadow->tsc_to_nsec_mul, shadow->tsc_shift); }
@@ -132,10 +265,14 @@ cycle_t xen_clocksource_read(void) {struct shadow_time_info *shadow = &get_cpu_var (shadow_time);cycle_t ret; - -get_time_values_from_xen (); - - ret = shadow->system_timestamp +get_nsec_offset (shadow); +unsigned version; + +do { + version =get_time_values_from_xen (); +barrier (); + ret = shadow->system_timestamp +get_nsec_offset (shadow); +barrier (); + }while (version !=__get_cpu_var (xen_vcpu)->time.version);put_cpu_var (shadow_time);
@@ -352,6 +489,8 @@ static irqreturn_t xen_timer_interrupt(i ret =IRQ_HANDLED ; } +do_stolen_accounting (); +return ret; }
@@ -378,6 +517,8 @@ static void xen_setup_timer(int cpu) evt->irq = irq;clockevents_register_device (evt); +setup_runstate_info (cpu); +put_cpu_var (xen_clock_events); }
@@ -390,7 +531,7 @@ __init void xen_time_init(void)clocksource_register (&xen_clocksource);if (HYPERVISOR_vcpu_op (VCPUOP_stop_periodic_timer, cpu,NULL ) ==0 ) { -/* Successfully turned off 100hz tick, so we have the +/* Successfully turned off 100Hz tick, so we have the vcpuop-based timer interface */ printk (KERN_DEBUG "Xen: using vcpuop timer interface\n" ); xen_clockevent = &xen_vcpuop_clockevent;
PATCH 28/44 xen: Implement sched_clock
In reply to a message not in the archiveImplement xen_sched_clock, which returns the number of ns the current vcpu has been actually in an unstolen state (ie, running or blocked, vs runnable-but-not-running, or offline) since boot.
--- arch/i386/xen/enlighten.c | 2 +- arch/i386/xen/time.c | 27 ++++++++++++++++++++++++++- arch/i386/xen/xen-ops.h | 3 +-- 3 files changed, 28 insertions(+), 4 deletions(-)
===================================================================
arch/i386/xen/enlighten.c +1 -1
@@ -683,7 +683,7 @@ static const struct paravirt_ops xen_par .set_wallclock = xen_set_wallclock, .get_wallclock = xen_get_wallclock, .get_cpu_khz = xen_cpu_khz, - .sched_clock = xen_clocksource_read, + .sched_clock = xen_sched_clock, .cpuid = xen_cpuid,
===================================================================
arch/i386/xen/time.c +26 -1
@@ -28,6 +28,8 @@#define TIMER_SLOP 100000#define NS_PER_TICK (1000000000LL / HZ) +static cycle_t xen_clocksource_read (void ); +/* These are perodically updated in shared_info, and then copied here. */ struct shadow_time_info {u64 tsc_timestamp;/* TSC at last update of time vals. */
@@ -169,6 +171,29 @@ static void do_stolen_accounting(void)account_steal_time (idle_task (smp_processor_id ()), ticks); } +/* +* Xen sched_clock implementation. Returns the number of unstolen +* nanoseconds, which is nanoseconds the VCPU spent in RUNNING+BLOCKED +* states. +*/ +unsigned long long xen_sched_clock (void ) +{ +struct vcpu_runstate_info state; +cycle_t now =xen_clocksource_read (); +s64 offset; + +get_runstate_snapshot (&state); + +WARN_ON (state.state != RUNSTATE_running); + + offset = now - state.state_entry_time; +if (offset <0 ) + offset =0 ; + +return state.time[RUNSTATE_blocked] + + state.time[RUNSTATE_running] + + offset; +}/* Get the CPU speed from Xen */
@@ -261,7 +286,7 @@ static u64 get_nsec_offset(struct shadowreturn scale_delta (delta, shadow->tsc_to_nsec_mul, shadow->tsc_shift); } -cycle_t xen_clocksource_read (void ) +static cycle_t xen_clocksource_read (void ) {struct shadow_time_info *shadow = &get_cpu_var (shadow_time);cycle_t ret;
===================================================================
arch/i386/xen/xen-ops.h +1 -2
@@ -2,7 +2,6 @@#define XEN_OPS_H #include <linux/init.h> -#include <linux/clocksource.h> DECLARE_PER_CPU(struct vcpu_info *, xen_vcpu); DECLARE_PER_CPU(unsigned long, xen_cr3);
@@ -18,7 +17,7 @@ void __init xen_time_init(void);void __init xen_time_init (void );unsigned long xen_get_wallclock (void );int xen_set_wallclock (unsigned long time); -cycle_t xen_clocksource_read (void ); +unsigned long long xen_sched_clock (void );void xen_mark_init_mm_pinned (void );
PATCH 29/44 xen: SMP guest support
In reply to a message not in the archiveThis is a fairly straightforward Xen implementation of smp_ops.
Xen has its own IPI mechanisms, and has no dependency on any APIC-based IPI. The smp_ops hooks and the flush_tlb_others pv_op allow a Xen guest to avoid all APIC code in arch/i386 (the only apic operation is a single apic_read for the apic version number).
One subtle point which needs to be addressed is unpinning pagetables when another cpu may have a lazy tlb reference to the pagetable. Xen will not allow an in-use pagetable to be unpinned, so we must find any other cpus with a reference to the pagetable and get them to shoot down their references.
--- arch/i386/xen/Kconfig | 2 arch/i386/xen/Makefile | 2 arch/i386/xen/enlighten.c | 117 +++++++++--- arch/i386/xen/events.c | 80 ++++++++ arch/i386/xen/mmu.c | 75 ++++++-- arch/i386/xen/mmu.h | 13 + arch/i386/xen/setup.c | 5 arch/i386/xen/smp.c | 407 +++++++++++++++++++++++++++++++++++++++++++++ arch/i386/xen/time.c | 17 + arch/i386/xen/xen-ops.h | 25 ++ include/xen/events.h | 27 ++ 11 files changed, 711 insertions(+), 59 deletions(-)
===================================================================
arch/i386/xen/Kconfig +1 -1
@@ -4,7 +4,7 @@ config XEN bool "Enable support for Xen hypervisor" - depends on PARAVIRT && X86_CMPXCHG && X86_TSC && !(PREEMPT || SMP || NEED_MULTIPLE_NODES) + depends on PARAVIRT && X86_CMPXCHG && X86_TSC && !(PREEMPT || NEED_MULTIPLE_NODES) help This is the Linux Xen port. Enabling this will allow the kernel to boot in a paravirtualized environment under the
===================================================================
arch/i386/xen/Makefile +2 -0
@@ -1,2 +1,4 @@ obj-y := enlighten.o setup.o features.o obj-y := enlighten.o setup.o features.o multicalls.o mmu.o \ events.o time.o + +obj-$(CONFIG_SMP) += smp.o
===================================================================
arch/i386/xen/enlighten.c +90 -27
194 lines not on this page · raw message
===================================================================
arch/i386/xen/events.c +79 -1
110 lines not on this page · raw message
===================================================================
arch/i386/xen/mmu.c +55 -20
90 lines not on this page · raw message
===================================================================
arch/i386/xen/mmu.h +13 -0
@@ -2,6 +2,19 @@#include <linux/linkage.h> #include <asm/page.h> + +/* +* Page-directory addresses above 4GB do not fit into architectural %cr3. +* When accessing %cr3, or equivalent field in vcpu_guest_context, guests +* must use the following accessor macros to pack/unpack valid MFNs. +* +* Note that Xen is using the fact that the pagetable base is always +* page-aligned, and putting the 12 MSB of the address into the 12 LSB +* of cr3. +*/ +#define xen_pfn_to_cr3 (pfn) (((unsigned)(pfn) << 12) | ((unsigned)(pfn) >> 20)) +#define xen_cr3_to_pfn (cr3) (((unsigned)(cr3) >> 12) | ((unsigned)(cr3) << 20)) +void set_pte_mfn (unsigned long vaddr,unsigned long pfn,pgprot_t flags);
===================================================================
arch/i386/xen/setup.c +5 -0
@@ -94,4 +94,9 @@ void __init xen_arch_setup(void) COMMAND_LINE_SIZE : MAX_GUEST_CMDLINE); pm_idle = xen_idle; + +#ifdef CONFIG_SMP +/* fill cpus_possible with all available cpus */ +xen_fill_possible_map (); +#endif }
===================================================================
arch/i386/xen/smp.c new file +407 -0
407 lines not on this page · raw message
===================================================================
arch/i386/xen/time.c +11 -6
@@ -519,7 +519,7 @@ static irqreturn_t xen_timer_interrupt(ireturn ret; } -static void xen_setup_timer (int cpu) +void xen_setup_timer (int cpu) {const char *name;struct clock_event_device *evt;
@@ -535,16 +535,20 @@ static void xen_setup_timer(int cpu)IRQF_DISABLED |IRQF_PERCPU |IRQF_NOBALANCING , name, NULL); - evt = &get_cpu_var (xen_clock_events); + evt = &per_cpu (xen_clock_events, cpu);memcpy (evt, xen_clockevent,sizeof (*evt)); evt->cpumask =cpumask_of_cpu (cpu); evt->irq = irq; -clockevents_register_device (evt);setup_runstate_info (cpu); - -put_cpu_var (xen_clock_events); +} + +void xen_setup_cpu_clockevents (void ) +{ +BUG_ON (preemptible ()); + +clockevents_register_device (&__get_cpu_var (xen_clock_events)); }__init void xen_time_init (void )
@@ -570,4 +574,5 @@ __init void xen_time_init(void) tsc_disable =0 ;xen_setup_timer (cpu); -} +xen_setup_cpu_clockevents (); +}
===================================================================
arch/i386/xen/xen-ops.h +25 -0
@@ -2,6 +2,12 @@#define XEN_OPS_H #include <linux/init.h> + +/* These are code, but not functions. Defined in entry.S */ +extern const char xen_hypervisor_callback[]; +extern const char xen_failsafe_callback[]; + +void xen_copy_trap_info (struct trap_info *traps); DECLARE_PER_CPU(struct vcpu_info *, xen_vcpu); DECLARE_PER_CPU(unsigned long, xen_cr3);
@@ -13,6 +19,8 @@ void __init xen_arch_setup(void);void __init xen_arch_setup (void );void __init xen_init_IRQ (void ); +void xen_setup_timer (int cpu); +void xen_setup_cpu_clockevents (void );unsigned long xen_cpu_khz (void );void __init xen_time_init (void );unsigned long xen_get_wallclock (void );
@@ -28,5 +36,22 @@ static inline unsigned xen_get_lazy_modereturn x86_read_percpu (xen_lazy_mode); } +void __init xen_fill_possible_map (void ); + +void xen_vcpu_setup (int cpu); +void xen_smp_prepare_boot_cpu (void ); +void xen_smp_prepare_cpus (unsigned int max_cpus); +int xen_cpu_up (unsigned int cpu); +void xen_smp_cpus_done (unsigned int max_cpus); + +void xen_smp_send_stop (void ); +void xen_smp_send_reschedule (int cpu); +int xen_smp_call_function (void (*func) (void *info),void *info,int nonatomic, +int wait); +int xen_smp_call_function_single (int cpu,void (*func) (void *info),void *info, +int nonatomic,int wait); + +int xen_smp_call_function_mask (cpumask_t mask,void (*func)(void *), +void *info,int wait);#endif /* XEN_OPS_H */
===================================================================
include/xen/events.h +23 -4
@@ -1,15 +1,32 @@#ifndef _XEN_EVENTS_H#define _XEN_EVENTS_H -#include <linux/irq.h> +#include <linux/interrupt.h> + +#include <xen/interface/event_channel.h> +#include <asm/xen/hypercall.h> + +enum ipi_vector { +XEN_RESCHEDULE_VECTOR , +XEN_CALL_FUNCTION_VECTOR , + +XEN_NR_IPIS , +};int bind_evtchn_to_irqhandler (unsigned int evtchn, -irqreturn_t (*handler)(int ,void *), +irq_handler_t handler,unsigned long irqflags,const char *devname,void *dev_id);int bind_virq_to_irqhandler (unsigned int virq,unsigned int cpu, -irqreturn_t (*handler)(int ,void *), -unsigned long irqflags,const char *devname,void *dev_id); +irq_handler_t handler, +unsigned long irqflags,const char *devname, +void *dev_id); +int bind_ipi_to_irqhandler (enum ipi_vector ipi, +unsigned int cpu, +irq_handler_t handler, +unsigned long irqflags, +const char *devname, +void *dev_id);/* * Common unbind function for all event sources. Takes IRQ to unbind from.
@@ -17,6 +34,8 @@ int bind_virq_to_irqhandler(unsigned int* made with bind_evtchn_to_irqhandler()). */ void unbind_from_irqhandler (unsigned int irq,void *dev_id); + +void xen_send_IPI_one (unsigned int cpu,enum ipi_vector vector);static inline void notify_remote_via_evtchn (int port) {
PATCH 30/44 xen: Add support for preemption
In reply to a message not in the archiveAdd Xen support for preemption. This is mostly a cleanup of existing preempt_enable/disable calls, or just comments to explain the current usage.
--- arch/i386/xen/Kconfig | 2 arch/i386/xen/enlighten.c | 98 ++++++++++++++++++++++++++------------------ arch/i386/xen/mmu.c | 5 +- arch/i386/xen/multicalls.c | 11 ++-- arch/i386/xen/time.c | 22 +++++++-- 5 files changed, 86 insertions(+), 52 deletions(-)
===================================================================
arch/i386/xen/Kconfig +1 -1
@@ -4,7 +4,7 @@ config XEN bool "Enable support for Xen hypervisor" - depends on PARAVIRT && X86_CMPXCHG && X86_TSC && !(PREEMPT || NEED_MULTIPLE_NODES) + depends on PARAVIRT && X86_CMPXCHG && X86_TSC && !NEED_MULTIPLE_NODES help This is the Linux Xen port. Enabling this will allow the kernel to boot in a paravirtualized environment under the
===================================================================
arch/i386/xen/enlighten.c +58 -40
202 lines not on this page · raw message
===================================================================
arch/i386/xen/mmu.c +4 -1
@@ -38,6 +38,7 @@* * Jeremy Fitzhardinge <[email protected]>, XenSource Inc, 2007 */ +#include <linux/sched.h> #include <linux/highmem.h> #include <linux/bug.h>
@@ -530,5 +531,7 @@ void xen_exit_mmap(struct mm_struct *mm)drop_mm_ref (mm);put_cpu (); +spin_lock (&mm->page_table_lock);xen_pgd_unpin (mm->pgd); -} +spin_unlock (&mm->page_table_lock); +}
===================================================================
arch/i386/xen/multicalls.c +6 -5
@@ -20,6 +20,7 @@* Jeremy Fitzhardinge <[email protected]>, XenSource Inc, 2007 */ #include <linux/percpu.h> +#include <linux/hardirq.h> #include <asm/xen/hypercall.h>
@@ -39,9 +40,11 @@ DEFINE_PER_CPU(unsigned long, xen_mc_irqvoid xen_mc_flush (void ) { -struct mc_buffer *b = &get_cpu_var (mc_buffer); +struct mc_buffer *b = &__get_cpu_var (mc_buffer);int ret =0 ;unsigned long flags; + +BUG_ON (preemptible ());/* Disable interrupts in case someone comes in and queues something in the middle */
@@ -60,7 +63,6 @@ void xen_mc_flush(void) }else BUG_ON (b->argidx !=0 ); -put_cpu_var (mc_buffer);local_irq_restore (flags);BUG_ON (ret);
@@ -68,10 +70,11 @@ void xen_mc_flush(void)struct multicall_space __xen_mc_entry (size_t args) { -struct mc_buffer *b = &get_cpu_var (mc_buffer); +struct mc_buffer *b = &__get_cpu_var (mc_buffer);struct multicall_space ret;unsigned argspace = (args +sizeof (u64) -1 ) /sizeof (u64); +BUG_ON (preemptible ());BUG_ON (argspace >MC_ARGS ); if (b->mcidx == MC_BATCH ||
@@ -83,7 +86,5 @@ struct multicall_space __xen_mc_entry(si ret.args = &b->args[b->argidx]; b->argidx += argspace; -put_cpu_var (mc_buffer); -return ret; }
===================================================================
arch/i386/xen/time.c +17 -5
@@ -88,7 +88,7 @@ static void get_runstate_snapshot(structu64 state_time;struct vcpu_runstate_info *state; -preempt_disable (); +BUG_ON (preemptible ()); state = &__get_cpu_var (runstate);
@@ -103,8 +103,6 @@ static void get_runstate_snapshot(struct *res = *state;barrier (); }while (get64 (&state->state_entry_time) != state_time); - -preempt_enable (); }static void setup_runstate_info (int cpu)
@@ -179,8 +177,18 @@ unsigned long long xen_sched_clock(void)unsigned long long xen_sched_clock (void ) {struct vcpu_runstate_info state; -cycle_t now =xen_clocksource_read (); +cycle_t now; +u64 ret;s64 offset; + +/* +* Ideally sched_clock should be called on a per-cpu basis +* anyway, so preempt should already be disabled, but that's +* not current practice at the moment. +*/ +preempt_disable (); + + now =xen_clocksource_read ();get_runstate_snapshot (&state);
@@ -190,9 +198,13 @@ unsigned long long xen_sched_clock(void)if (offset <0 ) offset =0 ; -return state.time[RUNSTATE_blocked] + + ret = state.time[RUNSTATE_blocked] + state.time[RUNSTATE_running] + offset; + +preempt_enable (); + +return ret; }
PATCH 31/44 xen: lazy-mmu operations
In reply to a message not in the archiveThis patch uses the lazy-mmu hooks to batch mmu operations where possible. This is primarily useful for batching operations applied to active pagetables, which happens during mprotect, munmap, mremap and the like (mmap does not do bulk pagetable operations, so it isn't helped).
--- arch/i386/xen/enlighten.c | 56 +++++++++++++++++++++++++++----------------- arch/i386/xen/mmu.c | 56 ++++++++++++++++++++++++++++++++------------ arch/i386/xen/multicalls.c | 4 +-- 3 files changed, 78 insertions(+), 38 deletions(-)
===================================================================
arch/i386/xen/enlighten.c +35 -21
@@ -451,28 +451,38 @@ static void xen_apic_write(unsigned longstatic void xen_flush_tlb (void ) { -struct mmuext_op op; - - op.cmd =MMUEXT_TLB_FLUSH_LOCAL ; -if (HYPERVISOR_mmuext_op (&op,1 ,NULL ,DOMID_SELF )) -BUG (); +struct mmuext_op *op; +struct multicall_space mcs =xen_mc_entry (sizeof (*op)); + + op = mcs.args; + op->cmd =MMUEXT_TLB_FLUSH_LOCAL ; +MULTI_mmuext_op (mcs.mc, op,1 ,NULL ,DOMID_SELF ); + +xen_mc_issue (PARAVIRT_LAZY_MMU ); }static void xen_flush_tlb_single (unsigned long addr) { -struct mmuext_op op; - - op.cmd =MMUEXT_INVLPG_LOCAL ; - op.arg1.linear_addr = addr &PAGE_MASK ; -if (HYPERVISOR_mmuext_op (&op,1 ,NULL ,DOMID_SELF )) -BUG (); +struct mmuext_op *op; +struct multicall_space mcs =xen_mc_entry (sizeof (*op)); + + op = mcs.args; + op->cmd =MMUEXT_INVLPG_LOCAL ; + op->arg1.linear_addr = addr &PAGE_MASK ; +MULTI_mmuext_op (mcs.mc, op,1 ,NULL ,DOMID_SELF ); + +xen_mc_issue (PARAVIRT_LAZY_MMU ); }static void xen_flush_tlb_others (const cpumask_t *cpus,struct mm_struct *mm,unsigned long va) { -struct mmuext_op op; +struct { +struct mmuext_op op; +cpumask_t mask; + } *args;cpumask_t cpumask = *cpus; +struct multicall_space mcs;/* * A couple of (to be removed) sanity checks:
@@ -489,17 +499,21 @@ static void xen_flush_tlb_others(const cif (cpus_empty (cpumask))return ; + mcs =xen_mc_entry (sizeof (*args)); + args = mcs.args; + args->mask = cpumask; + args->op.arg2.vcpumask = &args->mask; +if (va ==TLB_FLUSH_ALL ) { - op.cmd =MMUEXT_TLB_FLUSH_MULTI ; - op.arg2.vcpumask = (void *)cpus; + args->op.cmd =MMUEXT_TLB_FLUSH_MULTI ; }else { - op.cmd =MMUEXT_INVLPG_MULTI ; - op.arg1.linear_addr = va; - op.arg2.vcpumask = (void *)cpus; - } - -if (HYPERVISOR_mmuext_op (&op,1 ,NULL ,DOMID_SELF )) -BUG (); + args->op.cmd =MMUEXT_INVLPG_MULTI ; + args->op.arg1.linear_addr = va; + } + +MULTI_mmuext_op (mcs.mc, &args->op,1 ,NULL ,DOMID_SELF ); + +xen_mc_issue (PARAVIRT_LAZY_MMU ); }static unsigned long xen_read_cr2 (void )
===================================================================
arch/i386/xen/mmu.c +41 -15
73 lines not on this page · raw message
===================================================================
arch/i386/xen/multicalls.c +2 -2
@@ -5,8 +5,8 @@#include "multicalls.h" -#define MC_BATCH 8 -#define MC_ARGS (MC_BATCH * 32 / sizeof(u64)) +#define MC_BATCH 32 +#define MC_ARGS (MC_BATCH * 16 / sizeof(u64))struct mc_buffer {struct multicall_entry entries[MC_BATCH ];
PATCH 32/44 xen: hack to prevent bad segment register reload
In reply to a message not in the archiveThe hypervisor saves and restores the segment registers as part of the state is saves while context switching. If, during a context switch, the next process doesn't use the TLS segments, it invalidates the GDT entry, causing the segment register reload to fault. This fault effectively doubles the cost of a context switch.
This patch is a band-aid workaround which clears the usermode %gs after it has been saved for the previous process, but before it gets reloaded for the next, and it avoids having the hypervisor attempt to erroneously reload it.
--- arch/i386/xen/enlighten.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
===================================================================
arch/i386/xen/enlighten.c +12 -0
@@ -291,6 +291,18 @@ static void xen_load_tls(struct thread_sload_TLS_descriptor (t, cpu,2 );xen_mc_issue (PARAVIRT_LAZY_CPU ); + +/* +* XXX sleazy hack: If we're being called in a lazy-cpu zone, +* it means we're in a context switch, and %gs has just been +* saved. This means we can zero it out to prevent faults on +* exit from the hypervisor if the next process has no %gs. +* Either way, it has been saved, and the new value will get +* loaded properly. This will go away as soon as Xen has been +* modified to not save/restore %gs for normal hypercalls. +*/ +if (xen_get_lazy_mode () ==PARAVIRT_LAZY_CPU ) +loadsegment (gs,0 ); } static void xen_write_ldt_entry(struct desc_struct *dt, int entrynum,
PATCH 33/44 xen: use the hvc console infrastructure for Xen console
In reply to a message not in the archiveImplement a Xen back-end for hvc console.
* * *
Add early printk support via hvc console, enable using "earlyprintk=xen" on the kernel command line.
From: Gerd Hoffmann <[email protected]>
--- arch/i386/xen/events.c | 3 arch/x86_64/kernel/early_printk.c | 5 + drivers/char/Kconfig | 8 + drivers/char/Makefile | 1 drivers/char/hvc_xen.c | 159 +++++++++++++++++++++++++++++++++++++ include/xen/events.h | 1 include/xen/hvc-console.h | 6 + 7 files changed, 182 insertions(+), 1 deletion(-)
===================================================================
arch/i386/xen/events.c +2 -1
@@ -244,7 +244,7 @@ static int find_unbound_irq(void)return irq; } -static int bind_evtchn_to_irq (unsigned int evtchn) +int bind_evtchn_to_irq (unsigned int evtchn) {int irq;
@@ -269,6 +269,7 @@ static int bind_evtchn_to_irq(unsigned ireturn irq; } +EXPORT_SYMBOL_GPL (bind_evtchn_to_irq);static int bind_ipi_to_irq (unsigned int ipi,unsigned int cpu) {
===================================================================
arch/x86_64/kernel/early_printk.c +5 -0
@@ -6,6 +6,7 @@#include <asm/io.h> #include <asm/processor.h> #include <asm/fcntl.h> +#include <xen/hvc-console.h> /* Simple VGA output */
@@ -242,6 +243,10 @@ static int __init setup_early_printk(chasimnow_init (buf +6 ); early_console = &simnow_console; keep_early =1 ; +#ifdef CONFIG_HVC_XEN + }else if (!strncmp (buf,"xen" ,3 )) { + early_console = &xenboot_console; +#endif }if (keep_early)
===================================================================
drivers/char/Kconfig +8 -0
@@ -653,6 +653,14 @@ config HVC_BEAT help Toshiba's Cell Reference Set Beat Console device driver +config HVC_XEN + bool "Xen Hypervisor Console support" + depends on XEN + select HVC_DRIVER + default y + help + Xen virtual console device driver + config HVCS tristate "IBM Hypervisor Virtual Console Server support" depends on PPC_PSERIES
===================================================================
drivers/char/Makefile +1 -0
@@ -47,6 +47,7 @@ obj-$(CONFIG_HVC_RTAS) += hvc_rtas.o obj-$(CONFIG_HVC_RTAS) += hvc_rtas.o obj-$(CONFIG_HVC_BEAT) += hvc_beat.o obj-$(CONFIG_HVC_DRIVER) += hvc_console.o +obj-$(CONFIG_HVC_XEN) += hvc_xen.o obj-$(CONFIG_RAW_DRIVER) += raw.o obj-$(CONFIG_SGI_SNSC) += snsc.o snsc_event.o obj-$(CONFIG_MSPEC) += mspec.o
===================================================================
drivers/char/hvc_xen.c new file +159 -0
159 lines not on this page · raw message
===================================================================
include/xen/events.h +1 -0
@@ -13,6 +13,7 @@ enum ipi_vector { XEN_NR_IPIS, }; +int bind_evtchn_to_irq (unsigned int evtchn); int bind_evtchn_to_irqhandler(unsigned int evtchn, irq_handler_t handler, unsigned long irqflags, const char *devname,
===================================================================
include/xen/hvc-console.h new file +6 -0
@@ -0,0 +1,6 @@ +#ifndef XEN_HVC_CONSOLE_H +#define XEN_HVC_CONSOLE_H + +extern struct console xenboot_console; + +#endif /* XEN_HVC_CONSOLE_H */
PATCH 34/44 xen: Add grant table support
In reply to a message not in the archiveAdd Xen 'grant table' driver which allows granting of access to selected local memory pages by other virtual machines and, symmetrically, the mapping of remote memory pages which other virtual machines have granted access to.
This driver is a prerequisite for many of the Xen virtual device drivers, which grant the 'device driver domain' restricted and temporary access to only those memory pages that are currently involved in I/O operations.
--- drivers/Makefile | 2 drivers/xen/Makefile | 1 drivers/xen/grant-table.c | 582 +++++++++++++++++++++++++++++++++++ include/xen/grant_table.h | 107 ++++++ include/xen/interface/grant_table.h | 96 +++++ 5 files changed, 777 insertions(+), 11 deletions(-)
===================================================================
drivers/Makefile +2 -0
@@ -14,6 +14,8 @@ obj-$(CONFIG_ACPI) += acpi/ # was used and do nothing if so obj-$(CONFIG_PNP) += pnp/ obj-$(CONFIG_ARM_AMBA) += amba/ + +obj-$(CONFIG_XEN) += xen/ # char/ comes before serial/ etc so that the VT console is the boot-time # default.
===================================================================
drivers/xen/Makefile new file +1 -0
@@ -0,0 +1,1 @@ +obj-y += grant-table.o
===================================================================
drivers/xen/grant-table.c new file +582 -0
582 lines not on this page · raw message
===================================================================
include/xen/grant_table.h new file +107 -0
107 lines not on this page · raw message
===================================================================
include/xen/interface/grant_table.h +85 -11
157 lines not on this page · raw message
PATCH 35/44 xen: add the Xenbus sysfs and virtual device hotplug driver
In reply to a message not in the archiveThis communicates with the machine control software via a registry residing in a controlling virtual machine. This allows dynamic creation, destruction and modification of virtual device configurations (network devices, block devices and CPUS, to name some examples).
[ Greg, would you mind giving this a review? Thanks -J ]
--- drivers/xen/Makefile | 1 drivers/xen/xenbus/Makefile | 7 drivers/xen/xenbus/xenbus_client.c | 569 +++++++++++++++++++++ drivers/xen/xenbus/xenbus_comms.c | 233 ++++++++ drivers/xen/xenbus/xenbus_comms.h | 46 + drivers/xen/xenbus/xenbus_probe.c | 935 ++++++++++++++++++++++++++++++++++++ drivers/xen/xenbus/xenbus_probe.h | 74 ++ drivers/xen/xenbus/xenbus_xs.c | 861 +++++++++++++++++++++++++++++++++ include/asm-i386/xen/hypervisor.h | 1 include/xen/xenbus.h | 234 +++++++++ 10 files changed, 2961 insertions(+)
===================================================================
drivers/xen/Makefile +1 -0
@@ -1,1 +1,2 @@ obj-y += grant-table.o obj-y += grant-table.o +obj-y += xenbus/
===================================================================
drivers/xen/xenbus/Makefile new file +7 -0
@@ -0,0 +1,7 @@ +obj-y += xenbus.o + +xenbus-objs = +xenbus-objs += xenbus_client.o +xenbus-objs += xenbus_comms.o +xenbus-objs += xenbus_xs.o +xenbus-objs += xenbus_probe.o
===================================================================
drivers/xen/xenbus/xenbus_client.c new file +569 -0
569 lines not on this page · raw message
===================================================================
drivers/xen/xenbus/xenbus_comms.c new file +233 -0
233 lines not on this page · raw message
===================================================================
drivers/xen/xenbus/xenbus_comms.h new file +46 -0
46 lines not on this page · raw message
===================================================================
drivers/xen/xenbus/xenbus_probe.c new file +935 -0
935 lines not on this page · raw message
===================================================================
drivers/xen/xenbus/xenbus_probe.h new file +74 -0
74 lines not on this page · raw message
===================================================================
drivers/xen/xenbus/xenbus_xs.c new file +861 -0
861 lines not on this page · raw message
===================================================================
include/asm-i386/xen/hypervisor.h +1 -0
@@ -42,6 +42,7 @@#include <asm/ptrace.h> #include <asm/page.h> +#include <asm/desc.h> #if defined(__i386__)# ifdef CONFIG_X86_PAE # include <asm-generic/pgtable-nopud.h>
===================================================================
include/xen/xenbus.h new file +234 -0
234 lines not on this page · raw message
PATCH 36/44 xen: add virtual block device driver.
In reply to a message not in the archiveThe block device frontend driver allows the kernel to access block devices exported exported by a virtual machine containing a physical block device driver.
--- drivers/block/Kconfig | 9 drivers/block/Makefile | 1 drivers/block/xen-blkfront.c | 988 ++++++++++++++++++++++++++++++++++++++++++ include/linux/major.h | 2 4 files changed, 1000 insertions(+)
===================================================================
drivers/block/Kconfig +9 -0
@@ -425,4 +425,13 @@ config ATA_OVER_ETH source "drivers/s390/block/Kconfig" +config XEN_BLKDEV_FRONTEND + tristate "Xen virtual block device support" + depends on XEN + default y + help + This driver implements the front-end of the Xen virtual + block device driver. It communicates with a back-end driver + in another domain which drives the actual block device. + endif # BLK_DEV
===================================================================
drivers/block/Makefile +1 -0
@@ -28,3 +28,4 @@ obj-$(CONFIG_BLK_DEV_SX8) += sx8.o obj-$(CONFIG_BLK_DEV_SX8) += sx8.o obj-$(CONFIG_BLK_DEV_UB) += ub.o +obj-$(CONFIG_XEN_BLKDEV_FRONTEND) += xen-blkfront.o
===================================================================
drivers/block/xen-blkfront.c new file +988 -0
988 lines not on this page · raw message
===================================================================
include/linux/major.h +2 -0
@@ -158,6 +158,8 @@#define VXSPEC_MAJOR 200/* VERITAS volume config driver */ #define VXDMP_MAJOR 201/* VERITAS volume multipath driver */ +#define XENVBD_MAJOR 202/* Xen virtual block device */ +#define MSR_MAJOR 202#define CPUID_MAJOR 203
PATCH 37/44 xen: add virtual network device driver
In reply to a message not in the archiveThe network device frontend driver allows the kernel to access network devices exported exported by a virtual machine containing a physical network device driver.
--- drivers/net/Kconfig | 12 drivers/net/Makefile | 2 drivers/net/xen-netfront.c | 1863 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 1877 insertions(+)
===================================================================
drivers/net/Kconfig +12 -0
@@ -2477,6 +2477,18 @@ source "drivers/atm/Kconfig" source "drivers/atm/Kconfig" source "drivers/s390/net/Kconfig" + +config XEN_NETDEV_FRONTEND + tristate "Xen network device frontend driver" + depends on XEN + default y + help + The network device frontend driver allows the kernel to + access network devices exported exported by a virtual + machine containing a physical network device driver. The + frontend driver is intended for unprivileged guest domains; + if you are compiling a kernel for a Xen guest, you almost + certainly want to enable this. config ISERIES_VETH tristate "iSeries Virtual Ethernet driver support"
===================================================================
drivers/net/Makefile +2 -0
@@ -124,6 +124,8 @@ obj-$(CONFIG_PPPOE) += pppox.o pppoe.o obj-$(CONFIG_SLIP) += slip.o obj-$(CONFIG_SLHC) += slhc.o + +obj-$(CONFIG_XEN_NETDEV_FRONTEND) += xen-netfront.o obj-$(CONFIG_DUMMY) += dummy.o obj-$(CONFIG_IFB) += ifb.o
===================================================================
drivers/net/xen-netfront.c new file +1863 -0
1,863 lines not on this page · raw message
PATCH 38/44 xen: machine operations
In reply to a message not in the archiveMake the appropriate hypercalls to halt and reboot the virtual machine.
--- arch/i386/xen/enlighten.c | 43 +++++++++++++++++++++++++++++++++++++++++++ arch/i386/xen/smp.c | 4 +--- 2 files changed, 44 insertions(+), 3 deletions(-)
===================================================================
arch/i386/xen/enlighten.c +43 -0
@@ -30,6 +30,7 @@#include <xen/interface/xen.h> #include <xen/interface/physdev.h> #include <xen/interface/vcpu.h> +#include <xen/interface/sched.h> #include <xen/features.h> #include <xen/page.h>
@@ -43,6 +44,7 @@#include <asm/desc.h> #include <asm/pgtable.h> #include <asm/tlbflush.h> +#include <asm/reboot.h> #include "xen-ops.h" #include "mmu.h"
@@ -900,6 +902,45 @@ static const struct smp_ops xen_smp_ops };#endif /* CONFIG_SMP */ +static void xen_reboot (int reason) +{ +#ifdef CONFIG_SMP +smp_send_stop (); +#endif + +if (HYPERVISOR_sched_op (SCHEDOP_shutdown, reason)) +BUG (); +} + +static void xen_restart (char *msg) +{ +xen_reboot (SHUTDOWN_reboot); +} + +static void xen_emergency_restart (void ) +{ +xen_reboot (SHUTDOWN_reboot); +} + +static void xen_machine_halt (void ) +{ +xen_reboot (SHUTDOWN_poweroff); +} + +static void xen_crash_shutdown (struct pt_regs *regs) +{ +xen_reboot (SHUTDOWN_crash); +} + +static const struct machine_ops __initdata xen_machine_ops = { + .restart = xen_restart, + .halt = xen_machine_halt, + .power_off = xen_machine_halt, + .shutdown = xen_machine_halt, + .crash_shutdown = xen_crash_shutdown, + .emergency_restart = xen_emergency_restart, +}; +/* First C function to be called on Xen boot */ asmlinkage void __init xen_start_kernel(void) {
@@ -912,6 +953,8 @@ asmlinkage void __init xen_start_kernel(/* Install Xen paravirt ops */ paravirt_ops = xen_paravirt_ops; + machine_ops = xen_machine_ops; +#ifdef CONFIG_SMP smp_ops = xen_smp_ops;#endif
===================================================================
arch/i386/xen/smp.c +1 -3
@@ -311,9 +311,7 @@ static void stop_self(void *v)void xen_smp_send_stop (void ) { -cpumask_t mask = cpu_online_map; -cpu_clear (smp_processor_id (), mask); -xen_smp_call_function_mask (mask, stop_self,NULL ,0 ); +smp_call_function (stop_self,NULL ,0 ,0 ); }void xen_smp_send_reschedule (int cpu)
PATCH 39/44 xen: handle external requests for shutdown, reboot and sysrq
In reply to a message not in the archiveThe guest domain can be asked to shutdown or reboot itself, or have a sysrq key injected, via xenbus. This patch adds a watcher for those events, and does the appropriate action.
--- arch/i386/xen/Makefile | 2 arch/i386/xen/manage.c | 143 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 144 insertions(+), 1 deletion(-)
===================================================================
arch/i386/xen/Makefile +1 -1
@@ -1,4 +1,4 @@ obj-y := enlighten.o setup.o features.o obj-y := enlighten.o setup.o features.o multicalls.o mmu.o \ - events.o time.o + events.o time.o manage.o obj-$(CONFIG_SMP) += smp.o
===================================================================
arch/i386/xen/manage.c new file +143 -0
143 lines not on this page · raw message
PATCH 40/44 xen: Place vcpu_info structure into per-cpu memory
In reply to a message not in the archiveAn experimental patch for Xen allows guests to place their vcpu_info structs anywhere. We try to use this to place the vcpu_info into the PDA, which allows direct access.
If this works, then switch to using direct access operations for irq_enable, disable, save_fl and restore_fl.
--- arch/i386/xen/enlighten.c | 156 ++++++++++++++++++++++++++++++++++++++++-- arch/i386/xen/setup.c | 8 -- arch/i386/xen/smp.c | 5 - arch/i386/xen/xen-ops.h | 2 include/xen/interface/vcpu.h | 13 +++ 5 files changed, 166 insertions(+), 18 deletions(-)
===================================================================
arch/i386/xen/enlighten.c +150 -6
@@ -61,9 +61,63 @@ struct start_info *xen_start_info;struct start_info *xen_start_info;EXPORT_SYMBOL_GPL (xen_start_info); -void xen_vcpu_setup (int cpu) -{ +static /* __initdata */ struct shared_info dummy_shared_info; + +/* +* Point at some empty memory to start with. We map the real shared_info +* page as soon as fixmap is up and running. +*/ +struct shared_info *HYPERVISOR_shared_info = (void *)&dummy_shared_info; + +/* +* Flag to determine whether vcpu info placement is available on all +* VCPUs. We assume it is to start with, and then set it to zero on +* the first failure. This is because it can succeed on some VCPUs +* and not others, since it can involve hypervisor memory allocation, +* or because the guest failed to guarantee all the appropriate +* constraints on all VCPUs (ie buffer can't cross a page boundary). +* +* Note that any particular CPU may be using a placed vcpu structure, +* but we can only optimise if the all are. +* +* 0: not available, 1: available +*/ +static int have_vcpu_info_placement =1 ; + +static void __init xen_vcpu_setup (int cpu) +{ +struct vcpu_register_vcpu_info info; +int err; +struct vcpu_info *vcpup; +per_cpu (xen_vcpu, cpu) = &HYPERVISOR_shared_info->vcpu_info[cpu]; + +if (!have_vcpu_info_placement) +return ;/* already tested, not available */ + + vcpup = &per_cpu (xen_vcpu_info, cpu); + + info.mfn =virt_to_mfn (vcpup); + info.offset =offset_in_page (vcpup); + +printk (KERN_DEBUG "trying to map vcpu_info %d at %p, mfn %x, offset %d\n" , + cpu, vcpup, info.mfn, info.offset); + +/* Check to see if the hypervisor will put the vcpu_info +structure where we want it, which allows direct access via +a percpu-variable. */ + err =HYPERVISOR_vcpu_op (VCPUOP_register_vcpu_info, cpu, &info); + +if (err) { +printk (KERN_DEBUG "register_vcpu_info failed: err=%d\n" , err); + have_vcpu_info_placement =0 ; + }else { +/* This cpu is using the registered vcpu info, even if +later ones fail to. */ +per_cpu (xen_vcpu, cpu) = vcpup; +printk (KERN_DEBUG "cpu %d using vcpu_info at %p\n" , + cpu, vcpup); + } }static void __init xen_banner (void )
@@ -123,6 +177,20 @@ static unsigned long xen_save_fl(void)return (-flags) &X86_EFLAGS_IF ; } +static unsigned long xen_save_fl_direct (void ) +{ +unsigned long flags; + +/* flag has opposite sense of mask */ + flags = !x86_read_percpu (xen_vcpu_info.evtchn_upcall_mask); + +/* convert to IF type flag +-0 -> 0x00000000 +-1 -> 0xffffffff +*/ +return (-flags) &X86_EFLAGS_IF ; +} +static void xen_restore_fl (unsigned long flags) {struct vcpu_info *vcpu;
@@ -149,6 +217,25 @@ static void xen_restore_fl(unsigned long } } +static void xen_restore_fl_direct (unsigned long flags) +{ +/* convert from IF type flag */ + flags = !(flags &X86_EFLAGS_IF ); + +/* This is an atomic update, so no need to worry about +preemption. */ +x86_write_percpu (xen_vcpu_info.evtchn_upcall_mask, flags); + +/* If we get preempted here, then any pending event will be +handled anyway. */ + +if (flags ==0 ) { +barrier ();/* unmask then check (avoid races) */ +if (unlikely (x86_read_percpu (xen_vcpu_info.evtchn_upcall_pending))) +force_evtchn_callback (); + } +} +static void xen_irq_disable (void ) {/* There's a one instruction preempt window here. We need to
@@ -157,6 +244,12 @@ static void xen_irq_disable(void)preempt_disable ();x86_read_percpu (xen_vcpu)->evtchn_upcall_mask =1 ;preempt_enable_no_resched (); +} + +static void xen_irq_disable_direct (void ) +{ +/* Atomic update, so preemption not a concern. */ +x86_write_percpu (xen_vcpu_info.evtchn_upcall_mask,1 ); }static void xen_irq_enable (void )
@@ -176,6 +269,19 @@ static void xen_irq_enable(void)barrier ();/* unmask then check (avoid races) */ if (unlikely (vcpu->evtchn_upcall_pending)) +force_evtchn_callback (); +} + +static void xen_irq_enable_direct (void ) +{ +/* Atomic update, so preemption not a concern. */ +x86_write_percpu (xen_vcpu_info.evtchn_upcall_mask,0 ); + +/* Doesn't matter if we get preempted here, because any +pending event will get dealt with anyway. */ + +barrier ();/* unmask then check (avoid races) */ +if (unlikely (x86_read_percpu (xen_vcpu_info.evtchn_upcall_pending)))force_evtchn_callback (); }
@@ -551,9 +657,19 @@ static void xen_flush_tlb_others(const cxen_mc_issue (PARAVIRT_LAZY_MMU ); } +static void xen_write_cr2 (unsigned long cr2) +{ +x86_read_percpu (xen_vcpu)->arch.cr2 = cr2; +} +static unsigned long xen_read_cr2 (void ) {return x86_read_percpu (xen_vcpu)->arch.cr2; +} + +static unsigned long xen_read_cr2_direct (void ) +{ +return x86_read_percpu (xen_vcpu_info.arch.cr2); }static void xen_write_cr4 (unsigned long cr4)
@@ -753,8 +869,27 @@ static __init void xen_pagetable_setup_dif (HYPERVISOR_mmuext_op (&op,1 ,NULL ,DOMID_SELF ))BUG (); } - -xen_vcpu_setup (smp_processor_id ()); +} + +/* This is called once we have the cpu_possible_map */ +void __init xen_setup_vcpu_info_placement (void ) +{ +int cpu; + +for_each_possible_cpu (cpu) +xen_vcpu_setup (cpu); + +/* xen_vcpu_setup managed to place the vcpu_info within the +percpu area for all cpus, so make use of it */ +if (have_vcpu_info_placement) { +printk (KERN_INFO "Xen: using vcpu_info placement\n" ); + + paravirt_ops.save_fl = xen_save_fl_direct; + paravirt_ops.restore_fl = xen_restore_fl_direct; + paravirt_ops.irq_disable = xen_irq_disable_direct; + paravirt_ops.irq_enable = xen_irq_enable_direct; + paravirt_ops.read_cr2 = xen_read_cr2_direct; + } }static const struct paravirt_ops xen_paravirt_ops__initdata = {
@@ -788,7 +923,7 @@ static const struct paravirt_ops xen_par .write_cr0 = native_write_cr0, .read_cr2 = xen_read_cr2, - .write_cr2 = native_write_cr2, + .write_cr2 = xen_write_cr2, .read_cr3 = xen_read_cr3, .write_cr3 = xen_write_cr3,
@@ -974,7 +1109,16 @@ asmlinkage void __init xen_start_kernel(/* keep using Xen gdt for now; no urgent need to change it */ x86_write_percpu (xen_cr3,__pa (pgd)); -xen_vcpu_setup (0 ); + +#ifdef CONFIG_SMP +/* Don't do the full vcpu_info placement stuff until we have a +possible map. */ +per_cpu (xen_vcpu,0 ) = &HYPERVISOR_shared_info->vcpu_info[0 ]; +#else +/* May as well do it now, since there's no good time to call +it later on UP. */ +xen_setup_vcpu_info_placement (); +#endif paravirt_ops.kernel_rpl =1 ;if (xen_feature (XENFEAT_supervisor_mode_kernel))
===================================================================
arch/i386/xen/setup.c +0 -8
@@ -23,14 +23,6 @@/* These are code, but not functions. Defined in entry.S */ extern const char xen_hypervisor_callback[];extern const char xen_failsafe_callback[]; - -static __initdata struct shared_info init_shared; - -/* -* Point at some empty memory to start with. We map the real shared_info -* page as soon as fixmap is up and running. -*/ -struct shared_info *HYPERVISOR_shared_info = &init_shared;unsigned long *phys_to_machine_mapping;EXPORT_SYMBOL (phys_to_machine_mapping);
===================================================================
arch/i386/xen/smp.c +2 -3
@@ -142,8 +142,6 @@ void __init xen_smp_prepare_boot_cpu(voiBUG_ON (smp_processor_id () !=0 );native_smp_prepare_boot_cpu (); -xen_vcpu_setup (0 ); -/* We've switched to the "real" per-cpu gdt, so make sure the old memory can be recycled */ make_lowmem_page_readwrite (&per_cpu__gdt_page);
@@ -152,6 +150,8 @@ void __init xen_smp_prepare_boot_cpu(voicpus_clear (cpu_sibling_map[cpu]);cpus_clear (cpu_core_map[cpu]); } + +xen_setup_vcpu_info_placement (); }void __init xen_smp_prepare_cpus (unsigned int max_cpus)
@@ -262,7 +262,6 @@ int __cpuinit xen_cpu_up(unsigned int cpinit_gdt (cpu);per_cpu (current_task, cpu) = idle; -xen_vcpu_setup (cpu);irq_ctx_init (cpu);xen_setup_timer (cpu);
===================================================================
arch/i386/xen/xen-ops.h +1 -1
@@ -38,7 +38,7 @@ static inline unsigned xen_get_lazy_modevoid __init xen_fill_possible_map (void ); -void xen_vcpu_setup (int cpu); +void __init xen_setup_vcpu_info_placement (void );void xen_smp_prepare_boot_cpu (void );void xen_smp_prepare_cpus (unsigned int max_cpus);int xen_cpu_up (unsigned int cpu);
===================================================================
include/xen/interface/vcpu.h +13 -0
@@ -151,4 +151,17 @@ struct vcpu_set_singleshot_timer {#define _VCPU_SSHOTTMR_future (0)#define VCPU_SSHOTTMR_future (1U << _VCPU_SSHOTTMR_future) +/* +* Register a memory location in the guest address space for the +* vcpu_info structure. This allows the guest to place the vcpu_info +* structure in a convenient place, such as in a per-cpu data area. +* The pointer need not be page aligned, but the structure must not +* cross a page boundary. +*/ +#define VCPUOP_register_vcpu_info 10/* arg == struct vcpu_info */ +struct vcpu_register_vcpu_info { +uint32_t mfn;/* mfn of page to place vcpu_info */ +uint32_t offset;/* offset within page */ +}; +#endif /* __XEN_PUBLIC_VCPU_H__ */
PATCH 41/44 xen: Attempt to patch inline versions of common operations
In reply to a message not in the archiveThis patchs adds the mechanism to allow us to patch inline versions of common operations.
The implementations of the direct-access versions save_fl, restore_fl, irq_enable and irq_disable are now in assembler, and the same code is used for both out of line and inline uses.
--- arch/i386/kernel/asm-offsets.c | 8 ++ arch/i386/xen/Makefile | 2 arch/i386/xen/enlighten.c | 107 ++++++++++++++++++------------------- arch/i386/xen/xen-asm.S | 114 ++++++++++++++++++++++++++++++++++++++++ arch/i386/xen/xen-ops.h | 13 ++++ 5 files changed, 190 insertions(+), 54 deletions(-)
===================================================================
arch/i386/kernel/asm-offsets.c +8 -0
@@ -16,6 +16,8 @@#include <asm/processor.h> #include <asm/thread_info.h> #include <asm/elf.h> + +#include <xen/interface/xen.h> #define DEFINE (sym, val) \ asm volatile("\n->" #sym " %0 " #val : : "i" (val))
@@ -115,4 +117,10 @@ void foo(void)OFFSET (PARAVIRT_iret, paravirt_ops, iret);OFFSET (PARAVIRT_read_cr0, paravirt_ops, read_cr0);#endif + +#ifdef CONFIG_XEN +BLANK (); +OFFSET (XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask); +OFFSET (XEN_vcpu_info_pending, vcpu_info, evtchn_upcall_pending); +#endif }
===================================================================
arch/i386/xen/Makefile +1 -1
@@ -1,4 +1,4 @@ obj-y := enlighten.o setup.o features.o obj-y := enlighten.o setup.o features.o multicalls.o mmu.o \ - events.o time.o manage.o + events.o time.o manage.o xen-asm.o obj-$(CONFIG_SMP) += smp.o
===================================================================
arch/i386/xen/enlighten.c +54 -53
155 lines not on this page · raw message
===================================================================
arch/i386/xen/xen-asm.S new file +114 -0
114 lines not on this page · raw message
===================================================================
arch/i386/xen/xen-ops.h +13 -0
@@ -54,4 +54,17 @@ int xen_smp_call_function_mask(cpumask_tint xen_smp_call_function_mask (cpumask_t mask,void (*func)(void *),void *info,int wait); + +/* Declare an asm function, along with symbols needed to make it +inlineable */ +#define DECL_ASM (ret, name, ...) \ + ret name(__VA_ARGS__); \ + extern char name##_end[]; \ + extern char name##_reloc[] \ + +DECL_ASM (void, xen_irq_enable_direct, void); +DECL_ASM (void, xen_irq_disable_direct, void); +DECL_ASM(unsigned long, xen_save_fl_direct, void); +DECL_ASM(void, xen_restore_fl_direct, unsigned long); +#endif /* XEN_OPS_H */
PATCH 42/44 xen: suppress abs symbol warnings for unused reloc pointers
In reply to a message not in the archivearch/i386/xen/xen-asm.S defines some small pieces of code which are used to implement a few paravirt_ops. They're designed so they can be used either in-place, or be inline patched into their callsites if there's enough space.
Some of those operations need to make calls out (specifically, if you re-enable events [interrupts], and there's a pending event at that time). These calls need the call instruction to be relocated if the code is patched inline. In this case xen_foo_reloc is a section-relative symbol which points to xen_foo's required relocation.
Other operations have no need of a relocation, and so their corresponding xen_bar_reloc is absolute 0. These are the cases which are triggering the warning.
This patch adds those symbols to the list of safe abs symbols.
--- arch/i386/boot/compressed/relocs.c | 2 ++ 1 file changed, 2 insertions(+)
===================================================================
arch/i386/boot/compressed/relocs.c +2 -0
@@ -31,6 +31,8 @@ static const char* safe_abs_relocs[] = {"__kernel_rt_sigreturn" ,"__kernel_sigreturn" ,"SYSENTER_RETURN" , +"xen_irq_disable_direct_reloc" , + "xen_save_fl_direct_reloc", };static int is_safe_abs_reloc (const char * sym_name)
PATCH 43/44 xen: use iret directly when possible
In reply to a message not in the archiveMost of the time we can simply use the iret instruction to exit the kernel, rather than having to use the iret hypercall - the only exception is if we're returning into vm86 mode, or from delivering an NMI (which we don't support yet).
When running native, iret has the behaviour of testing for a pending interrupt atomically with re-enabling interrupts. Unfortunately there's no way to do this with Xen, so there's a window in which we could get a recursive exception after enabling events but before actually returning to userspace.
This causes a problem: if the nested interrupt causes one of the task's TIF_WORK_MASK flags to be set, they will not be checked again before returning to userspace. This means that pending work may be left pending indefinitely, until the process enters and leaves the kernel again. The net effect is that a pending signal or reschedule event could be delayed for an unbounded amount of time.
To deal with this, the xen event upcall handler checks to see if the EIP is within the critical section of the iret code, after events are (potentially) enabled up to the iret itself. If its within this range, it calls the iret critical section fixup, which adjusts the stack to deal with any unrestored registers, and then shifts the stack frame up to replace the previous invocation.
--- arch/i386/kernel/asm-offsets.c | 1 arch/i386/kernel/entry.S | 16 +++ arch/i386/xen/enlighten.c | 1 arch/i386/xen/xen-asm.S | 185 +++++++++++++++++++++++++++++++++++++++- arch/i386/xen/xen-ops.h | 1 5 files changed, 199 insertions(+), 5 deletions(-)
===================================================================
arch/i386/kernel/asm-offsets.c +1 -0
@@ -61,6 +61,7 @@ void foo(void)OFFSET (TI_addr_limit, thread_info, addr_limit);OFFSET (TI_restart_block, thread_info, restart_block);OFFSET (TI_sysenter_return, thread_info, sysenter_return); +OFFSET (TI_cpu, thread_info, cpu);BLANK ();OFFSET (GDS_size, Xgt_desc_struct, size);
===================================================================
arch/i386/kernel/entry.S +15 -1
@@ -1030,7 +1030,21 @@ ENTRY(xen_hypervisor_callback) CFI_ADJUST_CFA_OFFSET 4 SAVE_ALL TRACE_IRQS_OFF - mov %esp, %eax + + /* Check to see if we got the event in the critical + region in xen_iret_direct, after we've reenabled + events and checked for pending events. This simulates + iret instruction's behaviour where it delivers a + pending interrupt when enabling interrupts. */ + movl PT_EIP(%esp),%eax + cmpl $xen_iret_start_crit,%eax + jb 1f + cmpl $xen_iret_end_crit,%eax + jae 1f + + call xen_iret_crit_fixup + +1: mov %esp, %eax call xen_evtchn_do_upcall jmp ret_from_intr CFI_ENDPROC
===================================================================
arch/i386/xen/enlighten.c +1 -0
@@ -838,6 +838,7 @@ void __init xen_setup_vcpu_info_placemen paravirt_ops.irq_disable = xen_irq_disable_direct; paravirt_ops.irq_enable = xen_irq_enable_direct; paravirt_ops.read_cr2 = xen_read_cr2_direct; + paravirt_ops.iret = xen_iret_direct; } }
===================================================================
arch/i386/xen/xen-asm.S +181 -4
214 lines not on this page · raw message
===================================================================
arch/i386/xen/xen-ops.h +1 -0
@@ -67,4 +67,5 @@ DECL_ASM(unsigned long, xen_save_fl_dire DECL_ASM(unsigned long, xen_save_fl_direct, void); DECL_ASM(void, xen_restore_fl_direct, unsigned long); +void xen_iret_direct (void );#endif /* XEN_OPS_H */
PATCH 44/44 xen: disable all non-virtual drivers
In reply to a message not in the archiveA domU Xen environment has no non-virtual drivers, so make sure they're all disabled at once.
--- arch/i386/xen/setup.c | 2 ++ 1 file changed, 2 insertions(+)
===================================================================
arch/i386/xen/setup.c +2 -0
@@ -91,4 +91,6 @@ void __init xen_arch_setup(void)/* fill cpus_possible with all available cpus */ xen_fill_possible_map ();#endif + +paravirt_disable_iospace (); }
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [Xen-devel] [patch 03/44] usermodehelper: split setup from execution
Quoted 9 lines · Jeremy Fitzhardinge
plain text document attachment (usermodehelper-split-init.patch) Rather than having hundreds of variations of
call_usermodehelperfor various pieces of usermode state which could be set up, split the info allocation and initialization from the actual process execution.This means the general pattern becomes:
info =call_usermodehelper_setup(path, argv, envp); /* basic state */
call_usermodehelper_<SET EXTRA STATE>(info, stuff...); /* extra state */
call_usermodehelper_exec(info, wait); /* run process and free info */
The patch seems fine, but the names are awkward. They've always been awkward (it's *userspace* helper, not *usermode* helper), but this just shines a bright light on them.
So how about:
call_usermodehelper_setup -> create_userspace_helper call_usermodehelper_<SET_EXTRA_STATE> -> userspace_helper_... call_usermodehelper_exec -> run_userspace_helper
I can do that as a separate patch if you prefer (but it'd be nice to have it in the same merge window so the interface only churns once).
Rusty.
Re: [Xen-devel] [patch 03/44] usermodehelper: split setup from execution
Quoted 4 lines · Rusty Russell
The patch seems fine, but the names are awkward. They've always been awkward (it's *userspace* helper, not *usermode* helper), but this just shines a bright light on them.
Quoted 8 lines
So how about:
call_usermodehelper_setup -> create_userspace_helper call_usermodehelper_<SET_EXTRA_STATE> -> userspace_helper_... call_usermodehelper_exec -> run_userspace_helperI can do that as a separate patch if you prefer (but it'd be nice to have it in the same merge window so the interface only churns once).
I don't have any particular objection, but I think it would be nicer if they had a common prefix so that they're obviously related, and you can easily infer the lifetime of the info structure.
J
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [Xen-devel] [patch 17/44] Add nosegneg capability to the vsyscall page notes
Quoted 7 lines · Jeremy Fitzhardinge
plain text document attachment (xen-vsyscall-note.patch) Add the "nosegneg" fake capabilty to the vsyscall page notes. This is used by the runtime linker to select a glibc version which then disables negative-offset accesses to the thread-local segment via %gs. These accesses require emulation in Xen (because segments are truncated to protect the hypervisor address space) and avoiding them provides a measurable performance boost.
Hmm, this is still unconditional? Not that it causes any measurable slowdown when enabled, but ISTR discussing making this dynamic...
Rusty.
Re: [Xen-devel] [patch 17/44] Add nosegneg capability to the vsyscall page notes
Quoted 11 lines · Rusty Russell
Quoted 8 lines · Jeremy Fitzhardinge
plain text document attachment (xen-vsyscall-note.patch) Add the "nosegneg" fake capabilty to the vsyscall page notes. This is used by the runtime linker to select a glibc version which then disables negative-offset accesses to the thread-local segment via %gs. These accesses require emulation in Xen (because segments are truncated to protect the hypervisor address space) and avoiding them provides a measurable performance boost.
Quoted 2 lines
Hmm, this is still unconditional? Not that it causes any measurable slowdown when enabled, but ISTR discussing making this dynamic...
Played with it for a bit, but it's fairly fiddly. Didn't seem like it was worth the complexity.
J
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [patch 37/44] xen: add virtual network device driver
Quoted 6 lines · Jeremy Fitzhardinge
The network device frontend driver allows the kernel to access network devices exported exported by a virtual machine containing a physical network device driver.
Quoted 11 lines
Signed-off-by Jeremy Fitzhardinge <[email protected]>Signed-off-by Chris Wright <[email protected]>Cc Ian Pratt <[email protected]>Cc Christian Limpach <[email protected]>Cc Jeff Garzik <[email protected]>Cc Stephen Hemminger <[email protected]>Cc Christoph Hellwig <[email protected]>Cc Rusty Russell <[email protected]>Cc Herbert Xu <[email protected]>Cc Keir Fraser <[email protected]>
Seems fairly reasonable. ACK, presuming Xen dependencies are also merged.
Jeff
Re: [patch 37/44] xen: add virtual network device driver
In reply to a message not in the archiveReview
Quoted 6 lines
(quoted diff) +5
-0+struct netfront_info { + struct list_head list; + struct net_device *netdev; + + struct net_device_stats stats;
There is now a net_device_stats element inside net_device on 2.6.21 or later.
Review
Quoted 6 lines
(quoted diff) +6
-0+ + struct xen_netif_tx_front_ring tx; + struct xen_netif_rx_front_ring rx; + + spinlock_t tx_lock; + spinlock_t rx_lock;
It might be a performance advantage to reorder/align these structure elements to put transmit hot elements together, and put tx and rx on different cache lines?
Quoted 40 lines
(quoted diff) +40
-0+ unsigned int evtchn; + + /* Receive-ring batched refills. */ +#define RX_MIN_TARGET 8 +#define RX_DFL_MIN_TARGET 64 +#define RX_MAX_TARGET min_t(int, NET_RX_RING_SIZE, 256) + unsigned rx_min_target, rx_max_target, rx_target; + struct sk_buff_head rx_batch; + + struct timer_list rx_refill_timer; + + /* + * {tx,rx}_skbs store outstanding skbuffs. Free tx_skb entries + * are linked from tx_skb_freelist through skb_entry.link. + * + * NB. Freelist index entries are always going to be less than + * PAGE_OFFSET, whereas pointers to skbs will always be equal or + * greater than PAGE_OFFSET: we use this property to distinguish + * them. + */ + union skb_entry { + struct sk_buff *skb; + unsigned link; + } tx_skbs[NET_TX_RING_SIZE]; + grant_ref_t gref_tx_head; + grant_ref_t grant_tx_ref[NET_TX_RING_SIZE]; + unsigned tx_skb_freelist; + + struct sk_buff *rx_skbs[NET_RX_RING_SIZE]; + grant_ref_t gref_rx_head; + grant_ref_t grant_rx_ref[NET_RX_RING_SIZE]; + + struct xenbus_device *xbdev; + int tx_ring_ref; + int rx_ring_ref; + + unsigned long rx_pfn_array[NET_RX_RING_SIZE]; + struct multicall_entry rx_mcl[NET_RX_RING_SIZE+1]; + struct mmu_update rx_mmu[NET_RX_RING_SIZE]; +};
Re: [patch 37/44] xen: add virtual network device driver
Quoted 10 lines · Stephen Hemminger
Review
Quoted 6 lines
(quoted diff) +5
-0+struct netfront_info { + struct list_head list; + struct net_device *netdev; + + struct net_device_stats stats;There is now a
net_device_statselement insidenet_deviceon 2.6.21 or later.
Ah, OK. Should I just do a s/stats/netdev->stats/? Is there a generic get_stats routine as well?
Quoted 12 lines
Review
Quoted 7 lines
(quoted diff) +6
-0+ + struct xen_netif_tx_front_ring tx; + struct xen_netif_rx_front_ring rx; + + spinlock_t tx_lock; + spinlock_t rx_lock;It might be a performance advantage to reorder/align these structure elements to put transmit hot elements together, and put tx and rx on different cache lines?
Oh, right. I'd been meaning to look at that layout more closely.
Thanks,
J
Re: [patch 37/44] xen: add virtual network device driver
Quoted 12 lines · Jeremy Fitzhardinge
Quoted 10 lines · Stephen Hemminger
Review
Quoted 6 lines
(quoted diff) +5
-0+struct netfront_info { + struct list_head list; + struct net_device *netdev; + + struct net_device_stats stats;There is now a
net_device_statselement insidenet_deviceon 2.6.21 or later.
Quoted 2 lines
Ah, OK. Should I just do a s/stats/netdev->stats/? Is there a generic
get_statsroutine as well?
The default function points to the internal stats...
Cheers,
Rusty.
Re: [patch 37/44] xen: add virtual network device driver
Quoted 2 lines · Rusty Russell
The default function points to the internal stats...
Right you are.
J
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [Xen-devel] [patch 30/44] xen: Add support for preemption
hi
I am using xen,and I am curious about whether Xen support the preempt scheduler for the VMs or not
could the VM be prempted by xen to scheduler another VM?
Thanks in advance
Quoted 375 lines · Jeremy Fitzhardinge
Add Xen support for preemption. This is mostly a cleanup of existing preempt_enable/disable calls, or just comments to explain the current usage.
Signed-off-by Jeremy Fitzhardinge <[email protected]>Signed-off-by Chris Wright <[email protected]>--- arch/i386/xen/Kconfig | 2 arch/i386/xen/enlighten.c | 98 ++++++++++++++++++++++++++------------------ arch/i386/xen/mmu.c | 5 +- arch/i386/xen/multicalls.c | 11 ++-- arch/i386/xen/time.c | 22 +++++++-- 5 files changed, 86 insertions(+), 52 deletions(-)===================================================================
arch/i386/xen/Kconfig +1
-1@@ -4,7 +4,7 @@ config XEN bool "Enable support for Xen hypervisor" - depends on PARAVIRT && X86_CMPXCHG && X86_TSC && !(PREEMPT || NEED_MULTIPLE_NODES) + depends on PARAVIRT && X86_CMPXCHG && X86_TSC && !NEED_MULTIPLE_NODES help This is the Linux Xen port. Enabling this will allow the kernel to boot in a paravirtualized environment under the===================================================================
arch/i386/xen/enlighten.c +58
-40@@ -15,6 +15,7 @@#include <linux/init.h> #include <linux/smp.h> #include <linux/preempt.h> +#include <linux/hardirq.h> #include <linux/percpu.h> #include <linux/delay.h> #include <linux/start_kernel.h> @@ -108,11 +109,10 @@ static unsigned long xen_save_fl(void)struct vcpu_info *vcpu;unsigned long flags; -preempt_disable (); vcpu =x86_read_percpu (xen_vcpu); +/* flag has opposite sense of mask */ flags = !vcpu->evtchn_upcall_mask; -preempt_enable ();/* convert to IF type flag -0 -> 0x00000000 @@ -125,51 +125,56 @@ static void xen_restore_fl(unsigned long {struct vcpu_info *vcpu; -preempt_disable (); -/* convert from IF type flag */ flags = !(flags &X86_EFLAGS_IF ); + +/* There's a one instruction preempt window here. We need to +make sure we're don't switch CPUs between getting the vcpu +pointer and updating the mask. */ +preempt_disable (); vcpu =x86_read_percpu (xen_vcpu); vcpu->evtchn_upcall_mask = flags; +preempt_enable_no_resched (); + +/* Doesn't matter if we get preempted here, because any +pending event will get dealt with anyway. */ if (flags ==0 ) { -/* Unmask then check (avoid races). We're only protecting -against updates by this CPU, so there's no need for -anything stronger. */ -barrier (); - +preempt_check_resched (); +barrier ();/* unmask then check (avoid races) */ if (unlikely (vcpu->evtchn_upcall_pending))force_evtchn_callback (); -preempt_enable (); - }else -preempt_enable_no_resched (); + } }static void xen_irq_disable (void ) { +/* There's a one instruction preempt window here. We need to +make sure we're don't switch CPUs between getting the vcpu +pointer and updating the mask. */ +preempt_disable (); +x86_read_percpu (xen_vcpu)->evtchn_upcall_mask =1 ; +preempt_enable_no_resched (); +} + +static void xen_irq_enable (void ) +{struct vcpu_info *vcpu; -preempt_disable (); - vcpu =x86_read_percpu (xen_vcpu); - vcpu->evtchn_upcall_mask =1 ; -preempt_enable_no_resched (); -} - -static void xen_irq_enable (void ) -{ -struct vcpu_info *vcpu; - + +/* There's a one instruction preempt window here. We need to +make sure we're don't switch CPUs between getting the vcpu +pointer and updating the mask. */ preempt_disable (); vcpu =x86_read_percpu (xen_vcpu); vcpu->evtchn_upcall_mask =0 ; - -/* Unmask then check (avoid races). We're only protecting -against updates by this CPU, so there's no need for -anything stronger. */ -barrier (); - +preempt_enable_no_resched (); + +/* Doesn't matter if we get preempted here, because any +pending event will get dealt with anyway. */ + +barrier ();/* unmask then check (avoid races) */ if (unlikely (vcpu->evtchn_upcall_pending))force_evtchn_callback (); -preempt_enable (); }static void xen_safe_halt (void )@@ -189,6 +194,8 @@ static void xen_halt(void)static void xen_set_lazy_mode (enum paravirt_lazy_mode mode) { +BUG_ON (preemptible ()); +switch (mode) {case PARAVIRT_LAZY_NONE :BUG_ON (x86_read_percpu (xen_lazy_mode) ==PARAVIRT_LAZY_NONE );@@ -293,9 +300,13 @@ static void xen_write_ldt_entry(struct dxmaddr_t mach_lp =virt_to_machine (lp);u64 entry = (u64 )high <<32 | low; +preempt_disable (); +xen_mc_flush ();if (HYPERVISOR_update_descriptor (mach_lp.maddr, entry))BUG (); + +preempt_enable (); } static int cvt_gate_to_trap(int vector, u32 low, u32 high,@@ -328,11 +339,13 @@ static void xen_write_idt_entry(struct dstatic void xen_write_idt_entry (struct desc_struct *dt,int entrynum,u32 low,u32 high) { - -int cpu =smp_processor_id ();unsigned long p = (unsigned long )&dt[entrynum]; -unsigned long start =per_cpu (idt_desc, cpu).address; -unsigned long end = start +per_cpu (idt_desc, cpu).size +1 ; +unsigned long start, end; + +preempt_disable (); + + start =__get_cpu_var (idt_desc).address; + end = start +__get_cpu_var (idt_desc).size +1 ;xen_mc_flush ();@@ -347,6 +360,8 @@ static void xen_write_idt_entry(struct dif (HYPERVISOR_set_trap_table (info))BUG (); } + +preempt_enable (); } static void xen_convert_trap_info(const struct Xgt_desc_struct *desc,@@ -368,11 +383,9 @@ static void xen_convert_trap_info(constvoid xen_copy_trap_info (struct trap_info *traps) { -const struct Xgt_desc_struct *desc = &get_cpu_var (idt_desc); +const struct Xgt_desc_struct *desc = &__get_cpu_var (idt_desc);xen_convert_trap_info (desc, traps); - -put_cpu_var (idt_desc); }/* Load a new IDT into Xen. In principle this can be per-CPU, so we @@ -382,11 +395,10 @@ static void xen_load_idt(const struct Xg {static DEFINE_SPINLOCK (lock);static struct trap_info traps[257 ]; -int cpu =smp_processor_id (); - -per_cpu (idt_desc, cpu) = *desc;spin_lock (&lock); + +__get_cpu_var (idt_desc) = *desc;xen_convert_trap_info (desc, traps);@@ -402,6 +414,8 @@ static void xen_write_gdt_entry(struct dstatic void xen_write_gdt_entry (struct desc_struct *dt,int entry,u32 low,u32 high) { +preempt_disable (); +switch ((high >>8 ) &0xff ) {case DESCTYPE_LDT :case DESCTYPE_TSS :@@ -418,10 +432,12 @@ static void xen_write_gdt_entry(struct d } } + +preempt_enable (); }static void xen_load_esp0 (struct tss_struct *tss, -struct thread_struct *thread) +struct thread_struct *thread) {struct multicall_space mcs =xen_mc_entry (0 );MULTI_stack_switch (mcs.mc, __KERNEL_DS, thread->esp0);@@ -525,6 +541,8 @@ static unsigned long xen_read_cr3(void)static void xen_write_cr3 (unsigned long cr3) { +BUG_ON (preemptible ()); +if (cr3 ==x86_read_percpu (xen_cr3)) {/* just a simple tlb flush */ xen_flush_tlb ();===================================================================
arch/i386/xen/mmu.c +4
-1@@ -38,6 +38,7 @@* * Jeremy Fitzhardinge <[email protected]>, XenSource Inc, 2007 */ +#include <linux/sched.h> #include <linux/highmem.h> #include <linux/bug.h> @@ -530,5 +531,7 @@ void xen_exit_mmap(struct mm_struct *mm)drop_mm_ref (mm);put_cpu (); +spin_lock (&mm->page_table_lock);xen_pgd_unpin (mm->pgd); -} +spin_unlock (&mm->page_table_lock); +}===================================================================
arch/i386/xen/multicalls.c +6
-5@@ -20,6 +20,7 @@* Jeremy Fitzhardinge <[email protected]>, XenSource Inc, 2007 */ #include <linux/percpu.h> +#include <linux/hardirq.h> #include <asm/xen/hypercall.h> @@ -39,9 +40,11 @@ DEFINE_PER_CPU(unsigned long, xen_mc_irqvoid xen_mc_flush (void ) { -struct mc_buffer *b = &get_cpu_var (mc_buffer); +struct mc_buffer *b = &__get_cpu_var (mc_buffer);int ret =0 ;unsigned long flags; + +BUG_ON (preemptible ());/* Disable interrupts in case someone comes in and queues something in the middle */ @@ -60,7 +63,6 @@ void xen_mc_flush(void) }else BUG_ON (b->argidx !=0 ); -put_cpu_var (mc_buffer);local_irq_restore (flags);BUG_ON (ret);@@ -68,10 +70,11 @@ void xen_mc_flush(void)struct multicall_space __xen_mc_entry (size_t args) { -struct mc_buffer *b = &get_cpu_var (mc_buffer); +struct mc_buffer *b = &__get_cpu_var (mc_buffer);struct multicall_space ret;unsigned argspace = (args +sizeof (u64) -1 ) /sizeof (u64); +BUG_ON (preemptible ());BUG_ON (argspace >MC_ARGS ); if (b->mcidx == MC_BATCH ||@@ -83,7 +86,5 @@ struct multicall_space __xen_mc_entry(si ret.args = &b->args[b->argidx]; b->argidx += argspace; -put_cpu_var (mc_buffer); -return ret; }===================================================================
arch/i386/xen/time.c +17
-5@@ -88,7 +88,7 @@ static void get_runstate_snapshot(structu64 state_time;struct vcpu_runstate_info *state; -preempt_disable (); +BUG_ON (preemptible ()); state = &__get_cpu_var (runstate);@@ -103,8 +103,6 @@ static void get_runstate_snapshot(struct *res = *state;barrier (); }while (get64 (&state->state_entry_time) != state_time); - -preempt_enable (); }static void setup_runstate_info (int cpu)@@ -179,8 +177,18 @@ unsigned long long xen_sched_clock(void)unsigned long long xen_sched_clock (void ) {struct vcpu_runstate_info state; -cycle_t now =xen_clocksource_read (); +cycle_t now; +u64 ret;s64 offset; + +/* +* Ideally sched_clock should be called on a per-cpu basis +* anyway, so preempt should already be disabled, but that's +* not current practice at the moment. +*/ +preempt_disable (); + + now =xen_clocksource_read ();get_runstate_snapshot (&state);@@ -190,9 +198,13 @@ unsigned long long xen_sched_clock(void)if (offset <0 ) offset =0 ; -return state.time[RUNSTATE_blocked] + + ret = state.time[RUNSTATE_blocked] + state.time[RUNSTATE_running] + offset; + +preempt_enable (); + +return ret; }
Re: [Xen-devel] [patch 30/44] xen: Add support for preemption
Quoted 5 lines · tgh
hi
I am using xen,and I am curious about whether Xen support the preempt scheduler for the VMs or not
could the VM be prempted by xen to scheduler another VM?
Yes, that's the normal mode of operation. The hypervisor will timeslice multiple vcpus onto a single vcpu.
This patch doesn't relate to that; it's whether a Xen Linux guest's kernel can be preempted to reschedule processes while running under Xen. The normal xen-unstable or vendor Xen kernels don't support this, but the mainline kernel with paravirt_ops/xen support does.
J
Re: [Xen-devel] [patch 30/44] xen: Add support for preemption
Thank for your reply
and I still have several questions
Quoted 3 lines
Yes, that's the normal mode of operation. The hypervisor will timeslice multiple vcpus onto a single vcpu.
that is ,the VM could be preempted by xen,and could xen hypervisor also be preempted to reschedule other vm or xen kernel thread?and are there the counterpart abstractions in xen for kernel thread in linux?
Quoted 3 lines
This patch doesn't relate to that; it's whether a Xen Linux guest's kernel can be preempted to reschedule processes while running under Xen.
that is ,the patch makes the guest's kernel, rather than xen, be able to be preempted ,is it right?
Thanks in advance
Quoted 12 lines
The normal xen-unstable or vendor Xen kernels don't support this, but the mainline kernel with paravirt_ops/xen support does.
J
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Re: [Xen-devel] [patch 30/44] xen: Add support for preemption
Quoted 11 lines · tgh
Thank for your reply
and I still have several questionsQuoted 4 lines
Yes, that's the normal mode of operation. The hypervisor will timeslice multiple vcpus onto a single vcpu.
that is ,the VM could be preempted by xen,and could xen hypervisor also be preempted to reschedule other vm or xen kernel thread?and are there the counterpart abstractions in xen for kernel thread in linux?
Yes, a vcpu in Xen is the same as a task in the kernel. In the same way the kernel multiplexes multiple tasks onto your cpu(s), Xen multiplexes multiple vcpus onto your cpu(s). This isn't directly visible to the guest kernel, in the same way that user processes can't generally observe timeslicing.
Quoted 7 lines
Quoted 4 lines
This patch doesn't relate to that; it's whether a Xen Linux guest's kernel can be preempted to reschedule processes while running under Xen.
that is ,the patch makes the guest's kernel, rather than xen, be able to be preempted ,is it right?
Yes. Previous to that change, kernel preemption was disabled when compiling Xen support in.
J
Re: [Xen-devel] [patch 30/44] xen: Add support for preemption
Thank you for your reply
and what about the kernel thread in the xen hypervisor,are there some instance of kernel threads running in the hypervisor?
I am not sure ,but somewhere I read that there is no kernel thread in the xen hypervisor ,is it true or what about it?
Thanks in advance
Quoted 46 lines · Jeremy Fitzhardinge
Quoted 4 lines · tgh
Thank for your reply
and I still have several questionsQuoted 10 lines
Quoted 5 lines
Yes, that's the normal mode of operation. The hypervisor will timeslice multiple vcpus onto a single vcpu.
that is ,the VM could be preempted by xen,and could xen hypervisor also be preempted to reschedule other vm or xen kernel thread?and are there the counterpart abstractions in xen for kernel thread in linux?
Yes, a vcpu in Xen is the same as a task in the kernel. In the same way the kernel multiplexes multiple tasks onto your cpu(s), Xen multiplexes multiple vcpus onto your cpu(s). This isn't directly visible to the guest kernel, in the same way that user processes can't generally observe timeslicing.
Quoted 9 lines
Quoted 5 lines
This patch doesn't relate to that; it's whether a Xen Linux guest's kernel can be preempted to reschedule processes while running under Xen.
that is ,the patch makes the guest's kernel, rather than xen, be able to be preempted ,is it right?
Yes. Previous to that change, kernel preemption was disabled when compiling Xen support in.
J
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Re: [Xen-devel] [patch 30/44] xen: Add support for preemption
Quoted 6 lines · tgh
Thank you for your reply
and what about the kernel thread in the xen hypervisor,are there some instance of kernel threads running in the hypervisor?
I am not sure ,but somewhere I read that there is no kernel thread in the xen hypervisor ,is it true or what about it?
No, there are no linux kernel threads in the hypervisor. The only thread-like thing Xen has is a virtual CPU, and they're always guest domain vcpus.
J