Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9039014pxu; Mon, 28 Dec 2020 05:08:27 -0800 (PST) X-Google-Smtp-Source: ABdhPJw3zRidWv7QT1Nx5Ab1q5rPhNFgjYC/DEAEp5kY08XE7+auRZzIVwP0hdBzbC2hhG3ZhjQu X-Received: by 2002:a17:906:cec3:: with SMTP id si3mr41095104ejb.277.1609160907207; Mon, 28 Dec 2020 05:08:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609160907; cv=none; d=google.com; s=arc-20160816; b=sjStqE5KBZb6ZyMM3BfdoXJzSjbiuJoHD3V5kEERXbGtMZUKIwyOOdwuQammQ3URVt TZ2JHlsv+NzoTg/sDYpm680yksP1EXJcTCoG9/AzGQx91rC+eMju8i/PDecun/0vzhNO hNqk0irWpx0TGhLQSCNCejgB3RmLOJ/WIYTccs8TM0JKHPxgEOmAn4ILqN7YMdS/jciC m25XpltCzuiok77ao8YKRF3y+H3dsk4e8xaEUrl66LXs+bQpMLNFxNZlF9nTybHs4BpS 1obEMVdk0qxi+OKT8cSacm/V8Z3NfryU3xocsEW6ZydWrXnB4apuTt/Z7IB/msR8bWNh UkXg== 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=pAiC/I+x43yW0YVS/4JRYXbkqBOKLx7GVdwwsCGAnjw=; b=09/KMgWAjE3i8CDxdeWFcA5pxbwOMGh48Idk1s7xREH5uQeejikqQik2enF+soNq+F hO9H5MynzGXLSjrZDufv3B+NJAwCa/TR2IUfEjW5FX+ZnveC72FwAKqIgahvWf4t5RFt //fyVOUqwCQDK0I+hLdfb9RysT3ClE5QiGMq8ZYGZ2aM7dUduiaGrLBKat45WtroKRYy 4iiMbt4L1Kk6KRitjhOEe5iI5hhzwmUB7aV5g0VKgqd7A7HhC6/kcsqhU/XhFlqsQlQ5 wA/NqhWbo910KXBIFfH87L7HjtMOI+ncDuFX1d3LuY5AO4Y5zzCwQsqe8eN6lkH79pI0 ZFGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=HgktQBdV; 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 i3si18071126ejk.273.2020.12.28.05.08.04; Mon, 28 Dec 2020 05:08:27 -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=HgktQBdV; 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 S1729573AbgL1NF6 (ORCPT + 99 others); Mon, 28 Dec 2020 08:05:58 -0500 Received: from mail.kernel.org ([198.145.29.99]:33494 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729556AbgL1NFs (ORCPT ); Mon, 28 Dec 2020 08:05:48 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3AE84207C9; Mon, 28 Dec 2020 13:05:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609160707; bh=fGy1YKEeSStzMJzTGrGQxzTkmcxsX2O4nZLJ7vqaE8E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HgktQBdVB8lnHlWuNgaohW/uoLKWq/crG9dRpy63ONPmy6vyNYQU0HiC7UL93wq/Y rTw5f4UCl2Xh72/GPBj/tQocgr01U9P8HuG1BEgNtLKCuvH/m4ftF5zdkXuQXBHrqd N5mkqvtrXm+wMycoMjCSHFD6rL00GWjOVGtOQE+k= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Athira Rajeev , Michael Ellerman Subject: [PATCH 4.9 143/175] powerpc/perf: Exclude kernel samples while counting events in user space. Date: Mon, 28 Dec 2020 13:49:56 +0100 Message-Id: <20201228124900.186264839@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201228124853.216621466@linuxfoundation.org> References: <20201228124853.216621466@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 @@ -2023,6 +2023,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) {