Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp4274295pxb; Tue, 2 Mar 2021 10:47:22 -0800 (PST) X-Google-Smtp-Source: ABdhPJxlwvmsVQVk2T/XCXAdOxf88TGlrDWMdRQ5VdLuLnRl7LVuCwJoVauwLTYH4c23kSeA1Ryo X-Received: by 2002:a05:6402:3596:: with SMTP id y22mr1408084edc.207.1614710842039; Tue, 02 Mar 2021 10:47:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614710842; cv=none; d=google.com; s=arc-20160816; b=h9Wfkn7H73mMCmXMM4obmyhyVQJZqDLN0Qya4qajM5wkV8uH1leTCiUcH0oaaIk7hq ypPkWvdpeKpyIiPUNkGfobKVDjJH4soypOYexXxKL2t/xWR8LyHTTnDCOEcQEUkzOGZ8 mz6fJWMbDaK9erMC3xMONxGoK0jYAvV2JbQ0+0TE9BSEd122jlnLZkHnc0jev0o3oJ6i QjZg6jbmoG9KpN5QXv4nGKJhkoYU20Ge/7mAKwSntu9qnfC2/ZPpINnc/uyt7KzUszda fh1ytOzffHeM/oH4MajdIm8wZbTrt6ol4F+Nx7zM+xAFRhtBzQ73cUbZRZpbbV7Jf4pG xtpQ== 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:organization :from:references:cc:to:subject:ironport-sdr:ironport-sdr; bh=kYRf2Z6/qxRdBFLrX8CrOyLeC2FqI3ZzjxeZvxcqyzY=; b=kj/jUprpSGmvXZ5KfdYyycdtKggCTNj3wWmPuN8rG4EwDb05OjnggUTAAM7jAvLAGi Pc8vkNx7qytMkK35QR5ODsJTiqxrPGfX4bgbhnzcY5rgLg4r9jyaBAj9OZ6enIiqwoqS QSTc4hTby2B/M7OFKNiVRToRIHgT7o60IIgn8YuefIw/pgNp6erQV7Pj2zdDz+09vwWV /KEBsaoPRcjcI5LCFtVKlzz0gorgbxlSjL64guf2X51dT3sweOtu9CABDP0D7WCPtvuF 3cTeUcpzCdD0t1Nh+ugsSCctfb/TYnhxuO3CijlKcyvoNwzgd+M9cWWPgHXUFYFlLSwf h4Og== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g11si4782896ejd.733.2021.03.02.10.46.58; Tue, 02 Mar 2021 10:47:22 -0800 (PST) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234662AbhCBEiV (ORCPT + 99 others); Mon, 1 Mar 2021 23:38:21 -0500 Received: from mga03.intel.com ([134.134.136.65]:24436 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347334AbhCBCym (ORCPT ); Mon, 1 Mar 2021 21:54:42 -0500 IronPort-SDR: MGul3XlqCh8eF0ltbz9vf5HWc0rcYwRQSlqg0RhPdzZnjLEFhB54FW0dpYiAm86IYt/HO5HEld BWoGxOCpPKtg== X-IronPort-AV: E=McAfee;i="6000,8403,9910"; a="186721906" X-IronPort-AV: E=Sophos;i="5.81,216,1610438400"; d="scan'208";a="186721906" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Mar 2021 18:52:56 -0800 IronPort-SDR: 0Y5NNDMqa45GgezOLyZGo9r8aF1T93aO2XijT0PR13FtODXOlI0A+3m/eiyJiE90gfi0q2nXh+ VjuEKKEMRVeA== X-IronPort-AV: E=Sophos;i="5.81,216,1610438400"; d="scan'208";a="406507788" Received: from likexu-mobl1.ccr.corp.intel.com (HELO [10.238.4.93]) ([10.238.4.93]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Mar 2021 18:52:54 -0800 Subject: Re: [PATCH v2 1/4] KVM: vmx/pmu: Add MSR_ARCH_LBR_DEPTH emulation for Arch LBR To: Sean Christopherson Cc: Paolo Bonzini , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org References: <20210203135714.318356-1-like.xu@linux.intel.com> <20210203135714.318356-2-like.xu@linux.intel.com> From: Like Xu Organization: Intel OTC Message-ID: Date: Tue, 2 Mar 2021 10:52:51 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.8.0 MIME-Version: 1.0 In-Reply-To: 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 2021/3/2 6:34, Sean Christopherson wrote: > On Wed, Feb 03, 2021, Like Xu wrote: >> @@ -348,10 +352,26 @@ static bool intel_pmu_handle_lbr_msrs_access(struct kvm_vcpu *vcpu, >> return true; >> } >> >> +/* >> + * Check if the requested depth values is supported >> + * based on the bits [0:7] of the guest cpuid.1c.eax. >> + */ >> +static bool arch_lbr_depth_is_valid(struct kvm_vcpu *vcpu, u64 depth) >> +{ >> + struct kvm_cpuid_entry2 *best; >> + >> + best = kvm_find_cpuid_entry(vcpu, 0x1c, 0); >> + if (depth && best) > >> + return (best->eax & 0xff) & (1ULL << (depth / 8 - 1)); > > I believe this will genereate undefined behavior if depth > 64. Or if depth < 8. > And I believe this check also needs to enforce that depth is a multiple of 8. > > For each bit n set in this field, the IA32_LBR_DEPTH.DEPTH value 8*(n+1) is > supported. > > Thus it's impossible for 0-7, 9-15, etc... to be legal depths. Thank you! How about: best = kvm_find_cpuid_entry(vcpu, 0x1c, 0); if (best && depth && !(depth % 8)) return (best->eax & 0xff) & (1ULL << (depth / 8 - 1)); return false; > > >> + >> + return false; >> +} >> + >