From patchwork Tue Oct 8 00:19:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dennis Zhou X-Patchwork-Id: 13895539 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 DCF14E7716D for ; Thu, 5 Dec 2024 15:21:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B94A16B00B6; Thu, 5 Dec 2024 10:19:14 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 79FAC6B00BF; Thu, 5 Dec 2024 10:19:13 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 50A856B00D3; Thu, 5 Dec 2024 10:19:10 -0500 (EST) 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 4CCFD6B007B for ; Mon, 7 Oct 2024 20:19:51 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 3D7BF1A06D9 for ; Tue, 8 Oct 2024 00:19:50 +0000 (UTC) X-FDA: 82648526940.17.7339F15 Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) by imf06.hostedemail.com (Postfix) with ESMTP id 1AFAD180009 for ; Tue, 8 Oct 2024 00:19:48 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=none; spf=pass (imf06.hostedemail.com: domain of dennisszhou@gmail.com designates 209.85.214.174 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=1728346654; 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=OZOjUAMjE+z7ARKhidfYBi130Fhv93GEGFcCmmtZl0+CPVTYz89zwl+QBhCFCRDucM9uIF 2fJsgnqpcOXx+XZ8mqWSduiM47kusAN4zxUwcbVTojUaOgt2FwEsHZGfGggU3wJNe0J8ec 5t3fq0QRB/wdaCbbho86bTYcyDzfPKg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1728346654; a=rsa-sha256; cv=none; b=ixRqqSpmo+/WQuZc+gua9dmD0z/NEQG+s5yMAJsUuLG/RMJBsmAUXdBDo5NKcPxHxoiIvy TnF1ky6QS1NYaHKlr9UDuTawElEMHvDCB/C+37tbN2aOXBr0PicSOkBKg3ot/WClwEWH0+ LkAlzI5EKAUbkG20xnLy/L0rNICgw3M= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=none; spf=pass (imf06.hostedemail.com: domain of dennisszhou@gmail.com designates 209.85.214.174 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-pl1-f174.google.com with SMTP id d9443c01a7336-20b84bfbdfcso39239775ad.0 for ; Mon, 07 Oct 2024 17:19:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728346788; x=1728951588; 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=FM1kJoSv+s2kOKxqqEa3h+fKE1HiwcmCbsxjG3M0SlAN/RxEhu2SByKm5HBmlH8z/O IoKyBT1lXgLULps30wFgZQT3qOvtu2oAsb8fkZJe41tdaiZYYvN3R0JehCxLQwzonaVu +2WAo7Ci9qgeKuL6xpOHXHsBKdFe2JzxWtC0+8KCHxjlgXSECS01clVSOXKKBmpxpQHy YSg14EinZi6A87b4dgi1PLprT+tlS/gKKNT/OTMiYM05hvr+1gVHnTfMo8WgFgp7GAAa seVrZCUnEvNQeQ6Dqc1NXuHAiSYHDVQGU8I3XbIsItYjOM3bc2DGBf1Eno+HS4T4ican wE+w== X-Forwarded-Encrypted: i=1; AJvYcCUxgtvE4HttpJnW4oi3IY9Ux4SWbwfWecDZ8ZeS2QMkxAsm6Q45EnN6/vYmeNbpSP/NUP6e9ekDyw==@kvack.org X-Gm-Message-State: AOJu0Yww+8lswA+gaeQhZcJF2QYW973k7rRsnpur5l6eMgV63siKtm06 fgYjDpe7UYpKMmZgnkR+mKNiyOKjayZOUlOGCsgZJShCIzYrD4CenAcfyw== X-Google-Smtp-Source: AGHT+IGEPV+q46O9fac0wxKhozafa0XGsZakH4+zUnU4jeFRpYv1WrbIiCUsH2PPprfZ0/21whVgTA== X-Received: by 2002:a17:902:e745:b0:20b:6c1e:1e13 with SMTP id d9443c01a7336-20c4e357c4dmr22343035ad.23.1728346787792; Mon, 07 Oct 2024 17:19:47 -0700 (PDT) Received: from snowbird.robot.car ([199.73.127.3]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7e9f6821508sm5635942a12.31.2024.10.07.17.19.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Oct 2024 17:19:47 -0700 (PDT) From: Dennis Zhou To: Andrew Morton Cc: Tejun Heo , Christoph Lameter , 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: Mon, 7 Oct 2024 17:19:42 -0700 Message-ID: <20241008001942.8114-1-dennis@kernel.org> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-Stat-Signature: qb5y9ymhjwnx1eo1ooc1checkj9z7d4f X-Rspamd-Pre-Result: action=add header; module=dmarc; Action set by DMARC X-Rspamd-Queue-Id: 1AFAD180009 X-Rspam-User: X-Rspamd-Server: rspam08 X-Rspam: Yes X-HE-Tag: 1728346788-270600 X-HE-Meta: U2FsdGVkX1+bnM7BQOkue3YjvTVUA6NiY4hOFOhVlnUWp9+lTi6bjQlnvCfueTdIOiGzsfoJfNMre5GN2vU9YSUoLGLSF6MmAYWS20mtETUx+zeiFeSbtesdhG5N0vy13ABH8i5p+4q3BbPRG0IgECa+YWoiWOIoH9s+rxGrCNV5WAQJJrhxc2/YkCzHeWzG2615+0IynuMwHesfX64Q/pgUpVsZqtTIcK6oTp7cob0Ul0Jcrwjf6B/CBmwyHmlGOWdIJTKX3FarKUS4KN4fkNcpuyAFrxlYahp1vW+Uw/uwJtigL4rQcBEiQGq7V8MuP3jIomt2DCRZEGDoukhY9njJsFjXyVRWajg3zyo3HyS8Q5GCDqR/xx4Aky+zESpLaqcH1CTZ482w7zDZGXz+xUksGxL2qOd8qzjHId1cZQCzFh+Ufm8bgdP2VCB5fEhkVCy0EKYMGjAlceEo3bIg6E0NCd+Tc8Bbbz/kF7o9XR1l5Y8q/+ZYSgmYIB8cMw/Eq0F//rS1fpHtlhO6+5fYQqabjQm40Lez8AjbRXd9qZQeznEEpk3Pcd8tNVsY+GVl+uCbDDeYFlxoqmyWH5GHPA8BBt8DQ3+ELaOEP05PG5BRVKYDWJltTYsjOiW+rFYmihVXJMOiSW8hNU5l8BuBZYQXfo/epG/7+ErlRXj3FAIcr9yprTRFdU/9hbL/aow25yEmodnp/WKz9pJLCXFUo10gORO396Mf3EHoxi3Nt/nzaxBDZ2464AGr6EsI8EOidxCptUuKti0QWLMnw1g2FAFktpQF5YIcfsDTAfLd/YslS9U/c/lFh99mpfork02E+YvEn4GgG2jqayNW4NVDgAf02IWbLyl8wA6vfeI4BRynMhM5oBXEpmDmHyEpOAR8YWSr1cG4JoRyMQCctZqKjCteh56jpabB8nKpDtEn/IWddIyVoB8JVMFnd0JJ9ZelKfp+0RqsNJFexvAKT55 GcQOSZqm Db486xYJ8j+TLrPmrzZBLawdgJ5+7o9qUDvwYKcMtKCVEKoAGf+s+9wd3H9yAKD4pk1MW0AiBl0kD+8J/xIsWgbycwYHUHSTjjV+KfiG6B2ThhH544zXvZEc92mEKphqyWanHa3cssX5JQA6+RdjRhGXuAgxm83UyZImflHBEtDqpuxLBo3/Z5e1E6ABpIOowKhvmTmpirJ+ZRShk9mwxXrTL4XGcrT3T0YIf3aZtfCCgt0oqZ3Jx+IFd99dxD+O+d3v8vB5WFNg2ISbtTuH9LhpSg1cj3WxGmdzbCYLBwS6EXH4jlWwEnesiaLUTrR6/PAxhfOPgrdExNOWLk+4mc7Me95zE3IhO7sPmV6G/XJAhEe/vQyzWT8fQGXX+pihXEGgmr0eUFwcvuFqbnC+pw5Q2CrMEXSF/aUMfYNAGvfAcA1WEioflWbc1Fs2m7F8mKPn3VCHObwJB7O8OaC9h+5RBEg== 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: 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);