From patchwork Fri Apr 14 08:22:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Hunter X-Patchwork-Id: 83285 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp218836vqo; Fri, 14 Apr 2023 01:25:41 -0700 (PDT) X-Google-Smtp-Source: AKy350bKtYXyzoIx7C9KsFnOqOQUqTVYXJ8zxinoFnpnFjXpxCLXxVGhirzfJo0/9UNIFxUn/ZY5 X-Received: by 2002:a17:902:db10:b0:1a6:494c:f723 with SMTP id m16-20020a170902db1000b001a6494cf723mr2140634plx.54.1681460741307; Fri, 14 Apr 2023 01:25:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681460741; cv=none; d=google.com; s=arc-20160816; b=WJinp7V1NOFkzgX5IywwmjGS4ydj15WgwlH0EpPMm2pd+SCRBPWmprUBG+yaxg9BqL zjP2xA6ymZrHKaCr2yLSY1j/Gyy8c96tRVMLKYXZyYgMZoGmqaXizDOucrXnO+E9t+rq QLNRp5hNa9wmtqJ03coM1/C02dqdm5sZNoK0P6PSI1LtKnj4er9SdvKQrnmziRBrSeWG lwm/lnQWXCPuHpHk87c1WjRQOyFfrexOLTFG6y2BVre1vRkcTRx84koQIY/joWb9ZWJw KQ9qMoEVrUFYOuMP8hr1fG1Atlt4HDT+yWFNcPfgygSt0bHKm5ONt5HZu3w+6pALwheD qzAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:organization :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=iD7v+IQFV0HmhxCjWzW6/hN2SiJquhiNnXd4fWTOzRY=; b=gKrcm/wH9O6ZxdCHSkE4TdsDX4myerbuU3if9e5dXwaSuWpBXzmGsf2Tvce97sTKzb Fxw62cvYzU+MsgPZqtFkmZdg/7haBHGGPUTrqZeAZAWn5sfABWTlfuKWGXCkSEzvgcU/ h2j0yvyJArARi/CZtj2Gy1K6hl2eEnu56h+7GpbMxtHva7wp6cvcENN+YvqHGJt9BNtR G8VwVL2ZObBpYnEwqUkcpRKTEonFKrOUb9+7vs9QB0f0aBLnx7G7B3R18coxCMX6mA4Q /sa8BmxVDe26sNl2PpqdNJ6bfynw7uYeq9cTgdKbd/srTEPuNFFKz7wlIDk+faDOm1r5 Puyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=dglHk3ST; 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=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b11-20020a170903228b00b001a1e4051da5si4470397plh.498.2023.04.14.01.25.28; Fri, 14 Apr 2023 01:25:41 -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=@intel.com header.s=Intel header.b=dglHk3ST; 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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229749AbjDNIYA (ORCPT + 99 others); Fri, 14 Apr 2023 04:24:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33922 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230220AbjDNIXt (ORCPT ); Fri, 14 Apr 2023 04:23:49 -0400 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AFECF7EF5; Fri, 14 Apr 2023 01:23:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1681460614; x=1712996614; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=3nHcjAW5hAXD3jrHcmKICBKZPcBY+tB2vS9Jj26IxgQ=; b=dglHk3STL+XoTEAcBm1p7GlojlLHnTIFjlP3TzcNoD4YIrk5PVTglCaZ SwruLGdz3Hu7q6wALVUpVLYliszc61pmLDesKZI7Pm1wQ+ekgNYYANhhn ySRb9EbGuXDjW1OMjH1Ehw8IfOc9vINvTkfs72oyoDiY269wpvFR0JPFX JCquoLQOybIx4JVDHz6YquGmWZhKnJiX2z7np+a3fpTs53UY2ZkZyXjir fhYkfwE6L0C4179o5b249s8pKg19hGBJmN/jCUGYsGxoxUlSgqUomXSgL nOR3O0QuFWfpeMAfV5dF5hcqk/kp1j7ZCVYjRM36YPbkI+DSxtdsvEMKf Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10679"; a="430708139" X-IronPort-AV: E=Sophos;i="5.99,195,1677571200"; d="scan'208";a="430708139" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Apr 2023 01:23:34 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10679"; a="683267542" X-IronPort-AV: E=Sophos;i="5.99,195,1677571200"; d="scan'208";a="683267542" Received: from ahunter6-mobl1.ger.corp.intel.com (HELO ahunter-VirtualBox.home\044ger.corp.intel.com) ([10.249.34.252]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Apr 2023 01:23:31 -0700 From: Adrian Hunter To: Peter Zijlstra Cc: Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH RFC 4/5] perf: Add comm to the sideband ioctl Date: Fri, 14 Apr 2023 11:22:59 +0300 Message-Id: <20230414082300.34798-5-adrian.hunter@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230414082300.34798-1-adrian.hunter@intel.com> References: <20230414082300.34798-1-adrian.hunter@intel.com> MIME-Version: 1.0 Organization: Intel Finland Oy, Registered Address: PL 281, 00181 Helsinki, Business Identity Code: 0357606 - 4, Domiciled in Helsinki X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE 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?1763139378129614148?= X-GMAIL-MSGID: =?utf-8?q?1763139378129614148?= Support the case of output to an active event, and return an error if output is not possible in that case. Set PERF_RECORD_MISC_STATUS_ONLY to differentiate the ioctl status-only sideband event from a "real" sideband event. Signed-off-by: Adrian Hunter --- kernel/events/core.c | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/kernel/events/core.c b/kernel/events/core.c index ed4af231853a..cddc02c2e411 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -8265,8 +8265,7 @@ static int perf_event_comm_match(struct perf_event *event) return event->attr.comm; } -static void perf_event_comm_output(struct perf_event *event, - void *data) +static int perf_event_comm_output(struct perf_event *event, void *data) { struct perf_comm_event *comm_event = data; struct perf_output_handle handle; @@ -8275,7 +8274,7 @@ static void perf_event_comm_output(struct perf_event *event, int ret; if (!perf_event_comm_match(event)) - return; + return -ENOENT; perf_event_header__init_id(&comm_event->event_id.header, &sample, event); ret = perf_output_begin(&handle, &sample, event, @@ -8296,9 +8295,10 @@ static void perf_event_comm_output(struct perf_event *event, perf_output_end(&handle); out: comm_event->event_id.header.size = size; + return ret; } -static void perf_event_comm_event(struct perf_comm_event *comm_event) +static int perf_event_comm_event(struct perf_comm_event *comm_event, struct perf_event *event) { char comm[TASK_COMM_LEN]; unsigned int size; @@ -8312,17 +8312,15 @@ static void perf_event_comm_event(struct perf_comm_event *comm_event) comm_event->event_id.header.size = sizeof(comm_event->event_id) + size; - perf_iterate_sb(perf_event_comm_output, - comm_event, - NULL); + return perf_output_sb(perf_event_comm_output, comm_event, NULL, event); } -void perf_event_comm(struct task_struct *task, bool exec) +static int __perf_event_comm(struct task_struct *task, bool exec, struct perf_event *event) { struct perf_comm_event comm_event; if (!atomic_read(&nr_comm_events)) - return; + return -ENOENT; comm_event = (struct perf_comm_event){ .task = task, @@ -8331,7 +8329,8 @@ void perf_event_comm(struct task_struct *task, bool exec) .event_id = { .header = { .type = PERF_RECORD_COMM, - .misc = exec ? PERF_RECORD_MISC_COMM_EXEC : 0, + .misc = (exec ? PERF_RECORD_MISC_COMM_EXEC : 0) | + (event ? PERF_RECORD_MISC_STATUS_ONLY : 0), /* .size */ }, /* .pid */ @@ -8339,7 +8338,12 @@ void perf_event_comm(struct task_struct *task, bool exec) }, }; - perf_event_comm_event(&comm_event); + return perf_event_comm_event(&comm_event, event); +} + +void perf_event_comm(struct task_struct *task, bool exec) +{ + __perf_event_comm(task, exec, NULL); } /* @@ -12891,7 +12895,10 @@ static int perf_event_emit_namespaces(struct perf_event *event, struct task_stru static int perf_event_emit_comm(struct perf_event *event, struct task_struct *task) { - return -EINVAL; + if (!event->attr.comm) + return -EINVAL; + + return __perf_event_comm(task, false, event); } static int perf_event_emit_mmap(struct perf_event *event, struct task_struct *task)