Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp3291632rdg; Tue, 17 Oct 2023 09:59:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHTzcI/QYEto9k2gzp4w94nLnllPLo3hr0yai/Wj66SQ+bPETvdVZIdzggB2hLkEKoyo92I X-Received: by 2002:a05:6a20:7352:b0:135:1af6:9a01 with SMTP id v18-20020a056a20735200b001351af69a01mr2937322pzc.8.1697561954828; Tue, 17 Oct 2023 09:59:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697561954; cv=none; d=google.com; s=arc-20160816; b=y62cRZOO+LxPV24OgYLYut11v8oa6rHEBKwe/a0z53jGGZP3c9YZX56NzU4FtYpklV I1R+AESg3aPMlZTwPINEOd+7FZCWNKVbjUHfk5jHEzQ7GAGCZD5Kd+rqip9Adbou1F5e n1+ykXDa/Zh1Z2J19e4wKeR/xqbeRSIy+lbYyjME3qPo/QuDa8mvqpUOKTdiErCiBEbo hgxrSxD6BjJ3avIHf1L94m51oq7265P/dAqlKbtAwlO/LfOgJbICc2X9w+/eUdBwsCkJ JkMzOxUAAa4Wc1d956jYTjqR9EzXbWC14qyLVNYkJkLUbJrNAFmv6GGLPlCjFgSHvvSo 76ug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=ehHiG5u8VUrGyvdvtZ5izhIhQL5g/E91S/K67Xu9F2I=; fh=Rz09qwPU1WnoCUu7xJUwmet3YKHK9B3cmNE0QUUfKvg=; b=Oui03pRX4I3aMV4lTdtiQWdDwV0Td8YOlCmWh5TiviEYicJfoU5Pr8EO2Wl4Lvtz7D j0E56AGWeLJ3V5qAmXVw8kPesCXKeCU4uAApCox4uKkLG516bUUOuv/yaG4WsxCLfx0t kxVUN1wmAtI3JdZCkcn2p87EBQKcGX5L6qdaOvGTzpXUeLwtxojHYCxqdVQ/ql0LK0GK tM3TfuHCdhWYOjvAFU/QI8DKTuF5o/VJuyhokgh6MnsriAS04HBljJKfIRHG6o50xBYm fGLYXPuWZwl3q+m44D8zD/RKbjrFR3Eaob4H6aETOPizTQPh+g5u93Nn0fAJWPlhA3o6 ljsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=HsZ+yZMW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id h1-20020a17090acf0100b0027d18475bd3si2074765pju.168.2023.10.17.09.59.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 09:59:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=HsZ+yZMW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (Postfix) with ESMTP id 739308029313; Tue, 17 Oct 2023 09:59:12 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234966AbjJQQ7E (ORCPT + 99 others); Tue, 17 Oct 2023 12:59:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39476 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234917AbjJQQ67 (ORCPT ); Tue, 17 Oct 2023 12:58:59 -0400 Received: from mail-yb1-xb35.google.com (mail-yb1-xb35.google.com [IPv6:2607:f8b0:4864:20::b35]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EAABBBA for ; Tue, 17 Oct 2023 09:58:55 -0700 (PDT) Received: by mail-yb1-xb35.google.com with SMTP id 3f1490d57ef6-d9beb865a40so2509848276.1 for ; Tue, 17 Oct 2023 09:58:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1697561935; x=1698166735; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=ehHiG5u8VUrGyvdvtZ5izhIhQL5g/E91S/K67Xu9F2I=; b=HsZ+yZMWmDsMDdrizETAGYwBuuk14i732KmQBss8+RTYrOYPV9NoVW/tKkNAnCUYw9 gc5YzWhFtvm/7tsVFIdUZ92qutuLi+6uMoAyPMHCW+n6SHmzJ5Pf107eR7etY7E2svPN nYj8Mc3k+fIwBNBpM5IDfuksdX2XvZLWryzwPJUpiK2TBz2D8VPQlNZ8UcL2iZ3WT/7i +Vkeh6pHkUlEN01RJHho9jZv1gIJsS26Rv6RG32tVW40ALqKYQMrAOilAVrEpHECAF3y gHigajW4UztKWIJs6irQoFl9+/slSv6V7KzIM2k5I+4VJeQ5/nFoeWWqEuciHSKbyISp 6IUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697561935; x=1698166735; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ehHiG5u8VUrGyvdvtZ5izhIhQL5g/E91S/K67Xu9F2I=; b=v7YK5orEcr4+VD64p2mlo6B1VIFvrk5w+cPM+bs6E+kFEe4fiLUyS1yo4gAkeYD0Xc //YCOJE+/lZayXNjh5NhNa2+mLk7KVk0jJbOBO2sEhG3aiFIZUVNRtQOgynheOaMojKH IIiCTdMhcyspuwk2NPJKuHgM+/Dfrpvmo4Ko3V/EE7tkU0nHghQBDgP4a3hm25i8Cdy0 hdZxSwpsKd0XU4xMP0qOVpsDLlCnEpytkLPz6Y8F2aLYwhd2vXA0nKJYgXf/aZcli4hk BmZw1w6Wt+pmUxl9Pu3lGv6LW5H7Y6MBAz0Hh/pHcBK4PIWrI6ITfWy2uHV6CyqmYMnv TE4w== X-Gm-Message-State: AOJu0YyBXF7mqHeI43QW2U7AHDNZtJV+4mprSYiAr2rx4JpOPP20QMEu ZUGzfKUltgwFRLQELmcA6nr7FjJgguw0gHp2aOPV1g== X-Received: by 2002:a25:ec02:0:b0:d86:357:e314 with SMTP id j2-20020a25ec02000000b00d860357e314mr2757061ybh.47.1697561934985; Tue, 17 Oct 2023 09:58:54 -0700 (PDT) MIME-Version: 1.0 References: <20231002204017.GB27267@noisy.programming.kicks-ass.net> <20231003081616.GE27267@noisy.programming.kicks-ass.net> <20231004112152.GA5947@noisy.programming.kicks-ass.net> <03b7da03-78a1-95b1-3969-634b5c9a5a56@amd.com> <20231011141535.GF6307@noisy.programming.kicks-ass.net> In-Reply-To: From: Mingwei Zhang Date: Tue, 17 Oct 2023 09:58:18 -0700 Message-ID: Subject: Re: [Patch v4 07/13] perf/x86: Add constraint for guest perf metrics event To: Manali Shukla Cc: Peter Zijlstra , Sean Christopherson , Ingo Molnar , Dapeng Mi , Paolo Bonzini , Arnaldo Carvalho de Melo , Kan Liang , Like Xu , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , kvm@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Zhenyu Wang , Zhang Xiong , Lv Zhiyuan , Yang Weijiang , Dapeng Mi , David Dunn , Thomas Gleixner , Jim Mattson , Like Xu Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 pete.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 (pete.vger.email [0.0.0.0]); Tue, 17 Oct 2023 09:59:12 -0700 (PDT) On Tue, Oct 17, 2023 at 3:24=E2=80=AFAM Manali Shukla wrote: > > On 10/11/2023 7:45 PM, Peter Zijlstra wrote: > > On Mon, Oct 09, 2023 at 10:33:41PM +0530, Manali Shukla wrote: > >> Hi all, > >> > >> I would like to add following things to the discussion just for the aw= areness of > >> everyone. > >> > >> Fully virtualized PMC support is coming to an upcoming AMD SoC and we = are > >> working on prototyping it. > >> > >> As part of virtualized PMC design, the PERF_CTL registers are defined = as Swap > >> type C: guest PMC states are loaded at VMRUN automatically but host PM= C states > >> are not saved by hardware. > > > > Per the previous discussion, doing this while host has active counters > > that do not have ::exclude_guest=3D1 is invalid and must result in an > > error. > > > > Yeah, exclude_guest should be enforced on host, while host has active PMC > counters and VPMC is enabled. > > > Also, I'm assuming it is all optional, a host can still profile a guest > > if all is configured just so? > > > > Correct, host should be able to profile guest, if VPMC is not enabled. > > >> If hypervisor is using the performance counters, it > >> is hypervisor's responsibility to save PERF_CTL registers to host save= area > >> prior to VMRUN and restore them after VMEXIT. > > > > Does VMEXIT clear global_ctrl at least? > > > > global_ctrl will be initialized to reset value(0x3F) during VMEXIT. Simil= arly, > all the perf_ctl and perf_ctr are initialized to reset values(0) at VMEXI= T. Are these guest values (automatically) saved in the guest area of VMCB on VMEXIT? > > >> In order to tackle PMC overflow > >> interrupts in guest itself, NMI virtualization or AVIC can be used, so= that > >> interrupt on PMC overflow in guest will not leak to host. > > > > Can you please clarify -- AMD has this history with very dodgy PMI > > boundaries. See the whole amd_pmu_adjust_nmi_window() crud. Even the > > PMUv2 update didn't fix that nonsense. > > > > How is any virt stuff supposed to fix this? If the hardware is late > > delivering PMI, what guarantees a guest PMI does not land in host > > context and vice-versa? > > > > How does NMI virtualization (what even is that) or AVIC (I'm assuming > > that's a virtual interrupt controller) help? > > > > When NMI virtualization is enabled and source of VNMI is in guest, micro = code will > make sure that VNMI will directly be delivered to the guest (even if NMI = was late > delivered), so there is no issue of leaking guest NMI to the host. > > > Please make very sure, with your hardware team, that PMI must not be > > delivered after clearing global_ctrl (preferably) or at the very least, > > there exists a sequence of operations that provides a hard barrier > > to order PMI. > > > We are verifying all the corner cases, while prototyping PMC virtualizati= on. > As of now, we don't see guest NMIs leaking to host issue. But latency iss= ues > still stays. How long is the latency? From the existing code (amd_pmu_disable_all() =3D> amd_pmu_check_overflow()), it seems to take up to 50 microseconds in amd_pmu_check_overflow(). But I wonder how much in reality. Thanks. -Mingwei >