Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp22565147rwd; Fri, 30 Jun 2023 09:31:40 -0700 (PDT) X-Google-Smtp-Source: APBJJlGvG7QmVNViXaWaRIoTUqZ5K4lOJGo9N6bSAX+uRSYIBxq0MdW1syFNVD88fWNDIc9NUX1g X-Received: by 2002:a05:6871:d82:b0:1b3:715c:463e with SMTP id vi2-20020a0568710d8200b001b3715c463emr489766oab.0.1688142700734; Fri, 30 Jun 2023 09:31:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688142700; cv=none; d=google.com; s=arc-20160816; b=Ccl+cx/q89IA7B/rfdzzr/E/+GXOSDE7P5FmAQ5oo0rqubF4YPs0hiQ1ASYmdjMgIW 1pCZB6pw92VpsRhaYjx682jlB35ZB3qCMt5xvI9Pr7rsk2FjF9hWIqqYolGumfejjTgQ ezp3dcZYNkv+gSHWIwskAZK5OSlpR6ZM2rU6L5l9UkYeSBSCf+YOJoFdBC9EfyIqquMX cdGiWbdF9I/70k8dK9AQPsMc7dazUYg42DQ8IPevjqdlXUmE7xua/X1VRR6zBV5VxzUj v3BI2LmayFCxkz15K4QHI+5IpnOgz3OTuoZbRlBj/F34OGCr7PR/2vpGLbrdpmFQXAVG qOQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=PGsWok1x7dplsdKnJrrmcBge8O50nAaWvf5Ok5mjPd4=; fh=TS2mxc8wESXTOKCDA58PXnuPWcD7HA1DAOoimABCKxQ=; b=qcNnH3gw3ZYcsDxQa7FhGNdvGpi8MKKtvPtPL2mmlK/zTFlE5VLNi+RDFPGhk1qPnW HMDmfQxOfi3UklINEp+srP9b7H0+Rlwd4dBlXPOraSzcIyEtzGgTfvFijwD+jlyddv1h IzBYMHhqe6r9hV+8jjMrPGeRudfNt9brrXGD4wiQsVeqBygErlfP7/fxax1/v6m6Z+Na +fbVNhydh1VMiPbLGPRULuw3NGj6dTAV9SJzWKr+RLgzD6j2jGKPnZblh+Ps5TEXZIks wmwPoFoRWdyrdo56OFVJQZMcgiB5JcPd/0aXGRnDj4JNKNaynPGl4N+sOsqcJwlUBmPO xoJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=eGWMOFM3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i16-20020a17090a7e1000b0024b91006d29si14803894pjl.48.2023.06.30.09.31.27; Fri, 30 Jun 2023 09:31:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=eGWMOFM3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S232873AbjF3PpK (ORCPT + 99 others); Fri, 30 Jun 2023 11:45:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54632 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232628AbjF3PpH (ORCPT ); Fri, 30 Jun 2023 11:45:07 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 056ADEC for ; Fri, 30 Jun 2023 08:45:07 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-573d70da2afso18892997b3.2 for ; Fri, 30 Jun 2023 08:45:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1688139906; x=1690731906; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=PGsWok1x7dplsdKnJrrmcBge8O50nAaWvf5Ok5mjPd4=; b=eGWMOFM3GXS9tFnRExmbojyXBqlwq1sFNIcYYNt/arDuFYsW3XSFXkF8D7ji6W9HFO 1t3zqgJECHeAewxekDfmjmiVJhjLuv9owT68r2sk+2anDX2FECxtAgkji45GUi35HryQ nILNZhxmPSGqpyMJw0/iGNlrEz4ODnzq5GXM50PzGwrgRZzC+KepSXcT4SAwym9y4qZl KHJxFeJS1IJT5FbMPZ1SwsdKgWGMLvYGxOt1AvuRTkQys+iVOHUejAi5cn3k1MnbnVWH RmKTPVBNf3EjgUD0yDXkRWnRtwRxM0ZgtC8du3g7YOe+EZkHyNXqogZjC+E7XsLHS5qx o7ug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688139906; x=1690731906; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=PGsWok1x7dplsdKnJrrmcBge8O50nAaWvf5Ok5mjPd4=; b=Ue/UK4glIml1eGUkt5iOnGpqgQM058g4lXGMC8eay8pTdaHwBfW9upJYa531blHhoY boCTZdBJ1EAWJwgq65NaahlBGWCqCoQ2VsKfUfV1E5OG48OUiVD7QkEZVOdot8HvaivR 1pYYoCt9igFWpFKuQkA6H06oy2IHU7Vb/H7235pmAtWUrrVcf2Y4UZFLa2HSUhXBBEOP zbBNJJYlcJbzOoi8r3qeyEPvtDIQOd/An/C/xnxkFyE4JxlGwFBo6LgeaMaV5OH5inqW u/3CA3Q1+AHi/E+MwADGy2F6qrybUhFeV2pLS2UDTVUWmDUEEfRq5l+yzPXCc88uG6Rq 2NCw== X-Gm-Message-State: ABy/qLaIQ8AomTn8d+3+DdO3g9CwxoPgL537Norli7xQbSp7NgsHedaF ekVhM34IX8SOQ9pgBZgHN2UiDgjGZ8M= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a81:760a:0:b0:56c:fce1:7d8d with SMTP id r10-20020a81760a000000b0056cfce17d8dmr23323ywc.6.1688139906026; Fri, 30 Jun 2023 08:45:06 -0700 (PDT) Date: Fri, 30 Jun 2023 08:45:04 -0700 In-Reply-To: Mime-Version: 1.0 References: <20230504120042.785651-1-rkagan@amazon.de> Message-ID: Subject: Re: [PATCH] KVM: x86: vPMU: truncate counter value to allowed width From: Sean Christopherson To: Roman Kagan , Jim Mattson , Paolo Bonzini , Eric Hankland , kvm@vger.kernel.org, Dave Hansen , Like Xu , x86@kernel.org, Thomas Gleixner , linux-kernel@vger.kernel.org, "H. Peter Anvin" , Borislav Petkov , Ingo Molnar , Mingwei Zhang Content-Type: text/plain; charset="us-ascii" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jun 30, 2023, Roman Kagan wrote: > On Fri, Jun 30, 2023 at 07:28:29AM -0700, Sean Christopherson wrote: > > On Fri, Jun 30, 2023, Roman Kagan wrote: > > > On Thu, Jun 29, 2023 at 05:11:06PM -0700, Sean Christopherson wrote: > > > > @@ -74,6 +74,14 @@ static inline u64 pmc_read_counter(struct kvm_pmc *pmc) > > > > return counter & pmc_bitmask(pmc); > > > > } > > > > > > > > +static inline void pmc_write_counter(struct kvm_pmc *pmc, u64 val) > > > > +{ > > > > + if (pmc->perf_event && !pmc->is_paused) > > > > + perf_event_set_count(pmc->perf_event, val); > > > > + > > > > + pmc->counter = val; > > > > > > Doesn't this still have the original problem of storing wider value than > > > allowed? > > > > Yes, this was just to fix the counter offset weirdness. My plan is to apply your > > patch on top. Sorry for not making that clear. > > Ah, got it, thanks! > > Also I'm now chasing a problem that we occasionally see > > [3939579.462832] Uhhuh. NMI received for unknown reason 30 on CPU 43. > [3939579.462836] Do you have a strange power saving mode enabled? > [3939579.462836] Dazed and confused, but trying to continue > > in the guests when perf is used. These messages disappear when > 9cd803d496e7 ("KVM: x86: Update vPMCs when retiring instructions") is > reverted. I haven't yet figured out where exactly the culprit is. Can you reverting de0f619564f4 ("KVM: x86/pmu: Defer counter emulated overflow via pmc->prev_counter")? I suspect the problem is the prev_counter mess.