Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp2266400imm; Wed, 3 Oct 2018 00:49:22 -0700 (PDT) X-Google-Smtp-Source: ACcGV62Lot+F2j5VLyriR0CY23EgBFpFisIzZlBUxQ7GoRhKZFlA+LPuAQUAuRZ5nj1tjUOyjKAF X-Received: by 2002:a17:902:8c84:: with SMTP id t4-v6mr303530plo.188.1538552962140; Wed, 03 Oct 2018 00:49:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538552962; cv=none; d=google.com; s=arc-20160816; b=0b3KZFH8c1ZDYSLm2XVr/XkV3B/Ov0SakdXj0yoiCB3vqJIaTzJQc9cndHCXw2B9sh QxY1LObgxOrgmbZaJ6Zx5Jxd2TIvTjPV2cK7tuH3p6FCWAu4fLzeG994hy+SDCvJzueo ZtbNM7MxlA0WIUJyX/jE7j0C9JTZUKwB/vlxZGepaqTR19D7Pi+lHh4IYUknsvb9VQ0q m0VeHRIgVI1y4nqgv/IumbHpMq3TUx9TuNbmtuZnezzQVIP6pnlCCVhHBGdr9C5qh3+q JFYitnEiyi5U778oIYPMeBzghbosWcw3cZAOEnyW7yZ6YwgYk38N5z2LBmcVNlyVuc/O qs3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=/UO2rFozn/4PHAiBN0lJ3YO/Zf8NghUaIMLXk5ZKrIw=; b=OYKni4jQNlf3NLcfg4Xg5/u1duL4kDDNuRCMBYvYPHPbVA+Md1FZfMDuiJnu01Q3hq kvpfvSwPBu13d1gV+YujnP2WqIEAshdHN3f061cheMP7QMc+CATD8eDIhWoHf5KQhbcD cpiEaeILhycZTLzz0pLhmYIrPTlIN8uRteUsLEXgnKf8Bjba0XHupgg+nagvO9ftlfvv PksN1Hgq3an941NG7XBvfzfb6cfGU4N8jHwqSVDz9QZQVJesP2IjGEy4YLNbU09ldNbk 5Q2AA4aoYlohkkbWJUcwxYglREku9r+dsijy0JzunJvCjvx+pMF+gf2PStxSe32jEJU4 qPcw== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y5-v6si680921plt.438.2018.10.03.00.49.07; Wed, 03 Oct 2018 00:49:21 -0700 (PDT) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727209AbeJCOfo (ORCPT + 99 others); Wed, 3 Oct 2018 10:35:44 -0400 Received: from foss.arm.com ([217.140.101.70]:47274 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726835AbeJCOfo (ORCPT ); Wed, 3 Oct 2018 10:35:44 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 6BA337A9; Wed, 3 Oct 2018 00:48:30 -0700 (PDT) Received: from queper01-lin (queper01-lin.emea.arm.com [10.4.13.27]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id C73AB3F5A0; Wed, 3 Oct 2018 00:48:24 -0700 (PDT) Date: Wed, 3 Oct 2018 08:48:23 +0100 From: Quentin Perret To: Andrea Parri Cc: Peter Zijlstra , rjw@rjwysocki.net, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, gregkh@linuxfoundation.org, mingo@redhat.com, dietmar.eggemann@arm.com, morten.rasmussen@arm.com, chris.redpath@arm.com, patrick.bellasi@arm.com, valentin.schneider@arm.com, vincent.guittot@linaro.org, thara.gopinath@linaro.org, viresh.kumar@linaro.org, tkjos@google.com, joel@joelfernandes.org, smuckle@google.com, adharmap@codeaurora.org, skannan@codeaurora.org, pkondeti@codeaurora.org, juri.lelli@redhat.com, edubezval@gmail.com, srinivas.pandruvada@linux.intel.com, currojerez@riseup.net, javi.merino@kernel.org Subject: Re: [PATCH v7 03/14] PM: Introduce an Energy Model management framework Message-ID: <20181003074822.bwlhiowr4upjwunm@queper01-lin> References: <20180912091309.7551-1-quentin.perret@arm.com> <20180912091309.7551-4-quentin.perret@arm.com> <20181002123031.GZ3439@hirez.programming.kicks-ass.net> <20181002125115.245r3ocusvyiexno@queper01-lin> <20181002134857.GE26858@hirez.programming.kicks-ass.net> <20181002140430.fpeiqzblbcaewg6n@queper01-lin> <20181002142924.GI26858@hirez.programming.kicks-ass.net> <20181002144025.wnanxibhdcnl23sf@queper01-lin> <20181002191217.GA4160@andrea> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181002191217.GA4160@andrea> User-Agent: NeoMutt/20171215 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Andrea, On Tuesday 02 Oct 2018 at 21:12:17 (+0200), Andrea Parri wrote: > An example might help clarify this: here is a scenario I can _imagine, > based on your description. > > CPU0 (em_register_perf_domain()) CPU1 (reader) > > [...] my_pd = READ_ONCE(per_cpu(em_data, 1)); /* em_cpu_get() */ > pd->table = table if (my_pd) > WRITE_ONCE(per_cpu(em_data, 1), pd); my_table = my_pd->table; /* process, dereference, ... my_table */ > > In this scenario, we'd like CPU1 to see CPU0's store to ->table (as well > as the stores to table[]) _if CPU1 sees CPU0's store to em_data (that is, > if my_pd != NULL). > > This guarantee does not hold with the WRITE_ONCE(), because CPU0 could > propagate the store to ->table and the store to em_data out-of-order. Ah, this is a very good point ... It's fine if a reader sees em_data half way through being updated, but it is NOT fine at all if a reader gets a pointer onto a half-baked em_perf_domain. So I agree, there is a problem here. (I also realize now that I totally misunderstood Peter's messages before which were basically pointing out this issue :/ ...) > The smp_store_release(), together with the address dependency headed by > the READ_ONCE(), provides this guarantee (and more...). > > (Enclosing the reader into an em_pd_mutex critical section would also > provide this guarantee, but I can imagine a few arguments for not using > a mutex... ;-) ). Right, using the mutex in em_cpu_get() could work too, although we probably don't want to do that. We might very well end up using it in a RCU critical section for example (although that's not the case with this series, I'm just looking forward a bit). So using smp_store_release() is the best choice here. I'll fix that up for v8. Thank you very much, Quentin