[alsa-devel] [PATCH 0/3] ALSA: intel8x0: Improve virtual environment detection
Improve detection logic as discussed early: add secondary checks by PCI SSID.
Note: patch [3/3] is made for alsa-driver tree.
This is refactoring patch: preparation for add improved detection code. Now all detection code placed in one place.
Signed-off-by: Konstantin Ozerkov kozerkov@parallels.com Signed-off-by: Denis V. Lunev den@openvz.org
diff --git a/pci/intel8x0.c b/pci/intel8x0.c index 45b2055..d726d94 100644 --- a/pci/intel8x0.c +++ b/pci/intel8x0.c @@ -2930,6 +2930,24 @@ static unsigned int sis_codec_bits[3] = { ICH_PCR, ICH_SCR, ICH_SIS_TCR };
+static int __devinit snd_intel8x0_inside_vm(void) +{ + int result = inside_vm; + + if (result < 0) { + /* detect KVM and Parallels virtual environments */ + result = kvm_para_available(); +#if defined(__i386__) || defined(__x86_64__) + result = result || boot_cpu_has(X86_FEATURE_HYPERVISOR); +#endif + } + + if (result) + printk(KERN_INFO "intel8x0: enable KVM optimization\n"); + + return result; +} + static int __devinit snd_intel8x0_create(struct snd_card *card, struct pci_dev *pci, unsigned long device_type, @@ -2997,9 +3015,7 @@ static int __devinit snd_intel8x0_create(struct snd_card *card, if (xbox) chip->xbox = 1;
- chip->inside_vm = inside_vm; - if (inside_vm) - printk(KERN_INFO "intel8x0: enable KVM optimization\n"); + chip->inside_vm = snd_intel8x0_inside_vm();
if (pci->vendor == PCI_VENDOR_ID_INTEL && pci->device == PCI_DEVICE_ID_INTEL_440MX) @@ -3243,14 +3259,6 @@ static int __devinit snd_intel8x0_probe(struct pci_dev *pci, buggy_irq = 0; }
- if (inside_vm < 0) { - /* detect KVM and Parallels virtual environments */ - inside_vm = kvm_para_available(); -#if defined(__i386__) || defined(__x86_64__) - inside_vm = inside_vm || boot_cpu_has(X86_FEATURE_HYPERVISOR); -#endif - } - if ((err = snd_intel8x0_create(card, pci, pci_id->driver_data, &chip)) < 0) { snd_card_free(card);
Detection code improved by PCI SSID usage. VM optimization now enabled only for known devcices (skip host devices forwarded to VM by VT-d or same kind of technology). For debug/troubleshooting purposes optimization can be forced (on/off) by module parameter: "inside_vm" (boolean).
Known devices (PCI SSID): 1af4:1100: Reserved for KVM devices. Note this is not yet implemented for KVM's ICH/AC'97 emulation. 1ab8:xxxx: Parallels ICH/AC'97 emulated sound.
Signed-off-by: Konstantin Ozerkov kozerkov@parallels.com Signed-off-by: Denis V. Lunev den@openvz.org
diff --git a/pci/intel8x0.c b/pci/intel8x0.c index d726d94..7db2a74 100644 --- a/pci/intel8x0.c +++ b/pci/intel8x0.c @@ -2930,20 +2930,41 @@ static unsigned int sis_codec_bits[3] = { ICH_PCR, ICH_SCR, ICH_SIS_TCR };
-static int __devinit snd_intel8x0_inside_vm(void) +static int __devinit snd_intel8x0_inside_vm(struct pci_dev *pci) { - int result = inside_vm; + int result = inside_vm; + char* msg = NULL;
- if (result < 0) { - /* detect KVM and Parallels virtual environments */ - result = kvm_para_available(); -#if defined(__i386__) || defined(__x86_64__) - result = result || boot_cpu_has(X86_FEATURE_HYPERVISOR); + /* check module parameter first (override detection) */ + if (result >= 0) { + msg = result ? "enable (forced) VM" : "disable (forced) VM"; + goto fini; + } + + /* detect KVM and Parallels virtual environments */ + result = kvm_para_available(); +#ifdef X86_FEATURE_HYPERVISOR + result = result || boot_cpu_has(X86_FEATURE_HYPERVISOR); #endif + if (!result) + goto fini; + + /* check for known (emulated) devices */ + if (pci->subsystem_vendor == 0x1af4 && + pci->subsystem_device == 0x1100) { + /* KVM emulated sound, PCI SSID: 1af4:1100 */ + msg = "enable KVM"; + } else if (pci->subsystem_vendor == 0x1ab8) { + /* Parallels VM emulated sound, PCI SSID: 1ab8:xxxx */ + msg = "enable Parallels VM"; + } else { + msg = "disable (unknown or VT-d) VM"; + result = 0; }
- if (result) - printk(KERN_INFO "intel8x0: enable KVM optimization\n"); +fini: + if (msg != NULL) + printk(KERN_INFO "intel8x0: %s optimization\n", msg);
return result; } @@ -3015,7 +3036,7 @@ static int __devinit snd_intel8x0_create(struct snd_card *card, if (xbox) chip->xbox = 1;
- chip->inside_vm = snd_intel8x0_inside_vm(); + chip->inside_vm = snd_intel8x0_inside_vm(pci);
if (pci->vendor == PCI_VENDOR_ID_INTEL && pci->device == PCI_DEVICE_ID_INTEL_440MX)
Fix build alsa-driver with recent changes in intel8x0 (improved virtualization detection).
"#ifdef X86_FEATURE_HYPERVISOR" check now placed in main code, no additional patching required.
Signed-off-by: Konstantin Ozerkov kozerkov@parallels.com Signed-off-by: Denis V. Lunev den@openvz.org
diff --git a/pci/intel8x0.patch b/pci/intel8x0.patch index 3b4b16f..6b3ce6c 100644 --- a/pci/intel8x0.patch +++ b/pci/intel8x0.patch @@ -43,17 +43,6 @@ } #else #define fill_nocache(buf, size, nocache) do { ; } while (0) -@@ -3247,8 +3258,10 @@ - /* detect KVM and Parallels virtual environments */ - inside_vm = kvm_para_available(); - #if defined(__i386__) || defined(__x86_64__) -+#ifdef X86_FEATURE_HYPERVISOR - inside_vm = inside_vm || boot_cpu_has(X86_FEATURE_HYPERVISOR); - #endif -+#endif - } - - if ((err = snd_intel8x0_create(card, pci, pci_id->driver_data, @@ -3320,3 +3333,5 @@
module_init(alsa_card_intel8x0_init)
At Wed, 9 Nov 2011 19:28:53 +0400, Konstantin Ozerkov wrote:
Improve detection logic as discussed early: add secondary checks by PCI SSID.
Note: patch [3/3] is made for alsa-driver tree.
Thanks, applied now.
The patch 3 couldn't be applied cleanly to my tree, so I refreshed by myself.
Which git trees are you referring to? At the next time, please create patches based on sound git tree, which is the base for linux-next: git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound.git
Also for the external alsa-driver, please use the git tree below: git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/alsa-driver-build.git
Takashi
On 09.11.11 20:41, Takashi Iwai wrote:
At Wed, 9 Nov 2011 19:28:53 +0400, Konstantin Ozerkov wrote:
Improve detection logic as discussed early: add secondary checks by PCI SSID.
Note: patch [3/3] is made for alsa-driver tree.
Thanks, applied now.
The patch 3 couldn't be applied cleanly to my tree, so I refreshed by myself.
Which git trees are you referring to? At the next time, please create patches based on sound git tree, which is the base for linux-next: git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound.git
Also for the external alsa-driver, please use the git tree below: git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/alsa-driver-build.git
Takashi
Thanks for advise.
I follow tutorial from http://www.alsa-project.org/main/index.php/GIT_Server I use git://git.alsa-project.org/alsa-driver.git git://git.alsa-project.org/alsa-kmirror.git
participants (2)
-
Konstantin Ozerkov
-
Takashi Iwai