Received: by 2002:a05:7412:d008:b0:f9:6acb:47ec with SMTP id bd8csp410097rdb; Wed, 20 Dec 2023 00:07:38 -0800 (PST) X-Google-Smtp-Source: AGHT+IGaLVM+6fN+RO+jrJC/J/19chESl7f9VbZC0hp0ouspPSxlYb3D7dHGkyY5kEjm/t6ocsZk X-Received: by 2002:a05:6214:f27:b0:67f:f92:29fd with SMTP id iw7-20020a0562140f2700b0067f0f9229fdmr15104144qvb.115.1703059657840; Wed, 20 Dec 2023 00:07:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703059657; cv=none; d=google.com; s=arc-20160816; b=l9vA6ccKx6/IWHMBx0dCyGgNyNREKZMt8E05Ph5vYu6qjmv/eN+P7ztAReNzKMevCX e89XKbvoQHJHobU3/w4kUa1BdljJZ/oAcXa/t1qHibnY8soFh+LKipt6IWgN1aSlqt7X zj9+xuxbrSUuyoyBrJEMnWoqghxOrQwfA9uIPCdO7GCD/TlY3p8DAMs1FVM5rr1QeJ4x GpBI7DYj/++n7p6JR9mimWpgFbUZ51Hznlh8OxVTRjFTKWu3zjPFsJ/H59dbghDLqR3I sct+iJF0Lw2hHCC4i4Lxp2+W+p3quzsJGIXCuKecRhe1Hr8KeR+atIc65aJJTFcXYGo1 QwZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:references:cc:to:from:subject :user-agent:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:date:message-id; bh=9gKYSwo9PT2t4YrH89Eirb9RzYP3iFINc4Ow4svVGuM=; fh=prFepmbmgwPViVl4A6I5qQyMr8Zt6T4sB0/ogyTt6ok=; b=ldF9n4Eqk7xAcC/Z7ZwHnWeI+nU32jug7/+2KKKVyEfsbxBV7SP48vi2vItWtpOaPj JrWXos+pfzzWKAQ6xu3rRDG3oRdiPGiu7y0Z/JpLr9PNiF8LC22hCoiyc3MmDdk+KV5C 4D9TGIRZwxq36ImtoQ5vTL7fY09zQEXjYee2FNRLxiUrxX6vm6/aGyh60VSDpndTNKbl BiCaIr+OdmtUDhvZrt721ftYQhR3dUNM7jGhD9LJD9A3tMY7WIMrXzrghmweunXRovyH c4BeW5aI2DXMr8hHZlaPd7qjSSsZ/fxf4CCr6kox3mzvtQupn0hFe7HNM/AVd/LzidaS QuBw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-6536-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-6536-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id x19-20020a0cda13000000b0067f610371dcsi3073259qvj.137.2023.12.20.00.07.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Dec 2023 00:07:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-6536-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-6536-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-6536-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 63F1D1C24AFD for ; Wed, 20 Dec 2023 08:07:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5A1D71CABE; Wed, 20 Dec 2023 08:07:32 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from out30-101.freemail.mail.aliyun.com (out30-101.freemail.mail.aliyun.com [115.124.30.101]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E94AB1CA93 for ; Wed, 20 Dec 2023 08:07:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R451e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046059;MF=lulie@linux.alibaba.com;NM=1;PH=DS;RN=14;SR=0;TI=SMTPD_---0VyteJLE_1703059645; Received: from 30.221.128.103(mailfrom:lulie@linux.alibaba.com fp:SMTPD_---0VyteJLE_1703059645) by smtp.aliyun-inc.com; Wed, 20 Dec 2023 16:07:26 +0800 Message-ID: <3b2805c0-daa1-4d2f-a3b3-4376a51ab219@linux.alibaba.com> Date: Wed, 20 Dec 2023 16:07:24 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RFC PATCH] relay: avoid relay_open_buf inproperly fails in buffer-only mode From: Philo Lu To: linux-kernel@vger.kernel.org Cc: akpm@linux-foundation.org, surenb@google.com, rppt@kernel.org, zhou.kete@h3c.com, zhao_lei1@hoperun.com, kunyu@nfschina.com, zhang.zhengming@h3c.com, gregkh@linuxfoundation.org, xuanzhuo@linux.alibaba.com, dust.li@linux.alibaba.com, alibuda@linux.alibaba.com, guwen@linux.alibaba.com, hengqi@linux.alibaba.com References: <20231220074725.23211-1-lulie@linux.alibaba.com> In-Reply-To: <20231220074725.23211-1-lulie@linux.alibaba.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Sorry, the email address of Andrew was wrongly spelled, so CC again. On 2023/12/20 15:47, Philo Lu wrote: > In buffer-only mode, relay_open(NULL, NULL, ...) is used to create the > buffer first, where chan->has_base_filename is not set. Though we still > need to call chan->cb->create_buf_file in relay_open_buf() to retrieve > global info for global buffer, the create_buf_file callback should > return NULL. With IS_ERR_OR_NULL() check, relay_open fails because of > the returned NULL dentry, so this patch reverts back to the WARN_ON() > version and add a comment for this behavior. > > Here is an example after fix: > ``` > struct dentry *my_create_buf_file(const char *filename, > struct dentry *parent, umode_t mode, > struct rchan_buf *buf, int *is_global) > { > if (!filename) > return NULL; > > return debugfs_create_file(filename, mode, parent, buf, > &relay_file_operations); > } > > relay_cb.create_buf_file = my_create_buf_file > relay_chan = relay_open(NULL, NULL, > subbuf_size, subbuf_num, > &relay_cb, NULL); > relay_late_setup_files(relay_chan, filename, parent); > ``` > > But before fix, the create_buf_file callback must be something like: > ``` > struct dentry *my_create_buf_file(const char *filename, > struct dentry *parent, umode_t mode, > struct rchan_buf *buf, int *is_global) > { > if (!filename) > return ERR_PTR(1); // a valid ptr is necessary for relay_open > > return debugfs_create_file(filename, mode, parent, buf, > &relay_file_operations); > } > ``` > > I'm not sure if this revertion proper because it may break existing use > cases. I think we can also remove the WARN_ON check instead. > > Fixes: 2c1cf00eeacb ("relay: check return of create_buf_file() properly") > Signed-off-by: Philo Lu > --- > kernel/relay.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/kernel/relay.c b/kernel/relay.c > index 83fe0325cde1..0700745447c1 100644 > --- a/kernel/relay.c > +++ b/kernel/relay.c > @@ -395,7 +395,8 @@ static struct rchan_buf *relay_open_buf(struct rchan *chan, unsigned int cpu) > dentry = chan->cb->create_buf_file(NULL, NULL, > S_IRUSR, buf, > &chan->is_global); > - if (IS_ERR_OR_NULL(dentry)) > + /* has_base_filename not set, so dentry should be NULL */ > + if (WARN_ON(dentry)) > goto free_buf; > } > > -- > 2.32.0.3.g01195cf9f