Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp719516ybl; Fri, 31 Jan 2020 06:52:07 -0800 (PST) X-Google-Smtp-Source: APXvYqz82tCyP57UEAK2xphCvV/2J46OR9FzMtSvqFDonN2sI6XX8AGM0Elib8qUB1PCaZgS1oE8 X-Received: by 2002:a9d:75da:: with SMTP id c26mr8019506otl.40.1580482327552; Fri, 31 Jan 2020 06:52:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580482327; cv=none; d=google.com; s=arc-20160816; b=An0rSAERH2K88B+Ri1KbTbljXlB3ThjlNokO8hUIMWG/caX5+XHEk7akPwJxIJNYnf W0m9E0mwPcnaqhua4Xp1ZiFCqxQuvoRXKgS3lFS1WL1xH9VYJyfC6B9TjoWFuts83tz6 HYuPurMNKBGVMqeDjYd76OoANdxTFO1k8A04iCr2VTc9KvuAbAOuhKLKk8Gbt/8MrXdy CKi4HIZqWJnhgHpfOMN/Df+D05EXsShkJvKU7Al1AiGkU5+50+Dyf859LSqVmkg7jaY4 d7XTIrW4hYC9E40a91pMoK3ZEROcyw3WwDzlZSm58Y2L4wT7SOumZ7VgwXvqoyKiOVV6 TLfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=GEWwUoDvKgE0JkyZkNP6WsuVDogS4Rbn/RaYXt1EZVU=; b=BwoLKnuU3dVVQ+aBqFlzEc48JVHLnvVJm6NrkW8KJZs++RJlZs8gxagyd/fdYUS4Zo 700Oq5lRGl+9Mq6XiC1+gGKJrEIZeimhSX6aXgIAIgM1pZEfEgqQ0wKtRrKzy0vimnrq 7YHQBPhzLR7vsOEYXJZ1fQ7YSyzsm6GEl7TMhCpygLth1dmo4uSy1bIenq0hcR/+bdJu 2bh4XuOknOCv7ttO0s9jWBL9eoIqUFxq8ccuiJuKNXsAXC6J4/oEAShUNrJE7D2tNg0I ImwtQr6zS9XXTMd2dac1ODZaviv1lpv70MbtjAGqKDsxG+OXGrMruCnf/PflFdEDTzse Aawg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lca.pw header.s=google header.b=smD1iayx; 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 z73si4401551oia.40.2020.01.31.06.51.55; Fri, 31 Jan 2020 06:52:07 -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=smD1iayx; 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 S1729147AbgAaOup (ORCPT + 99 others); Fri, 31 Jan 2020 09:50:45 -0500 Received: from mail-qv1-f67.google.com ([209.85.219.67]:45239 "EHLO mail-qv1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729128AbgAaOup (ORCPT ); Fri, 31 Jan 2020 09:50:45 -0500 Received: by mail-qv1-f67.google.com with SMTP id l14so3338343qvu.12 for ; Fri, 31 Jan 2020 06:50:43 -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:mime-version :content-transfer-encoding; bh=GEWwUoDvKgE0JkyZkNP6WsuVDogS4Rbn/RaYXt1EZVU=; b=smD1iayxRy+9VqIiytwLA1+Wp2M1FCHdFZi40FV96wO7/21DXgURoKiUJBzxmSsuA0 J/TKJHGfbp9fBWd1vKjx3GVOA4for31G8X26WcCN6PKFIYXFwBNcp7tGpgIz84SronKf ypV8j7J+KPqxJWgu0+7oEP6oobK5hR7mrO5F8u0GEjPaJMvmSbrSjMfKKLBRlSe4SCbs KDZpIEdyQNsdjI+qIy/naZCjY/0o6hpi2NOklMh/flVLpc4J77SojDLyE3lwwoSy9sdY Ij/geOdOjzzwvE1REKBvl78x5SHEWtOIIoWaduT9Hjgb9xaTV3hxRkZkiHKo4kthDtwL C7WQ== 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:mime-version :content-transfer-encoding; bh=GEWwUoDvKgE0JkyZkNP6WsuVDogS4Rbn/RaYXt1EZVU=; b=Wtvw4YWMiCzOYEHVl8Iyn5FseG8oiL1yDdiIv8BPBEutYX+UgAl5HmN7Z9gTjmZSHx zwAstQ0gflDvbAyGuPtNgewbZJz9uP78k77lQibioEy10cXMmGG6842HD0chg9f/gh8j J9iLDtsvMyloBZxDFbn6/6KLyY0gU4EWfCROoeyhiW6QZQG0l48HsnMy/f8c+n8STRhV +nl5MWPgKls+gqHxlQr7H4cn0FEW8GDVRSvhdPbU5siymYdVp2kwd+epat7RAhIZuWVa lIfXEfMkjLNVFqG9JuuMSyc6OJMqTP7ZwwYi9hjQHfcRmqRWn3Sniu0+FA/4NXXhMzhm tdwA== X-Gm-Message-State: APjAAAXgwvQzLDP3aGkCPK3Qm7hcZqVJWfyOqWqbU2iMoLm/Wt6MLIyU gtxfzbH/fVNyayXzgdNq5F6paw== X-Received: by 2002:a05:6214:1103:: with SMTP id e3mr10620973qvs.159.1580482243440; Fri, 31 Jan 2020 06:50:43 -0800 (PST) Received: from ovpn-120-129.rdu2.redhat.com (pool-71-184-117-43.bstnma.fios.verizon.net. [71.184.117.43]) by smtp.gmail.com with ESMTPSA id h13sm4921208qtu.23.2020.01.31.06.50.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 31 Jan 2020 06:50:42 -0800 (PST) From: Qian Cai To: peterz@infradead.org, mingo@redhat.com Cc: will@kernel.org, elver@google.com, linux-kernel@vger.kernel.org, Qian Cai Subject: [PATCH -next] locking/osq_lock: mark an intentional data race Date: Fri, 31 Jan 2020 09:50:38 -0500 Message-Id: <20200131145038.2386-1-cai@lca.pw> X-Mailer: git-send-email 2.21.0 (Apple Git-122.2) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org node->next could be accessed concurrently as reported by KCSAN, BUG: KCSAN: data-race in osq_lock / osq_unlock write (marked) to 0xffff8bb2f1abbe40 of 8 bytes by task 1138 on cpu 44: osq_lock+0x149/0x340 kernel/locking/osq_lock.c:143 __mutex_lock+0x277/0xd20 kernel/locking/mutex.c:657 mutex_lock_nested+0x31/0x40 kernfs_iop_getattr+0x58/0x90 vfs_getattr_nosec+0x11a/0x170 vfs_statx_fd+0x54/0x90 __do_sys_newfstat+0x40/0x90 __x64_sys_newfstat+0x3a/0x50 do_syscall_64+0x91/0xb47 entry_SYSCALL_64_after_hwframe+0x49/0xbe read to 0xffff8bb2f1abbe40 of 8 bytes by task 1150 on cpu 29: osq_unlock+0xee/0x170 kernel/locking/osq_lock.c:78 __mutex_lock+0xb68/0xd20 kernel/locking/mutex.c:686 mutex_lock_nested+0x31/0x40 kernfs_iop_getattr+0x58/0x90 vfs_getattr_nosec+0x11a/0x170 vfs_statx_fd+0x54/0x90 __do_sys_newfstat+0x40/0x90 __x64_sys_newfstat+0x3a/0x50 do_syscall_64+0x91/0xb47 entry_SYSCALL_64_after_hwframe+0x49/0xbe This is a false positive. Since even if that load is shattered the code will function correctly -- it checks for any !0 value, any byte composite that is !0 is sufficient. Hence, mark it as an intentional data race using the data_race() macro. Signed-off-by: Qian Cai --- kernel/locking/osq_lock.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/locking/osq_lock.c b/kernel/locking/osq_lock.c index 1f7734949ac8..009bf18c2226 100644 --- a/kernel/locking/osq_lock.c +++ b/kernel/locking/osq_lock.c @@ -75,7 +75,7 @@ osq_wait_next(struct optimistic_spin_queue *lock, * wait for either @lock to point to us, through its Step-B, or * wait for a new @node->next from its Step-C. */ - if (node->next) { + if (data_race(node->next)) { next = xchg(&node->next, NULL); if (next) break; -- 2.21.0 (Apple Git-122.2)