Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2407880pxb; Mon, 18 Jan 2021 17:54:38 -0800 (PST) X-Google-Smtp-Source: ABdhPJxReYDHDJDMTLi2vlfcHi/pv0Mooh0xAw47SqW/7GVs+KXwlEucBBufLZNMA8gj0U4O7fQN X-Received: by 2002:a17:906:2e9a:: with SMTP id o26mr1510156eji.77.1611021277849; Mon, 18 Jan 2021 17:54:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611021277; cv=none; d=google.com; s=arc-20160816; b=YKmqVBCNCYz4VbCL3OS4J9SeqohF+GCFodYPga+6Ydbnke11IS9pLGkM/myS3S+jOB bC6/624fGOwdwirltERiC1JCtxjRlpBvWCUa51+N3WlYzOzXP70D2+MqOzWQgNUdeuS5 SdyDDSB/COay7oCiE3XEVv1uIp/2dIeTiXBW2pSR/BRk1jp038TEhIAQlGESzL1mlHmv V8jOBMgrQPMQKU5H4zmV/WiymI0BadOkmu+fGMAU5b7+uNKqBsAI7VR5A45tpARcpLxY ON4GLGJ4nW5PqruNvoyUmadbDL6WErJ7NnMIrxNTIA/nKPGoHgQyH1V8qkyqK3J7vuHv S7XA== 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 :message-id:date:subject:cc:to:from; bh=ql795jc4Kq3SMjsAWU+kh/9Jvkn5u4qL9IP/wO0hdds=; b=pp+Rue69MzjjxUFjuOCR9uFXQaMf3DVZ9YqKCtM9NIVlTXQByiHS7GvlOXKO/F8n1/ lVV6/rVxlrrXaS6Ye6/wbnOTwyEl1jrEezuGBuIvrNtAKvo0+tSw31kCaxlD4S3zcKPB /8IqHhfCw1+v4RI+3jbkpW/h3gjyIj6e8rFhPPbXZRwkIa44BDzHEdyM5oxsN4+kzyzN iHjwiGuoiE68LaIyVGzgz97eSAYGy0EkwjfrfN6aGK69KTPTVWvi4DHetxN6WS1ZwRoJ WCMNJCGRNAMlSfej6tqyaSEAMaso83lyAMgPNb9Ie58otZWh4Xl9vTUuxjEpZ52ooJ8R WeXg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id jg15si7366389ejc.481.2021.01.18.17.54.15; Mon, 18 Jan 2021 17:54:37 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388019AbhARIsv (ORCPT + 99 others); Mon, 18 Jan 2021 03:48:51 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:11108 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387957AbhARIsS (ORCPT ); Mon, 18 Jan 2021 03:48:18 -0500 Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4DK5413sQLz15vJr; Mon, 18 Jan 2021 16:46:25 +0800 (CST) Received: from localhost (10.174.150.219) by DGGEMS406-HUB.china.huawei.com (10.3.19.206) with Microsoft SMTP Server id 14.3.498.0; Mon, 18 Jan 2021 16:47:22 +0800 From: Jay Zhou To: , CC: , , , , , , Subject: [PATCH] KVM: x86: get smi pending status correctly Date: Mon, 18 Jan 2021 16:47:20 +0800 Message-ID: <20210118084720.1585-1-jianjay.zhou@huawei.com> X-Mailer: git-send-email 2.28.0.windows.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.174.150.219] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- arch/x86/kvm/x86.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 9a8969a..9025c76 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -105,6 +105,7 @@ 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); static void store_regs(struct kvm_vcpu *vcpu); @@ -4230,6 +4231,9 @@ static void kvm_vcpu_ioctl_x86_get_vcpu_events(struct kvm_vcpu *vcpu, { process_nmi(vcpu); + if (kvm_check_request(KVM_REQ_SMI, vcpu)) + process_smi(vcpu); + /* * In guest mode, payload delivery should be deferred, * so that the L1 hypervisor can intercept #PF before -- 1.8.3.1