Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.
RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.

Bug 960383

Summary: SMP affinity to multiple CPUs is failed.
Product: Red Hat Enterprise Linux 6 Reporter: huiqingding <huding>
Component: qemu-kvmAssignee: Radim Krčmář <rkrcmar>
Status: CLOSED NOTABUG QA Contact: Virtualization Bugs <virt-bugs>
Severity: medium Docs Contact:
Priority: medium    
Version: 6.4CC: acathrow, alex.williamson, bsarathy, chayang, huding, juzhang, knoel, michen, mkenneth, mst, qzhang, virt-maint, xfu
Target Milestone: rc   
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2013-11-27 19:30:55 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description huiqingding 2013-05-07 07:04:44 UTC
Description of problem:
SMP affinity of virtio-net-pci device is failed. The result is as following (boot guest with 4 vcpus):
 1. "echo 1 > /proc/irq/XX/smp_affinity" can work. The interrupts can be distributed to CPU0

 2. "echo 2 > /proc/irq/XX/smp_affinity" can work. The interrupts can be distributed to CPU1

 3. "echo 3 > /proc/irq/XX/smp_affinity" doesn't work. The interrupts is distributed to the latested used vcpu. For example, first "echo 2 > /proc/irq/XX/smp_affinity" and the interrupts is distributed to CPU1. And then, "echo 3 > /proc/irq/XX/smp_affinity" and the interrupts is also always distributed to CPU1 and the interrupts on CPU0 and CPU1 is not modified.

 4. "echo f > /proc/irq/XX/smp_affinity" doesn't work. The interrupts is distributed to the latested used vcpu. For example, first "echo 4 > /proc/irq/XX/smp_affinity" and the interrupts is distributed to CPU2. And then, "echo f > /proc/irq/XX/smp_affinity" and the interrupts is also always distributed to CPU2 and the interrupts on other CPUs is not modified.

Version-Release number of selected component (if applicable):
kernel-2.6.32-358.8.1.el6.x86_64
qemu-kvm-0.12.1.2-2.362.el6.x86_64

How reproducible:
100%

Steps to Reproduce:
1. Boot guest:
/usr/libexec/qemu-kvm -M pc -cpu SandyBridge -enable-kvm -m 2048 -smp 4,sockets=2,cores=2,threads=1 -name rhel7 -rtc base=localtime,clock=host,driftfix=slew -drive file=/root/rhel6u4/rhel6u4.qcow2,if=none,id=drive-scsi0-disk0,format=qcow2,werror=stop,rerror=stop -device virtio-scsi-pci,id=scsi0,addr=0x4 -device scsi-hd,scsi-id=0,lun=0,bus=scsi0.0,drive=drive-scsi0-disk0,id=virtio-disk0,bootindex=1 -netdev tap,id=hostnet0,vhost=on,script=/etc/qemu-ifup -device virtio-net-pci,netdev=hostnet0,id=virtio-netpci0,mac=54:52:1b:35:2c:01,bus=pci.0,addr=0x5 -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x6 -serial unix:/tmp/ttyS0,server,nowait -vnc :10 -vga std -monitor stdio -spice port=3000,disable-ticketing
2. Stop irqbalance on guest
service irqbalance stop
3. On guest, flood ping remote box
ping -f 10.66.5.4
4. On remote box, flood ping guest
ping -f 10.66.7.183
5. Modify smp_affinity of virtio-net-pci device
echo f > /proc/irq/XX/smp_affinity
6. Check the interrupts number of each vcpu.
cat /proc/interrupts
  
Actual results:
IRQs are always assigned to one CPU of latest used, which is a single fixed vcpu within the mask and doesn't migrate to other CPUs.

For example, first "echo 4 > /proc/irq/XX/smp_affinity" and the interrupts is distributed to CPU2. And then, "echo f > /proc/irq/XX/smp_affinity" and the interrupts is also always distributed to CPU2 and the interrupts on other CPUs is not modified.

Expected results:

IRQs would be distributed across all CPUs.

Additional info:

Comment 1 huiqingding 2013-05-07 07:13:01 UTC
Assign a intel 82576 NIC card to guest and test SMP affinity. Also hits this problem. 

