From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752337AbdHHN5l (ORCPT ); Tue, 8 Aug 2017 09:57:41 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36906 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752059AbdHHN5k (ORCPT ); Tue, 8 Aug 2017 09:57:40 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 1D5416868F Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=pbonzini@redhat.com Subject: Re: [PATCH] KVM: X86: expand ->arch.apic_arb_prio to u64 To: "Longpeng (Mike)" Cc: rkrcmar@redhat.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, weidong.huang@huawei.com, arei.gonglei@huawei.com, wangxinxin.wang@huawei.com, longpeng.mike@gmail.com References: <1502192234-14068-1-git-send-email-longpeng2@huawei.com> <5e5d4edc-5861-b3d9-b4a2-890c9bbd53e0@redhat.com> <5989C1B5.5090308@huawei.com> From: Paolo Bonzini Message-ID: <09780c43-df1f-1f10-bb01-1fc7913910e4@redhat.com> Date: Tue, 8 Aug 2017 15:57:34 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: <5989C1B5.5090308@huawei.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Tue, 08 Aug 2017 13:57:40 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 08/08/2017 15:50, Longpeng (Mike) wrote: > > > On 2017/8/8 21:08, Paolo Bonzini wrote: > >> On 08/08/2017 13:37, Longpeng(Mike) wrote: >>> Currently 'apic_arb_prio' is int32_t, it's too short for long >>> time running. In our environment, it overflowed and then the >>> UBSAN was angry: >>> >>> signed integer overflow: >>> 2147483647 + 1 cannot be represented in type 'int' >>> CPU: 22 PID: 31237 Comm: qemu-kvm Tainted: ... >>> ... >>> Call Trace: >>> [] dump_stack+0x1e/0x20 >>> [] ubsan_epilogue+0x12/0x55 >>> [] handle_overflow+0x1ba/0x215 >>> [] __ubsan_handle_add_overflow+0x2a/0x31 >>> [] __apic_accept_irq+0x57a/0x5d0 [kvm] >>> [] kvm_apic_set_irq+0x9f/0xf0 [kvm] >>> [] kvm_irq_delivery_to_apic_fast+0x450/0x910 [kvm] >>> [] kvm_irq_delivery_to_apic+0xfa/0x7a0 [kvm] >>> [] kvm_set_msi+0xa9/0x100 [kvm] >>> [] kvm_send_userspace_msi+0x14d/0x1f0 [kvm] >>> [] kvm_vm_ioctl+0x4ee/0xdd0 [kvm] >>> ... >>> >>> We expand it to u64, this is large enough. Suppose the vcpu receives >>> 1000 irqs per second, then it won't overflow in 584942417 years. >>> ( 18446744073709551615/1000/3600/24/365 = 584942417 ) >> >> Since you only look at the difference, changing it to uint32_t should be >> enough. > > > Hi Paolo, > > I'm afraid uint32_t isn't enough. For 1000 irqs per second, it can only holds > 49 days ( although the overflow won't cause any corruption ). What matters is only the difference across 2 vCPUs. And in fact even 32 bits are probably too many, 16 or even 8 should be enough because overflowing arb_prio is a good thing. If you have delivered millions IRQs to VCPU0 (let's say for a day), and then switch the interrupt to VCPU1, you don't want to the next day to have interrupts going to VCPU1 only. A short warm-up time (a few seconds?) is acceptable, but then you should have interrupts distributed equally between VCPU0 and VCPU1. This can only happen if arb_prio overflows. Paolo > 4294967295/1000/3600/24 = 49 > >> >> Paolo >> > >> . >> > >