Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp22505ybc; Mon, 18 Nov 2019 19:20:32 -0800 (PST) X-Google-Smtp-Source: APXvYqwfvSxU2nzBuYaOoouK5GLkz2Vd5oTAWWOUjivlpp6f/OlAeKa1AMZvNR52WYQhaQtSjY0X X-Received: by 2002:a17:906:8307:: with SMTP id j7mr30301164ejx.171.1574133631888; Mon, 18 Nov 2019 19:20:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574133631; cv=none; d=google.com; s=arc-20160816; b=BL1Y9zG76mdBL5VN/gAbQbd4nbKfZWNl4Fs9QgvsQ6LSDIf1trqlF/D9O1YnVRGoBp sg0fQxRc26eFq1BmUcnlg08MgE2hfYJhrWcrJ5Awa0RnZxnFWab1WGp19eKawpP88+yM 5dcRtnAXFdU52pGRQvprlyGZ8YOWmBaCdfwKFkcta5KRcoiXHfh2v4xl3Ah5qr7Yho1n FILSiRU1lWAnqNs78b7nFepNmLAQNftL5txUXk75Qsx2PS7BzMFBWsWYEP9PL9nEyjEf 3haiaZYlwV+crwBJniqHPgV+rCgt76jfdWnRDpSchobKNHLVSpZ1Pu7oaay5/8lZYlMi z3ig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:feedback-id:message-id:date:subject:cc:to :from:dmarc-filter:dkim-signature:dkim-signature; bh=8Wl1HjNj/ne9cfASUOcrgvCED6XwRK3qQSoYjrdhoLI=; b=cl57tT6jU2tXvq1Y4BL8TIDVtbe61PpCXZn9eQfcbAhG00i0loSeUJBrYUccdpAZSs AtlQHzGWUgKoTBNLvOkLd3ulsInBRlBXzhfcHE8PiHDfed2M2njWhVz/3R9V3iLMP3bW ZszK/LfbzR+Q+hImYI5475OuKIGmR5qiSpF/pd6WH/veSuz2JVaCqdmiUItf5fVFVX2t HMe98KORBoAytEkP3D9vqDQz13hyacR0wNvtUmi1ln+AXbQjjjJNVJh8T5edoUi3n4Kx EtNZET01setu686RrNgnB+Pxs8EBAQ8ym/PteTxPQhLs4ElQOoO9+MiA7NjfRC9BjrL6 40Gw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=zsmsymrwgfyinv5wlfyidntwsjeeldzt header.b=Y03COGNW; dkim=pass header.i=@amazonses.com header.s=gdwg2y3kokkkj5a55z2ilkup5wp5hhxx header.b=a1pxYQM1; 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 i3si11463272edx.271.2019.11.18.19.20.08; Mon, 18 Nov 2019 19:20: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=zsmsymrwgfyinv5wlfyidntwsjeeldzt header.b=Y03COGNW; dkim=pass header.i=@amazonses.com header.s=gdwg2y3kokkkj5a55z2ilkup5wp5hhxx header.b=a1pxYQM1; 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 S1727677AbfKSDRJ (ORCPT + 99 others); Mon, 18 Nov 2019 22:17:09 -0500 Received: from a27-56.smtp-out.us-west-2.amazonses.com ([54.240.27.56]:47188 "EHLO a27-56.smtp-out.us-west-2.amazonses.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727505AbfKSDRI (ORCPT ); Mon, 18 Nov 2019 22:17:08 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple; s=zsmsymrwgfyinv5wlfyidntwsjeeldzt; d=codeaurora.org; t=1574133427; h=From:To:Cc:Subject:Date:Message-Id; bh=DSFxMH9kT34z8Vm44Q+35fj1K2btho1KSltCLrspVFc=; b=Y03COGNWcC2E6ORRMjEM65srtvWwA6u/HdJTrLUaioYww+58Z14VNeWzPW+hoRXy a5AzOjVfbpjERHJt/fb0atoCnFd0fsKrp3sKXf5BAk9ls1bOm9yDVlQT2Gf6q7YbzRD Q746TNvQ6+wNOe0/ZyGrpkJr2l79jkNQU8hk4/Pw= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple; s=gdwg2y3kokkkj5a55z2ilkup5wp5hhxx; d=amazonses.com; t=1574133427; h=From:To:Cc:Subject:Date:Message-Id:Feedback-ID; bh=DSFxMH9kT34z8Vm44Q+35fj1K2btho1KSltCLrspVFc=; b=a1pxYQM1qoFjc3UNphUru9S9B+jJaIXqSy2nYP6o9IgahlwRfT7dirxdHOYry9YG 4ibqg7jPFXJ3ZVJcGTnObS6S3SMW3mh1NNgvi+xpFJMq0l0JDIlSFZzSeK3bEJ1wUxd xOppEDtmJulhxkfa7Fhk4q9Qbud7y7gcdMyagiAQ= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-caf-mail-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=2.0 tests=ALL_TRUSTED,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.0 DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 8D066C433A2 Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; spf=none smtp.mailfrom=neeraju@codeaurora.org From: Neeraj Upadhyay To: paulmck@kernel.org, josh@joshtriplett.org, rostedt@goodmis.org, mathieu.desnoyers@efficios.com, jiangshanlai@gmail.com, joel@joelfernandes.org Cc: linux-kernel@vger.kernel.org, gkohli@codeaurora.org, prsood@codeaurora.org, pkondeti@codeaurora.org, rcu@vger.kernel.org, Neeraj Upadhyay Subject: [PATCH v2] rcu: Fix missed wakeup of exp_wq waiters Date: Tue, 19 Nov 2019 03:17:07 +0000 Message-ID: <0101016e81a9ecb9-ce4a6425-f21d-4166-96ed-32d3700717f1-000000@us-west-2.amazonses.com> X-Mailer: git-send-email 1.9.1 X-SES-Outgoing: 2019.11.19-54.240.27.56 Feedback-ID: 1.us-west-2.CZuq2qbDmUIuT3qdvXlRHZZCpfZqZ4GtG9v3VKgRyF0=:AmazonSES Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org For the tasks waiting in exp_wq inside exp_funnel_lock(), there is a chance that they might be indefinitely blocked in below scenario: 1. There is a task waiting on exp sequence 0b'100' inside exp_funnel_lock(). This task blocks at wq index 1. synchronize_rcu_expedited() s = 0b'100' exp_funnel_lock() wait_event(rnp->exp_wq[rcu_seq_ctr(s) & 0x3] 2. The expedited grace period (which above task blocks for) completes and task (task1) holding exp_mutex queues worker and schedules out. synchronize_rcu_expedited() s = 0b'100' queue_work(rcu_gp_wq, &rew.rew_work) wake_up_worker() schedule() 3. kworker A picks up the queued work and completes the exp gp sequence and then blocks on exp_wake_mutex, which is held by another kworker, which is doing wakeups for expedited_sequence 0. rcu_exp_wait_wake() rcu_exp_wait_wake() rcu_exp_gp_seq_end(rsp) // rsp->expedited_sequence is incremented // to 0b'100' mutex_lock(&rcu_state.exp_wake_mutex) 4. task1 does not enter wait queue, as sync_exp_work_done() returns true, and releases exp_mutex. wait_event(rnp->exp_wq[rcu_seq_ctr(s) & 0x3], sync_exp_work_done(rsp, s)); mutex_unlock(&rsp->exp_mutex); 5. Next exp GP completes, and sequence number is incremented: rcu_exp_wait_wake() rcu_exp_wait_wake() rcu_exp_gp_seq_end(rsp) // rsp->expedited_sequence = 0b'200' 6. kworker A acquires exp_wake_mutex. As it uses current expedited_sequence, it wakes up workers from wrong wait queue index - it should have worken wait queue corresponding to 0b'100' sequence, but wakes up the ones for 0b'200' sequence. This results in task at step 1 indefinitely blocked. rcu_exp_wait_wake() wake_up_all(&rnp->exp_wq[rcu_seq_ctr(rsp->expedited_sequence) & 0x3]); This issue manifested as DPM device timeout during suspend, as scsi device was stuck in _synchronize_rcu_expedited(). schedule() synchronize_rcu_expedited() synchronize_rcu() scsi_device_quiesce() scsi_bus_suspend() dpm_run_callback() __device_suspend() Fix this by using the correct exp sequence number, the one which owner of the exp_mutex initiated and passed to kworker, to index the wait queue, inside rcu_exp_wait_wake(). Signed-off-by: Neeraj Upadhyay --- Changes since v1: - Updates the commit log with failure information. kernel/rcu/tree_exp.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/rcu/tree_exp.h b/kernel/rcu/tree_exp.h index e4b77d3..28979d3 100644 --- a/kernel/rcu/tree_exp.h +++ b/kernel/rcu/tree_exp.h @@ -557,7 +557,7 @@ static void rcu_exp_wait_wake(unsigned long s) spin_unlock(&rnp->exp_lock); } smp_mb(); /* All above changes before wakeup. */ - wake_up_all(&rnp->exp_wq[rcu_seq_ctr(rcu_state.expedited_sequence) & 0x3]); + wake_up_all(&rnp->exp_wq[rcu_seq_ctr(s) & 0x3]); } trace_rcu_exp_grace_period(rcu_state.name, s, TPS("endwake")); mutex_unlock(&rcu_state.exp_wake_mutex); -- QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation