From patchwork Tue Dec 27 19:21:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 36981 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp1543686wrt; Tue, 27 Dec 2022 11:23:27 -0800 (PST) X-Google-Smtp-Source: AMrXdXvm0ztyk/vSt1vjL5RnEGtfubyxjlTRilqDNlYmw4oyR4zgkO1r06U6JsrkPFAh4ySPo+AT X-Received: by 2002:a17:903:2786:b0:192:8a19:9b4f with SMTP id jw6-20020a170903278600b001928a199b4fmr4424824plb.41.1672169007427; Tue, 27 Dec 2022 11:23:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672169007; cv=none; d=google.com; s=arc-20160816; b=eir2OrqvmgSraY+xxgOfQ1qTzfLh8LSiQCG7DY1hpUopkEQYM875e2NSoVvXxMbun0 LLSaI+SgvchRawO6lXTgT9RT9NGoRZU412nfPyQlTOrALU5KgnI8w6p2eJnHpVFYcIq4 WZlsChynrfDXkQ5ly9P6cJLlsJ9XAZEsglDWi/E4vvonHOxok6Ijhcuyzgi4r3cgljRC r1PMYdgC1JW2f0kPDWaRmT9CDpuRjFcal53ny0qkZWBm391R73moHOWNPDqMpO7+k0JA qUzKVyyODHEQamuMhMRYKjA82aVwAMeKEZt/QdFnCimf7+YvCP9F6JnnTavdzHyoUurX ntXA== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a6-20020a631a06000000b0048be2671cd0si15017340pga.170.2022.12.27.11.23.15; Tue, 27 Dec 2022 11:23: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=@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 + 99 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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1753396289026216780?= X-GMAIL-MSGID: =?utf-8?q?1753396289026216780?= 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();