From patchwork Thu Nov 17 01:28:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Jordan X-Patchwork-Id: 13046015 X-Patchwork-Delegate: herbert@gondor.apana.org.au 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C2120C43219 for ; Thu, 17 Nov 2022 01:29:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230103AbiKQB3b (ORCPT ); Wed, 16 Nov 2022 20:29:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35770 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232983AbiKQB3a (ORCPT ); Wed, 16 Nov 2022 20:29:30 -0500 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1B63945A17; Wed, 16 Nov 2022 17:29:29 -0800 (PST) Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 2AGMiDnI010256; Thu, 17 Nov 2022 01:28:59 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-2022-7-12; bh=euxkXEoRAY7xnDK5NayvCNU49ShH2JwVZkcet08Vaeo=; b=HT8gBU4X8l09tzG5dfmiJm1VxnMOTBa11Ke21sD+lEZM96KD3y3hIJwgnRJloK3bX3oQ 1Ume67bb2YzN9qHENWBcMTf9DO/o/pSuVhV3b2TWBt1VAAtElznGG9600VtTLkA0vOsC LMRiWbHW0W1lOJP6VuBWV/NnyUd8uMnKZjTi07n1HZag1aETDlMbG6YnnOh0cfbYX0xq cRe43URU7iI7jGKG1t5PpOx+HMRDoRDXhd/TACKhP0W0h4i65/2ZKn2GXFUpNSm2fOX6 kLF3ZcHaj5CnD4Z6OlHRhF5718e4Sf0VnlamQRpx5+s9yR4wZ3q+qy+oQVUhEH28XMxt lw== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3kv8ykpmkw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 17 Nov 2022 01:28:43 +0000 Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 2AH0II6W012415; Thu, 17 Nov 2022 01:28:05 GMT Received: from nam12-bn8-obe.outbound.protection.outlook.com (mail-bn8nam12lp2172.outbound.protection.outlook.com [104.47.55.172]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3kt1xendfw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 17 Nov 2022 01:28:05 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QmRFF9gcb0CJsu71043OIoPVTcmgZ+LcIrZ9dMqldKnYGVT1hGL0uW6zcZNhWdYrq+13yjdeFg2PfhtIpo4zb894XpA6QjSAAV/8eWndiGRNYjHfALeNSqgD1LfX+uA/83BfMWYSoeWtTG7RoYxFrHAwVNjZHbao7HEw5EAVvAXPrhCaLAtMwsS3jupuDZkfRvEtaatOf8QMvXJrgfL9lbC4uXm9/ziic7XhUX5GtKcgZ3kOieLAmplLMB1diAdsDuDn8ztNgRqt1AV2nDX8RUtiEndEBPkwMtqsBnLySgK+vwcIjO1O59AJBwuKAS1x/7mW8T9cewkxlLLwu+KfLg== 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=euxkXEoRAY7xnDK5NayvCNU49ShH2JwVZkcet08Vaeo=; b=hnx8RH3bouK/IhTy+a4LFYvI8T5d8A+zneaNBawI7J76wyWBgluzv8aPnehiEiHnYgKEeC5D160qLldCVgcdUC8VwNAshInnFrVnM+cNr+Ejata5+OWiIVBMUWgpPLQMPB5e1opgsQe738c6+O7lzzkEvnJnYQ/5K1H48HnrEJfXSH5vgZi+3soZWK0G8th5AjCx57/4hyyiD2l771gJoXHHvbfNaFn9xOU+HZmVXafSS0am0XLycG29K88ouJVHPBIE9ciX/5LorueULjupi8zYPUBzFrc3KJcTPz6e4OiKUMgj6Rpjr1mvzk7APpK48XuEMOaD6KYFhjLxxPIm6Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; 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=euxkXEoRAY7xnDK5NayvCNU49ShH2JwVZkcet08Vaeo=; b=KgsWEJgsWBnrh8OVd0YxYcyS7Gyklq4fq3hRTcu1TK0C80U+JliFMXenqG232wDwfMOeR9UabQedolddVUEhHFBxGSI4m4dBAGDf+0EG4vBrkTIchOkCfvbiTgN+DqlWIfZvorUvBd0i60JjVdwwpEeYFABdgNUDobJGT6eSt/U= Received: from SA1PR10MB5711.namprd10.prod.outlook.com (2603:10b6:806:23e::20) by CY5PR10MB5961.namprd10.prod.outlook.com (2603:10b6:930:2e::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5791.25; Thu, 17 Nov 2022 01:28:03 +0000 Received: from SA1PR10MB5711.namprd10.prod.outlook.com ([fe80::8127:f9d4:2c92:c253]) by SA1PR10MB5711.namprd10.prod.outlook.com ([fe80::8127:f9d4:2c92:c253%7]) with mapi id 15.20.5813.014; Thu, 17 Nov 2022 01:28:03 +0000 From: Daniel Jordan To: Herbert Xu , Steffen Klassert Cc: Nicolai Stange , Martin Doucha , linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, Daniel Jordan Subject: [PATCH] padata: Always leave BHs disabled when running ->parallel() Date: Wed, 16 Nov 2022 20:28:02 -0500 Message-Id: <20221117012802.62504-1-daniel.m.jordan@oracle.com> X-Mailer: git-send-email 2.38.1 X-ClientProxiedBy: MN2PR03CA0020.namprd03.prod.outlook.com (2603:10b6:208:23a::25) To SA1PR10MB5711.namprd10.prod.outlook.com (2603:10b6:806:23e::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA1PR10MB5711:EE_|CY5PR10MB5961:EE_ X-MS-Office365-Filtering-Correlation-Id: 0cfd26bc-0150-45a1-4683-08dac83af8f9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Pu+6puaXzoDUjYtA85Cf8xKKYHCgRecR0lDQbtBnmWdiGlbwXjDoqkkO8utZQiHkVM41Odc2Y/pO1YGcfO35wTzqHjJu4SV5PMwLg1pHDO5M4XaZn4KODAxmhg43On+nV045u6Amk5V6+7tfHBxYzsNgfXnhuPfvUk672lC3AqHBIFf0+rhYYB6DhXdU2GdXiqMJqLu4i/lN+v8VRHOxaz752qygTYELcTVN4gFIoh3l/DBOJYiIHsW+TlnoPwte0TUsYYWC6RUgGZM78WGmawSg2WhmUDIFw0BcuTTJZd4yUOmkGXF4sH5R8QLOFkIEkiNSU8gyLCN38Ts85XbCJArd5gI0bobdcDLPjeI3zQGmeUck4mj6rL90opfRKtl8slXuYOChQTF11GszrSVgOUni2YZUz3U3OVz3AXfgHLFH+ZEOsd/0pM3FQaUTF1pguH1x6NvN94z9HVWiGc/E50TKniaFPto8izBPsbWqQRFNqETAvOxTggUjCA7Al6kDVqJT9ecUylV+sOT0MnNw4O5M89CV+UhxUo8OWLYIVq471kCf63pawNu9yobM3p5cAISGIAtyknUy0X1WiVtixvpGhAheQy7V2tEtAqjvMyws6FGMgAnazJDmqEk1iyNK/3fVflnitVP+qKBWrYnr3ygKA8EkgghwZxShiMLOKI8xjJII2LOdnMCNREspSLRj/WLTcbuMJA5dtbpynpJOIA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SA1PR10MB5711.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(376002)(136003)(366004)(346002)(396003)(39860400002)(451199015)(6512007)(38100700002)(26005)(6506007)(1076003)(2616005)(186003)(83380400001)(5660300002)(2906002)(66476007)(6486002)(107886003)(8936002)(4326008)(54906003)(8676002)(66946007)(66556008)(41300700001)(316002)(478600001)(110136005)(103116003)(36756003)(86362001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: nAK5wwSvPJZ/ebFccB/dlFvPizF1UvQjskNv8p5q5wEB+ZET1kP60EozuvxVtkEvwNP0aMjBDHcdtGb0khhhkryVGpi4mUQMdDSpaJFt+qdFUVstcFjgHSZQIkDy1lS/7Hp6JEHX8GrJjA99sEdm8l6JsQDn2t7CfzQx+bV6mUAWTHXxRIAkQs7qquQa4k4mpuyWoNt395SqR/WsCNRnwR/3HAQFYwkG0p3xsLhsW2qL7G0Tw6LnJ/wmhvlOf2IPYsfx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FplS0klUf8pxKcw/GBBiNRJ9+4+95kiDAovSpjovImBf3pqdN9TBLNU11snQa5aUls/4L+6wq9MmppR8UPvHE0UTu/DHBCPXwIQqcjKzcFZUxFWBJ6NASYmDRdeR+8GPhbO9WhhGTf4C28f1zY34k24JKdry22VW+QDj0q8vgGhxPs7J0c5GJWb3v9XevOUAKFi1Of6ch51QRX2sKjl9wJN6fthp5 X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0cfd26bc-0150-45a1-4683-08dac83af8f9 X-MS-Exchange-CrossTenant-AuthSource: SA1PR10MB5711.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Nov 2022 01:28:03.8184 (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: 0NEzSL7zUMVl9eMW5TOurovW5ZWYKDRNocGonDdYEoO3yuP2ZOsl9Ueq9Vd2DJQ/XwXt/BQ6NhVEh4dutQKrvNZ6GbAtJTQZ7xj5s7mrXss= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR10MB5961 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-11-16_03,2022-11-16_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 bulkscore=0 mlxscore=0 phishscore=0 suspectscore=0 spamscore=0 adultscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2210170000 definitions=main-2211170008 X-Proofpoint-GUID: Gj1vdzlpzAul4GiQV9G3nEIR1mkH0I_5 X-Proofpoint-ORIG-GUID: Gj1vdzlpzAul4GiQV9G3nEIR1mkH0I_5 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org A deadlock can happen when an overloaded system runs ->parallel() in the context of the current task: padata_do_parallel ->parallel() pcrypt_aead_enc/dec padata_do_serial spin_lock(&reorder->lock) // BHs still enabled ... __do_softirq ... padata_do_serial spin_lock(&reorder->lock) It's a bug for BHs to be on in _do_serial as Steffen points out, so ensure they're off in the "current task" case like they are in padata_parallel_worker to avoid this situation. Reported-by: syzbot+bc05445bc14148d51915@syzkaller.appspotmail.com Fixes: 4611ce224688 ("padata: allocate work structures for parallel jobs from a pool") Signed-off-by: Daniel Jordan Acked-by: Steffen Klassert --- About the potential deadlock in padata_find_next(), I think this fix covers us there since that function is only called from padata_do_serial(), where BHs should now always be off, or invoke_padata_reorder(), where BHs are off as well. The _bh spinlock variants in padata_reorder() seem redundant. kernel/padata.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/kernel/padata.c b/kernel/padata.c index e5819bb8bd1d..97f51e0c1776 100644 --- a/kernel/padata.c +++ b/kernel/padata.c @@ -207,14 +207,16 @@ int padata_do_parallel(struct padata_shell *ps, pw = padata_work_alloc(); spin_unlock(&padata_works_lock); + if (!pw) { + /* Maximum works limit exceeded, run in the current task. */ + padata->parallel(padata); + } + rcu_read_unlock_bh(); if (pw) { padata_work_init(pw, padata_parallel_worker, padata, 0); queue_work(pinst->parallel_wq, &pw->pw_work); - } else { - /* Maximum works limit exceeded, run in the current task. */ - padata->parallel(padata); } return 0;