From patchwork Fri Dec 23 21:15:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frederic Weisbecker X-Patchwork-Id: 36338 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp509702wrn; Fri, 23 Dec 2022 13:16:14 -0800 (PST) X-Google-Smtp-Source: AMrXdXsJ6Dw/bAb4aYgKC0wtaM12gl/vHJiC1L1cfJpLETrzO8YHH4ODZOjPdhfkZTkZxdE6IinG X-Received: by 2002:a17:90b:4fc8:b0:21e:1c8e:f791 with SMTP id qa8-20020a17090b4fc800b0021e1c8ef791mr12060104pjb.31.1671830173770; Fri, 23 Dec 2022 13:16:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671830173; cv=none; d=google.com; s=arc-20160816; b=Xtcfq7/DQaVuhNneCWu22NOcoDYLvUmHx6wnPw4h7xcijBvXlhco/ppSwLBkqhkMNZ YYLk1uyFBbL7C+tZFLdBaq5JM2Sf2J7eNjJfNLOqVB4sYmAbvKUMXWeaa0SyGDzNg+pf 6VoduQ0i2FNyQFoHvPO+/psqI2iP0Pw7uInItFxN5W7ZPbfOZXTjZYrfYKgl3cW2XphU 6xyaBmzbZB0UjcaC4+WcAaegAje5VHgy1RIYV6s0WhSG0k5LsGwItS5Hn2i4ki+S++iT Mz8r8NRwVbpiCSHlSH4UngqaQBZLWRVBhE97Qp1B5a/YozwMTgMkqtMYP6c9CxXwi2cw 9w3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=96lY20R0EjqS8CVm07QUQpFhFlHk860jHE+6QyXHQV4=; b=H3TItfArLKlOePjmzU2fAUroggh7o9KrXOCqtsSKuweMxHT3yW4bVN7OCMv6UWyTcu eX802rA/AH5iVMF9kIt5TG49cukzLQKLUNxQUdjeMMX8sHHEDZ/b4IcTpOW0/E3nd5Bz dhrgWy+J1Of8ERcFpbixkmVe4luJqdK8CeuvmhTcZO5OyclgXVW2gYTM2+nD5dxp7u6x SMdMdbJo7DyutWfblqWXnN22lmUfVs9H3rjFWQ+FMiNgkxMh3V5E5RQ6SweBkR4XC0Xg 4R9OkBqoIUpgp3szoHtvcZiln0xKttmupdE4qEq+31D/aNHkj4Mhh4jv/4nlq7pCbVs9 SZ3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ogqwyKef; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id mw7-20020a17090b4d0700b0021a04add441si9006067pjb.104.2022.12.23.13.16.01; Fri, 23 Dec 2022 13:16:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ogqwyKef; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230515AbiLWVPQ (ORCPT + 99 others); Fri, 23 Dec 2022 16:15:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33118 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229650AbiLWVPO (ORCPT ); Fri, 23 Dec 2022 16:15:14 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 03FF1B1FE; Fri, 23 Dec 2022 13:15:14 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 95C5961842; Fri, 23 Dec 2022 21:15:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 86FBAC433EF; Fri, 23 Dec 2022 21:15:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1671830112; bh=hMpQQNYK95cKuQwDk/zAG80cKOmSryIgdedTMIx1SF8=; h=From:To:Cc:Subject:Date:From; b=ogqwyKefV3Obx8cU+3fu5TsIGJETglAJ6stHhNCSa7k2Ry5Ba9OB9yJgD7+sRMTcc apPnpnaamAHiM+C2tqxA2W05sPQ2rbUuegF7z4L0B1zmcjpvA3rQNgb/zZuPAfupHA h7qI3PvX2RFVdJDt9QAKZLn78C0xRh4rYSXQ09F/5GbdRFSrDNyIK3lAdvOcSOd3hm 2TKI9JJnqMGOX5XYxrLZMwoNvsgM6L7iCDfxFilrODBFEgi+EDLtfGHGuthR5qkj6J CE+YJyLGYuAUtaJND85aYHT1H22Z1Hbrd+R6Qo467nOggUInxs3da7mOATmZslH8e6 Gt8azMO2vCY2w== From: Frederic Weisbecker To: "Paul E . McKenney" , Thomas Gleixner , Peter Zijlstra Cc: LKML , Frederic Weisbecker , rcu@vger.kernel.org Subject: [PATCH] entry/rcu: Check TIF_RESCHED _after_ delayed RCU wake-up Date: Fri, 23 Dec 2022 22:15:07 +0100 Message-Id: <20221223211507.84249-1-frederic@kernel.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1753040996318595828?= X-GMAIL-MSGID: =?utf-8?q?1753040996318595828?= RCU sometimes needs to perform a delayed wake up for specific kthreads handling callbacks offloading (RCU_NOCB). This is handled through timers and upon entry to idle (also guest and user on nohz_full). However the delayed wake-up on kernel exit is actually performed after the thread flags are fetched towards the fast path check for work to do on exit to user. As a result, and if there is no other pending work to do upon that kernel exit, the current task will resume to userspace with TIF_RESCHED set and the pending wake up ignored. Fix this with fetching the thread flags _after_ the delayed RCU-nocb kthread wake-up. Fixes: 47b8ff194c1f ("entry: Explicitly flush pending rcuog wakeup before last rescheduling point") Signed-off-by: Frederic Weisbecker --- kernel/entry/common.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kernel/entry/common.c b/kernel/entry/common.c index 846add8394c4..a134e26b58c6 100644 --- a/kernel/entry/common.c +++ b/kernel/entry/common.c @@ -192,13 +192,14 @@ static unsigned long exit_to_user_mode_loop(struct pt_regs *regs, static void exit_to_user_mode_prepare(struct pt_regs *regs) { - unsigned long ti_work = read_thread_flags(); + unsigned long ti_work; lockdep_assert_irqs_disabled(); /* Flush pending rcuog wakeup before the last need_resched() check */ tick_nohz_user_enter_prepare(); + ti_work = read_thread_flags(); if (unlikely(ti_work & EXIT_TO_USER_MODE_WORK)) ti_work = exit_to_user_mode_loop(regs, ti_work);