Received: by 10.213.65.68 with SMTP id h4csp1583639imn; Wed, 4 Apr 2018 23:32:27 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+EdmMnV4fTFwHaNvDytFNzPy1Wpt20crASqhi73zRLTpT5zTsx04/AwsGLZ3X1Z/nOsyVZ X-Received: by 2002:a17:902:8d96:: with SMTP id v22-v6mr22127797plo.373.1522909947071; Wed, 04 Apr 2018 23:32:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522909947; cv=none; d=google.com; s=arc-20160816; b=ItNyKnQQJ2Szwfs5Wr/MoBIPoHR/hSOB5HHUxenU4QbU9Zr9JWqHtTV7b+PCz1pHQw zbVjTiSHPpvGxl3yL/QpDKYEjTCnpet9RJfDjOSBWT9rOp85clG5zWs6GevNjodIb44F LeIZVtL/p8lZHgBofyhD1kPTFEVXuVDo8XuIZ0n12oS9yV5gw73TZ5R3b0OG1WRRU12a bZGWxaIDH+yvTwU0J9DLPKVWIzIFsrgZA9T2dKxPvrYHZjFYRo0G+u8okkZ4fuGLPb3k L5goq1kN39dwUJQ8IQqdszl1Was6AWpP3x1zXP2U3Ox9lvmarFpRwvsy8WKOjnt+0gG+ h/HQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=WA1EBYkICZ9hgY6jfTF7VTCuPqiFHJO00Glo6+nUQ4M=; b=cfTFl6QZxmmJ+enaPKTGRxaTNnmCwwDE587KTxkR3I8KvU+7oq1cHbWTcexwV1FXLm wF0duoZK3OwNQukp5dLpwIP/G8OCf2keYzRZFry8QHcO6rvvyB9tDG+8p94MoEHfnEVc RgQEu29M3YxoNh/8+SvfzXbjmWIv+1BmHUTVBT50dFo4fk1bVpep6lDCpU0eBxCuGvRE SqQAfHOS8HXNQnKhwhrXMN4e+nKwpfzL8xt7k3FimccKIGic5B7406x0cCZkkOiBjvBE 1ixIflMK3mEpGt7USfkWzG4iMJMih4bsbCgCNZLgP5wQGmHSmiRBuKULR5PohClV31Ux AILA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=D/0UkySr; 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 a3si4870559pgt.644.2018.04.04.23.31.58; Wed, 04 Apr 2018 23:32:27 -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=D/0UkySr; 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 S1751445AbeDEGaG (ORCPT + 99 others); Thu, 5 Apr 2018 02:30:06 -0400 Received: from mail-pl0-f65.google.com ([209.85.160.65]:33281 "EHLO mail-pl0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751249AbeDEGaA (ORCPT ); Thu, 5 Apr 2018 02:30:00 -0400 Received: by mail-pl0-f65.google.com with SMTP id s10-v6so15821021plp.0 for ; Wed, 04 Apr 2018 23:30:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=WA1EBYkICZ9hgY6jfTF7VTCuPqiFHJO00Glo6+nUQ4M=; b=D/0UkySrCrFAgtlVjlIR+I9DBW/bIw0Kkp/iPgxVSAsshQnCRaVZlIOlu9eIk+qQXl WJvZIltWZIYXbCtxnoCi7qmriStwvEdoTuR2JXEeAywzTJa9UqspQvMkkiswcUUo/Lz2 vsvxXCAXSH7Yr3b8aUBm6u0utdYVNVl/MQsQ/fKF3Q4ScxJ8jBETXtZno/jFhA3STJrm wH7vj3+rJSe1qOxsnT2qsaQik8DXwKFY0l9InKmBS0fLms83i/I1lQFhZEUkPsxHN5Ia 0kY21A51gdgGWkw+7g22Pq84CpdLYTzaWkJGkOqH/dGc1sEodHpqgiz0M7tVkb4S+AfB qSKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=WA1EBYkICZ9hgY6jfTF7VTCuPqiFHJO00Glo6+nUQ4M=; b=QWDp7g/5NrsATcWdSjQ07nvP3K+p+ODO1WEQleRr1Xjl+Y+vrOVupM+WhvRGhk5Twv MIwkCaYL4ZvjB/dMmwl0Ag5stRpDqdgMYymcSTSnA3112EUc6BU7IvBMrg1pPtM0fdJD IRYNAgmhAnj4YG84JL6PWf26OIZwIwsf6aJORfYFw0+gDWDMgf5J0TMUxf+lOKWk9H21 95j98er5z+A3p/i6n+PElUZS8Aj020q5GMaqAMI7fMZsl6MkZghYIywck8xYeapG9+Nd eYXlhCcYjaAh1AvyOw43pQ2e8weuUb8x0kidkh3xMtA5UHsqeuzS9SIYN3pPhrIyzIWF RZVw== X-Gm-Message-State: ALQs6tC5zd6t22G8mHnhX0hkPjBLEnhmZIkkzJ2uAvck5MkDcHk5WRd3 xoW7uVSgdQiqk+QjkBV3bBZm7YeBoOc= X-Received: by 2002:a17:902:9892:: with SMTP id s18-v6mr5439878plp.95.1522909799281; Wed, 04 Apr 2018 23:29:59 -0700 (PDT) Received: from localhost (c-67-169-55-77.hsd1.ca.comcast.net. [67.169.55.77]) by smtp.gmail.com with ESMTPSA id h6sm8625937pfi.35.2018.04.04.23.29.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 04 Apr 2018 23:29:57 -0700 (PDT) From: Stephane Eranian To: linux-kernel@vger.kernel.org Cc: acme@redhat.com, peterz@infradead.org, mingo@elte.hu, ak@linux.intel.com, kan.liang@intel.com, jolsa@redhat.com Subject: [PATCH v2] perf/x86/intel: move regs->flags EXACT bit init Date: Wed, 4 Apr 2018 23:29:51 -0700 Message-Id: <1522909791-32498-1-git-send-email-eranian@google.com> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch removes a redundant store on regs->flags introduced by commit: 71eb9ee9596d ("perf/x86/intel: Fix linear IP of PEBS real_ip on Haswell and later CPUs") We were clearing the PERF_EFLAGS_EXACT but it was overwritten by regs->flags = pebs->flags later on. The PERF_EFLAGS_EXACT is a software flag using bit 3 of regs->flags. X86 marks this bit as Reserved. To make sure this bit is zero before we do any IP processing, we clear it explicitly. Patch also removes the following assignment: regs->flags = pebs->flags | (regs->flags & PERF_EFLAGS_VM); Because there is no regs->flags to preserve anymore because set_linear_ip() is not called until later. In V2, we improve reability of the comments. Signed-off-by: Stephane Eranian --- arch/x86/events/intel/ds.c | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/arch/x86/events/intel/ds.c b/arch/x86/events/intel/ds.c index da6780122786..e4e97fc8eec3 100644 --- a/arch/x86/events/intel/ds.c +++ b/arch/x86/events/intel/ds.c @@ -1153,7 +1153,6 @@ static void setup_pebs_sample_data(struct perf_event *event, if (pebs == NULL) return; - regs->flags &= ~PERF_EFLAGS_EXACT; sample_type = event->attr.sample_type; dsrc = sample_type & PERF_SAMPLE_DATA_SRC; @@ -1197,7 +1196,13 @@ static void setup_pebs_sample_data(struct perf_event *event, * and PMI. */ *regs = *iregs; - regs->flags = pebs->flags; + + /* + * Initialize regs_>flags from PEBS, + * clear exact bit (which uses x86 EFLAGS Reserved bit 3), + * i.e., do not rely on it being zero. + */ + regs->flags = pebs->flags & ~PERF_EFLAGS_EXACT; if (sample_type & PERF_SAMPLE_REGS_INTR) { regs->ax = pebs->ax; @@ -1217,10 +1222,6 @@ static void setup_pebs_sample_data(struct perf_event *event, regs->sp = pebs->sp; } - /* - * Preserve PERF_EFLAGS_VM from set_linear_ip(). - */ - regs->flags = pebs->flags | (regs->flags & PERF_EFLAGS_VM); #ifndef CONFIG_X86_32 regs->r8 = pebs->r8; regs->r9 = pebs->r9; @@ -1234,20 +1235,33 @@ static void setup_pebs_sample_data(struct perf_event *event, } if (event->attr.precise_ip > 1) { - /* Haswell and later have the eventing IP, so use it: */ + /* + * Haswell and later processors have eventing IP + * which avoids the off-by-1 skid. Use it when + * precise_ip >= 2 + */ if (x86_pmu.intel_cap.pebs_format >= 2) { set_linear_ip(regs, pebs->real_ip); regs->flags |= PERF_EFLAGS_EXACT; } else { - /* Otherwise use PEBS off-by-1 IP: */ + /* Otherwise, use PEBS off-by-1 IP */ set_linear_ip(regs, pebs->ip); - /* ... and try to fix it up using the LBR entries: */ + /* + * With precise_ip >= 2, try to fix up the off-by-1 IP + * using the LBR. If successful, the fixup function + * corrects regs->ip and calls set_linear_ip() on regs. + */ if (intel_pmu_pebs_fixup_ip(regs)) regs->flags |= PERF_EFLAGS_EXACT; } - } else + } else { + /* + * when precise_ip == 1, return the PEBS off-by-1 IP, + * no fixup attempted + */ set_linear_ip(regs, pebs->ip); + } if ((sample_type & (PERF_SAMPLE_ADDR | PERF_SAMPLE_PHYS_ADDR)) && -- 2.7.4