Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1976799imu; Wed, 12 Dec 2018 07:31:44 -0800 (PST) X-Google-Smtp-Source: AFSGD/UfctQmMqZPPtSMH5hE1NafsqeYEqQrmdUXWXILOLUmNmJ6uuxn01mEB7/gn4IPEby5rjcR X-Received: by 2002:a17:902:8f83:: with SMTP id z3mr19686581plo.328.1544628704023; Wed, 12 Dec 2018 07:31:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544628703; cv=none; d=google.com; s=arc-20160816; b=vzRkYteATxTbF0GJCmMNaZYpNMCwA37QLNLnoteDyYa2wZqgzWQ9ieit0/jcWFBJSK Akl2toDmOirlUwl1yS7TlEKC2+F4deh6j7SOLO8RF9dvokhzwnRaKbrmijORUTJr3AIc dHwvXiHY1Nf0GI/u4+0USUZVB1Ah323jVScAUvCth7SbCyvtXMpn/1Xf0fLBfc4VzFcX IZZH/QrYpebjXB1GafU8u8MvLjarsHFpvs4kdIaBXXEaW8iquyCDAG55TPRYSfVhjNvP +vZllQ2ZrL/ymF+BjJO+ZkHgi05mNk+wraeSCZ1rHqAY3tYEtUNkGF0o1KAc/EEYXdt0 0X0g== 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:dkim-signature; bh=TtlTE84oxlmz5yQs1GoQVX0Sm34zBTIdf418AO8syUM=; b=wdefjzEVbGdF3OREBnR2ZdHZV71iGQBTBKzIk3vV4Ac/Benx8NW7XQpylqGSECNyKJ sq3r5rN1z44rYgo1xTxokYst229AEpagYiD5dmYocAfhxfFc8vIMB1BgdDCzFw01c6bH 660IyH+LnxO8wNXbOqH6A/8wV72IrJCXuZ3nuO9SFNL+/Rol44nVnkHAHehgZ+bEUBNn y5EOeuShCncm3PcN+KoglMfI503xPXoLGUdLQ/Oshoz7bIVUUsHaM2M/qjdf02Tq2yll aTztuHgkXs0olyBsHICVHti3MaSWUKlhiYjDGYDfxEIMrlH+uAxcXwe2f7cuNFzSgxem vLOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=MOqqdI9n; 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 f95si16158799plb.60.2018.12.12.07.31.25; Wed, 12 Dec 2018 07:31:43 -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=@amarulasolutions.com header.s=google header.b=MOqqdI9n; 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 S1727752AbeLLP3I (ORCPT + 99 others); Wed, 12 Dec 2018 10:29:08 -0500 Received: from mail-ed1-f65.google.com ([209.85.208.65]:37491 "EHLO mail-ed1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726325AbeLLP3I (ORCPT ); Wed, 12 Dec 2018 10:29:08 -0500 Received: by mail-ed1-f65.google.com with SMTP id h15so15898396edb.4 for ; Wed, 12 Dec 2018 07:29:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=TtlTE84oxlmz5yQs1GoQVX0Sm34zBTIdf418AO8syUM=; b=MOqqdI9nDuT9ad7w+VR9/sxvpOLBJde/JsBD4IW4pE01/u+hpQzIEynBaALniXZ82C L6Cd8Lj+SxrZrHENfz7jOrL2Ee9cVdbXkeBgJr/0rts9B2TgRiuba0MTu0negKyF5/QL P8qQvFA4PwmfGkNLpf6vEDry83/LQIFNU6i/o= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=TtlTE84oxlmz5yQs1GoQVX0Sm34zBTIdf418AO8syUM=; b=QeRb/zERYmRyXcuprz7UCIThHBASrwwroyGkYDtqwixXgt3FNTSqTTYO/D/H1xXMYI uPq1GQhjbuDS1AZQhdeQvns4V5F8Fg8go4erIbZHLv4OUiyiqitxjdKV2TwOV66XcRAv ar0PuR3qwcMsmFE1Zk+0mekZZOvlQBxkaN9IwYmh89az1eJqOdPk6/gy/hmkABnZWHKO TdU5dJnXAWafaoccp6Mlc7GfaoWBFATpyiV7zOadltiGsEmSSmHdWFLYBnXjf6vdREny EzMzrAR/HB+EZB6p/UXD+i3Tw9z5cKmF5yF74+p65Sgv6J/qtTpMbcLfkVjEEt/l3mLF WJXQ== X-Gm-Message-State: AA+aEWbZlk7OKDtFEkLQIM7EebtHE6UpAs+CDpe7nNYmOW0Ks+BacRpZ 3mfnYt9ueb2RjG2P+3X4MPCq6w== X-Received: by 2002:a50:9770:: with SMTP id d45mr18112786edb.49.1544628546008; Wed, 12 Dec 2018 07:29:06 -0800 (PST) Received: from andrea (85.100.broadband17.iol.cz. [109.80.100.85]) by smtp.gmail.com with ESMTPSA id z40sm4927322edz.86.2018.12.12.07.29.04 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 12 Dec 2018 07:29:05 -0800 (PST) Date: Wed, 12 Dec 2018 16:28:52 +0100 From: Andrea Parri To: Prateek Sood Cc: peterz@infradead.org, mingo@redhat.com, dbueso@suse.de, linux-kernel@vger.kernel.org, sramana@codeaurora.org Subject: Re: [PATCH] percpu_rwsem: fix missed wakeup due to reordering of load Message-ID: <20181212152852.GA11111@andrea> References: <1543590656-7157-1-git-send-email-prsood@codeaurora.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1543590656-7157-1-git-send-email-prsood@codeaurora.org> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Nov 30, 2018 at 08:40:56PM +0530, Prateek Sood wrote: > In a scenario where cpu_hotplug_lock percpu_rw_semaphore is already > acquired for read operation by P1 using percpu_down_read(). > > Now we have P1 in the path of releaseing the cpu_hotplug_lock and P2 > is in the process of acquiring cpu_hotplug_lock. > > P1 P2 > percpu_up_read() path percpu_down_write() path > > rcu_sync_enter() //gp_state=GP_PASSED > > rcu_sync_is_idle() //returns false down_write(rw_sem) > > __percpu_up_read() > > [L] task = rcu_dereference(w->task) //NULL > > smp_rmb() [S] w->task = current > > smp_mb() > > [L] readers_active_check() //fails > schedule() > > [S] __this_cpu_dec(read_count) > > Since load of task can result in NULL. This can lead to missed wakeup > in rcuwait_wake_up(). Above sequence violated the following constraint > in rcuwait_wake_up(): > > WAIT WAKE > [S] tsk = current [S] cond = true > MB (A) MB (B) > [L] cond [L] tsk > > This can happen as smp_rmb() in rcuwait_wake_up() will provide ordering > of load before barrier with load and store after barrier for arm64 > architecture. Here the requirement is to order store before smp_rmb() > with load after the smp_rmb(). > > For the usage of rcuwait_wake_up() in __percpu_up_read() full barrier > (smp_mb) is required to complete the constraint of rcuwait_wake_up(). > > Signed-off-by: Prateek Sood I know this is going to sound ridiculous (coming from me or from the Italian that I am), but it looks like we could both work on our English. ;-) But the fix seems correct to me: Reviewed-by: Andrea Parri It might be a good idea to integrate this fix with fixes to the inline comments/annotations: for example, I see that the comment in rcuwait_wake_up() mentions a non-existing rcuwait_trywake(); moreover, the memory-barrier annotation "B" is used also for the smp_mb() preceding the __this_cpu_dec() in __percpu_up_read(). Andrea > --- > kernel/exit.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/kernel/exit.c b/kernel/exit.c > index f1d74f0..a10820d 100644 > --- a/kernel/exit.c > +++ b/kernel/exit.c > @@ -306,7 +306,7 @@ void rcuwait_wake_up(struct rcuwait *w) > * MB (A) MB (B) > * [L] cond [L] tsk > */ > - smp_rmb(); /* (B) */ > + smp_mb(); /* (B) */ > > /* > * Avoid using task_rcu_dereference() magic as long as we are careful, > -- > Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc., > is a member of Code Aurora Forum, a Linux Foundation Collaborative Project. >