Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933027AbcLMLyr (ORCPT ); Tue, 13 Dec 2016 06:54:47 -0500 Received: from mail-db5eur01on0099.outbound.protection.outlook.com ([104.47.2.99]:63694 "EHLO EUR01-DB5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932455AbcLMLyp (ORCPT ); Tue, 13 Dec 2016 06:54:45 -0500 X-Greylist: delayed 17943 seconds by postgrey-1.27 at vger.kernel.org; Tue, 13 Dec 2016 06:54:43 EST Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=rkagan@virtuozzo.com; Date: Mon, 12 Dec 2016 23:20:35 +0300 From: Roman Kagan To: Radim =?utf-8?B?S3LEjW3DocWZ?= CC: Denis Plotnikov , , , , Subject: Re: [PATCH v1] KVM: x86: avoid redundant REQ_EVENT Message-ID: <20161212202034.GA937@rkaganip.lan> Mail-Followup-To: Roman Kagan , Radim =?utf-8?B?S3LEjW3DocWZ?= , Denis Plotnikov , den@virtuozzo.com, pbonzini@redhat.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org References: <20161212140223.277077-1-dplotnikov@virtuozzo.com> <20161212162943.GA2237@potion> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20161212162943.GA2237@potion> User-Agent: Mutt/1.7.1 (2016-10-04) X-Originating-IP: [2a02:2168:e19:2c00:4ad2:24ff:fec3:31e0] X-ClientProxiedBy: VI1PR07CA0075.eurprd07.prod.outlook.com (10.164.94.171) To AM5PR0802MB2467.eurprd08.prod.outlook.com (10.175.45.8) X-MS-Office365-Filtering-Correlation-Id: 27f4fb17-3db7-4d13-867e-08d422cc58e5 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001);SRVR:AM5PR0802MB2467; X-Microsoft-Exchange-Diagnostics: 1;AM5PR0802MB2467;3:muk1kQ49oWihMZ5RevIm5fb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ozFNVfF X-Microsoft-Exchange-Diagnostics: 1;AM5PR0802MB2467;31:Irfjj7mhUfXkqV3XxUsmX8pJR9v0UBz5uTMDjVrtZlVhprCbm8jA8/MwbseXUBOU6DO8wy42xJnrmV5dDZsXKzk1cWo5CKNCaCh6FCcMiR/mFdcRaPjDJVncNH62L/GW0aIFWgdh5tcNsj18SfpuskqsALhGovrEPBHeklbfuLzs0soA99F/EWlGQv07wnz1CH6AJjvCs//lnMVtI9fOmBsm/EP/W22kU4oyG2lIh9aLfZdyn/Tm1x2oPGVcdbsH;20:rrAc7ML6HDcg870SXkDsiFy4mqPNcp7b7hKjtGDL68FvZcRxOM0Ni9cfGXRHZ3jOU5FtDbhCDVM7x8YakjL15GQP8iu/3qzwSZUHZYc9aZhppnGrE5FAq7qazQAl15fSH7/V72EJMU0AL/FGNNLxhxVlHH7BaelFIKtERsffFldyYz/z7dG1ypJZ43XEeLUX2y7EMl5EBv0qd0wPRIrAZ1s791LL86zfQCqdauEJCej0VVoFEHFqdCwtxpv42sE2 X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040375)(601004)(2401047)(8121501046)(5005006)(10201501046)(3002001)(6041248)(20161123564025)(20161123562025)(20161123555025)(20161123560025)(6072148);SRVR:AM5PR0802MB2467;BCL:0;PCL:0;RULEID:;SRVR:AM5PR0802MB2467; X-Microsoft-Exchange-Diagnostics: 1;AM5PR0802MB2467;4:v5D7rGUTnSXpBSLbbdM32KVE19c/9ExwmxdAl5ecRxApFpyyg9vhdZ4wOWupAV7e181DQZhpE0wuti/36fvwDOH7mKfsrHC///mt1K6p8F+iIzBhLtRY+u/EJo0FhiLcVnU/B5Xu2v2QtdQvJmeo15S4NN65gi2/POpMzXdf8EQZIxfSA3+dDD5S343gseAok/+d/oiJmmSGGmcigXIMo/3ibYOz16U/cFBl6uH0PTtNpUpXmWu5AHKgBdiT/T/XURl0BJVHlgAA5Ge6z/PmoNM2j6TXqk6rQ+RiXfJwGMNASOjPNboDaHvH8DPVB6w/DvrCKT5tHtapYvtpFjupfhZ817tyggjNn2zWSnqf54mXKTvV1kldRfCu7QG4LrNfuB5xDF3iZa49/u731PnJyzag/5kjCDrQcppumLjbrtpRUnK+z94aDcrSCOqMQqWVa28A6eLQNaQ94Log21UZB45p/fSiI1RtCyTneajwjyaWlnNRIH2nDEbkL5BjmqBZq2X9E7oe6ESVmCChS8MjUqWGs3PqDLXUlKB6ZbFpvqPpJ2PiOGkyyL3RcFK+d15LHRsJYxoFPmL9/hGJrkuy/g== X-Forefront-PRVS: 0154C61618 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(4630300001)(6009001)(7916002)(39450400003)(377424004)(199003)(24454002)(189002)(2870700001)(83506001)(101416001)(5660300001)(305945005)(6116002)(76176999)(33656002)(4326007)(92566002)(54356999)(21086003)(6506006)(9686002)(47776003)(110136003)(7736002)(50986999)(42186005)(36756003)(106356001)(4001350100001)(81166006)(81156014)(8676002)(38730400001)(105586002)(4001150100001)(6666003)(97736004)(6916009)(50466002)(68736007)(69596002)(229853002)(2950100002)(189998001)(2906002)(86362001)(23676002)(1076002)(18370500001);DIR:OUT;SFP:1102;SCL:1;SRVR:AM5PR0802MB2467;H:rkaganip.lan;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtBTTVQUjA4MDJNQjI0Njc7MjM6MjlNSCtLU2w5eFpDVEVLQWhjRG9ML3Jy?= =?utf-8?B?S053YWFqZE4xVjhobkdXa3owTUdHVnBobHlvWm9vVGphYis0b2ZabTJWcHM1?= =?utf-8?B?dFNxWEhEdENYbTk0a05oYkNvd0U4SCtvQWJRalFiWkFwVU9hb3JMQWh5Mlk0?= =?utf-8?B?bHBQdG56NTBHNkVxakhmZnVqQTBuaUpQSXFKMkJHU2E5aDJMSUVsajNkUnRi?= =?utf-8?B?THQ5U3I1L0xO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com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Dec 2016 20:20:41.8406 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0802MB2467 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1957 Lines: 42 On Mon, Dec 12, 2016 at 05:29:43PM +0100, Radim Krčmář wrote: > 2016-12-12 17:02+0300, Denis Plotnikov: > > When processing KVM_REQ_EVENT, apic_update_ppr is called which may set > > KVM_REQ_EVENT again if the recalculated value of PPR becomes smaller > > than the previous one. This results in cancelling the guest entry and > > reiterating in vcpu_enter_guest. > > > > However this is unnecessary because at this point KVM_REQ_EVENT is > > already being processed and there are no other changes in the lapic > > that may require full-fledged state recalculation. > > > > This situation is often hit on systems with TPR shadow, where the > > TPR can be updated by the guest without a vmexit, so that the first > > apic_update_ppr to notice it is exactly the one called while > > processing KVM_REQ_EVENT. > > > > To avoid it, introduce a parameter in apic_update_ppr allowing to > > suppress setting of KVM_REQ_EVENT, and use it on the paths called from > > KVM_REQ_EVENT processing. > > We also call: > > kvm_cpu_get_interrupt() in nested_vmx_vmexit() > - that path is intended without KVM_REQ_EVENT > kvm_cpu_has_interrupt() in vmx_check_nested_events(), > - I think it does no harm > kvm_cpu_has_interrupt() in kvm_vcpu_has_events() > kvm_cpu_has_interrupt() in kvm_vcpu_ready_for_interrupt_injection() > - both seem safe as we should not have an interrupt between TPR > threshold and the new PPR value, so the KVM_REQ_EVENT was useless. > > I would prefer we made sure that only callers from KVM_REQ_EVENT used > the function we are changing -- it is really easy to make a hard-to-find > mistake in interrupt delivery. Indeed, that was my concern as well. How about introducing a parameter to kvm_cpu_{has,get}_interrupt() with the same meaning, and pass it down to apic_update_ppr()? Then only the call sites under KVM_REQ_EVENT processing would pass "false" there, and the rest would remain with "true"? Roman.