From patchwork Mon Dec 10 18:47:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Kagan X-Patchwork-Id: 10722217 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4BA326C5 for ; Mon, 10 Dec 2018 18:47:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3C8922AC88 for ; Mon, 10 Dec 2018 18:47:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 30A672AC91; Mon, 10 Dec 2018 18:47:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BDDE42AC88 for ; Mon, 10 Dec 2018 18:47:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728774AbeLJSrf (ORCPT ); Mon, 10 Dec 2018 13:47:35 -0500 Received: from mail-eopbgr20106.outbound.protection.outlook.com ([40.107.2.106]:63839 "EHLO EUR02-VE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728650AbeLJSre (ORCPT ); Mon, 10 Dec 2018 13:47:34 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=VbYtpjUlFHZAheEKdbLJ5whVESyUsaTguCH4873SovM=; b=hZ6DRKqQUzA3awCEGK5wT1CrHVGKXEt2Fdcf9HnUYGwRluUCFgYcNyjupj1SStSpUFfoXrgQWKS6BwL2Ui51fFECoHppadifS0DHjzfM7n32+PXX5O8u3Dg+3eB4keXbxKAOsmM4dEw9ibUlZMnyNC5vMqDxeV4oMuqsaKu4V2k= Received: from DB8PR08MB4092.eurprd08.prod.outlook.com (20.179.10.210) by DB8PR08MB4091.eurprd08.prod.outlook.com (20.179.10.209) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1404.23; Mon, 10 Dec 2018 18:47:27 +0000 Received: from DB8PR08MB4092.eurprd08.prod.outlook.com ([fe80::d41:d012:1944:5810]) by DB8PR08MB4092.eurprd08.prod.outlook.com ([fe80::d41:d012:1944:5810%6]) with mapi id 15.20.1404.026; Mon, 10 Dec 2018 18:47:27 +0000 From: Roman Kagan To: "kvm@vger.kernel.org" CC: Paolo Bonzini , =?iso-8859-2?q?Radim_Kr=E8m=E1=F8?= , Vitaly Kuznetsov Subject: [PATCH 2/2] x86: kvm: hyperv: don't retry message delivery for periodic timers Thread-Topic: [PATCH 2/2] x86: kvm: hyperv: don't retry message delivery for periodic timers Thread-Index: AQHUkLjLylqEzCX6CESL5mSMNKU7kg== Date: Mon, 10 Dec 2018 18:47:27 +0000 Message-ID: <20181210184717.29086-3-rkagan@virtuozzo.com> References: <20181210184717.29086-1-rkagan@virtuozzo.com> In-Reply-To: <20181210184717.29086-1-rkagan@virtuozzo.com> Accept-Language: en-US, ru-RU Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [185.231.240.5] x-clientproxiedby: HE1PR05CA0181.eurprd05.prod.outlook.com (2603:10a6:3:f8::29) To DB8PR08MB4092.eurprd08.prod.outlook.com (2603:10a6:10:ab::18) authentication-results: spf=none (sender IP is ) smtp.mailfrom=rkagan@virtuozzo.com; x-ms-exchange-messagesentrepresentingtype: 1 x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;DB8PR08MB4091;20:L6EW5nviBIQaNcLMAQ7psUsJ9p4sM8JAZ+mGsyjU4pa3LW78sj3+mJXkUM4DXiAodByyn+VZ7lhmPxbVYK4ABN08xjOGFeUeOJi3M80DyrN5x44IZUZ1PYN9hCcwhcPowCQqyEWiU0B4aT4eTyZLplCMNbKcujpJJOCj6M3IlkE= x-ms-office365-filtering-correlation-id: b2fda3d8-19bc-4b70-14da-08d65ecfee41 x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390098)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(2017052603328)(7153060)(7193020);SRVR:DB8PR08MB4091; x-ms-traffictypediagnostic: DB8PR08MB4091: x-microsoft-antispam-prvs: x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(6040522)(2401047)(8121501046)(5005006)(3231455)(999002)(944501520)(52105112)(3002001)(93006095)(93001095)(10201501046)(148016)(149066)(150057)(6041310)(20161123558120)(20161123562045)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(201708071742011)(7699051)(76991095);SRVR:DB8PR08MB4091;BCL:0;PCL:0;RULEID:;SRVR:DB8PR08MB4091; x-forefront-prvs: 08828D20BC x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(366004)(346002)(136003)(376002)(39850400004)(396003)(189003)(199004)(54906003)(106356001)(71200400001)(105586002)(2906002)(86362001)(71190400001)(52116002)(486006)(316002)(2501003)(6116002)(3846002)(1076002)(476003)(8936002)(2616005)(256004)(14444005)(81156014)(1730700003)(8676002)(446003)(81166006)(2351001)(11346002)(102836004)(4326008)(15650500001)(53936002)(186003)(7736002)(6512007)(26005)(5660300001)(68736007)(6506007)(386003)(76176011)(305945005)(36756003)(14454004)(6486002)(99286004)(97736004)(66066001)(478600001)(6916009)(25786009)(5640700003)(6436002);DIR:OUT;SFP:1102;SCL:1;SRVR:DB8PR08MB4091;H:DB8PR08MB4092.eurprd08.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: virtuozzo.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: VGsEqZBJa0/OOg0JwNnC9+vkDh+aDE8tTYlLlADTr57sYGE1KeYxlyj18GA6I+RnTycFCsjDIkOKIpHwAu2lp4An3b1qKuanBpK/jLQoXGaD1JmMGqPve27fFFbA/nnS7/VL9/i4WdVZpoY5TXfFHnTlpXeSZBNuXFWunFDCZcH99wTifWc81dSKcb9joPAGNTAjIGioB25XPQ/89lWpavm6U0itBXn6PQkCwsAGUpFO/hO99VVcjKoUeLnuP0t4+EMV0k5KPuu7M+P+Lv8cTEqwAEgPQgz4e6bta2HqhmUcRZ+YmjDSN92QSK3Q6GFR spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: b2fda3d8-19bc-4b70-14da-08d65ecfee41 X-MS-Exchange-CrossTenant-originalarrivaltime: 10 Dec 2018 18:47:27.2270 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB8PR08MB4091 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The SynIC message delivery protocol allows the message originator to request, should the message slot be busy, to be notified when it's free. However, this is unnecessary and even undesirable for messages generated by SynIC timers in periodic mode: if the period is short enough compared to the time the guest spends in the timer interrupt handler, so the timer ticks start piling up, the excessive interactions due to this notification and retried message delivery only makes the things worse. [This was observed, in particular, with Windows L2 guests setting (temporarily) the periodic timer to 2 kHz, and spending hundreds of microseconds in the timer interrupt handler due to several L2->L1 exits; under some load in L0 this could exceed 500 us so the timer ticks started to pile up and the guest livelocked.] Relieve the situation somewhat by not retrying message delivery for periodic SynIC timers. This appears to remain within the "lazy" lost ticks policy for SynIC timers as implemented in KVM. Note that it doesn't solve the fundamental problem of livelocking the guest with a periodic timer whose period is smaller than the time needed to process a tick, but it makes it a bit less likely to be triggered. Signed-off-by: Roman Kagan Reviewed-by: Vitaly Kuznetsov --- arch/x86/kvm/hyperv.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c index 17d04d2c6d4f..3f2b93ad9ccf 100644 --- a/arch/x86/kvm/hyperv.c +++ b/arch/x86/kvm/hyperv.c @@ -557,7 +557,7 @@ static int stimer_get_count(struct kvm_vcpu_hv_stimer *stimer, u64 *pcount) } static int synic_deliver_msg(struct kvm_vcpu_hv_synic *synic, u32 sint, - struct hv_message *src_msg) + struct hv_message *src_msg, bool no_retry) { struct kvm_vcpu *vcpu = synic_to_vcpu(synic); int msg_off = offsetof(struct hv_message_page, sint_message[sint]); @@ -584,6 +584,9 @@ static int synic_deliver_msg(struct kvm_vcpu_hv_synic *synic, u32 sint, return r; if (hv_hdr.message_type != HVMSG_NONE) { + if (no_retry) + return 0; + hv_hdr.message_flags.msg_pending = 1; r = kvm_vcpu_write_guest_page(vcpu, msg_page_gfn, &hv_hdr.message_flags, @@ -616,11 +619,17 @@ static int stimer_send_msg(struct kvm_vcpu_hv_stimer *stimer) struct hv_message *msg = &stimer->msg; struct hv_timer_message_payload *payload = (struct hv_timer_message_payload *)&msg->u.payload; + /* + * don't retry message delivery for periodic ticks, otherwise they may + * pile up + */ + bool no_retry = stimer->config & HV_STIMER_PERIODIC; payload->expiration_time = stimer->exp_time; payload->delivery_time = get_time_ref_counter(vcpu->kvm); return synic_deliver_msg(vcpu_to_synic(vcpu), - HV_STIMER_SINT(stimer->config), msg); + HV_STIMER_SINT(stimer->config), msg, + no_retry); } static void stimer_expiration(struct kvm_vcpu_hv_stimer *stimer)