Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp1545602pxb; Tue, 8 Feb 2022 21:49:08 -0800 (PST) X-Google-Smtp-Source: ABdhPJxELbtlrFITOiOuAyDUOiK3KLZGdqK8QBBexrNWm2ojv/lHAr/fvN8r6YICMGzAyuo571Ck X-Received: by 2002:a17:90a:5407:: with SMTP id z7mr803224pjh.7.1644385748567; Tue, 08 Feb 2022 21:49:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644385748; cv=none; d=google.com; s=arc-20160816; b=zckKFlEp2T8xsNBz7bL0HBXHvhDnNi3SwlSkNXlHStkOHZEHK0yz1IJ58s3Npi6GZs HTS6WYlUnsIumRC3pN6GAgNX5ESSzX5fvWiAUHTZFB2K3owjIVq/GaTQOp8J3J07Y4/j AL7G3mTDib9F9TEFttg1a5Rl/FkhMawfmcen9Pg/gUeySXMYI5F05iZVpHS0pTgccDgL 0WjSKhEWidSNXc37duCMJRH77p/3HVQlVjrNhcsCHELupjR6XVIBC5pab+01vGTANaTO /XNmG7pFcaqreC3cyt9WRd8GzBWR3oknS8A+PMiag0rErUWm2FRoL7ZCGfRlt/b4ffWH woHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=9xA7eYVT5M2/VrmaYV4cA9B4eqyznJsTf6TVyU7AcS8=; b=e7xOimCLzUeuGG01kGy2f0tfyNTUy1IJ66ZlMVx3rTmkh4fjbO6qYsnoS02PWeZfGc WJjbd9TdDjzQW+mT3NY5PbGSWzM3xINUr2TL0c4kTMKI0l4Fzfqgr71HvKJ+Up7rRLCw gBrMlhYUzsNW1SHuuvCeiMLdSD1YGqCpkwuufm/nwmdT90hn2QzOzyv+H3jz5jSxF5sT Yx+OPAtpcVKGd60dlDVIiQdTyFPN1iqfT/TUL6uRDJZF4fhKo6SmXxPGFqWIzPdTxAjs BNYY5qldKYGXZRWCgXT9WNkd7Ywmoy25JSNDPjdGsCAOj6JmhaSSq8cDsIKB9JNDcz7C gIIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="eHe/pDa4"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=asLlUO5l; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id u9si3832516ple.105.2022.02.08.21.49.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Feb 2022 21:49:08 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="eHe/pDa4"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=asLlUO5l; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 21D96DF8E3F2; Tue, 8 Feb 2022 21:44:18 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1391318AbiBGOTs (ORCPT + 99 others); Mon, 7 Feb 2022 09:19:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44284 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1388526AbiBGNv5 (ORCPT ); Mon, 7 Feb 2022 08:51:57 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 62F0EC0401C0; Mon, 7 Feb 2022 05:51:56 -0800 (PST) Date: Mon, 07 Feb 2022 13:51:51 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1644241912; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9xA7eYVT5M2/VrmaYV4cA9B4eqyznJsTf6TVyU7AcS8=; b=eHe/pDa41pwmIPGYH51kk1NHelMzaqhOPr58LFvzbaA3W+wWVP1SSUvs10YJFgnTcdDTeE 4AKmD6HBEn6HN1g9SJcXRhqfPWpfLoLjypL+tAM2fU8chj9uSE+VNmzMCqzjcdj9dpbjX0 D/1SVCoh7Y0UvIsXRRnklvtMGnqEYfxeZqZCQ1Am/9wYnGtdlZciq0dKXTP8k4uJZkYUB6 4Q8hK0gpX3oKlcSxwSEH73IDMBsKXM/IvaNEAg9AASe3eKuQBuKRx79pyIEpNo4fDHeZ9X SDRNdlCG/QAZ8kjNiywv9IBVTpDkf9tC8kfCKwl4kfY/o+Q+ZlQIP/eJe191ZA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1644241912; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9xA7eYVT5M2/VrmaYV4cA9B4eqyznJsTf6TVyU7AcS8=; b=asLlUO5ldIeUUn2Esj//SUK2wuF1dNGufi9ZvYo71KvmKyj026bfUSxr0tmEBJV+z3wi/w YsgymR6bRh91nFDw== From: "tip-bot2 for Song Liu" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: perf/urgent] perf: Fix list corruption in perf_cgroup_switch() Cc: Song Liu , Rik van Riel , "Peter Zijlstra (Intel)" , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20220204004057.2961252-1-song@kernel.org> References: <20220204004057.2961252-1-song@kernel.org> MIME-Version: 1.0 Message-ID: <164424191171.16921.7739193739267946142.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-7.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the perf/urgent branch of tip: Commit-ID: 5f4e5ce638e6a490b976ade4a40017b40abb2da0 Gitweb: https://git.kernel.org/tip/5f4e5ce638e6a490b976ade4a40017b40abb2da0 Author: Song Liu AuthorDate: Thu, 03 Feb 2022 16:40:57 -08:00 Committer: Peter Zijlstra CommitterDate: Sun, 06 Feb 2022 22:37:27 +01:00 perf: Fix list corruption in perf_cgroup_switch() There's list corruption on cgrp_cpuctx_list. This happens on the following path: perf_cgroup_switch: list_for_each_entry(cgrp_cpuctx_list) cpu_ctx_sched_in ctx_sched_in ctx_pinned_sched_in merge_sched_in perf_cgroup_event_disable: remove the event from the list Use list_for_each_entry_safe() to allow removing an entry during iteration. Fixes: 058fe1c0440e ("perf/core: Make cgroup switch visit only cpuctxs with cgroup events") Signed-off-by: Song Liu Reviewed-by: Rik van Riel Signed-off-by: Peter Zijlstra (Intel) Link: https://lkml.kernel.org/r/20220204004057.2961252-1-song@kernel.org --- kernel/events/core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/events/core.c b/kernel/events/core.c index 57c7197..6859229 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -839,7 +839,7 @@ static DEFINE_PER_CPU(struct list_head, cgrp_cpuctx_list); */ static void perf_cgroup_switch(struct task_struct *task, int mode) { - struct perf_cpu_context *cpuctx; + struct perf_cpu_context *cpuctx, *tmp; struct list_head *list; unsigned long flags; @@ -850,7 +850,7 @@ static void perf_cgroup_switch(struct task_struct *task, int mode) local_irq_save(flags); list = this_cpu_ptr(&cgrp_cpuctx_list); - list_for_each_entry(cpuctx, list, cgrp_cpuctx_entry) { + list_for_each_entry_safe(cpuctx, tmp, list, cgrp_cpuctx_entry) { WARN_ON_ONCE(cpuctx->ctx.nr_cgroups == 0); perf_ctx_lock(cpuctx, cpuctx->task_ctx);