Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp387436pxb; Fri, 15 Jan 2021 16:19:18 -0800 (PST) X-Google-Smtp-Source: ABdhPJzM8lgDAj5aDPJlPP+zRN49ld+7BqG/tH5sI8aSuW941wnibo4ExhP6wKO1zopKe6/VPRVe X-Received: by 2002:aa7:c813:: with SMTP id a19mr11177222edt.192.1610756357903; Fri, 15 Jan 2021 16:19:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610756357; cv=none; d=google.com; s=arc-20160816; b=oax2LPazfDKnOWmoW9Stwwc8OBire/4nVhnuJybHHBB1rb3NUubKFRQl8/F8idxuLY DqrdTNoEBSItwM72YLlgdwUsHcpCS0gjkLwKZqkdH3ehztsuT2BX7KNfGLAl84AAKfYX Rb1Lgxtv5eqhj2mQXdwNDrVkuB4URgy63dRT6xLnaW0TEVhvzWFZ15saIRgpNFqE17tm LjkUo2gzIRGqlRlw27MAL4O4NmVhXTt+DectHqyYrCsAWJlAu/Ny1lHDzepLGrdGN9yJ KainFq/dUllvFXEHrrJVB5ghyzOPXtS5g8SVzurhPuxeByiHj4E28yI7Kj0WN8XmlIvI wk1g== 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=6yXtcuFIc7dVGNx7ADF/6iAn0EJcDM4Yx9eIq/yQWuE=; b=RTmViDqXSKjpicTWiba3tx2oqt2mg96qLhna8Doo505vUuK4Oo2XSFZbusrHx4B24b aYLYDpoU0tgs8duo4YlT0TTK77xJjCm57lPjpuNTYI7Sn6TDQZQrb4xlXRRRxO1opehr 78ivUM6xqEu3g8gXZ5RGyNaZgiT4RilXUvS77pg93HnMVfpolMAWT3LKuuc+OAh0F+Sl L913O6Zm6voUokbiy6dbsi9TQ/5l8MbRsUDa/aD1Gspt/B3IPzoe4SZp3s8d8ylZhQSX uWAh2VMQyC7o8PHD66RLWLKK2Z5GZwBzzU2lTv1wK/IJnrQ9lkFKw+GSDobcmJ9ZfCXi Bm+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=SccGeFKq; 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 f1si4451167ejd.696.2021.01.15.16.18.54; Fri, 15 Jan 2021 16:19:17 -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=SccGeFKq; 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 S1728888AbhAPARa (ORCPT + 99 others); Fri, 15 Jan 2021 19:17:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49910 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726282AbhAPAR3 (ORCPT ); Fri, 15 Jan 2021 19:17:29 -0500 Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 517ECC061793 for ; Fri, 15 Jan 2021 16:16:49 -0800 (PST) Received: by mail-pl1-x634.google.com with SMTP id r4so5520179pls.11 for ; Fri, 15 Jan 2021 16:16:49 -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=6yXtcuFIc7dVGNx7ADF/6iAn0EJcDM4Yx9eIq/yQWuE=; b=SccGeFKqKYJn6JGRmH/QcNJG9V7LUY+7YiLZyoDBARjMEytCqxFkYJhwJR3fj9ZrdY JBP/7CLS57/yGmRuYLOYczMhfd/OTNsISQKhkCmLoV7yNK0QW1xzqzOhOYk/q09GLkl8 aJ/6zxzBaufKtvaFB+X9EUdhJqtTr/548nwFKgG5f7QqIApV0ZGpsAEI8ZMUuHIOkXOX 1p3hggceXipEKPIRy98L0vxmtXSP7hl6UYau7rvHI6sgIPbwzjxUQH6lEuC5eD+OOPOV iQx6gPIpaEaha+KlXHnWTVw2UOaOJL1axxSODIsaBSvJY6XbvcI0QCyz0JruKNkdE/on Obew== 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=6yXtcuFIc7dVGNx7ADF/6iAn0EJcDM4Yx9eIq/yQWuE=; b=JAyEgpYIZXK58SEFck62u4Mb8LOhpW6LDOrpiNTmCG3aTedFRbvgWZkMUtoVWgTEYL zq/jMdCFwFatU2K/xXZ04+U0yLlVc+NknqRVJrk+6YLjgfdC7dUET63uIgGpyCfc8jk8 hRbnCZ2riob2io41hahjnGBVRruGK1NgFBLp9Vc/HMEB6T74XbVeSSWBjLmDg9Vo1sQM LMbA2qeJQtZcp0EIQNVY5tuCkvTG7ephnyoy58Wyo4aMaBPiub5HORce2aZSajZwRMo3 ibpr009/h//XGaOqBfDPa8YhcEtLsA1H0h9LQndK8G3n9BgV7EICEZY+BCou9orDbzgB zdXw== X-Gm-Message-State: AOAM532+bI5lKDoYWhkTdzAV7PJYozLsRv2W93EY+X258ew/Qssn30V4 8mOAeDjE3msimxTS2g0vdfxk9w== X-Received: by 2002:a17:902:8549:b029:de:8aaa:b012 with SMTP id d9-20020a1709028549b02900de8aaab012mr267476plo.34.1610756208738; Fri, 15 Jan 2021 16:16:48 -0800 (PST) Received: from google.com ([2620:15c:f:10:1ea0:b8ff:fe73:50f5]) by smtp.gmail.com with ESMTPSA id b188sm5255349pfg.68.2021.01.15.16.16.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Jan 2021 16:16:48 -0800 (PST) Date: Fri, 15 Jan 2021 16:16:41 -0800 From: Sean Christopherson To: Like Xu Cc: Paolo Bonzini , Sean Christopherson , syzkaller-bugs@googlegroups.com, Vitaly Kuznetsov , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, Wanpeng Li , linux-kernel@vger.kernel.org Subject: Re: [PATCH] KVM: x86/pmu: Fix UBSAN shift-out-of-bounds warning in intel_pmu_refresh() Message-ID: References: <20201229071144.85418-1-like.xu@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201229071144.85418-1-like.xu@linux.intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Dec 29, 2020, Like Xu wrote: > Since we know vPMU will not work properly when the guest bit_width(s) of > the [gp|fixed] counters are greater than the host ones, so we can setup a > smaller left shift value and refresh the guest pmu cpuid entry, thus fixing > the following UBSAN shift-out-of-bounds warning: > > shift exponent 197 is too large for 64-bit type 'long long unsigned int' > > Call Trace: > __dump_stack lib/dump_stack.c:79 [inline] > dump_stack+0x107/0x163 lib/dump_stack.c:120 > ubsan_epilogue+0xb/0x5a lib/ubsan.c:148 > __ubsan_handle_shift_out_of_bounds.cold+0xb1/0x181 lib/ubsan.c:395 > intel_pmu_refresh.cold+0x75/0x99 arch/x86/kvm/vmx/pmu_intel.c:348 > kvm_vcpu_after_set_cpuid+0x65a/0xf80 arch/x86/kvm/cpuid.c:177 > kvm_vcpu_ioctl_set_cpuid2+0x160/0x440 arch/x86/kvm/cpuid.c:308 > kvm_arch_vcpu_ioctl+0x11b6/0x2d70 arch/x86/kvm/x86.c:4709 > kvm_vcpu_ioctl+0x7b9/0xdb0 arch/x86/kvm/../../../virt/kvm/kvm_main.c:3386 > vfs_ioctl fs/ioctl.c:48 [inline] > __do_sys_ioctl fs/ioctl.c:753 [inline] > __se_sys_ioctl fs/ioctl.c:739 [inline] > __x64_sys_ioctl+0x193/0x200 fs/ioctl.c:739 > do_syscall_64+0x2d/0x70 arch/x86/entry/common.c:46 > entry_SYSCALL_64_after_hwframe+0x44/0xa9 > > Reported-by: syzbot+ae488dc136a4cc6ba32b@syzkaller.appspotmail.com > Signed-off-by: Like Xu > --- > arch/x86/kvm/vmx/pmu_intel.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/arch/x86/kvm/vmx/pmu_intel.c b/arch/x86/kvm/vmx/pmu_intel.c > index a886a47daebd..a86a1690e75c 100644 > --- a/arch/x86/kvm/vmx/pmu_intel.c > +++ b/arch/x86/kvm/vmx/pmu_intel.c > @@ -345,6 +345,7 @@ static void intel_pmu_refresh(struct kvm_vcpu *vcpu) > > pmu->nr_arch_gp_counters = min_t(int, eax.split.num_counters, > x86_pmu.num_counters_gp); > + eax.split.bit_width = min_t(int, eax.split.bit_width, x86_pmu.bit_width_gp); > pmu->counter_bitmask[KVM_PMC_GP] = ((u64)1 << eax.split.bit_width) - 1; > pmu->available_event_types = ~entry->ebx & > ((1ull << eax.split.mask_length) - 1); eax.split.mask_length needs similar treatment, doesn't it? > @@ -355,6 +356,8 @@ static void intel_pmu_refresh(struct kvm_vcpu *vcpu) > pmu->nr_arch_fixed_counters = > min_t(int, edx.split.num_counters_fixed, > x86_pmu.num_counters_fixed); > + edx.split.bit_width_fixed = min_t(int, > + edx.split.bit_width_fixed, x86_pmu.bit_width_fixed); > pmu->counter_bitmask[KVM_PMC_FIXED] = > ((u64)1 << edx.split.bit_width_fixed) - 1; > } > -- > 2.29.2 >