Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp2248530ybv; Mon, 24 Feb 2020 01:55:34 -0800 (PST) X-Google-Smtp-Source: APXvYqzeV7d9oCSJ5EV/WYHiYL7LTy+ob4LDOfhJ+0OErrQp6VaR4CY+Tiiz9U50vgTDHa2ZFyo2 X-Received: by 2002:aca:55cc:: with SMTP id j195mr12127364oib.22.1582538133986; Mon, 24 Feb 2020 01:55:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582538133; cv=none; d=google.com; s=arc-20160816; b=DliAsx+4xhtEs7D+MeglojX6EaO5sk6+teBRHGppv6uSWatPPPNaXj1N8/EJXH/W9r IEX8d+4KCjFdQ5ugctakjCehvFV5zk9SBCmIkYPLfw/EeBL+AV4OqP+o/GUAf2uHci+w qT4Sqp0rB3H1dGCafAR5uJ+l/O2r2f/DBPScMM7jSwVO72zanh4j9dwXfC83qh4GhdnT 0ykK/MpWGkomR9RmPiQYVpXgPZWypwwfQ5qtPhRSjuiZwK9PW1VJae0CpvM+QGRJgM88 un485hwND2Iw/owMfsZZ53q4EXa+P0iPiYMXFyl5sCMpHqr5GZBB12bzWMPcDvfxXeIy C/YQ== 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:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version; bh=F+My89CoO//JcgS0x8olvSFs8fj91u1Qw6aOpe/t/xU=; b=W0/5QTWNmkG34VCPA5m7cdEWd/Gj2kmOd7tmILVlS/vpJi8DnY/C1gzp67lSG9M+3J FFdifcnR3J7N8AfUeyyP8+VLWl650CIYE662w1N6VD6q6NapV7QE0vA5pu944ZpUTOAu CCE2B2URpIqhP2ejxZHyNjkCwURIXlN3JLxrtUyGtZzngXNA1zc4DL7azKnKvCtsM3hH 6kanO3wCGUA88XOt8EE1epah8gzOMPfMt9SdnD9IiMbxKjnUFOua7VF8iIDxZj9Veb7j I4O6V5Wsrs59/gJed9NgjvdiW+cYUQzBQA8aT+3La4KZHDfcTK5YGOjZiN2dPQylWhm1 UJaQ== 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 c76si3083595oig.149.2020.02.24.01.55.21; Mon, 24 Feb 2020 01:55:33 -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 S1727501AbgBXJyp convert rfc822-to-8bit (ORCPT + 99 others); Mon, 24 Feb 2020 04:54:45 -0500 Received: from mail-ot1-f65.google.com ([209.85.210.65]:32870 "EHLO mail-ot1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726765AbgBXJyp (ORCPT ); Mon, 24 Feb 2020 04:54:45 -0500 Received: by mail-ot1-f65.google.com with SMTP id w6so8182695otk.0; Mon, 24 Feb 2020 01:54:45 -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:content-transfer-encoding; bh=gc6ixcj3vcw3nu96Ty+gdGEq2138xYv/wwhs4XUu2JA=; b=tmAb1VYcMDhWJ0yTxSndDi4CVoc1mbrUMwol37RDmTWtqSN2ivlBNBSjkskjnt7l3L Bv5hvvDgkmw10ftcd83CADKWctU/mHCnp7Gfdwf69k7MyeNQc5/Lj97PtMSwHXmgFyGv A/6Bp42/Q0od1NYRYl2GwIStuAsyngKtEq2cN2eKrd/GiqiWlbkz9pAdM1pgQIvTdzPD g5pPplwVn2b3HovZMm1GO+Lq8J8Vp+Q+u6MKILNOzSAvnhgxNBpTh+PFppS9FZ9bZUf0 NYEqB4d5dPzU73M5e9yTiZARBF/ZX/rtV39erW1XSpNm5PSc81txEEU6Sf9rfXES4Lkq gBmQ== X-Gm-Message-State: APjAAAVJ2SuHxQGvv+6F5Vf/8R1O4rTZlD+l+uzjCfHojmZBXevO7/th 4Fewyxn/lhq6/ROK8LEW18+TJcLXwAUXRx50VV7aIgaj X-Received: by 2002:a05:6830:1651:: with SMTP id h17mr37281264otr.167.1582538084570; Mon, 24 Feb 2020 01:54:44 -0800 (PST) MIME-Version: 1.0 References: <62491094-D13B-4EED-8190-4AA4EB77036B@lca.pw> In-Reply-To: <62491094-D13B-4EED-8190-4AA4EB77036B@lca.pw> From: "Rafael J. Wysocki" Date: Mon, 24 Feb 2020 10:54:33 +0100 Message-ID: Subject: Re: [PATCH -next] power/qos: fix a data race in pm_qos_*_value To: Qian Cai Cc: "Rafael J. Wysocki" , "Rafael J. Wysocki" , elver@google.com, Linux PM , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Feb 24, 2020 at 2:01 AM Qian Cai wrote: > > > > > On Feb 23, 2020, at 7:12 PM, Rafael J. Wysocki wrote: > > > > 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. > > Could we rule out load tearing, store tearing and reload of global_req in cpuidle_governor_latency() for all compilers and architectures which could introduce logic bugs? > > int global_req = cpu_latency_qos_limit(); > > if (device_req > global_req) > device_req = global_req; > > If under register pressure, the compiler might get ride of the tmp variable, i.e., > > If (device_req > cpu_latency_qos_limit()) > —-> race with the writer. > device_req = cpu_latency_qos_limit(); Yes, there is a race here with or without the WRITE_ONCE()/READ_ONCE() annotations (note that these annotations don't prevent CPUs from reordering things, so device_req may be set before global_req regardless). However, worst-case it may cause an old value to be used and that can happen anyway if the entire cpuidle_governor_latency_req() runs between the curr_value update and pm_qos_set_value() in pm_qos_update_target(), for example. IOW, there is no guarantee that the new value will be used immediately after updating a QoS request anyway. I agree with adding the annotations (I was considering posting a patch doing that myself), but just as a matter of making the intention clear.