Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp840701yba; Wed, 24 Apr 2019 10:26:51 -0700 (PDT) X-Google-Smtp-Source: APXvYqy6xPeVor7eHbBecgz1rATP585rhAdiu4X7qh5uPWqseQO7h4HU7NfFQv9PnH2pfUYTpYO0 X-Received: by 2002:a17:902:e091:: with SMTP id cb17mr33185074plb.222.1556126811519; Wed, 24 Apr 2019 10:26:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556126811; cv=none; d=google.com; s=arc-20160816; b=nQx6kCiTJOn/yyqO3fx2dPQOEI5IlGoMV2uBOuLhHYs08oFbfKtyfyYDTMm+bNrIIi FL1uvpzK8zuTtsxc2B8QfLbxuh6TI3B8q5yqzphu4U6KZkuya174NQGht65Xd3xq3jo2 i5kNoSK/Qqx2ovT2ZoiBzIcEf8n3GDR/UgXImqESDEJNpJ2/gRR3Aq0tGCtUjp3ZMuUk 3mAg2bsTAnXgjEfCJFCo+prYBcQ7Bsyl2LCqvAQ3rUamLhDdNddsTzFk0dYGAQeK31h7 Xx21A2kAuDnOqnMTgo586cgEefh/ISatUmj9eAz3tNEP0/KmOR718BmGa9WICynd+MXo mHJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=9Zc+5gvjFvKfittn35uarOsyDJ+NmNyaZ+XpuUGrgXo=; b=P+U6WYjxqv/jmK8+i4Zd01pwB6FfGTaTKdtHA6zt9cyPuu/SgjSS8MWOTQT38WqEML dX1jvzptph6bfnTMC6krYIQGfIo4Llzm/3NlqzfmFy2cAb1n4tB6tTE0kKOQ+yLAxriW YfEsuIGmaqFJJzeivrnyiCYzlFRdq4XbHy6OrXlXPWKUdYBYbwPkBvqx6+veHxl7e8Gr vgIUTSSCnafX/nMCK6WJ72E6JfeCsteH1e8HVt7W/GiawuNpySE5NSaobeY5lZLB4H7c 3y0r28iLkRppns5fM6ip3hNZDJBDg8SGMOUOAga2mRgowLrw7BAD5e4SiGgXAI/HFwue 5PBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=dD4gOHwh; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id bg12si18914168plb.295.2019.04.24.10.26.36; Wed, 24 Apr 2019 10:26:51 -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=@kernel.org header.s=default header.b=dD4gOHwh; 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 S2389957AbfDXRY7 (ORCPT + 99 others); Wed, 24 Apr 2019 13:24:59 -0400 Received: from mail.kernel.org ([198.145.29.99]:50796 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389236AbfDXRY5 (ORCPT ); Wed, 24 Apr 2019 13:24:57 -0400 Received: from localhost (62-193-50-229.as16211.net [62.193.50.229]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 50D462054F; Wed, 24 Apr 2019 17:24:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1556126697; bh=gVEYfcB6W6VDwOqrK5oO/ieWo1ybxszzcy7OzesLC68=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dD4gOHwhODG0dfu0/BhY/pPeLXIKI1npq2jp72UvR90Hk92COWu9eUwx1D63Dz94L 6IaScUFqhpdAjii9QhmfafbLHva3owpGQsT4l3JGugo2vHXoRqDW9nXTVrYqlyvKEi Nv5GgWfCNpzlBlWUMeKAYprNe5INhVR4y0MkmnsI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Paolo Bonzini , Oren Twaig , Suravee Suthikulpanit Subject: [PATCH 4.9 29/44] Revert "svm: Fix AVIC incomplete IPI emulation" Date: Wed, 24 Apr 2019 19:10:07 +0200 Message-Id: <20190424170858.393371885@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190424170839.924291114@linuxfoundation.org> References: <20190424170839.924291114@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Suthikulpanit, Suravee commit 4a58038b9e420276157785afa0a0bbb4b9bc2265 upstream. This reverts commit bb218fbcfaaa3b115d4cd7a43c0ca164f3a96e57. As Oren Twaig pointed out the old discussion: https://patchwork.kernel.org/patch/8292231/ that the change coud potentially cause an extra IPI to be sent to the destination vcpu because the AVIC hardware already set the IRR bit before the incomplete IPI #VMEXIT with id=1 (target vcpu is not running). Since writting to ICR and ICR2 will also set the IRR. If something triggers the destination vcpu to get scheduled before the emulation finishes, then this could result in an additional IPI. Also, the issue mentioned in the commit bb218fbcfaaa was misdiagnosed. Cc: Radim Krčmář Cc: Paolo Bonzini Reported-by: Oren Twaig Signed-off-by: Suravee Suthikulpanit Cc: stable@vger.kernel.org Signed-off-by: Paolo Bonzini Signed-off-by: Greg Kroah-Hartman --- arch/x86/kvm/svm.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c @@ -3940,14 +3940,25 @@ static int avic_incomplete_ipi_intercept kvm_lapic_reg_write(apic, APIC_ICR, icrl); break; case AVIC_IPI_FAILURE_TARGET_NOT_RUNNING: { + int i; + struct kvm_vcpu *vcpu; + struct kvm *kvm = svm->vcpu.kvm; struct kvm_lapic *apic = svm->vcpu.arch.apic; /* - * Update ICR high and low, then emulate sending IPI, - * which is handled when writing APIC_ICR. + * At this point, we expect that the AVIC HW has already + * set the appropriate IRR bits on the valid target + * vcpus. So, we just need to kick the appropriate vcpu. */ - kvm_lapic_reg_write(apic, APIC_ICR2, icrh); - kvm_lapic_reg_write(apic, APIC_ICR, icrl); + kvm_for_each_vcpu(i, vcpu, kvm) { + bool m = kvm_apic_match_dest(vcpu, apic, + icrl & KVM_APIC_SHORT_MASK, + GET_APIC_DEST_FIELD(icrh), + icrl & KVM_APIC_DEST_MASK); + + if (m && !avic_vcpu_is_running(vcpu)) + kvm_vcpu_wake_up(vcpu); + } break; } case AVIC_IPI_FAILURE_INVALID_TARGET: