From patchwork Mon Aug 22 23:23:54 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brijesh Singh X-Patchwork-Id: 9294759 X-Patchwork-Delegate: herbert@gondor.apana.org.au 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 5A52C607FF for ; Mon, 22 Aug 2016 23:57:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4A62A288C3 for ; Mon, 22 Aug 2016 23:57:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3E36228A54; Mon, 22 Aug 2016 23:57:11 +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=ham 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 9A165288C3 for ; Mon, 22 Aug 2016 23:57:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754094AbcHVX5J (ORCPT ); Mon, 22 Aug 2016 19:57:09 -0400 Received: from mail-by2nam03on0084.outbound.protection.outlook.com ([104.47.42.84]:61955 "EHLO NAM03-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753407AbcHVX5G (ORCPT ); Mon, 22 Aug 2016 19:57:06 -0400 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=z1b4dSqKifj8UoSsKwrT9u6L5F/861tMKErunNGks0w=; b=lbnVcArjflvjECsFIfgjMbBONfDvixOqwVjFEMIcGCPFkswWQpGTdW5kgKCmC2JxAp0JnoGUj6eiITOcEn/ctQopYrl42JF8W1Fg2ioeT7Gf1Rn6CjhYadfXRuaxBpR0lvhr5J1laAqKmH+M7sq5oLrYt0v9cZonY27Rzmek5iE= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=brijesh.singh@amd.com; Received: from [127.0.1.1] (165.204.77.1) by BLUPR12MB0660.namprd12.prod.outlook.com (10.163.217.30) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA_P384) id 15.1.587.9; Mon, 22 Aug 2016 23:23:59 +0000 Subject: [RFC PATCH v1 02/28] kvm: svm: Add kvm_fast_pio_in support From: Brijesh Singh To: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Date: Mon, 22 Aug 2016 19:23:54 -0400 Message-ID: <147190823395.9523.16184607551630730040.stgit@brijesh-build-machine> In-Reply-To: <147190820782.9523.4967724730957229273.stgit@brijesh-build-machine> References: <147190820782.9523.4967724730957229273.stgit@brijesh-build-machine> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: BLUPR0401CA0029.namprd04.prod.outlook.com (10.162.114.167) To BLUPR12MB0660.namprd12.prod.outlook.com (10.163.217.30) X-MS-Office365-Filtering-Correlation-Id: da80ef9d-a8ba-4d97-a50d-08d3cae36674 X-Microsoft-Exchange-Diagnostics: 1; BLUPR12MB0660; 2:14LnBrNfiyyB4HsgEkkZlQFHUXdlmff08n0Ejg1mX/QLBfkLUOSPmjfic7oG4q74OWC0ak8vERopgo6FqQJWNRARMwrudNEL/M/OLAnH8ExPg25dpqhFuwskjz74n4LNntjYuT8yp64vDpHuCbf4QTC4rEFrJ2FZp1jG+Ox7gii7YTo0jGpb4jTZzVnntuk/; 3:nseotykk2nYQsX3WgJ8Cr46E9BvMRvc9ugPx+K1nJ1H/Z+qqVcE5q5KVAeNxIV03hkLMFDcPtrWma2lwCeQVkzNewb7R4ukv34r45jzDOWi/dGbDKRa8Wd9Lu43k2VlF; 25:oprq4GOosQyuR6XLxy0yuQ9gT5lgQcUXaY7Qm1R1Eg/CWJ8YtNDtQeP5M5+ls1GL/GStdabdC1X1RA+8yxdXaVo2HFAxdkKHKcDnszb2xGvLG4DPE7wFTHvUKSKieXjZhofJ3sa5x9aq9bmYsEv11/kUZEZUncBpvJz73P0WiGnpq8QH0BEaDTPvgc6xGzrpqcO+LGcGMLk/KNHIGhw6wsMN8cntrx3T01plYIQKDsDWNWwVSmEsehLSkcb1/TUfkcrmYnea0rCaJF61TnngXkblOL0Iy79l79t5D56gHBmHYGTk5ru5AzPX2GfqzPIBHWmRWY7udC1ssuVPidVhvtesvM+UDTH3u7pZKusdNYl0bRLGSGhe8pzXk6q6Vm+oEzswI7FBB5yHWIxw5hJVOV5YnuvdsTptrO2foFOa0CU= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BLUPR12MB0660; X-Microsoft-Exchange-Diagnostics: 1; BLUPR12MB0660; 31:to20OG1GsMQfttKN+raruWwqJtjU4MGOBjviarrFdKyw20ozCy2AHCuit3qN196H6614yrkXHBcCmdQPn3jJ261UqCYPjHGl8dsxGg64hVK9jZixJGuqurBCY5nogiwH89gbnRQ0uzSCV+EUdfZqVPY9NAv1kqm5wgj/GIoR6455KC544ujd76f49L5WpbCoWP9shy+3mfnnbNQhmm2d5flCxmrMufw67Y/VcdvfUig=; 20:KY65OhPeCFeKwcHOjFo9ThJwhHzacr3p+qUg64vCKuFoHY2Slbz4rQECfSY9kBownAGn7C4i9vcSN2xb0f9BQJR+aqe0UORqy0Iye6wqWTdpUim/pZz/+gv02SurQVUC57HrnYdlPjucrB5JyPl77tsgndtVv2TYr9x0bme8JIPTmro7ixMjeymu/8SlvuwcEhNEjWQjxAcXtiPSha2McMRqQkByRUyxHhWvz0BzuekG+JcQbcY3E39/mSS2/DLzsUjwKbOYpTaso7Ul5VgiQT+SoEwA7vlErVuswVFPEwnNOCH/8RGE/Px8zYx9eQjikzMxa5iLUx48kxNzfeviNiI2cV/S2OgNJBsgH8i41Jo7xDyHRAZH09AtjHHPFp/qpnL0J0jWKhLTH/HeE5WyautTjwRfiI1NxZVmDazEdwnBp8KRKwMsLVU9JVNYUg65HCJJbrGRz6OLJ5oR9sbVVhHLncC9Ssr6DRE0wbsHAbE6L6gYBGOWfNQABbxJEK/A X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040176)(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046)(6055026); SRVR:BLUPR12MB0660; BCL:0; PCL:0; RULEID:; SRVR:BLUPR12MB0660; X-Microsoft-Exchange-Diagnostics: 1; BLUPR12MB0660; 4:lhw9RpHjB/tdZN7ffGokmLKEahWxNZRu2EeQM4gwjuXuIbzUoAF6AxxfuB+9zGYEoXUN8pc4VbQIdneWzL5P/5lk8+QUVx5Zc0xZpaL0estU4ruc13vjZhS9xD2sDUTUpUM00EEDFw75uWUb74oXl2hmCRQNeO5tr//hsxqsCf1rTU0t/swKbERRVyxMqbX+g3BD5RhYs7dqwRFsxl8VvXH1QO+/U0rMap8OU1R+W9lISoHYQM2hhvjMWQ9Z84PBtYajZiWZpmS5Frmk4ryJmZQ1gzDulYrqKhNRksDMDFxkPLKh1gx9sVTWt1GLhWqSQQ5R+ZcOvgI3JPqddHTK0v7ZcgvhKqh8Dcb8dPj1mWo3fOhANbnmac/54uhWD58tdGqNP+qflFdCg7ziNkROW9GIZcrPZ8v8LAQgKajmB3b0Q7zY0uJ9ma8o+abppxVu X-Forefront-PRVS: 00429279BA X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6009001)(6049001)(7916002)(199003)(189002)(7406005)(7416002)(42186005)(47776003)(106356001)(19580395003)(97736004)(5001770100001)(23676002)(92566002)(4001350100001)(2950100001)(77096005)(8676002)(33646002)(81156014)(81166006)(2201001)(68736007)(586003)(83506001)(19580405001)(229853001)(86362001)(189998001)(50466002)(107886002)(2906002)(66066001)(9686002)(6116002)(54356999)(7736002)(105586002)(76176999)(3846002)(101416001)(230700001)(305945005)(33716001)(50986999)(5660300001)(103116003)(7846002)(921003)(83996005)(2101003)(217873001)(1121003); DIR:OUT; SFP:1101; SCL:1; SRVR:BLUPR12MB0660; H:[127.0.1.1]; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtCTFVQUjEyTUIwNjYwOzIzOnI5NFMvbHVsV2xWZnM3NmFUYjBsVnpkOVNT?= =?utf-8?B?UXhNVitpTkFIdjZDMnNWTkRTbnlXdUhvSWlKOWZDdDk0ZEIxUnhmSE5VUE5H?= =?utf-8?B?bGdZaTNPbXVTaFRnK0Q2eUgrZDhnbXlFWVFWalBXaXBGOWEvaG9TTm15aDlW?= =?utf-8?B?OS9YR3QwUVN2QU56WUJVaGFMZGRaS3pCQ29reUZZUzFhNjBOSXdUQTdISkRm?= =?utf-8?B?YzM1c2hsWmR6cGloWWFVTjRtRWtoZGFLTFRsQmV5MVNaYm9nWGpPeGF4N0c3?= =?utf-8?B?ZzBZSnBydTZiNE9MdzhoakJBeml1djNqbVluRXIwT2tmN01qeURUck1waU85?= =?utf-8?B?aWNIT0xyTlFUYVdWS1R2WkE2SHR6SGhSeWtPL3IyU2RKSlZtVThrenF6ZXcz?= =?utf-8?B?aWp2eEozNUlFdWExODNuTEVCdVZzVnJhQWhsSWptQ1hNSFYxaUtmd2tzb3Nk?= =?utf-8?B?bDN1YVl4VXhFV2RrNFAyN3o3cHkreFpub3ZOaDY5QXNlVXZHcTFmUHRONXdw?= =?utf-8?B?YXRNOFdUT1dVYl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pJIdGY2RUs+bJM=; 7:dsqZixSZ3aXklVhyikJrDRZugmTl91G2HtTxCnGLa0D2UNfZpLG0yDqgXrN8dGLdirakTuu+vpprsppBWaxM6PaqYT5br91uHs5kNwOKpShGLdbpJ6Oa6uto5M7ojKCKqxBCYH4NGMvYO7++zqa5rlpMMbTRkokRr+cwmp9bbSKID0hug6I0LgaNiIbfEv7tYumRKIkjwuqxB14Pza6WAN2mFmx0mYvH/i5740KYz68KBAmsqCTRNiTNvYlivPNH SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; BLUPR12MB0660; 20:VSan+yzEsr/2Jw+7/+1VtWrKL2/5BYDp8OCJbnZhgowb6gTfHOprKCgSv/BIZVguRajf4T1lrX94+hmeYNrapGWhk7fQSKXIXxkIWeJ2K0YAx8KIcAC2Rip5bY3vzq58We5wHsQSBZ1YlD2IYet5QNFBkW/Tu7poU/NHe04DHk/QFjqwnz/75dE9OmcCbFbSU5HxVK7t3ewXgnka4JyO1PsAj6PwBfV9B/fhe/9j1oEH1xxID6rZCFrkfERlJ1ap X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Aug 2016 23:23:59.5221 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLUPR12MB0660 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@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 --- 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 linux-crypto" 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 3f05d36..c38f878 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 d8b9c8c..fd5a9a8 100644 --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c @@ -2131,7 +2131,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; @@ -2139,7 +2139,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 d432894..78295b0 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -5579,6 +5579,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);