From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754934AbbJUNNQ (ORCPT ); Wed, 21 Oct 2015 09:13:16 -0400 Received: from bombadil.infradead.org ([198.137.202.9]:53920 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750715AbbJUNNP (ORCPT ); Wed, 21 Oct 2015 09:13:15 -0400 Date: Wed, 21 Oct 2015 15:13:10 +0200 From: Peter Zijlstra To: Andi Kleen Cc: acme@kernel.org, jolsa@kernel.org, linux-kernel@vger.kernel.org, Andi Kleen , stable@vger.kernel.org, Ingo Molnar Subject: Re: [PATCH 1/5] x86, perf: Fix LBR call stack save/restore Message-ID: <20151021131310.GE3604@twins.programming.kicks-ass.net> References: <1445366797-30894-1-git-send-email-andi@firstfloor.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1445366797-30894-1-git-send-email-andi@firstfloor.org> User-Agent: Mutt/1.5.21 (2012-12-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Oct 20, 2015 at 11:46:33AM -0700, Andi Kleen wrote: > From: Andi Kleen > > This fixes a bug added with the earlier 90405aa02. The bug > could lead to lost LBR call stacks. When restoring the LBR > state we need to use the TOS of the previous context, not > the current context. To do that we need to save/restore the tos. Current best practise also asks for: Fixes: 90405aa02247 ("perf/x86/intel/lbr: Limit LBR accesses to TOS in callstack mode") > Cc: # 4.2+ > Signed-off-by: Andi Kleen > --- a/arch/x86/kernel/cpu/perf_event_intel_lbr.c > +++ b/arch/x86/kernel/cpu/perf_event_intel_lbr.c > @@ -239,7 +239,7 @@ static void __intel_pmu_lbr_restore(struct x86_perf_task_context *task_ctx) > } > > mask = x86_pmu.lbr_nr - 1; > - tos = intel_pmu_lbr_tos(); > + tos = task_ctx->tos; > for (i = 0; i < tos; i++) { > lbr_idx = (tos - i) & mask; > wrmsrl(x86_pmu.lbr_from + lbr_idx, task_ctx->lbr_from[i]); > @@ -247,6 +247,7 @@ static void __intel_pmu_lbr_restore(struct x86_perf_task_context *task_ctx) > if (x86_pmu.intel_cap.lbr_format == LBR_FORMAT_INFO) > wrmsrl(MSR_LBR_INFO_0 + lbr_idx, task_ctx->lbr_info[i]); > } > + wrmsrl(x86_pmu.lbr_tos, tos); > task_ctx->lbr_stack_state = LBR_NONE; > } Any idea who much more expensive that wrmsr() is compared to the rdmsr() it replaces? If its significant we could think about having this behaviour depend on callstacks.