From patchwork Thu Apr 6 10:05:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 80182 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp916417vqo; Thu, 6 Apr 2023 03:29:09 -0700 (PDT) X-Google-Smtp-Source: AKy350ZiJwBj1jwI9eGola/viYxU1VeIgP9oulHRi2cQtPGLIB+wPo17UY/GE4Dphend2pVe+dn9 X-Received: by 2002:a17:903:42c3:b0:1a2:9051:f0a3 with SMTP id jy3-20020a17090342c300b001a29051f0a3mr7691962plb.24.1680776948852; Thu, 06 Apr 2023 03:29:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680776948; cv=none; d=google.com; s=arc-20160816; b=OljZB4apKoh1tTHSLAlsCVRra4pD/h74sjLPrAiXzNWFMGwwT5SC/TMjpGK0iCBgpZ wGO6/d3gvLbylx/oaDaMpUEfdyh4Xj9D27IrieZ6cwBo5w1YxFlJ8ORIqStIC4XKxEc7 8a47TdCcqxX/mEDKCgt4CUmceBduUGWIxJRxvJO1Rz9yJU+HiDGhTfjp52atdwc3tsi1 ghjRJutGbK3+70vExKioVvbWuggLZdu+S58C/oUm5QOUg2V/njKKL33BdWbEYhf8P+Jt vEhkAnZCksAcRMRNiHEAdTHZhxHVBCK8mA0zUlKOvRHrW60xeA4AV2NFQcgRDd/QAsDN 6uaw== 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=G9bnni2qE+KJKUu6Bc/CyqquYnVEcMbzQozYy1BO+BI=; b=v2oXmwurOsB+uGbq6QFreFOHhO4RyK4yQctPklBIrZupGVL0zqt8zql38RleqwEjHK 81WnlYnXRSLF2FijU4v1SoAlsVj/1O3+2pymgWZy08E4lSHcVSEjEudWO1VevzX/ziiH QK7m9a9E2aPHFJydyhExFLdFO0AocXYRVCiOb7NwwKDcVJtcxXG2eCqDBdrvwbK/mcRe sank2FA0gog9FtFKJ3JP8Okb73CGbGe+pAVlpsX/YMeIwtZEOb7c39UgMxtWgbU/4IRw sjaEE8uVTs60wUHFOLFpqbSqm4BqXbYckhAZUdiEJKGgOMAiZOTjdtnVeJ0ol8ojIond Uhfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=nfX1T98d; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=0rT0U5uo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id li11-20020a170903294b00b001990edf3d3csi1327966plb.251.2023.04.06.03.28.56; Thu, 06 Apr 2023 03:29:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=nfX1T98d; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=0rT0U5uo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234651AbjDFKFb (ORCPT + 99 others); Thu, 6 Apr 2023 06:05:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59442 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229914AbjDFKFJ (ORCPT ); Thu, 6 Apr 2023 06:05:09 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 399C55FCF; Thu, 6 Apr 2023 03:05:08 -0700 (PDT) Date: Thu, 06 Apr 2023 10:05:05 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1680775505; 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=G9bnni2qE+KJKUu6Bc/CyqquYnVEcMbzQozYy1BO+BI=; b=nfX1T98dWe3IfkI85QD8rAassbC/Vq9vh81/5WhVBC7xQFDenWuJkkvC8U+gbXuKGvtsHU R1m/UuKSXyLquDGnFSaj5KXUBiBvlKCT3rNsiibFKP4wuTcx74yx+iYBu/XTALsl/9rfoL AnKHbtm6DcdrT8aNTBogMQPhPDFCXPph/j/qhHDAe7gIbbnD6OzA0F0smHZtUGtVZdF7dg JE6Mc0gJC16c2UaRDHZIEP6UGEwxHJNN6mvxXDfRqn2VDz4iCzX7RdabONAeU3fqcOMHyL 2bk5slWNz/VCeDNpXnCTV+tRII9k6h6h1v6nez+FDq5Sdn/LovbrWFWO5dV7jg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1680775505; 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=G9bnni2qE+KJKUu6Bc/CyqquYnVEcMbzQozYy1BO+BI=; b=0rT0U5uopLKHRXjnAlS80z7pH6mTRsnS3gdRZsYY8Jn+CBw1CjhY2WjdKjoDhPkbRfNqJ1 vr/D+xR3aJQ7zPDw== From: "tip-bot2 for Kan Liang" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: perf/urgent] perf/core: Fix the same task check in perf_event_set_output Cc: Kan Liang , "Peter Zijlstra (Intel)" , Zhengjun Xing , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20230322202449.512091-1-kan.liang@linux.intel.com> References: <20230322202449.512091-1-kan.liang@linux.intel.com> MIME-Version: 1.0 Message-ID: <168077550501.404.1381259757947658488.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-2.5 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761067442198522396?= X-GMAIL-MSGID: =?utf-8?q?1762422370051427538?= The following commit has been merged into the perf/urgent branch of tip: Commit-ID: 24d3ae2f37d8bc3c14b31d353c5d27baf582b6a6 Gitweb: https://git.kernel.org/tip/24d3ae2f37d8bc3c14b31d353c5d27baf582b6a6 Author: Kan Liang AuthorDate: Wed, 22 Mar 2023 13:24:49 -07:00 Committer: Peter Zijlstra CommitterDate: Wed, 05 Apr 2023 09:58:46 +02:00 perf/core: Fix the same task check in perf_event_set_output The same task check in perf_event_set_output has some potential issues for some usages. For the current perf code, there is a problem if using of perf_event_open() to have multiple samples getting into the same mmap’d memory when they are both attached to the same process. https://lore.kernel.org/all/92645262-D319-4068-9C44-2409EF44888E@gmail.com/ Because the event->ctx is not ready when the perf_event_set_output() is invoked in the perf_event_open(). Besides the above issue, before the commit bd2756811766 ("perf: Rewrite core context handling"), perf record can errors out when sampling with a hardware event and a software event as below. $ perf record -e cycles,dummy --per-thread ls failed to mmap with 22 (Invalid argument) That's because that prior to the commit a hardware event and a software event are from different task context. The problem should be a long time issue since commit c3f00c70276d ("perk: Separate find_get_context() from event initialization"). The task struct is stored in the event->hw.target for each per-thread event. It is a more reliable way to determine whether two events are attached to the same task. The event->hw.target was also introduced several years ago by the commit 50f16a8bf9d7 ("perf: Remove type specific target pointers"). It can not only be used to fix the issue with the current code, but also back port to fix the issues with an older kernel. Note: The event->hw.target was introduced later than commit c3f00c70276d. The patch may cannot be applied between the commit c3f00c70276d and commit 50f16a8bf9d7. Anybody that wants to back-port this at that period may have to find other solutions. Fixes: c3f00c70276d ("perf: Separate find_get_context() from event initialization") Signed-off-by: Kan Liang Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Zhengjun Xing Link: https://lkml.kernel.org/r/20230322202449.512091-1-kan.liang@linux.intel.com --- kernel/events/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/events/core.c b/kernel/events/core.c index 115320f..435815d 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -12173,7 +12173,7 @@ perf_event_set_output(struct perf_event *event, struct perf_event *output_event) /* * If its not a per-cpu rb, it must be the same task. */ - if (output_event->cpu == -1 && output_event->ctx != event->ctx) + if (output_event->cpu == -1 && output_event->hw.target != event->hw.target) goto out; /*