From patchwork Tue Aug 22 07:45:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Qian X-Patchwork-Id: 13360310 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5CE02EE4996 for ; Tue, 22 Aug 2023 07:47:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=1tuO84iNntNFSD8TDBA7dNND0AmAibVZXmI1ypiIkaM=; b=3bIrybfLkgywpM Tymifzfk/kfm/Q4eXGWeTmK3Tl7zBy+cD2FT1MbZLHu6gJ4IgB315Ok94CS+DGdUeQe4aUTUGnibs EsL5gsI4A5DUesbzQ9+1ZeA+DrdDe3QeSrok7b+v3DUk9bXzBaEI72zkBnPzhergA3DdHqr1RgeWH O1wssWrILUApT596DCkj/CHLCx0LLo7Zn7kJl+MNqsFYYdKjlUeTCiwql0PAiN2RmaFXsYeagyetb HTGrcUzRUydDftmL+kHQsUpQj2Rkap2iI/21/0dQC3Pu4EOV5aaNaA3i095JurU7uDxIk69/NlVBR 7suEgyfFc5iDqjIF796A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qYM6A-00FNwt-06; Tue, 22 Aug 2023 07:46:46 +0000 Received: from mail-am6eur05on20624.outbound.protection.outlook.com ([2a01:111:f400:7e1b::624] helo=EUR05-AM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qYM66-00FNvU-17 for linux-arm-kernel@lists.infradead.org; Tue, 22 Aug 2023 07:46:43 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FbRCS8eCqU0b/QxSkub4MQx4FRgdzjd8YJCYwKMSXab80YJRDaaKG4clWJV+1CJofbz2AHRRoVfqNIMmYuO8qXPU7Gz5VW4zMj9m0e29W5RteSh9IMon5OE6vswCoP9GFAC8LeauqKMUxm/afiVkRMA3ABs/N5OSb3NKkOspH1+TfZ2MnFWNV6nPIAzXSJlCxjt+gvgG5zrmwoigxaLQZlrfSKvfucoPO8JwhF+sp/1WXblpKC096ppp3tLquye08dzGhDBzfQ9qAonocl2DSkIOcxIvPThuCe09e7Z3BxuSt3SmmK0FBzM45sjccThPGIJa02X9ECGgZvP1cPfHRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=C+GOmL4frijaYZHKD8WiXFppO1VhDpzcsWAqgOwwBIs=; b=nJQzihlfz/0vhkap6dyTPE5mlQ83W4K3j4d1DpH5+ukvdqqHfQKCOYn613KCAActQESollpPe4b0ExZXYx3GxR2w1B3l0dowts6KnNy7AUwEq1JDX0TPtneBcY50RvX6jWzeNhLe2lGRDLbTdAU98ZGsTd8oeTAbGhKLJS9bWOHC2spT7jGUiJU6Ynj6hF+zdG5W4yhfb5s793QFGBq1B2P67bLpHDGh5ai7sTLoyg80t3ynK8iMIMpxfVs4DOFniXxAl/RyRkmJCUyEAf1yVy0ko6CGNIMjr7S2rRvQEAizG+Moz485yB/FOESuDqV+tIWC0knPK1P1U6cEw7iGvA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=C+GOmL4frijaYZHKD8WiXFppO1VhDpzcsWAqgOwwBIs=; b=Vge7kgkzgMfwtzrFtREVCH2+TeCXyIjvu7xjixJ8YBzfTwSI63JXQBNqkfrNu4Qvl9V4bDhj0YVYmHYRWmJGBpzg1JuEcziNZhfhfOFD+SJZtnbff/X831mW1/i2ZWZIX78yxzjlqLeZ92bC4Omz9gus5XaA3v/eZJM18v12HUY= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM6PR04MB6341.eurprd04.prod.outlook.com (2603:10a6:20b:d8::14) by AM9PR04MB8082.eurprd04.prod.outlook.com (2603:10a6:20b:3e8::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.24; Tue, 22 Aug 2023 07:46:32 +0000 Received: from AM6PR04MB6341.eurprd04.prod.outlook.com ([fe80::613b:e94b:4ccd:f55a]) by AM6PR04MB6341.eurprd04.prod.outlook.com ([fe80::613b:e94b:4ccd:f55a%4]) with mapi id 15.20.6699.022; Tue, 22 Aug 2023 07:46:31 +0000 From: Ming Qian To: mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com, vincent.guittot@linaro.org Cc: dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, bristot@redhat.com, vschneid@redhat.com, eagle.zhou@nxp.com, tao.jiang_2@nxp.com, linux-imx@nxp.com, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH] wait: don't wake up freezable wait by freezing fake signal Date: Tue, 22 Aug 2023 15:45:47 +0800 Message-Id: <20230822074547.8037-1-ming.qian@nxp.com> X-Mailer: git-send-email 2.38.1 X-ClientProxiedBy: SG2PR03CA0131.apcprd03.prod.outlook.com (2603:1096:4:91::35) To AM6PR04MB6341.eurprd04.prod.outlook.com (2603:10a6:20b:d8::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM6PR04MB6341:EE_|AM9PR04MB8082:EE_ X-MS-Office365-Filtering-Correlation-Id: 00dc79d0-1154-4495-1313-08dba2e3e6dc X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: KkPTsm83buCaeLtxSKGpV2JOP26bN7jYqPUM+rzO6QRo4WKisOwkJuoU99haRHj5u4j4l5lWzin68R5BvmLn8lwl9M/1z2zn8GaFXfdE4F5ub0QwC5Iazmp8DYCQ8AWGS4jfllA5Cb9pfmU/RRe3Z5/5RADli5meWn5gtQNmEoE4EcQ6BdOiLqK/hjyXdQTJUbGH94KmI76ReFF2tkrlk+kMzJU5UM4GFgdMd/JoQk+Ah+TNkLbzVQLb3M0RyF9bMNfzJIBvMNhEjJS1M0LrRGhNDEzStiGGncqAIr9bwrNlgKnab0RV0eRj7DD0LRaTOqIZ/V8BWgseNekfkIMMT1wSru48Lw1BW/qtI5D3IGwUk+QtJTJzpOauw+QfFEEmLoru8OBGR/YFElFN2wnWa82E/aXk+XXtcyCeYQfad4th8S8/g4WkDxA2Rg3niLF2mlOaPay2ruIXWqRILQ98p+8Q2irjP9s0kqDyk4+AlZyuMjqtvl6MU8FFICwgDLGvFfL6a1PXk+Ukng6AeMf8gL4cL7I7YTzrTcMHdddjCDoe7AaD3rv1U/A65Atic0e6TFJPwr3tBRzMcVJIMXhfKa8RGorA2TgIyaU0PmxM8OFcMT3bvjx4IMXlmpLPNGzB X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM6PR04MB6341.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(396003)(136003)(39860400002)(346002)(376002)(366004)(1800799009)(186009)(451199024)(66476007)(66556008)(316002)(66946007)(6512007)(8676002)(8936002)(2616005)(4326008)(36756003)(41300700001)(1076003)(478600001)(6666004)(38100700002)(52116002)(38350700002)(6506007)(6486002)(83380400001)(2906002)(7416002)(86362001)(44832011)(5660300002)(26005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: b8OPJxzKaCXd2ctf70BRWHAm8Nomk9e9+IwQTZ507A7h+4QdGip70FmG24AjRJgLh8FTvs9iBaTS505d5LhDA8TL35zak/vIB/dnJ1a0nCQHAy+SLotiQcqR7joRCPFNL4KOQXhbluKI/lxoQ/glVZmjz8+4Y4MlkJSx8/eGPzHS4xKaKWojpHAj/DSyAOl3OB9d62l3AEs1VxyrMb0O8UuXw4OmZSZrY5KPIKYnwGLO8oMqFU58XCXB3cIlq5hf3WlsR8Cn5KQQzp/CV3bJASgMbsaSnMgLvgBuSSIVPjgUQaT23h/N/SEaSnMEyUy1S+d55TBonpnexjekTHjy97WRKs9GcXd4Bju65lhryKS8lVSYRnA/VrGw+U2Kh/Lg0eD1b146dJY/yz/nq9IzkcWlng+0Gctkf3ZG6x6YbNSWvUsgkfEk6tO1oFz+aWcDz4b6UgPe5re5s5U84i07K5KXZ/uyy1oERT2Pg6Yvfb4BA824WFNINIszqSYLbHMtdRE2UXfSn1v8djfIO807GDvJgPr5cd0Ma1ERMbEWcReDxpj3AbL9is20yrOEnf31p0gIduT+B1+sKcZDho7q3XpPg5X/veMECoJU48kGpIwbrPN+Uxad+/bZipMuue4GigiiOjx4BMOY22ZbnvqaAKfvGoLAVM8Zfsy9lRrimaj7QNslyPj1+0yYSV7XXLj1v2ZfNLqhA8U40KRqKnGkVq4SahfA1dsr3/1ss/ZZKxnrDZAqsdM4uys/fcBFB+qq0MuABkbN0xXFd+j/oePrl+WXEro/ilbAqM+tDBDxQ0V9XswpZ+3Jm2lJPVBB5OFAN1RSzRcRHN6bGf9MVSFPVqXjWXNHXWlbnRWeD7MPuIpdJhascoTyS7dTWMVYh3FMUmeP5UZWsMd1eN6MY4ujIYGOAANXJiqb8pf46uw4OX+qCfho7mw8cF1yo2RciG1nFG6LYXiD5MaqxCepNzQGR0gBlNj9dHR5kP8XDYX+pDahSqMf48TlZa0cYYSPETcwh3Od2JbOG7Q21aam0R3zp4d6/xY3mYpdRFAdYwVXaLBZrBf9u8kM3AfblLricrWOn3vAUBxGXxIomAvP4OB2DdPOupdtkDUMfKtRVkOaL1Yzji9qXp++QXTTtxcavZw9rOC0yF6mUBjmQAzt25+VEBANAI5JtyN52pWyfL540nZh0hEXwckrZI/3mqf+8IE/jEzYLCcFUkFcdHqk6G5T1BwSEtxZjRdy3P99Qpajlr3z3b8HIdkoeb9Y3bq7TfvejtUDB54tHpkcWkvPER7s54plBavmWfr8S+zIjVmeLCGJHTQZB1/AqF5tDLfd8b5PbCCmMi9dqCmc8juicQ9FYr2AsMVwXunICpuw0m9VbcooKQ8cveykzQbuJNKsk/gxds2p7iqNfNDEMvEY2FmwYm1vcPOSbKaCRxqdtTlJ4aHYRbqDz5oC2l5w+z52deYQYLcELi6NtjKSMShPAM3HRMFisF8Wdjz5VoWJe+3hayMu07Mr4Fl+oXw7CmVLhZUIRYjYjKCamL670N4bM8CnQS0AYQUaV6Z8ut6fEzq7ngpIMQGSYXzt6/6gTwhu4PpF X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 00dc79d0-1154-4495-1313-08dba2e3e6dc X-MS-Exchange-CrossTenant-AuthSource: AM6PR04MB6341.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Aug 2023 07:46:31.9458 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: vlLBJtcCME+Gmqch1zTaV6sXqp83/iNYWMIBvIzsfuYTc9BsA7FIsEdSwACRjoMEH4E0vduLI69YRsyFiVKcQA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR04MB8082 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230822_004642_386723_6787C8B9 X-CRM114-Status: GOOD ( 13.39 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org kernel may try to wake up task with fake signal when freezing task, if the task is waiting event using wait_event_freezable, it's better to freeze the wait, instead of breaking it. otherwise the caller may need to retry the wait, maybe like below code: if (rc == -ERESTARTSYS && freezing(current)) { clear_thread_flag(TIF_SIGPENDING); goto again; } Signed-off-by: TaoJiang Signed-off-by: Ming Qian --- include/linux/wait.h | 9 +++++++-- kernel/sched/wait.c | 14 ++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/include/linux/wait.h b/include/linux/wait.h index 5ec7739400f4..975ee67f259a 100644 --- a/include/linux/wait.h +++ b/include/linux/wait.h @@ -287,6 +287,7 @@ static inline void wake_up_pollfree(struct wait_queue_head *wq_head) (state & (TASK_INTERRUPTIBLE | TASK_WAKEKILL))) extern void init_wait_entry(struct wait_queue_entry *wq_entry, int flags); +bool freezing_wait(struct wait_queue_entry *wq_entry, int state); /* * The below macro ___wait_event() has an explicit shadow of the __ret @@ -314,8 +315,12 @@ extern void init_wait_entry(struct wait_queue_entry *wq_entry, int flags); break; \ \ if (___wait_is_interruptible(state) && __int) { \ - __ret = __int; \ - goto __out; \ + if (unlikely(freezing_wait(&__wq_entry, state))) { \ + clear_thread_flag(TIF_SIGPENDING); \ + } else { \ + __ret = __int; \ + goto __out; \ + } \ } \ \ cmd; \ diff --git a/kernel/sched/wait.c b/kernel/sched/wait.c index 802d98cf2de3..37c3b2bc1fc9 100644 --- a/kernel/sched/wait.c +++ b/kernel/sched/wait.c @@ -5,6 +5,8 @@ * (C) 2004 Nadia Yvette Chambers, Oracle */ +#include + void __init_waitqueue_head(struct wait_queue_head *wq_head, const char *name, struct lock_class_key *key) { spin_lock_init(&wq_head->lock); @@ -484,3 +486,15 @@ int woken_wake_function(struct wait_queue_entry *wq_entry, unsigned mode, int sy return default_wake_function(wq_entry, mode, sync, key); } EXPORT_SYMBOL(woken_wake_function); + +bool freezing_wait(struct wait_queue_entry *wq_entry, int state) +{ + if (!(state & TASK_FREEZABLE)) + return false; + if (fatal_signal_pending(wq_entry->private)) + return false; + if (unlikely(freezing(wq_entry->private))) + return true; + return false; +} +EXPORT_SYMBOL(freezing_wait);