This NIC card supports MSI-X and the detaild PCI information is as following:
# lspci -vvv -s 00:03.0
00:03.0 Ethernet controller: Intel Corporation 82576 Gigabit Network Connection (rev 01)
	Subsystem: Intel Corporation Gigabit ET2 Quad Port Server Adapter
	Physical Slot: 3
	Control: I/O+ Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B- DisINTx+
	Status: Cap+ 66MHz- UDF- FastB2B- ParErr- DEVSEL=fast >TAbort- <TAbort- <MAbort- >SERR- <PERR- INTx-
	Latency: 0, Cache Line Size: 32 bytes
	Interrupt: pin A routed to IRQ 11
	Region 0: Memory at f1020000 (32-bit, non-prefetchable) [size=128K]
	Region 1: Memory at f1400000 (32-bit, non-prefetchable) [size=4M]
	Region 2: I/O ports at c020 [size=32]
	Region 3: Memory at f1800000 (32-bit, non-prefetchable) [size=16K]
	Capabilities: [a0] Express (v2) Endpoint, MSI 00
		DevCap:	MaxPayload 512 bytes, PhantFunc 0, Latency L0s <512ns, L1 <64us
			ExtTag- AttnBtn- AttnInd- PwrInd- RBE+ FLReset-
		DevCtl:	Report errors: Correctable- Non-Fatal- Fatal- Unsupported-
			RlxdOrd+ ExtTag- PhantFunc- AuxPwr- NoSnoop+
			MaxPayload 128 bytes, MaxReadReq 512 bytes
		DevSta:	CorrErr- UncorrErr- FatalErr- UnsuppReq- AuxPwr- TransPend-
		LnkCap:	Port #0, Speed 2.5GT/s, Width x4, ASPM L0s L1, Latency L0 <4us, L1 <64us
			ClockPM- Surprise- LLActRep- BwNot-
		LnkCtl:	ASPM Disabled; RCB 64 bytes Disabled- Retrain- CommClk+
			ExtSynch- ClockPM- AutWidDis- BWInt- AutBWInt-
		LnkSta:	Speed 2.5GT/s, Width x4, TrErr- Train- SlotClk- DLActive- BWMgmt- ABWMgmt-
		DevCap2: Completion Timeout: Range ABCD, TimeoutDis+, LTR-, OBFF Not Supported
		DevCtl2: Completion Timeout: 16ms to 55ms, TimeoutDis-, LTR-, OBFF Disabled
		LnkSta2: Current De-emphasis Level: -6dB, EqualizationComplete-, EqualizationPhase1-
			 EqualizationPhase2-, EqualizationPhase3-, LinkEqualizationRequest-
	Capabilities: [40] Power Management version 3
		Flags: PMEClk- DSI+ D1- D2- AuxCurrent=0mA PME(D0-,D1-,D2-,D3hot-,D3cold-)
		Status: D0 NoSoftRst+ PME-Enable- DSel=0 DScale=0 PME-
	Capabilities: [70] MSI-X: Enable+ Count=10 Masked-
		Vector table: BAR=3 offset=00000000
		PBA: BAR=3 offset=00002000
	Capabilities: [50] MSI: Enable- Count=1/1 Maskable- 64bit-
		Address: 00000000  Data: 0000
	Kernel driver in use: igb
	Kernel modules: igb

Comment 5 Gleb Natapov 2013-05-23 16:23:51 UTC
Where the assumption that without irqbalancer irq will be distributed is comming from? This is irqbalancer job to distribute interrupts. In some limited scenarious OS can configure interrupt as LowPrio and then it will be distributed by HW, but most often than not such config is not possible or OS chose to not use it. On my physical machins all afinity is set to ffff and no interrupts are distributed.

Comment 6 Alex Williamson 2013-05-23 21:28:28 UTC
Gleb, is this a guest kernel issue?  Testing on a RHEL6.4 host, I find that an smp_affinity mask with multiple CPUs set does work with a RHEL6.4 guest, but does not work with a RHEL5 guest.  The name of the guest in comment 0 is rhel7, but I don't know if that reflects what's actually running.  Perhaps something broke upstream?

