Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp698330pxb; Tue, 2 Feb 2021 15:59:17 -0800 (PST) X-Google-Smtp-Source: ABdhPJyBLDcDiccNy/q5wbb8Oh76pdOWqI4/hKvj0xJaB2zh3HOxmg0iy8LlaFhtD2pKsZmxKYV2 X-Received: by 2002:a05:6402:510f:: with SMTP id m15mr490471edd.267.1612310357003; Tue, 02 Feb 2021 15:59:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612310356; cv=none; d=google.com; s=arc-20160816; b=bLtf1RZUf8g/VXdw/ZtmPZnkMoPgyX2Cxrg4eoqbGHdjRLQHyNpjId9vTjGQfuHuJF UwQg3S0CVtpPY7ICVK/IvcM2y0pd/Se/0AQMFzw/5jVcDTbrnLmbRhYE1y8Mds0WwH4L ONPIzU4JyiArVUGSoq3VDioV9F11UHcRNsZ3ucDLT5ouljZ+GWrsE2VEsR+iu/t8uw8J d9NSTw4RwZG31ADGyl/hCvpKqrkfIvi2aXu/Q33Elfdy4GZekeQnw7C91/8cuuRJyLtz OrIYe4u5+XHHlmY4yvNNFL6SM6igGeSgQa3fbL9wkD9YLomsoPLI7W1Wi6U2OrTa+tM8 IpXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=csevJ5oesPVlz4Gw/QZ73OWMBYN7Ih62KblP87CfLRQ=; b=0f352PweJbHcgzJhfEZc7Ayqfaxi+i6GDY+HtXbVRtMUIyy+HKDKokui2oOrpU9bx8 s23Pkskp3o9Ve18CQw/rxmKocEQdrTQly1IU4pNB3oxgz717/h1SCr5ASo2rPyyC2ueT MxJfw+zpSp3MFOVGt8/wZfu7eWh9ZqsPdE9RFRCIPZPPupS6bOL8pXlGF7Z8cQ1RZHzq deZ21zwmg7m9lNKXeUXDjDij5HtOKBc5kKV4l+ooWp61UWOv4e8EKErJrtXp+il53tWT p2p74Vf3s6w2UxzxhnRfLqwc8IMfR59v6xMR2po6ZY23c9gdnWMwCCPPbcTtKu7x8SWR dMQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=xw5ORjEz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id gb7si226282ejc.102.2021.02.02.15.58.52; Tue, 02 Feb 2021 15:59:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=xw5ORjEz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237537AbhBBRkA (ORCPT + 99 others); Tue, 2 Feb 2021 12:40:00 -0500 Received: from mail.kernel.org ([198.145.29.99]:49514 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234024AbhBBOM2 (ORCPT ); Tue, 2 Feb 2021 09:12:28 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 328C564FB3; Tue, 2 Feb 2021 13:52:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1612273937; bh=ap8D5h2Uoo5QL65hGFaPloFqwO29iOjT17jgglPdjHk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xw5ORjEzf2rNx97yqKRfGX3TmanO5pnhtq9PZAKxKIB7Z2VhUH4bZ4GBpaet5BNyQ 3rHjXnKuaQvvHC+32BD3G7R4dqWTxHnp/ztthFoJXAMJ5nWXJe+KYXTWHSDtKVi81S 5c4q2iP30eKowb83QlXzq2e36dOrjQXljmIdCreA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jay Zhou , Shengen Zhuang , Paolo Bonzini Subject: [PATCH 4.14 09/30] KVM: x86: get smi pending status correctly Date: Tue, 2 Feb 2021 14:38:50 +0100 Message-Id: <20210202132942.516085515@linuxfoundation.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210202132942.138623851@linuxfoundation.org> References: <20210202132942.138623851@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jay Zhou commit 1f7becf1b7e21794fc9d460765fe09679bc9b9e0 upstream. The injection process of smi has two steps: Qemu KVM Step1: cpu->interrupt_request &= \ ~CPU_INTERRUPT_SMI; kvm_vcpu_ioctl(cpu, KVM_SMI) call kvm_vcpu_ioctl_smi() and kvm_make_request(KVM_REQ_SMI, vcpu); Step2: kvm_vcpu_ioctl(cpu, KVM_RUN, 0) call process_smi() if kvm_check_request(KVM_REQ_SMI, vcpu) is true, mark vcpu->arch.smi_pending = true; The vcpu->arch.smi_pending will be set true in step2, unfortunately if vcpu paused between step1 and step2, the kvm_run->immediate_exit will be set and vcpu has to exit to Qemu immediately during step2 before mark vcpu->arch.smi_pending true. During VM migration, Qemu will get the smi pending status from KVM using KVM_GET_VCPU_EVENTS ioctl at the downtime, then the smi pending status will be lost. Signed-off-by: Jay Zhou Signed-off-by: Shengen Zhuang Message-Id: <20210118084720.1585-1-jianjay.zhou@huawei.com> Cc: stable@vger.kernel.org Signed-off-by: Paolo Bonzini Signed-off-by: Greg Kroah-Hartman --- arch/x86/kvm/x86.c | 5 +++++ 1 file changed, 5 insertions(+) --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -98,6 +98,7 @@ static u64 __read_mostly efer_reserved_b static void update_cr8_intercept(struct kvm_vcpu *vcpu); static void process_nmi(struct kvm_vcpu *vcpu); +static void process_smi(struct kvm_vcpu *vcpu); static void enter_smm(struct kvm_vcpu *vcpu); static void __kvm_set_rflags(struct kvm_vcpu *vcpu, unsigned long rflags); @@ -3290,6 +3291,10 @@ static void kvm_vcpu_ioctl_x86_get_vcpu_ struct kvm_vcpu_events *events) { process_nmi(vcpu); + + if (kvm_check_request(KVM_REQ_SMI, vcpu)) + process_smi(vcpu); + /* * FIXME: pass injected and pending separately. This is only * needed for nested virtualization, whose state cannot be