ALSA: intel8x0: Improve virtual environment detection
cover 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.
PATCH 1/3 ALSA: intel8x0: move virtual environment detection code into one place
This is refactoring patch: preparation for add improved detection code. Now all detection code placed in one place.
pci/intel8x0.c +19 -11
@@ -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);
Signature · 1 line
1.7.1
PATCH 2/3 ALSA: intel8x0: improve virtual environment detection
In reply to Konstantin OzerkovDetection 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.
pci/intel8x0.c +31 -10
@@ -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 )
Signature · 1 line
1.7.1
PATCH 3/3 alsa-driver: Fix build intel8x0
In reply to Konstantin OzerkovFix 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.
pci/intel8x0.patch +0 -11
@@ -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)
Signature · 1 line
1.7.1
Takashi Iwai
AppliedAt Wed, 9 Nov 2011 19:28:53 +0400,
Quoted 4 lines · Konstantin Ozerkov
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
Quoted 14 lines · Takashi Iwai
At Wed, 9 Nov 2011 19:28:53 +0400,
Quoted 3 lines · Konstantin Ozerkov
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
Quoted 5 lines
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.gitTakashi
Thanks for advise.
I follow tutorial from http://www.alsa-project.org/main/index.php/GIT_Server
I usegit://git.alsa-project.org/alsa-driver.gitgit://git.alsa-project.org/alsa-kmirror.git