Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp3863964iob; Tue, 17 May 2022 08:42:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxmHlEwRfffjP0xn1ZmzWfeZoI+JuG4G3jBFPC9oCbjfcsVU8CbYzMy7y6mMQxAhzgtUDwt X-Received: by 2002:a63:2215:0:b0:3c1:fd25:b6a1 with SMTP id i21-20020a632215000000b003c1fd25b6a1mr19825893pgi.406.1652802177534; Tue, 17 May 2022 08:42:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652802177; cv=none; d=google.com; s=arc-20160816; b=QPUONkb8opP3sxoCCnpT6NIuvg/I29d7ygOPTUiZ04DU5gGAs4itFTfmUcyI8wzmBH spuXoHEvR50Rv3kDEBRIRL2/HH+cGDCnoxqb0hMaJn6aLgdDeMufuKIeDdXgfI7oQ52X A7SVrxgHptP5y9Xmz2XRytJOLduA/11FhLFdiRodi70QSAQPC98BgEDE1mjYv/hBW5/7 4ycwXnLVpyGZM1KFOWDlHjJNCxGsKENmwhLx57/WC6kkqUIvgd0fj5TU1I0642lFjDNm 9YUbFz7uejbU9wF8XLgXotux6rQSldkacuZLmHl3RZAS8AccnfHNtMR8oa+f6GB4X9MD tPCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:sender:dkim-signature; bh=0lmFLC5QURVu6XbOogEJxka6Jitm3xVNpCgUYYeF1WY=; b=Hfu0JWNFTLIxqjLc/C+ES1KmWrr/7LDeAm16yxlcA2BuoOfeRCsqc2gsk24vh2q/xs 4DFeIDUCHuGvE1KrIZmWDBXZdKREhyoy1pX71/dKri8mTyMp4cLjOhdxE6kd8iN3wh6c zUjZ9G8w0Z+4ZVB4zDVjK+/RaD7CyRAjMr+kJgexkP4tfvS/EQ2k5YOSWpdpzAp5BfGz tfqxTiSvi1Wu+99qwVgcJtNGBze+5S0S5qtivXk2GzKBMlcKec9bGy4fd8N/D7x4c8Ff C4mZ57Tv1Y4RT5K6h/X4MEXw5BUsCgmiveq2Fch3c/hFb3k13O/TSIJZCnC3QCReXZw0 w6aA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=KqhIMVYS; 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 u20-20020a634554000000b003816043efb5si16812329pgk.426.2022.05.17.08.42.45; Tue, 17 May 2022 08:42: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=@gmail.com header.s=20210112 header.b=KqhIMVYS; 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 S235124AbiEQEV0 (ORCPT + 99 others); Tue, 17 May 2022 00:21:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37716 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238036AbiEQEVM (ORCPT ); Tue, 17 May 2022 00:21:12 -0400 Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A1688140BC for ; Mon, 16 May 2022 21:21:11 -0700 (PDT) Received: by mail-pj1-x1035.google.com with SMTP id gg20so6236207pjb.1 for ; Mon, 16 May 2022 21:21:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=0lmFLC5QURVu6XbOogEJxka6Jitm3xVNpCgUYYeF1WY=; b=KqhIMVYSjNMwsD3uFmY8mx2Xn2oOcT4oUTDA05XbvKsse6EbMjZv2SMKwEXGMYwZRw u/qvtBrZ7DlqjHUgtazfYbQjZmMoik0yARqyKhwzwnR26gJAEEq7kCDsP9nYSfd3u02W 2J4bplalNGtW0qAGVcDNr98l+BfcxF691q7MqZjdAG9gMdvmnOL2vZHtgEnow9VCtw0q AXNkAoFiwHXQNyq9+GOB/YjAEHCuAuyhSiA92MjXiVpKHbx36rTqBvD29GCZCUe3ktQa hUUhB2IqlSuw4O1PaN/4WSnqOOhJlq6HF+BMJcssuCsfTQA1eASpW8wXer4Azkuqj1LJ nuHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to; bh=0lmFLC5QURVu6XbOogEJxka6Jitm3xVNpCgUYYeF1WY=; b=qz7BOZJtq3j8lE7Avd5B7rgtM2cAQ4tDplXT5D8mpKc5RsiqC0/VlpbkjkjiefHaUh 19A8UA+z3vmaGt3j+ZDgJP/4LPLtj5tMZ6psi8dQLLU8HI+uAyTsKZeKYXOoZI4L00Cs GTY7zqynXBPOoNG30MtkfQfYUZsOai9m5s2ciUgQws0OfJSM11XxC//aQHgZC2MUxOYW WHdwm3MgrQ+UMMnkqmkt5EsqLC9ZGAOBeykEugbGfNavcnX+ofwm+iD2VkSwx8C6gG2q Euv+Hblm0vGfVqWa8k3cMydx6TTQhLF2dlFjFjkkfjBtAhz8IhGAPJj99MeGyu2bYyv2 3MKw== X-Gm-Message-State: AOAM532hsQGhJxXq1aWtad7HVp3qXMDE73rvvJbqFd+mLaB4s5Fv2H+f 32LI8tzUhoqnUW/1oPGG7Aw= X-Received: by 2002:a17:903:18f:b0:15e:93bd:730f with SMTP id z15-20020a170903018f00b0015e93bd730fmr20199308plg.172.1652761271004; Mon, 16 May 2022 21:21:11 -0700 (PDT) Received: from localhost ([2620:10d:c090:400::4:62fc]) by smtp.gmail.com with ESMTPSA id m14-20020a170902db0e00b0015e8d4eb228sm5998293plx.114.2022.05.16.21.21.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 May 2022 21:21:10 -0700 (PDT) Sender: Tejun Heo Date: Mon, 16 May 2022 18:21:09 -1000 From: Tejun Heo To: Imran Khan Cc: viro@zeniv.linux.org.uk, gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/5] kernfs: make ->attr.open RCU protected. Message-ID: References: <20220428055431.3826852-1-imran.f.khan@oracle.com> <20220428055431.3826852-3-imran.f.khan@oracle.com> <526b46a7-7daa-9050-1276-e19836816991@oracle.com> <4532123f-4c03-0303-1480-a51faabca806@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4532123f-4c03-0303-1480-a51faabca806@oracle.com> X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no 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 Tue, May 17, 2022 at 12:30:26PM +1000, Imran Khan wrote: > +/** > + * kernfs_deref_open_node - Get kernfs_open_node corresponding to @kn. > + * > + * @kn: target kernfs_node. > + * @val: RCU dereference will take place only if val is true. > + * > + * Fetch and return ->attr.open of @kn when current updater of ->attr.open > + * ensures that as long as @val is true, other updater(s) of ->attr.open > + * can not change it. The caller needs to pass value of the condition > + * (@val) that prevents value of ->attr.open from changing. > + * > + * This should ONLY be used by updaters of ->attr.open. > + */ > +static struct kernfs_open_node * > +kernfs_deref_open_node(struct kernfs_node *kn, bool val) > +{ > + return rcu_dereference_protected(kn->attr.open, val); > +} > + > +/** > + * kernfs_check_open_node - Get kernfs_open_node corresponding to @kn. > + * > + * @kn: target kernfs_node. > + * @val: RCU dereference will take place only if val is true. > + * > + * rcu_dereference and return ->attr.open of @kn. This is used in cases > + * where we can access ->attr.open outside RCU read-side critical section > + * as long as specified conditions are correct i.e @val is true. > + * > + * This should ONLY be used by readers of ->attr.open. > + */ > +static struct kernfs_open_node * > +kernfs_check_open_node(struct kernfs_node *kn, bool val) > +{ > + return rcu_dereference_check(kn->attr.open, val); > +} You gotta put the conditions inside these wrappers. These wrappers are supposed to describe as strict as reasonably possible so that the checks can catch people making mistakes. It doesn't make much sense to defer the condition to the callers. Just describe what the expected conditions are in the wrappers as best as you reasonably can. Thanks. -- tejun