Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp557439rwb; Fri, 18 Nov 2022 05:24:49 -0800 (PST) X-Google-Smtp-Source: AA0mqf7zVWMs64N5B9l4SqvZqNF1DVVjIDCD60GeqrKhAN5503n6RTyR+v0WrCxdNslFQFkGbUh7 X-Received: by 2002:a17:902:bd83:b0:187:31da:a260 with SMTP id q3-20020a170902bd8300b0018731daa260mr7445156pls.64.1668777888773; Fri, 18 Nov 2022 05:24:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668777888; cv=none; d=google.com; s=arc-20160816; b=zgZont30gSVvDXkc2urDTzZK7+caVWhKvf6Q329ie00g2sTW2TZ87F8fH2qT6tUqT5 pPPiJljZcGvCzSn8daLzv3uQGSpktlOofMz9xOvJLd+31hQjWaZn0N6kn4G2mI2X/bwO fZO9hCSR7202gx2VX1m4j1G0iqSQpw8hhN8NaIaOk79XdxbUZCG6Ytabi0s/Eh9RAavW gwnojCpycgnwpVgAzL7AApSJDsZvSJ8teRbenvd20G9dfkddOPeBg0e7gxtrOM8eVadY V71k4GyG3FemNBwGwzvUHQHpzv30x2l1wO8+NdEoDLbUcQ5p+8zX4lcFJDb/kBtyv6YE yZXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:in-reply-to:cc:references:message-id:date :subject:mime-version:from:content-transfer-encoding:dkim-signature; bh=KXa/KqsWUx3LunXpns38Xz9CP5g3bIDgcegqXBexaR0=; b=rNdPRC+yyF9yhCWGxLMjBRybjWDZArpG9MQEqBGURJqSUVqUgCKuYTs8dDw73AdOuQ 3SSeLhJnYc8nL1fFkxphxkslgwvUL3fPjss2LfUrvYtHuPRfvaDDEvv+bRAdYGs0y3jy L8uD/YuiqIaZV02cvEiRmNDsTot7gepIrOK4hys79qA3smPqCqD+x3bO58+ezCSftU72 HNaYekKtEaOr+pIKcEbzyd75guuW3eS8LXHtXi71JbPrA83nKSQOi1OmAba1y8OdID3T MxjNGYk9m3z8EiJK2xuQkjGE1jNa2qnnqjhc9gJxu7+lMXkiR2URu+HD2dCA/j7/NyX/ Q/+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@dilger-ca.20210112.gappssmtp.com header.s=20210112 header.b=rWu5hzNn; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nv5-20020a17090b1b4500b0020a613f8c79si8217715pjb.129.2022.11.18.05.24.29; Fri, 18 Nov 2022 05:24:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-ext4-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=@dilger-ca.20210112.gappssmtp.com header.s=20210112 header.b=rWu5hzNn; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242036AbiKRNVI (ORCPT + 99 others); Fri, 18 Nov 2022 08:21:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44480 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241602AbiKRNVA (ORCPT ); Fri, 18 Nov 2022 08:21:00 -0500 Received: from mail-ot1-x32f.google.com (mail-ot1-x32f.google.com [IPv6:2607:f8b0:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D37D467F40 for ; Fri, 18 Nov 2022 05:20:57 -0800 (PST) Received: by mail-ot1-x32f.google.com with SMTP id g51-20020a9d12b6000000b0066dbea0d203so3033451otg.6 for ; Fri, 18 Nov 2022 05:20:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dilger-ca.20210112.gappssmtp.com; s=20210112; h=to:in-reply-to:cc:references:message-id:date:subject:mime-version :from:content-transfer-encoding:from:to:cc:subject:date:message-id :reply-to; bh=KXa/KqsWUx3LunXpns38Xz9CP5g3bIDgcegqXBexaR0=; b=rWu5hzNnF25rLZATEON3a0L1rGQvcrMTYTugURvQltpAJFZWhkDwlLFtKpp8SG4ffh V4FC3iJb0zlCWTOq/lzby6aWArhjR/GoFISYVJAIuK3c84vBV60RVluDxxQ30kPvS39H 2qoxRdsTUr36CJZoqWim4bpfvp5bPnHtfumcwWPgCgtHfR69VDuV2YsRJz/DRkzj5NOF o+yHj625weo3j2mqi45xVQh/Q9557I05Q7wd3KH1O/vSJJqV52e4mSxFl3cmDo+V5hpe lKUs04zBDmFrisvQToCWgAwEgy9Dho2uj1kLYK6mqvdGr+vlhQlTIAJx07EUiZzemgY8 7LUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:in-reply-to:cc:references:message-id:date:subject:mime-version :from:content-transfer-encoding:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KXa/KqsWUx3LunXpns38Xz9CP5g3bIDgcegqXBexaR0=; b=O68rrMCUbw78es45ZX/9Zrznsx6e2KD7Ae+Lj102QG1hLdP6lABpjSl1S5I3Ue45vB GgguXvCMBSAtZx+nvooztib+fISgdKf/1ouX0zkr66DGJRmyuqfHxIR1gcBQo1gER9/L plhLie+Qgu2Ld8WuBivwINRh/dP8LVODuG4Q6IDpGZohwrBYT6s+HjSXcw93U1dLRhDB yHt0VEComCgkb8xehvxZdAePlb0QOG8qKZCE3AnZmcyfuLbk2JSHukR+ztx74EednduK wEZen4y52wRygXFCoISDD1rb2/2o/Z8RARrS1CUQz8Ble4bqWt1MF1ms+ECHaTKH4+WL Ix7g== X-Gm-Message-State: ANoB5pmr06d+9/EkVDRhlDovcYUfjNe4eKGoLDqYDXS/CiIoh+WB/ozq gZbQK6WKtfA3939C/kxCwlx9I3a6DUvdxrsP X-Received: by 2002:a9d:7687:0:b0:66c:2bb3:f2ab with SMTP id j7-20020a9d7687000000b0066c2bb3f2abmr3622441otl.354.1668777656688; Fri, 18 Nov 2022 05:20:56 -0800 (PST) Received: from smtpclient.apple ([205.169.26.81]) by smtp.gmail.com with ESMTPSA id i11-20020a9d53cb000000b00667ff6b7e9esm1550378oth.40.2022.11.18.05.20.55 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 18 Nov 2022 05:20:56 -0800 (PST) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable From: Andreas Dilger Mime-Version: 1.0 (1.0) Subject: Re: [RFCv1 01/72] e2fsck: Fix unbalanced mutex unlock for BOUNCE_MTX Date: Fri, 18 Nov 2022 07:20:55 -0600 Message-Id: <1BEDD834-2D4A-4E8E-936C-90DB5E322F9C@dilger.ca> References: <20221118113711.qby7gtky5k36f7vd@riteshh-domain> Cc: Theodore Ts'o , linux-ext4@vger.kernel.org, Harshad Shirwadkar , Wang Shilong , Andreas Dilger , Li Xi In-Reply-To: <20221118113711.qby7gtky5k36f7vd@riteshh-domain> To: "Ritesh Harjani (IBM)" X-Mailer: iPhone Mail (19H12) X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS 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-ext4@vger.kernel.org On Nov 18, 2022, at 05:37, Ritesh Harjani (IBM) wrot= e: >=20 > =EF=BB=BFOn 22/11/18 04:34AM, Andreas Dilger wrote: >>> On Nov 7, 2022, at 06:22, Ritesh Harjani (IBM) w= rote: >>>=20 >>> f_crashdisk test failed with UNIX_IO_FORCE_BOUNCE=3Dyes due to unbalance= d >>> mutex unlock in below path. >>>=20 >>> This patch fixes it. >>>=20 >>> Signed-off-by: Ritesh Harjani (IBM) >>> --- >>> lib/ext2fs/unix_io.c | 1 - >>> 1 file changed, 1 deletion(-) >>>=20 >>> diff --git a/lib/ext2fs/unix_io.c b/lib/ext2fs/unix_io.c >>> index e53db333..5b894826 100644 >>> --- a/lib/ext2fs/unix_io.c >>> +++ b/lib/ext2fs/unix_io.c >>> @@ -305,7 +305,6 @@ bounce_read: >>> while (size > 0) { >>> actual =3D read(data->dev, data->bounce, align_size); >>> if (actual !=3D align_size) { >>> - mutex_unlock(data, BOUNCE_MTX); >>=20 >> This patch doesn't show enough context, but AFAIK this is jumping before m= utex_down() >> is called, so this *should* be correct as is? >=20 > Thanks for the review, Andreas. >=20 > Yeah, the patch diff above is not sufficient since it doesn't share enuf > context. > But essentially when "actual" is not equal to "align_size", then in this i= f > condition it goes to label "short_read:", which always goto error_unlock, > where we anyways call mutex_unlock() >=20 > Looking at a lot of labels in this function, this definitely looks like=20= > something which can be cleaned up ("raw_read_blk()").=20 > I will add that to my list of todos.=20 You are correct, and it means this code is just not very clear to the reader= . I think it would make more sense to move the "short_read:" label to the end of the code= : actual =3D read(...); if (actual !=3D size) goto error_short_read; goto success_unlock; : actual =3D read(...); if (actual !=3D align_size) { actual =3D really_read; buf -=3D really_read; size +=3D really_read; goto error_short_read; } : success_unlock: mutex_unlock(...); return 0; error_short_read: if (actual < 0) { retval =3D errno; actual =3D 0; } else { retval =3D EXT2_ET_SHORT_READ; } error_unlock: mutex_unlock(...); That way the code follows the normal error handling convention and is less l= ikely to be surprising to the reader.=20 Cheers, Andreas=