Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1821483ybv; Sun, 23 Feb 2020 16:13:15 -0800 (PST) X-Google-Smtp-Source: APXvYqzOV5sGaF11xR/gplGHZRIyC4rE63AlxasEflen+Ww8AjIH/t1We78yZKn4Ou2DamPc7P8Y X-Received: by 2002:a05:6830:110a:: with SMTP id w10mr38497252otq.300.1582503195732; Sun, 23 Feb 2020 16:13:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582503195; cv=none; d=google.com; s=arc-20160816; b=oMHDwlo/Au1BmeekXbwyWKL7hq2g6KKRiwRRPAEUcoOE7tfHQxfwWmCLLo5ejgKJf2 RGugUiislSW9QlL2S7pUzwDoINd7a5sy5dUi+2QtsFppBrq3613FbnptdD7ZWntlCfN4 1TVBla2swTDDGuhm98dOTD01Y7LojD/Aui5gerA5Fi10ifA2f057TfVOAVefSTZSQoFB znE6dFs1eZoJAvZfzo2Q89I6da/Ky975PHbs0AxBVfvAhL9fNPnEEH1zVizwmf3oc/b2 8j5WLBpzvwSMwNmrNNkLokCePbTL9Zz5A+nv84EIAB6eL2bTrFzuJPHhg8nD07F9F4yW REMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version; bh=dXtF/HmMIrcd+cQtmXxs/T7lgY990MkWtsdCks/TALQ=; b=MGBLDWOq3Bdwts/fwG4CK+jmVtTpXHbgqSkF4MGL11bO772ZVO0Rx3S9vAkInIXNYn fu+yF/zvNBbXn9m3NeXVkiwt5ctVrU6f80c6tdACH2XP6MeonyWcUs2Tn2OAC2OLOeqL cV0i5xy3tPFXpeDyFI6gtQcfkXp/Iszxpg/MkRSjSgMDV3voyfVmQVRILTVcK0KByrvJ yC15C484m3+OM5DTqsvmrsHolSAt1ekscOvoNsuGt80SDWzvPxd4I2V/zCrywRJn/rQy Gd581ArBU/YQE8lrcP82ousjtDsauz0Vf3fzocDOXWkD7BooqE9udZokUcCYCD+iWY0i rPsw== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g26si5265115otn.180.2020.02.23.16.13.03; Sun, 23 Feb 2020 16:13:15 -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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727168AbgBXAM4 (ORCPT + 99 others); Sun, 23 Feb 2020 19:12:56 -0500 Received: from mail-oi1-f193.google.com ([209.85.167.193]:34433 "EHLO mail-oi1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726534AbgBXAM4 (ORCPT ); Sun, 23 Feb 2020 19:12:56 -0500 Received: by mail-oi1-f193.google.com with SMTP id l136so7378951oig.1; Sun, 23 Feb 2020 16:12:56 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=dXtF/HmMIrcd+cQtmXxs/T7lgY990MkWtsdCks/TALQ=; b=n1y0GFsabmOGSPdsWZwUCkx5zUH6EwT/QM3R2QhUuCiDi3yzz+PlNtyUy0TyjkaW2z 0UXfQNjTXmYZoELA1HAxUQAJLNjYNY39B8SSw1qtR/Cqi/xKT2FFUKwGb4qakt8texD1 edAMrtAmNF4Sj0eT4p4yVi/E7U96+SFVo695gqCUl3zp/ufLB857dk4BhGP2ojxdNTeu sdZnAq0wGuvcG783Ra8g15VheMBuZu+3T/i2ZAdMaV7dEcMcm0uBLSzpNj0Yh228rE53 eoVqjUwO8HOcdq3BR66pH5P9r1PCCjFKfh6XDdi7fOqtSjygDUrlxhS89HckN2/1s9vI DMlA== X-Gm-Message-State: APjAAAUY7HY0fwsDVAp/1y9UjrNXKl7d/BQGrMtUQhIpE4or/3pTYyF1 NZCivzGDXntTznKoRJ2k6vTFf8FpkvFWt1z7LDbfOw== X-Received: by 2002:a54:4e96:: with SMTP id c22mr11067116oiy.110.1582503175589; Sun, 23 Feb 2020 16:12:55 -0800 (PST) MIME-Version: 1.0 References: <1582319350-23515-1-git-send-email-cai@lca.pw> In-Reply-To: <1582319350-23515-1-git-send-email-cai@lca.pw> From: "Rafael J. Wysocki" Date: Mon, 24 Feb 2020 01:12:41 +0100 Message-ID: Subject: Re: [PATCH -next] power/qos: fix a data race in pm_qos_*_value To: Qian Cai Cc: "Rafael J. Wysocki" , elver@google.com, Linux PM , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Feb 21, 2020 at 10:09 PM Qian Cai wrote: > > cpu_latency_constraints.target_value could be accessed concurrently as > noticed by KCSAN, Yes, they could, pretty much by design. So why *exactly* is this a problem? > LTP: starting ppoll01 > BUG: KCSAN: data-race in cpu_latency_qos_limit / pm_qos_update_target It may be a bug under certain conditions, but you don't mention what conditions they are. Reporting it as a general bug is not accurate at the very least. > write to 0xffffffff99081470 of 4 bytes by task 27532 on cpu 2: > pm_qos_update_target+0xa4/0x370 > pm_qos_set_value at kernel/power/qos.c:78 > cpu_latency_qos_apply+0x3b/0x50 > cpu_latency_qos_remove_request+0xea/0x270 > cpu_latency_qos_release+0x4b/0x70 > __fput+0x187/0x3d0 > ____fput+0x1e/0x30 > task_work_run+0xbf/0x130 > do_exit+0xa78/0xfd0 > do_group_exit+0x8b/0x180 > __x64_sys_exit_group+0x2e/0x30 > do_syscall_64+0x91/0xb05 > entry_SYSCALL_64_after_hwframe+0x49/0xbe > > read to 0xffffffff99081470 of 4 bytes by task 0 on cpu 41: > cpu_latency_qos_limit+0x1f/0x30 > pm_qos_read_value at kernel/power/qos.c:55 > cpuidle_governor_latency_req+0x4f/0x80 > cpuidle_governor_latency_req at drivers/cpuidle/governor.c:114 > menu_select+0x6b/0xc29 > cpuidle_select+0x50/0x70 > do_idle+0x214/0x280 > cpu_startup_entry+0x1d/0x1f > start_secondary+0x1b2/0x230 > secondary_startup_64+0xb6/0xc0 > > Reported by Kernel Concurrency Sanitizer on: > CPU: 41 PID: 0 Comm: swapper/41 Tainted: G L 5.6.0-rc2-next-20200221+ #7 > Hardware name: HPE ProLiant DL385 Gen10/ProLiant DL385 Gen10, BIOS A40 07/10/2019 > > The read is outside pm_qos_lock critical section which results in a data > race. This is purely theoretical AFAICS and so it should be presented this way. Also the call traces above don't add much value to the changelog, so maybe try to explain what the problem is in English. > Fix it by adding a pair of READ|WRITE_ONCE(). > > Signed-off-by: Qian Cai > --- > kernel/power/qos.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/kernel/power/qos.c b/kernel/power/qos.c > index 32927682bcc4..db0bed2cae26 100644 > --- a/kernel/power/qos.c > +++ b/kernel/power/qos.c > @@ -52,7 +52,7 @@ > */ > s32 pm_qos_read_value(struct pm_qos_constraints *c) > { > - return c->target_value; > + return READ_ONCE(c->target_value); > } > > static int pm_qos_get_value(struct pm_qos_constraints *c) > @@ -75,7 +75,7 @@ static int pm_qos_get_value(struct pm_qos_constraints *c) > > static void pm_qos_set_value(struct pm_qos_constraints *c, s32 value) > { > - c->target_value = value; > + WRITE_ONCE(c->target_value, value); > } > > /** > -- > 1.8.3.1 >