Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3260598rwb; Mon, 15 Aug 2022 22:35:08 -0700 (PDT) X-Google-Smtp-Source: AA6agR7oqQDasjnlNfWVI06TN8pSjRdAfzljx0QKAmqL2RTsGarYE3Fnzlc3b5ipWimCrGLi75Bu X-Received: by 2002:a17:902:a50e:b0:171:4d1b:60a4 with SMTP id s14-20020a170902a50e00b001714d1b60a4mr20373797plq.79.1660628108345; Mon, 15 Aug 2022 22:35:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660628108; cv=none; d=google.com; s=arc-20160816; b=OJM0bJqbWnmX0dn9yptrXXWgcXVbNjEnrc45fwHr0c77/CKWrpJaXjPfswKYAOxpjF Kn2ycd3nlwibrlW38IQyS8/k26ysr6kWZEMDQo+kuoRntHjvprw3miIOv29z0kqb1Sl6 WgOp6uN0RMKq2PMDLfFYxYzDupBinCgMXQmqnyBfqu6jbG3tq7Rkd41n8+i+q99zarYX AcJYrnNs3aucl925uWkE4zqrtgo/T8jgJm6yC7dKEg3bM9siYRw4a1+Qd7n1jshxmMij dS8zb5x+oXdhxWjBwsGnzrxuJ2oXVjbc66zO3KmrSb3Jw+b96YgEeyPoq18DKL0CmMn1 eNOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=w0BOjgIv1jAeS5CAAWkLaSWKyZmMOGnw1oQHUZ5yRh0=; b=alWHruD6pzcylOzQIGqHKBS04V5QyuLGfKdHP7eVOAqMxLP49m7dMXcWeSPwvnrXmX B1zs0pHCtwyVlXIfRJpmghxdDXe/KRYa/NDn7fU3p9TElIZsz/y77uEWJ9DhC5O/zl0E 5ozTBXikLEFKtcg664HlZjVx5llCxpL0Be+mSk3bbdl0hqD9uH8OFh2XCaIjd3xYZFNt SgV2UVDMMP+MUVrvyp/huhaldv9RdVc8nylo2/8e3irgLWHJuwU2cegMmVNuF9LvB5vE bCSJYDIEt7CSju7CYtXveuZa7UdrFrMI+hMjLFoRuJ7yw6AcRziH0qk24X5VbHDmYjRB vYrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=vT+qjInG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j1-20020a63fc01000000b0041b539aec98si12211077pgi.816.2022.08.15.22.34.57; Mon, 15 Aug 2022 22:35:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=vT+qjInG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232230AbiHPEoj (ORCPT + 99 others); Tue, 16 Aug 2022 00:44:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42698 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232428AbiHPElN (ORCPT ); Tue, 16 Aug 2022 00:41:13 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9436ED4D; Mon, 15 Aug 2022 13:32:32 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id 06060CE12C5; Mon, 15 Aug 2022 20:32:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C772BC433D6; Mon, 15 Aug 2022 20:32:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660595549; bh=xqfJ9NdAkPaq4jMxZ9BS+VzU3qb/PbaYW6pplMlD1p0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vT+qjInGKM9ALcWLhObEzZ6SurvkZ7ylf7HfwtMg2NfGiYDm/h6DCYz/uken7j3Xi N9onZUKpjHVKTB3scOeWL0rMLuCmMYcFyPHMonzSfHzYvc9da7We3uHk63fnvHl+/V MoW/5DaLSjDou7oyx4Kiqha/IbvstIxCG5F4TcBo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Carpenter , Oded Gabbay , Sasha Levin Subject: [PATCH 5.19 0792/1157] habanalabs: fix double unlock on error in map_device_va() Date: Mon, 15 Aug 2022 20:02:28 +0200 Message-Id: <20220815180511.156800178@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180439.416659447@linuxfoundation.org> References: <20220815180439.416659447@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dan Carpenter [ Upstream commit a43a9f67774adbd575d10ec88824016fbe034777 ] If hl_mmu_prefetch_cache_range() fails then this code calls mutex_unlock(&ctx->mmu_lock) when it's no longer holding the mutex. Fixes: 9e495e24003e ("habanalabs: do MMU prefetch as deferred work") Signed-off-by: Dan Carpenter Reviewed-by: Oded Gabbay Signed-off-by: Oded Gabbay Signed-off-by: Sasha Levin --- drivers/misc/habanalabs/common/memory.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/misc/habanalabs/common/memory.c b/drivers/misc/habanalabs/common/memory.c index 663dd7e589d4..d5e6500f8a1f 100644 --- a/drivers/misc/habanalabs/common/memory.c +++ b/drivers/misc/habanalabs/common/memory.c @@ -1245,16 +1245,16 @@ static int map_device_va(struct hl_ctx *ctx, struct hl_mem_in *args, u64 *device rc = map_phys_pg_pack(ctx, ret_vaddr, phys_pg_pack); if (rc) { dev_err(hdev->dev, "mapping page pack failed for handle %u\n", handle); + mutex_unlock(&ctx->mmu_lock); goto map_err; } rc = hl_mmu_invalidate_cache_range(hdev, false, *vm_type | MMU_OP_SKIP_LOW_CACHE_INV, ctx->asid, ret_vaddr, phys_pg_pack->total_size); + mutex_unlock(&ctx->mmu_lock); if (rc) goto map_err; - mutex_unlock(&ctx->mmu_lock); - /* * prefetch is done upon user's request. it is performed in WQ as and so can * be outside the MMU lock. the operation itself is already protected by the mmu lock @@ -1283,8 +1283,6 @@ static int map_device_va(struct hl_ctx *ctx, struct hl_mem_in *args, u64 *device return rc; map_err: - mutex_unlock(&ctx->mmu_lock); - if (add_va_block(hdev, va_range, ret_vaddr, ret_vaddr + phys_pg_pack->total_size - 1)) dev_warn(hdev->dev, -- 2.35.1