Received: by 2002:a05:6358:111d:b0:dc:6189:e246 with SMTP id f29csp1451868rwi; Mon, 31 Oct 2022 17:08:36 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4YZ1HIsD29ii5WAYgIokHrrb9t5cACh8e2vR2vG/cjngZTJnf1pmBZU4/cR0pRDxooAALi X-Received: by 2002:aa7:c504:0:b0:461:122b:882b with SMTP id o4-20020aa7c504000000b00461122b882bmr16647922edq.14.1667261157479; Mon, 31 Oct 2022 17:05:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667261157; cv=none; d=google.com; s=arc-20160816; b=CI3/mixhWKoSTBj02M/uobG6vOj7vCuHuF6q/SpjcwlxGx61uPkjgONRDYB9fCC/wB AbHNvbfoXBnKzM2sXTJ874/1JLlbcfjxpUvsqE5yefXirUPVizj0jqBM3E6ucBy39SX1 Rt5YwtuMOGGCOO7stHYxaBQxoRkiKTDGmMpF07kLoqGuj17Pb8kYBhkvnl/8OHG6BZaP Ajd2QvaKt6j+60bYcuoMHAy3P09TJbTOn7hgSFOrbc0QwEW+Iy/AswEFdyYGdwlR+iXu NVrNgXoifyeLLkEJqEw+L3arlmmbLdpGbP65VJuICpx+fw75jwDP0+gTtbnnilIqjHS1 y0Uw== 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 :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=73OopBftU7sGLj01dvcfReU/cRxKImjfXTlnoGpIa24=; b=FCLX1QPi2dstOWcabSegNQ87TVj48g7KQnnphH+fAMzJWfb+WCfSZ0ZGrK4f7CfkKf aHxDrEbdsl+WIeMRHSLUU2dKQdY81kqVCZ5e5AsGxrjmspsKahdvyqPDrw6mmZR5Qd1M mLjqsLWReYMDzTl740NZ/tgVZwFmphyv0ka8EIJG7pkclJk7GIL2MqmKEv82o0QzExmd 0K13cJS2GzQTYLE4Ox6LmURL553/Gu8EGrbm/39ECb8C/E01EJoe79BeNcC+Zi3kmVPO qai+2eRwBufrz6rRb0u/V4UsEcjIiD1eWtE4x3hBPdxa42MmKnj9ZeT6zl0GlHZsJGFq kL+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=LLJYee2Z; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t2-20020a50ab42000000b00462af00c12bsi8946457edc.398.2022.10.31.17.05.21; Mon, 31 Oct 2022 17:05:57 -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=@kernel.org header.s=k20201202 header.b=LLJYee2Z; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229905AbiJaXzJ (ORCPT + 97 others); Mon, 31 Oct 2022 19:55:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42414 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229874AbiJaXzG (ORCPT ); Mon, 31 Oct 2022 19:55:06 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 08DB6120A7; Mon, 31 Oct 2022 16:55:06 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 9BDAF614F6; Mon, 31 Oct 2022 23:55:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B6A73C433B5; Mon, 31 Oct 2022 23:55:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1667260505; bh=HPgNN1zmJTmeIiVEP7njqfVDkUvRcG88oE73X4TTkmM=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=LLJYee2ZUICFXcFrnth5y9tCuofh2vLIAwu5qlWwlVVgA61FkGkgTF1a2CkQx26Av 7ruZwlD6BAN+OYYPiR64vdge4yUyf/DkeDgRiGorzdunZe73zlyzn7kgzIbBGzgrWz o/pSdqbUL8HsAQcTZUi2EkFuT91VRCLtfvBVD49CukRisxuzsXt89jbK1JNnKlLuji pwAcd8maGhudhFYdjs+SRAlGKjH+NlDkZT0YDtkWdIKWHYJyuAbPX1WrLnO8ayJJAK QqDavwg12dUV/YhSTl8zMDW2+vjvikuWvThBJLtK698tmAOcK3S+smycCcp08TE4tv VPuvP+GX23wVQ== Date: Tue, 1 Nov 2022 08:55:01 +0900 From: Masami Hiramatsu (Google) To: Beau Belgrave Cc: rostedt@goodmis.org, mathieu.desnoyers@efficios.com, dcook@linux.microsoft.com, alanau@linux.microsoft.com, linux-trace-devel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [RFC PATCH 1/2] tracing/user_events: Use remote writes for event enablement Message-Id: <20221101085501.443f2ac77bfb0803b91517c2@kernel.org> In-Reply-To: <20221031164603.GB69@W11-BEAU-MD.localdomain> References: <20221027224011.2075-1-beaub@linux.microsoft.com> <20221027224011.2075-2-beaub@linux.microsoft.com> <20221031234703.e275650899728e64cd3fb6c3@kernel.org> <20221031164603.GB69@W11-BEAU-MD.localdomain> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-8.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS 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 On Mon, 31 Oct 2022 09:46:03 -0700 Beau Belgrave wrote: > On Mon, Oct 31, 2022 at 11:47:03PM +0900, Masami Hiramatsu wrote: > > Hi, > > > > I have some comments. > > > > On Thu, 27 Oct 2022 15:40:10 -0700 > > Beau Belgrave wrote: > > > > [...] > > > @@ -1570,11 +1610,12 @@ static long user_reg_get(struct user_reg __user *ureg, struct user_reg *kreg) > > > * Registers a user_event on behalf of a user process. > > > */ > > > static long user_events_ioctl_reg(struct user_event_file_info *info, > > > - unsigned long uarg) > > > + struct file *file, unsigned long uarg) > > > { > > > struct user_reg __user *ureg = (struct user_reg __user *)uarg; > > > struct user_reg reg; > > > struct user_event *user; > > > + struct user_event_enabler *enabler; > > > char *name; > > > long ret; > > > > > > @@ -1607,8 +1648,12 @@ static long user_events_ioctl_reg(struct user_event_file_info *info, > > > if (ret < 0) > > > return ret; > > > > > > + enabler = user_event_enabler_create(file, ®, user); > > > + > > > + if (!enabler) > > > > Shouldn't we free the user_event if needed here? > > (I found the similar memory leak pattern in the above failure case > > of the user_events_ref_add().) > > > > user_events are shared across the entire group. They cannot be cleaned > up until all references are gone. This is true both in this case and the > in the user_events_ref_add() case. > > The pattern is to register events in the group's hashtable, then add > them to the local file ref array that is RCU protected. If the file ref > cannot be allocated, etc. the refcount on user is decremented. If we > cannot create an enabler, the refcount is still held until file release. OK, when the ioctl returns, there should be 3 cases; - Return success, a new(existing) user_event added. - Return error, no new user_event added. - Return error, a new user_event added but enabler is not initialized. And in the last case, the new user_event will be released when user closes the file. Could you comment it here? > > If the event has already been added to the local file ref array, it is > returned to prevent another reference. I'm not sure this point. Did you mean returning an error to prevent registering the same event again? > > > > + return -ENOMEM; > > > + > > > put_user((u32)ret, &ureg->write_index); > > > - put_user(user->index, &ureg->status_bit); > > > > > > return 0; > > > } > > [...] > > > @@ -1849,7 +1863,6 @@ static int user_status_open(struct inode *node, struct file *file) > > > > > > static const struct file_operations user_status_fops = { > > > .open = user_status_open, > > > - .mmap = user_status_mmap, > > > > So, if this drops the mmap operation, can we drop the writable flag from > > the status tracefs file? > > > > Good catch, yes I'll remove this. Thanks! > > > static int create_user_tracefs(void) > > { > > [...] > > /* mmap with MAP_SHARED requires writable fd */ > > emmap = tracefs_create_file("user_events_status", TRACE_MODE_WRITE, > > NULL, NULL, &user_status_fops); > > > > Thank you, > > > > -- > > Masami Hiramatsu (Google) > > Thanks, > -Beau -- Masami Hiramatsu (Google)