Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751379AbdILJAD (ORCPT ); Tue, 12 Sep 2017 05:00:03 -0400 Received: from mail-by2nam01on0059.outbound.protection.outlook.com ([104.47.34.59]:38624 "EHLO NAM01-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751214AbdILJAB (ORCPT ); Tue, 12 Sep 2017 05:00:01 -0400 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Suravee.Suthikulpanit@amd.com; Subject: Re: [PATCH 3/3] KVM: SVM: Add irqchip_split() checks before enabling AVIC To: =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= References: <1504669169-4919-1-git-send-email-suravee.suthikulpanit@amd.com> <1504669169-4919-4-git-send-email-suravee.suthikulpanit@amd.com> <20170908155324.GB14748@flask> Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, pbonzini@redhat.com, joro@8bytes.org From: Suravee Suthikulpanit Message-ID: <9475950b-566f-9425-5de9-9e6677e41043@amd.com> Date: Tue, 12 Sep 2017 01:59:55 -0700 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: <20170908155324.GB14748@flask> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [165.204.53.123] X-ClientProxiedBy: CY4PR1201CA0002.namprd12.prod.outlook.com (10.172.75.12) To CY4PR12MB1734.namprd12.prod.outlook.com (10.175.62.144) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 635e9037-2045-4405-8ddf-08d4f9bca58e X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(300000500095)(300135000095)(300000501095)(300135300095)(22001)(300000502095)(300135100095)(2017030254152)(48565401081)(300000503095)(300135400095)(2017052603199)(201703131423075)(201703031133081)(201702281549075)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095);SRVR:CY4PR12MB1734; X-Microsoft-Exchange-Diagnostics: 1;CY4PR12MB1734;3:QoSwgFBBQqQhkYe1KV/oq8XruEE7XaGjUNnrP7PfAcrz2g0xzzE/5jrVQXH/dP4PqjUMnw6cw3Qk2wk3KvJoxz47L1oJnc3dOAMY0UV42JcANqpp3jVEq5GX4/KJBsbCr9chAwN7IsgC5ywxmPR6945Msd9PtY6qQXdV0MS6kQO0jmpZKqvqxS1BCflF2ggxpqcSQqIsCzVMF9j8qfdI5Uxs3LYQw2YVP+8Nhm3P3kel36VwuRosxJEMOWpAKjON;25:fRk7I9LvJ6rGovO9BvdHspn2W1DuEBphOYRilqMJY+sW0kynZy6QUKtFPoQ4iE6FXgVGDUZMKCFy1dFYtFUMeBAWuDAxthDp69oEeDk6bkvEwxUVvKEcfsk0nMZAIl87Ers+9sir6HXnhlxBY6BOWux/SZZ+Z2nckXO6SnwUOwspDblaC+erg3RKeR/T9UjyeSrEjzyjmTiRhoCHdAbzpUWDirG2QlujezGdIzW3c2QpWm1ddS9UEud36pceWaPbItwCBSDbAi2xOpy/Tg1zUVV4RQXcDS7eBRR5S9HLsI6xnPVu50DW3yCVDf7lvhtd16UW6rH0HzLSIuGVTgY1sQ==;31:ssW4hNbE8/JXohT2VFTtQIvO2QnWOVzh+AjI/Pd9hCGVnVNmcWKVmkUhJ2OHyD1MnD3fM6R/0xCGgEv/mmfCv1nWDCqsNGlJWTbhS8E7vqnABmijwckTYLLMnkFlV3eE06jkuIWcsHES46EocjdYyMtfruvbPsjXLToRRM5bIMop4HxOIE60nbIp/X0VSjVk8nSDY+bav4m3knJAAzB2Vf/IGSUc4IYfQ0p8iyEYirs= X-MS-TrafficTypeDiagnostic: CY4PR12MB1734: X-Microsoft-Exchange-Diagnostics: 1;CY4PR12MB1734;20:sfzGauyXoGNT8wxreIAZ2HHDFzfq6+C9aHjajIh1GE50XHyK9IppX2zZSIkbJ5P9lytIoCHrdy8StdDe9psxtZiyu09tXuBAhVg7vjWBoQnC+vtxplKVyg688By7IapoxzC1plSdA6AP7r4Oye8BURR+vKAmJGjr0ra8eSNxxstWV6IuJnGE3s/NHx6KN70LrIKbKmbNFv5Q4Ajal5QlhJDj1sCnqqU3h5wmOVealX35H/R5S/APjwoR5oY9XFBXKKZdyt8lhjAzE4wU5dAJbyUn+61PpiVKs59Sh1VwGe7ZOp2uOyCkXYn583fkVB3HV+JojiSXMrIvydwP3D6/6cl6fRiDbA/zx9/VNtcn0kSHRBRpeCCNkNn6UsiDKDxUs7inS8j9K3/JpVA0c/CVW4IwKtq31ZET7hZslbe4vRCRliQt5RUBQRPLhChW7VnqZQgQOEOG29otgAGslqUJFjvBkMOh+CN+Fe5WWGFUJjx3xR+ANRzkXnhSDvB9yhun;4:vxbJtamPAQdeY3+zGzOYESP+c5UfflZUXnA6pDB/DyxT3gb+/1SXeFjwdukXEyOp4WHmT1dfR4qrPDnSxdXA2tnd6aYv21PL6lPyrTxn5HW/6PYViP35AeK13+/HWc8H8KJRbvZELVcZbnejoD2MR4vCPIFd3YImaNuE4L2G1Q2XioD5OD0k7XJtQnpX4dxRGLpHh0Q2stw0pkYtXJvY7jTtf9CAJ4SfJ8sJfq9JgagARjCo064xeDqq1VTgiP/jAcc6zf62+Jn9R8/1syIxuFJ12EGHNdBcv/Ah2haUPbI= X-Exchange-Antispam-Report-Test: UriScan:(767451399110); X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(2401047)(5005006)(8121501046)(10201501046)(100000703101)(100105400095)(93006095)(93001095)(3002001)(6055026)(6041248)(20161123560025)(20161123562025)(20161123558100)(20161123555025)(20161123564025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095);SRVR:CY4PR12MB1734;BCL:0;PCL:0;RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095);SRVR:CY4PR12MB1734; X-Forefront-PRVS: 042857DBB5 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(6009001)(39860400002)(24454002)(199003)(189002)(377424004)(305945005)(5660300001)(110136004)(2950100002)(229853002)(6916009)(4326008)(53416004)(31696002)(72206003)(33646002)(6116002)(65826007)(86362001)(3846002)(68736007)(105586002)(50986999)(2870700001)(53936002)(54356999)(101416001)(76176999)(106356001)(8676002)(6246003)(65806001)(36756003)(66066001)(23676002)(6486002)(65956001)(42186005)(189998001)(478600001)(53546010)(47776003)(25786009)(8936002)(83506001)(7736002)(31686004)(4001350100001)(6666003)(81166006)(97736004)(64126003)(81156014)(2906002)(316002)(50466002);DIR:OUT;SFP:1101;SCL:1;SRVR:CY4PR12MB1734;H:wsp093594wss.amd.com;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtDWTRQUjEyTUIxNzM0OzIzOmdodkR2aWFRckh5c2dKT1l0ZTdOdmlDanVj?= =?utf-8?B?TjlYMm5EeUhNWDZkK0ErdWV2QVJ1K2JRbUlmSUV1VUtzYUlvbm5nRG90WGxz?= =?utf-8?B?QTRLdVI0VFJRVnRTaHp6a0IxVjc2dUlQdTJpVXZiM21ibC84TENnbHVOZjMw?= =?utf-8?B?VXhSaVRoRXlhL1k4Ykoyb2dkT0ZMMVdTZmJ0WnlLd3NhQnh4WnVnMS9ucHhj?= =?utf-8?B?Z0duT1VBOFEwWVFhaldvSDJDWTc4Y0NQcEpBOXBxWmZqcmpiQlhwbDZjckxx?= =?utf-8?B?NytNc0tJdDlLNmM5eUlVTEQ2dnc0Tm5kaS9uNUI0ZFVDekw3eFF6RFhKT0RI?= =?utf-8?B?N05LRkJJVVFXWmFYeWUyUFVNSUVjTWRaeHVqaHltbWh1dGE3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HzeCsOA+hBWaZNyLFg7STaxZeCsdoscGzsYZTItqu+I/4Qn1ziV9GZL5VGRrSydKpe75BZ+D0SlGRRuNxFODc+IJyVSWN3JFx2VRHLSZNuFylerIQyv6Tp2AJdqgIq76sw==;24:5kDILvCqk+pSaV4dfwCSRFtxvTIGLiNU1tOwX3GQEghNXfCgOP8h8RMmkjcm42DwWP7OiXLyp97jbR3Tl7phFADntm/oNhUW5hc5ArPO7rE=;7:pg5pvB7zxhffYjOpm/v+XxFqxA8SKTYNxXCcaTUGO0DMgzMQGT7HYWxcA1O19cQQWm8soov+UWicmnYCWmHxgI1ksxxA82jRVy71zNZ4HZ7quM3t8gZsuQbrT1ISiO9mCoT+ySWx2xk2L1vU1n3gHYaNMh0oHvX90j3T2yZyIJc3mtIh5X2yszXc9SA0/RW8EgPFKj44JuGrBcG/+8PtSN1ukXGMVcGfmpaF5ceTOMI= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;CY4PR12MB1734;20:QvOGRMRB8ivhCDXxvOz6DHYD9UlR7bZSyUiFGm3FOmyZ7woJ4n/nE1TOcUCKjh+MJMSLTzLNdGckqskbqLiwmLfVNhwjFW6ZuZBsio9b+6RzZSRr8813wYlwytD9X3O6SGewcXa7kL5N4FJw2rdcsmcVxU2StgnPijvZNTr41eNS18ttv0+5BaGMf4UHFXEtcVSaCpCZGR9dx9I0rtyDB8vv4BG0YKF1V0SyCui9TYzoISOuepNrVIOBdEW094PO X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Sep 2017 08:59:58.7677 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1734 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2906 Lines: 96 Hi Radim, On 9/8/17 08:53, Radim Krčmář wrote: > 2017-09-05 22:39-0500, Suravee Suthikulpanit: >> SVM AVIC hardware accelerates guest write to APIC_EOI register >> (for edge-trigger interrupt), which means it does not trap to KVM. >> >> So, only enable SVM AVIC only in split irqchip mode. >> (e.g. launching qemu w/ option '-machine kernel_irqchip=split'). > > Yeah, hacking TMR to get the VM exit could result in future bugs. > We have to push split irqchip as the deafult in userspaces with this > change. Actually, I'm not quite sure about the advantages/disadvantages with split irqchip, and how it would affect other cases, and why it was not used as default currently. >> Suggested-by: Paolo Bonzini >> Signed-off-by: Suravee Suthikulpanit >> --- >> arch/x86/kvm/svm.c | 13 +++++++++---- >> 1 file changed, 9 insertions(+), 4 deletions(-) >> >> diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c >> index d1b3eb4..7ce191b 100644 >> --- a/arch/x86/kvm/svm.c >> +++ b/arch/x86/kvm/svm.c >> @@ -1292,7 +1291,7 @@ static void init_vmcb(struct vcpu_svm *svm) >> set_intercept(svm, INTERCEPT_PAUSE); >> } >> >> - if (avic) >> + if (kvm_vcpu_apicv_active(&svm->vcpu)) >> avic_init_vmcb(svm); >> /* >> @@ -1594,6 +1593,12 @@ static int avic_init_vcpu(struct vcpu_svm *svm) >> if (!avic) >> return 0; >> >> + if (!irqchip_split(svm->vcpu.kvm)) { > > The other place used kvm_vcpu_apicv_active() instead of checking > irqchip_split() directly, so I think it would be better to be consistent > and do it here too. > I'd also like if this workaround used !irqchip_split() exactly once. Ok, I'll clean up in V2. >> + pr_debug("%s: Disable AVIC due to non-split irqchip.\n", >> + __func__); > > There is going to be too much of those. pr_debug_once() would be a > better notification. We can also report it in svm_get_enable_apicv(). pr_debug_once does not use dynamic debug APIs. I think I can call pr_debug only when vcpu_id == 0. >> + return 0; >> + } >> + >> ret = avic_init_backing_page(&svm->vcpu); >> if (ret) >> return ret; >> @@ -4388,7 +4393,7 @@ static void svm_set_virtual_x2apic_mode(struct kvm_vcpu *vcpu, bool set) >> >> static bool svm_get_enable_apicv(struct kvm_vcpu *vcpu) >> { >> - return avic; >> + return avic && irqchip_split(vcpu->kvm); >> } >> >> static void svm_hwapic_irr_update(struct kvm_vcpu *vcpu, int max_irr) >> @@ -4405,7 +4410,7 @@ static void svm_refresh_apicv_exec_ctrl(struct kvm_vcpu *vcpu) >> struct vcpu_svm *svm = to_svm(vcpu); >> struct vmcb *vmcb = svm->vmcb; >> >> - if (!avic) >> + if (!avic || !irqchip_split(svm->vcpu.kvm)) > > Seems like we want !kvm_vcpu_apicv_active() here too. Right. > >> return; >> >> vmcb->control.int_ctl &= ~AVIC_ENABLE_MASK; > > (separate bug: refresh should be able to enable avic as well.) > > thanks. > Thanks, Suravee