From patchwork Tue Sep 12 18:07:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Beau Belgrave X-Patchwork-Id: 13878 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9ecd:0:b0:3f2:4152:657d with SMTP id t13csp629392vqx; Tue, 12 Sep 2023 12:21:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFQioGvPM50ooF/cjH8bVXJi2HzNXs8ULNehOFzhKsxQP34Hg1pj5ccrNOXrcVM5/SA4GFk X-Received: by 2002:a05:6870:6490:b0:1b3:fec4:31e with SMTP id cz16-20020a056870649000b001b3fec4031emr530950oab.6.1694546469063; Tue, 12 Sep 2023 12:21:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694546469; cv=none; d=google.com; s=arc-20160816; b=RPmsoysO784GzRvpizT+eLVy/W7ZkUnwe0EX43kGg4y8c0lxTpk0jyD5E5l2DDUbNw YaCRzIBrrtBKVe4WyyKK9gRrwIJRGFtac4o6BR7OtLUSDUrhx6JXXBUdZV1hM0VfsHux 9PXOrnYnphXxkjsbrbFjTA462AD650Y78fWAkf3uJEX/soF6zFh/WR4QnMJQ8JkGVyUR YoyLlu5MCMgxA2HkJZOujd/nD2FpRudgiI4DhxUaMqNcp5/nfxN8pHeBE7VZZ+1FzpSo goyUhAauVKjpOdML4aJe45sRa4F/QyDl/pF4J9XwIFV4kGk0j74SpZzpZ818ABJNbGKW Ao5g== 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 :message-id:date:subject:cc:to:from:dkim-signature:dkim-filter; bh=y1wsenSMOrkmybSIHUz/bazYjNhC0hJ4tRUN+9GanlI=; fh=g5yIVi+SPO3ajSHXdSEStn5LTcThSaZxjHkvi+qwBXA=; b=CpWcy27zs19kndWYcKOYqJi+AKw9eMfs6ZHg1VNR5UlT1EZb0iSl0ggGeTQHNAiupJ yCb+1moO3gdEICMGsAdT8UOjBsVks2VJsLddJ3YOUCal77vztp3VVb7sz1JY1TDgQYqA ZGsAB5OVALILOj3iPkDEZHD1cej0tFGAZxGUynArmJ7XTKJHLnMSeUgmZW5kxa1TmpzF 9cZKjWpszhUx4EGtUxd7MjytMjt7A58TTdzrsn9ToO4hOpiXW3M0nje08GPSCuPXUpZY ly1KLVrQDVNoCdzYQbz3+mI2MctuTWeEWAgeqisVe/XCk61ZdB38GzXRZbu73u6lPTj1 Cy0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=I79iPRKd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id s18-20020a639252000000b00564d6ad2746si5062307pgn.452.2023.09.12.12.21.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 12:21:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=I79iPRKd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 9746A81E62B1; Tue, 12 Sep 2023 11:07:21 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237300AbjILSHQ (ORCPT + 36 others); Tue, 12 Sep 2023 14:07:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48526 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229815AbjILSHP (ORCPT ); Tue, 12 Sep 2023 14:07:15 -0400 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 362C410D3; Tue, 12 Sep 2023 11:07:11 -0700 (PDT) Received: from localhost.localdomain (unknown [4.155.48.112]) by linux.microsoft.com (Postfix) with ESMTPSA id AC791212BC16; Tue, 12 Sep 2023 11:07:10 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com AC791212BC16 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1694542030; bh=y1wsenSMOrkmybSIHUz/bazYjNhC0hJ4tRUN+9GanlI=; h=From:To:Cc:Subject:Date:From; b=I79iPRKd+Rgw5hwAQXekb0Judn6ik8AwfQ4FYhrH4pLCPd0WA9ADtHhscmsFrnCKp lPvsaoxhq1BaSG/NHLBhjWuuLNIKP5AUWD/8ucQMbxYQkJFTZD98EXXmGySyvYiBxP DBbdzhUsU2eIFvrnrVYRwtI4Duz54xnQ5k5lQWNA= From: Beau Belgrave To: rostedt@goodmis.org, mhiramat@kernel.org Cc: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, ast@kernel.org, dcook@linux.microsoft.com Subject: [PATCH v2 0/3] tracing/user_events: Allow events to persist for perfmon_capable users Date: Tue, 12 Sep 2023 18:07:01 +0000 Message-Id: <20230912180704.1284-1-beaub@linux.microsoft.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Tue, 12 Sep 2023 11:07:21 -0700 (PDT) X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776860758653106835 X-GMAIL-MSGID: 1776860758653106835 There are several scenarios that have come up where having a user_event persist even if the process that registered it exits. The main one is having a daemon create events on bootup that shouldn't get deleted if the daemon has to exit or reload. Another is within OpenTelemetry exporters, they wish to potentially check if a user_event exists on the system to determine if exporting the data out should occur. The user_event in this case must exist even in the absence of the owning process running (such as the above daemon case). Since persistent events aren't automatically cleaned up, we want to ensure only trusted users are allowed to do this. It seems reasonable to use CAP_PERFMON as that boundary, since those users can already do many things via perf_event_open without requiring full CAP_SYS_ADMIN. This patchset brings back the ability to use /sys/kernel/tracing/dynamic_events to create user_events, as persist is now back to being supported. Both the register and delete of events that persist require CAP_PERFMON, which prevents a non-perfmon user from making an event go away that a perfmon user decided should persist. Change History: V2: Added common user_event_capable() function to check access given the register flags. Ensure access check is done for dynamic_events when implicitly removing events, such as "echo 'u:test' > /sys/kernel/tracing/dynamic_events". Beau Belgrave (3): tracing/user_events: Allow events to persist for perfmon_capable users selftests/user_events: Test persist flag cases tracing/user_events: Document persist event flags Documentation/trace/user_events.rst | 21 ++++++- include/uapi/linux/user_events.h | 11 +++- kernel/trace/trace_events_user.c | 36 +++++++----- .../testing/selftests/user_events/abi_test.c | 55 ++++++++++++++++++- .../testing/selftests/user_events/dyn_test.c | 54 +++++++++++++++++- 5 files changed, 157 insertions(+), 20 deletions(-) base-commit: fc1653abba0d554aad80224e51bcad42b09895ed