Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.2 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0E52BC10F13 for ; Sun, 14 Apr 2019 12:16:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C473C2084D for ; Sun, 14 Apr 2019 12:16:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="J26CvaM9" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726312AbfDNMQu (ORCPT ); Sun, 14 Apr 2019 08:16:50 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:33868 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726283AbfDNMQu (ORCPT ); Sun, 14 Apr 2019 08:16:50 -0400 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x3EC8eC6058942; Sun, 14 Apr 2019 12:15:47 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=content-type : mime-version : subject : from : in-reply-to : date : cc : content-transfer-encoding : message-id : references : to; s=corp-2018-07-02; bh=tSnXUKLxmVGLrN0WR8p4pE05W7QfcEhtmPJ4/H6ABQY=; b=J26CvaM9o9EyDnmspchGSbba6gy7pDwNARHLREjiQ8bWjaincDiGCKqQIsvzu055mLmM we8cVDvy/cEk1YEaA/+7aJCzaKfbP/NT0niMhqvKanIAX6gL1n2W/VHH8MookXBv9kWS uWCtqllkkt3B+SgpzQ4OVrILC1F0kAvp/L3aGhZ/W3bE1YJiGav1ettLWG+Kan5HDiRc C86W13rRIyG2j6QIo/f9bv/GMqPhO10Yk//Fsj5+KAtSHYJS7mrOuKkYZ2Z13S/6aeA8 TYJh3F5AAPeTSvRJ6qUiCLDLsQ70Ux4+UdnnrsIGlLnyao/Ge1fRnQlAo/wp0jkfclOd oA== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2120.oracle.com with ESMTP id 2rusneh3jb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 14 Apr 2019 12:15:47 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x3ECEB0A168400; Sun, 14 Apr 2019 12:15:46 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserp3020.oracle.com with ESMTP id 2rv2ttrqtt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 14 Apr 2019 12:15:46 +0000 Received: from abhmp0010.oracle.com (abhmp0010.oracle.com [141.146.116.16]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x3ECFjd7020546; Sun, 14 Apr 2019 12:15:45 GMT Received: from [192.168.14.112] (/79.178.245.34) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Sun, 14 Apr 2019 12:15:45 +0000 Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 11.1 \(3445.4.7\)) Subject: Re: [PATCH 6/7] KVM: lapic: Clean up the code for handling of a pre-expired hv_timer From: Liran Alon In-Reply-To: <20190412201834.10831-7-sean.j.christopherson@intel.com> Date: Sun, 14 Apr 2019 15:15:41 +0300 Cc: Paolo Bonzini , =?utf-8?B?UmFkaW0gS3LEjW3DocWZ?= , kvm@vger.kernel.org, Wanpeng Li Content-Transfer-Encoding: quoted-printable Message-Id: <9DCCF040-F617-4E10-9AA3-715F6EB51ADA@oracle.com> References: <20190412201834.10831-1-sean.j.christopherson@intel.com> <20190412201834.10831-7-sean.j.christopherson@intel.com> To: Sean Christopherson X-Mailer: Apple Mail (2.3445.4.7) X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9226 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=2 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1904140091 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9226 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=2 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1904140091 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org > On 12 Apr 2019, at 23:18, Sean Christopherson = wrote: >=20 > Calling apic_timer_expired() is a nop when a timer interrupt is = already > pending, i.e. there's no need to call apic_timer_expired() when = there's > a pending interrupt and the hv_timer wants to pend its own interrupt. > Separate the two flows to make the code more readable and to avoid an > unnecessary function call and read to ktimer->pending. In case timer is not periodic and r=3D=3D1, = atomic_read(&ktimer->pending) is not executed. >=20 > Cc: Wanpeng Li > Signed-off-by: Sean Christopherson > --- > arch/x86/kvm/lapic.c | 9 ++++++--- > 1 file changed, 6 insertions(+), 3 deletions(-) >=20 > diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c > index 1d649a2af04c..f0be6f148a47 100644 > --- a/arch/x86/kvm/lapic.c > +++ b/arch/x86/kvm/lapic.c > @@ -1703,9 +1703,12 @@ static bool start_hv_timer(struct kvm_lapic = *apic) > * the window. For periodic timer, leave the hv timer running = for > * simplicity, and the deadline will be recomputed on the next = vmexit. > */ > - if (!apic_lvtt_period(apic) && (r || = atomic_read(&ktimer->pending))) { > - if (r) > - apic_timer_expired(apic); > + if (!apic_lvtt_period(apic) && atomic_read(&ktimer->pending)) > + return false; > + > + /* set_hv_timer() returns '1' when the timer has already = expired. */ > + if (r) { > + apic_timer_expired(apic); > return false; > } >=20 > --=20 > 2.21.0 >=20 First, I think you should emphasise in commit message that you have = actually fixed a rare bug here. In case timer is periodic but given ktimer->tscdeadline has already = expired on host, we should call apic_timer_expired(). In addition, when start_hv_timer() returns false, restart_apic_timer() = just calls start_sw_timer() which use hrtimer instead of VMX preemption = timer. Therefore, it seems a bit ineffective to me for start_hv_timer() to = return false in case ktimer->pending or when ktimer->tscdeadline already = expired. Shouldn=E2=80=99t we return true in these cases? -Liran