From patchwork Mon Nov 14 22:04:26 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brijesh Singh X-Patchwork-Id: 9428505 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 848F260471 for ; Mon, 14 Nov 2016 22:04:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8422628ACF for ; Mon, 14 Nov 2016 22:04:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7676328AD2; Mon, 14 Nov 2016 22:04:41 +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 11B1128ACF for ; Mon, 14 Nov 2016 22:04:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S938789AbcKNWEg (ORCPT ); Mon, 14 Nov 2016 17:04:36 -0500 Received: from mail-bn3nam01on0067.outbound.protection.outlook.com ([104.47.33.67]:20054 "EHLO NAM01-BN3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932462AbcKNWEe (ORCPT ); Mon, 14 Nov 2016 17:04:34 -0500 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=AhIZ6PP/bTpTCmZihrr+sTLsnrPTS0A9/GlAq8SwKwiw1xgp1q3xeLfhvzLk8EJUYE6hkUaZG/sJiwCOuift+Nq2Yo/x7pbT6Ja8FX06YUdNJop72XEg79WxNuElsxXzp563urGBhDvT+zJN6H7uZ7/UyJZBE7p5hxL2Nfg+XHc= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=brijesh.singh@amd.com; Received: from [127.0.1.1] (165.204.77.1) by CY1PR12MB0665.namprd12.prod.outlook.com (10.163.238.150) 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:04:30 +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:04:26 -0500 Message-ID: <147916106624.15984.11121403315647871630.stgit@brijesh-build-machine> In-Reply-To: <147916104306.15984.5798892367621710557.stgit@brijesh-build-machine> References: <147916104306.15984.5798892367621710557.stgit@brijesh-build-machine> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: MWHPR21CA0001.namprd21.prod.outlook.com (10.173.47.11) To CY1PR12MB0665.namprd12.prod.outlook.com (10.163.238.150) X-Microsoft-Exchange-Diagnostics: 1; CY1PR12MB0665; 2:gNDRT0TYPk0IZyQLxO9wv9oiz3twH9mul/IxnBcPCQ3gtnDpc/Sf/U58z0POLNs8jrw9Dw+zCZdke2xAuG6fB2RX5r2tfpNQtvUdwU/B25pkK7mIwnPsawFk/RpzBRe6i836yjRld9KA2NhYiZPJuCmohFkBq6MzblXtG+IG4d0=; 3:zXOZ5hN/3JoWJ0XXb72kNp+3mpNWAdWScy1Wa83LyCyMaBx0qabpZshGeDxWKNDtbHCajJfTbZgSDe/R5tFACVypct8cejMdvP+pUjdgPpoqXRUskIu5xjK/F8YKQbY/szbJdBgcwlqGOUZVo9VIdhN7lH6jdAWUx88JptJ11MQ=; 25:Z77+48cM2/tpsLAIFqcda8X/CSLvD5+97cchTDm8gGg1fxamKGvsmHTOdqIBUm60iALQq48Pj0YcMDcyNTthels/g7z7xdjtB0+irEyXaTSbdMbpD3E7ree4yMk9NlKlnswyM4vSGrBISM49pSbAXVCK+O6cDPa+AWYxbsoa4BOwLG5lJJq85qj4xSo0qla5MSFRTzjl2+hkmqI8BA9Qmrt4vUoavN2HehzUMTa6TPJxjTIS0WIueW2Ar2DARR+U4Tm2061vBnsBR/uJIuAmGy0ukJjEUiqimkgCib1S2vK9dN1dqf5JaGhlBCVpUipteXSsmonI8NO8a1n3xgcMGs/SjaX18meZ/UOHRv2L54aoTcjxTJ7kmg6WSYCyzuAtuh6Ai5Q7JIZL3InuiohQ6q/jpMNI3mwHptNOGXEeeQ+LHOFLdv41DJkk6irE9EA0 X-MS-Office365-Filtering-Correlation-Id: 5c54bf79-bc9e-4c18-a813-08d40cda35eb X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001); SRVR:CY1PR12MB0665; X-Microsoft-Exchange-Diagnostics: 1; CY1PR12MB0665; 31:VnbpJUBAtS9QZFTwcvn/6mww9g5zBXkAw9Y9n/NQT1KLrDJszmbnB5j0VCzfnZ3YwRA7qqNzuh4aXs7vhCGy51Sp2YsRuKMNb1CAtIv3QzeVCmFfvAjAZ9kL5o2ixG2x3Z5XqnrdDzr9zgawGuGJ/rcElNrISgAhnGRVko7Hubocg4oxjTa9MUB5pDPZ1kjrTyBfqc6ZkSTo6r7stFX8G1HX3ONsbaCmyDHbQ1UP1gZr3pTAlKfF2vwVuXhS8jYbxlI+0yuYj4Q888mWbDZxsw==; 20:19R7vVqiFRw7YTUyi/PUuNtEycNMcQlBxvgnIwY4Pbte3PGm84X2S5d7/CyCwpMeup52AeZgRJmLpf27KyLBssF9o9anlF+UAph492b17FEnE1HIdJTjRlFgCcpJv88JS5qLQS9QpzcN4/vZPcZBNH8W3aZ/ZSZ+cUs+2jwG4XelAzgMhKi2NnabZBl2htzSRiXquxbb2rdp2SAiClbwQIvox6X/LJwQYLTEypidKMsnyv8w71X2yNLvYSj62KcQB6GV156jIynABl8yXzvr6e8sbhiV3VBk0gzBKFEaGf1wes6kAbjKN4apC5kYR7wk7MJuXgfdmlyV1l1k45Uux5BPZLTn2X9GRCY8pWUA6VAksS12KYAvTm0/gthHqrNXU849vGyC2K58U9ZS0tEbdqnwc/F0ibVCGSTWYCZ+rYuMz6wg4NQvDknWpotAE0lnYn20iSTgfS4KV8oq1LVXgi84CArqPCdtdotoZ4gmH1LFj6gNHCaCGzKip2KX61tX 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)(8121501046)(5005006)(3002001)(10201501046)(6055026)(6061324); SRVR:CY1PR12MB0665; BCL:0; PCL:0; RULEID:; SRVR:CY1PR12MB0665; X-Microsoft-Exchange-Diagnostics: 1; CY1PR12MB0665; 4:+TZ6u3e3kYb4OXDKthtGE+Rhq1Sp1+Rtd6LxmAtfNDfYgQtunclDYKuEDzDs+1CQ3pVPCWwP2lQhswRQ6ivAoSfmmjOjdJYw/Sxb9MEFShFZBeD/QeGM/mS0mS65bw59NnG9ULb7lHqbE2VXXOBnL16NZqU5l6+HCz6gDJ6BEGNIlDJDzSZw927buYbsFF8NnFn31dA1x9pQuhX3p4HFk+sxd/mKmUJVNSWP8lKPCMN2AioNm6GCa3efOxVU+27xc+o7s8nGQbMf48WzPiMP6viAGb6XdvpOITCQFbGhdLlopl0o/Exb15sD9MlzQ1H+k+Euot9rMyUcpunpiQfeL9WBJyGyUg6HhvKnMPr4U/EBP/sJ7bN6SqUA9KB9O9IDVXtGYnCb/17Zomyjam4jVvwVDuAoQo/xDJGjckf1ng1EdjIAWtL0svHhiYJ9v8Z1/3VG2DsYwn2e6V8Jhm/aIav5tQVaEPKkSduBy5tVii4= X-Forefront-PRVS: 0126A32F74 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6009001)(6049001)(7916002)(189002)(199003)(9686002)(23676002)(110136003)(83506001)(103116003)(3846002)(97736004)(33716001)(4326007)(42186005)(4001350100001)(6916009)(2906002)(6116002)(2950100002)(7736002)(7846002)(230700001)(305945005)(68736007)(66066001)(47776003)(6666003)(33646002)(77096005)(8676002)(81156014)(50986999)(50466002)(5660300001)(76176999)(54356999)(189998001)(2351001)(105586002)(101416001)(81166006)(92566002)(106356001)(86362001); DIR:OUT; SFP:1101; SCL:1; SRVR:CY1PR12MB0665; 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?MTtDWTFQUjEyTUIwNjY1OzIzOktrRm1LTXZmbGtHVnJPUzQ3WVhTMnJqSVcr?= =?utf-8?B?aEZFUlhielhpL1lEQVZDQmJTcHEwMWFXYXkyelBqN3RaT0JEb3BJWkxnUFl6?= =?utf-8?B?UWkyTFNCMGhWUjZxSWpoZTZPVTBGeUsxeTZtTTJRYVQ4dzRmRTRQbldHQVZn?= =?utf-8?B?S3IydG9kNHRNWGtvNUQxYW8zOHl5QzJWYVhUK0c1SkxEL1pCYW1jSVE4VHBQ?= =?utf-8?B?cVV2dUswdWRhWVA2ZnN6MmF0OU9TUmNtTmk2YVMyZDh5Ri9oQnFHN1l6MGdx?= =?utf-8?B?OWFOV0VDclkzd0hSWEpoYW5hemRpUjlkQVB3TTZ4dE5EUlB0Y0ZlT2UrMzl0?= =?utf-8?B?bGZRT0dzSUlrMi81TmFnQ2x5dGtXN1lMT1p6NmlxWWVKNUFrRUJXeVpyaUxq?= =?utf-8?B?bmlnUFRVUEJzQ3M4b2JSVEZkYitQWXh0VmxEQ2lOTTV1V04wNmY0clVKcVov?= =?utf-8?B?WjF4SzlTeGN3ZXlRVWt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RqpMDz4rJFD/QoOwP71RS+9RptppImfjnDO4wpPbBLAO/ES0jTKYkr/vgx208kqDSGsAdc7EKycbPfnzR9hhqF2BYKGIbaeOXrbwKIf+Dhb/JyOWzGRCfdqWI/sW0rl4sbrt4yncBetPCr3VCEISYKQR+85duSFoIbcZGtzEIfN97X3YR/ihK60VX6plbjWX5tzr0H9qs4NilCrMqSTyH0CoWRQlDqE+6YEEP+l9a4WBP4Dj6+3Um4U=; 20:orikwsQ86fo6A1K790+v7UXMzmqGxPOkcG7VS14ixclHjUuxbCrVSbN6v6EA3xccHrgixb5MajwDnzMF9Md/m68X05YRdq1WDTpq39mi3Jl9mhwcnuyA9WjEIhWl4QpRXyiDe4Y2X5wp0rgQMW6p5wrJADY5QQTpxvZefEC3WR+cSoCt22BFgYsrf+GJb9LsJSHd/29JypVaV6uh905EYCjaW498WVi7GkDdrxu5yjtqIJg/ViznI5JquzGgM38B X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Nov 2016 22:04:30.4796 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR12MB0665 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);