Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S938728AbcKWRfH (ORCPT ); Wed, 23 Nov 2016 12:35:07 -0500 Received: from mail-by2nam01on0083.outbound.protection.outlook.com ([104.47.34.83]:33143 "EHLO NAM01-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S934902AbcKWRfF (ORCPT ); Wed, 23 Nov 2016 12:35:05 -0500 X-Greylist: delayed 1988 seconds by postgrey-1.27 at vger.kernel.org; Wed, 23 Nov 2016 12:35:04 EST Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=brijesh.singh@amd.com; Subject: [PATCH v2 2/3] kvm: svm: Add kvm_fast_pio_in support From: Brijesh Singh To: CC: , , , , , , , , , Date: Wed, 23 Nov 2016 12:01:50 -0500 Message-ID: <147992051077.27638.10638232569505545101.stgit@brijesh-build-machine> In-Reply-To: <147992048887.27638.17559991037474542240.stgit@brijesh-build-machine> References: <147992048887.27638.17559991037474542240.stgit@brijesh-build-machine> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: DM5PR12CA0064.namprd12.prod.outlook.com (10.175.83.154) To CY1PR12MB0665.namprd12.prod.outlook.com (10.163.238.150) X-Microsoft-Exchange-Diagnostics: 1;CY1PR12MB0665;2:VXrmT3EDAyJzdtG+r/mNriRfKyev01AxuW85DYPbEXAXF8aubwswVpvkC3D1g19WMuqHc1I0JFCgZ39GAekxN07L9gfxvLu0CPwyj5pUsI7bu0tiXEhxX9X4sLP3Ykp4iqgXYD8rpRE0crzjW9iNQiIgpKps4xkvkqc1kybDlgo=;3:3rzmroq6xjESoc94edoxHKy1W/Lse5TaDlzUbYZx/WN/rBpaTfiNr6IgPPSpvlOeDsqZVEhnGDSIxmgKFydvByQv8daIjygkTpN2Eg5MrXOKcH2IOXOHG4C01mjg11uhNyc9CXqLiXM2gweuKgeOOvHKrx2jXQV2aOLhRGvFq5I=;25:LmV2gr49KPaa5Gzu2WXp33thTPhuG5lsvHNzmMub+ooklWFQyZpiSCDK/2H4aOObMWqvQSKuCsH0FMjZw2NW4pE+zbEUUFeU8rt/ie7JyCg4BqeRLicDoy000zJhk4EgKh16QdPif0d+5en4D8qa3qqSavzz1H9keWQ7U4RAf7/xY7+xG8ugcba29QnnFH9Qr7QFuEUSCnh9Ez00WZLmmS8ZSgY+g9tGqLP35Wqolrli5SZQxOy9i6CnAbLLC6beQFibXFkwkBHWbiD36oz1xcjeLfn3/GTwCL3Mu1Mea3QpeQJIimyyAV6UXAlttghdUs0JjhR0V074POqnFEgQLLQ/6hdFdK9bX2VcSjofo7AuLl0GDPdqSReTzQsVehRiqCS1WRHrISacI4vqGIKORhfYPiaZXXSDj+uJuzXF3FMjFXvheKb1jcXsG/MTRGHDMyN1ZslfOtMbKCTe2S6GJg== X-MS-Office365-Filtering-Correlation-Id: 632ce6cf-1bf6-42e3-af71-08d413c26d70 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001);SRVR:CY1PR12MB0665; X-Microsoft-Exchange-Diagnostics: 1;CY1PR12MB0665;31:J5Hd0Gs6ZomCnv2N8S/4C0CMh0CkdCUM6UWSD4RAINWALH91yLyF+tbb4e6Sl7uzoPIAlhscui0olGWWSzEIDUXPYLf82cHItZ7xBg5/7XwKFdFu/Y9zeeGuWrNuqbn18icilWXcz3953mF+fNw4Dp7P/Sv5uJPytLdCdPBlwNILf3qqjxKLTz6+GB1jViugfWbshNmpva/lq0XDrWaSdzbIz3d9VuudEiduN64UOnAAmrevBXZ0fpsaHws103q4DhbepY+5mpcH4VnRhsRJki+hb7Wsffs9bGlb9MMhFOk=;20:K2xGOywqdLOijALzySTTPpTCWtDRyywkiPnsA0/sEJdcbhMUVvA5aKo+jcMgbO+1N9H2aAO8i+t5S4ltmT6qe+3I0RuStJDgwdbvNIG3aGMt6zBRnTZ7dyVFoVikXWpFeUkjnO9zFnhuh/Wlm5OvGA+6ArgTy+GsltXNQuPyIqF/P9HixIwNAn45Agidf3bygAOJD73sC+uk2uXfi/xAk0KV/MNw2SNCF8C1XbsrOh8JuektTzcK2wYm/iSesrQcN5wx0DYEsVkvwcSmSIS4fgLOT9Prob2r/y8kRxEGoUsT06nWO6lBIjMXSXB5JyCycQCsoa9YCUSyZdBYeUF18Nq+dDMktWGtRmnsLnW7CV7gW+6o+uyT8QOEsX4rAFc7mvCNaRZn14M90tmgr4zM/Xdz7oYQApC/h4seLWZQsoLIhoBfD8v3+P3Oo2HloOCDheBozVbh7lkhGVzbTJD1aQ9fL703dOnYpAL0/HRkb27lktWj95QR9J/hnExFJhFT X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6060326)(6040307)(6045199)(601004)(2401047)(8121501046)(5005006)(3002001)(10201501046)(6055026)(6041248)(6061324);SRVR:CY1PR12MB0665;BCL:0;PCL:0;RULEID:;SRVR:CY1PR12MB0665; X-Microsoft-Exchange-Diagnostics: 1;CY1PR12MB0665;4:5NY4upz+mbhhALQuefe0pAK79V0neVCERgY44Xj8CW0532C8mFzcfZcvQOE0u7do3tmzK+Fr7Omz6nOuNrIaPXKHE4kHb5CEFjHTEu7r7grXU3y10R3Fb6ufwLXoE+bxSJV5+8m67H0v1EaALAV4lcl2n2aRLJ3XbuvlvLzEI8ioPrKGBirkTetubN//w1hAgNa5q6w1vX1HXS/ePbefCSLPIu1DiyD28j8jbY+1+Q9VQAur/odtZCi69aMz9RUUGCVx+dsyL+2x8VNTQQzX+GILq7HjErV17UwaoviDsbJYAEq7+8fIs8KTp30zWmsWjMsZYDoHfw3XqxQqAF6PXTBeW8aAYZ0la8tqaTWmY4kae6VelIaxX+fTJ7Gxd/a88ntwb1f7w9Ik2Fb7lQsWSuFK4S5U6eSfZz5eX3eS4+nPK/7rdT+PVr3EC3Ty8IRA5qygU0M/B0aU0jONh3IH/i+15sMKx1bpWmttKMhHu+ncupTn0hrVbhaQ5T1QskHpzWXvHqnM33tEFgVJyZS3Mx6DNk1Mkvw7bPzVJBh7CtI= X-Forefront-PRVS: 013568035E X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(4630300001)(6009001)(6049001)(7916002)(199003)(189002)(23676002)(6916009)(110136003)(77096005)(2950100002)(6116002)(92566002)(83506001)(6666003)(3846002)(86362001)(4001350100001)(5660300001)(97736004)(189998001)(7416002)(8676002)(2906002)(7736002)(33716001)(38730400001)(76176999)(50986999)(54356999)(305945005)(50466002)(103116003)(81166006)(105586002)(4326007)(230700001)(2351001)(101416001)(106356001)(33646002)(81156014)(9686002)(42186005)(47776003)(66066001)(68736007)(7846002);DIR:OUT;SFP:1101;SCL:1;SRVR:CY1PR12MB0665;H:[127.0.1.1];FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtDWTFQUjEyTUIwNjY1OzIzOitNVnBYZytpMDRjRFdzR2lxaVVjdlY4S2I3?= =?utf-8?B?b2tjU3h2c2dQZFlxaHRhWnhRMXJMcThXV1labDRBenV0c01CcmZjZ0dpa0ZN?= =?utf-8?B?MVRjc2Yzek9kL3ZFVFhSL05NdTlRWXNZRTdEaGVBSXU5dG4zaVJiNnBISFk0?= =?utf-8?B?aWxEYWoyZzc1Si9ucHZaTjNmejVrN2UwQ2Z0TnBmUkZQRjBibWhNMkdwcTNF?= =?utf-8?B?Vzg1UVE0QmZxekVKUVFmSVpqQnBaU3RTY3RJNFFxdGVDVWlzQkwxdGxTMGtG?= =?utf-8?B?SDJveU16UmsvRC9ESm9aemd1WnJjN0l0cmJiSnNmVjQvUlZ1Qm9jdDBxdS8z?= =?utf-8?B?RXQxbTZjVjNKZEdIWW0wV21ZMFVlZVRWN1VMLzhEY00vakxkeTd0QUhpc0JF?= =?utf-8?B?ckd4akYwd01CNVVSNWNJeW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m1iL3I4YUFoeXZVU01IdUdzWldQRnF0RTM2NTZuc3JTczNlNUxXRjkr?= =?utf-8?B?c3FoNEdqQWhJVGJKQklwS0ovRlNSSXliaExKVjJEa25xYmFSYldLSW11ZXA3?= =?utf-8?B?bUpheDlyUmUvYUxqZG0vd0tRN1FTWDlodld5WmZRRkM4akZVN3BNVkdrMGQv?= =?utf-8?B?RkdRbmphWFBhSXZxZytyTGEwVnNXSWdJUW9MTzVkR0lEcVhYWVRjcmZLQzZT?= =?utf-8?Q?sA7X9gkvl59bGDTM4dKdDHY/ftL0JpfxWhE2L1sxJ7cI=3D?= X-Microsoft-Exchange-Diagnostics: 1;CY1PR12MB0665;6:VO9CEWuX2xGlL0RD0p7vhXJ5ohTMt3pAe4j4CpYMPmKBSKOra84wx5i4gYeQ3vNnGzynThhsgXdLCK9QaDpM8ZgEDJZNfVRRp4gpN0KSYdmqdlVLsdneHq+lvlmrIEZyWIbbGiIRNpDwbBtAKmVVOQUMilaTFfnDn711QWwFhl7b47KUT+nujAHu7F6CUaIM8aDZ29Dcxu59if1XNESrja1rsMstdM1MRQVFYGm1FSLVaj89Via/b80raee05fahrHmCx0RFIn3QIbitb/Lr7qlKh1c+dI2F9plGTXKNFmrx3dSUe7Ae0SfUhj/p++3dc8RvZymQnHUg2+Rc/OQenENfmSZvBvDRMvDrZO5shJNWkwIdULnGBSiknjz5F6Xb;5:ZpOa2eh7ZIN6VTG5HZmLovOHw7yhN34as6sSkM9d1GiURmzSntFIfEUkTel5gb904u7iUI456CwHzPO49pa87I+bVCf77RkL1FhVTKKGXWqUPRKbsc2QRaM7W0N4YVlIBX3gzF4emwh5kTbCotMyKw==;24:1oBgwyOEZAHD1l1SKibeMgvkGVzkLMOheWlJ3xG2qUFUN0KPlMOIngU3iCbCsvkUFwMJ5ChAwWxONNf85G2LV3C0btbYIfxXfN0SeIY+4tw= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;CY1PR12MB0665;7:3JOPEPenhH6z1khmIXmpCykQTr8DJiOGZIkTFftW3VY+6S633S2DCCfQQmksKFHTqR0V0G3U/PDJj/Jga1McpSM5lbG8F6C+uborRH7+9Eeh1LMWwci/8u35Z2OCJgimAsS1vy98u61/suzjK2Vz9/rb4UxIaTHsNi5kMR5TsMYWVrgkT5n2kyIus397PF10VlxVh43XF8cy442f5eOa3NW9bIqfQGRArBz3IVFxyhlThjTYXuXZRuifBKIjwEh2LcwjEmf6oGtNX9eEmmtjgPw6qwv+zRb4yxqilZLbMQd9LeFoi/8rB5yenOMcRXLucgQubosvqMjbE+cOcdasq5ULHWqoHtK6jJpIoovhQpk=;20:Ji2nAxJT0Z+iYifXEIxuvnEif0XxHMV2QggT68w4SyGOpRb6e618pjzIMweegAhJQ9j4BIoYjGEatzoRd9AHqzc++FLO68XWaoUr/TDQM/1oPEhAAjySldXa5kM/Irs4wd5rgIDteDh3p5L8uXXCqRcO8POWcKuHPid4bMZEcm7pdAd4Ft3o3O/kpxpiR4IGKjhq9NgqARyc968aOV0eOEZWyaxs+A4AkihFqOkdTPqpInErcWX5oN6dRop+kgR0 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Nov 2016 17:01:54.1933 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR12MB0665 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3461 Lines: 103 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(-) 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 04c5d96..c30f62dc 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -5638,6 +5638,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);