Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9172380pxu; Mon, 28 Dec 2020 08:22:15 -0800 (PST) X-Google-Smtp-Source: ABdhPJwljlwg/vyaYjoFuADVxRPWm6QXDU5zPHRasuWaWyxVtuN2Qotj8x7rM/KwPC4nilKHX1zI X-Received: by 2002:a17:906:d8a3:: with SMTP id qc3mr42454403ejb.443.1609172535345; Mon, 28 Dec 2020 08:22:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609172535; cv=none; d=google.com; s=arc-20160816; b=fV98F47wndUwiRzfoocVS5zot2OJZO5ijVB4l/Dvbhl41auimlJPrr1BDE3DX7Sn3U B6oTkdutnq4Edms9rH0pBhk+sDVzGuzrItDoS84jGugKGzuO3Jcn6B0Pk+SnLk5tX4sy KMUE7FMJDutM3hJflBk+JpUlURW9ai3IM8WsI0fejU0DKjF6Hfj+S/R6I/9ZX2YfI0BN /AzrLqDe0IdifYJ4IASjfJFsoD8knp+Q5fGzjThRNqNRR5bHXr8KlHBRUEjXiyvjWWVN IGv0r0hDp0nAEiIXKaCiJW6ZWKDjBzjLRBsxLyjYQtJkrouXQ6/27T4hVmDFUoZjCg8g cxDw== 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=RGgu0OhBj5bRJ2LXS2Q8seUv7K386tPuomT3y+QYO/o=; b=vyUajMojW3McguIxXELhyrQIcOdmgQsWIG7qg53P1mq2+mSiGxSxRMCbs8AsGK5PBe cM8F3sbrjEiSYDVY+c7B/gwkt+9AqH87JLntpdL8ZwRTqIM0wYUERi9RcvuDBAkGjBDo 0rVgKkWkOW5fxxQm0j1y6WQnWl9PSskXn+hsc9zvVkoaw/fI1bzQ4wxgxUVa8OR+rxak saMjJFj1Xb9oPgIIVq+SjC60boYj+zlVY34f9momIkcb119Hh9DD2uDWbHOHmaq151gi ytXynoH170PxBzJTulKqeWrpSCjyZBtvlDPbLYiMaS3j6F0CTavdQQLfko1skekczOzt w8Lw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ntS1r7dZ; 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 o26si20513578edw.74.2020.12.28.08.21.52; Mon, 28 Dec 2020 08:22:15 -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=ntS1r7dZ; 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 S2440847AbgL1QRP (ORCPT + 99 others); Mon, 28 Dec 2020 11:17:15 -0500 Received: from mail.kernel.org ([198.145.29.99]:45408 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731502AbgL1NRG (ORCPT ); Mon, 28 Dec 2020 08:17:06 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id C18E7207C9; Mon, 28 Dec 2020 13:16:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609161386; bh=flFALhujOsQ/SdUfxgVQE78tjaNosgiy4sL9SMFY8oY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ntS1r7dZiAvFy+He3D93PjcT+7kVxCtNyvCR6+E5zGrElmobVOYcG7HLFcI+aJh3H LXM6KZhihNbfoPfSXJS7+vH+BJKI44qYP9x+uBSveYPPoWvbPZhCUSFeYNsEuVcde/ AgrjI1jc3yQFwgDj0pBcJTR//JSSUmjl5hqim+eE= 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.14 196/242] powerpc/perf: Exclude kernel samples while counting events in user space. Date: Mon, 28 Dec 2020 13:50:01 +0100 Message-Id: <20201228124914.329789714@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201228124904.654293249@linuxfoundation.org> References: <20201228124904.654293249@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 @@ -2068,6 +2068,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) {