From patchwork Mon Nov 14 22:15:51 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brijesh Singh X-Patchwork-Id: 9428625 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 03C356047D for ; Mon, 14 Nov 2016 22:31:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 114D328A2F for ; Mon, 14 Nov 2016 22:31:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 058C528AD3; Mon, 14 Nov 2016 22:31: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=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable 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 6AC2528A2F for ; Mon, 14 Nov 2016 22:31:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933656AbcKNWbO (ORCPT ); Mon, 14 Nov 2016 17:31:14 -0500 Received: from mail-sn1nam02on0075.outbound.protection.outlook.com ([104.47.36.75]:55307 "EHLO NAM02-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752842AbcKNWbM (ORCPT ); Mon, 14 Nov 2016 17:31:12 -0500 X-Greylist: delayed 910 seconds by postgrey-1.27 at vger.kernel.org; Mon, 14 Nov 2016 17:31:11 EST DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=maOLpN73peURmSXBwdAzYw0Ss0gfwLkK06m9EE8D3b4=; b=zGac2pd8l72az2JNpD354U4dMS2OuHEooZAYIlAdjG3AjhE0QuOXe81K5cB4dQaOedraM5Rz9hRW3PocKqsKmS1Kovk6KaeEgneCfUyBNTSXY3jMzZVZdwqmMua4vuq1XOiILa0PeX4A+tHi+hEU3IMtf6YCKoh5k2tsEt5hn6c= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=brijesh.singh@amd.com; Received: from [127.0.1.1] (165.204.77.1) by BLUPR12MB0659.namprd12.prod.outlook.com (10.163.217.29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.721.10; Mon, 14 Nov 2016 22:15:55 +0000 Subject: [PATCH v1 2/3] kvm: svm: Add kvm_fast_pio_in support From: Brijesh Singh To: CC: , , , , , , , , , , Date: Mon, 14 Nov 2016 17:15:51 -0500 Message-ID: <147916175150.16347.2494044229416144843.stgit@brijesh-build-machine> In-Reply-To: <147916172660.16347.15695649975899246333.stgit@brijesh-build-machine> References: <147916172660.16347.15695649975899246333.stgit@brijesh-build-machine> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: DM5PR20CA0002.namprd20.prod.outlook.com (10.173.136.140) To BLUPR12MB0659.namprd12.prod.outlook.com (10.163.217.29) X-Microsoft-Exchange-Diagnostics: 1; BLUPR12MB0659; 2:qUGIxOjtVrnGxQlQswnbMG8gV4TqBihZOXNb65KOzIk2OLbmBm2WIGodEAH08CAx2T96PPOgL+MgrjEFujzsG5kvMS2wacCMsY95cTlYvb6SiYVrwKuGGJ6k0MZXlBkBryvPxxas3cW1wKP7A+i7ssdm/SjQjDL/tewwZ48BHqU=; 3:2nxPmdFKUcV2Gf5szHYCRbIuvdmoaxGwxdsHGQjCv0F0OWDVLGXTislNFny/oMgBevDG6zKLEOqKvF5s+8QaQIWw9NGbTkS97IcKp0i0oqVdoFTAmGnix4VWS7PxShThOTeQzC76ErzhZIxZvHAErq/WVk5Hfj3EmOaOXyxUR6Y= X-MS-Office365-Filtering-Correlation-Id: 9c115d9c-28c0-4c61-3e71-08d40cdbce37 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001); SRVR:BLUPR12MB0659; X-Microsoft-Exchange-Diagnostics: 1; BLUPR12MB0659; 25:M/B0td+aelEqlsin2qggEESt8fOe7jW7cziJiueRhKHwWf/fimN+wZhAPDaqqRKSz7L8HOagZ6DcUdxNvlx0Y0QytoIkhq2DvWMp7Yecild1WSKCUwj6XIXgL4QomQ+AsepqVUZ9kkwhgjQWsCTHBrYSzMvIhFAoKEvjWu2Y50VvRlOiSMA3AI47HcGaJaSBzY22ZQiXGt0+cZ2GNqMLPQS4VowK58Ib148pGc+zSJDcISv0BL4y9oiuhbFrsL0Kst1p6w91eVBU9NY8ZnIM6bp9XUI7XJcl1gTD7S7JNSinJv5nuCBHI1CXMtGkn6gPu8ZLOt5FYqkkUC/MwPeIFy7keBwoHhptjl4Ish1qB2PpMzQ82LpF1yR4TnqAeb0a0R9RvaCcUlOA3DpAWt1uj8vxIPPdQolmRitpO43GAA1kKMb824+/10OolsnK4KqR57Qb/VfgafKHT4TX4Qn+aQx+SqzrA1mdTqVDsqyLtb+ekwtcvutZBu/llZDYxVVVOBBTQQJiZhAhs+E2KKbJVyM0O1AtNzjDI+lcCw7IzCu2ttckwVFpJEoiVSrWmNevxQypE++hyOy+fwwEBJ2VQEl29mwv+3aLHP9JJPc0UA23yZTUj6S1DxCpkaret3iHGJN5muPpUUJiy+PAy9XfhANLVT2LpneJY4n/T+Z97AsaZ+KecSKX8ouPjCI2z5Dnq0T7+IFFQtlW3hAt0RMZQTx2q1Yz7aWGFKZnbKu38cI= X-Microsoft-Exchange-Diagnostics: 1; BLUPR12MB0659; 31:QvCM7KYqB4BRAE0ARq/LMpf6XOzIAkA+6yvaIjib6o4GfU3+HeraSBBKy9G9HZMYQJcwl0I+HIwOTw69uRnC/sIIzmVNQhJehdd+yyrkmlVDRCVuwkxBDZzU4wKQX6Fj11ttgOEICovuAVyEcT5oKLKrYXSDp2vnwha9pmKOlqonOZPRRrvQPYULbFKzNLcPdou57h0MRHYtQr+EFpNYGlHloyAzvzdZOQiVs1Oajta86XYAcqbcA1nKq/SpG1eu; 20:D2CtXqGC/pSlO6uMuivWg4kKNRTisOpueRlj97hx0np0ngieBg308AeE8gnkpSQh/nC2N/UGO2HAnf7frCCec3eKQ1YSMAWv1M5dmyOuf7Paz//kGZoGxq7Syt229gOUH8S2f6ay0psEpdXLelY53+j0zCrXNyT5xVwRhv0l1sdOCxOLzFD8OY/UPVp79Z9ZyaqoKSyw8/PePE2JIqoVm6aLgtfBmTYyyr+AXakj+nM2xhxLdeQBRO6G8dex0Cr/p6FS6mffy8DjI7AIFKqm+Q6MaIe5Ls8YZLhHXq4cYFiml4rrKXQBn8jtSWdW1r/6Nr8UCaOUKbHzlYVLqXuC8qyO6zMlIwp0g4w7wC/FVI+CC+3fqLlhPESA6+HcVEMJ+7I27L57NjfBDju0WBZ9i92IEZr5SFXC0A3+eF+wsukOcJ3V0mLlWhjCPuqpO6V9/2Emud/nZEDXQZ0mPjbDYGtzSxLF0z400duUO4kLqkm37/JrthqdqMIJ8XEFQ1sQ X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6060326)(601004)(2401047)(5005006)(8121501046)(10201501046)(3002001)(6055026)(6061324); SRVR:BLUPR12MB0659; BCL:0; PCL:0; RULEID:; SRVR:BLUPR12MB0659; X-Microsoft-Exchange-Diagnostics: 1; BLUPR12MB0659; 4:kxVRo6xYCO5VSiVfTDRAM6DFQQCdFV3r2HSVTO1U97LBEyMWkYoU7E7W8SNCNrEcazyhXNgkzgghrefIqjaXjBu1cKi3KEPYOyw47oXO2aPcz2a7r6iHZYqKQwsFuITvH2kdwACzJ70lspaU6LoJgZ4+CW2is1+szm1DjjfyA1MJ6yi96IQHw9tUP0/MISq3w0ushw3FrU4FhnvN1wC2DbCGT3totyq6SD/FXPOoQE48T+PK8xcgovZJX9ymKNygYVN4stcWFWALsgImM6xsyQo7xJTmhhlqvtiGwy+mxkcN/USqDydIc6yrULiRbhkrGFqmuSq62RSAfVxADAvL8DHLV2UTquzSBE3TBQHCu0vX+/JBxuToT8L8g88tY25fzRTUzbgIO/kZn5Oy6RgqkYUvTFkVQCzqO3U0s6c9FKOYLeUr3sbABkTpHdgZCCsdqKvd7K0QhefBJ+WPHZ6brSTmQbXCGYwhlf1x4bXJue4= X-Forefront-PRVS: 0126A32F74 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6049001)(6009001)(7916002)(189002)(199003)(66066001)(2906002)(6116002)(47776003)(101416001)(7416002)(110136003)(2950100002)(6666003)(83506001)(6916009)(33716001)(77096005)(189998001)(81166006)(5660300001)(97736004)(81156014)(23676002)(4326007)(4001350100001)(105586002)(33646002)(7736002)(7846002)(2351001)(305945005)(54356999)(50986999)(76176999)(9686002)(50466002)(8676002)(68736007)(230700001)(92566002)(3846002)(42186005)(103116003)(106356001)(86362001); DIR:OUT; SFP:1101; SCL:1; SRVR:BLUPR12MB0659; H:[127.0.1.1]; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtCTFVQUjEyTUIwNjU5OzIzOlI3SWxzK3NpRWRvM0xXNGU2QVJOMGppNjR3?= =?utf-8?B?K2hPc0NTMzNYVWtwbWkxOG13UkNYTk5CTGhZZXRGNmw4WU9nK0liSVdvZnZE?= =?utf-8?B?ek5VUVAxaGNTeXRhWW80ZG56b2FIODBtVUJYK1d5MVBKZ3MwVUdMUWRKSnlY?= =?utf-8?B?YlVrQTh3RWxVTDhCNX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LLzSFCahSdTSUT3A/11+0gdcCKXM8Vt+boqJDtOPmDhzj/mLzbxNbOzTQDjyuHMJrFjp/4COumfVcOVOGS+koC4iZs+PFLKaOFANeBJ68dGZw==; 24:qEPgiV/2mmQcYz5A0GN8XsjcjNP/rodS9UytuZJKrRE3/EWyszAEWe0S6Z5p8XeYQrbVbV8cnE8t7kRAbMXu/PpHlzdiRnrAtcvbDtFrfI0= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; BLUPR12MB0659; 7:JDPdiiPYdJt5naUqUwAseqHHrCBfcFqnf7oGq2FRE6HLK+qgNQpOtA0+Ht7XXGdHyGGudSXik3g7numJ4POt0Gfmpvlx7JkFb29ML4lCwdr3pY9Z2gqnxvrdhnskB9Gos9Z7Al1L1iHZtQlKFmUXgRDUyRoW2CoaULTDW1/O4MNZEEIl/6hSGjwIMvvgS2moptXcqmZsVHAMuDPj1ioEw6Yy48n4qa5mAVyWyIKcaFnblFe6mQU0M8bAZJF7NnAUZO6+BsGaybGDFiFu3/8fycD1Mk71SPK3nASTFUwGn68kvYP7VDD13y3e19MeLr6rHqMZ1Bfx3FmtJbzXYQOmSqcjEzzx9relX/k2BpnbUOM=; 20:Gjaeqf5z6cpEelVcuXz6IvKAvYowX8VpI6YSu16lIzUsk9smw1YobYn2wWAfLKzjqZWSr+wM5/7QzB0bcGuWvxwTreMewARJe6EvXnpz5ki1W2ABVjx0VH1r/7nYsyL9QMnSkhLRElKJJhZSU2SzcEmy1cZoyTiUyF249Sl/zWnKKozNvlUUDjECowAHxVhmNHU9Cud7zSHG8q5P6cVBC9sZV/3kNLV6ZTHpILPbtiZ1TpuJAnDsb2tt8142CjY3 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Nov 2016 22:15:55.5343 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLUPR12MB0659 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Tom Lendacky Update the I/O interception support to add the kvm_fast_pio_in function to speed up the in instruction similar to the out instruction. Signed-off-by: Tom Lendacky Reviewed-by: Borislav Petkov Signed-off-by: Brijesh Singh --- arch/x86/include/asm/kvm_host.h | 1 + arch/x86/kvm/svm.c | 5 +++-- arch/x86/kvm/x86.c | 43 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 2 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index da07e17..77cb3f9 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1133,6 +1133,7 @@ int kvm_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr); struct x86_emulate_ctxt; int kvm_fast_pio_out(struct kvm_vcpu *vcpu, int size, unsigned short port); +int kvm_fast_pio_in(struct kvm_vcpu *vcpu, int size, unsigned short port); void kvm_emulate_cpuid(struct kvm_vcpu *vcpu); int kvm_emulate_halt(struct kvm_vcpu *vcpu); int kvm_vcpu_halt(struct kvm_vcpu *vcpu); diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c index 4e462bb..5e64e656 100644 --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c @@ -2270,7 +2270,7 @@ static int io_interception(struct vcpu_svm *svm) ++svm->vcpu.stat.io_exits; string = (io_info & SVM_IOIO_STR_MASK) != 0; in = (io_info & SVM_IOIO_TYPE_MASK) != 0; - if (string || in) + if (string) return emulate_instruction(vcpu, 0) == EMULATE_DONE; port = io_info >> 16; @@ -2278,7 +2278,8 @@ static int io_interception(struct vcpu_svm *svm) svm->next_rip = svm->vmcb->control.exit_info_2; skip_emulated_instruction(&svm->vcpu); - return kvm_fast_pio_out(vcpu, size, port); + return in ? kvm_fast_pio_in(vcpu, size, port) + : kvm_fast_pio_out(vcpu, size, port); } static int nmi_interception(struct vcpu_svm *svm) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 3017de0..d02aeff 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -5617,6 +5617,49 @@ int kvm_fast_pio_out(struct kvm_vcpu *vcpu, int size, unsigned short port) } EXPORT_SYMBOL_GPL(kvm_fast_pio_out); +static int complete_fast_pio_in(struct kvm_vcpu *vcpu) +{ + unsigned long val; + + /* We should only ever be called with arch.pio.count equal to 1 */ + BUG_ON(vcpu->arch.pio.count != 1); + + /* For size less than 4 we merge, else we zero extend */ + val = (vcpu->arch.pio.size < 4) ? kvm_register_read(vcpu, VCPU_REGS_RAX) + : 0; + + /* + * Since vcpu->arch.pio.count == 1 let emulator_pio_in_emulated perform + * the copy and tracing + */ + emulator_pio_in_emulated(&vcpu->arch.emulate_ctxt, vcpu->arch.pio.size, + vcpu->arch.pio.port, &val, 1); + kvm_register_write(vcpu, VCPU_REGS_RAX, val); + + return 1; +} + +int kvm_fast_pio_in(struct kvm_vcpu *vcpu, int size, unsigned short port) +{ + unsigned long val; + int ret; + + /* For size less than 4 we merge, else we zero extend */ + val = (size < 4) ? kvm_register_read(vcpu, VCPU_REGS_RAX) : 0; + + ret = emulator_pio_in_emulated(&vcpu->arch.emulate_ctxt, size, port, + &val, 1); + if (ret) { + kvm_register_write(vcpu, VCPU_REGS_RAX, val); + return ret; + } + + vcpu->arch.complete_userspace_io = complete_fast_pio_in; + + return 0; +} +EXPORT_SYMBOL_GPL(kvm_fast_pio_in); + static int kvmclock_cpu_down_prep(unsigned int cpu) { __this_cpu_write(cpu_tsc_khz, 0);