From patchwork Fri May 20 07:50:42 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Zhang X-Patchwork-Id: 9128847 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 C3AC16048B for ; Fri, 20 May 2016 07:50:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B430520120 for ; Fri, 20 May 2016 07:50:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A542F2796F; Fri, 20 May 2016 07:50:52 +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_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, 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 B8E9220120 for ; Fri, 20 May 2016 07:50:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755452AbcETHus (ORCPT ); Fri, 20 May 2016 03:50:48 -0400 Received: from mail-oi0-f65.google.com ([209.85.218.65]:36020 "EHLO mail-oi0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754795AbcETHur (ORCPT ); Fri, 20 May 2016 03:50:47 -0400 Received: by mail-oi0-f65.google.com with SMTP id g16so7923804oib.3 for ; Fri, 20 May 2016 00:50:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=to:cc:from:subject:message-id:date:user-agent:mime-version :content-transfer-encoding; bh=oOKkQsoWYtRS31/ATsXApdKyo3kAepjXiw7SAU07yxA=; b=JDG/8ieXgt3uxOzW5rT2eK5jsT24TNcgl7VjxnKpgiEA7pcuhqdA+CdcUzczaNECCH Klc4rys3nu0g3LVK9p+O8U0igWLLBrWdfoZb5FVXWigV+OGZnsIlgSi/Z3FhQjXwWXJu AlFXQ2KVRZ4/8o0FToWOgOC9berOLsAcZtMBX8xgOikJ3AcUkyG8f7lWEFwbpB9TrIbM lXWy8HdCuQlEewZgK8ZujDhEJ6LF/IEDu5Fmc+EaHGHQKhhk4mgsNiwhJTQsE/cL0AEb 4RRpT/6QOh7c2u3m1nksQmvlef0XzEZXfBX0PC6laQ37vqTtDxVIOUVYs9dX3jEFR1Ck Sruw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:to:cc:from:subject:message-id:date:user-agent :mime-version:content-transfer-encoding; bh=oOKkQsoWYtRS31/ATsXApdKyo3kAepjXiw7SAU07yxA=; b=BYSs4Zdssm/+b/SLySiAtuFRfrJdyTS7F9VCQpvdqlWAW1J9fuvKMi5y7PFnVhFtjz ZpKCjU3VOpw1SWY37CfK9f4/2tsJiLjii3UvSO7Z0fkI0UzHAO2NoeS8jWcaRzIkRlZV dz92A6A1/XIIkJ7jvxtkkN3Q6aqZZhiMCHAIdTaDaI4hWTkrNY14Qr6ZLvUnrPGwIOcg 6OxA5Bpgpl6tYjOY5/dxDmGC/OvtaQEg+3uVxrp4UR5csYyajYf0vQFfpRq7jgAY5m2b 991QeYZ2p7W2PKqZD573zg5nZdvijvfS+o37FmpyQ+OA1XJiQTPRjfOvSteZVid7nq+K 5Tcw== X-Gm-Message-State: AOPr4FUpNncK+bBoxgSzA7mgQE7kHwpNWv4FzQyvdLmLBDkcIGI7CzZv6lqyZN1e0JOAOQ== X-Received: by 10.202.60.138 with SMTP id j132mr751328oia.201.1463730647003; Fri, 20 May 2016 00:50:47 -0700 (PDT) Received: from [127.0.0.1] ([47.88.86.135]) by smtp.gmail.com with ESMTPSA id 95sm3019251otr.19.2016.05.20.00.50.44 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 20 May 2016 00:50:46 -0700 (PDT) To: Paolo Bonzini , rkrcmar@redhat.com, Feng Wu Cc: kvm@vger.kernel.org From: Yang Zhang Subject: [PATCH] KVM: VMX: check apicv is active before using VT-d posted interrupt Message-ID: <7fec7586-a7c6-59dd-7653-2f88de75fbe4@gmail.com> Date: Fri, 20 May 2016 15:50:42 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.1.0 MIME-Version: 1.0 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP VT-d posted interrupt is relying on the CPU side's posted interrupt. Need to check whether VCPU's APICv is active before enabing VT-d posted interrupt. Signed-off-by: Yang Zhang Signed-off-by: Shengge Ding --- arch/x86/kvm/vmx.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) do { @@ -2180,7 +2181,8 @@ static void vmx_vcpu_pi_put(struct kvm_vcpu *vcpu) struct pi_desc *pi_desc = vcpu_to_pi_desc(vcpu); if (!kvm_arch_has_assigned_device(vcpu->kvm) || - !irq_remapping_cap(IRQ_POSTING_CAP)) + !irq_remapping_cap(IRQ_POSTING_CAP) || + !kvm_vcpu_apicv_active(vcpu)) return; /* Set SN when the vCPU is preempted */ @@ -10698,7 +10700,8 @@ static int vmx_pre_block(struct kvm_vcpu *vcpu) struct pi_desc *pi_desc = vcpu_to_pi_desc(vcpu); if (!kvm_arch_has_assigned_device(vcpu->kvm) || - !irq_remapping_cap(IRQ_POSTING_CAP)) + !irq_remapping_cap(IRQ_POSTING_CAP) || + !kvm_vcpu_apicv_active(vcpu)) return 0; vcpu->pre_pcpu = vcpu->cpu; @@ -10764,7 +10767,8 @@ static void vmx_post_block(struct kvm_vcpu *vcpu) unsigned long flags; if (!kvm_arch_has_assigned_device(vcpu->kvm) || - !irq_remapping_cap(IRQ_POSTING_CAP)) + !irq_remapping_cap(IRQ_POSTING_CAP) || + !kvm_vcpu_apicv_active(vcpu)) return; do { @@ -10817,7 +10821,8 @@ static int vmx_update_pi_irte(struct kvm *kvm, unsigned int host_irq, int idx, ret = -EINVAL; if (!kvm_arch_has_assigned_device(kvm) || - !irq_remapping_cap(IRQ_POSTING_CAP)) + !irq_remapping_cap(IRQ_POSTING_CAP) || + !kvm_vcpu_apicv_active(kvm->vcpus[0])) return 0; idx = srcu_read_lock(&kvm->irq_srcu); diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index 7ebf27b..8ba87f3 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -2072,7 +2072,8 @@ static void vmx_vcpu_pi_load(struct kvm_vcpu *vcpu, int cpu) unsigned int dest; if (!kvm_arch_has_assigned_device(vcpu->kvm) || - !irq_remapping_cap(IRQ_POSTING_CAP)) + !irq_remapping_cap(IRQ_POSTING_CAP) || + !kvm_vcpu_apicv_active(vcpu)) return;