Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp983150imu; Fri, 21 Dec 2018 10:29:11 -0800 (PST) X-Google-Smtp-Source: ALg8bN7/JuA3YfczQbXMEqIekdeCfub0pn9P7RQgcIBrSrMIshtk4UTV4wMZb/WcMBKAkSJASEr6 X-Received: by 2002:a17:902:e18c:: with SMTP id cd12mr3397654plb.279.1545416951041; Fri, 21 Dec 2018 10:29:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545416951; cv=none; d=google.com; s=arc-20160816; b=MiHxuvkSuLHUo5xN9I7ePGvI2W6aJl/SKMo3B2CuXTVvCp6Zb/lIBmIjk/i2MYzsVA luMwBrsfvBcpznfCTPNgLx4Gz5F6STyx6GaOzCWodfluFLMHhS69Gagu7Qi5B36uEXJn 3+4W2NaS5xZcCzms4RdJk3Vmr0w3wiLOYpG7YMcVJ6fL75Z6vFjXXbtr9UmsZBRMVH+a wz0ObS5mVOv0CrI8Z8ns/9epqk70FGBaxf2nKOj7noqXQTfXxUjp1ehxYD/HKBsXIR6Y qGI/anJj/dJrbm1wW/hXgPCTE+hmgn6jwZZdh5SSApNMjKMph2Lgz99/4QgeEg8+TSde rxhg== 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=6NhD3iKAIKpmO3OXekjBxkYrlMQxXxTpXmOu23KoWWM=; b=ul1DgyuCazAgSTjrmH2d9SVMSQiE4CmQB46oGqQvoeRkNVbLiLx82w8sCCjPsk0PQL TDNEvXm4lXsA5mbe8KESTEF6B7usYGNC/u5o/HriSQDaboTKvLVyuS60dMMiItXYm6Bq EyeLA88CEyP5ibnT8IFbvpygFRjAsrZtsu7hAYtxQh6UOTGUkbST4wleygkcoUUJkuSK vCrZciKQ3y9ckIGd3oWU/MY0WKQmRwxBqK51+aTry9tKLhjeLb+hPqIhgTMW/e9V+ysm 2QTVO2CGe8oXrCembhF+0iXckS388ukWiXCPfiQPSfI+u4+ItbajkFYNlEW3ZrH5RWeN 99Qw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=Apm9NhOy; 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 u25si21922777pgm.532.2018.12.21.10.28.55; Fri, 21 Dec 2018 10:29:10 -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=Apm9NhOy; 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 S2388220AbeLUJpZ (ORCPT + 99 others); Fri, 21 Dec 2018 04:45:25 -0500 Received: from mail-ed1-f68.google.com ([209.85.208.68]:43623 "EHLO mail-ed1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733247AbeLUJpY (ORCPT ); Fri, 21 Dec 2018 04:45:24 -0500 Received: by mail-ed1-f68.google.com with SMTP id f9so4118540eds.10 for ; Fri, 21 Dec 2018 01:45:23 -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=6NhD3iKAIKpmO3OXekjBxkYrlMQxXxTpXmOu23KoWWM=; b=Apm9NhOykmsfFpkEtJ7mkMv4jz/eB1qlFqzY8L6pCpx61FmZYC47M+AACI72S8uXKn cX2PusVpt2+XsVGF3+9DdY1vY0lQ8tUO/JjQxpUDM73MIt6IpNKJ387FWJnFIv4xScJN 2rnO20RrrLLOj1Ns4KZcb6wSkiMAphV608Pc4= 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=6NhD3iKAIKpmO3OXekjBxkYrlMQxXxTpXmOu23KoWWM=; b=B7Y3OLyC1W6U7PmCIpMzvusTuwcL924yruLjwcXxMkaMlM4CIDKolwk0dW+ZrBBj94 0Cfc12o0da4uMgAtnUoW6HKFKnamLNIRxI6PFQoYQgxmAssAeur3fqBRj0vGW5lsTHp7 SlbS1n2rxMhyB2dvB8xPwNi+O9wA8ayN4tznFYXyDEcI29IxsdaBYam2fB2uR8uI3R02 XKJsAvo1httjsGOSkiCKBZ7DcFLDw3yzwPml9iSo+3AMBBC4Rfa703X81oIiidsm6Vc8 o5X5hmSVR4GlYEkm9PMy6/nhcu1AOq5V2gUTQTC8Z/bYiAl0+80Hr7CCiarYhuvt9dNQ iBFA== X-Gm-Message-State: AA+aEWaEXmat1qWKgW7J0bkDQ0pLJrgmVOmoyJH98L+DH6hkgPHbrHV/ Mnt7WQMVWYN6Ih0cQvzPxHgpDg== X-Received: by 2002:aa7:d29a:: with SMTP id w26mr1879284edq.30.1545385522857; Fri, 21 Dec 2018 01:45:22 -0800 (PST) Received: from andrea (host250-139-dynamic.26-79-r.retail.telecomitalia.it. [79.26.139.250]) by smtp.gmail.com with ESMTPSA id b46sm6882975edd.94.2018.12.21.01.45.21 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 21 Dec 2018 01:45:22 -0800 (PST) Date: Fri, 21 Dec 2018 10:45:15 +0100 From: Andrea Parri To: Prateek Sood Cc: dbueso@suse.de, peterz@infradead.org, mingo@redhat.com, linux-kernel@vger.kernel.org, sramana@codeaurora.org Subject: Re: [PATCH] percpu_rwsem: fix missed wakeup due to reordering of load Message-ID: <20181221094515.GA3740@andrea> References: <1545377353-30441-1-git-send-email-prsood@codeaurora.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1545377353-30441-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, Dec 21, 2018 at 12:59:13PM +0530, Prateek Sood wrote: > P1 is releaseing the cpu_hotplug_lock and P2 is 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, it 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 > Acked-by: Davidlohr Bueso It looks like Peter has already queued this, c.f., https://git.kernel.org/pub/scm/linux/kernel/git/peterz/queue.git/commit/?h=locking/core&id=73685b8af253cf32b1b41b3045f2828c6fb2439e with a modified changelog and my Reviewed-by (that I confirm). I can't tell how/when this is going to be upstreamed (guess via -tip), Peter? Andrea > > --- > kernel/exit.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/kernel/exit.c b/kernel/exit.c > index ac1a814..696e0e1 100644 > --- a/kernel/exit.c > +++ b/kernel/exit.c > @@ -298,7 +298,7 @@ void rcuwait_wake_up(struct rcuwait *w) > /* > * Order condition vs @task, such that everything prior to the load > * of @task is visible. This is the condition as to why the user called > - * rcuwait_trywake() in the first place. Pairs with set_current_state() > + * rcuwait_wake_up() in the first place. Pairs with set_current_state() > * barrier (A) in rcuwait_wait_event(). > * > * WAIT WAKE > @@ -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. >