Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp3057849rdg; Tue, 17 Oct 2023 03:24:47 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGNW9gR5068IjHl5VFgriI5tloI7xqLl9WJD7jl1MPXFXB/BCpWVO1pHsmDW9kOHOspW7VN X-Received: by 2002:a17:902:d481:b0:1ca:90bf:156f with SMTP id c1-20020a170902d48100b001ca90bf156fmr2316548plg.37.1697538287576; Tue, 17 Oct 2023 03:24:47 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697538287; cv=pass; d=google.com; s=arc-20160816; b=X0y9ZM6TV/09kFZTvZtRnX/Qrd7hXcYrIilvB4W+0pvqerdfrpppuBECJC/yVvTxhw ENMM5gD+xKl+i6H7e3sL1DHZ56YHW5xnMDOeJ9jCsUuRZiNksJrG4h38p/7b0GUXEr/G yzqbU+HT4A47y7DSMBNShvNT+hy7eljjLKBaNeOI6VTK1KZ/WC4idF5adCsa0quIKjnj RYV7szmzC12XVa7x72YqdJ3LtvUciD7muXm9lGDyTxv//WQk+lsozKK6AvRzvVDvWUeo /UWI7GW/bLy1USJpeMbSS4vPtCO0MszzSaRBSYlok/gBvslY21kgDmHw7GVc92R+zSmc BtnQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :in-reply-to:from:references:cc:to:subject:user-agent:date :message-id:dkim-signature; bh=hkI/ESHaVWN97YLxP2N1yT5zwD12AFsR7KpZBtrljjI=; fh=5TofPbdBC3DFUqr/zH/H5xjJ5tkY/6SbLxW3vuZGHv8=; b=FPR7WbAwRB9oXvAIlZJMZrD/b4Sxo6mFTcr6k0cgDLNvZOX1FJ5ySLYBZZaKBNcHbK mP5ywKL7Pj8OQyJ95+idXHO/64mXWkx9pUK23dsohhrZ5TG4ddbW9zZE4QTwfX6MDSQs iEgH7yMqb5HNKVdX2ZqlmEETmQ2+ef/ois7WXzP4O5KQm8rzGoT2QyqS6+71DtfXnZWt G5dnfPx8ZMKcOmYkwpk+qxHPrgEyu0jRr2ieyFOqX/jIvs6pR/ZSnLYKquzu8IytCD1Z HRdjJrUUI7cXU9l2lo5qjt+VRMHde4r5I73VfM6CWfCDQuZ1Hm+a4EVKKo2hZfJXEFp5 FoOw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=tgMF8GJe; arc=pass (i=1 spf=pass spfdomain=amd.com dkim=pass dkdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id l1-20020a170902eb0100b001ca01fd8942si380592plb.120.2023.10.17.03.24.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 03:24:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=tgMF8GJe; arc=pass (i=1 spf=pass spfdomain=amd.com dkim=pass dkdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id AF622806CC06; Tue, 17 Oct 2023 03:24:46 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234807AbjJQKYm (ORCPT + 99 others); Tue, 17 Oct 2023 06:24:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37946 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233570AbjJQKYl (ORCPT ); Tue, 17 Oct 2023 06:24:41 -0400 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2062.outbound.protection.outlook.com [40.107.92.62]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 826ED8E; Tue, 17 Oct 2023 03:24:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hIwND35CjyiM4db2fCgPyB8elnu4xQAx5+mgEaGkC1yncUr988efMZPxUO6Ei6xolFeXWk7uPvfsvjsY50UbL07KIwQSb9ps82VTWkOdO5LXDeEZrwHJBvo6FDohbAvkIaVBzuPkxDfEwJL+Q/3rkyxl94c9o94xKAHzRgH1sKpivXuOU86Gl+AT6UmGrwqfwiF7QJ0mfM09lNvf/WfuGTtUgg9uEdHiJQUwQtwUpBLB1ALnw+iSgZMfLI727vHe58WSwo10GDLguHe23vjr5dtk4yXxUrVHXAcXq88PTCPgDRTC21xbxGVeI7K9GBGDcTOPJ3PIk+qUJ+vO2D3o1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=hkI/ESHaVWN97YLxP2N1yT5zwD12AFsR7KpZBtrljjI=; b=Jo6/5/+Wry9zjW9kOQLFz0G5o5EbLJyQkMy0s3opiO9zaCsemCXle5hLfHEIummv4E26+4sS0YvNpQqAPkrbv1OwnHNWwC8Epfro4hAc6To7kDDPp0Q7/OQGf+QSXoPDV6HMablHXf9GVh2IjFDVMt0uM1lWCkY9o0Cdxnq1LWGOxsncsyFhZAKGNcJtqnMM37+CFNAEUikOVyXRUPuflbfmKBx6yxnOFp6ZYC2Qhbv7piXQuPCnOsBAFZAvVL6kpCmTkuQibLFq1Z16D981cJfV2+A+zUvusSzocHVPMxJYN3+2tqe12EWjQrKCdBTLvVyRSsfXYwenUTpW0kuGGg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=hkI/ESHaVWN97YLxP2N1yT5zwD12AFsR7KpZBtrljjI=; b=tgMF8GJeNwms9quKFbvWQ7DOzuIq96OAvUtrPfK+Yk3g7s7ElYnKZllW0KNY7+q2PTbNnFNOo/91ndPTfnm2f7FXkGJRSKSjVQcUC9R50wMpKbGKl4tM6fghvQi6qzzkyGWMXIFAAl8KKWx969CCphSzzYYvepeBL8rTPwK40ZM= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com; Received: from DS7PR12MB6214.namprd12.prod.outlook.com (2603:10b6:8:96::13) by IA0PR12MB9046.namprd12.prod.outlook.com (2603:10b6:208:405::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6886.35; Tue, 17 Oct 2023 10:24:37 +0000 Received: from DS7PR12MB6214.namprd12.prod.outlook.com ([fe80::2d00:60c4:e350:a14d]) by DS7PR12MB6214.namprd12.prod.outlook.com ([fe80::2d00:60c4:e350:a14d%5]) with mapi id 15.20.6907.021; Tue, 17 Oct 2023 10:24:37 +0000 Message-ID: Date: Tue, 17 Oct 2023 15:54:20 +0530 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.12.0 Subject: Re: [Patch v4 07/13] perf/x86: Add constraint for guest perf metrics event To: Peter Zijlstra Cc: 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 , Mingwei Zhang , Jim Mattson , Like Xu 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> From: Manali Shukla In-Reply-To: <20231011141535.GF6307@noisy.programming.kicks-ass.net> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-ClientProxiedBy: PN3PR01CA0053.INDPRD01.PROD.OUTLOOK.COM (2603:1096:c01:98::14) To DS7PR12MB6214.namprd12.prod.outlook.com (2603:10b6:8:96::13) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS7PR12MB6214:EE_|IA0PR12MB9046:EE_ X-MS-Office365-Filtering-Correlation-Id: d48c7f94-beaf-4f59-8077-08dbcefb432f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 54TDlUDGqRqMDC6EKucEzfGRjGDZuEQp/Du+oCMAXQcImnmswBr9qizOi3JKAQeEUqhV6G3xtvLDLxUhb6W2eVg2xsp9229evs/0OsX/eDoPYdJ68iquQYrqYIvWX2NgmGlAUYNUG+A1eBy9KdCIpcaPDfpTFsnxPk3JCZORYJdISucdWtpSPzBcmYPWPAM1rKZut5UlX4DjuMCqr6zNWIjNN2s/lLxnte1RI64TIIK/AZ8rK+cGl3+tusy9eJroSH7/+3BuLxJB5VIn3vJE8cmNvu2FwzAmusn8R08A8SpK9fA3uY+g6wTCtdrYqzSUlSj620sooeiOSHgKlkmfxU0fPz9cidaNUGeVaE2fnGzRgElK++pFIUzOBboncHYCz/CiOiOgOyXXC0L4ML84bFIeuE7lsi1bo2L7T/c7gNKaV+WK5UeTZpiwKRvSMiBR3+N9S2/0w4OkJ5r7Ovp4O8F4IklwX8iBXpIYupmATADGBuqamgN7eVPOkw49YkrMg7gwAo1CV8OEFrJoSRR3pxRPwMHb9ktZhy7JXlQ0vGtM7ex6mIAFjQhRPSEmKjwfb6XGwmFrIh/amiOUT/017Yw1O2oxQQrYNtWzoiOwXZMQK2ZLrOGty0Q639Y2v2Jv7nMj6sWSUDnI+1tOnUYgfg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DS7PR12MB6214.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(376002)(366004)(396003)(136003)(346002)(39860400002)(230922051799003)(64100799003)(451199024)(1800799009)(186009)(31686004)(6666004)(478600001)(66476007)(54906003)(6916009)(6486002)(66946007)(66556008)(41300700001)(83380400001)(31696002)(38100700002)(86362001)(6512007)(316002)(2616005)(26005)(6506007)(53546011)(5660300002)(44832011)(36756003)(7416002)(8676002)(4326008)(2906002)(8936002)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?MFNRclVSVGVrSTZreTJaaitwWXBaOXFiRitEZWlYL09YOVRyZFdOTXl2dVp1?= =?utf-8?B?QVA3eU11ajRnc3VGQk5CMUZKRDUxQm92YXhjRUJ5RnZoWUFzM3NlN0VKalhO?= =?utf-8?B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bEhCaFJCQnVJWkowSmFBSytwcVliREdtZGlLQ3VlSHg1dW14WCtoTm1TSHpm?= =?utf-8?B?YXc2TllhUkM5WmU0eUd3cU9zVzZPYU9kZUhXSEsxaTNLRWJaSDJvenVHc25U?= =?utf-8?B?M1BLemdGUUlTODNVYkZVN29TUEtVeUloNmVvUjJXOTNLOUNSZWhmTHBmSTNv?= =?utf-8?Q?Engi8IdTE2r2kSlSz8OWq4BH8?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: d48c7f94-beaf-4f59-8077-08dbcefb432f X-MS-Exchange-CrossTenant-AuthSource: DS7PR12MB6214.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Oct 2023 10:24:36.8835 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 8QlTE4/zQ4WtJ9Vp0cUieFmZ9Kl3gp26tUMT3hZIwIr2LzbPqgQwtrrH6RMc+P32U4JaeCogHO0YMMWjM3wRxw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB9046 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, NICE_REPLY_A,RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS, SPF_NONE 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 17 Oct 2023 03:24:46 -0700 (PDT) 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 awareness 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 PMC states >> are not saved by hardware. > > Per the previous discussion, doing this while host has active counters > that do not have ::exclude_guest=1 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. Similarly, all the perf_ctl and perf_ctr are initialized to reset values(0) at 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 virtualization. As of now, we don't see guest NMIs leaking to host issue. But latency issues still stays.