Comment 7 huiqingding 2013-05-24 09:47:37 UTC
Hello, Gleb,
(In reply to Gleb Natapov from comment #5)
> Where the assumption that without irqbalancer irq will be distributed is
> comming from? 

I make irq affinity test refering to IRQ-affinity.txt in kernel-doc. About why to stop irqbalance service, mainly refer to some tech doc from internet such as: https://access.redhat.com/site/documentation/en-US/Red_Hat_Enterprise_MRG/2/html/Realtime_Tuning_Guide/sect-Realtime_Tuning_Guide-General_System_Tuning-Interrupt_and_Process_Binding.html

>On my physical machins all afinity is set to ffff and no interrupts are distributed.

I test two cards on physical machines, the result is: 
1) One supports MSI-X, I set ffff and interrupts can only be distributed to CPU0.
2) The other supports MSI, I set ffff and interrupts can be distributed to all cpus.

I assign the NIC card supporting MSI to rhel6.4 guest. 
On guest, I set ffff and interrupts can only be distributed to CPU0.
Add "pci=nomsi" to guest kernel line, set ffff and interrupts can only be distributed to CPU0. 


The host and guest kernel version is:
kernel-2.6.32-358.el6.x86_64
The qemu-kvm version is:
qemu-kvm-0.12.1.2-2.370.el6.x86_64

Best regards,
Ding Huiqing

Comment 8 Gleb Natapov 2013-05-24 10:41:20 UTC
(In reply to Alex Williamson from comment #6)
> Gleb, is this a guest kernel issue?  Testing on a RHEL6.4 host, I find that
> an smp_affinity mask with multiple CPUs set does work with a RHEL6.4 guest,
> but does not work with a RHEL5 guest.  The name of the guest in comment 0 is
> rhel7, but I don't know if that reflects what's actually running.  Perhaps
> something broke upstream?

I wouldn't call it an issue :) But yes, it depends on how guest kernel
configures interrupt controller. The only way HW can distribute interrupts
is by LowPrio mechanism and the mechanism is very limit and does not allow
distribution to arbitrary set of vcpus (if there is more then 8 cpus anyway).
Probably newer kernels stop even trying, but I cannot tell if this intentional
or a bug.

There is a reason irqbalacer exists.

Comment 9 Gleb Natapov 2013-05-24 10:51:50 UTC
(In reply to huiqingding from comment #7)
> Hello, Gleb,
> (In reply to Gleb Natapov from comment #5)
> > Where the assumption that without irqbalancer irq will be distributed is
> > comming from? 
> 
> I make irq affinity test refering to IRQ-affinity.txt in kernel-doc.
That document predates beginning of the git. This is ancient history.
 
>  About
> why to stop irqbalance service, mainly refer to some tech doc from internet
> such as:
> https://access.redhat.com/site/documentation/en-US/Red_Hat_Enterprise_MRG/2/
> html/Realtime_Tuning_Guide/sect-Realtime_Tuning_Guide-General_System_Tuning-
> Interrupt_and_Process_Binding.html
This document talks about manually binding interrupts to cpus, which works perfectly fine according to
your test if you do not expect interrupt to be distributed to multiple cpus.

> 
> >On my physical machins all afinity is set to ffff and no interrupts are distributed.
> 
> I test two cards on physical machines, the result is: 
> 1) One supports MSI-X, I set ffff and interrupts can only be distributed to
> CPU0.
> 2) The other supports MSI, I set ffff and interrupts can be distributed to
> all cpus.
It has nothing to do with MSI or MSI-X. What's machines HW (number of sockets/cores) and kernel versions.

Comment 13 Radim Krčmář 2013-11-27 19:30:55 UTC
This behavior is expected, "-cpu SandyBridge" enables x2apic and KVM emulates just "physical x2apic", which does not allow lowest priority delivery.

(We have lowest priority delivery in "flat" mode only; guest kernel with "nox2apic" parameter will likely use it.)

Comment 14 Radim Krčmář 2013-11-28 18:23:55 UTC
*** Bug 1029343 has been marked as a duplicate of this bug. ***