From patchwork Fri Feb 9 12:24:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wanpeng Li X-Patchwork-Id: 10208927 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id DA517602D8 for ; Fri, 9 Feb 2018 12:25:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D36D929811 for ; Fri, 9 Feb 2018 12:25:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C809429816; Fri, 9 Feb 2018 12:25:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3549029811 for ; Fri, 9 Feb 2018 12:25:16 +0000 (UTC) Received: from localhost ([::1]:43387 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ek7jv-0008Gz-3i for patchwork-qemu-devel@patchwork.kernel.org; Fri, 09 Feb 2018 07:25:15 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58372) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ek7jC-0007mI-5v for qemu-devel@nongnu.org; Fri, 09 Feb 2018 07:24:31 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ek7jA-0003OY-SC for qemu-devel@nongnu.org; Fri, 09 Feb 2018 07:24:30 -0500 Received: from mail-oi0-x243.google.com ([2607:f8b0:4003:c06::243]:37387) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ek7jA-0003Ku-Mo for qemu-devel@nongnu.org; Fri, 09 Feb 2018 07:24:28 -0500 Received: by mail-oi0-x243.google.com with SMTP id t78so5987871oih.4 for ; Fri, 09 Feb 2018 04:24:27 -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; bh=4vW+KhGjUWs1DtqZQ0ThlNNko5f6tea0l+i2Gyfsrq8=; b=jjcNueyVz63EvU5jyvL/STPDZQ2vBuMC3PI4gfsJ3jPtPLBS8E/o/s8U1YInLtxogV 9AAb+PMSzZpYHDS7+zbrpt1Bfbgp2hmVJgP/zLDDW3pjRcY7N7wzkluSqr8vdxy8Dgf9 gZe0Sadfyk3yl99l+aLp/tULxKRwHKxWJXYHDnJQg94IfXyilXLu0V6G0aq21LN+J0GN TIkuNxGPodNNutucoAGmDNYaz88TLeQWp1tBe7oxxefj/JBzsfwrWMjsn7v4JFK4VwSa cKXCmdK2b0IvV/9GxuhRJ0hl7kiuJ+/5M4ZoUxJu9bUFVOAUXBIupCQJbnkJdQ33zHJ2 wcYg== 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; bh=4vW+KhGjUWs1DtqZQ0ThlNNko5f6tea0l+i2Gyfsrq8=; b=UAYi598wu5f0Egmtk1sJumqpf6HA1YerKvfC5aXNqDSr4KlbIXAwomjvs0GKyWPmza z4AF1JT2rLEmpoBXo0YzruUeKW8gw36ATjkNuJq+Uf6auo4nhRsQNAoI13SYGNWJj5Tx 1krvAaA9lNPuG5p/mxf20o4oVDpi8Pk5bCb8S1U5CquiXe1RloNFYbO9xQbR0dcnhAW0 FpESEHnw4KVaATcX0bH5JBEhv5mNsfwfFQHhG16t8hHdoeHfgKfgyMft5SvbKD2iPSn0 cJUT5RHB9LBbFCntJtm0IJBd72V1dAUfmeKP0Fm5qokSTAbzjGWkLUmT/9vmBQmbIT1X EJHA== X-Gm-Message-State: APf1xPB9GToeeImBgS3zUvdiieVd8IoFwSoJT97tyzlpB4SlgoD4j8RK x8+jcL85gxRuaNQBi/iZdrL1b+NL1RA1J5luFTU= X-Google-Smtp-Source: AH8x2258UlBST/H0K9lsebb5AhDq4+Yeunli7mbt7G1Vbp2RuP82vWdeDtducEb1nezGgudt4amji/BF059lvujhjYE= X-Received: by 10.202.91.84 with SMTP id p81mr1560794oib.232.1518179066429; Fri, 09 Feb 2018 04:24:26 -0800 (PST) MIME-Version: 1.0 Received: by 10.74.10.129 with HTTP; Fri, 9 Feb 2018 04:24:26 -0800 (PST) In-Reply-To: <20180209114615.GG13981@localhost.localdomain> References: <1518083060-5881-1-git-send-email-wanpengli@tencent.com> <20180208181207.GB13981@localhost.localdomain> <20180209114615.GG13981@localhost.localdomain> From: Wanpeng Li Date: Fri, 9 Feb 2018 20:24:26 +0800 Message-ID: To: Eduardo Habkost X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4003:c06::243 Subject: Re: [Qemu-devel] [PATCH] target-i386: adds PV_DEDICATED hint CPUID feature bit X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , "qemu-devel@nongnu.org Developers" , kvm , =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 2018-02-09 19:46 GMT+08:00 Eduardo Habkost : > On Fri, Feb 09, 2018 at 09:41:41AM +0100, Paolo Bonzini wrote: >> On 08/02/2018 19:12, Eduardo Habkost wrote: >> > On Thu, Feb 08, 2018 at 05:44:20PM +0800, Wanpeng Li wrote: >> >> From: Wanpeng Li >> >> >> >> Add PV_DEDICATED hint cpuid feature bit. >> >> >> > [...] >> >> diff --git a/target/i386/cpu.c b/target/i386/cpu.c >> >> index d70954b..cf48931 100644 >> >> --- a/target/i386/cpu.c >> >> +++ b/target/i386/cpu.c >> >> @@ -4076,6 +4076,9 @@ static int x86_cpu_filter_features(X86CPU *cpu) >> >> x86_cpu_get_supported_feature_word(w, false); >> >> uint32_t requested_features = env->features[w]; >> >> env->features[w] &= host_feat; >> >> + if (cpu->pv_dedicated && (w == FEAT_KVM)) { >> >> + env->features[w] |= CPUID_PV_DEDICATED; >> >> + } >> > >> > Why do this trick here instead of just adding "pv-dedicated" to >> > feature_word_info[FEAT_KVM].feat_names? >> >> I think because it can be added independent of KVM_GET_SUPPORTED_CPUID. > > If QEMU knows it can be enabled if outside GET_SUPPORTED_CPUID, > kvm_arch_get_supported_cpuid() can return it as supported. The guest fails to detect the new cpuid this time. /* fallback for older kernels */ Regards, Wanpeng Li diff --git a/target/i386/cpu.c b/target/i386/cpu.c index d70954b..e2974ad 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -358,6 +358,20 @@ static FeatureWordInfo feature_word_info[FEATURE_WORDS] = { .cpuid_eax = KVM_CPUID_FEATURES, .cpuid_reg = R_EAX, .tcg_features = TCG_KVM_FEATURES, }, + [FEAT_KVM_HINTS] = { + .feat_names = { + "hint-dedicated", NULL, NULL, NULL, + NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, + }, + .cpuid_eax = KVM_CPUID_FEATURES, .cpuid_reg = R_EDX, + .tcg_features = TCG_KVM_FEATURES, + }, [FEAT_HYPERV_EAX] = { .feat_names = { NULL /* hv_msr_vp_runtime_access */, NULL /* hv_msr_time_refcount_access */, diff --git a/target/i386/cpu.h b/target/i386/cpu.h index f91e37d..9f73692 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -475,6 +475,7 @@ typedef enum FeatureWord { FEAT_8000_0008_EBX, /* CPUID[8000_0008].EBX */ FEAT_C000_0001_EDX, /* CPUID[C000_0001].EDX */ FEAT_KVM, /* CPUID[4000_0001].EAX (KVM_CPUID_FEATURES) */ + FEAT_KVM_HINTS, /* CPUID[4000_0001].EDX */ FEAT_HYPERV_EAX, /* CPUID[4000_0003].EAX */ FEAT_HYPERV_EBX, /* CPUID[4000_0003].EBX */ FEAT_HYPERV_EDX, /* CPUID[4000_0003].EDX */ @@ -670,6 +671,8 @@ typedef uint32_t FeatureWordArray[FEATURE_WORDS]; #define CPUID_7_0_EDX_AVX512_4FMAPS (1U << 3) /* AVX512 Multiply Accumulation Single Precision */ #define CPUID_7_0_EDX_SPEC_CTRL (1U << 26) /* Speculation Control */ +#define KVM_HINTS_DEDICATED (1U << 0) + #define CPUID_8000_0008_EBX_IBPB (1U << 12) /* Indirect Branch Prediction Barrier */ #define CPUID_XSAVE_XSAVEOPT (1U << 0) diff --git a/target/i386/kvm.c b/target/i386/kvm.c index ad4b159..a0aad80 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -383,6 +383,9 @@ uint32_t kvm_arch_get_supported_cpuid(KVMState *s, uint32_t function, if (!kvm_irqchip_in_kernel()) { ret &= ~(1U << KVM_FEATURE_PV_UNHALT); } + } else if (function == KVM_CPUID_FEATURES && reg == R_EDX) { + ret |= KVM_HINTS_DEDICATED; + found = 1; }