From patchwork Wed May 4 19:09:47 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Suthikulpanit, Suravee" X-Patchwork-Id: 67169 Delivered-To: patch@linaro.org Received: by 10.140.92.199 with SMTP id b65csp357686qge; Wed, 4 May 2016 12:11:16 -0700 (PDT) X-Received: by 10.98.12.213 with SMTP id 82mr14355356pfm.90.1462389076068; Wed, 04 May 2016 12:11:16 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d10si6350056pav.185.2016.05.04.12.11.15; Wed, 04 May 2016 12:11:16 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@amdcloud.onmicrosoft.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755391AbcEDTLH (ORCPT + 29 others); Wed, 4 May 2016 15:11:07 -0400 Received: from mail-bn1bon0098.outbound.protection.outlook.com ([157.56.111.98]:47936 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752610AbcEDTLE (ORCPT ); Wed, 4 May 2016 15:11:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:To:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=brmhwu4Jggqqh/pmGZ9JogQjkQngGEkwjd1bupOXe+U=; b=UwV6Wzbq/cvQ5eiAmQj3ZtQpHAtOyO7Dq55mHJkK9TPQREXFGgx7dbYFxy++kn3noZV3MNP/kEij2jCVZ8IzYT9PvHA8LQgvGs0IfZmf7BCrEuNyfhVmnmLVTauqvQJ6S2/VYhMiSAbsbcMTcoT38Zm0ZBHcYge6pHOp6XC/yY8= Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none; redhat.com; dmarc=none action=none header.from=amd.com; Received: from ssuthiku-cz-dev.amd.com (165.204.77.1) by BLUPR12MB0433.namprd12.prod.outlook.com (10.162.92.139) with Microsoft SMTP Server (TLS) id 15.1.477.8; Wed, 4 May 2016 19:10:52 +0000 From: Suravee Suthikulpanit To: , , , , , CC: , , , , Suravee Suthikulpanit , Suravee Suthikulpanit Subject: [PART1 V5 08/13] svm: Add interrupt injection via AVIC Date: Wed, 4 May 2016 14:09:47 -0500 Message-ID: <1462388992-25242-9-git-send-email-Suravee.Suthikulpanit@amd.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1462388992-25242-1-git-send-email-Suravee.Suthikulpanit@amd.com> References: <1462388992-25242-1-git-send-email-Suravee.Suthikulpanit@amd.com> MIME-Version: 1.0 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: BY2PR21CA0014.namprd21.prod.outlook.com (10.162.74.152) To BLUPR12MB0433.namprd12.prod.outlook.com (10.162.92.139) X-MS-Office365-Filtering-Correlation-Id: cf1182f1-fbe4-49e1-545c-08d3744fd393 X-Microsoft-Exchange-Diagnostics: 1; BLUPR12MB0433; 2:U+u5MvETCJLimhCR+P+Ev72STBU2TX68Ygw1x1Tq3yrkA1+RFd2J1KBkBbmaLhlA7adHxNKjsFYlWvnEarsUSbsg6JUTBxdjZ0pIvum5UgoQP8dj1xkAv51wRk/UWMT6NxRYHS2zIqZC0VcAPqwuHzqutR5Zs2dQuyjUankZ8osxKf8A4C6uQrNzVWIf2wGT; 3:eqaxBAXIkCE/svsZpdaE8+5NkYKdtTlGuT7Et4rR46ZLX6rYN7jS+PbLpKel3iA8/Eo01+BAsk+Ggam1LMPUGZFpg9IoQq3RHZnbZwrw2hI470/8zVRyRPUdsOE71TME X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BLUPR12MB0433; X-Microsoft-Exchange-Diagnostics: 1; BLUPR12MB0433; 25:cMyI9xNZmeHCGkEvtFxy4rJAG20gqFd+JSIyCmY1ZuwmXRi8sYNv50WuwxPayv3noKW4syMhHj1jXAg/yAB0cS14tQrRA8CFdubpXTrpbutCf3ulcKISsO0aYOW2RTcciKX5U9QJpxLttFhvFrkixspJu10XTXQPIF87HXjZS1hcwP9tXRvbd0C+ovs+pgAwI4viHT07+ycrCN0ulDKkF3aKTRBh36y90ErRYkHaDRJE926Vlli6b2KpxRbkHtfo2LppQDSH0iymonG5xlBHoet4msp/OgAdvYc9X5RdD2mvavOmiLNJpaIti3AQegqXFFatwyiYB4C/mfJICS4LolbNj7eyZ10fk7sbLJlIOWL1eU49tx2VB+r0nsjzXkIbvVGwVYphQCOOiQBL775zNw0irtmWFVDLOOUl3rYUPEum24ZmskJ4Pbv5tKaGFNK4WyRzjTX3WlMvowUjAWTn02yqJKOSHsga0fppwvXN/APyN/MMcmKYZGvGDv4qPdwluvR5lv8jYU1iYkf+TboUsnYnCL5QgkKfq5nxUYJ+OSg85SvDu2/znt4kp5W9lqLU3OCe8kqk64c8DqOrvokF6XEQOm+qlTCyXbYeSPaJ41k965mKOt5f6DigBOK27cIseavq0W70MncP2KwBpi3iBtPsndgvuetPL1X6fMeGBtY= X-Microsoft-Exchange-Diagnostics: 1; BLUPR12MB0433; 20:t3NLZuLCklr8CshZzge+334jY71NL9r5ZxT/giFqDkYnCDnl9UOBjSfb1pufE0qzoB3Gw13QkkrugzJULIOfDZZJ0+IAqdLH25K//ARju3ooh7yeYHkQFx4u6zdsI+Sa/sPkyHDCExkaT6HH6XrKByxHSOVvYgEZTgsmNaloKIX2JSntMCzRdr3Tlv9yRTubGdw/mdTewa/NYvUJ8TbDqnUQzbAxzpMFqWtUdM5OEKlxP6cWL/TooQauZ9FW9Jv68/H3LpdQ0D2hJMpBofSckKqW9LPK3TijCEI7S3QZPmVXiL4Wy3/r+CaGJd8KNWbqrVBjyxd0tHF+7Zo6/gZRp2Xe4jM4sMDxlwAm04fwFCMHGMV5/FXxSZlajZB2MEemDiNo45sgH+39i07jTWwU8A+myym0Wym4Ih2vUR5SlGyQ098l6o8SdnSj7tCfW/3k6Ha7Sk9wOnk0utAg+bwQUE0wcA8rg8Sws1mkW67YXQX7EiFtxpPbmOu/Ydnu5qZ+; 4:yKl48l3QsBu27XwR/Re5dycxUghqypvWTViUgDRdf2HP36tMPw35sxLPl9nbIMN6Mak4njKwsUMVpjTLQPUgA2iNFIkHZrfZGTJ+1o4sJ0axQ2sY87HBZy8tUUMBcFXADsDoZViJvfipjhsGWL5VkTx9vxgYS1dMzOZrIbNmxvE30bE2jT/Pl2TgRHOuJ9qZGvTbXtAoCAnHfxfeL+CUq36cvWByD+vE2WYGbG0CFbr7UJc3XnCjpKfK6ZPf6WwdVkcSCr01xKUxbis4736c9FrFvRhZitJkoNUuhKG+tN+5JJAIuXs/lqQIEFDGwUoE2Ft+2kggqdMtwtHt0hZ842zMWPsvyY2VDmaOCtR/zka+4HWYE6PZN9iQ+H6PgLY9lzVPxQU12gVLOfrHSnsmJl0A8VfE0FqjGmKrzNViT/uGU2vQExmXnjiXte4ZBGhL X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(9101528026)(9101521098)(601004)(2401047)(8121501046)(5005006)(3002001)(10201501046)(6055026); SRVR:BLUPR12MB0433; BCL:0; PCL:0; RULEID:; SRVR:BLUPR12MB0433; X-Forefront-PRVS: 093290AD39 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6009001)(50986999)(76176999)(50226002)(47776003)(66066001)(229853001)(36756003)(189998001)(19580395003)(19580405001)(2906002)(2950100001)(5003940100001)(53416004)(2201001)(5004730100002)(92566002)(4326007)(5001770100001)(77096005)(586003)(42186005)(5008740100001)(81166005)(48376002)(3846002)(6116002)(86362001)(50466002); DIR:OUT; SFP:1101; SCL:1; SRVR:BLUPR12MB0433; H:ssuthiku-cz-dev.amd.com; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BLUPR12MB0433; 23:IihU6rrGfwivl7AhKmZSyY6LZqgpciOfjZjRdPFZLPP/mQvlB+b28EJ0ZxpXcNXkhZbA1uxpfU+MzOsm8+XRgAUfo5i9gx8W1eWvk9jJt+pRZu50mTnhmr9hy7gbBztzOMNNapmi0Rt11XoVgbNayhvE89lSjA7IoEZRisQwv5WgAYsQYto3FDEp0+7V+VZhFKNWXuP3VY1mXIpgJ1lW/BGiOx9gkkk6LYl1+JsMKW8L49fucdjPyDSf48IR8V12oRgXpwuHZ5SRzMQF20hINsHkjAtR0dMna7XggMLHsNkLaNvO/fkI6nskwBLI7kTPM/xz1nRmRRhR+JqPhyKDk3WZOSxFiDWk/bm8vBs3KFSAq2zgMl23faN8N10KQ/JUlA83E8Ec8GKaO69gfu5rmow+5+bHd06LLUL9nyDe3gyydS70OAShGpNES1vjOXX2PDFe/7mV5TfHfl+zGjIqYwbrSZJyGx8HbV/UzydTuS2b+tujn5IGcy2d5PhQw874l9KzW0FI4oWlwKUnKpzMqvtsumYazNfa9MthFrVG3IPLFbzLEoXnRYqiLuFv4ElOWSFsFShqQ7YeVosy4HYhpVhRK1poSeYP3d7wB5YPAFaWetQYF+ZMWqJVbVL3D3YsntkmL/hIXDYGF7jMEnVwsxf9aHKsGHruqzCr1xOk+SzBkb1Iluwev7WRL/8WlQQxZb26+NanceKMSeNipJtSX2CxS6ccudwBbhCGsDV5ounW33c9A/Vns6w3ZyvuApQ/rv1hnWglxHOGTdmmYRgUWqONf+yHacrmIDFiBkfSQublaDPPnCB4kPYuEkC8xq7FhfKSjIG/s5zRbsE7Y6/GBH0TvUujUmzUoQhp58QCK4IO9xjpwoTM5bUYgWv6UGhc X-Microsoft-Exchange-Diagnostics: 1; BLUPR12MB0433; 5:Uc++BgNXBJUFu0GCGGP+piHJcLVzAZ4f+JHahU+iOvUd/yMvI2jiN1PaorCV0YBjMObaMGt1JepigrNmLj0u4DK9Un4YcQAN2BwJUo1lythZ0f30v82L+/LTgRbeNZV6YWk57nuCZbUz6N9mAynk2w==; 24:KI8gl6s5CW/NZoI8Vtd5tfnT5jkjel1Rpgbcc2pvMjH2mT2CDXW46nrpvdCkp79HTpCigHlwGnXHey7ysXwzjdWyyWJ5HAV4lTTH96O5QBI=; 7:1fbTav8XMK8JytU0BU6NVO6cU3UpJJ2sCsrYOVdJRb4rxT/VpuHMEztESIE0lIrxCmjKvcgtP3d8yKYMp9zwVS7SOHvGJVeRSwmG+zZimKQckmB9mWesSZHPgewQ8qdmxeNFPIVkULOqed6PVL5mzm5hS3/fjADnwoCpVepIp2I=; 20:iL3Z02wldzT3qow2x3kZcMjwk3Ej/LpbXBUIAWJm/KFmk+9L1efrJimEp+G54tGF1AZLgQ0Y9jGQel2uHejYIVpjofCWK2L/m71GG+ZVWP9u949TfECbQ7uIEaeIsD7Dqei2z2kViRdcwNZNOeu+zllDJ8yjW6PTKHMLoawsqcqb55uz9m0LEyiBFWAA/joPEZD9DAKUgifYaGBVXjhj3XJLzXPBp5vQSCD1p4kijGKbvt4dCiUbwB0pMuGfFzF0 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 May 2016 19:10:52.2599 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLUPR12MB0433 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch introduces a new mechanism to inject interrupt using AVIC. Since VINTR is not supported when enable AVIC, we need to inject interrupt via APIC backing page instead. This patch also adds support for AVIC doorbell, which is used by KVM to signal a running vcpu to check IRR for injected interrupts. Signed-off-by: Suravee Suthikulpanit --- arch/x86/kvm/svm.c | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) -- 1.9.1 diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c index 4b00dc6..3a97874 100644 --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c @@ -71,6 +71,8 @@ MODULE_DEVICE_TABLE(x86cpu, svm_cpu_id); #define SVM_FEATURE_DECODE_ASSIST (1 << 7) #define SVM_FEATURE_PAUSE_FILTER (1 << 10) +#define SVM_AVIC_DOORBELL 0xc001011b + #define NESTED_EXIT_HOST 0 /* Exit handled on host level */ #define NESTED_EXIT_DONE 1 /* Exit caused nested vmexit */ #define NESTED_EXIT_CONTINUE 2 /* Further checks needed */ @@ -293,6 +295,17 @@ static inline void avic_update_vapic_bar(struct vcpu_svm *svm, u64 data) mark_dirty(svm->vmcb, VMCB_AVIC); } +static inline bool avic_vcpu_is_running(struct kvm_vcpu *vcpu) +{ + struct vcpu_svm *svm = to_svm(vcpu); + u64 *entry = svm->avic_physical_id_cache; + + if (!entry) + return false; + + return (READ_ONCE(*entry) & AVIC_PHYSICAL_ID_ENTRY_IS_RUNNING_MASK); +} + static void recalc_intercepts(struct vcpu_svm *svm) { struct vmcb_control_area *c, *h; @@ -2865,10 +2878,11 @@ static int clgi_interception(struct vcpu_svm *svm) disable_gif(svm); /* After a CLGI no interrupts should come */ - svm_clear_vintr(svm); - svm->vmcb->control.int_ctl &= ~V_IRQ_MASK; - - mark_dirty(svm->vmcb, VMCB_INTR); + if (!kvm_vcpu_apicv_active(&svm->vcpu)) { + svm_clear_vintr(svm); + svm->vmcb->control.int_ctl &= ~V_IRQ_MASK; + mark_dirty(svm->vmcb, VMCB_INTR); + } return 1; } @@ -3762,6 +3776,7 @@ static inline void svm_inject_irq(struct vcpu_svm *svm, int irq) { struct vmcb_control_area *control; + /* The following fields are ignored when AVIC is enabled */ control = &svm->vmcb->control; control->int_vector = irq; control->int_ctl &= ~V_INTR_PRIO_MASK; @@ -3840,6 +3855,18 @@ static void svm_sync_pir_to_irr(struct kvm_vcpu *vcpu) return; } +static void svm_deliver_avic_intr(struct kvm_vcpu *vcpu, int vec) +{ + kvm_lapic_set_irr(vec, vcpu->arch.apic); + smp_mb__after_atomic(); + + if (avic_vcpu_is_running(vcpu)) + wrmsrl(SVM_AVIC_DOORBELL, + __default_cpu_present_to_apicid(vcpu->cpu)); + else + kvm_vcpu_wake_up(vcpu); +} + static int svm_nmi_allowed(struct kvm_vcpu *vcpu) { struct vcpu_svm *svm = to_svm(vcpu); @@ -3894,6 +3921,9 @@ static void enable_irq_window(struct kvm_vcpu *vcpu) { struct vcpu_svm *svm = to_svm(vcpu); + if (kvm_vcpu_apicv_active(vcpu)) + return; + /* * In case GIF=0 we can't rely on the CPU to tell us when GIF becomes * 1, because that's a separate STGI/VMRUN intercept. The next time we @@ -4637,6 +4667,7 @@ static struct kvm_x86_ops svm_x86_ops = { .sched_in = svm_sched_in, .pmu_ops = &amd_pmu_ops, + .deliver_posted_interrupt = svm_deliver_avic_intr, }; static int __init svm_init(void)