From mboxrd@z Thu Jan 1 00:00:00 1970 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 EF66FCFB442 for ; Mon, 7 Oct 2024 05:07:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2ACF86B0103; Mon, 7 Oct 2024 01:07:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 25D476B0104; Mon, 7 Oct 2024 01:07:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1240A6B0105; Mon, 7 Oct 2024 01:07:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id EB7D86B0103 for ; Mon, 7 Oct 2024 01:07:35 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 6266C40A94 for ; Mon, 7 Oct 2024 05:07:35 +0000 (UTC) X-FDA: 82645623270.20.BB15819 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.8]) by imf20.hostedemail.com (Postfix) with ESMTP id 5C8E51C000F for ; Mon, 7 Oct 2024 05:07:32 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b="c/q4VOMl"; spf=pass (imf20.hostedemail.com: domain of lkp@intel.com designates 192.198.163.8 as permitted sender) smtp.mailfrom=lkp@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1728277585; 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-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=aLF97olaCpFiJoz1BUsDa8ldnBPtfuhuEpMdxqeJDdU=; b=6AHDYz8Wqv8uhrOzHkn0kB78ew36U0ZZWLgi7F1euXk0K58iE4O64Oy+kzi3XrYwYl0iHR 46+5vn/kvi3OGL3PZ6fUS2bIo9YX+Ivow/7k7ND6dCX3LYnUU9C2N8sLk6/y1YicbOLMZ1 MQkUVchgD1oJmNt2DKnY2ArvhRcPUbY= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b="c/q4VOMl"; spf=pass (imf20.hostedemail.com: domain of lkp@intel.com designates 192.198.163.8 as permitted sender) smtp.mailfrom=lkp@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1728277585; a=rsa-sha256; cv=none; b=v1AGXJ6WR9k4Pifceq24D/exl4cgeCLWTZ7bsRNLPb4jXUOVLVRqn8T4LglMzElYgp71JA TgXVXgA40KHIOpep0jjkLOGjOFrQ9NwhVftSbsDgvmtfwp2GVEGSOC/G8Ceo2oFRHWWlE3 apxc0ftMMLeyl7UwIujsdWKo6am6vyg= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1728277652; x=1759813652; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=ilDL4Wcf6Tmyau30miOiykib5wiV9EZuzRqaVlwzhV4=; b=c/q4VOMlbQy1ztUZFhi/34L8rP3yHMYZSnd5a+sFMCLQ6sAT3eEXjryX KVut41PostKlAu7UrXREfz/TyB6HL8DPtyd3Rbotq/WGn23hiz9dzpKhQ PRnDE/yjGMp9aRfQRsU8Ni9/7ao5nM7RE3LWbn9M36wbRAtiWFrMc9ERY Sv63x0xiuOhYmjVDBY8G8C9EXIsydjyGkvWnipINgsEELe3seT4A0IYUA 0nwskulsa/cBr00jgQF60kA6oOggfCTqqwZmQ7oEI7Qwm0APU7KwlgNei tF0XfS11teswiLUx15wJStM+8cOWdWpAftGK8cU3E0hHevviqbbjdmV5F w==; X-CSE-ConnectionGUID: Iw5Gzb6KQmKn5K9KgAXWKQ== X-CSE-MsgGUID: xevU2CiHQXeoX5onoJVUMw== X-IronPort-AV: E=McAfee;i="6700,10204,11217"; a="44942194" X-IronPort-AV: E=Sophos;i="6.11,183,1725346800"; d="scan'208";a="44942194" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Oct 2024 22:07:30 -0700 X-CSE-ConnectionGUID: uTqtuvXcQ6KhVHe04r9JeQ== X-CSE-MsgGUID: RgTsME9jRz6qcgPmhnnDXQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,183,1725346800"; d="scan'208";a="79941926" Received: from lkp-server01.sh.intel.com (HELO a48cf1aa22e8) ([10.239.97.150]) by fmviesa004.fm.intel.com with ESMTP; 06 Oct 2024 22:07:28 -0700 Received: from kbuild by a48cf1aa22e8 with local (Exim 4.96) (envelope-from ) id 1sxfxu-0004bq-1J; Mon, 07 Oct 2024 05:07:26 +0000 Date: Mon, 7 Oct 2024 13:06:49 +0800 From: kernel test robot To: Jeongjun Park , akpm@linux-foundation.org Cc: llvm@lists.linux.dev, oe-kbuild-all@lists.linux.dev, kasong@tencent.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, syzbot+fa43f1b63e3aa6f66329@syzkaller.appspotmail.com, Jeongjun Park Subject: Re: [PATCH] mm: swap: prevent possible data-race in __try_to_reclaim_swap Message-ID: <202410071223.t0yF8vP8-lkp@intel.com> References: <20241004142504.4379-1-aha310510@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20241004142504.4379-1-aha310510@gmail.com> X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 5C8E51C000F X-Stat-Signature: dtx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jYAjtr6cqg966G5tKboY8OCwWlsxr7EFHMQqfM34r2OpfQYq9Iq1gZ0jSdLo/mfWAxDhOfsyeNQE2zKsxcOd5kTdKbKN+g7iWLcN47EdjTecN2slAAFAYEuKBZreqfZUYk9YzTP4ecoaHvx+j4Wy83S1aQ365Yto6uU2PXwIWooHSFDqIKdbIHrCUeEGXS5TI+qdVGIg2fYvR30QcnSWlRmGPWFfZm5A+MHPWX+JfsvNJ7ZmSJ6SEp19QoxJ02co5MgbHUILytN69rNuCpUV+5JgPE/PYiNIDVHfQwhjC8vMONOHpBmPhoLNJiXx/F4XrHXVwzd/rOBXTx7vmavp7TvXMZakrOv3OKr+VJ0Wjd8nkIhXs5IXAElf56PpH0CMlHSW3SwhyzamvbP6UTzHhX1touVI/tphnHye41iLEPSwyJtRq9W24Zd/VU36clFef5Mzi6IjdckeikjSJIc88KQBtZamAAMpx4Rw== 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: List-Subscribe: List-Unsubscribe: Hi Jeongjun, kernel test robot noticed the following build warnings: [auto build test WARNING on akpm-mm/mm-everything] url: https://github.com/intel-lab-lkp/linux/commits/Jeongjun-Park/mm-swap-prevent-possible-data-race-in-__try_to_reclaim_swap/20241004-222733 base: https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything patch link: https://lore.kernel.org/r/20241004142504.4379-1-aha310510%40gmail.com patch subject: [PATCH] mm: swap: prevent possible data-race in __try_to_reclaim_swap config: x86_64-kexec (https://download.01.org/0day-ci/archive/20241007/202410071223.t0yF8vP8-lkp@intel.com/config) compiler: clang version 18.1.8 (https://github.com/llvm/llvm-project 3b5b5c1ec4a3095ab096dd780e84d7ab81f3d7ff) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241007/202410071223.t0yF8vP8-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot | Closes: https://lore.kernel.org/oe-kbuild-all/202410071223.t0yF8vP8-lkp@intel.com/ All warnings (new ones prefixed by >>): >> mm/swapfile.c:203:6: warning: variable 'ret' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized] 203 | if (!folio_trylock(folio)) | ^~~~~~~~~~~~~~~~~~~~~ mm/swapfile.c:254:9: note: uninitialized use occurs here 254 | return ret; | ^~~ mm/swapfile.c:203:2: note: remove the 'if' if its condition is always false 203 | if (!folio_trylock(folio)) | ^~~~~~~~~~~~~~~~~~~~~~~~~~ 204 | goto out; | ~~~~~~~~ mm/swapfile.c:190:9: note: initialize the variable 'ret' to silence this warning 190 | int ret, nr_pages; | ^ | = 0 1 warning generated. vim +203 mm/swapfile.c bea67dcc5eea0f Barry Song 2024-08-08 177 a62fb92ac12ed3 Ryan Roberts 2024-04-08 178 /* a62fb92ac12ed3 Ryan Roberts 2024-04-08 179 * returns number of pages in the folio that backs the swap entry. If positive, a62fb92ac12ed3 Ryan Roberts 2024-04-08 180 * the folio was reclaimed. If negative, the folio was not reclaimed. If 0, no a62fb92ac12ed3 Ryan Roberts 2024-04-08 181 * folio was associated with the swap entry. a62fb92ac12ed3 Ryan Roberts 2024-04-08 182 */ bcd49e86710b42 Huang Ying 2018-10-26 183 static int __try_to_reclaim_swap(struct swap_info_struct *si, bcd49e86710b42 Huang Ying 2018-10-26 184 unsigned long offset, unsigned long flags) c9e444103b5e7a KAMEZAWA Hiroyuki 2009-06-16 185 { efa90a981bbc89 Hugh Dickins 2009-12-14 186 swp_entry_t entry = swp_entry(si->type, offset); 862590ac3708e1 Kairui Song 2024-07-30 187 struct address_space *address_space = swap_address_space(entry); 862590ac3708e1 Kairui Song 2024-07-30 188 struct swap_cluster_info *ci; 2c3f6194b008b2 Matthew Wilcox (Oracle 2022-09-02 189) struct folio *folio; 862590ac3708e1 Kairui Song 2024-07-30 190 int ret, nr_pages; 862590ac3708e1 Kairui Song 2024-07-30 191 bool need_reclaim; c9e444103b5e7a KAMEZAWA Hiroyuki 2009-06-16 192 862590ac3708e1 Kairui Song 2024-07-30 193 folio = filemap_get_folio(address_space, swap_cache_index(entry)); 66dabbb65d673a Christoph Hellwig 2023-03-07 194 if (IS_ERR(folio)) c9e444103b5e7a KAMEZAWA Hiroyuki 2009-06-16 195 return 0; c9e444103b5e7a KAMEZAWA Hiroyuki 2009-06-16 196 /* bcd49e86710b42 Huang Ying 2018-10-26 197 * When this function is called from scan_swap_map_slots() and it's 2c3f6194b008b2 Matthew Wilcox (Oracle 2022-09-02 198) * called by vmscan.c at reclaiming folios. So we hold a folio lock bcd49e86710b42 Huang Ying 2018-10-26 199 * here. We have to use trylock for avoiding deadlock. This is a special 2c3f6194b008b2 Matthew Wilcox (Oracle 2022-09-02 200) * case and you should use folio_free_swap() with explicit folio_lock() c9e444103b5e7a KAMEZAWA Hiroyuki 2009-06-16 201 * in usual operations. c9e444103b5e7a KAMEZAWA Hiroyuki 2009-06-16 202 */ 862590ac3708e1 Kairui Song 2024-07-30 @203 if (!folio_trylock(folio)) 862590ac3708e1 Kairui Song 2024-07-30 204 goto out; 862590ac3708e1 Kairui Song 2024-07-30 205 b2dbc30a2a909d Jeongjun Park 2024-10-04 206 /* offset could point to the middle of a large folio */ b2dbc30a2a909d Jeongjun Park 2024-10-04 207 entry = folio->swap; b2dbc30a2a909d Jeongjun Park 2024-10-04 208 offset = swp_offset(entry); b2dbc30a2a909d Jeongjun Park 2024-10-04 209 nr_pages = folio_nr_pages(folio); b2dbc30a2a909d Jeongjun Park 2024-10-04 210 ret = -nr_pages; b2dbc30a2a909d Jeongjun Park 2024-10-04 211 862590ac3708e1 Kairui Song 2024-07-30 212 need_reclaim = ((flags & TTRS_ANYWAY) || 2c3f6194b008b2 Matthew Wilcox (Oracle 2022-09-02 213) ((flags & TTRS_UNMAPPED) && !folio_mapped(folio)) || 862590ac3708e1 Kairui Song 2024-07-30 214 ((flags & TTRS_FULL) && mem_cgroup_swap_full(folio))); 862590ac3708e1 Kairui Song 2024-07-30 215 if (!need_reclaim || !folio_swapcache_freeable(folio)) 862590ac3708e1 Kairui Song 2024-07-30 216 goto out_unlock; 862590ac3708e1 Kairui Song 2024-07-30 217 862590ac3708e1 Kairui Song 2024-07-30 218 /* 862590ac3708e1 Kairui Song 2024-07-30 219 * It's safe to delete the folio from swap cache only if the folio's 862590ac3708e1 Kairui Song 2024-07-30 220 * swap_map is HAS_CACHE only, which means the slots have no page table 862590ac3708e1 Kairui Song 2024-07-30 221 * reference or pending writeback, and can't be allocated to others. 862590ac3708e1 Kairui Song 2024-07-30 222 */ 862590ac3708e1 Kairui Song 2024-07-30 223 ci = lock_cluster_or_swap_info(si, offset); 862590ac3708e1 Kairui Song 2024-07-30 224 need_reclaim = swap_is_has_cache(si, offset, nr_pages); 862590ac3708e1 Kairui Song 2024-07-30 225 unlock_cluster_or_swap_info(si, ci); 862590ac3708e1 Kairui Song 2024-07-30 226 if (!need_reclaim) 862590ac3708e1 Kairui Song 2024-07-30 227 goto out_unlock; 862590ac3708e1 Kairui Song 2024-07-30 228 862590ac3708e1 Kairui Song 2024-07-30 229 if (!(flags & TTRS_DIRECT)) { 862590ac3708e1 Kairui Song 2024-07-30 230 /* Free through slot cache */ 862590ac3708e1 Kairui Song 2024-07-30 231 delete_from_swap_cache(folio); 862590ac3708e1 Kairui Song 2024-07-30 232 folio_set_dirty(folio); 862590ac3708e1 Kairui Song 2024-07-30 233 ret = nr_pages; 862590ac3708e1 Kairui Song 2024-07-30 234 goto out_unlock; c9e444103b5e7a KAMEZAWA Hiroyuki 2009-06-16 235 } 862590ac3708e1 Kairui Song 2024-07-30 236 862590ac3708e1 Kairui Song 2024-07-30 237 xa_lock_irq(&address_space->i_pages); 862590ac3708e1 Kairui Song 2024-07-30 238 __delete_from_swap_cache(folio, entry, NULL); 862590ac3708e1 Kairui Song 2024-07-30 239 xa_unlock_irq(&address_space->i_pages); 862590ac3708e1 Kairui Song 2024-07-30 240 folio_ref_sub(folio, nr_pages); 862590ac3708e1 Kairui Song 2024-07-30 241 folio_set_dirty(folio); 862590ac3708e1 Kairui Song 2024-07-30 242 862590ac3708e1 Kairui Song 2024-07-30 243 spin_lock(&si->lock); 862590ac3708e1 Kairui Song 2024-07-30 244 /* Only sinple page folio can be backed by zswap */ 862590ac3708e1 Kairui Song 2024-07-30 245 if (nr_pages == 1) 862590ac3708e1 Kairui Song 2024-07-30 246 zswap_invalidate(entry); 862590ac3708e1 Kairui Song 2024-07-30 247 swap_entry_range_free(si, entry, nr_pages); 862590ac3708e1 Kairui Song 2024-07-30 248 spin_unlock(&si->lock); 862590ac3708e1 Kairui Song 2024-07-30 249 ret = nr_pages; 862590ac3708e1 Kairui Song 2024-07-30 250 out_unlock: 862590ac3708e1 Kairui Song 2024-07-30 251 folio_unlock(folio); 862590ac3708e1 Kairui Song 2024-07-30 252 out: 2c3f6194b008b2 Matthew Wilcox (Oracle 2022-09-02 253) folio_put(folio); c9e444103b5e7a KAMEZAWA Hiroyuki 2009-06-16 254 return ret; c9e444103b5e7a KAMEZAWA Hiroyuki 2009-06-16 255 } 355cfa73ddff2f KAMEZAWA Hiroyuki 2009-06-16 256 -- 0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki