From patchwork Fri Aug 9 21:06:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Jordan X-Patchwork-Id: 11087609 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D124E1398 for ; Fri, 9 Aug 2019 21:08:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BB54B209CD for ; Fri, 9 Aug 2019 21:08:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AF4BA212D5; Fri, 9 Aug 2019 21:08:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 430D3209CD for ; Fri, 9 Aug 2019 21:08:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726125AbfHIVI0 (ORCPT ); Fri, 9 Aug 2019 17:08:26 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:45396 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726078AbfHIVI0 (ORCPT ); Fri, 9 Aug 2019 17:08:26 -0400 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x79L5ckN070468; Fri, 9 Aug 2019 21:08:15 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 : mime-version : content-transfer-encoding; s=corp-2019-08-05; bh=qPGkfFOzCb8gidKvwQnil0iLWuNYNpWlWuUd78n126c=; b=VPi+kpqy0bi3E9ra/RYYGrfhuQgzF7z+//srmIaL+tCfXJ35FGn/4vcqn/1T05mJXxLd YIjGYfJbUxhJPrOgtzeoKfTQoB/YpIAZhvZdvjYCOzfKZu33yVpHOUtEeFthlA+8hE7v YletivaSHwBNNRLnqHcvOra4hJKYBDadgVP1UQbBPTpT3FDgT35hEYu2/Sz69QEKgaUB JV6B3IYPrvaFh3p5XKEYOrHbBVDFIMCx6nJXhZ3KnaYUkJWjYbNh+B61S70ZliMaEi3B 8Qfmg1z0/anJu2lOTkd45QRDDH8kIpWomV6uWI6qqHS3KYpDIrHpcq4F1mSUGlgLKUpt lg== 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 : mime-version : content-transfer-encoding; s=corp-2018-07-02; bh=qPGkfFOzCb8gidKvwQnil0iLWuNYNpWlWuUd78n126c=; b=VgLe7xqr47J3KwzCUURxYaKc0fZO3TdQT9zUVnIs1dSjA94hBriLCvOlJOVmk7JoZS9f U+EfgT/NkB6rM1KcouHBKM2lck2twbzXUVE2/ZMhFeLdkObfuF21kRH9P1gNKNxviGtp s840uWwedscVlhuw5n12MXMc7okF0f5rLYeD1ossyRGAGi9Zz++wAkdzYC5km0Idq5Mp WfyQW1GBqUpL8sOobw3TITDkBd5vr6fwDkUFqfy6mAOWDDA2jox56XTbNd3bArO1MzTp RZmMDJtofx2tfU08RpCiShqoct14NbE9UH/xJPW8aMgHPwZmiorG/CiNNtlvWD211sZk fA== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by aserp2120.oracle.com with ESMTP id 2u8hasj5rq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 09 Aug 2019 21:08:15 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x79L49hm015714; Fri, 9 Aug 2019 21:06:15 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserp3020.oracle.com with ESMTP id 2u8x9fwp4b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 09 Aug 2019 21:06:15 +0000 Received: from abhmp0012.oracle.com (abhmp0012.oracle.com [141.146.116.18]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x79L6DGG016522; Fri, 9 Aug 2019 21:06:14 GMT Received: from localhost.localdomain (/73.60.114.248) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 09 Aug 2019 14:06:13 -0700 From: Daniel Jordan To: Herbert Xu , Steffen Klassert Cc: Daniel Jordan , linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] padata: validate cpumask without removed CPU during offline Date: Fri, 9 Aug 2019 17:06:03 -0400 Message-Id: <20190809210603.20900-1-daniel.m.jordan@oracle.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190809192857.26585-2-daniel.m.jordan@oracle.com> References: <20190809192857.26585-2-daniel.m.jordan@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9344 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1906280000 definitions=main-1908090206 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9344 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1906280000 definitions=main-1908090206 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Configuring an instance's parallel mask without any online CPUs... echo 2 > /sys/kernel/pcrypt/pencrypt/parallel_cpumask echo 0 > /sys/devices/system/cpu/cpu1/online ...crashes like this: divide error: 0000 [#1] SMP PTI CPU: 4 PID: 281 Comm: modprobe Not tainted 5.2.0-padata-base+ #25 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.12.0- RIP: 0010:padata_do_parallel+0xf1/0x270 ... Call Trace: pcrypt_do_parallel+0xed/0x1e0 [pcrypt] pcrypt_aead_encrypt+0xbf/0xd0 [pcrypt] do_mult_aead_op+0x68/0x112 [tcrypt] test_mb_aead_speed.constprop.0.cold+0x21a/0x55a [tcrypt] do_test+0x2280/0x4ca2 [tcrypt] tcrypt_mod_init+0x55/0x1000 [tcrypt] ... The cpumask_weight call in padata_cpu_hash returns 0, causing the division error, because the mask has no CPUs, which is expected in this situation. The problem is __padata_remove_cpu doesn't mark the instance PADATA_INVALID as expected, which would have made padata_do_parallel return error before doing the division, because it checks for valid masks too early. Fix by moving the checks after the masks have been adjusted for the offlined CPU. Only do the second check if the first succeeded to avoid inadvertently clearing PADATA_INVALID. Stop the instance unconditionally and start again if the masks are valid. Stopping the instance only after an invalid mask is found risks this div-by-0 crash since a padata_do_parallel call in another task could happen between cpumask_clear_cpu and padata_validate_cpumask. Fixes: 33e54450683c ("padata: Handle empty padata cpumasks") Signed-off-by: Daniel Jordan Cc: Herbert Xu Cc: Steffen Klassert Cc: linux-crypto@vger.kernel.org Cc: linux-kernel@vger.kernel.org --- v2: Don't leave the instance stopped if the masks are valid. kernel/padata.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/kernel/padata.c b/kernel/padata.c index d056276a96ce..01460ea1d160 100644 --- a/kernel/padata.c +++ b/kernel/padata.c @@ -702,10 +702,7 @@ static int __padata_remove_cpu(struct padata_instance *pinst, int cpu) struct parallel_data *pd = NULL; if (cpumask_test_cpu(cpu, cpu_online_mask)) { - - if (!padata_validate_cpumask(pinst, pinst->cpumask.pcpu) || - !padata_validate_cpumask(pinst, pinst->cpumask.cbcpu)) - __padata_stop(pinst); + __padata_stop(pinst); pd = padata_alloc_pd(pinst, pinst->cpumask.pcpu, pinst->cpumask.cbcpu); @@ -716,6 +713,9 @@ static int __padata_remove_cpu(struct padata_instance *pinst, int cpu) cpumask_clear_cpu(cpu, pd->cpumask.cbcpu); cpumask_clear_cpu(cpu, pd->cpumask.pcpu); + if (padata_validate_cpumask(pinst, pd->cpumask.pcpu) && + padata_validate_cpumask(pinst, pd->cpumask.cbcpu)) + __padata_start(pinst); } return 0; From patchwork Mon Aug 12 21:02:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Jordan X-Patchwork-Id: 11090841 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 654091398 for ; Mon, 12 Aug 2019 21:02:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 55E52285AD for ; Mon, 12 Aug 2019 21:02:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 48D39285AF; Mon, 12 Aug 2019 21:02:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B144B285AB for ; Mon, 12 Aug 2019 21:02:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726144AbfHLVCT (ORCPT ); Mon, 12 Aug 2019 17:02:19 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:39412 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726663AbfHLVCT (ORCPT ); Mon, 12 Aug 2019 17:02:19 -0400 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x7CKwfo2001766; Mon, 12 Aug 2019 21:02:08 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 : mime-version : content-transfer-encoding; s=corp-2019-08-05; bh=8v5ewYFjrCTDzF3BX4DOpWAFLC7ncCV9cpa2YE8L4Zw=; b=JpCMSKJxNiBihN+XUr7Qs8Kp5uMED6z06VaIy3pKkJy9SZ7VMismJBXRbk3vtKfdVJDk P1PCC57c2duWzRDccouM92uOuNlwtv5oHpnQg9rjg7tRgHZiSVYP50rNgyEFCvSobNbV JXvjjDqTmWjqsKVxvSfznhK2c5ETbyyhaODZwQlWldYrWsNdsStE7HZNaGQmFieDNKX9 OV7X055033lqUUlO8LKJOj3z7Vv8WciYVtg39/EzPFeH/9lHw7cxaiBF5Ii+9Yaejwj1 jdKpK7TF8ytnQGO9rZTwf1BtrN749PZ55Y6TbZk+VnbAn5SiTNZchLfXgg7K4Eifad2Z JQ== 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 : mime-version : content-transfer-encoding; s=corp-2018-07-02; bh=8v5ewYFjrCTDzF3BX4DOpWAFLC7ncCV9cpa2YE8L4Zw=; b=sCg5UXi7sqXmZxU6krn/lamt8vu2xvc7hSAkH9QOX5St7WH28xkvO2mg2vrEdLuW1LRK +JTQrOJx2rye5RrmT83vs24IEHwtPWeG1jbWx1cmlTVhe5HGn4iD9gsOjPjg2/PgWUNm 97gT3Ll4o8cRzC4kS1A6JycePb9xXvl8j/CFV8Jn31a627GrzIiEmPMTiZoriN/oEGOW TtgSq5x19c5LSGQ1+NXiaNQh/NGEr4cNNl0SgTjTmqLZqHRr2BVHK6bRpUBThm9rQ4tj ttU+XDYApUP/mywoX7b1hER9kSXy3O9bjVPYxfXAcNZqsTmdr3KXLXuTfs86Z8oqM3Mp 7Q== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2120.oracle.com with ESMTP id 2u9pjqa2em-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 12 Aug 2019 21:02:07 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x7CKva67017187; Mon, 12 Aug 2019 21:02:07 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserp3020.oracle.com with ESMTP id 2u9nre9hqs-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 12 Aug 2019 21:02:06 +0000 Received: from abhmp0008.oracle.com (abhmp0008.oracle.com [141.146.116.14]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x7CL25pr024438; Mon, 12 Aug 2019 21:02:06 GMT Received: from parnassus.us.oracle.com (/10.39.240.231) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 12 Aug 2019 14:02:05 -0700 From: Daniel Jordan To: Herbert Xu , Steffen Klassert Cc: Daniel Jordan , linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/2] padata: initialize usable masks to reflect offlined CPU Date: Mon, 12 Aug 2019 17:02:00 -0400 Message-Id: <20190812210200.13653-1-daniel.m.jordan@oracle.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190809210603.20900-1-daniel.m.jordan@oracle.com> References: <20190809210603.20900-1-daniel.m.jordan@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9347 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1906280000 definitions=main-1908120204 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9347 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1906280000 definitions=main-1908120204 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP __padata_remove_cpu clears the offlined CPU from the usable masks after padata_alloc_pd has initialized pd->cpu, which means pd->cpu could be initialized to this CPU, causing padata to wait indefinitely for the next job in padata_get_next. Make the usable masks reflect the offline CPU when they're established in padata_setup_cpumasks so pd->cpu is initialized properly. Fixes: 6fc4dbcf0276 ("padata: Replace delayed timer with immediate workqueue in padata_reorder") Signed-off-by: Daniel Jordan Cc: Herbert Xu Cc: Steffen Klassert Cc: linux-crypto@vger.kernel.org Cc: linux-kernel@vger.kernel.org --- Hi, one more edge case. All combinations of CPUs among parallel_cpumask, serial_cpumask, and CPU hotplug have now been tested in a 4-CPU VM, and an 8-CPU VM has run with random combinations of these settings for over an hour. kernel/padata.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/kernel/padata.c b/kernel/padata.c index 01460ea1d160..c1002ac4720c 100644 --- a/kernel/padata.c +++ b/kernel/padata.c @@ -702,17 +702,27 @@ static int __padata_remove_cpu(struct padata_instance *pinst, int cpu) struct parallel_data *pd = NULL; if (cpumask_test_cpu(cpu, cpu_online_mask)) { + cpumask_var_t pcpu, cbcpu; + __padata_stop(pinst); - pd = padata_alloc_pd(pinst, pinst->cpumask.pcpu, - pinst->cpumask.cbcpu); + /* + * padata_alloc_pd uses cpu_online_mask to get the usable + * masks, but @cpu hasn't been removed from it yet, so use + * temporary masks that exclude @cpu so the usable masks show + * @cpu as offline for pd->cpu's initialization. + */ + cpumask_copy(pcpu, pinst->cpumask.pcpu); + cpumask_copy(cbcpu, pinst->cpumask.cbcpu); + cpumask_clear_cpu(cpu, cbcpu); + cpumask_clear_cpu(cpu, pcpu); + + pd = padata_alloc_pd(pinst, pcpu, cbcpu); if (!pd) return -ENOMEM; padata_replace(pinst, pd); - cpumask_clear_cpu(cpu, pd->cpumask.cbcpu); - cpumask_clear_cpu(cpu, pd->cpumask.pcpu); if (padata_validate_cpumask(pinst, pd->cpumask.pcpu) && padata_validate_cpumask(pinst, pd->cpumask.cbcpu)) __padata_start(pinst);