[v2] mm/page_reporting: replace rcu_access_pointer() with rcu_dereference_protected()
Message ID | 20221228012902.1510901-1-sj@kernel.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp1668638wrt; Tue, 27 Dec 2022 17:38:59 -0800 (PST) X-Google-Smtp-Source: AMrXdXsDMeAyOmRykoclMoym0O312X2mD8l3Yvbs2jj0nAl2tlv6VGMxDYm8QMUj066d24P+RN39 X-Received: by 2002:a05:6a20:a59a:b0:9d:efbf:7864 with SMTP id bc26-20020a056a20a59a00b0009defbf7864mr30354149pzb.25.1672191539712; Tue, 27 Dec 2022 17:38:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672191539; cv=none; d=google.com; s=arc-20160816; b=aX2pPWLTvaBasL8dy+gWrReBE9syRaZmqTz9+RN190ovI+QmqU731SZXwfeTEVCuH2 tjQMeDvzaCLUjVUyWHX8K6vL5ceUkOLP50a+2KtR1hlTzzmRTs7to/NbfPdF7h5VVsr6 kmAKElFTwjPEEx3sZXprGjnw228z8onPdGnZ5pHX7HOZcVkx8zwujpSwiXEneS/sgl6y eABLKqy99kYaakOF3qjbOrnLNdSHtd+DLEVu7oQoEzKGjH/SYUB+g4fbvTRTtySYMh71 yIZo1EMkjUvOseaWSxKwfDSCht4s92cjLwVg8+gVchrRxLs892m4eYl2YGr37w9pY6X+ CemQ== 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=+GjBIcG1XK4MOTxEs5gCnUbmFtQjxi34Q8bMQCgOi+g=; b=cPst8X2ixetkRI+6laohrzWDRYnM+daP5x+Lhk1R4dFPOAb3M/4V7XUHnFnX5RF/wG S+cnREcbtM2/gl36Yeog7JvSYteLv/0DDe3fa9GeaolnegkZhixHjfylQtihWmtS3WDu kunCtHUrOkkj0g7jes/CCz0D5Lzu7IB+N2GvbEmRPewv0PgYG+6o4/N92GSULYMPDPgr tXhajksdLgBHX8skg5ckE/t162BDne3CZAFlBzJpR6GWBSsYR60EpyO/kTiXSFrpeBNJ VGBux0owtFW3OArM6W077h1f54WN5jyK8yahA69k7cCJrVik1A/tJo8yIlhBs44Z3t04 qUvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=hKkaqU5o; 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 p12-20020a65490c000000b00489a4cba354si16099989pgs.453.2022.12.27.17.38.47; Tue, 27 Dec 2022 17:38:59 -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=hKkaqU5o; 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 S230064AbiL1B3P (ORCPT <rfc822;eddaouddi.ayoub@gmail.com> + 99 others); Tue, 27 Dec 2022 20:29:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58568 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229475AbiL1B3O (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 27 Dec 2022 20:29:14 -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 21F67DF15; Tue, 27 Dec 2022 17:29:13 -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 A57D2B80FEC; Wed, 28 Dec 2022 01:29:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B905CC433D2; Wed, 28 Dec 2022 01:29:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672190950; bh=3XVIwz9Ohm85QPhk+zsQOi2XQO0+IAfPFOpLecTxMg0=; h=From:To:Cc:Subject:Date:From; b=hKkaqU5oJoC5WDr5ZPFVqhMzboiYc9mkt1GblQx3R3L6rpSJqAja5O+NLlk2MuppA gXQOuUvTWqG6KJWIYIcJSFkQgUxFBKhVgskJiAjO0sYxGEXKo/A4ci4wp/Yl/Nj+Cb jzeklfprYSsSHFv5+VbC6Z0u6taoVst5nFDyV2mm0itOc44wstERjnIM0b8tlnYt9i mfiBsn4N0ZWslLezaermTPArVLxYi1kmZiARJRvd4WbC/aTyfsjTsug+czx8161kcF agtfinvxgJI+dBy74z20AVTCGPDjDnaRVb0RAIuV7fcId33dDZLxs8Ro1I7ynE6+a3 arjxjrw/UNoYA== From: SeongJae Park <sj@kernel.org> 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 <sj@kernel.org> Subject: [PATCH v2] mm/page_reporting: replace rcu_access_pointer() with rcu_dereference_protected() Date: Wed, 28 Dec 2022 01:29:02 +0000 Message-Id: <20221228012902.1510901-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: <linux-kernel.vger.kernel.org> 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?1753419915895395849?= |
Series |
[v2] mm/page_reporting: replace rcu_access_pointer() with rcu_dereference_protected()
|
|
Commit Message
SeongJae Park
Dec. 28, 2022, 1:29 a.m. UTC
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 <sj@kernel.org>
---
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(-)
Comments
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/ > 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 <sj@kernel.org> > --- > 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? Thanks, Miaohe Lin
On Wed, 28 Dec 2022 09:45:00 +0800 Miaohe Lin <linmiaohe@huawei.com> 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 <sj@kernel.org> > > --- > > 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
Hi SeongJae, I love your patch! Yet something to improve: [auto build test ERROR on akpm-mm/mm-everything] url: https://github.com/intel-lab-lkp/linux/commits/SeongJae-Park/mm-page_reporting-replace-rcu_access_pointer-with-rcu_dereference_protected/20221228-093057 base: https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything patch link: https://lore.kernel.org/r/20221228012902.1510901-1-sj%40kernel.org patch subject: [PATCH v2] mm/page_reporting: replace rcu_access_pointer() with rcu_dereference_protected() config: x86_64-randconfig-a002-20221226 compiler: clang version 14.0.6 (https://github.com/llvm/llvm-project f28c006a5895fc0e329fe15fead81e37457cb1d1) reproduce (this is a W=1 build): wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # https://github.com/intel-lab-lkp/linux/commit/f7744809d7f12dccff86c60831ddf3c316ada60e git remote add linux-review https://github.com/intel-lab-lkp/linux git fetch --no-tags linux-review SeongJae-Park/mm-page_reporting-replace-rcu_access_pointer-with-rcu_dereference_protected/20221228-093057 git checkout f7744809d7f12dccff86c60831ddf3c316ada60e # save the config file mkdir build_dir && cp config build_dir/.config COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=x86_64 olddefconfig COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash If you fix the issue, kindly add following tag where applicable | Reported-by: kernel test robot <lkp@intel.com> All errors (new ones prefixed by >>): >> mm/page_reporting.c:360:5: error: member reference base type 'typeof (page_reporting_order)' (aka 'unsigned int') is not a structure or union lockdep_is_held(&page_reporting_order))) { ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/lockdep.h:286:52: note: expanded from macro 'lockdep_is_held' #define lockdep_is_held(lock) lock_is_held(&(lock)->dep_map) ^ ~~~~~~~ include/linux/rcupdate.h:664:54: note: expanded from macro 'rcu_dereference_protected' __rcu_dereference_protected((p), __UNIQUE_ID(rcu), (c), __rcu) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~ include/linux/rcupdate.h:460:21: note: expanded from macro '__rcu_dereference_protected' RCU_LOCKDEP_WARN(!(c), "suspicious rcu_dereference_protected() usage"); \ ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/rcupdate.h:381:8: note: expanded from macro 'RCU_LOCKDEP_WARN' if ((c) && debug_lockdep_rcu_enabled() && !__warned) { \ ^ 1 error generated. vim +360 mm/page_reporting.c 351 352 int page_reporting_register(struct page_reporting_dev_info *prdev) 353 { 354 int err = 0; 355 356 mutex_lock(&page_reporting_mutex); 357 358 /* nothing to do if already in use */ 359 if (rcu_dereference_protected(pr_dev_info, > 360 lockdep_is_held(&page_reporting_order))) { 361 err = -EBUSY; 362 goto err_out; 363 } 364 365 /* 366 * If the page_reporting_order value is not set, we check if 367 * an order is provided from the driver that is performing the 368 * registration. If that is not provided either, we default to 369 * pageblock_order. 370 */ 371 372 if (page_reporting_order == -1) { 373 if (prdev->order > 0 && prdev->order <= MAX_ORDER) 374 page_reporting_order = prdev->order; 375 else 376 page_reporting_order = pageblock_order; 377 } 378 379 /* initialize state and work structures */ 380 atomic_set(&prdev->state, PAGE_REPORTING_IDLE); 381 INIT_DELAYED_WORK(&prdev->work, &page_reporting_process); 382 383 /* Begin initial flush of zones */ 384 __page_reporting_request(prdev); 385 386 /* Assign device to allow notifications */ 387 rcu_assign_pointer(pr_dev_info, prdev); 388 389 /* enable page reporting notification */ 390 if (!static_key_enabled(&page_reporting_enabled)) { 391 static_branch_enable(&page_reporting_enabled); 392 pr_info("Free page reporting enabled\n"); 393 } 394 err_out: 395 mutex_unlock(&page_reporting_mutex); 396 397 return err; 398 } 399 EXPORT_SYMBOL_GPL(page_reporting_register); 400
Hi SeongJae, I love your patch! Yet something to improve: [auto build test ERROR on akpm-mm/mm-everything] url: https://github.com/intel-lab-lkp/linux/commits/SeongJae-Park/mm-page_reporting-replace-rcu_access_pointer-with-rcu_dereference_protected/20221228-093057 base: https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything patch link: https://lore.kernel.org/r/20221228012902.1510901-1-sj%40kernel.org patch subject: [PATCH v2] mm/page_reporting: replace rcu_access_pointer() with rcu_dereference_protected() config: riscv-randconfig-r022-20221225 compiler: clang version 16.0.0 (https://github.com/llvm/llvm-project f5700e7b69048de958172fb513b336564e7f8709) reproduce (this is a W=1 build): wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # install riscv cross compiling tool for clang build # apt-get install binutils-riscv64-linux-gnu # https://github.com/intel-lab-lkp/linux/commit/f7744809d7f12dccff86c60831ddf3c316ada60e git remote add linux-review https://github.com/intel-lab-lkp/linux git fetch --no-tags linux-review SeongJae-Park/mm-page_reporting-replace-rcu_access_pointer-with-rcu_dereference_protected/20221228-093057 git checkout f7744809d7f12dccff86c60831ddf3c316ada60e # save the config file mkdir build_dir && cp config build_dir/.config COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=riscv olddefconfig COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=riscv SHELL=/bin/bash If you fix the issue, kindly add following tag where applicable | Reported-by: kernel test robot <lkp@intel.com> All errors (new ones prefixed by >>): In file included from mm/page_reporting.c:4: In file included from include/linux/page_reporting.h:6: In file included from include/linux/scatterlist.h:9: In file included from arch/riscv/include/asm/io.h:136: include/asm-generic/io.h:547:31: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] val = __raw_readb(PCI_IOBASE + addr); ~~~~~~~~~~ ^ include/asm-generic/io.h:560:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] val = __le16_to_cpu((__le16 __force)__raw_readw(PCI_IOBASE + addr)); ~~~~~~~~~~ ^ include/uapi/linux/byteorder/little_endian.h:37:51: note: expanded from macro '__le16_to_cpu' #define __le16_to_cpu(x) ((__force __u16)(__le16)(x)) ^ In file included from mm/page_reporting.c:4: In file included from include/linux/page_reporting.h:6: In file included from include/linux/scatterlist.h:9: In file included from arch/riscv/include/asm/io.h:136: include/asm-generic/io.h:573:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] val = __le32_to_cpu((__le32 __force)__raw_readl(PCI_IOBASE + addr)); ~~~~~~~~~~ ^ include/uapi/linux/byteorder/little_endian.h:35:51: note: expanded from macro '__le32_to_cpu' #define __le32_to_cpu(x) ((__force __u32)(__le32)(x)) ^ In file included from mm/page_reporting.c:4: In file included from include/linux/page_reporting.h:6: In file included from include/linux/scatterlist.h:9: In file included from arch/riscv/include/asm/io.h:136: include/asm-generic/io.h:584:33: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] __raw_writeb(value, PCI_IOBASE + addr); ~~~~~~~~~~ ^ include/asm-generic/io.h:594:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] __raw_writew((u16 __force)cpu_to_le16(value), PCI_IOBASE + addr); ~~~~~~~~~~ ^ include/asm-generic/io.h:604:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] __raw_writel((u32 __force)cpu_to_le32(value), PCI_IOBASE + addr); ~~~~~~~~~~ ^ include/asm-generic/io.h:743:2: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] insb(addr, buffer, count); ^~~~~~~~~~~~~~~~~~~~~~~~~ arch/riscv/include/asm/io.h:104:53: note: expanded from macro 'insb' #define insb(addr, buffer, count) __insb(PCI_IOBASE + (addr), buffer, count) ~~~~~~~~~~ ^ In file included from mm/page_reporting.c:4: In file included from include/linux/page_reporting.h:6: In file included from include/linux/scatterlist.h:9: In file included from arch/riscv/include/asm/io.h:136: include/asm-generic/io.h:751:2: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] insw(addr, buffer, count); ^~~~~~~~~~~~~~~~~~~~~~~~~ arch/riscv/include/asm/io.h:105:53: note: expanded from macro 'insw' #define insw(addr, buffer, count) __insw(PCI_IOBASE + (addr), buffer, count) ~~~~~~~~~~ ^ In file included from mm/page_reporting.c:4: In file included from include/linux/page_reporting.h:6: In file included from include/linux/scatterlist.h:9: In file included from arch/riscv/include/asm/io.h:136: include/asm-generic/io.h:759:2: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] insl(addr, buffer, count); ^~~~~~~~~~~~~~~~~~~~~~~~~ arch/riscv/include/asm/io.h:106:53: note: expanded from macro 'insl' #define insl(addr, buffer, count) __insl(PCI_IOBASE + (addr), buffer, count) ~~~~~~~~~~ ^ In file included from mm/page_reporting.c:4: In file included from include/linux/page_reporting.h:6: In file included from include/linux/scatterlist.h:9: In file included from arch/riscv/include/asm/io.h:136: include/asm-generic/io.h:768:2: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] outsb(addr, buffer, count); ^~~~~~~~~~~~~~~~~~~~~~~~~~ arch/riscv/include/asm/io.h:118:55: note: expanded from macro 'outsb' #define outsb(addr, buffer, count) __outsb(PCI_IOBASE + (addr), buffer, count) ~~~~~~~~~~ ^ In file included from mm/page_reporting.c:4: In file included from include/linux/page_reporting.h:6: In file included from include/linux/scatterlist.h:9: In file included from arch/riscv/include/asm/io.h:136: include/asm-generic/io.h:777:2: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] outsw(addr, buffer, count); ^~~~~~~~~~~~~~~~~~~~~~~~~~ arch/riscv/include/asm/io.h:119:55: note: expanded from macro 'outsw' #define outsw(addr, buffer, count) __outsw(PCI_IOBASE + (addr), buffer, count) ~~~~~~~~~~ ^ In file included from mm/page_reporting.c:4: In file included from include/linux/page_reporting.h:6: In file included from include/linux/scatterlist.h:9: In file included from arch/riscv/include/asm/io.h:136: include/asm-generic/io.h:786:2: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] outsl(addr, buffer, count); ^~~~~~~~~~~~~~~~~~~~~~~~~~ arch/riscv/include/asm/io.h:120:55: note: expanded from macro 'outsl' #define outsl(addr, buffer, count) __outsl(PCI_IOBASE + (addr), buffer, count) ~~~~~~~~~~ ^ In file included from mm/page_reporting.c:4: In file included from include/linux/page_reporting.h:6: In file included from include/linux/scatterlist.h:9: In file included from arch/riscv/include/asm/io.h:136: include/asm-generic/io.h:1134:55: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] return (port > MMIO_UPPER_LIMIT) ? NULL : PCI_IOBASE + port; ~~~~~~~~~~ ^ >> mm/page_reporting.c:360:5: error: member reference base type 'unsigned int' is not a structure or union lockdep_is_held(&page_reporting_order))) { ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/lockdep.h:286:52: note: expanded from macro 'lockdep_is_held' #define lockdep_is_held(lock) lock_is_held(&(lock)->dep_map) ^ ~~~~~~~ include/linux/rcupdate.h:664:54: note: expanded from macro 'rcu_dereference_protected' __rcu_dereference_protected((p), __UNIQUE_ID(rcu), (c), __rcu) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~ include/linux/rcupdate.h:460:21: note: expanded from macro '__rcu_dereference_protected' RCU_LOCKDEP_WARN(!(c), "suspicious rcu_dereference_protected() usage"); \ ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/rcupdate.h:409:52: note: expanded from macro 'RCU_LOCKDEP_WARN' #define RCU_LOCKDEP_WARN(c, s) do { } while (0 && (c)) ^ 13 warnings and 1 error generated. vim +360 mm/page_reporting.c 351 352 int page_reporting_register(struct page_reporting_dev_info *prdev) 353 { 354 int err = 0; 355 356 mutex_lock(&page_reporting_mutex); 357 358 /* nothing to do if already in use */ 359 if (rcu_dereference_protected(pr_dev_info, > 360 lockdep_is_held(&page_reporting_order))) { 361 err = -EBUSY; 362 goto err_out; 363 } 364 365 /* 366 * If the page_reporting_order value is not set, we check if 367 * an order is provided from the driver that is performing the 368 * registration. If that is not provided either, we default to 369 * pageblock_order. 370 */ 371 372 if (page_reporting_order == -1) { 373 if (prdev->order > 0 && prdev->order <= MAX_ORDER) 374 page_reporting_order = prdev->order; 375 else 376 page_reporting_order = pageblock_order; 377 } 378 379 /* initialize state and work structures */ 380 atomic_set(&prdev->state, PAGE_REPORTING_IDLE); 381 INIT_DELAYED_WORK(&prdev->work, &page_reporting_process); 382 383 /* Begin initial flush of zones */ 384 __page_reporting_request(prdev); 385 386 /* Assign device to allow notifications */ 387 rcu_assign_pointer(pr_dev_info, prdev); 388 389 /* enable page reporting notification */ 390 if (!static_key_enabled(&page_reporting_enabled)) { 391 static_branch_enable(&page_reporting_enabled); 392 pr_info("Free page reporting enabled\n"); 393 } 394 err_out: 395 mutex_unlock(&page_reporting_mutex); 396 397 return err; 398 } 399 EXPORT_SYMBOL_GPL(page_reporting_register); 400
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))) { err = -EBUSY; goto err_out; } @@ -401,7 +402,8 @@ void page_reporting_unregister(struct page_reporting_dev_info *prdev) { mutex_lock(&page_reporting_mutex); - if (rcu_access_pointer(pr_dev_info) == prdev) { + if (prdev == rcu_dereference_protected(pr_dev_info, + lockdep_is_held(&page_reporting_mutex))) { /* Disable page reporting notification */ RCU_INIT_POINTER(pr_dev_info, NULL); synchronize_rcu();