Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp220234pxy; Thu, 22 Apr 2021 00:03:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwklCqhMKvFCGxf2jFMw069OJvHq8C35KrvBtK0utvz+KE+mCAyTDXuuF4rHZj8ycP3goqw X-Received: by 2002:a63:105d:: with SMTP id 29mr2138821pgq.45.1619075012556; Thu, 22 Apr 2021 00:03:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619075012; cv=none; d=google.com; s=arc-20160816; b=GZqPj2a7D6gz43IHc8zZFx11nCB3vhpL1jqOtcrxfUug4RYePaINGBvfrwAfXUAxjc 0EQmwcShnBsso0RrTwYmdgUOTL61YigEV2YfCF+tfSzc+LfBagb1KQHaLybpNY4c3Yxz aVqqTf+6qyd4qGh2VRKh8+AEm4BYHOQWm/KYz+Xn3TLXQzJYrkXec6nnTvHb+HdLyC7Z Cr3q1Z6c5NqQYgY9APpzTE+dJojFl8iPpaoOG+izL9cdS4sbxQ/8DEtaKCH7VT7FdI5e mqVvSjZlu6VLgJvNe2G+0KWIUpdohBaWXIHpRK1FnFWg/0xZmsnFi6jU42aOYGxP+s+F 8FQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=U1sBIWc97pwUoI/Y/7htamKNpDUssIIcTnKBNjle2Og=; b=AGQm/VYHednGuX4BWFE/SQO/hGi96plsVhjxiHGXOAHZPTLuGDkCErfki7CzvjFhJw izmgLDFKC/92V6seBGaTPpRSLeVUc72APhl5xrF5Qo1sKDrqJ5m0/7GGW2bMjeZ3s1V6 b2hBjZ4MjZlJFRPbsZ6HSFSumk299kuGoHC1xZL9vNAxnT2Z9zMGx+OOC3JS6p9hP+zX NS//mZIKxszHHfwtnEmijDVwsQrnamUjVIuX9S3QqMCux9As7O9nSAVvfDx53beC9gMA zRk/iYaPsAZH5B+NCo+G6NkY3zg4BKTt5rFAVqrP6csXYleloCh75OhG3wlbNLBDgxIz urpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="bS/r7X2Z"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e3si1893344plh.216.2021.04.22.00.03.19; Thu, 22 Apr 2021 00:03:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="bS/r7X2Z"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230241AbhDVHDY (ORCPT + 99 others); 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-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 >