Received: by 10.223.185.116 with SMTP id b49csp252925wrg; Thu, 8 Mar 2018 16:53:17 -0800 (PST) X-Google-Smtp-Source: AG47ELs7SWweirr2kL4F25d3ZAeoYkLSryp9lJb+HfOSgJfA5toeQ0eNPJo6sp4ylD1xllf0EUYX X-Received: by 10.101.81.76 with SMTP id g12mr22697217pgq.88.1520556796927; Thu, 08 Mar 2018 16:53:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520556796; cv=none; d=google.com; s=arc-20160816; b=wmk4cPcBVMv+F8imZe/XoJamfMGWJXHgJIdbqVOylNLiKcH6LN4sU4FbYo7GehS1MJ Ty/GtsascH9ol8ykqXl8PUMpwiFRb4zJpDsyVEwbSnv3ZnnXBPaK+xruJtmRgNian2cA 9fbWvtOQOszHexCjbVTNbqmCPfi2TstrzemeI3rELabcd3jH21CYFMVJZFu1SYEQIAc7 No+lyxBFafn99dPa33pv4M8NWaNhOb9HeV4gH/Y72R/11tGZtSSLEd0IjkGQztVaYlUy 268VnbwiMM/O8/oPe7kwdv6SVWARg8PHnqFp/DR3rdDVr6yetXVMN0XoMmNloNDvoVWJ yxfg== 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:cc:to:subject :message-id:date:from:references:in-reply-to:mime-version :dkim-signature:arc-authentication-results; bh=wGy2zbvD5lxRrnl/n9Hf7t//FfQ+2LQvwO2d+QzSxH0=; b=oRVnLip/sXTOcHQRCgbD6Kkcpu+ZclkI6Z59R3H/9VqI/C1MniX8jd0/5fvJ38rrkU vnOhRTCZQwylRmiVH36ehoHOi+lKp3fcVpiziJJWoUWCU3F8Fxm1/ilpBGNAtsf6y48g BC7H+p6Lml9s6ocHFgI17/5nMriSeZBGZqB4h3k1sRH4UxWIaelj0fPjxUzsStE4dmbJ 8PRI0aYytgg5CF2XcSlOxze/4ibi94p7dTAqlkcnbzw6Z0ZpGQWe22aoDrZASET1NzmB 2UDL0xnpgTWd9VI3lbd33QRPRfLcAHRwQ+yRQHdAhFzPNfvDp7KqsucuF5P78qfV1sR4 j53Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=hGe5rYnA; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e5si13779197pgf.646.2018.03.08.16.53.02; Thu, 08 Mar 2018 16:53:16 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=hGe5rYnA; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752051AbeCIAvw (ORCPT + 99 others); Thu, 8 Mar 2018 19:51:52 -0500 Received: from mail-oi0-f67.google.com ([209.85.218.67]:38740 "EHLO mail-oi0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751247AbeCIAvq (ORCPT ); Thu, 8 Mar 2018 19:51:46 -0500 Received: by mail-oi0-f67.google.com with SMTP id h23so5823993oib.5; Thu, 08 Mar 2018 16:51:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=wGy2zbvD5lxRrnl/n9Hf7t//FfQ+2LQvwO2d+QzSxH0=; b=hGe5rYnAgz7pgjl/247Lay/RN65ThDsADpUolnxkGPNkNiosRtkuquTPA2TxdRBqhQ 3j/cNtusd0RfLQ0x1MhdlGi8TreKAgVmhoXJGQ74iCtHSsPCXpEZDRSeeDe6QXwtSoY4 h08JcWppN8ftY26JQv0OeoIUKAyeOacTzKSTdR00WZEf0pxiVDtYHyOEscTSdIzVnKfj CNHbUqG5CyeCWgb/xsKiG/Q+WAbNzegvkTReIlSo3e/Z3edDEFvEAhnkd5B5kgDrPZDX R4BQEc7XdLDWNAoRVqPyttY4MbzvqCk0f77kERGm4BhSN2LUSwgVRVchRgT6EoQy12nb AqYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=wGy2zbvD5lxRrnl/n9Hf7t//FfQ+2LQvwO2d+QzSxH0=; b=RdzM6JtlC3hv10Y4hXbkQD099t6MVsJJiJPxr+O0RXo58aJKLi3QHVVCwfRpjjDVFO W/B6pA1bi1dFtumpjR4WdAmsBOu07phOkXMEB4WNU+d64WB74a/y3ivLTUknvfvxB6yj vP3NBz9dTEgoRW7ZtcE5khwA2JZ1q9lahbhWpEAzIbncDQVd9YNve0d60nqRDQbQCb3y Tjm7omrNNDbY/CcNnqKyt5fDhpZk8hu0SaVrfCyxQ9j+BDMjW51LmZt+EB6faabVjAQ6 pfvcInmbu290cEYmbFeBAxZqqZhi87qaIk5zpCwdgszq8yxSo/fmWJkJCqXh7L594uY8 Un8A== X-Gm-Message-State: APf1xPCzvoomDfzTeXasEnNE7l1/pZH1Ir3ZmJqT6d4Q4CJ1dYSOygjD 8tNWeHgTy/RxsJmv716Laj16fBv2NTkY9t9G0gk= X-Received: by 10.202.186.197 with SMTP id k188mr18349359oif.119.1520556705275; Thu, 08 Mar 2018 16:51:45 -0800 (PST) MIME-Version: 1.0 Received: by 10.74.208.10 with HTTP; Thu, 8 Mar 2018 16:51:44 -0800 (PST) In-Reply-To: <20180308204029.GK12290@flask> References: <1519897782-8124-1-git-send-email-wanpengli@tencent.com> <1519897782-8124-2-git-send-email-wanpengli@tencent.com> <20180308204029.GK12290@flask> From: Wanpeng Li Date: Fri, 9 Mar 2018 08:51:44 +0800 Message-ID: Subject: Re: [PATCH 2/3] KVM: X86: Provides userspace with a capability to not intercept HLT To: =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= Cc: LKML , kvm , Paolo Bonzini Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 2018-03-09 4:40 GMT+08:00 Radim Kr=C4=8Dm=C3=A1=C5=99 : > 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=C4=8Dm=C3=A1=C5=99 >> 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. Agreed. > >> + >> control->iopm_base_pa =3D __sme_set(iopm_base); >> control->msrpm_base_pa =3D __sme_set(__pa(svm->msrpm)); >> control->int_ctl =3D 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 b= een >> + * advanced. >> + */ >> + if (kvm_hlt_in_guest(vcpu->kvm) && >> + vmcs_read32(GUEST_ACTIVITY_STATE) =3D=3D GUEST_ACT= IVITY_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(). Will do in v2. Regards, Wanpeng Li