Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9093406pxu; Mon, 28 Dec 2020 06:29:01 -0800 (PST) X-Google-Smtp-Source: ABdhPJzm2OqH8RDs3ksHUSJzd6wQWJIEga94iZg7hTSiwMJM34J7HLuyhg0JGk6eE5+y9ti393Uc X-Received: by 2002:a17:906:1393:: with SMTP id f19mr41238656ejc.431.1609165741051; Mon, 28 Dec 2020 06:29:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609165741; cv=none; d=google.com; s=arc-20160816; b=qSbpZTbqV2oTGhS/EBGf7r9t7SwxS0CntjWTFSn7jkxrXQ7vI5IhDHw4QBig6cSpYU f7qPdJUkUZ7XFAMf8W3En9WwDocN970/6DfZBQdlNAOKrK8QHnR9/jcRREK4YURxsYMv GLc14kf4I5sxQd8dNPo1iY9g1t6LB1pP4F3X4HsFrSSYZwUbL7cbdP4tpyiELb7alflf L+ABkXr60/Qj6OZsOpx5iwimiZH/XtsMKE96QYIAtHQ8kbO6tNP18wWFGMUaFtJKWPUo Qe4lHuNSNyH1oXIw+AfL9dgtL9YtFHElvX3bFw2HgSd3K96Jfke+AGhHlxmaLaLmPRrm Zerg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Obh7enJXcVvFGdhqTZ00PPf9uW7Vip8Q+TyDKIdd46g=; b=JD6o1mrK+stIJdPV3Q2PLoGguNppBkfh2PDNvp29qHQBIXHTAQmWGC1DOdn6BJdZiW jhVppSMpAntGZ5Pcz388ffnD/CsBi7rP22kvn9ArAjvUQb/Oc2nK+Chu+gSGjFKY4xcr NnhULjNs1tsCLzdApSRtxRIaq5hEKY0ithVjjS/XUfF0EmmNlJANxpRQG4qw8OHV2zDc 4lEntSP8GWgB+UFGyIwSsvo04fDrFsWnHALTKbqYCoAAHE0sBUrlsHosKjOmh3Atdk04 VrylzV4KdvK78/rzi028KzEIpCXUMLq4eHzuossjnpGdXjP89Czl8yiiD0h8PnaOg6U6 9Uvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=xVBIQsVG; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d20si19319101ejd.409.2020.12.28.06.28.37; Mon, 28 Dec 2020 06:29:01 -0800 (PST) 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=@linuxfoundation.org header.s=korg header.b=xVBIQsVG; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2503843AbgL1O0i (ORCPT + 99 others); Mon, 28 Dec 2020 09:26:38 -0500 Received: from mail.kernel.org ([198.145.29.99]:34320 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2503804AbgL1O00 (ORCPT ); Mon, 28 Dec 2020 09:26:26 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id B709B221F0; Mon, 28 Dec 2020 14:25:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609165545; bh=PeJ1Yj5psgqWtPPXCG4oxH/sNvVPUnY6H9cNlzKs/H0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xVBIQsVG7B2M4PBoUUoRPT5Y3x3XB/+Ti5CPRcdqfx2ZRDS/v6hzXF4+scdp4fxNp xzQh+pCpVm1BpZNXtcr+HQu3zuhy5vHFosQYcIBCuI/rzdYisnmgZU5MUm618zzPNb UOJnjc4F/Wz5xtVghICkE/1p5oBnmqhspAQ76VBg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Athira Rajeev , Michael Ellerman Subject: [PATCH 5.10 569/717] powerpc/perf: Exclude kernel samples while counting events in user space. Date: Mon, 28 Dec 2020 13:49:27 +0100 Message-Id: <20201228125048.168549072@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201228125020.963311703@linuxfoundation.org> References: <20201228125020.963311703@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Athira Rajeev commit aa8e21c053d72b6639ea5a7f1d3a1d0209534c94 upstream. Perf event attritube supports exclude_kernel flag to avoid sampling/profiling in supervisor state (kernel). Based on this event attr flag, Monitor Mode Control Register bit is set to freeze on supervisor state. But sometimes (due to hardware limitation), Sampled Instruction Address Register (SIAR) locks on to kernel address even when freeze on supervisor is set. Patch here adds a check to drop those samples. Cc: stable@vger.kernel.org Signed-off-by: Athira Rajeev Signed-off-by: Michael Ellerman Link: https://lore.kernel.org/r/1606289215-1433-1-git-send-email-atrajeev@linux.vnet.ibm.com Signed-off-by: Greg Kroah-Hartman --- arch/powerpc/perf/core-book3s.c | 10 ++++++++++ 1 file changed, 10 insertions(+) --- a/arch/powerpc/perf/core-book3s.c +++ b/arch/powerpc/perf/core-book3s.c @@ -2125,6 +2125,16 @@ static void record_and_restart(struct pe perf_event_update_userpage(event); /* + * Due to hardware limitation, sometimes SIAR could sample a kernel + * address even when freeze on supervisor state (kernel) is set in + * MMCR2. Check attr.exclude_kernel and address to drop the sample in + * these cases. + */ + if (event->attr.exclude_kernel && record) + if (is_kernel_addr(mfspr(SPRN_SIAR))) + record = 0; + + /* * Finally record data if requested. */ if (record) {