Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp3589508rwl; Tue, 27 Dec 2022 11:31:25 -0800 (PST) X-Google-Smtp-Source: AMrXdXtfli3kDuhKRm8vW6PufiL1yE1CDPmaQzSLjETvJs8bZpPCjdLvLtqvMwD6QQAfa1kDCqkl X-Received: by 2002:a17:903:3253:b0:192:6bfe:2a32 with SMTP id ji19-20020a170903325300b001926bfe2a32mr10740700plb.56.1672169485349; Tue, 27 Dec 2022 11:31:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672169485; cv=none; d=google.com; s=arc-20160816; b=tNDd2HsGmzBV7dwSSGcD2l95VG9wc2Iq2vFTXADlbUZA94HaaXuKP/WpKgZMcfAnvb eeyMtUH28ho/yEUHHAtHD7lvC6BVeotCjx9vtR1gEn2LZOBwqhMYzuoVAn/VT905J98W UYX5pzx5DNHqJ/1hNlZ9g6BIUZr+e9dGut8UBUXYb/AZgU9b/7W6/VS90103czerYWEp AlkctPVomwiqIHIftqI+f2hf3AodxSE0q5tEem3jH92B0eoF+4OOGtQj5SkImSC1mDZB niWBHJPK48hxG7FWaeB3xcW0Oly2BjKKJgEPEPY/f6yIB3LSHZQ2RO7YbGYcplbn09zP tyzw== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=UGqOJ/OwJuH3HnwXLcj6CYhQufJZIjHm1FgtL/4iQ+s=; b=g4d9NeMZufc/RCmqW9l6lTQECQman+6Swec61LczXaKixJVhhuYeWKknYzDYOTZULo tbz8l05aJdn2ZXbN9c8Uss3iH/jw2D9d5lMA1m9cnuVm1DocDv9/bpZUVZJNlkN+PE0P YWfCNL5TDGNDwLXZs9f+2B00dbNhKsKMx25HlZPegF+V1eW6miXMdWCj7FJUaGHhdy5J /MXQDhof4jLvWNfN+4HFDtOr+NsTlzxgSsujiepBC+AklXMIR/jmojLlkdZXDEN+LTf1 Mjve/5kKg4s8wRWlSXWFuSLmJfEwA164gJJBK6v68bSLiXhIs1oVwMffiSEuTg8puavV ZNfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=vDLqcDB6; 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 u10-20020a655c0a000000b00476db6fe4cfsi13999769pgr.829.2022.12.27.11.31.16; Tue, 27 Dec 2022 11:31:25 -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=vDLqcDB6; 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 S229849AbiL0TWm (ORCPT + 66 others); Tue, 27 Dec 2022 14:22:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44146 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229488AbiL0TWk (ORCPT ); Tue, 27 Dec 2022 14:22:40 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 68838D4C; Tue, 27 Dec 2022 11:22:39 -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 ams.source.kernel.org (Postfix) with ESMTPS id 193F3B810A9; Tue, 27 Dec 2022 19:22:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2D798C433D2; Tue, 27 Dec 2022 19:22:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672168956; bh=HQogRMPkd4mTd9GL8MsC9tWHVut88yOyJXgzfE2Mg/8=; h=From:To:Cc:Subject:Date:From; b=vDLqcDB61J3uvKTRrDb2HTD3ZgflRoB2EjpBVWxzA4nFFZPKELz3A1ATtPhJR7nuL pkNiAu21YNCmlcuILqK/UTlowtfwJiO+fcIoJ1RSFVvuZRMCzHgVY64shOCgOFFAVQ hE6EABBBgJRC3y+nyI54+sp/U8XuXpVx9s2H3htxUu1g26mvnJixurxR0kJKPPTwnM PYBECaM3VLbY+MvgJk1ZlQt+SnYFvTV/ECNyD+qvNWTODSyJ5zxwp7cygtqTVbbcgi 8R5Daa7u2KjSf7C/ZM9eoYbiE3kTkS9lygWpZGGrvEa49em6AmNCXL36qB+aDU6iNL Jzk2YVAe/ljSg== From: SeongJae Park To: akpm@linux-foundation.org Cc: alexander.h.duyck@linux.intel.com, paulmck@kernel.org, linux-mm@kvack.org, rcu@vger.kernel.org, linux-kernel@vger.kernel.org, SeongJae Park Subject: [PATCH] mm/page_reporting: replace rcu_access_pointer() with rcu_dereference_protected() Date: Tue, 27 Dec 2022 19:21:58 +0000 Message-Id: <20221227192158.2553-1-sj@kernel.org> X-Mailer: git-send-email 2.25.1 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 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 while concurrent updtes to the pointer is avoided by holding the update 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 --- mm/page_reporting.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/page_reporting.c b/mm/page_reporting.c index 79a8554f024c..079e0ebe1fb7 100644 --- a/mm/page_reporting.c +++ b/mm/page_reporting.c @@ -356,7 +356,7 @@ 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, true)) { err = -EBUSY; goto err_out; } @@ -401,7 +401,7 @@ void page_reporting_unregister(struct page_reporting_dev_info *prdev) { mutex_lock(&page_reporting_mutex); - if (rcu_access_pointer(pr_dev_info) == prdev) { + if (rcu_dereference_protected(pr_dev_info, true) == prdev) { /* Disable page reporting notification */ RCU_INIT_POINTER(pr_dev_info, NULL); synchronize_rcu(); -- 2.25.1