From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.0 required=3.0 tests=BAYES_00,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BFF3BC433ED for ; Mon, 17 May 2021 19:54:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9DB3361285 for ; Mon, 17 May 2021 19:54:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236740AbhEQTzh (ORCPT ); Mon, 17 May 2021 15:55:37 -0400 Received: from mail-oi1-f171.google.com ([209.85.167.171]:36366 "EHLO mail-oi1-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235960AbhEQTz2 (ORCPT ); Mon, 17 May 2021 15:55:28 -0400 Received: by mail-oi1-f171.google.com with SMTP id f184so7594377oig.3 for ; Mon, 17 May 2021 12:54:12 -0700 (PDT) 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=UJvFAYsfphhNGnY3JCFzbqw4ycY8JjD7sKxWZWUclr0=; b=UzreqkDOWnnwglZ5z3LqZl35ZnXvHJr9l16aTLJdndTzKqEQ9LEzJ8TcVb1fvdQI42 hzC4Q20VTg7i9F6dt8fPEErdO1trFCSvxPWzpO3P9JmerEJLNM4YHzqZgA3JU4q7416H Ofy1OF4O/bcnxuy1jqcuUHt2kg2mZ48xRwiTukHveIr6YB1oyCf/O6BcFpWccoCjv170 HdZH/Kel8hewvYPX5mvLjBOTZIT4fFRQPRkkwhJgTVtBRTkfiwxDzDgq4lUrh15IBNSD w5TXFosIhIRNdJehyda9d8yZgi2z+X8/IFej/hMacqI5QsQwbe3N2d5p6iO8hBUHMBjk F2sw== X-Gm-Message-State: AOAM533jW4omaNXAsTbD6o1e+uZSg4jgDWVwBSPo6KQIAaR30bZiNteg AwmsK6jK0+5kIvNtXANFcQ== X-Google-Smtp-Source: ABdhPJz2iLQy5JnlibjkljwKIgDqzaIcmfI5Zf6XTZobqsaP4PvnrXrcib+BZmN16wilY0bRGDtzjw== X-Received: by 2002:a05:6808:128a:: with SMTP id a10mr579189oiw.161.1621281251996; Mon, 17 May 2021 12:54:11 -0700 (PDT) Received: from xps15.herring.priv (24-155-109-49.dyn.grandenetworks.net. [24.155.109.49]) by smtp.googlemail.com with ESMTPSA id m81sm2920758oig.43.2021.05.17.12.54.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 May 2021 12:54:10 -0700 (PDT) From: Rob Herring To: Will Deacon , Catalin Marinas , Peter Zijlstra , Ingo Molnar , Mark Rutland Cc: Arnaldo Carvalho de Melo , Jiri Olsa , Kan Liang , Ian Rogers , Alexander Shishkin , honnappa.nagarahalli@arm.com, Zachary.Leaf@arm.com, Raphael Gault , Jonathan Cameron , Namhyung Kim , Itaru Kitayama , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v8 2/5] perf: Track per-PMU sched_task() callback users Date: Mon, 17 May 2021 14:54:02 -0500 Message-Id: <20210517195405.3079458-3-robh@kernel.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210517195405.3079458-1-robh@kernel.org> References: <20210517195405.3079458-1-robh@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kan Liang Current perf only tracks the per-CPU sched_task() callback users, which doesn't work if a callback user is a task. For example, the dirty counters have to be cleared to prevent data leakage when a new userspace access task is scheduled in. The task may be created on one CPU but running on another CPU. It cannot be tracked by the per-CPU variable. A global variable is not going to work either because of the hybrid PMUs. Add a per-PMU variable to track the callback users. Suggested-by: Rob Herring Signed-off-by: Kan Liang [robh: Also call sched_task() got sched out cases] Signed-off-by: Rob Herring --- include/linux/perf_event.h | 3 +++ kernel/events/core.c | 8 +++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h index 4cf081e22b76..a88d52e80864 100644 --- a/include/linux/perf_event.h +++ b/include/linux/perf_event.h @@ -300,6 +300,9 @@ struct pmu { /* number of address filters this PMU can do */ unsigned int nr_addr_filters; + /* Track the per PMU sched_task() callback users */ + atomic_t sched_cb_usage; + /* * Fully disable/enable this PMU, can be used to protect from the PMI * as well as for lazy/batch writing of the MSRs. diff --git a/kernel/events/core.c b/kernel/events/core.c index 2e947a485898..6d0507c23240 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -3448,7 +3448,8 @@ static void perf_event_context_sched_out(struct task_struct *task, int ctxn, perf_pmu_disable(pmu); - if (cpuctx->sched_cb_usage && pmu->sched_task) + if (pmu->sched_task && + (cpuctx->sched_cb_usage || atomic_read(&pmu->sched_cb_usage))) pmu->sched_task(ctx, false); /* @@ -3488,7 +3489,8 @@ static void perf_event_context_sched_out(struct task_struct *task, int ctxn, raw_spin_lock(&ctx->lock); perf_pmu_disable(pmu); - if (cpuctx->sched_cb_usage && pmu->sched_task) + if (pmu->sched_task && + (cpuctx->sched_cb_usage || atomic_read(&pmu->sched_cb_usage))) pmu->sched_task(ctx, false); task_ctx_sched_out(cpuctx, ctx, EVENT_ALL); @@ -3851,7 +3853,7 @@ static void perf_event_context_sched_in(struct perf_event_context *ctx, cpu_ctx_sched_out(cpuctx, EVENT_FLEXIBLE); perf_event_sched_in(cpuctx, ctx, task); - if (cpuctx->sched_cb_usage && pmu->sched_task) + if (pmu->sched_task && (cpuctx->sched_cb_usage || atomic_read(&pmu->sched_cb_usage))) pmu->sched_task(cpuctx->task_ctx, true); perf_pmu_enable(pmu); -- 2.27.0 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9B6A7C433ED for ; Mon, 17 May 2021 19:56:52 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 20DAD60FF1 for ; Mon, 17 May 2021 19:56:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 20DAD60FF1 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=J6x1/hmcooAdNDZvcKMDtWV/UAfZGQm/YAzAJrmJWfU=; b=NfAMOCiSX/3MzxfqNCgZGRAEW Ku6XYN9+/52nmnQhJxSsWCxyPFo2hbxrObpaaZ5z6vFWGiyl04Ab95YB7BkgVQFNZBEAsVKVfO6Fq 8pcuKWngkuAHhxcnc6dPPmlt6UyjZrGerLIDrNDILzoIN59B8iJ4yRmIVHFw4NbgnDxM7X+AB3+10 69kLJZAr46uvWPlDdLks+mWexsvGwVh6hGOkO9+J5g8YazUieR7k7BGzE+S1WeVdGix/z12LZ/z3x VopG8LUmxDj1To9oit60r56uUHgPnqGImZSWbglqcUje68NI5qjR3D63vcl36TbD+RXyFhPEo+roL ssEeq7CdA==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lijK5-00FzKz-T6; Mon, 17 May 2021 19:54:42 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lijJg-00FzG9-8c for linux-arm-kernel@desiato.infradead.org; Mon, 17 May 2021 19:54:16 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=UJvFAYsfphhNGnY3JCFzbqw4ycY8JjD7sKxWZWUclr0=; b=uQuPxLXVNVw8ao8lnYwYT4+ad3 S6VyzIvMRzeHcHlsWPPU5hiC/odL01LxwiC0TrM5Tdr7B7dxSyq1ZAL1+PGNobKdqbJupks8uhPt6 EGWIXUvzntmoYXItupynHLOaCBej8TQ4hOdjRlILfOQip7ebV7qX7DqTyqQHXNLBX37hSaetUXX9e SzlfkanP031l2Z5fYgXAlJxewsbNhcxgHvSyw5xKnDDZRoCodTw08KEu2R6vQ2rURqsZl2fMLQom1 rBRMih6XckYDH30iLmel7HxVoEgTAPvIl0lk37V1JNJnIBvcEZykha7NBX/q2a83MFPPYA1fpMct2 evVStoWA==; Received: from mail-oi1-f173.google.com ([209.85.167.173]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lijJd-00E6Zo-Bf for linux-arm-kernel@lists.infradead.org; Mon, 17 May 2021 19:54:15 +0000 Received: by mail-oi1-f173.google.com with SMTP id h9so7596605oih.4 for ; Mon, 17 May 2021 12:54:12 -0700 (PDT) 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=UJvFAYsfphhNGnY3JCFzbqw4ycY8JjD7sKxWZWUclr0=; b=WWHyrtoMfhF9nQ8i2xNzDdbMEkM+1O9yEcW/eI3GAs8PrSjVzBREna/sdWNQLklIar HY/a5bb/PO4aR16ROEW/aQyHI6vPvj9NU4wtZewmmBaz0p/JAj+9wxtA+4huCMP4LPAG 4U8M1K8lRcd2bessFwTX6cPVNwYfRQ2qsUwO5gKEh1YB99XpXdRmIp8vl7fz8UC0ww+L AKMmkpWV44t8eccpHE3zREmSL2P25nMNnS2sgt4YClxAmo7DFsF4RoqljG0YqRVdTOc5 MCA1Du8L+aeZ0wQ+Hh1A7bW2ppqYBErxTW/s02eT8X2oMBx7S/pPG01grD5OuVz08pnr Mybg== X-Gm-Message-State: AOAM531faKsnQekuPVERoBIOtDO18CpKpb/RSStw/tCVZNL4Zhhoe4Vk FdzRDJDiAEM1FCOJbscshQ== X-Google-Smtp-Source: ABdhPJz2iLQy5JnlibjkljwKIgDqzaIcmfI5Zf6XTZobqsaP4PvnrXrcib+BZmN16wilY0bRGDtzjw== X-Received: by 2002:a05:6808:128a:: with SMTP id a10mr579189oiw.161.1621281251996; Mon, 17 May 2021 12:54:11 -0700 (PDT) Received: from xps15.herring.priv (24-155-109-49.dyn.grandenetworks.net. [24.155.109.49]) by smtp.googlemail.com with ESMTPSA id m81sm2920758oig.43.2021.05.17.12.54.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 May 2021 12:54:10 -0700 (PDT) From: Rob Herring To: Will Deacon , Catalin Marinas , Peter Zijlstra , Ingo Molnar , Mark Rutland Cc: Arnaldo Carvalho de Melo , Jiri Olsa , Kan Liang , Ian Rogers , Alexander Shishkin , honnappa.nagarahalli@arm.com, Zachary.Leaf@arm.com, Raphael Gault , Jonathan Cameron , Namhyung Kim , Itaru Kitayama , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v8 2/5] perf: Track per-PMU sched_task() callback users Date: Mon, 17 May 2021 14:54:02 -0500 Message-Id: <20210517195405.3079458-3-robh@kernel.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210517195405.3079458-1-robh@kernel.org> References: <20210517195405.3079458-1-robh@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210517_125413_403137_169F6F46 X-CRM114-Status: GOOD ( 16.98 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Kan Liang Current perf only tracks the per-CPU sched_task() callback users, which doesn't work if a callback user is a task. For example, the dirty counters have to be cleared to prevent data leakage when a new userspace access task is scheduled in. The task may be created on one CPU but running on another CPU. It cannot be tracked by the per-CPU variable. A global variable is not going to work either because of the hybrid PMUs. Add a per-PMU variable to track the callback users. Suggested-by: Rob Herring Signed-off-by: Kan Liang [robh: Also call sched_task() got sched out cases] Signed-off-by: Rob Herring --- include/linux/perf_event.h | 3 +++ kernel/events/core.c | 8 +++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h index 4cf081e22b76..a88d52e80864 100644 --- a/include/linux/perf_event.h +++ b/include/linux/perf_event.h @@ -300,6 +300,9 @@ struct pmu { /* number of address filters this PMU can do */ unsigned int nr_addr_filters; + /* Track the per PMU sched_task() callback users */ + atomic_t sched_cb_usage; + /* * Fully disable/enable this PMU, can be used to protect from the PMI * as well as for lazy/batch writing of the MSRs. diff --git a/kernel/events/core.c b/kernel/events/core.c index 2e947a485898..6d0507c23240 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -3448,7 +3448,8 @@ static void perf_event_context_sched_out(struct task_struct *task, int ctxn, perf_pmu_disable(pmu); - if (cpuctx->sched_cb_usage && pmu->sched_task) + if (pmu->sched_task && + (cpuctx->sched_cb_usage || atomic_read(&pmu->sched_cb_usage))) pmu->sched_task(ctx, false); /* @@ -3488,7 +3489,8 @@ static void perf_event_context_sched_out(struct task_struct *task, int ctxn, raw_spin_lock(&ctx->lock); perf_pmu_disable(pmu); - if (cpuctx->sched_cb_usage && pmu->sched_task) + if (pmu->sched_task && + (cpuctx->sched_cb_usage || atomic_read(&pmu->sched_cb_usage))) pmu->sched_task(ctx, false); task_ctx_sched_out(cpuctx, ctx, EVENT_ALL); @@ -3851,7 +3853,7 @@ static void perf_event_context_sched_in(struct perf_event_context *ctx, cpu_ctx_sched_out(cpuctx, EVENT_FLEXIBLE); perf_event_sched_in(cpuctx, ctx, task); - if (cpuctx->sched_cb_usage && pmu->sched_task) + if (pmu->sched_task && (cpuctx->sched_cb_usage || atomic_read(&pmu->sched_cb_usage))) pmu->sched_task(cpuctx->task_ctx, true); perf_pmu_enable(pmu); -- 2.27.0 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel