diff options
Diffstat (limited to 'zarb-ml/mageia-dev/attachments/20120109/d93f433f')
4 files changed, 328 insertions, 0 deletions
diff --git a/zarb-ml/mageia-dev/attachments/20120109/d93f433f/attachment-0001.obj b/zarb-ml/mageia-dev/attachments/20120109/d93f433f/attachment-0001.obj new file mode 100644 index 000000000..2bd391f8b --- /dev/null +++ b/zarb-ml/mageia-dev/attachments/20120109/d93f433f/attachment-0001.obj @@ -0,0 +1,93 @@ +c::is_xen() use cpuid in order to detect we're under XEN + +diff -up ./c/stuff.xs.pl.tv2 ./c/stuff.xs.pl +--- ./c/stuff.xs.pl.tv2 2012-01-09 10:49:22.807894338 +0100 ++++ ./c/stuff.xs.pl 2012-01-09 11:03:04.124482279 +0100 +@@ -105,6 +105,40 @@ int length_of_space_padded(char *str, in + return len; + } + ++int pv_context; ++static void cpuid(uint32_t idx, ++ uint32_t *eax, ++ uint32_t *ebx, ++ uint32_t *ecx, ++ uint32_t *edx) ++{ ++ asm volatile ( ++ "test %1,%1 ; jz 1f ; ud2a ; .ascii \"xen\" ; 1: cpuid" ++ : "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx) ++ : "0" (idx), "1" (pv_context) ); ++} ++ ++static int check_for_xen(void) ++{ ++ uint32_t eax, ebx, ecx, edx; ++ char signature[13]; ++ ++ cpuid(0x40000000, &eax, &ebx, &ecx, &edx); ++ *(uint32_t *)(signature + 0) = ebx; ++ *(uint32_t *)(signature + 4) = ecx; ++ *(uint32_t *)(signature + 8) = edx; ++ signature[12] = ' . "'\0'" . '; ++ ++ if ( strcmp("XenVMMXenVMM", signature) || (eax < 0x40000002) ) ++ return 0; ++ ++ cpuid(0x40000001, &eax, &ebx, &ecx, &edx); ++ printf("Running in %s context on Xen v%d.%d.\n", ++ pv_context ? "PV" : "HVM", (uint16_t)(eax >> 16), (uint16_t)eax); ++ return 1; ++} ++ ++ + MODULE = c::stuff PACKAGE = c::stuff + + '; +@@ -116,6 +150,46 @@ pcmcia_probe() + + print ' + int ++is_xen() ++ CODE: ++ pid_t pid; ++ int status; ++ uint32_t dummy; ++ ++ /* Check for execution in HVM context. */ ++ if ( check_for_xen() ) ++ return 0; ++ ++ /* Now we check for execution in PV context. */ ++ pv_context = 1; ++ ++ /* ++ * Fork a child to test the paravirtualised CPUID instruction. ++ * If executed outside Xen PV context, the extended opcode will fault. ++ */ ++ pid = fork(); ++ switch ( pid ) ++ { ++ case 0: ++ /* Child: test paravirtualised CPUID opcode and then exit cleanly. */ ++ cpuid(0x40000000, &dummy, &dummy, &dummy, &dummy); ++ exit(0); ++ case -1: ++ fprintf(stderr, "Fork failed.\n"); ++ return 0; ++ } ++ ++ /* ++ * Parent waits for child to terminate and checks for clean exit. ++ * Only if the exit is clean is it safe for us to try the extended CPUID. ++ */ ++ waitpid(pid, &status, 0); ++ if ( WIFEXITED(status) && check_for_xen() ) ++ return 0; ++ ++ return 0; ++ ++int + del_partition(hd, part_number) + int hd + int part_number
\ No newline at end of file diff --git a/zarb-ml/mageia-dev/attachments/20120109/d93f433f/attachment-0002.obj b/zarb-ml/mageia-dev/attachments/20120109/d93f433f/attachment-0002.obj new file mode 100644 index 000000000..f2bd56e85 --- /dev/null +++ b/zarb-ml/mageia-dev/attachments/20120109/d93f433f/attachment-0002.obj @@ -0,0 +1,71 @@ +(is_xen) enable to detect if we run under XEN +(should better check through cpuid...) + +(hasCPU_virt_support) detect whether we've HW support for virt or not + +(_is_kernelServer_supported) split it out of _is_kernelServer_needed() + +(_bestKernelXEN_extensions) select kernel-server or kernel-xen-pvps +when running under XEN (depending on virt HW support presence) + +(_bestKernel_extensions) use _bestKernelXEN_extensions() in order to +select the proper kernel for XEN + +diff -up ./detect_devices.pm.tv ./detect_devices.pm +--- ./detect_devices.pm.tv 2012-01-09 10:33:40.946242888 +0100 ++++ ./detect_devices.pm 2012-01-09 10:40:47.668522223 +0100 +@@ -1213,6 +1213,10 @@ sub is_vmware() { + any { $_->{driver} =~ /Card:VMware/ } detect_devices::pci_probe(); + } + ++sub is_xen() { ++ -f '/proc/xen/capabilities'; ++} ++ + sub is_netbook_nettop() { + my @cpus = getCPUs(); + (any { $_->{'model name'} =~ /(\bIntel\(R\) Atom\(TM\)\B)/i } @cpus) || +@@ -1254,6 +1258,10 @@ sub hasCPUMicrocode() { + return $hasCPUMicrocode; + } + ++sub hasCPU_virt_support() { ++ has_cpu_flag('svm') || has_cpu_flag('vmx'); ++} ++ + sub hasCPUFreq() { + require cpufreq; + to_bool(cpufreq::get_modules()) +diff -up ./install/pkgs.pm.tv ./install/pkgs.pm +--- ./install/pkgs.pm.tv 2012-01-09 10:30:32.527118304 +0100 ++++ ./install/pkgs.pm 2012-01-09 10:44:48.727700307 +0100 +@@ -105,12 +105,19 @@ sub packageByName { + $best; + } + +-sub _is_kernelServer_needed() { ++sub _is_kernelServer_supported() { + # forbid selecting kernel-server if not having PAE since PAE support is mandatory for kernel-server: +- return if !detect_devices::has_cpu_flag('pae'); ++ detect_devices::has_cpu_flag('pae'); ++} ++sub _is_kernelServer_needed() { ++ return if !_is_kernelServer_supported(); + arch() =~ /i.86/ && detect_devices::dmi_detect_memory() > 3.8 * 1024 || detect_devices::isServer(); + } + ++sub _bestKernelXEN_extensions() { ++ _is_kernelServer_supported() && detect_devices::hasCPU_virt_support() ? '-server' : '-xen-pvps'; ++} ++ + sub _bestKernel_extensions { + my ($o_match_all_hardware) = @_; + +@@ -118,6 +125,7 @@ sub _bestKernel_extensions { + $o_match_all_hardware ? (arch() =~ /i.86/ ? '-desktop586' : '-desktop') : + detect_devices::is_xbox() ? '-xbox' : + detect_devices::is_i586() ? '-desktop586' : ++ detect_devices::is_xen() ? _bestKernelXEN_extensions() : + _is_kernelServer_needed() ? '-server' : + '-desktop'; + }
\ No newline at end of file diff --git a/zarb-ml/mageia-dev/attachments/20120109/d93f433f/attachment-0003.obj b/zarb-ml/mageia-dev/attachments/20120109/d93f433f/attachment-0003.obj new file mode 100644 index 000000000..2bd391f8b --- /dev/null +++ b/zarb-ml/mageia-dev/attachments/20120109/d93f433f/attachment-0003.obj @@ -0,0 +1,93 @@ +c::is_xen() use cpuid in order to detect we're under XEN + +diff -up ./c/stuff.xs.pl.tv2 ./c/stuff.xs.pl +--- ./c/stuff.xs.pl.tv2 2012-01-09 10:49:22.807894338 +0100 ++++ ./c/stuff.xs.pl 2012-01-09 11:03:04.124482279 +0100 +@@ -105,6 +105,40 @@ int length_of_space_padded(char *str, in + return len; + } + ++int pv_context; ++static void cpuid(uint32_t idx, ++ uint32_t *eax, ++ uint32_t *ebx, ++ uint32_t *ecx, ++ uint32_t *edx) ++{ ++ asm volatile ( ++ "test %1,%1 ; jz 1f ; ud2a ; .ascii \"xen\" ; 1: cpuid" ++ : "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx) ++ : "0" (idx), "1" (pv_context) ); ++} ++ ++static int check_for_xen(void) ++{ ++ uint32_t eax, ebx, ecx, edx; ++ char signature[13]; ++ ++ cpuid(0x40000000, &eax, &ebx, &ecx, &edx); ++ *(uint32_t *)(signature + 0) = ebx; ++ *(uint32_t *)(signature + 4) = ecx; ++ *(uint32_t *)(signature + 8) = edx; ++ signature[12] = ' . "'\0'" . '; ++ ++ if ( strcmp("XenVMMXenVMM", signature) || (eax < 0x40000002) ) ++ return 0; ++ ++ cpuid(0x40000001, &eax, &ebx, &ecx, &edx); ++ printf("Running in %s context on Xen v%d.%d.\n", ++ pv_context ? "PV" : "HVM", (uint16_t)(eax >> 16), (uint16_t)eax); ++ return 1; ++} ++ ++ + MODULE = c::stuff PACKAGE = c::stuff + + '; +@@ -116,6 +150,46 @@ pcmcia_probe() + + print ' + int ++is_xen() ++ CODE: ++ pid_t pid; ++ int status; ++ uint32_t dummy; ++ ++ /* Check for execution in HVM context. */ ++ if ( check_for_xen() ) ++ return 0; ++ ++ /* Now we check for execution in PV context. */ ++ pv_context = 1; ++ ++ /* ++ * Fork a child to test the paravirtualised CPUID instruction. ++ * If executed outside Xen PV context, the extended opcode will fault. ++ */ ++ pid = fork(); ++ switch ( pid ) ++ { ++ case 0: ++ /* Child: test paravirtualised CPUID opcode and then exit cleanly. */ ++ cpuid(0x40000000, &dummy, &dummy, &dummy, &dummy); ++ exit(0); ++ case -1: ++ fprintf(stderr, "Fork failed.\n"); ++ return 0; ++ } ++ ++ /* ++ * Parent waits for child to terminate and checks for clean exit. ++ * Only if the exit is clean is it safe for us to try the extended CPUID. ++ */ ++ waitpid(pid, &status, 0); ++ if ( WIFEXITED(status) && check_for_xen() ) ++ return 0; ++ ++ return 0; ++ ++int + del_partition(hd, part_number) + int hd + int part_number
\ No newline at end of file diff --git a/zarb-ml/mageia-dev/attachments/20120109/d93f433f/attachment.obj b/zarb-ml/mageia-dev/attachments/20120109/d93f433f/attachment.obj new file mode 100644 index 000000000..f2bd56e85 --- /dev/null +++ b/zarb-ml/mageia-dev/attachments/20120109/d93f433f/attachment.obj @@ -0,0 +1,71 @@ +(is_xen) enable to detect if we run under XEN +(should better check through cpuid...) + +(hasCPU_virt_support) detect whether we've HW support for virt or not + +(_is_kernelServer_supported) split it out of _is_kernelServer_needed() + +(_bestKernelXEN_extensions) select kernel-server or kernel-xen-pvps +when running under XEN (depending on virt HW support presence) + +(_bestKernel_extensions) use _bestKernelXEN_extensions() in order to +select the proper kernel for XEN + +diff -up ./detect_devices.pm.tv ./detect_devices.pm +--- ./detect_devices.pm.tv 2012-01-09 10:33:40.946242888 +0100 ++++ ./detect_devices.pm 2012-01-09 10:40:47.668522223 +0100 +@@ -1213,6 +1213,10 @@ sub is_vmware() { + any { $_->{driver} =~ /Card:VMware/ } detect_devices::pci_probe(); + } + ++sub is_xen() { ++ -f '/proc/xen/capabilities'; ++} ++ + sub is_netbook_nettop() { + my @cpus = getCPUs(); + (any { $_->{'model name'} =~ /(\bIntel\(R\) Atom\(TM\)\B)/i } @cpus) || +@@ -1254,6 +1258,10 @@ sub hasCPUMicrocode() { + return $hasCPUMicrocode; + } + ++sub hasCPU_virt_support() { ++ has_cpu_flag('svm') || has_cpu_flag('vmx'); ++} ++ + sub hasCPUFreq() { + require cpufreq; + to_bool(cpufreq::get_modules()) +diff -up ./install/pkgs.pm.tv ./install/pkgs.pm +--- ./install/pkgs.pm.tv 2012-01-09 10:30:32.527118304 +0100 ++++ ./install/pkgs.pm 2012-01-09 10:44:48.727700307 +0100 +@@ -105,12 +105,19 @@ sub packageByName { + $best; + } + +-sub _is_kernelServer_needed() { ++sub _is_kernelServer_supported() { + # forbid selecting kernel-server if not having PAE since PAE support is mandatory for kernel-server: +- return if !detect_devices::has_cpu_flag('pae'); ++ detect_devices::has_cpu_flag('pae'); ++} ++sub _is_kernelServer_needed() { ++ return if !_is_kernelServer_supported(); + arch() =~ /i.86/ && detect_devices::dmi_detect_memory() > 3.8 * 1024 || detect_devices::isServer(); + } + ++sub _bestKernelXEN_extensions() { ++ _is_kernelServer_supported() && detect_devices::hasCPU_virt_support() ? '-server' : '-xen-pvps'; ++} ++ + sub _bestKernel_extensions { + my ($o_match_all_hardware) = @_; + +@@ -118,6 +125,7 @@ sub _bestKernel_extensions { + $o_match_all_hardware ? (arch() =~ /i.86/ ? '-desktop586' : '-desktop') : + detect_devices::is_xbox() ? '-xbox' : + detect_devices::is_i586() ? '-desktop586' : ++ detect_devices::is_xen() ? _bestKernelXEN_extensions() : + _is_kernelServer_needed() ? '-server' : + '-desktop'; + }
\ No newline at end of file |
