Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp5690665pxb; Wed, 26 Jan 2022 18:58:52 -0800 (PST) X-Google-Smtp-Source: ABdhPJxinFk3QtjyK0P4pdl/b9wqUY+AqjeoJq3t5IN5mPeqwI4gyl/r9l61xAiAtPR555vKO68u X-Received: by 2002:a17:907:8689:: with SMTP id qa9mr1334302ejc.512.1643252332466; Wed, 26 Jan 2022 18:58:52 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1643252332; cv=pass; d=google.com; s=arc-20160816; b=zcXk3nqSElG+xkPKAGsnM1smiQ5GzVggjnKgOkn+NjRhtaP/B1nR2mqb4YXsJG7Ous z9EbUAF7T5KOx5NteP/dZWXYjpIiD8ive8foqkYr5RVIp+BChT1kJmMZpSUKy3UAKmvg ETvdhNb+RSwS7FgxuRRGKOsv52+89Og5kQLdh8ukegD/JqG94nrnJ/gV07O0QJdqd2tr qEPHo8G0OCmuUC654DDI9EcL0/v1mqONc/BxBcZkUvBTfRUERiCrg0IXIkxUvYE/c+bc vvqFGB7DzDV3At7mnjVs2RH0rnT06GewesDT/AmIFykGB4StkDEpTbT7gxX57PgSjFoh hvFQ== 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 :message-id:date:subject:cc:to:from:dkim-signature:dkim-signature; bh=8EPhp0kXU1pgZYdQ1+Va8IcxIvVGws+w0AGnvyrQPlE=; b=P99wSU5XqIGG/aBTQuTLlR8I7hsJ3Xgxc9mKUb3Cq2fjAi52rXTBVQsWH/1+ZOsNe0 iRHeQc92HzoPZ739Xs1gIeL0UirDaHVcZmazzzanTwDMa7mNlkyl9Ps2KuuaP1cXSeEy pDw54c5WrIs6Acczh1lMEo6dfpjwMkKWswOEachwzaJW9kLBrD29PUIflayRF3iPGBht 85CkyqewdOuhtyeTzfP73NSKclCZguXYg3vk7S4QbnhHeTCbeezeG0B12IvOtEh9XUkH HEaXTF5PKAGW+qKUbkxrYsPSaJ8oCwHBcS6hxvLsvPh4hZ/+g682m8uHJXiOj8LpFRwZ JNfQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2021-07-09 header.b=FzyPb3rb; dkim=pass header.i=@oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=QsOHd4eB; 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 z28si610766ejl.19.2022.01.26.18.58.28; Wed, 26 Jan 2022 18:58:52 -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=FzyPb3rb; dkim=pass header.i=@oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=QsOHd4eB; 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 S231235AbiAZXDI (ORCPT + 99 others); Wed, 26 Jan 2022 18:03:08 -0500 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:24178 "EHLO mx0b-00069f02.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230344AbiAZXDH (ORCPT ); Wed, 26 Jan 2022 18:03:07 -0500 Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 20QKYtNu011847; Wed, 26 Jan 2022 23:02:38 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : content-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=8EPhp0kXU1pgZYdQ1+Va8IcxIvVGws+w0AGnvyrQPlE=; b=FzyPb3rbc7q1207RahYSv6SiJY5UFoyzdHdtXoP2kaUHHlMPohfcNJZLInGNCrwexZ7q 0wVNxupHAcPmU/kOb3fnq96wi9Dirmr9iykaidnrwxAQCmxMIalw1dTbG7NTA7a2QOsv /BhEoYEocbrOO+GNssICfC9hI+KuxDz0Z5DSei9g2EFhZQvP0Gnf3gligf+sSN3U1FMy 8rjwcGTqYd2hMhUKMv501EPeZByizTRFcaf5LJQQAJ0DnU2YSaSK8xcEjpm9IIhj0IIA /VZoGtF770vv2+/RefQbrE0B7oDObwep9ZSY/C4B9oaqDNLwz9hZH1TC6szKhbkgl2ME uA== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by mx0b-00069f02.pphosted.com with ESMTP id 3dsxaaffqa-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 26 Jan 2022 23:02:38 +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 20QMoVHZ151216; Wed, 26 Jan 2022 23:02:37 GMT Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2175.outbound.protection.outlook.com [104.47.56.175]) by userp3020.oracle.com with ESMTP id 3drbcs2njr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 26 Jan 2022 23:02:37 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lAOumSDg7zLdOYBwTSb0dfdlLtm8Fg4oJvSOV7rQZPsPToExWdnrb34H43V6aX5QMb6mIoICCqFdIChx/E/JbbbWmpiXXMVh/HS31sibl+x98cc0yD8Fuoc2aLEANTvVhHlyGxqO0go+AjrHXOzn+rwSmNqcUNtwhcBAWGJfIH6CTG/Y74gduq0HtakBcoC2W94cqobSuqGQLBz4FSDGEePAnnTE/PeZY49RxF6/mfXKZT3Xt0R8LqpMs0SEL344rMqxbnyvdtM7UB2TV+0VNzTMoE3cDCcrtkFiaWRc34ZqrNsT0Z+cgc13eiEqLzPQdp4d9Rvc9tTyy2vuQmwalQ== 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=8EPhp0kXU1pgZYdQ1+Va8IcxIvVGws+w0AGnvyrQPlE=; b=PHe9cmyTvBPy5url2NQUjf/s3e9aXw5WL23SPcNmBWsa759HwF3cedY1nPxtvRdt5Zu/MMh2iZuw0YnE8dCXIpovXWz9f9Fk2QoPucGM+5lDWNfm1VtMdcEfokof10jqs10kQWDRHZ5/2F9QZdWt6iE3ELLDRX9gGabAz2gTUGj1L+Oe+8uFOYZjyaHBFWpz3dSNOVZV89WuVdsRZvgG1JgHAhbJhpndP17sczkppsIEjC+bsFkPxK4AIiy5xdXn2qzDtdQpc37Yc+7widvZMkRzh0dFBuISrA104tzDVYBIxyrUe62fvi+OdHOL2fhu9py8h1qxSRn/u2dwsbfRKQ== 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=8EPhp0kXU1pgZYdQ1+Va8IcxIvVGws+w0AGnvyrQPlE=; b=QsOHd4eBU26EHNiBrgNZS60fZtxTSS8yGNEZ8/li6cFvKf90WI49z7ftHI8UQsYZ8RwQr+pJ1csXptMK4fzpOxpp0bM0jq033hQo5muxRAFD0xrvZE2gacqYITjCqNTj7MwuP5QybUsAcBQh5FH7UGUM4rAE1TlgU/MiEvrPliY= Received: from CH2PR10MB4166.namprd10.prod.outlook.com (2603:10b6:610:78::20) by MWHPR10MB1615.namprd10.prod.outlook.com (2603:10b6:301:7::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4930.17; Wed, 26 Jan 2022 23:02:34 +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:34 +0000 From: Stephen Brennan To: Andrew Morton , Sergey Senozhatsky , Petr Mladek Cc: Arnd Bergmann , Steven Rostedt , Stephen Brennan , Sebastian Reichel , John Ogness , Andy Shevchenko , Luis Chamberlain , linux-kernel@vger.kernel.org Subject: [PATCH v2 0/4] printk: reduce deadlocks during panic Date: Wed, 26 Jan 2022 15:02:32 -0800 Message-Id: <20220126230236.750229-1-stephen.s.brennan@oracle.com> X-Mailer: git-send-email 2.30.2 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: SN7P220CA0011.NAMP220.PROD.OUTLOOK.COM (2603:10b6:806:123::16) 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: 6117f5ca-6a02-4c2d-b26c-08d9e11ff015 X-MS-TrafficTypeDiagnostic: MWHPR10MB1615: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: XMm6SygKwj7aaYfyWe7ZuoGFzzzpNCGyHrtn+mAVdrhDSAfYfPHPeZz9RHv37Ri3Pet65tATRXbkKIyFQPaL78yq8HZphvUfg/ACkfWy++98BIXXT7a6OlbdoS5annaPaVNaMptL9H0kWKrBcYnhteDwqw1nj5Nya9zsbOt9xRWiIXhWM4f6Sd29kwTvQQ2HSYnKHi9aFfp5erIVxJG5Oia8lri7jm+KiDGO2kAuBeHVjrzXM+mk3Yse2uGinn/BvYb7XWvb5CTv1KrfcC0LMdpW8MCKKGC1jigQ8r7pAXuoT8pPd9OpZJ0q3rcpvYGNC11nozo4uRawXdHsItFhfZ3GcWjwtePJBkHKh9zHTBE/osZdEEnty0zUjn/CMwVaA0wQQ485Qp9BVYCBln2UKup7yAV0z9ljUWy1TiiYgFCSoATr7B3NWRQPHjoL7Ld1WcKX0FosCUDW8bWeBVxulnNdyY2VT2JFui9Hs+Mk8Y/3FDUMTPndt4TAQHdoWCJ/slevmZY1WL50E97lUpM/dIEC8HCN81qJOXhNCDKMatQjR661J+pR9IvBN6hZeMaHI4euXTN1H2LhqoSyxfmiuhOjKq8xfq8TPoH+FFjNMPwZGJyqYL83503gwFnb2tz61RhRCCljUP7QP6Eab+7Aba20lAVsVdQgi15peTFkGoH9rpObkn40xzfgzRznmXBQD2Y9yly3ELvu9MG05mvGMA== 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:(13230001)(366004)(83380400001)(36756003)(2906002)(86362001)(110136005)(54906003)(6506007)(52116002)(5660300002)(38100700002)(38350700002)(508600001)(6486002)(8936002)(103116003)(186003)(4326008)(6512007)(8676002)(66476007)(66556008)(66946007)(316002)(26005)(1076003)(7416002)(2616005)(20210929001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-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exchange-CrossTenant-Network-Message-Id: 6117f5ca-6a02-4c2d-b26c-08d9e11ff015 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:34.0793 (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: fbKi5zqRTRbx3PC5BOtpJ3PTy7eagwGH7PEQnxJOo1hKgVN5LQvkgWfcTqi/zaTGqVmvQ3sdK5kJkCTlg0EabW2BeJHnqcplYo2mC0XC4f4= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR10MB1615 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: _6aGNX_lN00LnvAcdcON-fbVMf-kvcCZ X-Proofpoint-ORIG-GUID: _6aGNX_lN00LnvAcdcON-fbVMf-kvcCZ Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When a caller writes heavily to the kernel log (e.g. writing to /dev/kmsg in a loop) while another panics, there's currently a high likelihood of a deadlock (see patch 2 for the full description of this deadlock). The principle fix is to disable the optimistic spin once panic_cpu is set, so the panic CPU doesn't spin waiting for a halted CPU to hand over the console_sem. However, this exposed us to a livelock situation, where the panic CPU holds the console_sem, and another CPU could fill up the log buffer faster than the consoles could drain it, preventing the panic from progressing and halting the other CPUs. To avoid this, patch 3 adds a mechanism to suppress printk (from non-panic-CPU) during panic, if we reach a threshold of dropped messages. A major goal with all of these patches is to try to decrease the likelihood that another CPU is holding the console_sem when we halt it in panic(). This reduces the odds of needing to break locks and potentially encountering further deadlocks with the console drivers. To test, I use the following script, kmsg_panic.sh: #!/bin/bash date # 991 chars (based on log buffer size): chars="$(printf 'a%.0s' {1..991})" while :; do echo $chars > /dev/kmsg done & echo c > /proc/sysrq-trigger & date exit I defined a hang as any time the system did not reboot to a login prompt on the serial console within 60 seconds. Here are the statistics on hangs using this script, before and after the patch. before: 776 hangs / 1484 trials - 52.3% after : 0 hangs / 408 trials - 0.0% v2: Each patch has minor updates from code reviews. I've re-done testing and updated the above statistics. Exact changes are in each patch. Stephen Brennan (4): panic: Add panic_in_progress helper printk: disable optimistic spin during panic printk: Avoid livelock with heavy printk during panic printk: Drop console_sem during panic include/linux/panic.h | 6 +++++ kernel/printk/printk.c | 51 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 56 insertions(+), 1 deletion(-) -- 2.30.2