From patchwork Fri Mar 18 06:09:43 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Suthikulpanit, Suravee" X-Patchwork-Id: 64024 Delivered-To: patch@linaro.org Received: by 10.112.199.169 with SMTP id jl9csp870240lbc; Thu, 17 Mar 2016 23:13:40 -0700 (PDT) X-Received: by 10.98.79.9 with SMTP id d9mr20803188pfb.46.1458281620207; Thu, 17 Mar 2016 23:13:40 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id hq1si2311646pac.56.2016.03.17.23.13.39; Thu, 17 Mar 2016 23:13:40 -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; 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; dkim=pass header.i=@amdcloud.onmicrosoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757180AbcCRGNX (ORCPT + 30 others); Fri, 18 Mar 2016 02:13:23 -0400 Received: from mail-by2on0058.outbound.protection.outlook.com ([207.46.100.58]:3904 "EHLO na01-by2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752268AbcCRGLY (ORCPT ); Fri, 18 Mar 2016 02:11:24 -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=RJ+XIrpzmDtmXQBFcZH3mBufxewZLMoq8K4RMC/faqQ=; b=a+rGqEjfn39DGLCVa8Zja7TSnJJZe0Ck6jLkqWxCxBG0vjemDQHee7CJQjNgeQa2CM0HZ5zlrJ4KmYkhYkU0P17fgiljbzx4TMA3Eskkd2XRRRyUBha9v5/DQExz0Da6NGXrPhT5jSgZB/j7fjx0uhPwi0CQWfVdiKWQdgzZcRk= Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none; redhat.com; dmarc=none action=none header.from=amd.com; Received: from localhost.localdomain (124.121.8.20) by BY1PR12MB0437.namprd12.prod.outlook.com (10.162.147.139) with Microsoft SMTP Server (TLS) id 15.1.443.12; Fri, 18 Mar 2016 06:11:11 +0000 From: Suravee Suthikulpanit To: , , , , , CC: , , , , Suravee Suthikulpanit , Suravee Suthikulpanit Subject: [PART1 RFC v3 07/12] svm: Add interrupt injection via AVIC Date: Fri, 18 Mar 2016 01:09:43 -0500 Message-ID: <1458281388-14452-8-git-send-email-Suravee.Suthikulpanit@amd.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1458281388-14452-1-git-send-email-Suravee.Suthikulpanit@amd.com> References: <1458281388-14452-1-git-send-email-Suravee.Suthikulpanit@amd.com> MIME-Version: 1.0 X-Originating-IP: [124.121.8.20] X-ClientProxiedBy: SG2PR04CA0047.apcprd04.prod.outlook.com (25.169.49.143) To BY1PR12MB0437.namprd12.prod.outlook.com (25.162.147.139) X-MS-Office365-Filtering-Correlation-Id: fa9d1870-4330-4c76-fed9-08d34ef41fc9 X-Microsoft-Exchange-Diagnostics: 1; BY1PR12MB0437; 2:zavUU90ED1xkZrEAe5EnXatwnszRk2UUWNkMdMOwpQvmepdG0S0Zjvx8LB3sSAEsuczXUx/WGZMS5qN4Ph8VuYH973dsG/oX2hwb8KLa6Fmn7MSPx6TRxHOINc2jQaTv8L6tj18GWAOTZByKB+0dE9upSXVatdLfKJSzF0T1tJlBNy9StzZ8OZHLmM/UgDQc; 3:FQk6E3R6Y0PJ3wX9e55mXRLNLG9n0Hmvxgsnx8EdfW9/3UrVaoFHtJ1IF0P5GIgANGRwtFM+QA8owfb/KMsUwil/7ixT+kcNkpMhaX7j8oPsKFBSTihn1jQukhTq1htb; 25:ZPdZtHuHohzZXby6DPzt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PRtLnxJVX6hz+Ccx1JvAVQkmWBwv2JD8OZQc0X4bmdM9j8ircGNNT2yPe92; 4:BNc48MHRS5DeaUXuSdXoJ6bqmgdOaesX2ACUtcwa2dMGNDR+9+OlwDuNsWOYF8HOSE9Fm0ygOjkjZ2E+wlD1y/ctXtDVSawWPYE1k9BTB65E7DmOVw/BaHlrF8xZ+KGgqD1NSXUC7JPep8E3aPj7rAuLLbmiK3yiEA5YEWNOUOEBboF9P6gdhvRmpEAYQ0sjA4IpUKikpcFVopS9GX4hpfwZRAg4iRhbFs+TUrboROv60dgYHRwoa+GvWXy2ahiEqM59s3u6IdEfAWc3WuI+hn+s3Jvt6k+69y+QLozNHtBC6QjMdvqreyu+pDTx0s6qM2GLEEBLuaXI4LsupsAVpckJXC7tBzzfgezxABmk4GqBmg6J19qidjAtMIbCYOWi X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(8121501046)(5005006)(10201501046)(3002001); SRVR:BY1PR12MB0437; BCL:0; PCL:0; RULEID:; SRVR:BY1PR12MB0437; X-Forefront-PRVS: 088552DE73 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6009001)(6069001)(189998001)(66066001)(19580395003)(19580405001)(47776003)(42186005)(3846002)(5001770100001)(50226001)(6116002)(2201001)(86362001)(586003)(229853001)(2950100001)(36756003)(5004730100002)(77096005)(81166005)(5003940100001)(4326007)(50466002)(92566002)(48376002)(5008740100001)(76176999)(50986999); DIR:OUT; SFP:1101; SCL:1; SRVR:BY1PR12MB0437; H:localhost.localdomain; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BY1PR12MB0437; 23:CgKVP5dxijsXTYD1FfNml1X0bQaSiUjSw+M/UzhrG3jnz6NrOfvI9ptiOsUqeXeWD2tWDUIKlk7uW3P6Qb5SYpj0YA0pM/QjDuxNf34WK1giHFm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UnpUwa3rGoT+FPEuyggqhWdL92BIisTib1iFR9sUt19Q5TxCR3KMn6vq1/zF+k9ok5LjbxUDLHoBc+fa4TqDXl+u6n8VNhkf2fhk+OSmgc7OwfYkNfL+GxockJ+uv1hXjWdrd1EyCZWsLa6nP62a6gUsK1QcIP8jntmmMZ+3hIE0JG8tW4GawruUc6tP9tkZlT/pB73hr2cUoKp5/NQ7kRIS6I1aUEdlxPg/8bJARL9HJKdBJrkY X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Mar 2016 06:11:11.9969 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY1PR12MB0437 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 | 46 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) -- 1.9.1 diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c index 621c948..8e31ad3 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 */ @@ -217,6 +219,8 @@ static bool npt_enabled = true; static bool npt_enabled; #endif +static struct kvm_x86_ops svm_x86_ops; + /* allow nested paging (virtualized MMU) for all guests */ static int npt = true; module_param(npt, int, S_IRUGO); @@ -291,6 +295,18 @@ static inline struct vcpu_svm *to_svm(struct kvm_vcpu *vcpu) return container_of(vcpu, struct vcpu_svm, vcpu); } +static inline bool avic_vcpu_is_running(struct kvm_vcpu *vcpu) +{ + struct vcpu_svm *svm = to_svm(vcpu); + u64 *entry; + + entry = svm->avic_phy_apic_id_cache; + if (!entry) + return false; + + return (READ_ONCE(*entry) & AVIC_PHY_APIC_ID__IS_RUN_MSK); +} + static void recalc_intercepts(struct vcpu_svm *svm) { struct vmcb_control_area *c, *h; @@ -964,6 +980,8 @@ static __init int svm_hardware_setup(void) if (avic) { printk(KERN_INFO "kvm: AVIC enabled\n"); + } else { + svm_x86_ops.deliver_posted_interrupt = NULL; } return 0; @@ -2877,8 +2895,10 @@ 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; + if (!svm_vcpu_avic_enabled(svm)) { + svm_clear_vintr(svm); + svm->vmcb->control.int_ctl &= ~V_IRQ_MASK; + } mark_dirty(svm->vmcb, VMCB_INTR); @@ -3453,6 +3473,9 @@ static int msr_interception(struct vcpu_svm *svm) static int interrupt_window_interception(struct vcpu_svm *svm) { + if (svm_vcpu_avic_enabled(svm)) + BUG(); + kvm_make_request(KVM_REQ_EVENT, &svm->vcpu); svm_clear_vintr(svm); svm->vmcb->control.int_ctl &= ~V_IRQ_MASK; @@ -3767,6 +3790,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; @@ -3844,6 +3868,20 @@ static void svm_sync_pir_to_irr(struct kvm_vcpu *vcpu) return; } +static void svm_deliver_avic_intr(struct kvm_vcpu *vcpu, int vec) +{ + struct vcpu_svm *svm = to_svm(vcpu); + + kvm_lapic_set_vector(vec, svm->vcpu.arch.apic->regs + APIC_IRR); + 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); @@ -3904,6 +3942,9 @@ static void enable_irq_window(struct kvm_vcpu *vcpu) * get that intercept, this function will be called again though and * we'll get the vintr intercept. */ + if (svm_vcpu_avic_enabled(svm)) + return; + if (gif_set(svm) && nested_svm_intr(svm)) { svm_set_vintr(svm); svm_inject_irq(svm, 0x0); @@ -4638,6 +4679,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)