Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752348AbdHHTZM (ORCPT ); Tue, 8 Aug 2017 15:25:12 -0400 Received: from mail-sn1nam01on0050.outbound.protection.outlook.com ([104.47.32.50]:51171 "EHLO NAM01-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752070AbdHHTZK (ORCPT ); Tue, 8 Aug 2017 15:25:10 -0400 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=brijesh.singh@amd.com; Cc: brijesh.singh@amd.com, pbonzini@redhat.com, joro@8bytes.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, x86@kernel.org, Thomas.Lendacky@amd.com Subject: Re: [PATCH v2] KVM: x86: Avoid guest page table walk when gpa_available is set To: =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= References: <1495206749-25393-1-git-send-email-brijesh.singh@amd.com> <20170719111939.GA16149@potion> <3d6d983e-b8e2-ac6d-409e-38e96f2da940@amd.com> <20170720074316.GA30718@potion> From: Brijesh Singh Message-ID: <2aa4bae3-79ef-0988-0333-813af04382a4@amd.com> Date: Tue, 8 Aug 2017 14:24:59 -0500 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: <20170720074316.GA30718@potion> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-Originating-IP: [165.204.78.1] X-ClientProxiedBy: MWHPR15CA0042.namprd15.prod.outlook.com (10.173.226.156) To SN1PR12MB0158.namprd12.prod.outlook.com (10.162.3.145) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 72b31371-3f76-4f5e-dd0f-08d4de932d44 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(300000500095)(300135000095)(300000501095)(300135300095)(22001)(300000502095)(300135100095)(2017030254152)(300000503095)(300135400095)(48565401081)(201703131423075)(201703031133081)(201702281549075)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095);SRVR:SN1PR12MB0158; X-Microsoft-Exchange-Diagnostics: 1;SN1PR12MB0158;3:gqU/nDfHHNOrqYXSVa/ucjKI+8RpsXZQxCCvthYuIY0Z6yO+coXC/XynEmUtys6o30S02X3Tfxi63x4NwhVAwmCwoufxR4TzQyhCHmUVdtb1oPHsQDuLmLOxUokJUl+0xgIR9VEy2LqX1Lj35P0Djl/rPh1ZZLJ7ihA45J+dDjsDnwzPdYZvBajDXwP+FqFN4o4kY9ljJLOqzuDmhqmqCq+JE4USFyZzbuELFsJrwu9dPmDEi/dSDuioGZkxi96j;25:LHIkXJpkXCKhfC5scNf/4hxN/m4kyOIAbD/mDeq7/LMz4TR0Bp9Qyi4eLBaF35iCm58m7vy/wizND/+OHNP0Q0+4OKHDcKZD+Viu7T+Xfz6jlcbwXHS3UcZ6irqs2k7ZRTvbHmy4GDpKoFQQQmM6wfcquPVwXxYimLpZGnOOxhPwmKMZrykAi56APOSReBYjUpnq4aWpfuNlgzM6AHod+JpBBdkPhIbe8+3uGvhRQCCfr+RnQUsH0t+wcyn25qqJiU3NUurU3jEkYcrykj01eT+pXFg63bp1xsfg53iaL4AfiY1rHXOybSEtkwELnG+xjPolv6iXk0d43GpQBf6eXQ==;31:K7qwJ1oUBbyfP1PcWDbjz2cgLkGqvX7fxkYvydCJGDRw3kiAaLjB0ZJhL3qLp1sbcsQMp+t9xC5PHHtuE7lSqcKXyPsLGv1cBEsze5HJyaLAIk1ansmDFAe+K9IWO1cfsUzLn7HMwX9Tr0RCRf4iRMJkTJcaUFHGOz1WBGmdb/B4VZbW71L+xG85A0GHv88Tvl81PgouV1kAKXgc5bNpyRp/t3w3h2kq/kCZhmNyYvM= X-MS-TrafficTypeDiagnostic: SN1PR12MB0158: X-Microsoft-Exchange-Diagnostics: 1;SN1PR12MB0158;20:K6dhncqn2l611mqAIDBA1/U8SYbw4dZ2E0tAV0gST/i+9Nh06gc8lKM0zjoF5u90grbDqK1NzzBGwc59d10mSnT8Dgd71LtD3gV8MtMbwBqn2/wYzNpKgFDcTQj9Yf6PK21MZn21/moHR0gamzy+tRTTSTtA4LlUygy9xwmDZFpSdW/+2zqW/niPXUSqhZbM7fYeUMxImX2GOh9Ltb182knNG+C8joNAUOZtl5uT8RK5mprRsua5MRO4Pss5nKpuaTuVgsvcdZy5rHmnIz7Qg6Y0cAkC7YevuJsg3X4LtfCC+o4ZrH058KUNp83FA6XiF1UXdArlDGto+jaSruHAweJ9WWUJaiWf382hiYBt1DiHM44bmCaWFMJR5l0obaffZ1Y/E9CPZvJYgtgkNeTvsgOEnTc0TjbL6qWpMxkEqkLBIVJ+GdeaEvqjnl/2WRTBlOLhIn3A95lGQvBDcqz5bZ16QY8FaHn+Qkw9sQppqCPiYGmiaxIJ/f9slH/k7zkN;4:iPs31HAL7fimwuFHf+bdGIxjofKKVBP4MvMVVvYjRkv3HPcxjn7BQ+zrPN6GchwmXSB26iND+iDCfH3/spaMr0gW7yfFGz6f1BbinCAC7x1ONJVXTObIEpyJeE0tyerqfDjZ+mKsFqJhrx7pMuw0Fmz0UORhF8gvLqxcpsQUnulIa64AF49pD4I0TZruG/xO22y/pWpgq4VYpZd0oUCNiPSIJlJr4x8BcCADx7A8mEuuRSQb7GhoaIkY1fS5by4b X-Exchange-Antispam-Report-Test: UriScan:; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(601004)(2401047)(8121501046)(5005006)(3002001)(10201501046)(93006095)(93001095)(100000703101)(100105400095)(6055026)(6041248)(20161123555025)(20161123562025)(20161123564025)(20161123560025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123558100)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095);SRVR:SN1PR12MB0158;BCL:0;PCL:0;RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095);SRVR:SN1PR12MB0158; X-Forefront-PRVS: 03932714EB X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(4630300001)(7370300001)(6049001)(6009001)(39410400002)(39400400002)(39860400002)(39840400002)(39850400002)(39450400003)(209900001)(377454003)(377424004)(24454002)(189002)(199003)(47776003)(7350300001)(50986999)(76176999)(110136004)(478600001)(38730400002)(53376002)(305945005)(93886004)(54356999)(2870700001)(101416001)(31686004)(7736002)(66066001)(106356001)(6306002)(81166006)(5660300001)(81156014)(4326008)(53936002)(2906002)(65826007)(33646002)(8676002)(3846002)(6116002)(105586002)(25786009)(6246003)(65806001)(68736007)(229853002)(36756003)(31696002)(42186005)(83506001)(966005)(77096006)(6486002)(53546010)(23676002)(189998001)(64126003)(97736004)(86362001)(575784001)(4001350100001)(90366009)(50466002)(6666003)(6916009)(2950100002)(65956001)(6606295002);DIR:OUT;SFP:1101;SCL:1;SRVR:SN1PR12MB0158;H:[10.236.136.62];FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtTTjFQUjEyTUIwMTU4OzIzOkxNU1BpcDBGVTRucVl6bmlZVzFkSjlnbSt0?= =?utf-8?B?L2Izb29qa1dTRSt5V0l1UlZHcFZFTzljWXdwSVU0ZUcvSXc4WW5BWFRmRWUw?= =?utf-8?B?MUlWRnpEMi9TK3J2Z3oxbms1Y2xPOHlLalZKT0lRUm9QdjU4VXVKY0ZiVkZL?= =?utf-8?B?QkhReHdHT2U0WHNGczdwTnJJQWFsTTQ1aytSVkQzNVlaVGh5ZGtSa2VrU3Mw?= =?utf-8?B?TTdrSDdaU1UzTlRrcXRnQUh5bkRSbFdBMVFISEtHSXpVN0YzOEFlUWc4UCtk?= =?utf-8?B?QTF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rpoYevciMDkISg9wNE75CQk9jZ204rkswXyDxDGlGiebeTqeiOFIp+FiwZXTWvCAC1z+4l4z9a6GC4Dk+GjK9cD715WLH0zUaj7Nz8LOjwyNlfxBYNO2wURbz/q92Xof8dlNRB7/OPnpvkxDkA+lmy/5u/0OQ= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;SN1PR12MB0158;20:qu1wm39D6DnsnDafbincen1XI9cU7YSu7tEhiWiZybYwJ7q7e8iH7Gshd1HlErF4qYtFmAYTgHxmQoVvYCPUGXO9fKfGyRYiKEBRe1MUioIMlRfwJxsSuvu8rniqwjQ7orHoZ5LANGdw9e8kCs2fVeuLh23gg2bfDCYRG2IHSvScpm2iJu89xg+vnXAVKZjbJbGrzKaLOxqVI6A4J76qW7X8wMUc5qQI5hBX3Z87sDLI9MqkWO2h3iY0/6zz2kwF X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Aug 2017 19:25:05.2129 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB0158 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2549 Lines: 68 Hi Radim, On 07/20/2017 02:43 AM, Radim Krčmář wrote: > 2017-07-19 08:35-0500, Brijesh Singh: >> On 07/19/2017 06:19 AM, Radim Krčmář wrote: >>> 2017-07-17 16:32-0500, Brijesh Singh: >>>> Hi Paolo and Radim >>>> >>>> Any comments on this patch, I could not find it in 4.13-2 branch. >>>> >>>> Please let me know if you want to fix something, or want me to >>>> refresh and resend the patch. >>> >>> Sorry, I tried it during the merge window, but it didn't pass tests on >>> VMX and I got distracted by other bugs before looking into the cause. >>> >>> Can you reproduce the fail? >>> >> >> No worries, thanks. >> >> I can try to reproduce it, are you running kvm-unittest or something different? > > I noticed that a linux guest hung in early boot, but at least (io)apic > kvm-unit-tests failed as well, IIRC. > >> IIRC, VMX does not set the gpa_available flag hence I am wondering what did I miss >> in the patch to trigger the failure. I will debug it and let you know. > > It does now, in ept_violation and ept_misconfig, > I am able to reproduce the issue on VMX, Sorry it took a bit longer to verify it. I was not aware that VMX is also making use of gpa_available flag hence I missed updating the vmx.c to set the gpa_val. After applying the below small patch I am able to boot the guest on Intel Xeon E5-2665. Additionally, there was one issue in current patch pointed by Paolo [1]. If patch was using vcpu->arch.gpa_val check as pointed by Paolo then on VMX we will silently fallback to guest page table walk (even when gpa_available is set). I guess since I have testing my code on SVM platform hence never caught the error. I will soon send updated patch. [1] http://marc.info/?l=kvm&m=150116338725964&w=2 diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index b5e0b02..9309fbb 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -6309,6 +6309,7 @@ static int handle_ept_violation(struct kvm_vcpu *vcpu) ? PFERR_PRESENT_MASK : 0; vcpu->arch.gpa_available = true; + vcpu->arch.gpa_val = gpa; vcpu->arch.exit_qualification = exit_qualification; return kvm_mmu_page_fault(vcpu, gpa, error_code, NULL, 0); @@ -6326,6 +6327,7 @@ static int handle_ept_misconfig(struct kvm_vcpu *vcpu) } ret = handle_mmio_page_fault(vcpu, gpa, true); + vcpu->arch.gpa_val = gpa; vcpu->arch.gpa_available = true; if (likely(ret == RET_MMIO_PF_EMULATE)) return x86_emulate_instruction(vcpu, gpa, 0, NULL, 0) ==