Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp408463imu; Fri, 21 Dec 2018 00:59:31 -0800 (PST) X-Google-Smtp-Source: ALg8bN5yt2bkErmfCtL2+iJHJqFHVbz48DZauuR4qYrlVyd2ormLD/u9DfDeef8zEkVqyoA7RjH1 X-Received: by 2002:a63:ac1a:: with SMTP id v26mr1573340pge.293.1545382771776; Fri, 21 Dec 2018 00:59:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545382771; cv=none; d=google.com; s=arc-20160816; b=ihX4S1xROk4WvNkCCXaBYlp5TZMZ338GYUXOiUb1SSmmlj1ejgfcebL2w8hg58T1EM jLVDgmnlfSs+S1EH7X5oaKHUXJvkZeI00UF0baV4J8J59zjaWLaiDPph9ESvilvlYT/Y L+UhdVwaOfEimwqbtTVK9W4gg1f4FNZ/gwVuVEKELdFrmBijYeVnWpGxaXvpkkEhOc7L geT8bWnyEmXzzCqZ2fch2xY++IdUj8UY0pw+YBdw2unvtK8XLj+pJ0rNBGkcVkPlfzTj jZOYhjJ25/Y+zRPR8jfl/oCfo+UTcQWDYq6GcL00+2g8wssS0pIcDhC7BzHvVdivNmyk BGfw== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dmarc-filter :dkim-signature:dkim-signature; bh=hZfA6/zzxSnQDyFRpwiIJgug0oPaZW39nNYMPyl28aY=; b=GTXUA8jMTb/AbFUqh1nXfgOA5+Pr22DNk9EGFhYOtcSzhBHq8XHC+J5qfGtwNH/Dwu hUthGnNCLqjJW6GXCbJfWaoTyt2BTt3fTiXZDXDImP0MI2qIB2mfk4kDUGOttnbvUu6J 0y6twe+HHFn0ep2mSaFrErRkGze+T3yfDjmcyJIqdcJ5hz48w+53VLdCjpnL/z/VsLh6 SVrirMmFCLJJp6B7LkkRVpISWYKoGs7UeOrbxNT73z91ky1AcnYmezbT8XjwacUHJpme 6gDTc9o8zi2pNcO0PIjdpbiSgNI3HlHGphC50RrAG+XV+lLU1diOVw1Rarj28O65Wbc0 Zj4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=M26lwCpS; dkim=pass header.i=@codeaurora.org header.s=default header.b=RypjB3fQ; 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 v9si20683141pgt.464.2018.12.21.00.59.16; Fri, 21 Dec 2018 00:59:31 -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=@codeaurora.org header.s=default header.b=M26lwCpS; dkim=pass header.i=@codeaurora.org header.s=default header.b=RypjB3fQ; 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 S1731667AbeLUGgF (ORCPT + 99 others); Fri, 21 Dec 2018 01:36:05 -0500 Received: from smtp.codeaurora.org ([198.145.29.96]:48638 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727920AbeLUGgE (ORCPT ); Fri, 21 Dec 2018 01:36:04 -0500 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 92E6060208; Fri, 21 Dec 2018 06:36:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1545374163; bh=af8no7Z/E/LiL7O+JRO0jFB/5+xcxXn21WWrNWTjYHs=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=M26lwCpS61fLaYUW1xnyu1RXJup4KcZYpTO618hRvOGSInv8fEMwsFz7vj6cZftfP +P+ajBn1gkbZuijo52W6zBGUZ9A+2vkcjJimSGiG6nPeVuVmYiVyYAqE6dlPmh1es4 w1HHmueaFbTO1QLpgQSD0+A12tE5MEslIuAi9PpQ= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on pdx-caf-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=ALL_TRUSTED,BAYES_00, DKIM_INVALID,DKIM_SIGNED autolearn=no autolearn_force=no version=3.4.0 Received: from [10.204.79.19] (blr-c-bdr-fw-01_globalnat_allzones-outside.qualcomm.com [103.229.19.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: prsood@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 9B2A260208; Fri, 21 Dec 2018 06:36:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1545374162; bh=af8no7Z/E/LiL7O+JRO0jFB/5+xcxXn21WWrNWTjYHs=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=RypjB3fQpNDb/LzieMF3Q53rl3GTO7meCBuLEaWP9qruS38OSJfDCfBG3+fP/xE16 3Rt+9QHFa+mAPA2frq1bAIM8/kM+ho9HrKw7QyGJLz44mBoXgqZIjBqeBqcq7CCx1n 6rbbimKCyEgrh+SZYt9j1k48d8KJQp7pQtPxN8Sk= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 9B2A260208 Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=prsood@codeaurora.org Subject: Re: [PATCH] percpu_rwsem: fix missed wakeup due to reordering of load To: Andrea Parri Cc: peterz@infradead.org, mingo@redhat.com, dbueso@suse.de, linux-kernel@vger.kernel.org, sramana@codeaurora.org References: <1543590656-7157-1-git-send-email-prsood@codeaurora.org> <20181212152852.GA11111@andrea> From: Prateek Sood Message-ID: Date: Fri, 21 Dec 2018 12:05:51 +0530 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <20181212152852.GA11111@andrea> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 12/12/2018 08:58 PM, Andrea Parri wrote: > 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(); Ok, I will update the comment in next version of the patch. > moreover, the memory-barrier annotation "B" is used also for the > smp_mb() preceding the __this_cpu_dec() in __percpu_up_read(). In this annotation "B" is corresponding to annotation "A" in rcuwait_wait_event(). So this seems to be correct. > > 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. >> -- Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc., is a member of Code Aurora Forum, a Linux Foundation Collaborative Project