Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp6131944ybv; Wed, 12 Feb 2020 06:36:05 -0800 (PST) X-Google-Smtp-Source: APXvYqzdfoJXp2kgwTxiydeb1uiNmwoZU7SCBlJZkfXzmBB5t4M70vV6hQ6gDHv0JDciRMF2xZia X-Received: by 2002:aca:b70a:: with SMTP id h10mr6707864oif.20.1581518165323; Wed, 12 Feb 2020 06:36:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581518165; cv=none; d=google.com; s=arc-20160816; b=McIKZFQvVccgJp0caofzLSNhBtsl+1xxBLNd4xwv81ynaUaW1cib5OMhvSeLt7ss19 bhqoqZ8kBbSpweZhst4e4J7x7MZSrZexe39eNKd1W4gWNjwc1xqJgaW5Gzh+Jth04aAg 68Ox1NxQhn3bLtYC1fKfR8jfaBI2BzM3NiSfzY/9YSUZiIvYqZdXlkw1qoCtHyRpFFUf 5efKg+mYinj5XC1RgTkl5YFPfAWRNRizriIuEhePLoAdm/UlAugRqtldgGjHiU+I730z lYTJweXJNDgRockD3yDAU0ObY5tLEe8dVAnHR8MPaO+2g3s1ik8wBak//9FKVQupAXb6 6kTw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=5H+ytVXAlSIDd672XrGaeP1xTzQC9Kh/R6V2+KHWLTY=; b=Su4fmFn+1H39H9fzYZg3RjqfJEJS0YQgMAoOGYzYYs1fIE9kroZSJUeJdgcW/B6NOU TWyH4SGivtlc0aRSOA+3sjeSyIuwoj6M6tLD7wI06uaP08eCVz5M12DcsAwJEEJ4hKuc 4YfBLQL37MixifZNKPr9nGgDjtX2RTJayJvZYE+xJ2Mrs4vdDIFQsyMpUkYZM3Ys1B2v +GTBYZiF3UgAi8w4NgHTyWDcFpXezgSMO6jqQYCo0smMspuGgSnFANy2oa8DRXHDtskQ Zbs72G+hlpo66HUWdKfWF7ix6ojkeCRbD079Vw0kWmktNz6nvDZpa/5+IrMA6Wo4veZH C18w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lca.pw header.s=google header.b=J7K7FCFb; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x23si263136otq.41.2020.02.12.06.35.52; Wed, 12 Feb 2020 06:36:05 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@lca.pw header.s=google header.b=J7K7FCFb; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727698AbgBLOfZ (ORCPT + 99 others); Wed, 12 Feb 2020 09:35:25 -0500 Received: from mail-qk1-f196.google.com ([209.85.222.196]:43807 "EHLO mail-qk1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727092AbgBLOfY (ORCPT ); Wed, 12 Feb 2020 09:35:24 -0500 Received: by mail-qk1-f196.google.com with SMTP id p7so2202737qkh.10 for ; Wed, 12 Feb 2020 06:35:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lca.pw; s=google; h=from:to:cc:subject:date:message-id; bh=5H+ytVXAlSIDd672XrGaeP1xTzQC9Kh/R6V2+KHWLTY=; b=J7K7FCFbZRwrJb3Q+P7eJKiwdE/0J6PYJFAy0oTD5YWB7lVxPIyz7mb4kGSYB7f5ai GOl1OBkENvmFQh+biNB5124mMtZGq6OE+jeGeKm+fLvo0ejxGAx6b5DQ1INbFoofJvBZ mutqVIJ8CxHsw8LZitpsUperrnkczXQJ7H1mtFP8vfsCbziI/6XDy8MDc6MDZCf877dJ 8duSgt1UXtpTqXbFnQig0ZAOHwyAGzILldc0Ery+QBC/B41ThIMSP99nOvrhiJBv8/fN 6IGnCdR0gVNydp1V1iCmUxJ2e7DAnvTv9tDD+ZXAXPZJUk1cW5SmKXQ9plauBwfTxNVL xndQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=5H+ytVXAlSIDd672XrGaeP1xTzQC9Kh/R6V2+KHWLTY=; b=JEcu/fKgabBPog4I3+HJc4z3Qt46LiB82tMxIZtnUFw+bNX0Z7/CJ+kr88W713bXS3 UNW9X/RvmRwVA0EjxPs+03jgcRLCX5VF7vPfRUdD1kl5zVAL5xp1HdoXj3VwQEmS8AOZ r1jIsp12psyOYe33MXv5enEFAA87LfA4WqiRPUssMLb2/ElMMpGqs+rEZ/ymSWEI4j2E avx+Jf4S0tvJZsXba5pcZQ0TBUb6RwgNiKFt1DGmqaJp7enpJxQ4LVa4ddBOQPZjMeFM hHxa0GLCsQy8mHle3vowCO/H2u3v98WM28MClBbn+7Tt8GMgde5LVYZ1w36ulGdB85hF rlhg== X-Gm-Message-State: APjAAAXcbBQ23LkXZwwE7p7M9OiiBKM39y65Is2towDGusR47jmWGBJY U5Dw2m5v9OQj/At/AIcfEshAGWDErQ+P4w== X-Received: by 2002:ae9:edc4:: with SMTP id c187mr2983448qkg.34.1581518123593; Wed, 12 Feb 2020 06:35:23 -0800 (PST) Received: from qcai.nay.com (nat-pool-bos-t.redhat.com. [66.187.233.206]) by smtp.gmail.com with ESMTPSA id v10sm245191qtp.22.2020.02.12.06.35.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 12 Feb 2020 06:35:21 -0800 (PST) From: Qian Cai To: akpm@linux-foundation.org Cc: tj@kernel.org, elver@google.com, cl@linux.com, dennis@kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Qian Cai Subject: [PATCH -next v2] mm/util: annotate an data race at vm_committed_as Date: Wed, 12 Feb 2020 09:35:09 -0500 Message-Id: <1581518109-21180-1-git-send-email-cai@lca.pw> X-Mailer: git-send-email 1.8.3.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org "vm_committed_as.count" could be accessed concurrently as reported by KCSAN, read to 0xffffffff923164f8 of 8 bytes by task 1268 on cpu 38: __vm_enough_memory+0x43/0x280 mm/util.c:801 mmap_region+0x1b2/0xb90 mm/mmap.c:1726 do_mmap+0x45c/0x700 vm_mmap_pgoff+0xc0/0x130 vm_mmap+0x71/0x90 elf_map+0xa1/0x1b0 load_elf_binary+0x9de/0x2180 search_binary_handler+0xd8/0x2b0 __do_execve_file+0xb61/0x1080 __x64_sys_execve+0x5f/0x70 do_syscall_64+0x91/0xb47 entry_SYSCALL_64_after_hwframe+0x49/0xbe write to 0xffffffff923164f8 of 8 bytes by task 1265 on cpu 41: percpu_counter_add_batch+0x83/0xd0 lib/percpu_counter.c:91 exit_mmap+0x178/0x220 include/linux/mman.h:68 mmput+0x10e/0x270 flush_old_exec+0x572/0xfe0 load_elf_binary+0x467/0x2180 search_binary_handler+0xd8/0x2b0 __do_execve_file+0xb61/0x1080 __x64_sys_execve+0x5f/0x70 do_syscall_64+0x91/0xb47 entry_SYSCALL_64_after_hwframe+0x49/0xbe The warning is almost impossible to trigger according to the commit 82f71ae4a2b8 ("mm: catch memory commitment underflow") but leave it for now to catch any possible unbalanced vm_unacct_memory() in the future. Since only the read is operating as lockless, mark it as an intentional data race using the data_race() macro to avoid modifying percpu_counter_read() and still catch unintended races elsewhere. Acked-by: Christoph Lameter Acked-by: Dennis Zhou Signed-off-by: Qian Cai --- v2: add some code comments. mm/util.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/mm/util.c b/mm/util.c index 988d11e6c17c..cc89e2404e19 100644 --- a/mm/util.c +++ b/mm/util.c @@ -798,8 +798,12 @@ int __vm_enough_memory(struct mm_struct *mm, long pages, int cap_sys_admin) { long allowed; - VM_WARN_ONCE(percpu_counter_read(&vm_committed_as) < - -(s64)vm_committed_as_batch * num_online_cpus(), + /* + * A transient decrease in the value is unlikely, so no need + * READ_ONCE() for vm_committed_as.count. + */ + VM_WARN_ONCE(data_race(percpu_counter_read(&vm_committed_as) < + -(s64)vm_committed_as_batch * num_online_cpus()), "memory commitment underflow"); vm_acct_memory(pages); -- 1.8.3.1