Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1968754imm; Fri, 7 Sep 2018 08:51:05 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZn21biAzf6kvJ29Ys+Cw5mR7x3Zo21RWikmE3qGXvMjpJU9M6392IqG1Uo9Ctkox0V/bCu X-Received: by 2002:a17:902:7587:: with SMTP id j7-v6mr8705325pll.256.1536335465270; Fri, 07 Sep 2018 08:51:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536335465; cv=none; d=google.com; s=arc-20160816; b=h8sbuewtu1ps8NmSsaLBxVOjy96l9xpYv1DHl6G6if4cVSih/hcwchvBMMqkLTq9Y9 +TmrNtgUQ/INGLSSGAc+O+ky/x1cHPN3j7tvEezOihy5/v4AcFBJy4Pif8rlVTD3fKr8 lIWfn1vHi+bjNX2qaWmSmFBTykPwInmOwNURbaMWC/Me+g2ejnUC6U5jKrG9od5h5XkK 00qA+oP4hCBcDREAAnfazv9SmKAFXwk5WfXSY7YsG0wWaHbmr9swjNLSbSjNGuKdGWJD x2CpvtocCh2K9mpMWx7a9RM63iDvstX5RYhuVym7KC3RO0IPVz6vYgZJRf13QsKiswt0 VWiQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=C14Jv6OqEu91YYl9D0II/PlmJJ5pjs0XzVdp7LD1wLU=; b=yAtdx2tMGKYbBeEmLsXhj7Bv97B/W0hXJu8E1dkQhZG0llAAO6xnCS2p+774el51OY S3aupGtsJdSTsE7mZ4/NKXA4+w+nWXkEe9SP3w54Qwgp9nLSPTcPp8dHcpVpEeQgzU2g AdF12RVh0Dm7u0eve90rksgblSPgK5JE7nj7iNkrvwnogX6ktKdesyH+5CUvkveICoex sx+VePhIyA7L+5MA2fd6zmqXJRAW0Z2m/+KS3N7OT5CT8ac3vIQnePmDaPbZF6Dundvl F00dlxnPhk/jYGddk+5Wjto1k4VZUOr8GZ0ZXPTIUqstdNAoc5jSD2T8Fseicc79PD0j ow/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=FO3JCZHg; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l3-v6si8965970pga.137.2018.09.07.08.50.50; Fri, 07 Sep 2018 08:51:05 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=FO3JCZHg; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729922AbeIGTSf (ORCPT + 99 others); Fri, 7 Sep 2018 15:18:35 -0400 Received: from mail-oi0-f66.google.com ([209.85.218.66]:38192 "EHLO mail-oi0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728082AbeIGTSf (ORCPT ); Fri, 7 Sep 2018 15:18:35 -0400 Received: by mail-oi0-f66.google.com with SMTP id x197-v6so27634833oix.5 for ; Fri, 07 Sep 2018 07:37:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=C14Jv6OqEu91YYl9D0II/PlmJJ5pjs0XzVdp7LD1wLU=; b=FO3JCZHgN1Cz1xGmCG8/8a1tvDEkP+kk93Z9RODPw3QiKTeFDscaF01CZGS7fE8VRp cVSKrRRJBNzp4xzbJYKSbHm7xu3EM0DGNprJ+Eq0No8O6I2mciaID6NR0RLLbeTJ2mrx haMVGH+8ADK86PNNrVi9R6cYd9RXinRB6NSLZ8dWdjosNRx5iLfMwh97MwV2uwCZ1yfv SGcs/v7+34M8/9T4uLawJURMYBU4TBnXZC15kAhIPJPbuQFx+Ct8Odeiinphs7eE6rOs HCYAyo2OFC5ank50TTHuflu+lWSltUVQ4f+5AKh77SddVIS0+BmExkJ6QkcZlzlvwoCU K5eA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=C14Jv6OqEu91YYl9D0II/PlmJJ5pjs0XzVdp7LD1wLU=; b=mAl7H08gTw+ksumfS58/SgfaCl+YVkcQXuWtqau6QA//KILf2KwQTK/FN6Bklw29lD +4yxH8l/ScwRXsTFOiD+DKawnnAXkEpMFg8y06iro7kTFUekgM8SlIzvWd1yETjP6QsG +NzcEK4/sWbRMP0bP6ruadcUT+TFxz1nMybjCSxnQBKR0SUpccRzkrzEzQjReuT4iNwk mG8QGl1pdYX3gTIcZZLoxCJqFnQKQBRbYpa2GFFupqr+61ONNLRGlrL9imSpJONQwTAc iw3iDA+CcrfV2LbQ81ohvQkgGs3O3KBlKHDRJhSvB4+DRRqNMIKCo9pYlInAQDhTqSvQ TzVw== X-Gm-Message-State: APzg51Cd2/nIHhj8RZQJIcXX41L0SOcB35WPL9DN4nnBoSmqzuqXkfhu 3ZpcFnJdJThFkbWLbHKeG1mcneKv9DGx9UMaX1RTd0uTu3E= X-Received: by 2002:aca:dc55:: with SMTP id t82-v6mr7556195oig.159.1536331041375; Fri, 07 Sep 2018 07:37:21 -0700 (PDT) MIME-Version: 1.0 References: <1536233456-12173-1-git-send-email-wei.w.wang@intel.com> <1536233456-12173-8-git-send-email-wei.w.wang@intel.com> In-Reply-To: <1536233456-12173-8-git-send-email-wei.w.wang@intel.com> From: Jann Horn Date: Fri, 7 Sep 2018 16:36:54 +0200 Message-ID: Subject: Re: [PATCH v2 7/8] KVM: PMU: support to save/restore the guest lbr stack on vCPU switching To: wei.w.wang@intel.com Cc: kernel list , kvm@vger.kernel.org, Paolo Bonzini , Andi Kleen , kan.liang@intel.com, Peter Zijlstra , Ingo Molnar , =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= , like.xu@intel.com Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Sep 7, 2018 at 4:28 PM Wei Wang wrote: > This patch adds support to KVM to save/restore the lbr stack on vCPU > context switching. > > When the guest sets the ACTIVE bit of MSR_KVM_PV_LBR_CTRL, a perf event > is created on the host for the related vCPU. This perf event ensures the > LBR stack to be saved/restored when the vCPU thread is scheduled out/in. > The perf event is removed and freed when the guest clears the ACTIVE > bit. [...] > +void guest_lbr_event_release(struct kvm_pmu *pmu) > +{ > + struct perf_event *event = pmu->guest_lbr_event; > + > + if (unlikely(!pmu->guest_lbr_event)) { > + pr_err("%s: guest_lbr_event already freed\n", __func__); > + return; > + } > + > + if (event) { > + event->pmu->stop(event, PERF_EF_UPDATE); > + perf_event_release_kernel(event); > + } > + pmu->guest_lbr_event = NULL; > +} Is there some guarantee that this method will be called when the vCPU is torn down on guest exit?