Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp929964pxb; Wed, 3 Mar 2021 21:27:43 -0800 (PST) X-Google-Smtp-Source: ABdhPJxrCnIKmFg+EUNlQh33RqDQJIh+UWpLhIq3/1/zJcbb6oqAJpHdNJaxfDSC/2ZfCJNJjq7l X-Received: by 2002:a17:906:bc81:: with SMTP id lv1mr2301832ejb.135.1614835663632; Wed, 03 Mar 2021 21:27:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614835663; cv=none; d=google.com; s=arc-20160816; b=0MCTlCun3Mq0D9mkYRvrEivlrfbyMVbfYeJIL8uA/MJGfG6ynZTn69KPSc2xgxiQwG lvbcm9nU5AHGaxuONS3PUkp6nRStQiSJxFyNs2GlDaVSUO3C0uIgv+Za8csGWISuAACY DCGL13zKynRCQVZ1bJRnKtOB8r/t12mvFJ4Xcv4ImivFd95zpFNwB9KBsMpT6UypQApP Db9DiVb9b8QT3JUh8U0nd5HStq7NTmwDXjkiTtsyshUmbTlE16p9wDtysNfziXdbh19h C9+DdwgA1HteZqlCIlJm/VzPIgQ++F0uJbb5wGsXpghcERiS2paZ/6i4Z2B4eDlHQ4HN +wbg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=/AwKDtv+GHa7MHunk/c29uxwQVds8fgP8tOf9dSrqJA=; b=qjR+BJOuIR/uHRtbWAD2b1PAvO1OYxxyy2yMIIGH9YFs+mwOlfwtr2Npm2Wq0Xz+p0 C+YaAkHcMvjogDxnHMBP1chMfKGCPkIyIrFVkcVGXqZUMz698byUELsm4+ne1p7/9FvO dG3rVgCSos6r7Jro9U0kAKCAc3C77o1HY82zP6ppEypm3P8PhbcCScXXUqH5wn7YGicX eJmN4vQbAFRI9FIveFKapftOeeZehSa+g/cgXC3vCywHF/kY/Ogl9P5w+VpX5r/HZkFP ZTOcUBE7N0wp8nLhWTBKWhg5Z+3/Ge1qRxzLFBzBgTfn41GAXE0/XjhPcEJO1WKvbS0Q tRNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=rEWXvFMY; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id lj27si7961049ejb.513.2021.03.03.21.27.21; Wed, 03 Mar 2021 21:27:43 -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; dkim=pass header.i=@google.com header.s=20161025 header.b=rEWXvFMY; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1575385AbhCBDz6 (ORCPT + 99 others); Mon, 1 Mar 2021 22:55:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245370AbhCAWeu (ORCPT ); Mon, 1 Mar 2021 17:34:50 -0500 Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 006E1C061788 for ; Mon, 1 Mar 2021 14:34:07 -0800 (PST) Received: by mail-pf1-x42e.google.com with SMTP id m6so12510455pfk.1 for ; Mon, 01 Mar 2021 14:34:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=/AwKDtv+GHa7MHunk/c29uxwQVds8fgP8tOf9dSrqJA=; b=rEWXvFMYmBv6dncujhbwJ+VzGxtQNkur08Sj/C2v8MwzMmAzcIHW9PminN8h4aktnS 4OR+f6sa6+84Ad3Mch/48AwghE8o82uh3M/TuO+51/JGLAvuK9d8kAngISagiMzrAkJL AWhcLzIngiasFXpQmULKnogHY1Z0Px6DkplZlLhqEg8ey7MQtXqvIxRl0gQOtVqY7oE5 vOadraRURss1IYLQ1k3yzbuKK8cgs5pgDnp8lpY0UBechIhhC/oqG9pv+NpSsYByIUFb d6Den2mTKfnPXFzC4p1lRSGcesiLpSJR1sn48Wny4YV4NgHNKHTrQJ2fSMFHysZ8UjeE OZQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=/AwKDtv+GHa7MHunk/c29uxwQVds8fgP8tOf9dSrqJA=; b=RhPnHMy1TiVCdZABm2YCQYqUyXyOBU7pldTKuVHoNFpxR/RdXEh/WTWjcpOD/xGkeM YQT/ZKqihVv6dZ2qRiT8Y/U2v+Ybir/nifHM81mb3im0J3iIKMDtE8ldQm+PiwWJhTUD IvzVQBGdZh3UUNgDfJ1AWRuneL9/+XyT5EahERq0PfZ5HitJ0hTeHFnqXOx9ZFJep1tM J7w7YyTz97M5gbM/uZvK9xSl87mFDIIS39d84Vxhr95OpplFzaDZc0feaukE3JDH2cMO kQiLcrfCq6raFJYowtRbsRfTcxvLIXrGEjkwcL/josQkIRLm1jM0WrfPa74p7Y1WPlIV +zKQ== X-Gm-Message-State: AOAM530KVKzukWbs0iiY3eKRvSNIqEOWvyO7Pi8BhHnz/8uSnSG+7kf3 v/kuRD1Lni/EDwT6/VaSSyg51A== X-Received: by 2002:a63:6dc3:: with SMTP id i186mr8303678pgc.314.1614638047291; Mon, 01 Mar 2021 14:34:07 -0800 (PST) Received: from google.com ([2620:15c:f:10:5d06:6d3c:7b9:20c9]) by smtp.gmail.com with ESMTPSA id 63sm4128729pfg.187.2021.03.01.14.34.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Mar 2021 14:34:06 -0800 (PST) Date: Mon, 1 Mar 2021 14:34:00 -0800 From: Sean Christopherson To: Like Xu Cc: Paolo Bonzini , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 1/4] KVM: vmx/pmu: Add MSR_ARCH_LBR_DEPTH emulation for Arch LBR Message-ID: References: <20210203135714.318356-1-like.xu@linux.intel.com> <20210203135714.318356-2-like.xu@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210203135714.318356-2-like.xu@linux.intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. > + > + return false; > +} > +