From patchwork Mon Jan 9 17:31:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dennis Dalessandro X-Patchwork-Id: 13093936 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 8417EC61DB3 for ; Mon, 9 Jan 2023 17:31:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234192AbjAIRbr (ORCPT ); Mon, 9 Jan 2023 12:31:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53778 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237024AbjAIRbS (ORCPT ); Mon, 9 Jan 2023 12:31:18 -0500 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2108.outbound.protection.outlook.com [40.107.237.108]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5EBCC1583D for ; Mon, 9 Jan 2023 09:31:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gl680FCDu18hmiVeMxN3yka+aA+pOMSykS1bGjQt7iJOH+LZR2YDW/ZWIWZAsvrnrZ3RFaAbyVIzex1aWYvW9eAJIDGLiIsDcIsncqEILI2K5ateos0Naa2pjwXl1o4FGfzjoIbrEYhVoVlh3gU2MDIFJOHwNPT3GoD9UK3//QA8ee2SbydB3gGCzJQEeRzTwdMfEK/bKF1pK14HsdXkBQTPB0XdpQ7BLZm0G9CnApe1T3+ugXVP572uHsItpfuFk11SvLTAKDaGbZSLp6pcaDTaAvZblI5JZ0XXG7TnnC3lX9eZ9mmhFF9J0adVPANXNd0AQixxNnrgpotnvbP42A== 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=t13avY4AeDtGmHo2jebyMj3c8Bz7MWkBGAMojmTrgx0=; b=ed6FqTmmqg7GVEJrBZP7orrZQ5cY7j4JexW6ty//YQulMHIZBgtMRmjdXDsEedszR1FRBY43QK6gGivuiTv5/IsnQHCNxYrgcfwdPJTbtOprkTpJYHvnFa4qwoVOsZPjHFhGSsoQ2u/6XzkzwQjKLctxm1lwDMkmnkALvrBz2+p/Ft94RlFpVnNvOAYIXL16tn3IvcBW6o2QcZuHo2tg2Z6e+oq7z0CDsZA1c5OSuBJmBmu7Z6mnvB7DYowlomms2dNFJZmce93Yx+W9Y4xLuNlrQGSOk/5EfWbHJcrkAdSMHdqKZ9TPhoyvSCGeQ51OXf5ST/+iHWYEXdZObz2EmQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 208.255.156.42) smtp.rcpttodomain=nvidia.com smtp.mailfrom=cornelisnetworks.com; dmarc=bestguesspass action=none header.from=cornelisnetworks.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cornelisnetworks.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=t13avY4AeDtGmHo2jebyMj3c8Bz7MWkBGAMojmTrgx0=; b=gQlWUqjITGMI1Xac6Y31CAlMPcMfQXjwMWvaoI1/itispDwrI/DHXsjBWeVzY6WASwwilFGGCLo1BoOu5zv9bd6X4afvwXah+Fx60iNKK4bm/4AKk5d97AzGygcote+KwcD8Kotm/y88K5N+pBBl14sSCOY0OA5OcPFUZ1n1XMw1QPg8XNJVvKmuaYYw4YsYhcCImS/r3cFj3hMZuY2eRWDiFdn35QUo250qB33zgPiR38fp+1ACQm5WqX+nuxMvJNhsCum0Vx0RmEOIEz1NNkCRt8Y0o8mudXKpVSaeZyyyZ2djfLq+m0Re/mur6E/Z6SUJ5Jl47A0ZIPoNvUXE1A== Received: from BL0PR03CA0005.namprd03.prod.outlook.com (2603:10b6:208:2d::18) by DM6PR01MB3772.prod.exchangelabs.com (2603:10b6:5:8f::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5986.18; Mon, 9 Jan 2023 17:31:14 +0000 Received: from BL02EPF00010208.namprd05.prod.outlook.com (2603:10b6:208:2d:cafe::ed) by BL0PR03CA0005.outlook.office365.com (2603:10b6:208:2d::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5986.18 via Frontend Transport; Mon, 9 Jan 2023 17:31:14 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 208.255.156.42) smtp.mailfrom=cornelisnetworks.com; dkim=none (message not signed) header.d=none;dmarc=bestguesspass action=none header.from=cornelisnetworks.com; Received-SPF: Pass (protection.outlook.com: domain of cornelisnetworks.com designates 208.255.156.42 as permitted sender) receiver=protection.outlook.com; client-ip=208.255.156.42; helo=awfm-02.cornelisnetworks.com; pr=C Received: from awfm-02.cornelisnetworks.com (208.255.156.42) by BL02EPF00010208.mail.protection.outlook.com (10.167.241.199) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5986.15 via Frontend Transport; Mon, 9 Jan 2023 17:31:09 +0000 Received: from awfm-02.cornelisnetworks.com (localhost [127.0.0.1]) by awfm-02.cornelisnetworks.com (8.16.1/8.16.1) with ESMTP id 309HV6B91472580; Mon, 9 Jan 2023 12:31:06 -0500 Subject: [PATCH for-rc 1/6] IB/hfi1: Restore allocated resources on failed copyout From: Dennis Dalessandro To: jgg@nvidia.com, leonro@nvidia.com Cc: Dean Luick , linux-rdma@vger.kernel.org Date: Mon, 09 Jan 2023 12:31:06 -0500 Message-ID: <167328546603.1472310.17312024395730671459.stgit@awfm-02.cornelisnetworks.com> In-Reply-To: <167328512911.1472310.3529280633243532911.stgit@awfm-02.cornelisnetworks.com> References: <167328512911.1472310.3529280633243532911.stgit@awfm-02.cornelisnetworks.com> User-Agent: StGit/1.5.dev2+g9ce680a5 MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF00010208:EE_|DM6PR01MB3772:EE_ X-MS-Office365-Filtering-Correlation-Id: 46245ca8-7daf-490c-4354-08daf2674e3c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: WcGgsn072NUaLx4IXLKXhdeGSSt8wjl89RmEueJlxDeXUGwautW+K3SAXvC5qqm5YjQz6gUdvrFTaoSJuVMXc3dhT9LhRovxrVkbu3uUXwv25WM6xyfoFYcRB55Z50hPYYGMlegoALF6Hpd6CPMW81BhDiDFyDcsyTitcUetAr0loxdcE4zDJXDjtHST2FHZH3y1YSbsMjosFs/EFZ3Crepexa9Aym3gm/f0N04mQTBQIpXhR6zoboznxGuqOKgrtahHb7w265YY6OsuIGQDppYG7JMzLs58FMTTi+GmJHlH4lvpknZMHBY8fhnSB5PQCvILsZlO8ix6OaOmFyUYnXCn1S6QK1ooso88zqqgHKAHUOmwW5PWrFf+m+48RPMO48HrXCfeU778FrvA8MBb9PXsxCY2sIUb6UdGRF5mZ9A+nE2i+hyeqZBxQVrgBWHpfytjgET1F83rpnZ+XvcmdXwtm7hZPIq1ld3/wMXtF4d6A88TgVyX+illZ0DhpXuo/4OlFKIiO9u8TDZ1WiuQzZQDtHlNZD7d9S6+9q5eoGLDNUmI73eAxaSZ2odLxvfrp9XVGTYiIbFTALVe4tGexW4DFvzB/4+h3ivE/cwaM9//f6sXf82rOrY7Wap990LvVrts3FKVf2EIMPf7VX98DfHSQPzBRJ3jeKZ79ty7Bd/R6Hub/vr9bsDgp4XNwyO/O+IhbLrpq2yw2TeFVQS2qQ== X-Forefront-Antispam-Report: CIP:208.255.156.42;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:awfm-02.cornelisnetworks.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230022)(4636009)(346002)(376002)(39830400003)(136003)(396003)(451199015)(36840700001)(46966006)(426003)(41300700001)(47076005)(7126003)(316002)(4326008)(336012)(8676002)(70586007)(70206006)(83380400001)(82310400005)(86362001)(36860700001)(81166007)(356005)(40480700001)(103116003)(8936002)(5660300002)(44832011)(55016003)(2906002)(478600001)(186003)(7696005)(26005)(36900700001);DIR:OUT;SFP:1102; X-OriginatorOrg: cornelisnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Jan 2023 17:31:09.6346 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 46245ca8-7daf-490c-4354-08daf2674e3c X-MS-Exchange-CrossTenant-Id: 4dbdb7da-74ee-4b45-8747-ef5ce5ebe68a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=4dbdb7da-74ee-4b45-8747-ef5ce5ebe68a;Ip=[208.255.156.42];Helo=[awfm-02.cornelisnetworks.com] X-MS-Exchange-CrossTenant-AuthSource: BL02EPF00010208.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR01MB3772 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org From: Dean Luick Fix a resource leak if an error occurs. Fixes: f404ca4c7ea8 ("IB/hfi1: Refactor hfi_user_exp_rcv_setup() IOCTL") Signed-off-by: Dean Luick Signed-off-by: Dennis Dalessandro --- drivers/infiniband/hw/hfi1/file_ops.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/infiniband/hw/hfi1/file_ops.c b/drivers/infiniband/hw/hfi1/file_ops.c index f5f9269fdc16..c9fc913db00c 100644 --- a/drivers/infiniband/hw/hfi1/file_ops.c +++ b/drivers/infiniband/hw/hfi1/file_ops.c @@ -1318,12 +1318,15 @@ static int user_exp_rcv_setup(struct hfi1_filedata *fd, unsigned long arg, addr = arg + offsetof(struct hfi1_tid_info, tidcnt); if (copy_to_user((void __user *)addr, &tinfo.tidcnt, sizeof(tinfo.tidcnt))) - return -EFAULT; + ret = -EFAULT; addr = arg + offsetof(struct hfi1_tid_info, length); if (copy_to_user((void __user *)addr, &tinfo.length, sizeof(tinfo.length))) ret = -EFAULT; + + if (ret) + hfi1_user_exp_rcv_invalid(fd, &tinfo); } return ret; From patchwork Mon Jan 9 17:31:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dennis Dalessandro X-Patchwork-Id: 13093937 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 59BDFC54EBD for ; Mon, 9 Jan 2023 17:32:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230005AbjAIRbs (ORCPT ); Mon, 9 Jan 2023 12:31:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53680 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237022AbjAIRbS (ORCPT ); Mon, 9 Jan 2023 12:31:18 -0500 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2120.outbound.protection.outlook.com [40.107.220.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 23E5AB70 for ; Mon, 9 Jan 2023 09:31:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dDW5WK7asRpy7UFTGpq21O8uqRUcSqOW3o2nOGRSuQTGKITTan1NUlXPPDAcMXn4PHNGUfvxwgslgS7jL9L7WXjfkvLPZ+BQ3GzixYebvGjGhXPcM1XidONpCXAC7XKU134xnep9y2TutVmclHWs3eIVmAQ7FKk6yGEjv8FQEl6l6Fvl9io0CsPuCyqJ9KfoPn/2D5FwFMU6tys79sV963tvb3FeW1f9+ETpFxGpcL7NjpLCGoeNB5ojcM1t28k8wkuNpTPYdFrxw7yFcWDLSXAvr2OWP/95WmpKzdro6sIixyBfXUiJdF9oQxYfIy61GSaqxkTeSzxr5P5u7dg+lA== 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=VlwR2gYk50YuxRpcljWa+CiIPIBD05wGGQOW2rdS7Mk=; b=VONTw6veumg+r/t2b1XIczeRASXIolobOA+gjewzq1eNIwfORBYkSbmkS1O384FVM7Uq3fuC+t7TTQ765sBrPeIPC+XC1EgVoil8wEIUnqvYwNaZxf8oKD9kn0HD2bmp26s27zOL86yqVAbYUbDitvA24Ok0LYwwh+1T4GpWLUOFdW7vdRo8sAoNuEnlwVA3tNmTHT9hq7ZAirgfl5LMzBOlLFnT7fncH+psbMceCvXgNtEsJcfm1Mo+sO6UHrmiFcqbx/6Gf/bnMBj8Uy8IEXUxYKaSMX26ElyZi0SXNsfM2N/AjuDsz2fbsbISwEJ/ICuxvVKdi5gkCotz0z3AOg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 208.255.156.42) smtp.rcpttodomain=nvidia.com smtp.mailfrom=cornelisnetworks.com; dmarc=bestguesspass action=none header.from=cornelisnetworks.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cornelisnetworks.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=VlwR2gYk50YuxRpcljWa+CiIPIBD05wGGQOW2rdS7Mk=; b=LDNIQYkLosittWrNtSDNPe5vXHSDHv6lcTxapSdzW4ivEQZYwytAGqHAgPUFpl95QkznnkMtLFLCMIBpYTxZhvgAAR1O4EnkOmBb4a93oauDXCkOrRviFTZT+17R3IveEQ3/CZHzEDTCNdpAfSqZtbMPgu/C4UCcmG5m5bwUazTsRgUxAfXOvJx1WOOKG+lt8+s/PfWR0m3xqrEjAVZ4+u+eRmzUKhF9WObX1Y3ffuc73mAI35eX+U9PSAOcs01kvrCUB+k2YLP5i5u/QPPocrEreqglgG6lMvxe88pD9KOjh4oOMs0EvqWcvcvE2agxNfYu/O1yK8ws9kW5eK653w== Received: from DM6PR12CA0007.namprd12.prod.outlook.com (2603:10b6:5:1c0::20) by BL3PR01MB7044.prod.exchangelabs.com (2603:10b6:208:35f::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5986.18; Mon, 9 Jan 2023 17:31:12 +0000 Received: from DM6NAM11FT049.eop-nam11.prod.protection.outlook.com (2603:10b6:5:1c0:cafe::f4) by DM6PR12CA0007.outlook.office365.com (2603:10b6:5:1c0::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5986.18 via Frontend Transport; Mon, 9 Jan 2023 17:31:12 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 208.255.156.42) smtp.mailfrom=cornelisnetworks.com; dkim=none (message not signed) header.d=none;dmarc=bestguesspass action=none header.from=cornelisnetworks.com; Received-SPF: Pass (protection.outlook.com: domain of cornelisnetworks.com designates 208.255.156.42 as permitted sender) receiver=protection.outlook.com; client-ip=208.255.156.42; helo=awfm-02.cornelisnetworks.com; pr=C Received: from awfm-02.cornelisnetworks.com (208.255.156.42) by DM6NAM11FT049.mail.protection.outlook.com (10.13.172.188) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5986.18 via Frontend Transport; Mon, 9 Jan 2023 17:31:12 +0000 Received: from awfm-02.cornelisnetworks.com (localhost [127.0.0.1]) by awfm-02.cornelisnetworks.com (8.16.1/8.16.1) with ESMTP id 309HVBfD1472589; Mon, 9 Jan 2023 12:31:11 -0500 Subject: [PATCH for-rc 2/6] IB/hfi1: Reject a zero-length user expected buffer From: Dennis Dalessandro To: jgg@nvidia.com, leonro@nvidia.com Cc: Dean Luick , linux-rdma@vger.kernel.org Date: Mon, 09 Jan 2023 12:31:11 -0500 Message-ID: <167328547120.1472310.6362802432127399257.stgit@awfm-02.cornelisnetworks.com> In-Reply-To: <167328512911.1472310.3529280633243532911.stgit@awfm-02.cornelisnetworks.com> References: <167328512911.1472310.3529280633243532911.stgit@awfm-02.cornelisnetworks.com> User-Agent: StGit/1.5.dev2+g9ce680a5 MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6NAM11FT049:EE_|BL3PR01MB7044:EE_ X-MS-Office365-Filtering-Correlation-Id: 6bcdc85f-18ee-4e78-db58-08daf2674d8d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: PVHRrJyzxBY0h6rKzGFkHqn7oY+0DAdaY4xGYcO1gsBiBRS+htosywnlDFgua/GYi+WskNxiK+32Q3QI4j4xz+nUoZKDjRGwGT5PaDpGtjLSkGyScExC8+qIfcmd+sXoe4ZAtrL3vsrMM0sjNCde00ZeiMyvN/bgnrek5f2rMaZWu3vMoOdk9mCKffu/7M+T4E7yWu9PIY+OVpZAbVrfMuhWQhwiOc2S9erIcErNVBleftSGMtf/CEY9v8VJZYEL3t898thP3MLmBEBNPa30myfHGu2n41qoLrRR+uGjy8yOh/9nzb7EumFX1wzLrHFWSeAYon+fl5dbl59shntaXaZEpunX2z485f1u3XP47ZIICkG9b9zSkKc4FZK3F5vbCqWR3D5JKo13BbaH9bD2slD4MMFG2xvsXqkPHe9bX0sFmZF97jRySekvmD1Ynec7C04WpVCmkPcq5XecwDk5xFB6auIH9kkBafckxPmpkGq4COWBpJWE004aHxK11tynAuKMvCAzM4fzjAltqcp4SdyzJu6sKuSvVcE+X0Nz5PZds1LlKeuukbEhU+s8I4rvO8U4GErSRbsEe5mYoR8kiYtHc6ofHC/DlDv1i2Ltqjo4DLArIROmdPe1NcZiMJuXMDx1KP0Ssirca4PBTt13dEUBw5yjce1DUCtm0hMo2Pk+OUhDhiTicNKXC9FRpSI+QzxqFsL9fpjTFWuQG8XNBw== X-Forefront-Antispam-Report: CIP:208.255.156.42;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:awfm-02.cornelisnetworks.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230022)(4636009)(346002)(376002)(39840400004)(136003)(396003)(451199015)(46966006)(36840700001)(82310400005)(8936002)(5660300002)(2906002)(426003)(81166007)(47076005)(41300700001)(7696005)(70206006)(316002)(4326008)(70586007)(8676002)(44832011)(4744005)(356005)(40480700001)(26005)(55016003)(7126003)(336012)(186003)(83380400001)(36860700001)(86362001)(478600001)(103116003)(36900700001);DIR:OUT;SFP:1102; X-OriginatorOrg: cornelisnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Jan 2023 17:31:12.1479 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6bcdc85f-18ee-4e78-db58-08daf2674d8d X-MS-Exchange-CrossTenant-Id: 4dbdb7da-74ee-4b45-8747-ef5ce5ebe68a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=4dbdb7da-74ee-4b45-8747-ef5ce5ebe68a;Ip=[208.255.156.42];Helo=[awfm-02.cornelisnetworks.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT049.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL3PR01MB7044 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org From: Dean Luick A zero length user buffer makes no sense and the code does not handle it correctly. Instead, reject a zero length as invalid. Fixes: 97736f36dbeb ("IB/hfi1: Validate page aligned for a given virtual addres") Signed-off-by: Dean Luick Signed-off-by: Dennis Dalessandro --- drivers/infiniband/hw/hfi1/user_exp_rcv.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/infiniband/hw/hfi1/user_exp_rcv.c b/drivers/infiniband/hw/hfi1/user_exp_rcv.c index 186d30291260..3c609b11e71c 100644 --- a/drivers/infiniband/hw/hfi1/user_exp_rcv.c +++ b/drivers/infiniband/hw/hfi1/user_exp_rcv.c @@ -256,6 +256,8 @@ int hfi1_user_exp_rcv_setup(struct hfi1_filedata *fd, if (!PAGE_ALIGNED(tinfo->vaddr)) return -EINVAL; + if (tinfo->length == 0) + return -EINVAL; tidbuf = kzalloc(sizeof(*tidbuf), GFP_KERNEL); if (!tidbuf) From patchwork Mon Jan 9 17:31:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dennis Dalessandro X-Patchwork-Id: 13093939 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 BC710C6379F for ; Mon, 9 Jan 2023 17:32:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234251AbjAIRcP (ORCPT ); Mon, 9 Jan 2023 12:32:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53672 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237236AbjAIRbY (ORCPT ); Mon, 9 Jan 2023 12:31:24 -0500 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2100.outbound.protection.outlook.com [40.107.236.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A3539B7D2 for ; Mon, 9 Jan 2023 09:31:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YIGUYFoMMwVmcO2//IQzUiYOamTxtNmG5sgUFG917dDQoMl4KoNvrHbsB83sDUwlvpTx73+K39imFjpmnRhvlj3MWTaUtMGy93gMGUMgDM70iuc678eB05Eduy9ue3XxV40t5CJhZLJf79FiiDM6FkzPu+9Swj/htcnR01rxZ/G2XFTATgT7afuMb4S3IRu++YY8eERKH2RnQFckc/WdZGZ7CmyUaFuM+O3+Sllq+gLsEIRN2RZY2TxXP58zWOSZI/pjV1oLi5YF0RooFM0eqBR+1Hx9k6qdI5A3l43MTxA8AFkLZ0jaBQG7K46Do7ZYo3a2jhjTmNzv6VeYe39PXg== 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=Nroqvo4SBQd95e7VAhZ0plVitykUI6oVJZjj8czpQcE=; b=HSHBexuqzbrFs+mHlmKkiczJ2xSoEUEdeLsc1KtuZ45B7TzarACxInGJpYmbj4bwhx0oAPn2WFXWWP4YYQT5Mr8k6HzypdAVJw0G7ySmDBSBQO9zXrh4h6DRSyFpqWq1Zt1M43yTr9NM3Ua0VHAQqhAa00Sbf6iQPaIQAk53/LbY8lTKVAf/14seZT/wooQQ+FT4R+8yHUb19buwoyPVhU0JPAJEo+/tAcQrvMTg+ImNMPa6+k7FmFObLOiIMxQNkHL5ROhUtlhloGB9UtbCxJUVedW+G3pxo+od8K8/ykrp2Wx74J+HqQ16bplhjDeCCM6c9w+K3pE9HyTg0rtB2A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 208.255.156.42) smtp.rcpttodomain=nvidia.com smtp.mailfrom=cornelisnetworks.com; dmarc=bestguesspass action=none header.from=cornelisnetworks.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cornelisnetworks.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Nroqvo4SBQd95e7VAhZ0plVitykUI6oVJZjj8czpQcE=; b=Q3exd5TGfveCnZc8AhNrIq2StEG2e/5XPtaZNBsSoMUUYZdJ2TKqGjAPtSUCL2PE2LxuHSqlxib7Yh+PT1eOlvCXngI2EUgRgIgFqZ46kLoXPtBgO2bKJC3h8yUSFIDUNotphy0UMt2LqDvjSsGm37vTEQg/QAHQZbONsY6yM9drh9WlHqjp5nnv9FKbqx3J/nyGkS8R1N+OhXPpHf25GUF4AEcHj8SJgMKI5drtOsKYTigleSt0pPjqXNG1RlUmxblzjT6fHIJHoO1pQByqSk5PJ+/jMHKjt+pVZoS2jlxgMpUewE/F5iQFK117NmkTBKs7GRNi/pahOJLul7IXrw== Received: from DS7P222CA0024.NAMP222.PROD.OUTLOOK.COM (2603:10b6:8:2e::13) by SJ0PR01MB8082.prod.exchangelabs.com (2603:10b6:a03:4e2::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5986.18; Mon, 9 Jan 2023 17:31:17 +0000 Received: from DM6NAM11FT091.eop-nam11.prod.protection.outlook.com (2603:10b6:8:2e:cafe::fb) by DS7P222CA0024.outlook.office365.com (2603:10b6:8:2e::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5986.18 via Frontend Transport; Mon, 9 Jan 2023 17:31:17 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 208.255.156.42) smtp.mailfrom=cornelisnetworks.com; dkim=none (message not signed) header.d=none;dmarc=bestguesspass action=none header.from=cornelisnetworks.com; Received-SPF: Pass (protection.outlook.com: domain of cornelisnetworks.com designates 208.255.156.42 as permitted sender) receiver=protection.outlook.com; client-ip=208.255.156.42; helo=awfm-02.cornelisnetworks.com; pr=C Received: from awfm-02.cornelisnetworks.com (208.255.156.42) by DM6NAM11FT091.mail.protection.outlook.com (10.13.173.108) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5944.17 via Frontend Transport; Mon, 9 Jan 2023 17:31:17 +0000 Received: from awfm-02.cornelisnetworks.com (localhost [127.0.0.1]) by awfm-02.cornelisnetworks.com (8.16.1/8.16.1) with ESMTP id 309HVGeA1472598; Mon, 9 Jan 2023 12:31:16 -0500 Subject: [PATCH for-rc 3/6] IB/hfi1: Reserve user expected TIDs From: Dennis Dalessandro To: jgg@nvidia.com, leonro@nvidia.com Cc: Dean Luick , linux-rdma@vger.kernel.org Date: Mon, 09 Jan 2023 12:31:16 -0500 Message-ID: <167328547636.1472310.7419712824785353905.stgit@awfm-02.cornelisnetworks.com> In-Reply-To: <167328512911.1472310.3529280633243532911.stgit@awfm-02.cornelisnetworks.com> References: <167328512911.1472310.3529280633243532911.stgit@awfm-02.cornelisnetworks.com> User-Agent: StGit/1.5.dev2+g9ce680a5 MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6NAM11FT091:EE_|SJ0PR01MB8082:EE_ X-MS-Office365-Filtering-Correlation-Id: 924bc644-bfea-40e4-3bb5-08daf267508b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: awMlE205fGE1T//9YBpBpgogBnOeyGK3wtuSePd/YcXeFMEyWt1Mp9GhnUtsCjBxUw8l6e8kSnC4lFG1iuKMTQRE7cH2YuL5oq+PNo5Qbos0ziiyTEfrzTdbVBvwLhD5426IAQBcPa/94CUry/83lHwNSL26eFpzDSOQwC44dg1tJ5fgpP4mVQdWoVNPkcdHJ7SCDybvei5qA+sKa0Ucj4Htepr16RgZhVzwgka1bReQRFKafbUHjneRgKkiV949yBXGjlbWHaXywMcEZw/el8SHqZDRW65/8X2Zwz+1/U8++KFGqa9B/RiI9WTRC44pL8TahGwuv71Zw/hKVm+Inlep2z78tzPYe2lbcmTXkPMNNbz2qByZCflfYZWdvkNa41vL0TcyzysE5jh5q1SDy/n7gfVZH9JakARWdXFoFZdgKRIPXsRLlT0vB+jyAjGaPIA6GX6qDF0Q3jR2eTQ93jNFvO+BByme9cGKUt06FzS0RSPWYv2/SseRdqc3ZvLfPJP4pbfLIYrhLMOcKf7/A42gKoh3/CUX07jZ5P3MoWw+bXhRsm3mRy0axY4DWRLflNOf8NJvQD/P+VZQxwLcKW7T8RDjfho1CxHs+uUKVScQyIrBjpF8M6RHZBazQIWc5K/igAcyh/58sWD+xJ0EsfNA5oX5ZRxsNYVJ4mUlKOerXMhV5t6QQSvikTCtaWoAgDA3nULIsP3EAo7Zd4GlFw== X-Forefront-Antispam-Report: CIP:208.255.156.42;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:awfm-02.cornelisnetworks.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230022)(4636009)(376002)(396003)(136003)(39840400004)(346002)(451199015)(46966006)(36840700001)(478600001)(103116003)(40480700001)(47076005)(7126003)(4326008)(336012)(186003)(26005)(55016003)(70206006)(70586007)(8676002)(316002)(7696005)(83380400001)(36860700001)(86362001)(81166007)(356005)(426003)(41300700001)(82310400005)(5660300002)(2906002)(44832011)(8936002)(36900700001);DIR:OUT;SFP:1102; X-OriginatorOrg: cornelisnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Jan 2023 17:31:17.2108 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 924bc644-bfea-40e4-3bb5-08daf267508b X-MS-Exchange-CrossTenant-Id: 4dbdb7da-74ee-4b45-8747-ef5ce5ebe68a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=4dbdb7da-74ee-4b45-8747-ef5ce5ebe68a;Ip=[208.255.156.42];Helo=[awfm-02.cornelisnetworks.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT091.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR01MB8082 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org From: Dean Luick To avoid a race, reserve the number of user expected TIDs before setup. Fixes: 7e7a436ecb6e ("staging/hfi1: Add TID entry program function body") Signed-off-by: Dean Luick Signed-off-by: Dennis Dalessandro --- drivers/infiniband/hw/hfi1/user_exp_rcv.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/drivers/infiniband/hw/hfi1/user_exp_rcv.c b/drivers/infiniband/hw/hfi1/user_exp_rcv.c index 3c609b11e71c..d7487555d109 100644 --- a/drivers/infiniband/hw/hfi1/user_exp_rcv.c +++ b/drivers/infiniband/hw/hfi1/user_exp_rcv.c @@ -282,16 +282,13 @@ int hfi1_user_exp_rcv_setup(struct hfi1_filedata *fd, /* Find sets of physically contiguous pages */ tidbuf->n_psets = find_phys_blocks(tidbuf, pinned); - /* - * We don't need to access this under a lock since tid_used is per - * process and the same process cannot be in hfi1_user_exp_rcv_clear() - * and hfi1_user_exp_rcv_setup() at the same time. - */ + /* Reserve the number of expected tids to be used. */ spin_lock(&fd->tid_lock); if (fd->tid_used + tidbuf->n_psets > fd->tid_limit) pageset_count = fd->tid_limit - fd->tid_used; else pageset_count = tidbuf->n_psets; + fd->tid_used += pageset_count; spin_unlock(&fd->tid_lock); if (!pageset_count) @@ -400,10 +397,11 @@ int hfi1_user_exp_rcv_setup(struct hfi1_filedata *fd, nomem: hfi1_cdbg(TID, "total mapped: tidpairs:%u pages:%u (%d)", tididx, mapped_pages, ret); + /* adjust reserved tid_used to actual count */ + spin_lock(&fd->tid_lock); + fd->tid_used -= pageset_count - tididx; + spin_unlock(&fd->tid_lock); if (tididx) { - spin_lock(&fd->tid_lock); - fd->tid_used += tididx; - spin_unlock(&fd->tid_lock); tinfo->tidcnt = tididx; tinfo->length = mapped_pages * PAGE_SIZE; From patchwork Mon Jan 9 17:31:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dennis Dalessandro X-Patchwork-Id: 13093938 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 43AEAC61DB3 for ; Mon, 9 Jan 2023 17:32:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230493AbjAIRcQ (ORCPT ); Mon, 9 Jan 2023 12:32:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53690 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237287AbjAIRb0 (ORCPT ); Mon, 9 Jan 2023 12:31:26 -0500 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2115.outbound.protection.outlook.com [40.107.244.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D24E1B87D for ; Mon, 9 Jan 2023 09:31:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Vs0Qzu1aEc24nprAfHwST4xhlkljEqlTYg7UZnV2YFTEi4kg+l+/j+WzVEV+rWjK+2n9BUE+SUVgaU4wJYW8HdJWrfCRDbaTbKRPtGoypH2gPCl+7DPYiVnpBUjzlYuzLMGLpB5U4MAzSwChK6dpgwlb1sNWFEOUFBCGUa+s0X47wO/vQHhkOi/6nGEEQlbRF8S3NJoFsVvLfRCA8GSmtZVN1yVzYox0OJWYFWVRfWQBhyYku5D/3I3Ft8SPd2ra44vuRfOSSPpLi068I3BxteAVNO98p7ByfuI1zeAOlwreo0t7BqKuvMLVuuoTmfg+Tieo2JAihvt+be9aNnUnrg== 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=U7v/MUyz+2qqaJHcQD34muWmkGmqeSgKIz+ETnc5lts=; b=EfOES/PJJNCsEF9Haqu7+9B+OYKRn3JslzXFqzHjfNg0QuaipBtZzsoERQLk09VI0DLXTv5duwLzLoKNC8VNZcsy19uD+I2W5dybPFX2FPQYgEm9WCdpioORlmisCC3fHLyhL+KNxoDQtzeM+AkVRfNk/icxIjnNmTAQQvuEdwtcnkW3NkQXTjEjfHZsiwtPVwS3rvoeFtIqsAThTD/2EOYWuxJdRVW7mSme866z9bn/bij3poheFPpTCYXNUujwHEJJh58oUKhCqXfx9YiOwXZvFEEZ5ir5ec2fu4DXIpud3UBzuKQIkGQmudLBQF3NOjthKMa11IUibj04pPo+6A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 208.255.156.42) smtp.rcpttodomain=nvidia.com smtp.mailfrom=cornelisnetworks.com; dmarc=bestguesspass action=none header.from=cornelisnetworks.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cornelisnetworks.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=U7v/MUyz+2qqaJHcQD34muWmkGmqeSgKIz+ETnc5lts=; b=DS+VaEzW8+VTEtljOmg8/rJG+KG9OezJXlQwKnLm6m5PdAJWebJRhtKf9GMT8inVh94ng1MYwGS3GY76CY1YlLATeEJlQIyRdxvp8YFNrC6ZbKlQ5WH7pAmkkpXMsEJWfhnLg35B4gk8zSvJsHfbWL7j3o473fGuY3pmandpOxEgNsUY26KNfayuCqJcZzjIsRHGGSPmZSK7ANCxPT4ckwqhf8GW3qG670+ZOPr1ENxfG12i+SkeANoJ1pTWEVN745HaHDtWy6Zju41IpoQm+J62A9s9fVYBEme2sT4nFA6p5C5WWkSCl85y+3821AqWkjLhA+OeBJaPd7+o+wI4Uw== Received: from DM6PR08CA0030.namprd08.prod.outlook.com (2603:10b6:5:80::43) by SN7PR01MB7924.prod.exchangelabs.com (2603:10b6:806:347::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5986.18; Mon, 9 Jan 2023 17:31:22 +0000 Received: from DM6NAM11FT003.eop-nam11.prod.protection.outlook.com (2603:10b6:5:80:cafe::9c) by DM6PR08CA0030.outlook.office365.com (2603:10b6:5:80::43) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5986.18 via Frontend Transport; Mon, 9 Jan 2023 17:31:22 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 208.255.156.42) smtp.mailfrom=cornelisnetworks.com; dkim=none (message not signed) header.d=none;dmarc=bestguesspass action=none header.from=cornelisnetworks.com; Received-SPF: Pass (protection.outlook.com: domain of cornelisnetworks.com designates 208.255.156.42 as permitted sender) receiver=protection.outlook.com; client-ip=208.255.156.42; helo=awfm-02.cornelisnetworks.com; pr=C Received: from awfm-02.cornelisnetworks.com (208.255.156.42) by DM6NAM11FT003.mail.protection.outlook.com (10.13.173.162) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5986.18 via Frontend Transport; Mon, 9 Jan 2023 17:31:22 +0000 Received: from awfm-02.cornelisnetworks.com (localhost [127.0.0.1]) by awfm-02.cornelisnetworks.com (8.16.1/8.16.1) with ESMTP id 309HVLvE1472607; Mon, 9 Jan 2023 12:31:21 -0500 Subject: [PATCH for-rc 4/6] IB/hfi1: Fix expected receive setup error exit issues From: Dennis Dalessandro To: jgg@nvidia.com, leonro@nvidia.com Cc: Dean Luick , linux-rdma@vger.kernel.org Date: Mon, 09 Jan 2023 12:31:21 -0500 Message-ID: <167328548150.1472310.1492305874804187634.stgit@awfm-02.cornelisnetworks.com> In-Reply-To: <167328512911.1472310.3529280633243532911.stgit@awfm-02.cornelisnetworks.com> References: <167328512911.1472310.3529280633243532911.stgit@awfm-02.cornelisnetworks.com> User-Agent: StGit/1.5.dev2+g9ce680a5 MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6NAM11FT003:EE_|SN7PR01MB7924:EE_ X-MS-Office365-Filtering-Correlation-Id: 3599c980-2268-4e13-4dd9-08daf26753a5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 3WXL8zIh3qxUkdBPdHi2mot5zEVjmAB1MtKDLH/WAWrSRrYpuOPmwNS/LZI/hjmDRuwW3WbHJhl5xICSgqFf87XhQmObnUc5zTKnxUeUDZsWxESxvTRSdcO6VNrQBYNDTXpdKvvkXpZ314EYgQR/SAu/oX1hWYKomrQVUAjzY/iV6puMdfhpYCje2XUNCIDLLutuu21/f5TLkxc40rTlAILb7tt6BMl8TgSPkCedI4bYsescHA04lbFCeHlr75VZa+bec74QUPptKCMfwWynj+psY+lz0A4zGXELH1LWbxHXell5Af1lFwTmEj5hNc8zKzgyXnbZiSV3C0WWNzVTJAQgMyoSfNb4+JS866OXmZO8DlcVNC8s9z8EASZS5OT2vH92faWsEaOMVGTPiu6cMWdanOlVzqKaGYgTGoCXAgbaci2ksdfkFLiffBeP8IH8/2NXMlaWwKt2rUFx2crjxuzN8QESpOUZAj3v9RPIwMEdB6Wavd5G6dDxAcVQkofDtVBwFFhvlqdwdlrO+lWfEduO5vyG5TLD9Q4Rp/LQQddJFURvy89on46Cbj5H5dObHYVrLV1kGaQD+0+MWQw2wGRuIaIhzTf5QiBbQ03Lt2wx0c5NXAkWzGQUkkZHIhjO/KMqaiPDsaBImNXfCsm+SlyjxglbGO0MmtWSIdhGD7TrUtIwI3CoN1t+XwW3jXqFON7ZAUkOJyz9b0MPyRWSiw== X-Forefront-Antispam-Report: CIP:208.255.156.42;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:awfm-02.cornelisnetworks.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230022)(4636009)(396003)(39840400004)(136003)(346002)(376002)(451199015)(36840700001)(46966006)(8676002)(4326008)(70586007)(316002)(7696005)(70206006)(44832011)(356005)(2906002)(5660300002)(8936002)(81166007)(41300700001)(426003)(47076005)(36860700001)(83380400001)(103116003)(478600001)(40480700001)(7126003)(336012)(186003)(26005)(86362001)(55016003)(82310400005)(36900700001);DIR:OUT;SFP:1102; X-OriginatorOrg: cornelisnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Jan 2023 17:31:22.4148 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3599c980-2268-4e13-4dd9-08daf26753a5 X-MS-Exchange-CrossTenant-Id: 4dbdb7da-74ee-4b45-8747-ef5ce5ebe68a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=4dbdb7da-74ee-4b45-8747-ef5ce5ebe68a;Ip=[208.255.156.42];Helo=[awfm-02.cornelisnetworks.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT003.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR01MB7924 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org From: Dean Luick Fix three error exit issues in expected receive setup. Re-arrange error exits to increase readability. Issues and fixes: 1. Possible missed page unpin if tidlist copyout fails and not all pinned pages where made part of a TID. Fix: Unpin the unused pages. 2. Return success with unset return values tidcnt and length when no pages were pinned. Fix: Return -ENOSPC if no pages were pinned. 3. Return success with unset return values tidcnt and length when no rcvarray entries available. Fix: Return -ENOSPC if no rcvarray entries are available. Fixes: 7e7a436ecb6e ("staging/hfi1: Add TID entry program function body") Fixes: 97736f36dbeb ("IB/hfi1: Validate page aligned for a given virtual addres") Fixes: f404ca4c7ea8 ("IB/hfi1: Refactor hfi_user_exp_rcv_setup() IOCTL") Signed-off-by: Dean Luick Signed-off-by: Dennis Dalessandro --- drivers/infiniband/hw/hfi1/user_exp_rcv.c | 83 +++++++++++++++++------------ 1 file changed, 50 insertions(+), 33 deletions(-) diff --git a/drivers/infiniband/hw/hfi1/user_exp_rcv.c b/drivers/infiniband/hw/hfi1/user_exp_rcv.c index d7487555d109..88df8ca4bb57 100644 --- a/drivers/infiniband/hw/hfi1/user_exp_rcv.c +++ b/drivers/infiniband/hw/hfi1/user_exp_rcv.c @@ -268,15 +268,14 @@ int hfi1_user_exp_rcv_setup(struct hfi1_filedata *fd, tidbuf->psets = kcalloc(uctxt->expected_count, sizeof(*tidbuf->psets), GFP_KERNEL); if (!tidbuf->psets) { - kfree(tidbuf); - return -ENOMEM; + ret = -ENOMEM; + goto fail_release_mem; } pinned = pin_rcv_pages(fd, tidbuf); if (pinned <= 0) { - kfree(tidbuf->psets); - kfree(tidbuf); - return pinned; + ret = (pinned < 0) ? pinned : -ENOSPC; + goto fail_unpin; } /* Find sets of physically contiguous pages */ @@ -291,14 +290,16 @@ int hfi1_user_exp_rcv_setup(struct hfi1_filedata *fd, fd->tid_used += pageset_count; spin_unlock(&fd->tid_lock); - if (!pageset_count) - goto bail; + if (!pageset_count) { + ret = -ENOSPC; + goto fail_unreserve; + } ngroups = pageset_count / dd->rcv_entries.group_size; tidlist = kcalloc(pageset_count, sizeof(*tidlist), GFP_KERNEL); if (!tidlist) { ret = -ENOMEM; - goto nomem; + goto fail_unreserve; } tididx = 0; @@ -394,44 +395,60 @@ int hfi1_user_exp_rcv_setup(struct hfi1_filedata *fd, } unlock: mutex_unlock(&uctxt->exp_mutex); -nomem: hfi1_cdbg(TID, "total mapped: tidpairs:%u pages:%u (%d)", tididx, mapped_pages, ret); + + /* fail if nothing was programmed, set error if none provided */ + if (tididx == 0) { + if (ret >= 0) + ret = -ENOSPC; + goto fail_unreserve; + } + /* adjust reserved tid_used to actual count */ spin_lock(&fd->tid_lock); fd->tid_used -= pageset_count - tididx; spin_unlock(&fd->tid_lock); - if (tididx) { - tinfo->tidcnt = tididx; - tinfo->length = mapped_pages * PAGE_SIZE; - if (copy_to_user(u64_to_user_ptr(tinfo->tidlist), - tidlist, sizeof(tidlist[0]) * tididx)) { - /* - * On failure to copy to the user level, we need to undo - * everything done so far so we don't leak resources. - */ - tinfo->tidlist = (unsigned long)&tidlist; - hfi1_user_exp_rcv_clear(fd, tinfo); - tinfo->tidlist = 0; - ret = -EFAULT; - goto bail; - } + /* unpin all pages not covered by a TID */ + unpin_rcv_pages(fd, tidbuf, NULL, mapped_pages, pinned - mapped_pages, + false); + + tinfo->tidcnt = tididx; + tinfo->length = mapped_pages * PAGE_SIZE; + + if (copy_to_user(u64_to_user_ptr(tinfo->tidlist), + tidlist, sizeof(tidlist[0]) * tididx)) { + ret = -EFAULT; + goto fail_unprogram; } - /* - * If not everything was mapped (due to insufficient RcvArray entries, - * for example), unpin all unmapped pages so we can pin them nex time. - */ - if (mapped_pages != pinned) - unpin_rcv_pages(fd, tidbuf, NULL, mapped_pages, - (pinned - mapped_pages), false); -bail: + kfree(tidbuf->pages); kfree(tidbuf->psets); + kfree(tidbuf); kfree(tidlist); + return 0; + +fail_unprogram: + /* unprogram, unmap, and unpin all allocated TIDs */ + tinfo->tidlist = (unsigned long)tidlist; + hfi1_user_exp_rcv_clear(fd, tinfo); + tinfo->tidlist = 0; + pinned = 0; /* nothing left to unpin */ + pageset_count = 0; /* nothing left reserved */ +fail_unreserve: + spin_lock(&fd->tid_lock); + fd->tid_used -= pageset_count; + spin_unlock(&fd->tid_lock); +fail_unpin: + if (pinned > 0) + unpin_rcv_pages(fd, tidbuf, NULL, 0, pinned, false); +fail_release_mem: kfree(tidbuf->pages); + kfree(tidbuf->psets); kfree(tidbuf); - return ret > 0 ? 0 : ret; + kfree(tidlist); + return ret; } int hfi1_user_exp_rcv_clear(struct hfi1_filedata *fd, From patchwork Mon Jan 9 17:31:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dennis Dalessandro X-Patchwork-Id: 13093940 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 10336C678D5 for ; Mon, 9 Jan 2023 17:32:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233602AbjAIRcQ (ORCPT ); Mon, 9 Jan 2023 12:32:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54076 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237450AbjAIRbe (ORCPT ); Mon, 9 Jan 2023 12:31:34 -0500 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2095.outbound.protection.outlook.com [40.107.94.95]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 673211AD9B for ; Mon, 9 Jan 2023 09:31:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KxhA8xaTZvQ/DXnJ/WeabJKB0xVwsBkGovAEQfJsLA+UZdi4l0x4CBGFnMwcLZI0eA0JE2NiIrVo+9knifxt9ZX6G0Bw9u61X+duEWHIQqTL6kzgV80Cj3ibbnAedZ2QcVKLpj+dyg19ogoXEqdH5fdGU3mtlZWnVZrdxtntqlVGxnxKrKvOiOOlYVCsYNTTBXrFhO3dpmSTtD756qJuN0WOeeNciEK6CZqn9WTo3gfC4izLns6vHsOE6L3LN8V/q9UUXWTqqirfUXVBwTiu0h0sgTiUVsDUSXMu0ks7Gi9xy4hj/d4munjj8Tfa7mbGG04zqLhHUA/CMDRK/4AJBQ== 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=0DEWAf8QVcGJU9hBCwApXzw/3hU0O1Hc4bHLQf4ThCU=; b=mypbuO78uRv48Jf1dfD+IhhfggY9vx0V7JlCvaOmW1yBRd4kU/h97unt72YF5Y1u6xb7kWrE9SJYWlIbbPDZvvGyKGI9mUcTuMh2nQ0cpovnTjTiE681pahyxQY7nbM3ZBPre/lAHfA4ij+kBE7aJO0LwakAtUwNGFBXtbgtM1DkKQQ+UzdBpDebydzmshEkfwTzR2TettXet+MPdEvQAXpLwut04w/TPHrS2Q+gHAPabmQ+hv2o4Z7WWnBlCatvBPydYlBlm9WZihE53qDPwOrQ5gco7OvNW9Z3q4TdYUqmc2YiyfPfFZUFsH/YnoUp4lNls0GL9cvPKeNulGj8UQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 208.255.156.42) smtp.rcpttodomain=nvidia.com smtp.mailfrom=cornelisnetworks.com; dmarc=bestguesspass action=none header.from=cornelisnetworks.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cornelisnetworks.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=0DEWAf8QVcGJU9hBCwApXzw/3hU0O1Hc4bHLQf4ThCU=; b=XlrzUr0uzrRnpXFRi8MrabnNcVv6sj/PSFyvlMowLGtp7PVeMcRa5zSHx/p4Q0Bfdb+ARleP43rqMmeUlkclSwmh7yMgSJ254RUmxNpVlX6KfWROSUjPP2aH1snOmr9SHF0n9wydeDNVYqhdyPw6S5WPYleiPE6o7EbMAVPdo+nZ/5xMEKz/p8Rg0WR41QnaDF9PHkG0sl2OR3i7FMZEjpuWkx6dznfjXMS59+zbWxeidr+EzxN/2dqxRiwwb16cosoy+Hg6AemvrMGL7mnVFJ+jMdns62DsPATDNSOaqhmSCs34BUG3zL9Ehk+1lQK6kIHs+xgv39nglWW3oxqB+g== Received: from BL1PR13CA0291.namprd13.prod.outlook.com (2603:10b6:208:2bc::26) by CO1PR01MB6616.prod.exchangelabs.com (2603:10b6:303:da::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5986.18; Mon, 9 Jan 2023 17:31:28 +0000 Received: from BL02EPF00010206.namprd05.prod.outlook.com (2603:10b6:208:2bc:cafe::82) by BL1PR13CA0291.outlook.office365.com (2603:10b6:208:2bc::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6002.11 via Frontend Transport; Mon, 9 Jan 2023 17:31:28 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 208.255.156.42) smtp.mailfrom=cornelisnetworks.com; dkim=none (message not signed) header.d=none;dmarc=bestguesspass action=none header.from=cornelisnetworks.com; Received-SPF: Pass (protection.outlook.com: domain of cornelisnetworks.com designates 208.255.156.42 as permitted sender) receiver=protection.outlook.com; client-ip=208.255.156.42; helo=awfm-02.cornelisnetworks.com; pr=C Received: from awfm-02.cornelisnetworks.com (208.255.156.42) by BL02EPF00010206.mail.protection.outlook.com (10.167.241.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5986.15 via Frontend Transport; Mon, 9 Jan 2023 17:31:27 +0000 Received: from awfm-02.cornelisnetworks.com (localhost [127.0.0.1]) by awfm-02.cornelisnetworks.com (8.16.1/8.16.1) with ESMTP id 309HVQEe1472615; Mon, 9 Jan 2023 12:31:26 -0500 Subject: [PATCH for-rc 5/6] IB/hfi1: Immediately remove invalid memory from hardware From: Dennis Dalessandro To: jgg@nvidia.com, leonro@nvidia.com Cc: Dean Luick , linux-rdma@vger.kernel.org Date: Mon, 09 Jan 2023 12:31:26 -0500 Message-ID: <167328548663.1472310.7871808081861622659.stgit@awfm-02.cornelisnetworks.com> In-Reply-To: <167328512911.1472310.3529280633243532911.stgit@awfm-02.cornelisnetworks.com> References: <167328512911.1472310.3529280633243532911.stgit@awfm-02.cornelisnetworks.com> User-Agent: StGit/1.5.dev2+g9ce680a5 MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF00010206:EE_|CO1PR01MB6616:EE_ X-MS-Office365-Filtering-Correlation-Id: 50aacbc9-f748-4e75-ec96-08daf26756bf X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: JQdLgAkaOAq00vlLZ74PdjdqQ815ypFfxh8CsYxri/z18UsI6cE8Hv18I0/BSyGvRrO17D59q8cFnGtCXN5UUz/vM7N8xXUu9eHXc5mUn8cisR+aKvXeqAC9GFUTxLymPZrmAWrwMI1wAgSOOaNADs3HgNc+0ezESHPd50Eg79ro0gJhYLch1Z4KkyqlSFAz5NGNxZL1XoaIoZ1KpE/0rZaCMJlG3SRsZZlztT3zTJRBKv5EQtiJRd0PnF8cuRlL/v4NLraAhMzI3DMt0brehXlAClUyRVQn2GquSY+e7DoP+T9aV+onh5VErGTw0AKa4spLLQOADpQM36+sNR1RqIQUEhnqs+8CERNOg4tvvTQ4iD3dA9Ek8Y51D3oYis+oJxHeBmn5Igwy72loyUay91r1mrAAQ9Woa44KImvh3/Hh4zVu8lgp95KRu52cITZAidjvXtdHKLovii1IgzyGlUfQbnXVtq4W60mSh/Lz4ahG8x8+0x9EcM5Fivwy2EL6KsyDIsZSquRbCKlwH3bwX6bl9Wme5PTEZchyC2cB33Y89hIrSb414txiq0UXBkEGwbGi5F/x9VA5tClWAHaYYVfcQ/GJ2Bh5p0EHagO1Gis8ceGQif+RHvM4LiLLNZUvifpcWFVpsxaOa73UslH4jMOFCx/wecvafEtJdWYg0HgTkwsrbXsDwF5CylPEHRiml+DW5OPx960W5lCQyS3cCtYSsuMiqWHWaUsZqikRtxM= X-Forefront-Antispam-Report: CIP:208.255.156.42;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:awfm-02.cornelisnetworks.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230022)(4636009)(396003)(346002)(376002)(39840400004)(136003)(451199015)(36840700001)(46966006)(103116003)(41300700001)(4326008)(83380400001)(8676002)(70206006)(70586007)(5660300002)(8936002)(26005)(55016003)(40480700001)(186003)(356005)(7126003)(336012)(81166007)(7696005)(478600001)(86362001)(36860700001)(316002)(82310400005)(426003)(47076005)(2906002)(44832011)(14773001)(36900700001);DIR:OUT;SFP:1102; X-OriginatorOrg: cornelisnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Jan 2023 17:31:27.5755 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 50aacbc9-f748-4e75-ec96-08daf26756bf X-MS-Exchange-CrossTenant-Id: 4dbdb7da-74ee-4b45-8747-ef5ce5ebe68a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=4dbdb7da-74ee-4b45-8747-ef5ce5ebe68a;Ip=[208.255.156.42];Helo=[awfm-02.cornelisnetworks.com] X-MS-Exchange-CrossTenant-AuthSource: BL02EPF00010206.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO1PR01MB6616 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org From: Dean Luick When a user expected receive page is unmapped, it should be immediately removed from hardware rather than depend on a reaction from user space. Fixes: 2677a7680e77 ("IB/hfi1: Fix memory leak during unexpected shutdown") Signed-off-by: Dean Luick Signed-off-by: Dennis Dalessandro --- drivers/infiniband/hw/hfi1/user_exp_rcv.c | 43 ++++++++++++++++++++--------- drivers/infiniband/hw/hfi1/user_exp_rcv.h | 1 + 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/drivers/infiniband/hw/hfi1/user_exp_rcv.c b/drivers/infiniband/hw/hfi1/user_exp_rcv.c index 88df8ca4bb57..f402af1e2903 100644 --- a/drivers/infiniband/hw/hfi1/user_exp_rcv.c +++ b/drivers/infiniband/hw/hfi1/user_exp_rcv.c @@ -28,8 +28,9 @@ static int program_rcvarray(struct hfi1_filedata *fd, struct tid_user_buf *, unsigned int start, u16 count, u32 *tidlist, unsigned int *tididx, unsigned int *pmapped); -static int unprogram_rcvarray(struct hfi1_filedata *fd, u32 tidinfo, - struct tid_group **grp); +static int unprogram_rcvarray(struct hfi1_filedata *fd, u32 tidinfo); +static void __clear_tid_node(struct hfi1_filedata *fd, + struct tid_rb_node *node); static void clear_tid_node(struct hfi1_filedata *fd, struct tid_rb_node *node); static const struct mmu_interval_notifier_ops tid_mn_ops = { @@ -469,7 +470,7 @@ int hfi1_user_exp_rcv_clear(struct hfi1_filedata *fd, mutex_lock(&uctxt->exp_mutex); for (tididx = 0; tididx < tinfo->tidcnt; tididx++) { - ret = unprogram_rcvarray(fd, tidinfo[tididx], NULL); + ret = unprogram_rcvarray(fd, tidinfo[tididx]); if (ret) { hfi1_cdbg(TID, "Failed to unprogram rcv array %d", ret); @@ -723,6 +724,7 @@ static int set_rcvarray_entry(struct hfi1_filedata *fd, } node->fdata = fd; + mutex_init(&node->invalidate_mutex); node->phys = page_to_phys(pages[0]); node->npages = npages; node->rcventry = rcventry; @@ -762,8 +764,7 @@ static int set_rcvarray_entry(struct hfi1_filedata *fd, return -EFAULT; } -static int unprogram_rcvarray(struct hfi1_filedata *fd, u32 tidinfo, - struct tid_group **grp) +static int unprogram_rcvarray(struct hfi1_filedata *fd, u32 tidinfo) { struct hfi1_ctxtdata *uctxt = fd->uctxt; struct hfi1_devdata *dd = uctxt->dd; @@ -786,9 +787,6 @@ static int unprogram_rcvarray(struct hfi1_filedata *fd, u32 tidinfo, if (!node || node->rcventry != (uctxt->expected_base + rcventry)) return -EBADF; - if (grp) - *grp = node->grp; - if (fd->use_mn) mmu_interval_notifier_remove(&node->notifier); cacheless_tid_rb_remove(fd, node); @@ -796,23 +794,34 @@ static int unprogram_rcvarray(struct hfi1_filedata *fd, u32 tidinfo, return 0; } -static void clear_tid_node(struct hfi1_filedata *fd, struct tid_rb_node *node) +static void __clear_tid_node(struct hfi1_filedata *fd, struct tid_rb_node *node) { struct hfi1_ctxtdata *uctxt = fd->uctxt; struct hfi1_devdata *dd = uctxt->dd; + mutex_lock(&node->invalidate_mutex); + if (node->freed) + goto done; + node->freed = true; + trace_hfi1_exp_tid_unreg(uctxt->ctxt, fd->subctxt, node->rcventry, node->npages, node->notifier.interval_tree.start, node->phys, node->dma_addr); - /* - * Make sure device has seen the write before we unpin the - * pages. - */ + /* Make sure device has seen the write before pages are unpinned */ hfi1_put_tid(dd, node->rcventry, PT_INVALID_FLUSH, 0, 0); unpin_rcv_pages(fd, NULL, node, 0, node->npages, true); +done: + mutex_unlock(&node->invalidate_mutex); +} + +static void clear_tid_node(struct hfi1_filedata *fd, struct tid_rb_node *node) +{ + struct hfi1_ctxtdata *uctxt = fd->uctxt; + + __clear_tid_node(fd, node); node->grp->used--; node->grp->map &= ~(1 << (node->rcventry - node->grp->base)); @@ -871,10 +880,16 @@ static bool tid_rb_invalidate(struct mmu_interval_notifier *mni, if (node->freed) return true; + /* take action only if unmapping */ + if (range->event != MMU_NOTIFY_UNMAP) + return true; + trace_hfi1_exp_tid_inval(uctxt->ctxt, fdata->subctxt, node->notifier.interval_tree.start, node->rcventry, node->npages, node->dma_addr); - node->freed = true; + + /* clear the hardware rcvarray entry */ + __clear_tid_node(fdata, node); spin_lock(&fdata->invalid_lock); if (fdata->invalid_tid_idx < uctxt->expected_count) { diff --git a/drivers/infiniband/hw/hfi1/user_exp_rcv.h b/drivers/infiniband/hw/hfi1/user_exp_rcv.h index 8c53e416bf84..2ddb3dac7d91 100644 --- a/drivers/infiniband/hw/hfi1/user_exp_rcv.h +++ b/drivers/infiniband/hw/hfi1/user_exp_rcv.h @@ -27,6 +27,7 @@ struct tid_user_buf { struct tid_rb_node { struct mmu_interval_notifier notifier; struct hfi1_filedata *fdata; + struct mutex invalidate_mutex; /* covers hw removal */ unsigned long phys; struct tid_group *grp; u32 rcventry; From patchwork Mon Jan 9 17:31:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dennis Dalessandro X-Patchwork-Id: 13093941 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 C4F97C5479D for ; Mon, 9 Jan 2023 17:32:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233877AbjAIRcR (ORCPT ); Mon, 9 Jan 2023 12:32:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53680 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237472AbjAIRbl (ORCPT ); Mon, 9 Jan 2023 12:31:41 -0500 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2126.outbound.protection.outlook.com [40.107.92.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 24E38B70 for ; Mon, 9 Jan 2023 09:31:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CX/JeJyCZ8y6tvhXs3Ehh9CiO+eU/19lG1c8y5+jD6xyC7/4zWLv24muRHQ6Ghkue+aJgfe6LBpXybh+wZw3psbMZjdOh+7Riq77Kostv91byF61+cnJbY9DBN+MhWyc5CAkVfWCPJVNTwACbbb5vEXjsVPRTqmYbZLGF/s2LJvKACAUxapZLOQbS5Z1s0/5RYy6ofvGys9isBGYkKUHAkSYVBzjNNAqt7q5W/km4uRkATHgx3jN5/DXwoXyvlt5LQUsAPu+6RoL/PxpGm32EqXJUSYHLnZbrqawyMY3EqLNLT1jqotNIJK5kW/0E2BsHYXt4nShNfEl1n1Jv6BnKQ== 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=mWHxjjSGrA1VujlrgEPpdNoPmLLlOYYVETSIr2Eqjlo=; b=bKyLeRn3lcTtoqO4hNnXarhiWS2PbjVgRG9sdktXD6xhTt9gIkMGYwKb1MVgUub1YRdaLsv/i7QuKDPh5h0pPn8Q2cwFk3PII9tQqyz4mAk8lNE/MowTs6iqFw7Q/5jPtlXi5T6irmxVM8LYbR0HfpZhp03l+FMbqDtjsOvZ3il4Va7VDgPK16YPs+ysvWzEO1zGZ4NnFz19Txgrj5v1tlZR7BL+DDrPs5pKwK5KyT2hi3gCisDFu+c7Bl8FB0ftGmuQegRxex5EyWCK3bzR/yJsJYntFLR9XUp7ZAz/ON5PCa7G+hCw2OIzLUYdmhI8MOlv7EaDEM4UE4d/xAALcA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 208.255.156.42) smtp.rcpttodomain=nvidia.com smtp.mailfrom=cornelisnetworks.com; dmarc=bestguesspass action=none header.from=cornelisnetworks.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cornelisnetworks.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=mWHxjjSGrA1VujlrgEPpdNoPmLLlOYYVETSIr2Eqjlo=; b=RMdng6yELmkWdzAW8encjPPSX1hE/+XBXmY0eceMsWO/TW5GcncyXUHPAPbrb15r2Sba+7gtG+LJ3biR7xkjMED4x7xuwhLMbdRKgYUVppkSIIHHMUqB9TgIxWV1cdNlDgZc4c+5azqpVLPkZ2iizZShi6uIGaTsATh0sxhrkhhotVruVGCdSt+FiBmkuNzR4FCzISZA8f1QJ+lA/Mg2qeowLWGh05px9ULLvK0P7R3hJiPFCX5167O2Db+T2TUctz6Fnu8B2Q+kl0wRV5/k30tGxsCnDA2yEwjB9U27RASz4Oo4RFsnI8E3hs2gDAfYMlGwFcyRDEG9U5wh/zspWQ== Received: from BL1PR13CA0248.namprd13.prod.outlook.com (2603:10b6:208:2ba::13) by SJ0PR01MB6176.prod.exchangelabs.com (2603:10b6:a03:29c::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5986.18; Mon, 9 Jan 2023 17:31:34 +0000 Received: from BL02EPF00010209.namprd05.prod.outlook.com (2603:10b6:208:2ba:cafe::4e) by BL1PR13CA0248.outlook.office365.com (2603:10b6:208:2ba::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6002.6 via Frontend Transport; Mon, 9 Jan 2023 17:31:33 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 208.255.156.42) smtp.mailfrom=cornelisnetworks.com; dkim=none (message not signed) header.d=none;dmarc=bestguesspass action=none header.from=cornelisnetworks.com; Received-SPF: Pass (protection.outlook.com: domain of cornelisnetworks.com designates 208.255.156.42 as permitted sender) receiver=protection.outlook.com; client-ip=208.255.156.42; helo=awfm-02.cornelisnetworks.com; pr=C Received: from awfm-02.cornelisnetworks.com (208.255.156.42) by BL02EPF00010209.mail.protection.outlook.com (10.167.241.198) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5986.15 via Frontend Transport; Mon, 9 Jan 2023 17:31:32 +0000 Received: from awfm-02.cornelisnetworks.com (localhost [127.0.0.1]) by awfm-02.cornelisnetworks.com (8.16.1/8.16.1) with ESMTP id 309HVV7C1472625; Mon, 9 Jan 2023 12:31:31 -0500 Subject: [PATCH for-rc 6/6] IB/hfi1: Remove user expected buffer invalidate race From: Dennis Dalessandro To: jgg@nvidia.com, leonro@nvidia.com Cc: Dean Luick , linux-rdma@vger.kernel.org Date: Mon, 09 Jan 2023 12:31:31 -0500 Message-ID: <167328549178.1472310.9867497376936699488.stgit@awfm-02.cornelisnetworks.com> In-Reply-To: <167328512911.1472310.3529280633243532911.stgit@awfm-02.cornelisnetworks.com> References: <167328512911.1472310.3529280633243532911.stgit@awfm-02.cornelisnetworks.com> User-Agent: StGit/1.5.dev2+g9ce680a5 MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF00010209:EE_|SJ0PR01MB6176:EE_ X-MS-Office365-Filtering-Correlation-Id: e65188c3-2a6e-480c-f2a8-08daf26759e1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Or42fr9YDVpTtjhSivcrh17Zpod66l0ogVnzJJ9uVxUntuQsBrhey7sn1sFxljvl5Xnl4soP8Fli/DkYcg41sZEsWJPI3zzAUs6kWqA4L+fh6F9uau61Fh5qpp8D9gvNydr5oClRW6mktDOeoKO32lrKIS0fnKqBfBkii2UWY+gcEFyaBrO30qsMqa+KwIKjfAt6WxyaYmeWYpnvFj8sMpbjF7Tzcn5XqkVhQIykffuJyUApFvDyjdsH3hpJn5IAr7U2iQGpNWwHoPvNr+wtBRzqY4apS1c0P6/MPiRBA7uuSn6jh9b2tZNlTTXITUt0/svut2JFwtWMvg06vdSqaHRyqlzeAATfG7ouBIdXLYtqkwqqI3tAcXaMMLq9EFT5zfhIzxYREOth4ESOm+syb8haArpidEFAELPmGTdVBdCx9Mex0r6hqpeWbnosnOrXgAyl27yFECmdC+LJhANVHN/5JvfIwBBLhoQbj8NhN0D58282BnNQF7G3ygpWh8r5RcVojbCOyQCoT1TfbUsBvG5hZWjmZ1rJhX9CIsw+4slKUYwdUAHsoldiP/RbXW4QkxJob3B6+bDSPFqBK3VQh+WtoQ9yYFs9/T5A62/H6VOwNRjkmuLR87qf2oYRNwC5ROHTaAedQs1a+BAMpuePcJmuL/g9oOWOwuzaH4fbpHcCsB761YtUu7pzqCQVQNrGnHAInpMDtSKssu3w2RjQkw== X-Forefront-Antispam-Report: CIP:208.255.156.42;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:awfm-02.cornelisnetworks.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230022)(4636009)(346002)(136003)(376002)(39840400004)(396003)(451199015)(36840700001)(46966006)(41300700001)(7696005)(478600001)(86362001)(70206006)(70586007)(40480700001)(8936002)(5660300002)(4326008)(2906002)(26005)(186003)(8676002)(55016003)(356005)(336012)(7126003)(83380400001)(426003)(44832011)(47076005)(36860700001)(103116003)(82310400005)(81166007)(316002)(36900700001);DIR:OUT;SFP:1102; X-OriginatorOrg: cornelisnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Jan 2023 17:31:32.8942 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e65188c3-2a6e-480c-f2a8-08daf26759e1 X-MS-Exchange-CrossTenant-Id: 4dbdb7da-74ee-4b45-8747-ef5ce5ebe68a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=4dbdb7da-74ee-4b45-8747-ef5ce5ebe68a;Ip=[208.255.156.42];Helo=[awfm-02.cornelisnetworks.com] X-MS-Exchange-CrossTenant-AuthSource: BL02EPF00010209.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR01MB6176 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org From: Dean Luick During setup, there is a possible race between a page invalidate and hardware programming. Add a covering invalidate over the user target range during setup. If anything within that range is invalidated during setup, fail the setup. Once set up, each TID will have its own invalidate callback and invalidate. Fixes: 3889551db212 ("RDMA/hfi1: Use mmu_interval_notifier_insert for user_exp_rcv") Signed-off-by: Dean Luick Signed-off-by: Dennis Dalessandro --- drivers/infiniband/hw/hfi1/user_exp_rcv.c | 58 +++++++++++++++++++++++++++-- drivers/infiniband/hw/hfi1/user_exp_rcv.h | 2 + 2 files changed, 55 insertions(+), 5 deletions(-) diff --git a/drivers/infiniband/hw/hfi1/user_exp_rcv.c b/drivers/infiniband/hw/hfi1/user_exp_rcv.c index f402af1e2903..b02f2f0809c8 100644 --- a/drivers/infiniband/hw/hfi1/user_exp_rcv.c +++ b/drivers/infiniband/hw/hfi1/user_exp_rcv.c @@ -23,6 +23,9 @@ static void cacheless_tid_rb_remove(struct hfi1_filedata *fdata, static bool tid_rb_invalidate(struct mmu_interval_notifier *mni, const struct mmu_notifier_range *range, unsigned long cur_seq); +static bool tid_cover_invalidate(struct mmu_interval_notifier *mni, + const struct mmu_notifier_range *range, + unsigned long cur_seq); static int program_rcvarray(struct hfi1_filedata *fd, struct tid_user_buf *, struct tid_group *grp, unsigned int start, u16 count, @@ -36,6 +39,9 @@ static void clear_tid_node(struct hfi1_filedata *fd, struct tid_rb_node *node); static const struct mmu_interval_notifier_ops tid_mn_ops = { .invalidate = tid_rb_invalidate, }; +static const struct mmu_interval_notifier_ops tid_cover_ops = { + .invalidate = tid_cover_invalidate, +}; /* * Initialize context and file private data needed for Expected @@ -254,6 +260,7 @@ int hfi1_user_exp_rcv_setup(struct hfi1_filedata *fd, tididx = 0, mapped, mapped_pages = 0; u32 *tidlist = NULL; struct tid_user_buf *tidbuf; + unsigned long mmu_seq = 0; if (!PAGE_ALIGNED(tinfo->vaddr)) return -EINVAL; @@ -264,6 +271,7 @@ int hfi1_user_exp_rcv_setup(struct hfi1_filedata *fd, if (!tidbuf) return -ENOMEM; + mutex_init(&tidbuf->cover_mutex); tidbuf->vaddr = tinfo->vaddr; tidbuf->length = tinfo->length; tidbuf->psets = kcalloc(uctxt->expected_count, sizeof(*tidbuf->psets), @@ -273,6 +281,16 @@ int hfi1_user_exp_rcv_setup(struct hfi1_filedata *fd, goto fail_release_mem; } + if (fd->use_mn) { + ret = mmu_interval_notifier_insert( + &tidbuf->notifier, current->mm, + tidbuf->vaddr, tidbuf->npages * PAGE_SIZE, + &tid_cover_ops); + if (ret) + goto fail_release_mem; + mmu_seq = mmu_interval_read_begin(&tidbuf->notifier); + } + pinned = pin_rcv_pages(fd, tidbuf); if (pinned <= 0) { ret = (pinned < 0) ? pinned : -ENOSPC; @@ -415,6 +433,20 @@ int hfi1_user_exp_rcv_setup(struct hfi1_filedata *fd, unpin_rcv_pages(fd, tidbuf, NULL, mapped_pages, pinned - mapped_pages, false); + if (fd->use_mn) { + /* check for an invalidate during setup */ + bool fail = false; + + mutex_lock(&tidbuf->cover_mutex); + fail = mmu_interval_read_retry(&tidbuf->notifier, mmu_seq); + mutex_unlock(&tidbuf->cover_mutex); + + if (fail) { + ret = -EBUSY; + goto fail_unprogram; + } + } + tinfo->tidcnt = tididx; tinfo->length = mapped_pages * PAGE_SIZE; @@ -424,6 +456,8 @@ int hfi1_user_exp_rcv_setup(struct hfi1_filedata *fd, goto fail_unprogram; } + if (fd->use_mn) + mmu_interval_notifier_remove(&tidbuf->notifier); kfree(tidbuf->pages); kfree(tidbuf->psets); kfree(tidbuf); @@ -442,6 +476,8 @@ int hfi1_user_exp_rcv_setup(struct hfi1_filedata *fd, fd->tid_used -= pageset_count; spin_unlock(&fd->tid_lock); fail_unpin: + if (fd->use_mn) + mmu_interval_notifier_remove(&tidbuf->notifier); if (pinned > 0) unpin_rcv_pages(fd, tidbuf, NULL, 0, pinned, false); fail_release_mem: @@ -740,11 +776,6 @@ static int set_rcvarray_entry(struct hfi1_filedata *fd, &tid_mn_ops); if (ret) goto out_unmap; - /* - * FIXME: This is in the wrong order, the notifier should be - * established before the pages are pinned by pin_rcv_pages. - */ - mmu_interval_read_begin(&node->notifier); } fd->entry_to_rb[node->rcventry - uctxt->expected_base] = node; @@ -919,6 +950,23 @@ static bool tid_rb_invalidate(struct mmu_interval_notifier *mni, return true; } +static bool tid_cover_invalidate(struct mmu_interval_notifier *mni, + const struct mmu_notifier_range *range, + unsigned long cur_seq) +{ + struct tid_user_buf *tidbuf = + container_of(mni, struct tid_user_buf, notifier); + + /* take action only if unmapping */ + if (range->event == MMU_NOTIFY_UNMAP) { + mutex_lock(&tidbuf->cover_mutex); + mmu_interval_set_seq(mni, cur_seq); + mutex_unlock(&tidbuf->cover_mutex); + } + + return true; +} + static void cacheless_tid_rb_remove(struct hfi1_filedata *fdata, struct tid_rb_node *tnode) { diff --git a/drivers/infiniband/hw/hfi1/user_exp_rcv.h b/drivers/infiniband/hw/hfi1/user_exp_rcv.h index 2ddb3dac7d91..f8ee997d0050 100644 --- a/drivers/infiniband/hw/hfi1/user_exp_rcv.h +++ b/drivers/infiniband/hw/hfi1/user_exp_rcv.h @@ -16,6 +16,8 @@ struct tid_pageset { }; struct tid_user_buf { + struct mmu_interval_notifier notifier; + struct mutex cover_mutex; unsigned long vaddr; unsigned long length; unsigned int npages;