Received: by 2002:ab2:7855:0:b0:1f9:5764:f03e with SMTP id m21csp1050146lqp; Thu, 23 May 2024 07:42:02 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUSuTRg7ruC/8GN8zVvJ76eFRTvsfXUaU9m++YAqW2NtRCbf93Es+uhzgKVEGcQLSdIV1WjW6/oIIVo4GKKrEI4WKot1IEDUdAxeDZgvQ== X-Google-Smtp-Source: AGHT+IGhP8dYCIfwqMu+XUNfXf1+HnuD83bKXnw6G8X128qYaTbjNJe1XTJKuUAdcRNq07RbvGac X-Received: by 2002:a54:408d:0:b0:3c9:6510:5908 with SMTP id 5614622812f47-3cdb44251c3mr5074600b6e.28.1716475321759; Thu, 23 May 2024 07:42:01 -0700 (PDT) Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id af79cd13be357-792bf277333si309541885a.23.2024.05.23.07.42.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 May 2024 07:42:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-187660-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=fail (signature failed); spf=pass (google.com: domain of linux-kernel+bounces-187660-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-187660-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 56BFB1C215B0 for ; Thu, 23 May 2024 14:42:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DB4F5149E1E; Thu, 23 May 2024 14:41:51 +0000 (UTC) Received: from NAM04-DM6-obe.outbound.protection.outlook.com (mail-dm6nam04on2127.outbound.protection.outlook.com [40.107.102.127]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4C0BC13E032; Thu, 23 May 2024 14:41:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.102.127 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716475311; cv=fail; b=PQQKvhjZZwie1jZb9gfe+RAYXyPDG7st4vTNT5D04yxSc/fDwr26DNMGsyArIfZ9+YthVD8XRWpno5aaSOJaPZN03/eGyRjSXxzvzvOijHcfSKZn8M6p/dAFcKGsWYuW34Tiy9UkJkbPuUA+DN4GdkIbBw23dIAAyUKgoMpykEc= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716475311; c=relaxed/simple; bh=Oj7kN41vjPfc4JdsoH/ALbY0yL58cpk8841ZQzZqKY0=; h=Message-ID:Date:Subject:To:Cc:References:From:In-Reply-To: Content-Type:MIME-Version; b=sOmSaLwRzKjfAGXtFut949XAtMhlmVfVtbU/2OT2ir8fVKTrkdSIIcVytHmn86x3titSkgWNFrO2wK5E2dHy+HAQPg0waryTZtbuo4LyjzTjKRg1V6oWn66zWnClpnsKiU/NVs/cngWT7lK7oR/qp38Y/I01rYyXWZ+nFg6r2FY= ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=talpey.com; spf=pass smtp.mailfrom=talpey.com; arc=fail smtp.client-ip=40.107.102.127 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=talpey.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=talpey.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dRfkDPhl9zoYz1YahOoJ7x0GkiFx+rLIuAGdiwanGHVtkRzXakYQrBVonYo2xaY37ZRgsnRSzVTY+xhI+Rwn+pnjR4fIBSQ845WtNKfPud5/+U7PxSCnoyo5TFsXTTgIGh4UFvZZf/vJR3RoZJ/N/ugQWej43Ar6VmuKK4Vwe1Q0nYDc6u0zwPqxT1rqm+7Spg2tn8dVOy4AzWnAufiTFFHAgXGNRuL9UL+y5MCcx0itqNkWDdOtpql0dG5m4QiH1+q/pXLuJQ9+hl78EJkLEaADf8nXO0wk5FZs/Aqc61oih3WP0qmWfMNJ7TMxCihu99kghRYKwaVE3vjGpPagLw== 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=jfRBmtNwix1Hpx40bKuOsdHs8UfMJjXzZxejIhQ4Di0=; b=S5bO6UV8IHFSXHbpIWbQP/HXhsTG6QHDo61a00fEDsFoexDfnaEGrZCf7qZd9UfNXPb3e1oX/oKF33LqS0eubATbYZJbq1UYEOZArvE87xrsrFxdx/0yGX+748qF1JKUupc8k5XBQifnZCOCYbtQ24ukQZGa1NSy0YfEJ367kQmiUtrANEj3TQIQKf0NgViFnJLuF/ZgyUvW6X5GszcOHHV8IGQ/KEEoWeh6gg678sSe44G4RV6fk+v40PCg3CHYK3/vT5KcD2dqvMJnwhPQRY/8ewvyUvx+8kavcV5FQyV0j0RXdKMdcjYS4h8FuzixgvPSnNoAxmWLHE6glHstmw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=talpey.com; dmarc=pass action=none header.from=talpey.com; dkim=pass header.d=talpey.com; arc=none Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=talpey.com; Received: from CH0PR01MB7170.prod.exchangelabs.com (2603:10b6:610:f8::12) by PH7PR01MB8514.prod.exchangelabs.com (2603:10b6:510:2e6::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7611.22; Thu, 23 May 2024 14:41:45 +0000 Received: from CH0PR01MB7170.prod.exchangelabs.com ([fe80::97c:561d:465f:8511]) by CH0PR01MB7170.prod.exchangelabs.com ([fe80::97c:561d:465f:8511%4]) with mapi id 15.20.7611.016; Thu, 23 May 2024 14:41:45 +0000 Message-ID: <536b0f03-db96-49a3-93de-d9ea835e8785@talpey.com> Date: Thu, 23 May 2024 10:41:42 -0400 User-Agent: Mozilla Thunderbird Subject: Re: [RFC PATCH] cifs: Fix credit handling in cifs_io_subrequest cleanup To: David Howells , Steve French , Paulo Alcantara Cc: Shyam Prasad N , Rohith Surabattula , Jeff Layton , linux-cifs@vger.kernel.org, netfs@lists.linux.dev, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org References: <469451.1716418742@warthog.procyon.org.uk> Content-Language: en-US From: Tom Talpey In-Reply-To: <469451.1716418742@warthog.procyon.org.uk> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-ClientProxiedBy: BL1PR13CA0128.namprd13.prod.outlook.com (2603:10b6:208:2bb::13) To CH0PR01MB7170.prod.exchangelabs.com (2603:10b6:610:f8::12) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH0PR01MB7170:EE_|PH7PR01MB8514:EE_ X-MS-Office365-Filtering-Correlation-Id: f4373abb-58c0-42bd-45ea-08dc7b3677d1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|376005|7416005|1800799015|366007; X-Microsoft-Antispam-Message-Info: =?utf-8?B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I;SFV:NSPM;H:CH0PR01MB7170.prod.exchangelabs.com;PTR:;CAT:NONE;SFS:(13230031)(376005)(7416005)(1800799015)(366007);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?WmZlSVh2aTJWNCsybzVhb1BVY0kwYllqWDZZV2lHblNKN0ZzUCsrZVdvZ2NT?= =?utf-8?B?RzlQS0YxQlFoVUhaZndDWUJGQzNsZlFtYTkvSENtbjl4WE93OHkzT2FJSDMy?= =?utf-8?B?cGdkR25GV2crWi9uUlNpNkhlRk9kdHZDejVvTFVEUGx4cUI1Yno2N1FwS0lV?= =?utf-8?B?MkgraDNJS2tRQmljWCtXZFYzU0xZM3BkSjVTc3gvaG94VzVjVjFUWFdidEtv?= =?utf-8?B?K25UWXBuVEJhOTFxMjRPajVJdHhWWFEwV0pGV1R5Y0k3cS9paTl1cUxINXox?= =?utf-8?B?WlZCSkRTSzA1VHMwbTlHZ2h1NWg1UkdCTGdnNjZHN3hwK0dET1RPL0xzeTAv?= =?utf-8?B?RURRSEUybWNDZVlEVHh0MThRNjhEZmgvRmxpaXpVdXZXdUo1NlB6Rlp0ZmI5?= =?utf-8?B?dnZWWGd1SlVISlBTMklhQ2hYWnlDVm9DVWtWOXVDcFZyQ3FyUVhGTU1BdHk5?= =?utf-8?B?aTJHWXBNRWxpRW1vZTR1U09BSXZLY3FZNFFHM3ZwVWtINjROWGZ1TEk5NHFZ?= =?utf-8?B?S0ZPREx2UzNrblFjVVVVRGI1SHNldG5qd0lIcHIxYU5jamRaR2NCZUVQeWJx?= =?utf-8?B?b245Qnlpc1pUVHYzWSsweHFlbzMyeVltaSszZTVCYjd3ZFlxNGdCdmNoTU5P?= =?utf-8?B?djM5SWNLV3dEYk1Jejd2SktxVThXZ2xyMktkK01WQktkeU82bDh3MkhXRVNh?= =?utf-8?B?cFBycVJhVExDbnZtME1PQTFjT1d3QmZRRjJ0R2ZuYWJC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ZUY3pEbGc5aXc3UlFVWnFqOFlIOWtF?= =?utf-8?B?bHJ1Q1B6SklmR1dGQ3RMZkxqWnJ4NlFnR1hNdXlpRUZCV205SmFZSDl2cCto?= =?utf-8?B?U1QxZ0FmdzBlVklGWStvM1pWMkp6UXBJUTlITGVicHp3ZFdCRWM5ckN2RGty?= =?utf-8?B?cmkwNWJlREJCelllODJHQ00xa0VuMzlsOWV3L09aWjdFazVMS3pzVS95cEwz?= =?utf-8?B?dStXbnQydWxnN3JqL04zOUc1cmR2M3NDMkl4YzloUFM3WEoxcURJN1BCeVQw?= =?utf-8?B?bzRpQlEzQzdVZUl0ak11Sytsa3JJZGxvM3ZQVlFmdGNheDlTNUQ4U3NFWnFx?= =?utf-8?B?SVczL3lIdzRBZ1lqcjRweTZFMTZuOVoxbzBUK0dHdHF6eXdIaVRONjB1Y2Q1?= =?utf-8?B?Y2xhMnR2QkFGY2JaL0t3VTlNMXVCWlY0V0wyQ2xlTkZTUHpZRThEQ2x1MUlR?= =?utf-8?Q?tUVusMPLUwDG0x2MeJYU3iXeQ?= X-OriginatorOrg: talpey.com X-MS-Exchange-CrossTenant-Network-Message-Id: f4373abb-58c0-42bd-45ea-08dc7b3677d1 X-MS-Exchange-CrossTenant-AuthSource: CH0PR01MB7170.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 May 2024 14:41:44.9479 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 2b2dcae7-2555-4add-bc80-48756da031d5 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: xSh0BfbURbR4YfN8Uu0AqWYv2tJeWWmI0Off2LbhceLgXi1X21F7H6AYvgfHchKs X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR01MB8514 On 5/22/2024 6:59 PM, David Howells wrote: > > When a cifs_io_subrequest (wrapping a netfs_io_subrequest) is cleaned up in > cifs_free_subrequest(), it releases any credits that are left in > rdata->credits. However, this is a problem because smb2_writev_callback() > calls add_credits() to add the new credits from the response header > CreditRequest to the available pool. > > This can cause a warning to be emitted in smb2_add_credits() as > server->in_flight gets doubly decremented and a later operation sees it > having prematurely reached 0. > > Fix this by clearing the credit count after actually issuing the request on > the assumption that we've given the credits back to the server (it will > give us new credits in the reply). From a protocol standpoint it's correct to reserve the credits while the operation is in flight. But from a code standpoint it seems risky to stop accounting for them. What if the operation is canceled, or times out? I'd quibble with the assertion that the server will "give us new credits in the response". The number of granted credits is always the server's decision, not guaranteed by the protocol (except for certain edge conditions). I guess I'd suggest a deeper review by someone familiar with the mechanics of fs/smb/client credit accounting. It might be ok! Tom. > Signed-off-by: David Howells > cc: Steve French > cc: Paulo Alcantara > cc: Shyam Prasad N > cc: Rohith Surabattula > cc: Jeff Layton > cc: linux-cifs@vger.kernel.org > cc: netfs@lists.linux.dev > cc: linux-fsdevel@vger.kernel.org > --- > fs/smb/client/file.c | 7 +++++-- > 1 file changed, 5 insertions(+), 2 deletions(-) > > diff --git a/fs/smb/client/file.c b/fs/smb/client/file.c > index 9d5c2440abfc..73e2765c4d2f 100644 > --- a/fs/smb/client/file.c > +++ b/fs/smb/client/file.c > @@ -110,6 +110,7 @@ static void cifs_issue_write(struct netfs_io_subrequest *subreq) > goto fail; > > wdata->server->ops->async_writev(wdata); > + wdata->credits.value = 0; > out: > return; > > @@ -205,10 +206,12 @@ static void cifs_req_issue_read(struct netfs_io_subrequest *subreq) > > rc = adjust_credits(rdata->server, &rdata->credits, rdata->subreq.len); > if (!rc) { > - if (rdata->req->cfile->invalidHandle) > + if (rdata->req->cfile->invalidHandle) { > rc = -EAGAIN; > - else > + } else { > rc = rdata->server->ops->async_readv(rdata); > + rdata->credits.value = 0; > + } > } > > out: > > >