Received: by 10.223.185.116 with SMTP id b49csp51900wrg; Thu, 8 Mar 2018 12:43:41 -0800 (PST) X-Google-Smtp-Source: AG47ELuY2MbVJpCT3jwEX9oAltx5bazA91JdpHUWjZ2JvtzaSx6GmBj/yt+/yPpUDyQG0agiDxLq X-Received: by 2002:a17:902:b58d:: with SMTP id a13-v6mr25617508pls.123.1520541821820; Thu, 08 Mar 2018 12:43:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520541821; cv=none; d=google.com; s=arc-20160816; b=PARn85avn1mtbKNAdk3V2jT2Wfyx6mRGaFmZFuPCOkji06xw8/h4GOHsdQxPu4B7qM Ua9jH/1AWvGUnyW2m3kQattrWCPVd4OynV+noXb74k4NY3OHdhGIXFINHl2GrytHJYEy 3/RDmDaolGf/Z1mzLPBZO0+r2owQBW2zh1X2UdNN6N8flUmwQuhnthX6NAPr6fw8HbuU fc9LCTvlOThGg86ObpRuzWyPPlhf9L96SWItw2/BpLW7WrSZUNpAdiqQyShl4y+8AhbQ CRJleTWMb5u+4WFLmSTTaQMBvG+Lkud9EOPG47kSq4u4PR90yQGmDfnlqZsiPsntTSNR BG6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=tpYck9FjDc4Jef0e3iR+tadrM8+mBksEOG6iuAWGhFk=; b=HwX0Feq3PK1i2zMB/iBBW6HuLRDW2VXvn0R9Gi9MTnF0xSK6XLuRGtB38xE1jg5weQ RPXBP5c8ZmR9qzWvNBG29eRD1P5+ikvzdIVnDlbXuFVcy+unhIaepVoV4I1ATaexI7ld owMevmwCAqgr02b5xid8tnz/1IlZqCfrVyi5Gpyk0OoI6WJDoFGWxiVR3WZ2ABiRRPGt MQ4JB20rR10IYnOTUkG51M8/b3x4cs6ruNdmxla8gxFYw9y17QBNIh3Yjc9XG60/lQqH zw3BYy0y64THCFjHplsgUlU1sHohUhAeN2N5pY5BgoY+XPp6wJBxJrFUiTRfw53eUlE6 c/wg== ARC-Authentication-Results: i=1; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b62si16366847pfl.409.2018.03.08.12.43.27; Thu, 08 Mar 2018 12:43:41 -0800 (PST) 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751216AbeCHUlM (ORCPT + 99 others); Thu, 8 Mar 2018 15:41:12 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:38442 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751157AbeCHUlK (ORCPT ); Thu, 8 Mar 2018 15:41:10 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 51A79BD9E; Thu, 8 Mar 2018 20:41:10 +0000 (UTC) Received: from flask (unknown [10.43.2.80]) by smtp.corp.redhat.com (Postfix) with SMTP id 925D8202322A; Thu, 8 Mar 2018 20:41:08 +0000 (UTC) Received: by flask (sSMTP sendmail emulation); Thu, 08 Mar 2018 21:40:29 +0100 Date: Thu, 8 Mar 2018 21:40:29 +0100 From: Radim =?utf-8?B?S3LEjW3DocWZ?= To: Wanpeng Li Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Paolo Bonzini Subject: Re: [PATCH 2/3] KVM: X86: Provides userspace with a capability to not intercept HLT Message-ID: <20180308204029.GK12290@flask> References: <1519897782-8124-1-git-send-email-wanpengli@tencent.com> <1519897782-8124-2-git-send-email-wanpengli@tencent.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1519897782-8124-2-git-send-email-wanpengli@tencent.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Thu, 08 Mar 2018 20:41:10 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Thu, 08 Mar 2018 20:41:10 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'rkrcmar@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 2018-03-01 17:49+0800, Wanpeng Li: > From: Wanpeng Li > > If host CPUs are dedicated to a VM, we can avoid VM exits on HLT. > This patch adds the per-VM non-HLT-exiting capability. > > Cc: Paolo Bonzini > Cc: Radim Krčmář > Signed-off-by: Wanpeng Li > --- > diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h > index dff3a5d..fcf8339 100644 > --- a/arch/x86/kvm/svm.c > +++ b/arch/x86/kvm/svm.c > @@ -1394,6 +1394,9 @@ static void init_vmcb(struct vcpu_svm *svm) > set_intercept(svm, INTERCEPT_MWAIT); > } > > + if (!kvm_hlt_in_guest(svm->vcpu.kvm)) > + set_intercept(svm, INTERCEPT_HLT); We unconditionally set INTERCEPT_HLT just above, so that line has to be removed. > + > control->iopm_base_pa = __sme_set(iopm_base); > control->msrpm_base_pa = __sme_set(__pa(svm->msrpm)); > control->int_ctl = V_INTR_MASKING_MASK; > diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c > @@ -2525,6 +2525,19 @@ static int nested_vmx_check_exception(struct kvm_vcpu *vcpu, unsigned long *exit > return 0; > } > > +static void vmx_clear_hlt(struct kvm_vcpu *vcpu) > +{ > + /* > + * Ensure that we clear the HLT state in the VMCS. We don't need to > + * explicitly skip the instruction because if the HLT state is set, > + * then the instruction is already executing and RIP has already been > + * advanced. > + */ > + if (kvm_hlt_in_guest(vcpu->kvm) && > + vmcs_read32(GUEST_ACTIVITY_STATE) == GUEST_ACTIVITY_HLT) > + vmcs_write32(GUEST_ACTIVITY_STATE, GUEST_ACTIVITY_ACTIVE); > +} The clearing seems to be still missing around SMM -- I think you need to call vmx_clear_hlt() from pre_enter_smm(). Thanks.