Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp864168pxf; Wed, 7 Apr 2021 13:36:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwMnoqLsdZrV7maGvBw7yyEGwOtLQ3m+7YLtAH2+GZcPXUDCw9SKrmmE5RdETC3UgtpbWu/ X-Received: by 2002:a5e:980e:: with SMTP id s14mr4083466ioj.63.1617827785608; Wed, 07 Apr 2021 13:36:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617827785; cv=none; d=google.com; s=arc-20160816; b=k4wZkeJvKvz9w6EBvvMHrpa04M0ws4hkZVGs34lGrqaCG9vWsr34cCFazoigB9O6T9 73J4khuKlJrarOGsG0qQ7Kfqg0akbk/4YNwRDHbyqTG+k6Nn7SsRoP6feukSqx/DLiaI bZvuNZQWzvHdZxa/fVVItvVWaDHYWj6kSXGAkJlpD0JQlK+G4hBzzpgqbSWwdg9rx8h4 iqs+co43bd38Mngp9mpdPaE1lozctZ3Uhl2FBZtrUKD8G806zzyj0bDdwuc3r9LzQ6bg KQzyLtK8mIydStG+RZRanOMq3d+W4JjJu0ZRBtWTsGQet0om6trUYDgztb3+2cUytG8U SGoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=pm5+BhR2cUpRyMJC2aIbNNtM1LjZJ9DWAVkZw86zhBE=; b=qj+pshoifucxL3Wm1VchFKriEVN72fVfmPxjHyNdzTu8S8hQjHvF676od9nsuKOBkb 3d43o3bQhX6Zv0o2s0GCuS41YQHYGe3gmKiGdN9FXH0B+aUDvI27iAnCAexLXF2986m+ ViW3dhR5pUZpSs4nhr8CMmOqDdQUUGOmw2gLcHePc2LaZ0oQ21f525+NBSadTBlzxDik U6jKU2xUwifh6fVZ2zxIwy+oulEBE88eRuwgvtFNt4qF43lOt5/e5oVbM61U8K2trK66 z8olQ6IXG1sEHMK30xhgHKQEtz2VrC2JOdUubOq9tSCaEGhnMguFP7eqhdLQhlosKxPM vSaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=CI5xZ1RX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d11si19180085ioy.14.2021.04.07.13.36.13; Wed, 07 Apr 2021 13:36:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=CI5xZ1RX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349622AbhDGIlI (ORCPT + 99 others); Wed, 7 Apr 2021 04:41:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55502 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231909AbhDGIlG (ORCPT ); Wed, 7 Apr 2021 04:41:06 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5CB30C06174A; Wed, 7 Apr 2021 01:40:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=pm5+BhR2cUpRyMJC2aIbNNtM1LjZJ9DWAVkZw86zhBE=; b=CI5xZ1RXdGdwTpFA766l3JgwrG zo8qhk2L0zX9WsU/pD2KeXwR7ZZTV4YKaE8pXlTiusWDAOV4pdb6Vk/bTOwxJvLeqlciBH0xUjNVI Y8nZ6R0gfcYma3Omn2gStLFmxgcQ+dbIt4+r8E2qgQ1P9sz/wYzyNW8vmdzanUU7VqBiHKVKc8sMV 1bCzhFMdws7SmGj0oIRWmQOMEhz6NxcNFmf3cP4Man4zI/x5gRrr4Ll9FusgaPXF4UHMwWjSlWvdY T3Lvl+/EARw7NcJ0m08ozE30L54q7PEPHQLYUwzdL/hFk/tNNQQVbg0aJSbKfGdh1XLSnoAY0i/4Y 7CvDZlcQ==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94 #2 (Red Hat Linux)) id 1lU3jG-00EBC2-NY; Wed, 07 Apr 2021 08:40:06 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 176E9300119; Wed, 7 Apr 2021 10:40:01 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 0237424403D8F; Wed, 7 Apr 2021 10:40:00 +0200 (CEST) Date: Wed, 7 Apr 2021 10:40:00 +0200 From: Peter Zijlstra To: Like Xu Cc: Sean Christopherson , Paolo Bonzini , eranian@google.com, andi@firstfloor.org, kan.liang@linux.intel.com, wei.w.wang@intel.com, Wanpeng Li , Vitaly Kuznetsov , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, x86@kernel.org, linux-kernel@vger.kernel.org, Andi Kleen Subject: Re: [PATCH v4 06/16] KVM: x86/pmu: Reprogram guest PEBS event to emulate guest PEBS counter Message-ID: References: <20210329054137.120994-1-like.xu@linux.intel.com> <20210329054137.120994-7-like.xu@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210329054137.120994-7-like.xu@linux.intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Mar 29, 2021 at 01:41:27PM +0800, Like Xu wrote: > diff --git a/arch/x86/kvm/pmu.c b/arch/x86/kvm/pmu.c > index 827886c12c16..3509b18478b9 100644 > --- a/arch/x86/kvm/pmu.c > +++ b/arch/x86/kvm/pmu.c > @@ -74,11 +74,20 @@ static void kvm_perf_overflow_intr(struct perf_event *perf_event, > { > struct kvm_pmc *pmc = perf_event->overflow_handler_context; > struct kvm_pmu *pmu = pmc_to_pmu(pmc); > + bool skip_pmi = false; > > if (!test_and_set_bit(pmc->idx, pmu->reprogram_pmi)) { > - __set_bit(pmc->idx, (unsigned long *)&pmu->global_status); > + if (perf_event->attr.precise_ip) { > + /* Indicate PEBS overflow PMI to guest. */ > + skip_pmi = test_and_set_bit(GLOBAL_STATUS_BUFFER_OVF_BIT, > + (unsigned long *)&pmu->global_status); Is there actual concurrency here, or did you forget to type __? And in case you're using vim, use something like: set cino=(0:0 > + } else > + __set_bit(pmc->idx, (unsigned long *)&pmu->global_status); > kvm_make_request(KVM_REQ_PMU, pmc->vcpu); > > + if (skip_pmi) > + return; > + > /* > * Inject PMI. If vcpu was in a guest mode during NMI PMI > * can be ejected on a guest mode re-entry. Otherwise we can't