Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp1652507rdb; Tue, 20 Feb 2024 02:58:55 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVmcK8TFS9B1rXQ0pSqZwwo/QDUZsiBJ0l0lnp1F8LudrEzfg7ep6reX/vAVjk+mwnzO7HHpqniGYi/6yjc+QRoFpuy/8oGgUpAEw3i/w== X-Google-Smtp-Source: AGHT+IFd1McO9/ekpQ/+I/UZttDsBni6atdFjrXbhblls52uZd3ZpMokTw5MwOuDUacHHKfKSjRx X-Received: by 2002:a17:90a:f692:b0:299:84cb:c70b with SMTP id cl18-20020a17090af69200b0029984cbc70bmr4184095pjb.39.1708426734952; Tue, 20 Feb 2024 02:58:54 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708426734; cv=pass; d=google.com; s=arc-20160816; b=dyNxGE0Rl27iWWqhpOSdE97ST8Wo66YBYDw8wCtds7WsG/AscT4Siuz81eyQprBR7q MG8otIg5jx+dwfxEvlTYsZyJw6OfaZPP+4GCHIB37p8YoW8SRL9tbO5LSsA6xTKYn11F SEbNDOIrGWpSFMLh9+qfz5l37SW/haPYgxPKI3pAzvvcHI9/h/sxPe1TPh6kaXBZYoyO 8RU0cZfOn/MfGFp0Ib7vx0ty0UmN5lLIhs8vmiFJYrBAOk5mE2ylWRkbRIZgYGEzLV9p u73bL9N/+Qjvb6hVPklANinmP0/dcT3kuAjZKiNX1ijxzEgEz+7zzqYCvN3NjZxyXvj1 4fhQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=x1dXJmu9Nanj3JJhkblhi78dtxr9mOoMw+nXdkteozQ=; fh=AJNg6sMLCDnVrKqkOEmATgQKREQDXwGmToLj4RkOrR8=; b=NF2oIW2wR8e0g5aOrETbYU2ZaBFC6gV/M6eZNwB6FhWDpmOU3wXPqgAkfVBpYQ+uX3 dw1b6RfcUdFnAaJz8ZAlmZI1sgSIyd8UEly+C0W0J2MWwDb62W4uDZTHNyAhuwRzZTQ2 Vj8MYEoDZ+XkyFuHkBjqM0nzFa0twZ9DFAAf0H2x3F4mmd/PYnC3ZwXyw2TMf+QSi5Ep 0g92bwb5Gi5DtiQIQNsjR1nSeiA4zr61zq/k4DMqpCQu/bfnOeA0F1RPUSFFNwMTqbx0 JTnJ5/aHPprvTS+QJKtnYC4AONsI+QYcZevcvuDIcl27FPpyjTFsyOGuPitvvpKZNPiC HVoA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.alibaba.com header.s=default header.b=oP8bJC1Z; arc=pass (i=1 spf=pass spfdomain=linux.alibaba.com dkim=pass dkdomain=linux.alibaba.com dmarc=pass fromdomain=linux.alibaba.com); spf=pass (google.com: domain of linux-kernel+bounces-72865-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-72865-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.alibaba.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id y22-20020a17090aca9600b0029898ed5732si6148988pjt.86.2024.02.20.02.58.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 02:58:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-72865-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.alibaba.com header.s=default header.b=oP8bJC1Z; arc=pass (i=1 spf=pass spfdomain=linux.alibaba.com dkim=pass dkdomain=linux.alibaba.com dmarc=pass fromdomain=linux.alibaba.com); spf=pass (google.com: domain of linux-kernel+bounces-72865-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-72865-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 9DE8F286D60 for ; Tue, 20 Feb 2024 10:58:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9C8D365BA3; Tue, 20 Feb 2024 10:58:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="oP8bJC1Z" Received: from out30-110.freemail.mail.aliyun.com (out30-110.freemail.mail.aliyun.com [115.124.30.110]) (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 8D0956519D for ; Tue, 20 Feb 2024 10:58:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.110 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708426729; cv=none; b=TXzm7Il80FCW+qkyxee0gRJIdKQqADnaO7nIwao4r0qGIyZJwhZ5DQHXE5ULqOdaKqCEilFzze10Cut0GCcAeqHa82RID5Pq0rKI+P5VSLUY90l50arSy0oI/A8F3pUxSTMl0yJtnlTOKCGg8ovLDGkp/xgQEwA7usc2pXdIiXQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708426729; c=relaxed/simple; bh=JWW1JxkqWuHVa6b8AqZqenUuq61dUCp0Rh4lrmiIiQs=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=gfGHK9WwWMjJzu2yYTMFMAGu/qEzYbi81mropY94eQ1fT2xJy9BiFHpnJN7Gi8TBAAD0eirzshr0ldMeBqog3ELB5JpWhWv61j6rw9rcWBUdfah1l8h3a/IyY84ptKMPa+ZqODzx7c0UTZ0t6mlxe4KvU8GD1emwfOPsmF1Kmco= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=oP8bJC1Z; arc=none smtp.client-ip=115.124.30.110 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 DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1708426717; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=x1dXJmu9Nanj3JJhkblhi78dtxr9mOoMw+nXdkteozQ=; b=oP8bJC1Z+pZE0mI1Pa/YGrbivtV8t18JYDMvxpwjGbyPpD32G/ZSZXg2R3P6BE87pTtJHkccsnPtWeFMbkQQz3DryBzP/KpAMJheqkdGmrFeJ7PPPjIT60TLswCSWaY4SIhxs1xyXC2br36nVM8xG0E1xX7sQ15Hy9beoDfOu8A= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R141e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046050;MF=lulie@linux.alibaba.com;NM=1;PH=DS;RN=13;SR=0;TI=SMTPD_---0W0wa1gb_1708426716; Received: from localhost(mailfrom:lulie@linux.alibaba.com fp:SMTPD_---0W0wa1gb_1708426716) by smtp.aliyun-inc.com; Tue, 20 Feb 2024 18:58:37 +0800 From: Philo Lu To: linux-kernel@vger.kernel.org Cc: akpm@linux-foundation.org, zhou.kete@h3c.com, zhao_lei1@hoperun.com, nabijaczleweli@nabijaczleweli.xyz, 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 Subject: [PATCH] relay: avoid relay_open_buf inproperly fails in buffer-only mode Date: Tue, 20 Feb 2024 18:58:36 +0800 Message-Id: <20240220105836.15815-1-lulie@linux.alibaba.com> X-Mailer: git-send-email 2.32.0.3.g01195cf9f Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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. However, with IS_ERR_OR_NULL() checking, relay_open fails because the returned dentry == NULL. This patch remove the IS_ERR_OR_NULL() for compatibility and update the comment to explain the behavior. Here is a create_buf_file callback 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 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); } ``` Fixes: 2c1cf00eeacb ("relay: check return of create_buf_file() properly") Signed-off-by: Philo Lu --- kernel/relay.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/kernel/relay.c b/kernel/relay.c index a8e90e98bf2c..0d8b8325530a 100644 --- a/kernel/relay.c +++ b/kernel/relay.c @@ -391,12 +391,13 @@ static struct rchan_buf *relay_open_buf(struct rchan *chan, unsigned int cpu) goto free_buf; relay_set_buf_dentry(buf, dentry); } else { - /* Only retrieve global info, nothing more, nothing less */ + /* In buffer-only mode, relay_open_buf is called with + * filename=NULL, but create_buf_file is still needed to + * retrieve is_global info. So dentry should be NULL here. + */ dentry = chan->cb->create_buf_file(NULL, NULL, S_IRUSR, buf, &chan->is_global); - if (IS_ERR_OR_NULL(dentry)) - goto free_buf; } buf->cpu = cpu; -- 2.32.0.3.g01195cf9f