Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp892563imu; Fri, 21 Dec 2018 09:02:39 -0800 (PST) X-Google-Smtp-Source: ALg8bN6mU4PEv4NYKUvqGoHKTZ0+0CYslLSRif0ta1mVYk/2MHcsEkwjOUC1tVpRyZi/4Hi0QOYc X-Received: by 2002:a17:902:f81:: with SMTP id 1mr3205152plz.174.1545411759131; Fri, 21 Dec 2018 09:02:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545411759; cv=none; d=google.com; s=arc-20160816; b=kRxYdn8/rAe7e9kcuqjDmOyneLYCfd57BzhSFNW2ECJ0OQ1xMKOyTiBhJ2C0Y+PIUN 4SkFChHa4tQLgXQfKUOUROVSv8m5HWxpn1VN8VxRvqjqUwxfc0mkVPu4BVC9taG8VIXW 3P4GJ3BF55FlFFlkcrT1ugqcKCHlQhu39ufxFGhh1haB9fghEV104t8am5wuECd2Iy1S bU6V0cbQ3BV6OfiwvdMQ/R8yqCAD8ukBNANHgzt6ONLPlpwoIPu0vC4w/n3KUaIojsot APq2nuMJ9Of77k4eRyD//CWtWDO7xUqEl/8KZMNtS1cjU5IY4jRqIHytBDLG+SejhyJR sNRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dmarc-filter:dkim-signature:dkim-signature; bh=SOTrDQWK+OhgHI29qdEQ01BNdMJxTst8qGDPl37Y0Eo=; b=bKooQgl6eBFlWlK0igmGCPYz8AA3FMMwlG4WqQ/SToMBPMkxKE41RxjIUPaPkRcSEH tiQ8dkrlAsNwkH9ZeyHmIeSR0rcJwiGeo62xBsaV1cVXClgDwAkNTjg76R7HY27I5Qbs vzH5CpTplCmVjOWlaun75dVHKtEJcPV1r+ODcHtLO4fQhxHtashjS7yK5KELxTLBJdRP eThGmgqXU3dMPzSKILz+5OqQIbyxxcKIHgBc50+fKf+8JjrVbkxxVaF989phheZ4Io2S xBPenW99Db0eajdhaB41Q1fcgsQbQgR04ZGa8KujjyFGMlwkUSbGboFa2tohPvPWI19J MN9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=Xs5vn3hJ; dkim=pass header.i=@codeaurora.org header.s=default header.b=C0lLKc4j; 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 s12si20860265pgh.488.2018.12.21.09.02.21; Fri, 21 Dec 2018 09:02:39 -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=Xs5vn3hJ; dkim=pass header.i=@codeaurora.org header.s=default header.b=C0lLKc4j; 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 S2387775AbeLUH3t (ORCPT + 99 others); Fri, 21 Dec 2018 02:29:49 -0500 Received: from smtp.codeaurora.org ([198.145.29.96]:51900 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733056AbeLUH3r (ORCPT ); Fri, 21 Dec 2018 02:29:47 -0500 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id D884460E3D; Fri, 21 Dec 2018 07:29:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1545377387; bh=0rh/Y3orgABr/6NpLslESGMZRGQdp5fE3fGdz1kPfxM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Xs5vn3hJ7Pc9C2m/D/wAwjQGZvQmlGZNCdIpQxD/mrbafwQQjCqXKh0TO43nDh4rY SYjCtWdU0l/i2GWIvLQDcRRTxDYdzZMs6o++gPQCnqJ6nFiyrPZ0e2NEfu8ZZEIIXW piXrqv+jzVrdidzRnEKjExX0+Q1OcQAdNPtch3I0= 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 46DC960DE9; Fri, 21 Dec 2018 07:29:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1545377369; bh=0rh/Y3orgABr/6NpLslESGMZRGQdp5fE3fGdz1kPfxM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=C0lLKc4jpCmAfCR7d5Ju3wHNHN59GDgOKaOv1hAukMQzI5o4go/ZRG1hzmIfWEuFd Gqwg8aLMlGXyF9zYhgRfO9WBUv/G5NdelsahC4kfGuILI4Sml5EVtigLyqfx6wqFCa GR1Vj1PN8m1sCbgdLP7/ZRt0/Qh4Ih0KT1B7cZKU= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 46DC960DE9 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: dbueso@suse.de, andrea.parri@amarulasolutions.com, peterz@infradead.org, mingo@redhat.com Cc: linux-kernel@vger.kernel.org, sramana@codeaurora.org, Prateek Sood Subject: [PATCH] percpu_rwsem: fix missed wakeup due to reordering of load Date: Fri, 21 Dec 2018 12:59:13 +0530 Message-Id: <1545377353-30441-1-git-send-email-prsood@codeaurora.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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.