Received: by 10.223.185.116 with SMTP id b49csp767330wrg; Sat, 10 Feb 2018 19:30:53 -0800 (PST) X-Google-Smtp-Source: AH8x224Rcbd0naQp6+xRYOJhylBqnKPKs745vpn4t005hheHZtKfBIaNeo2Ts2MAuhqa38iN5co1 X-Received: by 2002:a17:902:930a:: with SMTP id bc10-v6mr7140780plb.19.1518319853635; Sat, 10 Feb 2018 19:30:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518319853; cv=none; d=google.com; s=arc-20160816; b=0/MRc1a7akiVYw1kVnUrquPx6ggSMQiPRxxqo7JXlZUp0epuuwOf349m0C1ucDltLW 9TLIpJ9TCUVx3P8zyjZiZ4fDdH72k+dDobxUGmZB2bMVmptrlDbKynRTyEh9+q8h6fAJ TaG7k+vtUHnMhNp9/1cCag3vwcjkY3yyPxvEuqAdY8K0Wg9ZCEbMEZ6sPV3mbWk/8HUL kAUzcOddNMHuXWxFSMP79/IZqSqJ/E0vOIsh+kiN7K+ACmKTPoOSox9jVpeujtnTzHeN 99SS/d4R8yPnaj9eD/b7FTWoRW/J6Rw3Hk8xVR53aaBa+88KT59tMbRh4y/ZO/9fnWuZ 1AFA== 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:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=luGGhAmTLfoIsv89MXx19L6hLW/UVI5FgEeaRXstZ+4=; b=kFfMz39kmuArJZWtybs7Y0CGCKYIcp/DOYpwSXsx0w/gz3l5WPYfDrcybEtpy8ToHO 6bUDmJt/yrXGlCcaXAjrkGgGYlKva8ghno3R1SYOt+24kvplja9gswpD3AxW1anVfp6o 4kQBFJ1AHZ9z6MYx9iPU0Fd51uOqQJrQkbSx0MezEp2U7EiXg4uj0Mr3y7Lr3zeZcsTS zVmLn1GMDfsaMWtn3XhxTdVeSkGQrPhUgVam/xW13vcjvb+TSxL95iJoXecynaC6+STo MPtSkBcCFMzUi8J9Swn6H2lXGTbnsWtNOCueCPvZJCbHJflyMDymjznby1XdVEC56eY7 klhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=buOellp1; 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 l63-v6si3906025plb.565.2018.02.10.19.30.39; Sat, 10 Feb 2018 19:30:53 -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=buOellp1; 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 S1752554AbeBKD34 (ORCPT + 99 others); Sat, 10 Feb 2018 22:29:56 -0500 Received: from mail-pf0-f196.google.com ([209.85.192.196]:36303 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752268AbeBKD3x (ORCPT ); Sat, 10 Feb 2018 22:29:53 -0500 Received: by mail-pf0-f196.google.com with SMTP id p8so700020pff.3; Sat, 10 Feb 2018 19:29:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=luGGhAmTLfoIsv89MXx19L6hLW/UVI5FgEeaRXstZ+4=; b=buOellp1KSK0X+7ZFav5q/88uky0kco37X8lSQNicb2u1Foy9poJdJgNvLxMx+wJBl xNa3RNS4kjE2Go4Q/7tYnWtRuCiALEgEnSf5oLoPUKWlHdhzmkUw5dX5xPTL2rGiS4jZ x+hD1HSrlEwN/tD+l6CQG6A9ceCzzj49HAJ4GEFzXPGqCHxq16kwJwKqqfYTZjn1cmH7 l098+9EYQXXC7niqAdUc9e1rT9EK5zLPXzODKGcT+GBIaQtWqU75jiYwESYN1+dYTIGw zKqHf9gvxYG++hAGdVIhQ63xiW6qyF3w3YFOVgTWgI7w+/yKgJZRPNcj3gy/xXr3mWd+ +ZcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=luGGhAmTLfoIsv89MXx19L6hLW/UVI5FgEeaRXstZ+4=; b=sXtuCI2ia0SBtCj1uMs7XzOV6GUetnJpDx46gvLC71A5kGmEZY7GtNHWIBPtu2HSHp BhufKC+d353RBAPasgIgLPjnsrnpBwvoNGVXB7oHtIFPBEzQ57mQ/ydoOePkYQygnLw1 SFLDV+Ux8Ue262cjmby/OU1S7/eSLbf60B4MN+IiVjspoJCt1sIYCHgWfIx771XZR/R0 NowMpCPVEbLXj7L6SryCGepvRcvqQHcEd7qBOA2GIodV2Htuji9yOUnQTvTm57Lj7AzZ VVzho7CYpipKlk2gPaGXYIPY6gB+A4QVeGT7erV+bLpHP/u3yYkfsdViJIwmCtCgKl12 LEUA== X-Gm-Message-State: APf1xPCiJ3WtSLDP3bhfeILwgREjGDPibhFAqHumiObNzI8kcsckznth HvlJiS0rJM5gmaPKlMJfNLSf+A== X-Received: by 10.99.113.85 with SMTP id b21mr2209433pgn.305.1518319792862; Sat, 10 Feb 2018 19:29:52 -0800 (PST) Received: from localhost.localdomain ([203.205.141.123]) by smtp.googlemail.com with ESMTPSA id a19sm18752504pfh.170.2018.02.10.19.29.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 10 Feb 2018 19:29:52 -0800 (PST) From: Wanpeng Li X-Google-Original-From: Wanpeng Li To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Eduardo Habkost Subject: [PATCH v3 1/3] KVM: Introduce dedicated vCPUs hint KVM_HINTS_DEDICATED Date: Sun, 11 Feb 2018 11:29:44 +0800 Message-Id: <1518319786-1466-2-git-send-email-wanpengli@tencent.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1518319786-1466-1-git-send-email-wanpengli@tencent.com> References: <1518319786-1466-1-git-send-email-wanpengli@tencent.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Wanpeng Li This patch introduces dedicated vCPUs hint KVM_HINTS_DEDICATED, guest checks this feature bit to determine if they run on dedicated vCPUs, allowing optimizations. Cc: Paolo Bonzini Cc: Radim Krčmář Cc: Eduardo Habkost Signed-off-by: Wanpeng Li --- Documentation/virtual/kvm/cpuid.txt | 12 +++++++++++- arch/mips/include/asm/kvm_para.h | 5 +++++ arch/powerpc/include/asm/kvm_para.h | 5 +++++ arch/s390/include/asm/kvm_para.h | 5 +++++ arch/x86/include/asm/kvm_para.h | 6 ++++++ arch/x86/include/uapi/asm/kvm_para.h | 8 ++++++-- arch/x86/kernel/kvm.c | 5 +++++ include/asm-generic/kvm_para.h | 5 +++++ include/linux/kvm_para.h | 5 +++++ 9 files changed, 53 insertions(+), 3 deletions(-) diff --git a/Documentation/virtual/kvm/cpuid.txt b/Documentation/virtual/kvm/cpuid.txt index dcab6dc..e283b88 100644 --- a/Documentation/virtual/kvm/cpuid.txt +++ b/Documentation/virtual/kvm/cpuid.txt @@ -23,7 +23,7 @@ This function queries the presence of KVM cpuid leafs. function: define KVM_CPUID_FEATURES (0x40000001) -returns : ebx, ecx, edx = 0 +returns : ebx, ecx eax = and OR'ed group of (1 << flag), where each flags is: @@ -62,3 +62,13 @@ KVM_FEATURE_CLOCKSOURCE_STABLE_BIT || 24 || host will warn if no guest-side || || per-cpu warps are expected in || || kvmclock. ------------------------------------------------------------------------------ + + edx = and OR'ed group of (1 << flag), where each flags is: + + +flag || value || meaning +================================================================================ +KVM_HINTS_DEDICATED || 0 || guest checks this feature bit + || || to determine if they run on dedicated + || || vCPUs, allowing optimizations +--------------------------------------------------------------------------------- diff --git a/arch/mips/include/asm/kvm_para.h b/arch/mips/include/asm/kvm_para.h index 60b1aa0..bd1f4ee 100644 --- a/arch/mips/include/asm/kvm_para.h +++ b/arch/mips/include/asm/kvm_para.h @@ -94,6 +94,11 @@ static inline unsigned int kvm_arch_para_features(void) return 0; } +static inline unsigned int kvm_arch_hint_features(void) +{ + return 0; +} + #ifdef CONFIG_MIPS_PARAVIRT static inline bool kvm_para_available(void) { diff --git a/arch/powerpc/include/asm/kvm_para.h b/arch/powerpc/include/asm/kvm_para.h index 336a91a..8e58c00 100644 --- a/arch/powerpc/include/asm/kvm_para.h +++ b/arch/powerpc/include/asm/kvm_para.h @@ -61,6 +61,11 @@ static inline unsigned int kvm_arch_para_features(void) return r; } +static inline unsigned int kvm_arch_hint_features(void) +{ + return 0; +} + static inline bool kvm_check_and_clear_guest_paused(void) { return false; diff --git a/arch/s390/include/asm/kvm_para.h b/arch/s390/include/asm/kvm_para.h index 74eeec9..b2c935c 100644 --- a/arch/s390/include/asm/kvm_para.h +++ b/arch/s390/include/asm/kvm_para.h @@ -193,6 +193,11 @@ static inline unsigned int kvm_arch_para_features(void) return 0; } +static inline unsigned int kvm_arch_hint_features(void) +{ + return 0; +} + static inline bool kvm_check_and_clear_guest_paused(void) { return false; diff --git a/arch/x86/include/asm/kvm_para.h b/arch/x86/include/asm/kvm_para.h index 7b407dd..2c7d368 100644 --- a/arch/x86/include/asm/kvm_para.h +++ b/arch/x86/include/asm/kvm_para.h @@ -88,6 +88,7 @@ static inline long kvm_hypercall4(unsigned int nr, unsigned long p1, #ifdef CONFIG_KVM_GUEST bool kvm_para_available(void); unsigned int kvm_arch_para_features(void); +unsigned int kvm_arch_hint_features(void); void kvm_async_pf_task_wait(u32 token, int interrupt_kernel); void kvm_async_pf_task_wake(u32 token); u32 kvm_read_and_reset_pf_reason(void); @@ -115,6 +116,11 @@ static inline unsigned int kvm_arch_para_features(void) return 0; } +static inline unsigned int kvm_arch_hint_features(void) +{ + return 0; +} + static inline u32 kvm_read_and_reset_pf_reason(void) { return 0; diff --git a/arch/x86/include/uapi/asm/kvm_para.h b/arch/x86/include/uapi/asm/kvm_para.h index 7a2ade4..e8f5dfb 100644 --- a/arch/x86/include/uapi/asm/kvm_para.h +++ b/arch/x86/include/uapi/asm/kvm_para.h @@ -10,8 +10,10 @@ */ #define KVM_CPUID_SIGNATURE 0x40000000 -/* This CPUID returns a feature bitmap in eax. Before enabling a particular - * paravirtualization, the appropriate feature bit should be checked. +/* This CPUID returns two feature bitmaps in eax, edx. Before enabling + * a particular paravirtualization, the appropriate feature bit should + * be checked in eax. The performance hint feature bit should be checked + * in edx. */ #define KVM_CPUID_FEATURES 0x40000001 #define KVM_FEATURE_CLOCKSOURCE 0 @@ -27,6 +29,8 @@ #define KVM_FEATURE_PV_UNHALT 7 #define KVM_FEATURE_PV_TLB_FLUSH 9 +#define KVM_HINTS_DEDICATED 0 + /* The last 8 bits are used to indicate how to interpret the flags field * in pvclock structure. If no bits are set, all flags are ignored. */ diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c index 4e37d1a..77a0723 100644 --- a/arch/x86/kernel/kvm.c +++ b/arch/x86/kernel/kvm.c @@ -604,6 +604,11 @@ unsigned int kvm_arch_para_features(void) return cpuid_eax(kvm_cpuid_base() | KVM_CPUID_FEATURES); } +unsigned int kvm_arch_hint_features(void) +{ + return cpuid_edx(kvm_cpuid_base() | KVM_CPUID_FEATURES); +} + static uint32_t __init kvm_detect(void) { return kvm_cpuid_base(); diff --git a/include/asm-generic/kvm_para.h b/include/asm-generic/kvm_para.h index 18c6abe..93e133d 100644 --- a/include/asm-generic/kvm_para.h +++ b/include/asm-generic/kvm_para.h @@ -19,6 +19,11 @@ static inline unsigned int kvm_arch_para_features(void) return 0; } +static inline unsigned int kvm_arch_hint_features(void) +{ + return 0; +} + static inline bool kvm_para_available(void) { return false; diff --git a/include/linux/kvm_para.h b/include/linux/kvm_para.h index 51f6ef2..30503b7 100644 --- a/include/linux/kvm_para.h +++ b/include/linux/kvm_para.h @@ -9,4 +9,9 @@ static inline bool kvm_para_has_feature(unsigned int feature) { return !!(kvm_arch_para_features() & (1UL << feature)); } + +static inline bool kvm_hint_has_feature(unsigned int feature) +{ + return !!(kvm_arch_hint_features() & (1UL << feature)); +} #endif /* __LINUX_KVM_PARA_H */ -- 2.7.4