From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CCCB7C433ED for ; Thu, 22 Apr 2021 07:02:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 87D0E61403 for ; Thu, 22 Apr 2021 07:02:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230404AbhDVHDY (ORCPT ); Thu, 22 Apr 2021 03:03:24 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:41933 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229629AbhDVHDX (ORCPT ); Thu, 22 Apr 2021 03:03:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1619074967; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=U1sBIWc97pwUoI/Y/7htamKNpDUssIIcTnKBNjle2Og=; b=bS/r7X2ZtS35AxyCjt2XmKu3FN5Qu4wjNHzFlu0/mrmw/orhaL4AMMs8mH1DlJ0I7v/juT GRJSpPyX3sVCJOUO/kZHyrJJfvuT+eUV4xk4C1Mqubm0VZN5d2p5gtYhKyzOUvl3cos2or SO2Ese9g6bm33YpHBXDzipPBbTHPiUo= Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-249-D0DmNPObOyO3AM4PS_N7IQ-1; Thu, 22 Apr 2021 03:02:13 -0400 X-MC-Unique: D0DmNPObOyO3AM4PS_N7IQ-1 Received: by mail-ed1-f70.google.com with SMTP id l22-20020a0564021256b0290384ebfba68cso12374507edw.2 for ; Thu, 22 Apr 2021 00:02:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=U1sBIWc97pwUoI/Y/7htamKNpDUssIIcTnKBNjle2Og=; b=EalOo+eIN5OYn4b1MZBPg0NVQ29DNpmq5zat/uxbBOdsdv3oCmiXstk9ckDy5sY3cz 0gykJ7CVn/rjD6fefTmhuNUedYmG/fg3UhTBoMoi3A93C0sfVKMjU8sApUQ2NfENcHEA swUEcFeudQ1fXbrPbmmWZWZm/4bpaDNQkLha/Loj4Njb5SvlUUPrvM9uk5dhgCrlE9sh vijsS2Oj7vwZ9SU/hfcGvn2DvvInwf3CGDzjnPyNRSyvo9Om2Y6nz2ZmcvW7t0Y05wh8 ihRIDpdKE8Bn5Ny8ZpA6j9A48C/xT9BI3nL4v3OHCHGwEvg56PwcfVvvSF+OoySuweSq 0IuA== X-Gm-Message-State: AOAM532Ff/fToS+JIu9DANDo5MGUbE6latYL4E+a/xIXvv7/wnzk4rcn oifU9zG/7+7ArCCx0GxiMcVbBnVQFwCECo0Ttebuao2+zaQlPZWEqr/QGqU58gIT0a+lqwGbNkq zKCG8+LTGh1/i760JdOxcH9gD X-Received: by 2002:a05:6402:54f:: with SMTP id i15mr1922178edx.365.1619074932130; Thu, 22 Apr 2021 00:02:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwW6HSmx2bqE6mJ1T+jSutBTgTnXdsbeh+wMEVf31ITrNbtI2a0LDOgDf0Ru09R/HBq590CVw== X-Received: by 2002:a05:6402:54f:: with SMTP id i15mr1922156edx.365.1619074931964; Thu, 22 Apr 2021 00:02:11 -0700 (PDT) Received: from ?IPv6:2001:b07:6468:f312:c8dd:75d4:99ab:290a? ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id n13sm1196993ejx.27.2021.04.22.00.02.10 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 22 Apr 2021 00:02:11 -0700 (PDT) Subject: Re: [PATCH 0/5] KVM: x86: Use kernel x86 cpuid utilities in KVM selftests To: Ricardo Koller Cc: kvm@vger.kernel.org, Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , "H. Peter Anvin" , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Nathan Chancellor , Nick Desaulniers , linux-kernel@vger.kernel.org, clang-built-linux@googlegroups.com References: <20210422005626.564163-1-ricarkol@google.com> From: Paolo Bonzini Message-ID: Date: Thu, 22 Apr 2021 09:02:09 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.0 MIME-Version: 1.0 In-Reply-To: <20210422005626.564163-1-ricarkol@google.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 22/04/21 02:56, Ricardo Koller wrote: > The kernel has a set of utilities and definitions to deal with x86 cpu > features. The x86 KVM selftests don't use them, and instead have > evolved to use differing and ad-hoc methods for checking features. The > advantage of the kernel feature definitions is that they use a format > that embeds the info needed to extract them from cpuid (function, index, > and register to use). > > The first 3 patches massage the related cpuid header files in the kernel > side, then copy them into tools/ so they can be included by selftests. > The last 2 patches replace the tests checking for cpu features to use > the definitions and utilities introduced from the kernel. I queued the first, but I am not sure about the rest. An alternative is to copy over the code from kvm-unit-tests which encodes the leaf/subleaf/register/bit values into the X86_FEATURE_* value. Sharing code with kvm-unit-tests is probably simpler than adding #ifdef __KERNEL__ and keeping the headers in sync. Paolo > Thanks, > Ricardo > > Ricardo Koller (5): > KVM: x86: Move reverse CPUID helpers to separate header file > x86/cpu: Expose CPUID regs, leaf and index definitions to tools > tools headers x86: Copy cpuid helpers from the kernel > KVM: selftests: Introduce utilities for checking x86 features > KVM: selftests: Use kernel x86 cpuid features format > > arch/x86/events/intel/pt.c | 1 + > arch/x86/include/asm/cpufeature.h | 23 +- > arch/x86/include/asm/processor.h | 11 - > arch/x86/kernel/cpu/scattered.c | 2 +- > arch/x86/kernel/cpuid.c | 2 +- > arch/x86/kvm/cpuid.h | 177 +----------- > arch/x86/kvm/reverse_cpuid.h | 185 +++++++++++++ > tools/arch/x86/include/asm/cpufeature.h | 257 ++++++++++++++++++ > tools/arch/x86/include/asm/cpufeatures.h | 3 + > .../selftests/kvm/include/x86_64/cpuid.h | 61 +++++ > .../selftests/kvm/include/x86_64/processor.h | 16 -- > .../kvm/include/x86_64/reverse_cpuid.h | 185 +++++++++++++ > .../selftests/kvm/include/x86_64/svm_util.h | 11 +- > tools/testing/selftests/kvm/lib/x86_64/svm.c | 6 +- > tools/testing/selftests/kvm/lib/x86_64/vmx.c | 5 +- > tools/testing/selftests/kvm/steal_time.c | 5 +- > .../kvm/x86_64/cr4_cpuid_sync_test.c | 23 +- > .../selftests/kvm/x86_64/set_sregs_test.c | 25 +- > .../selftests/kvm/x86_64/vmx_pmu_msrs_test.c | 8 +- > .../kvm/x86_64/vmx_set_nested_state_test.c | 5 +- > .../selftests/kvm/x86_64/xss_msr_test.c | 10 +- > 21 files changed, 749 insertions(+), 272 deletions(-) > create mode 100644 arch/x86/kvm/reverse_cpuid.h > create mode 100644 tools/arch/x86/include/asm/cpufeature.h > create mode 100644 tools/testing/selftests/kvm/include/x86_64/cpuid.h > create mode 100644 tools/testing/selftests/kvm/include/x86_64/reverse_cpuid.h >