Received: by 10.223.185.116 with SMTP id b49csp43091wrg; Thu, 8 Mar 2018 12:33:26 -0800 (PST) X-Google-Smtp-Source: AG47ELtJ+ilXogKub2AKJ/8uPmkU+td2mKidnaKZYuiODrKqtd6CliK7jiTiL4VWZBEvQdwRDPiw X-Received: by 2002:a17:902:6909:: with SMTP id j9-v6mr24590627plk.447.1520541206269; Thu, 08 Mar 2018 12:33:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520541206; cv=none; d=google.com; s=arc-20160816; b=DkdMxVD5h4DPjqyn1pJ534IJrzy+TsPPER1wpRewvjA5+E4ZJilUgUOH/XS/VrxjNP XzQ8lTNj7SWP0uSB8cpmCPgTaqFvgMUHkZ3WgO5R6P1RiEJGMvo6it9rYAdMrWfJUUg/ 8WAOCfeTp7qMkCK7jH5AB+1omHmNGOFEBg0J6SQo9qxPsKIrolqWAjUoNx+26+phG/Qq TpgXAKgwhHO6jO6o6U3G6XhYm7hRWYFz7IvJI6kbil/Tl2o+6b7unDeOFL0Lf9JTb3HM 2w7YHXKTVD4xTl5302vIXZO//OdJKbW6seW3sDlYNbZ15EKUvt/i/hi63SCuQ/TMzFZb wI4Q== 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=71JfWjPWsuH+1c5REqKOP+QazFCeYMIZ1PsM2ryoA0s=; b=A0h+XBRq7CNdRARSKomRgTxY3ZTAVMpa6W5KMbFzo+0YwJlE8SpDY6xfg+b/2T5ARn AP2HZ91+mIWmItaXPLEm79lwZCCQcke4HPh/FSZmtRcXdu8sW9ph4udl06evIAs6fKrL S271l76heG4UT2VWDCj1F3MEwdA5874WMYfGNMD0ZL8PwWiHatIjWHWK0/BXxpVRZxkX 2Bm7kh3+YvG6plzlQuRyvbmk6UPUKlTjHVyalSwjone3qFUf4ZrjAFMC0YD2E/uE0EM1 o5QiwRmgLilgb+pweXP4184lgpzCX+WQugoO6NWsuzfQhCjGI7lHaKcDb8JQiXRMM+PA 66fQ== 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 62-v6si15361228ple.491.2018.03.08.12.33.11; Thu, 08 Mar 2018 12:33:26 -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 S1751072AbeCHUcP (ORCPT + 99 others); Thu, 8 Mar 2018 15:32:15 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:59102 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750761AbeCHUcN (ORCPT ); Thu, 8 Mar 2018 15:32:13 -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 08C147C6CC; Thu, 8 Mar 2018 20:32:13 +0000 (UTC) Received: from flask (unknown [10.43.2.80]) by smtp.corp.redhat.com (Postfix) with SMTP id 4442C2026E03; Thu, 8 Mar 2018 20:32:11 +0000 (UTC) Received: by flask (sSMTP sendmail emulation); Thu, 08 Mar 2018 21:31:32 +0100 Date: Thu, 8 Mar 2018 21:31:32 +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 1/3] KVM: X86: Provides userspace with a capability to not intercept MWAIT Message-ID: <20180308203132.GJ12290@flask> References: <1519897782-8124-1-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-1-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.2]); Thu, 08 Mar 2018 20:32:13 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Thu, 08 Mar 2018 20:32:13 +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 > > Allowing a guest to execute MWAIT without interception enables a guest > to put a (physical) CPU into a power saving state, where it takes > longer to return from than what may be desired by the host. > > Don't give a guest that power over a host by default. (Especially, > since nothing prevents a guest from using MWAIT even when it is not > advertised via CPUID.) > > Cc: Paolo Bonzini > Cc: Radim Krčmář > Signed-off-by: Wanpeng Li > --- > diff --git a/Documentation/virtual/kvm/api.txt b/Documentation/virtual/kvm/api.txt > @@ -1041,7 +1041,8 @@ On systems that do not support this ioctl, it always fails. On systems that > do support it, it only works for extensions that are supported for enablement. > > To check if a capability can be enabled, the KVM_CHECK_EXTENSION ioctl should > -be used. > +be used. Blindly passing the KVM_CHECK_EXTENSION result to KVM_ENABLE_CAP is > +a valid thing to do when vCPUs are associated to dedicated physical CPUs. This is not true even for x86 KVM_CAP_SPLIT_IRQCHIP and neither is is a need to limit ourselves. Just leave it be. > +7.13 KVM_CAP_X86_DISABLE_EXITS > + > +Architectures: x86 > +Parameters: args[0] defines which exits are disabled > +Returns: 0 on success, -EINVAL when args[0] contains invalid exits > + > +Valid exits in args[0] are > + > +#define KVM_X86_DISABLE_EXITS_MWAIT (1 << 0) > + > +Enabling this capability on a VM provides userspace with a way to no > +longer intercepts some instructions for improved latency in some > +workloads. Not enable KVM_FEATURE_PV_UNHALT if you block HLT. The last sentence belong to the patch that enables HLT. KVM could in theory handle the case (although it makes no sense), so if it doesn't currently work, please add a check to kvm_update_cpuid() that forbids KVM_FEATURE_PV_UNHALT when halt exits are disabled. Also, it would be nicer to write that as "Do not enable KVM_FEATURE_PV_UNHALT if you disable HLT exits." > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > @@ -2780,9 +2780,15 @@ static int msr_io(struct kvm_vcpu *vcpu, struct kvm_msrs __user *user_msrs, > return r; > } > > +static inline bool kvm_mwait_can_in_guest(void) I think kvm_can_mwait_in_guest would be a better name. > +{ > + return boot_cpu_has(X86_FEATURE_MWAIT) && > + !boot_cpu_has_bug(X86_BUG_MONITOR); > +} > + > diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h > index b91215d..cd1215e 100644 > --- a/arch/x86/kvm/x86.h > +++ b/arch/x86/kvm/x86.h > @@ -2,8 +2,6 @@ > #ifndef ARCH_X86_KVM_X86_H > #define ARCH_X86_KVM_X86_H > > -#include > -#include > #include > #include > #include "kvm_cache_regs.h" > @@ -264,10 +262,12 @@ static inline u64 nsec_to_cycles(struct kvm_vcpu *vcpu, u64 nsec) > __rem; \ > }) > > -static inline bool kvm_mwait_in_guest(void) > +#define KVM_X86_DISABLE_EXITS_MWAIT (1 << 0) > +#define KVM_X86_DISABLE_VALID_EXITS (KVM_X86_DISABLE_EXITS_MWAIT) > + > +static inline bool kvm_mwait_in_guest(struct kvm *kvm) > { > - return boot_cpu_has(X86_FEATURE_MWAIT) && > - !boot_cpu_has_bug(X86_BUG_MONITOR); > + return kvm->arch.mwait_in_guest; With this nice variable, the wrapper actually makes the code harder to read. Please use kvm->arch.mwait_in_guest directly (and the same for the other two future exits), thanks.