Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp299264rwr; Wed, 19 Apr 2023 06:45:55 -0700 (PDT) X-Google-Smtp-Source: AKy350ZXGM9zr/kwooaAa+mjmCJAxYWeKVW1n4LFHuNzZfeDp6Kv1HjNyL4hm8ZZ/xsysNkp5G8N X-Received: by 2002:aa7:8889:0:b0:63d:2382:4948 with SMTP id z9-20020aa78889000000b0063d23824948mr3744235pfe.25.1681911955458; Wed, 19 Apr 2023 06:45:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681911955; cv=none; d=google.com; s=arc-20160816; b=AwgiQ8tAsBQwae0IMpqrdhNlq4BbO8zJcCyQ0D7i285kmhGpaU97QTshVemEDg4pyD eF23yHYW6EQlXQpQuFOw9PliQmTMgtIafHNeGDzAhZucy/WB0QgylMVIA/zR83o48Gis n7XVheIHAW0NB8TPCt6m7c8rFmecYLmU9JwZmiiSy2eE7f1NB/xr5m11DsG3UXR64oW9 FoO6BR6QW9J/EbMOwOKsy8fXlvJUtmRXWKqviw2+OUbsXglargxM1+mzI3cLbOoKYy6y e8aileQdOuXhVjj+bYRWJ6h6HPhwjfyQBEwZTjY5XDKwweCwhO9ea0Hk+fUxmMrqqYB4 38tQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=E3S7zUDqSoGDbvXpJqNdjvrmE0MdUknEcdQTrbgz6t4=; b=g4kvQ7m5S8AzR47b/bpXXycwWcXoEY3/83zWOQ5/AF7B8x3XSUMRcyae0iuFpJCWJR DbnHEzOtdnlXQbIzq8eLwQsEKYfMAt4Sknr3D4xZiYSGJ7xXjnMY27oATep5iGMPuiq9 y5tTm4PviRj8FF3th7W307DXUcZh8g+6T6QCuAMEa2fue6cNq0BYnTzssxZ0gg8y6FDn Id67aHJ5sNtu3xNk45g39zGZ87qon8ic7+QvkS4ZVYCIJ9BSlAn1lQ5iv+wjMqxCYelC iVV6lSlhqE8PWYrnxaTLSZjHeg8sh5FR3/GpC+uIfwEu0qxaASI0ihJ7jOZ7jYb+iLhC y5bQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=okkUGo7g; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x17-20020aa79411000000b0063d61f05a8fsi1284362pfo.198.2023.04.19.06.45.41; Wed, 19 Apr 2023 06:45:55 -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=@gmail.com header.s=20221208 header.b=okkUGo7g; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233054AbjDSNl7 (ORCPT + 99 others); Wed, 19 Apr 2023 09:41:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48804 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232035AbjDSNl6 (ORCPT ); Wed, 19 Apr 2023 09:41:58 -0400 Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB2F2E60; Wed, 19 Apr 2023 06:41:56 -0700 (PDT) Received: by mail-pj1-x1036.google.com with SMTP id k65-20020a17090a3ec700b00247131783f7so765624pjc.0; Wed, 19 Apr 2023 06:41:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681911716; x=1684503716; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=E3S7zUDqSoGDbvXpJqNdjvrmE0MdUknEcdQTrbgz6t4=; b=okkUGo7gegyBD1nHjFvS6ZtyWsjV2AUXQmYK005ZtfngbgAwntbnuR92yEq1p/Xxlf r1ReTZFI6mgRMkXTAa5YLi4cjQ/VbBWji6o5ZExu040KTWeUCsTPNz6EIzTIPL0AM07U GitaV/m6Nd4SCe4M96IfaG10Q/YqQFDbNcb27qu8KBH2DjTjRr68fO4n9IZC9gS+xBVt nzTqmk6ufa8SZGlOyOB4ZCYFwZ4kGu/vmOpzDxHGtLD+RseqQgDZrKRkQJ+tBvVFAqo0 XxLnZSQi+jYrkMKuuh+5x74wEpnLPdUgDYnMkosBwDok2fQGFYBVWUBmY7lPD7UhA1Xy oPeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681911716; x=1684503716; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=E3S7zUDqSoGDbvXpJqNdjvrmE0MdUknEcdQTrbgz6t4=; b=fUzDDTiq1hwaaWCAEGxlkFirvaK8QU7NLrSwK+PRB6F57E/ex6PzWp5WDv8XhP+bU9 pJO5DHTCYy4u8ZlycWKKQZVLqTc85NkLw+EoonOxMGJLuFpDXjg1KTLKmi9egehYqYIN wN1XXWPI7Xo8jNNfhe0KIvVXi8T+QVfgwX4iEOwy1fUmp3bPqA2+4ovWIVxELVlbhloX r1X9prNom41ZundkFSt/sHZ7kmBgrGRvlSl1Qz9wAqEHv8oLNTAIPUk3bdqUTyay9XK6 oWEBLMUqHOYDosJxxVte7/O/2kUKKSj3YPu+2ipEOfq5mAnPQQ+AA/iU0x+c3125WrlE vHTg== X-Gm-Message-State: AAQBX9dfhaLncySZ6ffDpvlPZEy7Qz0n/PiQEMoqGJ5sIkzqj/h7FMgn ahGg+v/YpzIqLRj8ZBpmv+o= X-Received: by 2002:a05:6a21:151b:b0:f0:3c5e:b997 with SMTP id nq27-20020a056a21151b00b000f03c5eb997mr3253130pzb.58.1681911715565; Wed, 19 Apr 2023 06:41:55 -0700 (PDT) Received: from [192.168.255.10] ([103.7.29.32]) by smtp.gmail.com with ESMTPSA id p22-20020aa78616000000b0063b675f01a2sm9206802pfn.26.2023.04.19.06.41.52 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 19 Apr 2023 06:41:54 -0700 (PDT) Message-ID: <34b5dd08-edac-e32f-1884-c8f2b85f7971@gmail.com> Date: Wed, 19 Apr 2023 21:41:45 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.10.0 Subject: Re: [PATCH 5/5] KVM: x86/pmu: Hide guest counter updates from the VMRUN instruction Content-Language: en-US To: Sean Christopherson Cc: Paolo Bonzini , Ravi Bangoria , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, "Bangoria, Ravikumar" , Santosh Shukla , "Tom Lendacky (AMD)" , Ananth Narayan References: <20230310105346.12302-1-likexu@tencent.com> <20230310105346.12302-6-likexu@tencent.com> <509b697f-4e60-94e5-f785-95f7f0a14006@gmail.com> From: Like Xu In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 7/4/2023 10:56 pm, Sean Christopherson wrote: > On Fri, Apr 07, 2023, Like Xu wrote: >> On 7/4/2023 10:18 am, Sean Christopherson wrote: >>> Wait, really? VMRUN is counted if and only if it enters to a CPL0 guest? Can >>> someone from AMD confirm this? I was going to say we should just treat this as >>> "normal" behavior, but counting CPL0 but not CPL>0 is definitely quirky. >> >> VMRUN is only counted on a CPL0-target (branch) instruction counter. > > Yes or no question: if KVM does VMRUN and a PMC is programmed to count _all_ taken > branches, will the PMC count VMRUN as a branch if guest CPL>0 according to the VMCB? YES, my quick tests (based on run_in_user() from KUT on Zen4) show: EVENTSEL_GUESTONLY + EVENTSEL_ALL + VMRUN_to_USR -> AMD_ZEN_BR_RETIRED + 1 EVENTSEL_GUESTONLY + EVENTSEL_ALL + VMRUN_to_OS -> AMD_ZEN_BR_RETIRED + 1 EVENTSEL_GUESTONLY + EVENTSEL_USR + VMRUN_to_USR -> AMD_ZEN_BR_RETIRED + 1 EVENTSEL_GUESTONLY + EVENTSEL_OS + VMRUN_to_OS -> AMD_ZEN_BR_RETIRED + 1 VENTSEL_GUESTONLY + EVENTSEL_OS + VMRUN_to_USR -> No change VENTSEL_GUESTONLY + EVENTSEL_USR + VMRUN_to_OS -> No change I'm actually not surprised and related test would be posted later. > >> This issue makes a guest CPL0-target instruction counter inexplicably >> increase, as if it would have been under-counted before the virtualization >> instructions were counted. > > Heh, it's very much explicable, it's just not desirable, and you and I would argue > that it's also incorrect. This is completely inaccurate from the end guest pmu user's perspective. I have a toy that looks like virtio-pmu, through which guest users can get hypervisor performance data. But the side effect of letting the guest see the VMRUN instruction by default is unacceptable, isn't it ? > > AMD folks, are there plans to document this as an erratum? I agree with Like that > counting VMRUN as a taken branch in guest context is a CPU bug, even if the behavior > is known/expected. +CC: Santosh, Tom, Ananth