From patchwork Wed Jun 14 16:33:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Beau Belgrave X-Patchwork-Id: 10776 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp80035vqr; Wed, 14 Jun 2023 09:37:41 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ40JYOXjHUJsRn3vRAPB7/VC62wlGxEh11cRufrULi1A2b4y5KtF17Il47Gu5Rm8IBdIZkr X-Received: by 2002:a17:907:26ca:b0:974:1e0e:9bd4 with SMTP id bp10-20020a17090726ca00b009741e0e9bd4mr16398047ejc.16.1686760660776; Wed, 14 Jun 2023 09:37:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686760660; cv=none; d=google.com; s=arc-20160816; b=V6Fe8qy5s+iXSGKSaANutYVtKW5mkKnqp3HYBl8GLfIpL3yiVlOzF3hKRIpW6N4nv7 nHljBwSE/R6ueLGh29lc5yC6NJtE9ZbNlD2RbfKeXNexhGpjdwfVqIfUDUkbCYF3OgTD NuSzohL6YJ8LEloxMiFIkVeAazI+HKE6pgPLnlt/4AIhqn4qEkAAbXXsapwymMrvpnSz 89fUmqXFc1wZDeKAi79+JZS9nbP8cEn6zUj7NY6XPJ3M7/0xBp2h0ndZRG9LAC6ehN0Q 4RchSRwQDTtkHn79DzEgG7ghEAgkLVbjr2laks0s1aaAwprM1KsFWEDn9XzF/fdu2Ztw duQQ== 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=SiFmm2ES1OHrXqYC7FgeWMYoLEAUTGZzcnUadkZnZkg=; b=fv9/rL9bdIb61HjHI7bLOTmjN5JK4SL1RLNPm54dlBh1PyKvSfjDhU9gcXUwclHXma 1ryah5/7d8dHQoVND/H1+DQGhDz0oMPQs7J9tlhrA9ddWCaLBT+esgSQBCd3IQqzS7C0 YN1CtfOnPU8ALXU0EAXe3BxgFQdPSJQGPg3InaueX2T/2SaBpLwHmVAkGXqJI1Iy4rPy 9lbMX1tNqL0nlc/+WdLU97CVLISgPZIJIwqO1YgdKOhmCerQ/sotB9P+WCuJpN7Ev0dJ 0ffP28VJKerqGw40OgNIPuPbao6XxwaiUoK9EGkWk6EnRJ0NZ8CxMSuLidz81Kq4X79x j1vw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b="rUHHiW/A"; 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=NONE dis=NONE) header.from=linux.microsoft.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q17-20020a170906389100b00977e0bdac8asi7635220ejd.583.2023.06.14.09.37.09; Wed, 14 Jun 2023 09:37:40 -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=@linux.microsoft.com header.s=default header.b="rUHHiW/A"; 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=NONE dis=NONE) header.from=linux.microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234259AbjFNQdn (ORCPT + 99 others); Wed, 14 Jun 2023 12:33:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46816 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233227AbjFNQdl (ORCPT ); Wed, 14 Jun 2023 12:33:41 -0400 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D05361A3; Wed, 14 Jun 2023 09:33:40 -0700 (PDT) Received: from W11-BEAU-MD.localdomain (unknown [76.135.27.212]) by linux.microsoft.com (Postfix) with ESMTPSA id 26B3120FEA3D; Wed, 14 Jun 2023 09:33:40 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 26B3120FEA3D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1686760420; bh=SiFmm2ES1OHrXqYC7FgeWMYoLEAUTGZzcnUadkZnZkg=; h=From:To:Cc:Subject:Date:From; b=rUHHiW/AhatcwMBOg3++AmFnhNrvMvpmvFdFjpi6E359IY8R/yKumI000dXEWiut2 qdq19o59tM7PyVCCdv4bkEUb4J/dKzd3N1Di8IFV0UEx6UCkL+2tSDk3bJFO5PWVbH +R8iG7o1GIWhpngLTMUi/RwPZei2X4RQ6lSCvAiA= 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 v3 0/6] tracing/user_events: Add auto cleanup and a flag to persist events Date: Wed, 14 Jun 2023 09:33:30 -0700 Message-Id: <20230614163336.5797-1-beaub@linux.microsoft.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Spam-Status: No, score=-19.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE,URG_BIZ, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham 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?1768696746477274550?= X-GMAIL-MSGID: =?utf-8?q?1768696746477274550?= As part of the discussions for user_events aligning to be used with eBPF it became clear [1] we needed a way to delete events without having to rely upon the delete IOCTL. Steven suggested that we simply have an owner for the event, however, the event can be held by more than just the first register FD, such as perf/ftrace or additional registers. In order to handle all those cases, we must only delete after all references are gone from both user and kernel space. This series adds a internal register flag, USER_EVENT_REG_PERSIST, which causes the event to not delete itself upon the last put reference. We cannot fully drop the delete IOCTL, since we still want to enable events to be registered early via dynamic_events and persist. Events that do not use this new flag are auto-cleaned up upon no longer being used. This new flag is not exposed to user processes yet while we work out the details, however, the code is updated to accomodate it once it is ready. 1: https://lore.kernel.org/linux-trace-kernel/20230518093600.3f119d68@rorschach.local.home/ Change history v3: Rebased to trace/urgent as requested by Steven Removed user-facing references to USER_EVENT_REG_PERSIST while we work out the details Added check for any flags, even from dynamic_events, will return -EINVAL Added clarifying comment about event_mutex protection of refcounts Updated selftests to work given the absence of persist events Updated documentation to not include /sys/kernel/tracing/dynamic_events since they cannot be used until persist flags exist and a note about auto-deletions v2: Renamed series to "Add auto cleanup and a flag to persist events" Changed auto-delete to be default behavior, with new flag to persist events Beau Belgrave (6): tracing/user_events: Store register flags on events tracing/user_events: Track refcount consistently via put/get tracing/user_events: Add auto cleanup and future persist flag selftests/user_events: Ensure auto cleanup works as expected selftests/user_events: Adapt dyn_test to non-persist events tracing/user_events: Document auto-cleanup and remove dyn_event refs Documentation/trace/user_events.rst | 7 +- kernel/trace/trace_events_user.c | 208 ++++++++++++++---- .../testing/selftests/user_events/dyn_test.c | 177 +++++++++++---- .../selftests/user_events/ftrace_test.c | 49 ++++- 4 files changed, 346 insertions(+), 95 deletions(-) base-commit: a8c5c6a5c87ea10189ec43483f44800a4ec97785