Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1356727ybl; Wed, 18 Dec 2019 17:21:27 -0800 (PST) X-Google-Smtp-Source: APXvYqyWV72j1hONaQ5OrKf10axUMBVsBlxOasUfgVLPfiUvNipkwCE5ml4z4HAuxd0YlrR0uype X-Received: by 2002:a05:6830:1599:: with SMTP id i25mr5701436otr.205.1576718487281; Wed, 18 Dec 2019 17:21:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576718487; cv=none; d=google.com; s=arc-20160816; b=J2DMaYh0t6JFpSrkNjCDTrH/ARW1WjHC6lyF6Or8eZLpY0fV4wUuXotMGgL8OXrbkx nI/neUC73EOhV0rgWadjwz9aRQPtvNIWsJUwRNztivmFLN5HcFAo3aGHK+6v5OEGWHls sxmfjup1b8QIS13NaYP1ayW3cubL+Wd143lpua3pgRrLidSsR70zEHTWwc1Z03B+i5En kFEaiEqu+s9kt3tD3SJ85nxlbE4i/MLxo9ktnzY0xqEA9ZKFSc2FK8BqQYVG/1qianDs EAvXuTsh8lDU9t7yp8X+GmCP+Sl5cZQzoIUXt+gMlZXrn/9lgNaAlzEOTiaEYnZHE+Vf 3zOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:from:cc:references:to :subject; bh=6ME9aUotCGjCUDCe/45+NdLemRrGgLUrFjeuV5HrB90=; b=pA3sp2qmqW2GMPqoKLApWUCsk7rbdmuk3iC0Rmy3WC2oLnyK3I7ofO2QGsdidabs5B oRxk0xaArOgf0OBeoJovCSGBZp6UeDI8lX6baBEsp/l/N+O0JEWo0AJk658yDpnFLpR8 CO95BREYArr0p1mt1fYJsRp0mjUxa1fePmYhlmPca776PiRNcZKCUrCuGTE2LXynIoBg woPoMqeEgi1leErrCefDnQ40bMdiD1jKSTUY59Xb7LMLDrko2TAkcnOwix4UzNbRiX2c Lb0+z0BfUD1JlZ46e5GjZfJG3FtY6yabDCnKNB74rE928KZg29lWsOFaylXpn8w0woYS xj0w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e190si1945215oib.113.2019.12.18.17.21.11; Wed, 18 Dec 2019 17:21:27 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726726AbfLSBUZ (ORCPT + 99 others); Wed, 18 Dec 2019 20:20:25 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:8146 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726518AbfLSBUZ (ORCPT ); Wed, 18 Dec 2019 20:20:25 -0500 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 4843F5B79693D50AF8D0; Thu, 19 Dec 2019 09:20:23 +0800 (CST) Received: from [127.0.0.1] (10.177.131.64) by DGGEMS411-HUB.china.huawei.com (10.3.19.211) with Microsoft SMTP Server id 14.3.439.0; Thu, 19 Dec 2019 09:20:20 +0800 Subject: Re: [PATCH] powerpc/setup_64: use DEFINE_DEBUGFS_ATTRIBUTE to define fops_rfi_flush To: Michael Ellerman , , References: <20191218020842.186446-1-chenzhou10@huawei.com> <8736dhoq0j.fsf@mpe.ellerman.id.au> CC: , , "Nicolai Stange" , Julia Lawall From: Chen Zhou Message-ID: <69722925-d0ab-ab7e-022f-c901ead3989a@huawei.com> Date: Thu, 19 Dec 2019 09:20:19 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.7.1 MIME-Version: 1.0 In-Reply-To: <8736dhoq0j.fsf@mpe.ellerman.id.au> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.177.131.64] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Michael, On 2019/12/18 19:02, Michael Ellerman wrote: > Chen Zhou writes: >> Use DEFINE_DEBUGFS_ATTRIBUTE rather than DEFINE_SIMPLE_ATTRIBUTE for >> debugfs files. >> >> Semantic patch information: >> Rationale: DEFINE_SIMPLE_ATTRIBUTE + debugfs_create_file() >> imposes some significant overhead as compared to >> DEFINE_DEBUGFS_ATTRIBUTE + debugfs_create_file_unsafe(). > > I know you didn't write this text, but these change logs are not great. > It doesn't really explain why you're doing it. And it is alarming that > you're converting *to* a function with "unsafe" in the name. > > The commit that added the script: > > 5103068eaca2 ("debugfs, coccinelle: check for obsolete DEFINE_SIMPLE_ATTRIBUTE() usage") > > Has a bit more explanation. > > Maybe something like this: > > In order to protect against file removal races, debugfs files created via > debugfs_create_file() are wrapped by a struct file_operations at their > opening. > > If the original struct file_operations is known to be safe against removal > races already, the proxy creation may be bypassed by creating the files > using DEFINE_DEBUGFS_ATTRIBUTE() and debugfs_create_file_unsafe(). > > > The part that's not explained is why this file is "known to be safe > against removal races already"? > > It also seems this conversion will make the file no longer seekable, > because DEFINE_SIMPLE_ATTRIBUTE() uses generic_file_llseek() whereas > DEFINE_DEBUGFS_ATTRIBUTE() uses no_llseek. > > That is probably fine, but should be mentioned. Thanks for your explanation. This part indeed should be mentioned. Chen Zhou > > cheers > >> Signed-off-by: Chen Zhou >> --- >> arch/powerpc/kernel/setup_64.c | 4 ++-- >> 1 file changed, 2 insertions(+), 2 deletions(-) >> >> diff --git a/arch/powerpc/kernel/setup_64.c b/arch/powerpc/kernel/setup_64.c >> index 6104917..4b9fbb2 100644 >> --- a/arch/powerpc/kernel/setup_64.c >> +++ b/arch/powerpc/kernel/setup_64.c >> @@ -956,11 +956,11 @@ static int rfi_flush_get(void *data, u64 *val) >> return 0; >> } >> >> -DEFINE_SIMPLE_ATTRIBUTE(fops_rfi_flush, rfi_flush_get, rfi_flush_set, "%llu\n"); >> +DEFINE_DEBUGFS_ATTRIBUTE(fops_rfi_flush, rfi_flush_get, rfi_flush_set, "%llu\n"); >> >> static __init int rfi_flush_debugfs_init(void) >> { >> - debugfs_create_file("rfi_flush", 0600, powerpc_debugfs_root, NULL, &fops_rfi_flush); >> + debugfs_create_file_unsafe("rfi_flush", 0600, powerpc_debugfs_root, NULL, &fops_rfi_flush); >> return 0; >> } >> device_initcall(rfi_flush_debugfs_init); >> -- >> 2.7.4 > > . >