Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3865621imu; Fri, 30 Nov 2018 07:13:49 -0800 (PST) X-Google-Smtp-Source: AFSGD/UxPUh0A+9GVjoLbrVF4ZQMLQiFLZRHN6YBfDXuRlC9VxDGIJW11k9hrUb7XFiiu4tSh2su X-Received: by 2002:a62:848d:: with SMTP id k135mr5911908pfd.47.1543590828960; Fri, 30 Nov 2018 07:13:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543590828; cv=none; d=google.com; s=arc-20160816; b=VywOOie/xeor2eoOlbsKrDD8S9xvJ2Sb+zQII7fuYdbNyuTurfkRn/mdytoKStnVUB DTixS0zZqTn6AtrFK24p7JcudN4BuSYALojnrnFmIoOv7S5V8reeu5kcOUVpk3j68pRI mw+Tn9EbmVLMghaawGgX08NSg/146Q5ga7m/jOnpJVLUWULWP17kMv79BVPMtCKe1W1C DlDM/A38Eu7rMAGvAo4yNIbLj/LFolXvdCGa92i7my2BkObqvaro3QkmWF1cwtumbhDd I0fXWR2s1Y42QZFCk87DdH0mMaXmZ590j/P5V3ja7diuzyYES6BT/jPqRzeaDPxnXURu WsXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dmarc-filter:dkim-signature:dkim-signature; bh=5xXoCkCiUplvhRfnMiUIuq8iBADIurHMSvxo7KGLVN4=; b=rkqi5d/DZSwbNbV8OTg9B3Slk0khlEPPRqYH9e4ZYv2vI1BQXhIngxwJsMuJAX21YO 3VVSr8Jsqop1GCU7UKkW6RyPIi1CK+hYZ8ruKNrvDuYAtmwr+dK8p5GDFlrs8xFLHSlA 18pWvc6VNrkEUjkoDTMoNRgByhvhPNuTVRYcryoUK5tRj62jngrXSFynq4J2eri8F4MC nVbG8DbgICXCwcv5nlxgLMI5J5w7tF3QbC0pdGYQv52Q4ej/w9keIHeQr0aCXVaUP5Xv FbIUDUmn+nXRsFPIogCAUEt8amr6fo1BxtcUOIj4osybGAHu+xNr6zIeAQ2QP97s6jyx BJwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=hxVUUNuu; dkim=pass header.i=@codeaurora.org header.s=default header.b=dqJuV36Y; 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 w6si5476883pfb.191.2018.11.30.07.12.53; Fri, 30 Nov 2018 07:13:48 -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=hxVUUNuu; dkim=pass header.i=@codeaurora.org header.s=default header.b=dqJuV36Y; 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 S1727361AbeLACU5 (ORCPT + 99 others); Fri, 30 Nov 2018 21:20:57 -0500 Received: from smtp.codeaurora.org ([198.145.29.96]:38432 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726127AbeLACU5 (ORCPT ); Fri, 30 Nov 2018 21:20:57 -0500 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 69BCE6020A; Fri, 30 Nov 2018 15:11:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1543590678; bh=lxaIqP9U+KhM07BlGYGCxmM2dwCNlyP94hJ1XtgbF/o=; h=From:To:Cc:Subject:Date:From; b=hxVUUNuuNjr8tvdiu0z1dE5nJLQL1SxwCO8XjCKvpZdPYT2VRKbumU5bu6efmr9z8 d4ToKUVfy6xLy87WrF6MWma5hrRrK10/7/7kI1pf5siqTWo8KmRLqfMwV7rvrUPPhJ yrx2yZ1LAl/oN47+A4PtJBfGSxnOZaVI93eY3EfU= 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 prsood-linux.qualcomm.com (blr-c-bdr-fw-01_globalnat_allzones-outside.qualcomm.com [103.229.19.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: prsood@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 8C30160850; Fri, 30 Nov 2018 15:11:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1543590677; bh=lxaIqP9U+KhM07BlGYGCxmM2dwCNlyP94hJ1XtgbF/o=; h=From:To:Cc:Subject:Date:From; b=dqJuV36Y2zIs+lR3XJSFp4VbW7rqZM5gImmzaCUULxhOvyTF6AO44fsNRhqyOzIlt wCb9YXaP6lVq+30hGfTzT18T9o+Ot/Lg0dFp4dr8AjsGgNw0XxvyzObfvzy1vZEpcm rkear/Ghp/HZz2O6A/rmAExn8Srun4flyu7N0TsM= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 8C30160850 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 From: Prateek Sood To: peterz@infradead.org, mingo@redhat.com, dbueso@suse.de, prsood@codeaurora.org Cc: linux-kernel@vger.kernel.org, sramana@codeaurora.org Subject: [PATCH] percpu_rwsem: fix missed wakeup due to reordering of load Date: Fri, 30 Nov 2018 20:40:56 +0530 Message-Id: <1543590656-7157-1-git-send-email-prsood@codeaurora.org> X-Mailer: git-send-email 1.9.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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.