From patchwork Fri Sep 6 03:11:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dennis Zhou X-Patchwork-Id: 13793176 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 D6CAFCE7AA6 for ; Fri, 6 Sep 2024 03:11:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5248C6B0095; Thu, 5 Sep 2024 23:11:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4D5566B0098; Thu, 5 Sep 2024 23:11:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 39ADD6B0099; Thu, 5 Sep 2024 23:11:58 -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 1BF836B0095 for ; Thu, 5 Sep 2024 23:11:58 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 8818D1204A2 for ; Fri, 6 Sep 2024 03:11:57 +0000 (UTC) X-FDA: 82532839074.22.2185E1E Received: from mail-ot1-f53.google.com (mail-ot1-f53.google.com [209.85.210.53]) by imf26.hostedemail.com (Postfix) with ESMTP id D232214000B for ; Fri, 6 Sep 2024 03:11:55 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=none; spf=pass (imf26.hostedemail.com: domain of dennisszhou@gmail.com designates 209.85.210.53 as permitted sender) smtp.mailfrom=dennisszhou@gmail.com; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=kernel.org (policy=quarantine) ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1725592217; 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; bh=vHWxSRmAIq5y+t+Bsnw0e3+Xv51/57FXG9eUtKPq2dg=; b=IlH6h5WQZRXrKGNGimoBX9wpILzwJbPObcbel4UeapIBjWBFcOSg4gTVAhODHO5LkXP5nk MHSsl5GA+qXiyPCb655wiEoJMv8zLTHO9LII4HYcv33RcEKxrkaw6XxchgtDKaZInz5/wQ nyIoN4IM28R0S2FvwU7DtrT+Dc+FXVo= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725592217; a=rsa-sha256; cv=none; b=E8lTcZwA7fkp8tE99kC8geyQN5shLR5QoQnBOZvDyat6AI+OvcxO+FcnF0VKfX3SCszKGg 5VXDU1bnQbcng/9ABqHIJixsQoPlAFzwEqUCeINimv9c5O1pcwKvcDq9GSNW+hdzQPqbP2 KQ6vAR2iMsYRSV7AH/uqAZk8/EFUo20= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=none; spf=pass (imf26.hostedemail.com: domain of dennisszhou@gmail.com designates 209.85.210.53 as permitted sender) smtp.mailfrom=dennisszhou@gmail.com; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=kernel.org (policy=quarantine) Received: by mail-ot1-f53.google.com with SMTP id 46e09a7af769-70f6e65d605so927183a34.3 for ; Thu, 05 Sep 2024 20:11:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725592315; x=1726197115; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=vHWxSRmAIq5y+t+Bsnw0e3+Xv51/57FXG9eUtKPq2dg=; b=FLgt0Wmhx/fg54VknmaxPDlCpFDal8Mi1LQ1n+n0E5i+rQeXgMwb+1F58HACLpIy8j dCl5YhXHCpsMS3w0FvR79xCmfEtXSfA/TU615LPuAd2pXmpLOpzBZ9CYXgdH/LcmkL/7 RpDI3HekY0SWRG1ers71vNl46GCVvTFOYGRBFSimHdNOyeeI1oL4YX0S06gQUtZ2KgCi WrjBp5rneYwb+kF+lDHe7XjGiy2E/+HTiEE2dvwVrkkZHdcK2JGU97Mp6h7RzSad5ef7 ljt9p19648XbSlwL/PgEOVajFledduKAAXIt4BiKhQnZ+VL2lk9y4Cb+gEVSp1HX7REA rKWw== X-Gm-Message-State: AOJu0Yz4xxBxpQQ5j68MX2P7yevSU2S0zowmrzHzZNMxi0MTrq6Ziq9k 84aNkJvcbJvYJSpx9ngfMesXPMOjn49YvCedx+lffIaZWjLldQkw X-Google-Smtp-Source: AGHT+IGiIJOqPOM3+WDLMgLiBuKcw5W6p2Wxvkgw77bXyGx4kYgLOl7X9U6U2rRwJoGlwAqNa/wNNA== X-Received: by 2002:a05:6830:61c3:b0:709:3585:fd7e with SMTP id 46e09a7af769-70f5c3d48e5mr31144675a34.12.1725592314754; Thu, 05 Sep 2024 20:11:54 -0700 (PDT) Received: from snowbird.attlocal.net ([2600:1700:7c10:db60:551c:dde1:25ee:9a04]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7d4fbd84e73sm3425244a12.11.2024.09.05.20.11.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Sep 2024 20:11:54 -0700 (PDT) From: Dennis Zhou To: Tejun Heo , Christoph Lameter Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Dennis Zhou , kernel test robot Subject: [PATCH] percpu: fix data race with pcpu_nr_empty_pop_pages Date: Thu, 5 Sep 2024 20:11:51 -0700 Message-ID: <20240906031151.80719-1-dennis@kernel.org> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-Stat-Signature: 4z1m1ewq5qimsg3sxqzqkjz8faipk7d9 X-Rspamd-Pre-Result: action=add header; module=dmarc; Action set by DMARC X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Wgfgq5Vpteb+72lM8bRbqKG43nWj2g5c2Or8QToPYat75Wtyz1I6+4HVt3cRA+l+FACRv0+pli6oPnqgrjtkPdSYvS0yShiidlXtZo846cOIvYXqz+H6jeGXT1iR1yWd9vfgZCTHQrXzO5hJrrcM8qOzKY4q+VyH40NCyU8Up2cWE/RPU00w8yZx/hza0xl+aw0G8zcaGkvvitlrvJ4SrS4Ky86bzKBLbDAwkOt1ARyZWJUe04/daHC53Q5XFq2Uz428C1xcduazIshqzAXh69hzON+Zm4+RVNqtKB4pBxnUjk0F/xsYwFy2R3Cer1EQVFkVDxfurkQqmbdDM1kD1XHuCin4FFrLLE7q2MHgOB7DErFhu2UkS0q6Ghm9hs7sBsXk1zBh8OhyciPQ5j4bBDdPAO+KNR4Il4QbWImWlenVGsEdQtJqAF2tn33sOuksIRY8MOzIC3oa16sP90EHWnndmOFK247+7ReseNVkcPv4pUOTtuvzYN7bD1YFgt4m X-Bogosity: Ham, tests=bogofilter, spamicity=0.000606, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Fixes the data race by moving the read to be behind the pcpu_lock. This is okay because the code (initially) above it will not increase the empty populated page count because it is populating backing pages that already have allocations served out of them. Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-lkp/202407191651.f24e499d-oliver.sang@intel.com Signed-off-by: Dennis Zhou --- mm/percpu.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/mm/percpu.c b/mm/percpu.c index 20d91af8c033..325fb8412e90 100644 --- a/mm/percpu.c +++ b/mm/percpu.c @@ -1864,6 +1864,10 @@ void __percpu *pcpu_alloc_noprof(size_t size, size_t align, bool reserved, area_found: pcpu_stats_area_alloc(chunk, size); + + if (pcpu_nr_empty_pop_pages < PCPU_EMPTY_POP_PAGES_LOW) + pcpu_schedule_balance_work(); + spin_unlock_irqrestore(&pcpu_lock, flags); /* populate if not all pages are already there */ @@ -1891,9 +1895,6 @@ void __percpu *pcpu_alloc_noprof(size_t size, size_t align, bool reserved, mutex_unlock(&pcpu_alloc_mutex); } - if (pcpu_nr_empty_pop_pages < PCPU_EMPTY_POP_PAGES_LOW) - pcpu_schedule_balance_work(); - /* clear the areas and return address relative to base address */ for_each_possible_cpu(cpu) memset((void *)pcpu_chunk_addr(chunk, cpu, 0) + off, 0, size);