Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp5689923pxb; Wed, 26 Jan 2022 18:57:17 -0800 (PST) X-Google-Smtp-Source: ABdhPJy3Qmr0SAgu3psZKqW6Y8W19bGBaF7jpUtetNGHEdaAm1hAKj9YLmtd6EbtycImUhwAQnEr X-Received: by 2002:a17:906:7948:: with SMTP id l8mr1359416ejo.752.1643252236852; Wed, 26 Jan 2022 18:57:16 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1643252236; cv=pass; d=google.com; s=arc-20160816; b=ia/cUT6RBugT5BUT4kAbMkJKC1smSMJQkSKNwuUvRqJUQsg4rTp9BpVSxN1iNkhGYc 1fzJcGOFRTI3B8k79qMmpRqFQQqKfH65ailYEP84ymzV3YDXnw1Mp+uHAFcqMDpQo8SS 25pc5fE6/Ny2tWVBD2JlHyxah6xlm0f43eMtvgMI6RpKTuXXb7zI8mv+PMxFuVAKiYnR uOajvRpPs8H9ovzjHtiB8hNij4oDx9eKzI6V/wzx/BfjWZRuaEtO3fbM2NYTIKaTaO5a CSMWk8toU47UB8k/+HkR/P4z8nj0Tou4MWgeSOkmYlQo5mkq9N8Wy/A/QvpcON1nU+H/ Hwvw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-signature; bh=7t9nsNPOCsT6BFjau8nOqYco0RpwwaQjb1rKk3ztWq8=; b=olb4lLRMqGI/M1fnhU6vWIh2rWeD8VbFd37V+7lwC2TxkyBGQq1qhFLq+5Kuj55k7v UJIMVO40p6eh3IyeIYW7+R+pOzSx4SJc1yOgLs97tjqEdD7bEYijZXajEF0j9R+jv6qs XSTamIPPQFbs+gQb07uMzJi51weqqM5cisEzOIaXNqy4v7YzXdMlUlx5oxaUKDlQMnv6 g3juPbwBj7f5IttaFUatNKerZdfttZWL1u6dKCyqUtU1qjQ/wYx3EiS1U5e7zZE/+A/w RrhATtS00a8blRPdNV9bXaWpb7LJTVsJA9HYUAQ3olrLYw77dNdgizssDTwsImAAK4zK Iz9A== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2021-07-09 header.b="k/K0tECI"; dkim=pass header.i=@oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b="c2W2u/Jp"; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id du9si781236ejc.997.2022.01.26.18.56.52; Wed, 26 Jan 2022 18:57:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2021-07-09 header.b="k/K0tECI"; dkim=pass header.i=@oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b="c2W2u/Jp"; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232957AbiAZXDN (ORCPT + 99 others); Wed, 26 Jan 2022 18:03:13 -0500 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:31106 "EHLO mx0b-00069f02.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232803AbiAZXDL (ORCPT ); Wed, 26 Jan 2022 18:03:11 -0500 Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 20QKYoME016826; Wed, 26 Jan 2022 23:02:45 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=7t9nsNPOCsT6BFjau8nOqYco0RpwwaQjb1rKk3ztWq8=; b=k/K0tECIvON7KCDhW+22RYvtRl1tud5hrf9vKYVS1WCfdSuVbr3gam0P8GiV+t0kZkP/ NqUDR5phzALSuWmyli7Ffl/5aSxDNjzMDJjAQcK7nTnmyUkJ8ZWy180w9Hx2GOmy9SuN 3zGIoMSWBoBOH5VePeKBd8y0i63XmHFDSrzfbHRZV7jRNgxHurBE8f1UGaKkZXnTQlPr rROPGvCKUTMaNkB5KsPlV2mvFgA7sWusAl52aWsShylYmhXuDkm5CtUpatzX+ptnmv6O if8u8FjXHBmMP25cTiTlJINVfsQ19JAH5SiqUH6uH5nMcSsGUMwTGw9vl8OsgS11eg8w qg== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by mx0b-00069f02.pphosted.com with ESMTP id 3dsy9s7eer-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 26 Jan 2022 23:02:45 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 20QMoU8V151142; Wed, 26 Jan 2022 23:02:44 GMT Received: from nam04-dm6-obe.outbound.protection.outlook.com (mail-dm6nam08lp2042.outbound.protection.outlook.com [104.47.73.42]) by userp3020.oracle.com with ESMTP id 3drbcs2ns1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 26 Jan 2022 23:02:44 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ti/IEPnr89WyeX3zOBAoiaxVfkJuzg+TdIzmtF100XPxkj9t7feYA6BfNraKVZO5tyc4Cwd0LFIu3/yt9GlcRUD1WWsmyhMbiC/4Uvmqd5CvI8MQj54Timn3hY8wbmHU4/ay6lMPts46x01Qo1FgKFFeIPv+jCdYaJQipqhNfbIMd23H3KTsj7gqSE13NKBiYzXqVm/MqWJM9bFuMKmOP2orMshCXl175JPJZeG2mMJWkWeLBXSVzjh6kYFEqjDGWzBCLsklC8jIg+rNKqIZOO04Bz0qMRxpzisSRh7luWma2WQDjtiCnASPkAUt9K8PrMnHIIElR+YDqHgqS0M72A== 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=7t9nsNPOCsT6BFjau8nOqYco0RpwwaQjb1rKk3ztWq8=; b=PefhNobTLuChIfDSo6UU3KlN8PSk0MNBUhix/NNfmYBXVSEZMtMEvMOI5T5B+CjyYsv03uUiDEUSgjq3HDIBLhCKEzw1EmHAAWxtHI529wMgR+9ofG/g7YJWqrO+fkDjjEXjyi12zkOpc0W+uA/es5787u5eECc6Dcuvw34qRPDYOWvd2V6eO7kreC3OXn5osPlKaYeASsae0fEOlIhlodc5vX91drXMJblaZ9NAjD2hiIm2OKE3uIuGXBoUxUys29KwpYLBkHxkITZvEvAD54YgbVx30Q1KxfgZe+dZuvimaHIbWDudykgefht0ohSAhLr8sHEXGin9WvEwBLCtRw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=7t9nsNPOCsT6BFjau8nOqYco0RpwwaQjb1rKk3ztWq8=; b=c2W2u/JpP03iQE5Cpq5F4oyoAr4nQaXjZbDYTLgbQJxoiItl0FP+EWGlMSxujVLMdYVIXB/+WHawUx9JYh3GC2Rc7Z5kfhaArObtgnb1yQHBdwZ9ObCSP8JzHtbwWVg2S91CBiV/um4WynwXnTUl0SOGLTvpi08nVjeJnrg5KFY= Received: from CH2PR10MB4166.namprd10.prod.outlook.com (2603:10b6:610:78::20) by MWHPR1001MB2350.namprd10.prod.outlook.com (2603:10b6:301:2f::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4909.17; Wed, 26 Jan 2022 23:02:42 +0000 Received: from CH2PR10MB4166.namprd10.prod.outlook.com ([fe80::f4d7:8817:4bf5:8f2a]) by CH2PR10MB4166.namprd10.prod.outlook.com ([fe80::f4d7:8817:4bf5:8f2a%5]) with mapi id 15.20.4930.017; Wed, 26 Jan 2022 23:02:41 +0000 From: Stephen Brennan To: Sergey Senozhatsky , Petr Mladek Cc: Arnd Bergmann , Steven Rostedt , Andrew Morton , Stephen Brennan , Sebastian Reichel , John Ogness , Andy Shevchenko , Luis Chamberlain , linux-kernel@vger.kernel.org Subject: [PATCH v2 3/4] printk: Avoid livelock with heavy printk during panic Date: Wed, 26 Jan 2022 15:02:35 -0800 Message-Id: <20220126230236.750229-4-stephen.s.brennan@oracle.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220126230236.750229-1-stephen.s.brennan@oracle.com> References: <20220126230236.750229-1-stephen.s.brennan@oracle.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: CY5PR18CA0014.namprd18.prod.outlook.com (2603:10b6:930:5::13) To CH2PR10MB4166.namprd10.prod.outlook.com (2603:10b6:610:78::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8eaef3a0-9e9c-432b-dd81-08d9e11ff497 X-MS-TrafficTypeDiagnostic: MWHPR1001MB2350:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Hzxf6Gko7aaUPj3SQcn27IINvBUUEOLDpke8K8nstjXODA1QG01/4DI1L3X/iTY8PeyvVYvlc9Wl3VWGeCpxX+XpG9q4hoFAr2cH5qrz6B8Vp27hy38aG8km8t6/SaPdFSosm/w+FQW/UBkoVV2y/YOTiTv+va8xy06OOnxvfo6gOIAFZuPR61F00quy3r5JJ1pbBHzGx7nHHruvh/p/J9jKXmwVHxOmQT+VJFE8nI/lxA9wBjG8EH9eR89JlCa/IRVoCi94MbDSHPhUMhHGeyFNn7xLyCH+YJ5k+G5TLihboKwykuR0cPpSKg9QV7/WBPqWgg8M9MF9Aj+GU0vXXp4/Vy1sI26ew7a2peDdLd2LEWBotjSlF5NIA4Ip23KAmXUkNkdwgv4HK/YHeMYdQOXTtFpYt9Bt52NrQECLby2eQA2t4zc9mbAO2mKdZLzCFq/bu1PFzqctjJTqV2HBsQjcYzZSdcqtS8SHwWr00AEILgbz0TJKg0ogujiSFHO2vvXXn0fzUYqFgfkmBqGLwrd5CkLKgfOlpz7z8+KgQluPyfOI20CjjJANlmmVEgnx43LiBTosfc1havhG21I5MWKMOPprO4S7MCnNa55zuVXSRrotdcrmxNl2Xr3DfFW9xMp+gvbzV6FKuXHlDiT4+0KIiVvWIICOm1nXZbhwQG1cG3ZJt8TrhHFTzfxo5vzy7JgRmGkLJu2mSzvjzHaL6A== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CH2PR10MB4166.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(366004)(66946007)(316002)(110136005)(54906003)(4326008)(5660300002)(83380400001)(38350700002)(1076003)(86362001)(6486002)(6506007)(36756003)(186003)(38100700002)(26005)(8676002)(6512007)(8936002)(508600001)(7416002)(52116002)(103116003)(6666004)(66556008)(66476007)(2906002)(2616005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?w0N5itHM6dQKtWQVTSUV+ISXEmcOJY+H5dYVMRGHtFvuyB/7psHiXRnGQR5X?= =?us-ascii?Q?I3gy2kfHdJMKNMhyIY0V3AVbQH4POcT3lAl7cgIyU+j0OACKkDklXz6npfEq?= =?us-ascii?Q?CL9zrnAlSkcHHiM2ZS3Az2swQI/sduCfl2NEKz3mlpS8eisNP6KJ9KjXhOM5?= =?us-ascii?Q?VBtEUoRFUzS2vtb2CJw8QNrScJXryxLGHJWHy4QyU4KiT8vzSaZ/M3yTR1i6?= =?us-ascii?Q?pMmIawTI5OR/fQv5IheO8no+JM1KC0QKshiyGZM8Fc7UNvKVQSul0zgcxj0X?= =?us-ascii?Q?HEYXuybki0BVbTzJ+jV8I/fMXb0g41tjnmcVWNHqDFXICJixQtW+m2FSpqU8?= =?us-ascii?Q?tM6c7QrLIWEc+m+l/rXYxAmHl9ryP9gK+KyhjrgDqciSHUT099By+eFYF+TO?= =?us-ascii?Q?S+PRG3EnEFnEu4EAcYn5mI7s3BQoIgGN33pwew7JlAn2EnbG53cDIQV1hd0g?= =?us-ascii?Q?URdVMzH0DXf6hrlGlkgN3Acv+s6zJIlRVP5Z3gBopQPQoPPNg6vWqXpzgD8K?= =?us-ascii?Q?oUKR5BfZnWf191hnPnSiOGpq8o8qtWMPy4Oi0Fu46sSk2pscflBpoHqLG5Hh?= =?us-ascii?Q?K97xkGRtJRomorQMsu47cB+xENhr9zbggxN/xcAQ7C+M58Tmq/9qS8/O1/gu?= =?us-ascii?Q?Nad8RZUbVTKlYbzhdT/aS8TH5lhh6AjQDrBRp5SurUB5k4r7M3nrJVi33HQ+?= =?us-ascii?Q?4arcqrq1dYQ+f+kgWjF5leuOLbp+TyF1yDXnZoAp89f4XisTt6EoWWyOBkkC?= =?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GdyjxV0N3Po/OevcCRvkTiHYVZv73ZpJ6jjaO?= =?us-ascii?Q?QQmn0A=3D=3D?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8eaef3a0-9e9c-432b-dd81-08d9e11ff497 X-MS-Exchange-CrossTenant-AuthSource: CH2PR10MB4166.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Jan 2022 23:02:41.5495 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: sciBIcjlgdSeY1r4Nw8ukkxI8DAbzVuyVnjaG6Q1j0aiZEoXJBVCM6aHnrGjfg/vViGyCIdChz09LEyVnIBeTxmmNMTmptsbLz41ipvOO1I= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR1001MB2350 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10239 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 mlxscore=0 malwarescore=0 spamscore=0 phishscore=0 suspectscore=0 adultscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2201260131 X-Proofpoint-GUID: FLJHGdGniEs560aZ9QWlUNEJzGbLD0P4 X-Proofpoint-ORIG-GUID: FLJHGdGniEs560aZ9QWlUNEJzGbLD0P4 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org During panic(), if another CPU is writing heavily the kernel log (e.g. via /dev/kmsg), then the panic CPU may livelock writing out its messages to the console. Note when too many messages are dropped during panic and suppress further printk, except from the panic CPU. This could result in some important messages being dropped. However, messages are already being dropped, so this approach at least prevents a livelock. Signed-off-by: Stephen Brennan --- Notes: v2: Add pr_warn when we suppress printk on non-panic CPU kernel/printk/printk.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 20b4b71a1a07..18107db118d4 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -93,6 +93,12 @@ EXPORT_SYMBOL_GPL(console_drivers); */ int __read_mostly suppress_printk; +/* + * During panic, heavy printk by other CPUs can delay the + * panic and risk deadlock on console resources. + */ +int __read_mostly suppress_panic_printk; + #ifdef CONFIG_LOCKDEP static struct lockdep_map console_lock_dep_map = { .name = "console_lock" @@ -2228,6 +2234,10 @@ asmlinkage int vprintk_emit(int facility, int level, if (unlikely(suppress_printk)) return 0; + if (unlikely(suppress_panic_printk) && + atomic_read(&panic_cpu) != raw_smp_processor_id()) + return 0; + if (level == LOGLEVEL_SCHED) { level = LOGLEVEL_DEFAULT; in_sched = true; @@ -2613,6 +2623,7 @@ void console_unlock(void) { static char ext_text[CONSOLE_EXT_LOG_MAX]; static char text[CONSOLE_LOG_MAX]; + static int panic_console_dropped; unsigned long flags; bool do_cond_resched, retry; struct printk_info info; @@ -2667,6 +2678,11 @@ void console_unlock(void) if (console_seq != r.info->seq) { console_dropped += r.info->seq - console_seq; console_seq = r.info->seq; + if (panic_in_progress() && panic_console_dropped++ > 10) { + suppress_panic_printk = 1; + pr_warn("Too many dropped messages. " + "Supress messages on non-panic CPUs to prevent livelock.\n"); + } } if (suppress_message_printing(r.info->level)) { -- 2.30.2