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: 13082502 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id D0413C4167B for ; Tue, 27 Dec 2022 19:22:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 24B9F8E0002; Tue, 27 Dec 2022 14:22:40 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1FC4B8E0001; Tue, 27 Dec 2022 14:22:40 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0C48E8E0002; Tue, 27 Dec 2022 14:22:40 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id F19028E0001 for ; Tue, 27 Dec 2022 14:22:39 -0500 (EST) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id C74F41C5E23 for ; Tue, 27 Dec 2022 19:22:39 +0000 (UTC) X-FDA: 80289058038.13.0FCB856 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf29.hostedemail.com (Postfix) with ESMTP id 6D8A812000C for ; Tue, 27 Dec 2022 19:22:38 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=vDLqcDB6; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf29.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1672168958; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=UGqOJ/OwJuH3HnwXLcj6CYhQufJZIjHm1FgtL/4iQ+s=; b=Qxec28Jlv25zvWwO44+T+ps9rLB7CML4LvB6Qu9f1QBgwPfcM4S8+EYBn0E9RoAiuUV8qz exMafK2cEmkAVvP6US3uXbPGnk+bsrhnDIo2pFz70rlWq2T/SgJm3ZTJOl9n82g0WVby3T 86I4rnWkk8OweHwvfYSejAao19lgL50= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=vDLqcDB6; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf29.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1672168958; a=rsa-sha256; cv=none; b=zKnYnSVhzCIo68qqwowwgmyAoM0ART7PCmgpKbFGQOZLymUCpeG+qtyawO+LIiL3ibgaO4 xMwLzNb4b6K/KlYBNb+l9vlTm2cieiPa48F/i/Hhb0oaf8FB9bDRN+mQM2ic592oVKhDJv WR9GJYJ5s7lGkwimoCeYcvTxJ3fX7LA= 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 5793E61031; Tue, 27 Dec 2022 19:22:37 +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-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 6D8A812000C X-Stat-Signature: ehkmun383cux3oajogyctpjkb68e415r X-HE-Tag: 1672168958-359621 X-HE-Meta: U2FsdGVkX18yyR5rV1VBf8rv1Mdlxv+yklNy1baxx6MH/YTdTo+wLNPa/ObkSWdABNO39OpiY8H3BU+8B9gjX1rB51VhO8dwSJqtMY+QpA5k1Zn46hbjuFrh9awfuQPhxyeZqnfou08rZDy30+KJeGa3LNIw6PuFGoXYHwLFw/VRSnVOBXH+u4t6rmQOabHx+BHZnGo0P5hb+JiKH7Q11P+CXZH2phqvrPbDohS8nwf074u/LgeU4a25zOORYagyq85ViPW6UXtaz5+L0xvXhe9t6A7iPtM6qmDZeaBqeIqgEZiEIOa0zZGhvW5nM6lb8EQDZES6C++A2656M2MItEr4nZY2RZZWnq2CAPMeo7k9jHnSPOpSw9Pz4S5nN2iZSD786oa41Dnqt8TEX4Az/fBauFcIZ/QEo6vxKq5F5KVEFaGSeYH6OhnJ59vGO4a0ezXgFVBkMIsuuXWI20A+/PLlcStdo0Yzc1ZKOReGa2mrZq0rSG93c2dQL3Uhn1ySTwo7zQj1b7lpiU+jnsN8nhx14XT3GzeFGXwjv8WWU1Qpd25vJz78wM4wnFXyiM4Zhrjl3QmNBpkBPuTjk14n0DeSzs2RpfgWDG5vu7StJL252cV2yR9KCOTmvnTWUFUhZF1iNvhAH9O9oCo+74FOtsqysP1rnQDVu7pGcFWGAhy8GyFll66upNIGnMdmUQ0l7vj7rLRgmSpm4T1QdIiqWc13P+3ZifVOYwoyIbE6wAsXtgYgbQVL8S+k3yssu5NpgZMiPXiw1ntDewPn+tWaxdSOWZZBI1dPyvboE7hgpyk8ptU9yQLZmELMAvFmrqPhsKk8A2E472R22ESG1DQq1dqAwPqjD6Q0p5YojmSbI6tzhDMN2u3J0+1wFzumSJJhBGBMsGXxsAX/kvplcfouNSs1mpyxdlLOMyIrsgHStlEvE5frRbrhGmeXZCARpIY75FMF9G0ogKh5wD3rfCB JVOatspm sdN8MB5SqJQgWw0wh8mt/UYfuT6MMA/oZ33s4ABuaDeHPioPo1ivGIUP8PyZDrNSu2XIohWUVFj0nCEtweeZazonDyFoeuEWMjXza3bbB/gULhtXDidgEBgfsCQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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();