Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp2431483pxb; Thu, 3 Feb 2022 06:35:28 -0800 (PST) X-Google-Smtp-Source: ABdhPJywFqbYi47LOiHHQDc3pE9qSrbtucW2ubpx0B5VDxHp3r/d/xyrIf3OWGixdjNyi/HfFbSs X-Received: by 2002:a17:907:7da2:: with SMTP id oz34mr22117863ejc.400.1643898927819; Thu, 03 Feb 2022 06:35:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643898927; cv=none; d=google.com; s=arc-20160816; b=Z8ws/QbfniJyv6qxhUr0gaT+UhzMA3A00FV8Z34m5m54XtUsTviqzV8wUHfOGLkBwP hClwh8bOG7/m/2W5Pa0fd99fGkIvmIS8TAoFCDqm7P9E/U92G3mL/YVjhc10oUlLR8ZZ Fov79Bu19172cSdBWKkpELtk3uKYz0EEXILGpqTXNAosORiinwUR4EXtYqO6jyh9a0IH KtSZxlRhR6YDvMk40U/PAYDJQm6HsYkZs/B5oF1g7wRDrthLWkiGVyr5qSDlaEqCPMI5 yYigwV9gaxT+XomjL5Vns8cAFFhzgm3cpQUgPbUdKmKN+hAwVwqltXeBaTnmLUOqw/OI wK1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=3CIuft7MFInnh1xqsvdSm7aJQ1m6iJ5S3C53p3CCUHc=; b=FuWcBIewd52DmTpVIFpzgbiKm6jVmLK+9ql/UaJdjxPwfmRRAqiJAq0a9ZEH3xcuVu yn11vPxGscTyCnEQSBImfgsjSI/m1QE5uXm7D6mMe+CtRoqBVJo0mG5OsyarikOacaAN 7f681EDGFRSB9Lw90KYsbo17u90K6xaa9hgwCllRi0YNRiCabKZHIzIIXioJY+BgUBmU g7dFyxgF00ZhOMwrgoT3iX97wAtp5lp6cePRyyLnemx2rKhUk0V35F8ed18RUI3wcfh+ MkdkrDmBK8NBCa6ix++rxECqZ0CKScxTodS+4oCC+OxV4krFuk/DhyscazYQfe9XcoBM DCRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=T+H7wnmd; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sg17si14494530ejc.990.2022.02.03.06.35.01; Thu, 03 Feb 2022 06:35:27 -0800 (PST) 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=@gmail.com header.s=20210112 header.b=T+H7wnmd; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238990AbiBBT5a (ORCPT + 99 others); Wed, 2 Feb 2022 14:57:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229481AbiBBT53 (ORCPT ); Wed, 2 Feb 2022 14:57:29 -0500 Received: from mail-lj1-x22b.google.com (mail-lj1-x22b.google.com [IPv6:2a00:1450:4864:20::22b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 11717C061714 for ; Wed, 2 Feb 2022 11:57:29 -0800 (PST) Received: by mail-lj1-x22b.google.com with SMTP id q22so665068ljh.7 for ; Wed, 02 Feb 2022 11:57:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=3CIuft7MFInnh1xqsvdSm7aJQ1m6iJ5S3C53p3CCUHc=; b=T+H7wnmd7kfHJC8X6vmZGalF+103bfBAMVkRiADef73+EKFKl9I+0ZlOTqDGdHCbH8 Q1oEbfCllEYRsp1prWpBrTlb+wDNxqeKUCEiyHGRfzjNO5kIqgYkyrw4wwd8RflWRmTf Dkk3ZXyyLRzNW7qPpijDbsy8MZ3iQPAwtclg2Ct3ARAa0hPaa+nPn4DYtTVDW5uKy4P9 UJ0Px0+NhrQOFwDsqscBS8Tx2i0jbB/YL7rF42aizdgvyxaUYlDt/jxwHDk7l3Sl+pwb zUwh9fKqC3w8wLR2xhFRNELmJ5MgyIReJLSwXta04u6CnM18+RljvoLA+vzD1Bn4h5AJ dN0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=3CIuft7MFInnh1xqsvdSm7aJQ1m6iJ5S3C53p3CCUHc=; b=tA1L8IoA1gEJffyiN+0uAQMwppUmwyRuIJRWzE8Fa26RJq7wrB5TNDOP9wfNhdxmAS 6CoqqZu6mqqSYAamANU+1e4vuy5iRBW2LeH/x0Cek0D7MXjmm3f8ExaOxHaCg641TBAA ErBDlVblkPw070Rld/XhzBU0rnbZNySQLhAjOgVGoTq5tOFJJDjMH1W9NpnHaIivkq6R nhpdrpQzssMamC81iiL/jOVLGJFU4t0VX1ERyPCw8hueJgy3x3HN77wUklVLc94Om/4x 1YHbDZRbLqbEoOrIq1U4L+IRcnnZP9rDWb0+LjyxbHrJ6Zqy+LDz4sUPyahMbyzraRTk EpaA== X-Gm-Message-State: AOAM531JldYLnWvQiX/GQ1uWXHhwNWhxj2SDdeohdSFjA0Z/y2j8iaGJ 2jkqc3SSY+1F9XdHCAHD3Ch0lP4C/WI= X-Received: by 2002:a2e:97cf:: with SMTP id m15mr20067068ljj.316.1643831847205; Wed, 02 Feb 2022 11:57:27 -0800 (PST) Received: from grain.localdomain ([5.18.251.97]) by smtp.gmail.com with ESMTPSA id a2sm3967086lfl.246.2022.02.02.11.57.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Feb 2022 11:57:26 -0800 (PST) Received: by grain.localdomain (Postfix, from userid 1000) id 567C95A0020; Wed, 2 Feb 2022 22:57:25 +0300 (MSK) Date: Wed, 2 Feb 2022 22:57:25 +0300 From: Cyrill Gorcunov To: Jason Andryuk Cc: open list , "Eric W . Biederman" Subject: Re: [PATCH] kcmp: Comment get_file_raw_ptr() RCU usage Message-ID: References: <20220202151734.10418-1-jandryuk@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/2.0.7 (2021-05-04) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Feb 02, 2022 at 02:48:48PM -0500, Jason Andryuk wrote: > On Wed, Feb 2, 2022 at 12:44 PM Cyrill Gorcunov wrote: > > > > On Wed, Feb 02, 2022 at 10:17:34AM -0500, Jason Andryuk wrote: > > > This usage of RCU appears wrong since the pointer is passed outside the > > > RCU region. However, it is not dereferenced, so it is "okay". Leave a > > > comment for the next reader. > > > > > > Without a reference, these comparisons are racy, but even with their use > > > inside an RCU region, the result could go stale. > > > > > > Signed-off-by: Jason Andryuk > > > --- > > > I was looking for examples of task_lookup_fd_rcu()/files_lookup_fd_rcu() > > > and found this. It differed from the example given in > > > Documentation/filesystems/files.rst, so I was initially confused. A > > > comment seemed appropriate to avoid confusion. > > > > > > kernel/kcmp.c | 3 +++ > > > 1 file changed, 3 insertions(+) > > > > > > diff --git a/kernel/kcmp.c b/kernel/kcmp.c > > > index 5353edfad8e1..4fb23f242e0f 100644 > > > --- a/kernel/kcmp.c > > > +++ b/kernel/kcmp.c > > > @@ -63,6 +63,9 @@ get_file_raw_ptr(struct task_struct *task, unsigned int idx) > > > { > > > struct file *file; > > > > > > + /* This RCU locking is only present to silence warnings. The pointer > > > + * value is only used for comparison and not dereferenced, so it is > > > + * acceptable. */ > > > rcu_read_lock(); > > > file = task_lookup_fd_rcu(task, idx); > > > rcu_read_unlock(); > > > > They are not wrong, this is just such a bit weird semantics where > > we fetch the pointers and strictly speaking map them into numbers > > set to compare. But I agree that such tricks might confuse. How about > > > > /* > > * Fetching file pointers inside RCU read-lock section > > * and reuse them as plain numbers is done in a sake > > * of speed. But make sure never dereference them after. > > */ > > I would tweak it a little to "Fetch file pointers inside RCU read-lock > section, but skip additional locking for speed. The pointer values > will be used as integers, and must not be dereferenced." Up to you. Initially I use _raw_ptr suffix in function name trying to point out that the pointer obtained should not be considered in any way except a natural number. So I'm fine with any comment which helps readability. > > One other idea I had was to switch the return value to "void *". That > way it isn't a struct file, and it isn't readily dereference-able. > But I wasn't sure if that would be overkill. What do you think? Lets better stick with a comment I think. Thanks!