Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp3415206rdh; Thu, 28 Sep 2023 10:53:16 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH3UVosPIQsNyVnlmDajK3JehYXrhfKOeaeNWvCux4hvBSJamoJbO7tZ8rMfNffMiBFmycL X-Received: by 2002:a05:6a20:9381:b0:14d:9938:735f with SMTP id x1-20020a056a20938100b0014d9938735fmr2202373pzh.17.1695923596008; Thu, 28 Sep 2023 10:53:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695923595; cv=none; d=google.com; s=arc-20160816; b=ViXvK5vm5AZufrbAixDbqbFtiph+tbK521xTgygabzZGYDPgonZYtRdLf7yhjS8kHR Bx2SwhcQT5lQmcnJPKHlSIlskwkdt4mMMLVOj2U7V4eh0ZhjDGal/Q80HnD/WZ97wvHe YfW0TnCfldb+5SVK81hSJLYdadridyrTIN4x0bb9q9pAzqTECD79BWL6i519hdhc7oUq 7rssw8CxhBsR98gOWCbVXnjHjai5B8DWb2ae1Rnn489tlOJxWK034+opvZBQWVo7GUOH 43Fe89kzwAQXCpVJMdK64VgsRIZaGgbdXBwaQi0L8aiCwKHD9zVVst0SfEF6KDP2T/VC HQrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=DPGh9unxuL2nJXgyj58qseqaVYwl19QlZd4mAA+cegs=; fh=nYmWGJGV4iG8lM82+alVKjStXte33Byf1bxJsBf4LAM=; b=r3vLNoDS1GBc9IxpNGhn/DEzIZabZMCJjFD6L2D9sz+OfrXk2LOqWqox2JecMqviPR s5L7vYa1cEVpMaKFOh3sifFb2siKPuLJaTJls+41edOTBs3HCx4Lsm8uW5E0NlPEQG4x buMmRuX4AgcSQbum+In+xwwPKONilDYtvjnosk9D7AqHCjX2x9JbfcwZPPgU7NQVORw6 59l5iL2Ep91H4gPLJyY8bA+lrSV/8T5YyBRDSwOp80bJOrkJRBz1InhDwcpxtO3bMgK3 zEjrATOosQ70fCJ/I5b93mJjh0OqNMBooMY1Rgqrh2M67rFwRp+FrIOE5JwuTqAjIz1P eD2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="gu+PIV/u"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id c4-20020a170902d48400b001c3fa9a1e3esi20930742plg.493.2023.09.28.10.53.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 10:53:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="gu+PIV/u"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id C25C683C5533; Thu, 28 Sep 2023 09:43:03 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231285AbjI1Qmx (ORCPT + 99 others); Thu, 28 Sep 2023 12:42:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49120 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229581AbjI1Qmv (ORCPT ); Thu, 28 Sep 2023 12:42:51 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B7A931A4 for ; Thu, 28 Sep 2023 09:42:49 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-59f7d4bbfc7so174763647b3.3 for ; Thu, 28 Sep 2023 09:42:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1695919369; x=1696524169; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=DPGh9unxuL2nJXgyj58qseqaVYwl19QlZd4mAA+cegs=; b=gu+PIV/ukMC9Ipe1mQq9G9FQRWELInQviX22EBqut05dyTQIAjB6C6X7uirQ+bUhzn oWPjWLzKE0D+uDB73gg/aAgAZNpYvUapKWVGtCJ9Lf/hhERJBlLHekxk3s8sjXl3rF6G lXycmG2tI6GZIxYaXrB0YYbILIiIR1MjoJOjvBEudut5FhmnCy5L2r/j8UWN8w92N/8O dgABLXOKWi3BFDK5CHdIBSN6tv3DM1DwSXvSjrGAn3TC+GiCj9WaIDppccTtYvXgi5Ip 7fJOSQ5k8r3AOxH3GQNqfDNRZgwRwROsG5hrF9e3rNCCy1jNa7UQJrzee//qxzWKctGE TFww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695919369; x=1696524169; h=cc: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=DPGh9unxuL2nJXgyj58qseqaVYwl19QlZd4mAA+cegs=; b=BSTfV76GHRnBFCoqDDi8qrPa0N5RMnHYJmINfrtZseBUKQgIpQocwA3n2i6AHyuhYV jth3V5HSKwD84ON3IvVKHaafDd8zzGvkPDOLcpEvdSRkLrKIPbFwZg3UnX5wQvanIsTA 9y9YoVE1NpLxudUBVV3l3dDno5d8GzfC5AFNTo3Ac/zar1PdPfEghs2p/LbkyY99bdp7 qbbcYXs75tPekDqB+8bPGQSahAYydbiJThFqesBCmxwGjEhuDqu/nb6MOutFZXpvAI4L YY6JL8UAeI3wj2yVoNmFFykXC6UygnIaFn6vsUrsPFgalpugsNesORiAJD90HOQHlzl/ WZ8g== X-Gm-Message-State: AOJu0YzwDtrBNqgjtP/IS1tlTieZ0cE1w/woyIM+ultnI8bUk2EBxBkZ n5JSEDU6Wzq6vYhPCxhNc5PpkHebPcM= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a0d:ec10:0:b0:59b:e97e:f7d7 with SMTP id q16-20020a0dec10000000b0059be97ef7d7mr27808ywn.1.1695919368962; Thu, 28 Sep 2023 09:42:48 -0700 (PDT) Date: Thu, 28 Sep 2023 09:41:56 -0700 In-Reply-To: <20230504120042.785651-1-rkagan@amazon.de> Mime-Version: 1.0 References: <20230504120042.785651-1-rkagan@amazon.de> X-Mailer: git-send-email 2.42.0.582.g8ccd20d70d-goog Message-ID: <169567773146.165747.5292830285056018670.b4-ty@google.com> Subject: Re: [PATCH] KVM: x86: vPMU: truncate counter value to allowed width From: Sean Christopherson To: Sean Christopherson , kvm@vger.kernel.org, Roman Kagan Cc: Dave Hansen , Jim Mattson , Like Xu , Paolo Bonzini , x86@kernel.org, Thomas Gleixner , Eric Hankland , linux-kernel@vger.kernel.org, "H. Peter Anvin" , Borislav Petkov , Ingo Molnar Content-Type: text/plain; charset="utf-8" X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Thu, 28 Sep 2023 09:43:03 -0700 (PDT) On Thu, 04 May 2023 14:00:42 +0200, Roman Kagan wrote: > Performance counters are defined to have width less than 64 bits. The > vPMU code maintains the counters in u64 variables but assumes the value > to fit within the defined width. However, for Intel non-full-width > counters (MSR_IA32_PERFCTRx) the value receieved from the guest is > truncated to 32 bits and then sign-extended to full 64 bits. If a > negative value is set, it's sign-extended to 64 bits, but then in > kvm_pmu_incr_counter() it's incremented, truncated, and compared to the > previous value for overflow detection. > That previous value is not truncated, so it always evaluates bigger than > the truncated new one, and a PMI is injected. If the PMI handler writes > a negative counter value itself, the vCPU never quits the PMI loop. > > [...] Applied to kvm-x86 pmu, with a slightly massaged changelog. Thanks! And sorry for the horrendous delay... [1/1] KVM: x86/pmu: Truncate counter value to allowed width on write https://github.com/kvm-x86/linux/commit/b29a2acd36dd -- https://github.com/kvm-x86/linux/tree/next