Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754078AbcLNSzL (ORCPT ); Wed, 14 Dec 2016 13:55:11 -0500 Received: from mail-dm3nam03on0074.outbound.protection.outlook.com ([104.47.41.74]:5730 "EHLO NAM03-DM3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753482AbcLNSzI (ORCPT ); Wed, 14 Dec 2016 13:55:08 -0500 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=brijesh.singh@amd.com; Subject: Re: [PATCH v2 3/3] kvm: svm: Use the hardware provided GPA instead of page walk To: Paolo Bonzini References: <147992048887.27638.17559991037474542240.stgit@brijesh-build-machine> <147992052008.27638.18095073174935903705.stgit@brijesh-build-machine> <65a10dd8-5fae-350f-b597-f8f0261da766@redhat.com> <9820037d-e3ca-0131-3b04-2e51f2abc883@amd.com> <657442146.2535029.1481298111651.JavaMail.zimbra@redhat.com> <6e1fd4ba-016c-99ea-5b98-24f89479da4b@amd.com> <057d8a2e-0a3a-38d3-d9bf-9301e3eb8238@redhat.com> <43e626f1-e9a6-cf5d-4771-c6f7ca07ec8e@amd.com> CC: , , thomas lendacky , , , , , , , , From: Brijesh Singh Message-ID: <8ddf2c3b-833e-4c88-ff14-d1826171703e@amd.com> Date: Wed, 14 Dec 2016 12:39:01 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SN1PR0501CA0007.namprd05.prod.outlook.com (10.163.126.145) To CY1PR12MB0668.namprd12.prod.outlook.com (10.163.238.153) X-MS-Office365-Filtering-Correlation-Id: 2a6d9a66-cf1a-4dd1-86e1-08d424507c5c X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001);SRVR:CY1PR12MB0668; X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bkEC;20:Y1XtO5gHwdD7f1qEVvTpvVZEASORHZsqdS1XN5ZnoGhXzYR1qIyez2xe5ECqkEd84dM+LxrjFg+46vJ+mvPPimkDnif3aJOO1vAmmsdQJLc83IGaliStCnap9RU2Zlusa+jDilS4elDe4ky4QPvGMPB7Igwd2BQB8TqPFO6rMc52ju77wa4dtTv8tB/7VTYdjoLk350JaKj02Am49pbe4uXcZDmaykBL+1LAYkXakzgEqGSp9Ka1A89hlOzGxYOmsmBMVRxSBj3Hhh5XVnicfuz2NOYv/W6HcAySRvAECVU3F5J3Li1OoL5UKiRyg2cUBPUPgequDrheYO31jsmBHnzEV4bUPy66G2YRguXRuYdew3pYRi4X+uvY+2+omhsnY2+u44nNH238zSRLl4LFWjHkQ030RQk0+3S4Y3gJktvE3HfiJ3vG2KL6nAGu5UUQXHybKumIxJ4iWH3edBhPZyJ6fzX+xrGZILil6zD0PyEIiXliATdP36DZlPl099O/ X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(17755550239193); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040375)(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046)(6055026)(6041248)(20161123555025)(20161123560025)(20161123564025)(20161123562025)(6072148);SRVR:CY1PR12MB0668;BCL:0;PCL:0;RULEID:;SRVR:CY1PR12MB0668; X-Microsoft-Exchange-Diagnostics: 1;CY1PR12MB0668;4:PCvRvcRbE0a8idYi8Ghlh+OdgWIJoTrJT+4+9uPkKnoy+wOQg50USHS+oGinqkXwIZt1m/c+Cnuh+mG8c4g78ATbv5fJVBYmJHIrM6R/jROTZ/vv0TOD9N7F8HMLDxSelK3hWqIwNY1YvSH3ofM5OQxlCLx2URE+1qETBF+xHPkFvQpzzoHooYF+cXgjkF7BzWBe0lYcPAhahlvRjna9dFiYgNLzXHJFDYgwcFwl/NDJPxqPRtJaYOxrbz0AUH4OEY2/bTt6BKFzz3t7gcjm+8l2YNPJwonRW13mF9UVSbt3eN30sKC79eDGioWWCrc2JSVUQOufSg+ZuvzhWPhWo3MY1DgtOSl1tdN7tcos99l0C5FBX+hsFGJB3f3Oc8HdimEKlNqLMw+OOQrF4dwd0pQ5xVGEA0iZ+bu/SrZf6UXVIDL8aDXnDyDEZX38IYhnpDgAg2a6QvR2gMUgskbJISF6uRZ0oi+bE+ATyz1JxpN802yaGBPJTHi/MNiUU4LyqxHYxFtwWOAKMTB9lsq1kHyHbtUlLcofhLNsAzkhbUHAic3sBLlq4g5u9GE6wVSA1H5MbeMtd32G6RAJtEA51QIIposGXYPf477VKe1TLu8eOk63/rl+N5GbkNObV3PiV1DjU8fDjH1X55QBH5RqOA== X-Forefront-PRVS: 01565FED4C X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(4630300001)(979002)(6049001)(6009001)(7916002)(39860400002)(39840400002)(39410400002)(39850400002)(39450400003)(24454002)(377454003)(199003)(189002)(66066001)(65806001)(65956001)(230700001)(47776003)(106356001)(189998001)(2950100002)(68736007)(6916009)(110136003)(105586002)(83506001)(50466002)(7416002)(6666003)(25786008)(97736004)(4001350100001)(86362001)(31686004)(33646002)(36756003)(6116002)(229853002)(3846002)(42186005)(101416001)(92566002)(305945005)(54356999)(50986999)(93886004)(76176999)(8676002)(64126003)(38730400001)(7736002)(6486002)(4326007)(77096006)(31696002)(2906002)(23676002)(81166006)(90366009)(81156014)(65826007)(5660300001)(969003)(989001)(999001)(1009001)(1019001);DIR:OUT;SFP:1101;SCL:1;SRVR:CY1PR12MB0668;H:[10.236.136.62];FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtDWTFQUjEyTUIwNjY4OzIzOjdQRVRUMTIvYU52NndoZHRyUGg4d0RpTjZy?= =?utf-8?B?VnI3c0NjMTB6OXloL3RYMVdObThnL3RUUXZVeFdPcnBaSHJSR1ZEcm5IZExM?= =?utf-8?B?RnhPSXlFb2lsRGJTQW5ZSGplRVJmOXBy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X-Microsoft-Exchange-Diagnostics: 1;CY1PR12MB0668;7:wyjwlh/uhEc8EDCKIMJwf8PRV2okS38eLDo68Zqd3Vr+aaW8XRHPxh1XGaKCVES/XQpLqXbfCh+AWCGLq3zbrxwJ7Y/w4cy87qyd//a8oduLT10tGG62qiVxmf9BofzWSYoeMu6Oq/2G2gv6YgxPGaI5nWnKZ4V3muIxXDAJSdfh0ncfFv3hGfg/uEZD+0fq3nbCiYSuqgmK5NkUDYgrADVfo026VpwnP/Z2qMb9KGX2qkSurD28zbKUFLlCADknRaa6ZjQQNpG/mU7HrmZyWGXNeM4c2yHE2dN1Rbqww5pNu0O7zZo4KM5MHXUNZntYaITPTHf86m0olInowrZ3rDN8jNVafgLqThqGY7stX0gvlh3eR5ane0ZLKjSbhTAB/ZKcwjzWo0Av4ehzKca0ns/8lBDAFBVAKZ6QtROdf+DEtM6X7yGKR5T2SFYqiv84Pt39MbOvOhw6IJssCB3Lkg==;20:IS6EYFbaEnVRV2EofRW5VE3o5G4NLyWyZTWNi6txPEDkWtZ+CUFmFnrgex6AOb2vqtbJZ1X3uCqRtPRrwKDOuLKIdqGIR4JCGSaZ3bXlH3JzYzEysTXKrQixdbH9zHJmuN1A5Wj42nBb+eWOv015hbBclfqXrCz2I9WUVY7agz3WD2Kd+O3qIvX7APVSfQhebVFQ0XogUj4Yj1OWSC6O1i+pFbu16Rjd2OGvQm/gCKtD58qWXr5AYTS/CEQFdzEd X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Dec 2016 18:39:06.1939 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR12MB0668 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1951 Lines: 51 On 12/14/2016 11:23 AM, Paolo Bonzini wrote: > > > On 14/12/2016 18:07, Brijesh Singh wrote: >>> >> >> Since now we are going to perform multiple conditional checks before >> concluding that its safe to use HW provided GPA. How about if we add two >> functions "emulator_is_rep_string_op" and "emulator_is_two_mem_op" into >> emulator.c and use these functions inside the x86.c to determine if its >> safe to use HW provided gpa? > > Why not export only emulator_can_use_gpa from emulate.c? (So in the end > leaving emulator_is_string_op in emulate.c was the right thing to do, it > was just the test that was wrong :)). > Actually, I was not sure if putting emulator_can_use_gpa() in emulate.c was right thing - mainly because emulator.c does not deal with GPA. I will go with your advice and put it in emulator.c, it makes easy :) > The patch below is still missing the check for cross-page MMIO. Your > reference to the BKDG only covers MMCONFIG (sometimes referred to as > ECAM), not MMIO in general. Doing AND or OR into video memory for > example is perfectly legal, and I'm fairly sure that some obscure legacy > software does PUSH/POP into vram as well! > > I used your below code snippet to detect cross-page MMIO access. After applying these changes cross-page MMIO read/write unit test is passing just fine. I will include it in patch. > Actually there is a nice trick you can do to support cross-page > MMIO access detection: diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 37cd31645d45..754d251dc611 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -4549,6 +4549,7 @@ static int emulator_read_write_onepage(unsigned long addr, void *val, */ if (vcpu->arch.gpa_available && !emulator_can_use_hw_gpa(ctxt) && + (addr & ~PAGE_MASK) == (exception->address & ~PAGE_MASK) && vcpu_is_mmio_gpa(vcpu, addr, exception->address, write)) { gpa = exception->address; goto mmio;