Received: by 10.223.185.116 with SMTP id b49csp2874394wrg; Mon, 12 Feb 2018 17:07:45 -0800 (PST) X-Google-Smtp-Source: AH8x224sHLjqZjN6DaTaAlhBW82KIGDNztCAmaA1GfIwYjGdT8FzfARmtzAW+Hsfqnp8xfGvF7eF X-Received: by 2002:a17:902:5a88:: with SMTP id r8-v6mr9114317pli.426.1518484065187; Mon, 12 Feb 2018 17:07:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518484065; cv=none; d=google.com; s=arc-20160816; b=nfdlXktFz/KFBVS8SSeyc/c6MNHiRSzvl9i7a55k7Tn1QEDd7ulItnHN6jBbciSs0F kiPoogc+pbwpY4tJ6kmB8HRv39GwIq7a/FH6Mv4d6COAj7m+c7ctJC/0+bmclJgvIVGl no4w3jrdPiVAAAgfDdkao9BiHpGnW2xnVCQumBhLhGy2LnIG12d7u/Khi5QNumeMjgkH xBL94jhZBj836DSvpiseOa8Sy9ZN/j759BfNGsaInSJVflbOgjXZICug5aV8hKpYAv/t NHF3OSBoAzFQk4O1E8Q+SEJ7TL+m9N+spkirxU7RFnPbX9nGc4mQeOM2Lz0j5gukFYGm vgLA== 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=12st2cyr3PRlK5zrb6OsobkS+xr0US/60N9iGXIO4xw=; b=0UnrBjXDVADe45N65cvY5yr9gJzFm8zBWkWha/NZTdYkiu+qudhPUjcRZEZxFdeS1U /HuW61YGg4UXmDl75Fbk6mOqEJTRMDb2Cgsb8h9tXFvZ6IF0W9i1ZNe3hajS7755iOF6 Az7WDpKvheYEHfL1laebGYjD7cmzVn4UP5JcwA2x2RK1sR6UuY4+64Bs1qaI9T4frs7K MOqppJ2YxC8rB0m9sXoNxhHxmpHgDDxClf21LstFFbjmugMudoLgzJwaG4llFmwd6Y4k g0oERVhk4YdnZ6d+GP9qm6W/3l/SzZuaC8JLuM9Omqwbb0dnRoG+A9GdisY/tUDri/9Z DDDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=TIpUMbwB; 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 z8-v6si471858plk.316.2018.02.12.17.07.30; Mon, 12 Feb 2018 17:07:45 -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=TIpUMbwB; 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 S933131AbeBMBFx (ORCPT + 99 others); Mon, 12 Feb 2018 20:05:53 -0500 Received: from mail-pg0-f68.google.com ([74.125.83.68]:38283 "EHLO mail-pg0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933093AbeBMBFt (ORCPT ); Mon, 12 Feb 2018 20:05:49 -0500 Received: by mail-pg0-f68.google.com with SMTP id l24so2678681pgc.5; Mon, 12 Feb 2018 17:05:49 -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=12st2cyr3PRlK5zrb6OsobkS+xr0US/60N9iGXIO4xw=; b=TIpUMbwBp0zo3ZzH3m7dSOqw5aoI8jpQMGs62vKmXuptzlaQhzghCHCefd/5Qu2lAg vO5+IiFvrAKVy9VN5D4iSTFb68J8/QzIQ0ICq/qdvDI21UddP28c0yJrdGFMtTT0ysct WYHTV6lGXHlWY+sii/kjJEPijnlXIwwT450Wvj6V96Bp02Cor+FxybqZfnL9jn1KHBgq IuWT847nhLAST27Q/4ZSMr4+hqOiwm8eMvEvfVSnJ/PCFhEFpR1Az4HKTkSI+Q4+EU7C EP0vbZJRz73IRWfV52TLmjoBjDkEw1SJXLt/pJYS1QONWoNd8sTWGhHcmGYeN3v3dOuM OmGA== 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=12st2cyr3PRlK5zrb6OsobkS+xr0US/60N9iGXIO4xw=; b=UsykVpBZfkKFebRFAIjnmFAnjOGDIsqT/Af7t8oJHLlRX1pHsfEbAs+gv7p7I6VfQv 3oovl9JntZPEj5jzAmxRmpfHHho5Lx1q00vrWyeAi3hCgLzPBg6b5c5nJ1mRDP4S4spR u8Mzj7MZc/6I8gafSQhL8AGAKXsu34DoE7o0+m/V9IKZUqRZScCPy/UsB6AXa5fFyszC 23YLzdePqBGoEVYIfB9MV6UTqnQjw5uSlkS+z8Up12B2P3dLFOc+vXRDIiApTPpFISLm V0rhOjQT0IEY9e7Ln6bXrI5oYhJDR2dG1JmbiHYgLc9nIK/h06Xkop6ItL9SApsEWNYl 0ZMQ== X-Gm-Message-State: APf1xPD35mv9+tNO9RN6VgAN5F0Z5U+AcjY58UMNPNp2Scrb878Du6TL qPK+m9PAE//OpUyp6SZAorlVMg== X-Received: by 10.98.14.208 with SMTP id 77mr13035403pfo.99.1518483948921; Mon, 12 Feb 2018 17:05:48 -0800 (PST) Received: from localhost.localdomain ([203.205.141.123]) by smtp.googlemail.com with ESMTPSA id p4sm24500416pgn.81.2018.02.12.17.05.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 12 Feb 2018 17:05:48 -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 v4 1/3] KVM: Introduce dedicated vCPUs hint KVM_HINTS_DEDICATED Date: Tue, 13 Feb 2018 09:05:40 +0800 Message-Id: <1518483942-14741-2-git-send-email-wanpengli@tencent.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1518483942-14741-1-git-send-email-wanpengli@tencent.com> References: <1518483942-14741-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(vCPU pinning, and there is no vCPU over-commitment) 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 | 15 +++++++++++++-- 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, 55 insertions(+), 4 deletions(-) diff --git a/Documentation/virtual/kvm/cpuid.txt b/Documentation/virtual/kvm/cpuid.txt index dcab6dc..1600768 100644 --- a/Documentation/virtual/kvm/cpuid.txt +++ b/Documentation/virtual/kvm/cpuid.txt @@ -23,8 +23,8 @@ This function queries the presence of KVM cpuid leafs. function: define KVM_CPUID_FEATURES (0x40000001) -returns : ebx, ecx, edx = 0 - eax = and OR'ed group of (1 << flag), where each flags is: +returns : ebx, ecx + eax = an OR'ed group of (1 << flag), where each flags is: flag || value || meaning @@ -62,3 +62,14 @@ KVM_FEATURE_CLOCKSOURCE_STABLE_BIT || 24 || host will warn if no guest-side || || per-cpu warps are expected in || || kvmclock. ------------------------------------------------------------------------------ + + edx = an 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 there is vCPU pinning + || || and there is no vCPU over-commitment, + || || 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