Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp3927094rwl; Tue, 27 Dec 2022 18:19:13 -0800 (PST) X-Google-Smtp-Source: AMrXdXsRXyol6yw67IxgQK5nAonnZjjezlgyxIp4RaS2ATCEfpVXm1RiFLZAMn63s44U+Jo0j69l X-Received: by 2002:a17:902:7891:b0:191:3c62:3be8 with SMTP id q17-20020a170902789100b001913c623be8mr29230355pll.4.1672193953498; Tue, 27 Dec 2022 18:19:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672193953; cv=none; d=google.com; s=arc-20160816; b=V6AyN3ib3H4qEehLy8/cif2c3HVIUNgqHaWzg1AIfN76Ib1b+o+I5b9NJuxJVqL2gG wUYFOGeIMoGfrhI5rqkqGytjrlx+eQoNQN9I8udCEdTFtHGbZQKVYJVCNMyvlBxLgqOd xkX2+WFy+2PrLt71N6eGuvOfRpv/3Vc7D0/+BKgu6MR3SCcHHlbv0OUdqtNpEJo9f3iA r9FpIRyiNpoUa/fTzsK3PnYp9VWw86szvGCIbbMZEPl7xMsrFGTHN2Fq47nZ9XD2VYQ2 CFKmL7EjxT0tUEJCL8fZN0jihaQQiD79LbrOkqZe4OC8lej1lOWOe4DbaBKfgT58smdJ UQ0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=P5+k8xAbZk05u94NgigArqSOR+L5o5oc55ht3hRddcE=; b=yOkZ8qNpydwFU3ZE6SlAsPpk6ZzgzzcqUkqPehbhU59Rls5cGz4fGU3sn60Oz+1Q3H q3Ewo55BiwrFi+TElvFhQVrkB9YP1Ht3AFSIK51R63pV+LvHVzc7Fach89SQMlziprPn sQyM3hZj2izPYESN2Ka2a+BMkU3gS9cGk8+JPGNgjYabz+NW3RG4LY7SGlwTFdmFN1sx kPqSVs4c3WPt4wTNtj5oJdG+Lncf3R53hfj3xzgsdiUJ8VzkJ16T7W+A4IL8X6IeMvwj 1+BxLEDf3AZ3hm+xnRmu8U7cehq9C4EfyMPCsOi0gOKoJx2A86TmK0BNpITWd67ClZQj VUtw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=aeWc+l1u; 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 j5-20020a170902da8500b00189655d51f5si16959766plx.260.2022.12.27.18.19.04; Tue, 27 Dec 2022 18:19:13 -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=@kernel.org header.s=k20201202 header.b=aeWc+l1u; 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 S232625AbiL1CJ3 (ORCPT + 65 others); Tue, 27 Dec 2022 21:09:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47694 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232621AbiL1CJY (ORCPT ); Tue, 27 Dec 2022 21:09:24 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 381A9DFC2; Tue, 27 Dec 2022 18:09:22 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id B83F4611F2; Wed, 28 Dec 2022 02:09:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7F904C433D2; Wed, 28 Dec 2022 02:09:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672193361; bh=0+9mbLzHdVINwOD8vgA/LPr1HjdwcqowwuSzxvl7dXI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aeWc+l1u/GpeRN6IHZfdLNkL8f8QnVLmPhoDo3v7jJ5UYL/GYcKP7FF3ARl0YfVRp w3873WEAGUoq7z/E5YbwvCHXk75rJ+c44eesw3h6fylZTk1UEBb3Py3e2raHxojxQm bkNqVLJ6n7lKQMRuXR77bf7Xm/gJr5hyYA0KViggYysry68z67sUte+xPFApUAeX5w aOPcDHXvCq3Rdgklwu88jKx988Gn5cUdQdNxoc7mwt/4ndbeslOR+5bY8C52qt7JFT C9pUKBfrC1T8ncUFsUj2F3dDXgYAiSQOMlD5ghOxS2ooCetb4GWnZsLoHLsXEmR20j UUHQYNhlt+MjA== From: SeongJae Park To: Miaohe Lin Cc: SeongJae Park , akpm@linux-foundation.org, alexander.h.duyck@linux.intel.com, paulmck@kernel.org, linux-mm@kvack.org, rcu@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] mm/page_reporting: replace rcu_access_pointer() with rcu_dereference_protected() Date: Wed, 28 Dec 2022 02:09:18 +0000 Message-Id: <20221228020919.1511138-1-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <4bc4ab74-3ccd-f892-b387-d48451463d3c@huawei.com> References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham 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 Wed, 28 Dec 2022 09:45:00 +0800 Miaohe Lin wrote: > On 2022/12/28 9:29, SeongJae Park wrote: > > Page reporting fetches pr_dev_info using rcu_access_pointer(), which is > > for safely fetching a pointer that will not be dereferenced but could > > concurrently updated. The code indeed does not dereference pr_dev_info > > after fetcing it using rcu_access_pointer(), but it fetches the pointer > > Thanks for your work. Might something to improve. > > s/fetcing/fetching/ > > > while concurrent updtes to the pointer is avoided by holding the update > > s/updtes/updates/ Thank you! I shall add these to scripts/spelling.txt. > > > side lock, page_reporting_mutex. > > > > In the case, rcu_dereference_protected() is recommended because it > > provides better readability and performance on some cases, as > > rcu_dereference_protected() avoids use of READ_ONCE(). Replace the > > rcu_access_pointer() calls with rcu_dereference_protected(). > > > > Signed-off-by: SeongJae Park > > --- > > Changes from v1 > > (https://lore.kernel.org/linux-mm/20221227192158.2553-1-sj@kernel.org/) > > - Explicitly set the protection condition (Matthew Wilcox) > > > > mm/page_reporting.c | 6 ++++-- > > 1 file changed, 4 insertions(+), 2 deletions(-) > > > > diff --git a/mm/page_reporting.c b/mm/page_reporting.c > > index 79a8554f024c..5c557a3e1423 100644 > > --- a/mm/page_reporting.c > > +++ b/mm/page_reporting.c > > @@ -356,7 +356,8 @@ int page_reporting_register(struct page_reporting_dev_info *prdev) > > mutex_lock(&page_reporting_mutex); > > > > /* nothing to do if already in use */ > > - if (rcu_access_pointer(pr_dev_info)) { > > + if (rcu_dereference_protected(pr_dev_info, > > + lockdep_is_held(&page_reporting_order))) { > > I think it should be lockdep_is_held(&page_reporting_mutex) instead of > lockdep_is_held(&page_reporting_order) here? You're right, thank you for finding this. I will fix these in the next version. Thanks, SJ > > Thanks, > Miaohe Lin