From nobody Wed Oct 8 07:40:24 2025 Received: from mail-lf1-f41.google.com (mail-lf1-f41.google.com [209.85.167.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 986022E54D2; Mon, 30 Jun 2025 18:36:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751308566; cv=none; b=fI7SIjdP3KNbvttcKWy60CBH7WkA67+B+CnUbFLIeVQpWRGSvEEQp6+ayNi2jua9rmsWaGa73B5ZrRyoVKrBfIB8XRZX+MiV2bs7iDraVegwHhkRvgVEfhzNnEA37MSwQejVtU1l15zg9EFPWi/uv6GfXKIGkoEw1vcVMfkq+do= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751308566; c=relaxed/simple; bh=CJDIdZiGcnrzwH4FjTCpmNqcK+ouJMAgoNX3eCN5Yg0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=vBIDJDvjODhaseQcsz9Y99tWWRiF+EkziCUt/K4JB+iW9lrjKx0TNp2Yq7kbSlVmn2ReuHSEmbw/eVM0+GGIFrD9QewTywY+0R0Dmrb8zEVHRrsjabGUqzKOucVWNYNBcAJH8BMLuJaOSzsfFLqhB0jQaX5c3/r+x7LJgmUDchg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=eFwm5yod; arc=none smtp.client-ip=209.85.167.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="eFwm5yod" Received: by mail-lf1-f41.google.com with SMTP id 2adb3069b0e04-553c31542b1so2844420e87.2; Mon, 30 Jun 2025 11:36:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1751308563; x=1751913363; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=vloA9hnEfaZRfFrBFN7HQOldZIvROZ2AysUaNQzK8FE=; b=eFwm5yodsiUN0lFiqJxuL7x4axmCWgk4+VxmxDSSihT4aLh9wPDZAVd38Z5UxRhIey rYfkF3D3Zt+A+q00xlP0qJO48i94sFf5Ex528PExdomSNk7DQie/T5Dhm8E1+7mBlC9B N8XmAVNh4MCyhNZKgnmnxDmKOYtbBKgcITDqjLCYegTnQCjFY03G3kHUmT1GNuYSZygh huVSxxFn56tJo1KeWJ3pgCS8NBCuiw7nAlNJoQAC012UPHnhzMcPbZpLtETF4fhlWYPG 0TIf0nk9OeVDHL8RuxxP5Pn9OK/wcFEDLToOVouirreoXHQJ6LV+FOO/8d3KmFvNvE3u NWrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751308563; x=1751913363; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vloA9hnEfaZRfFrBFN7HQOldZIvROZ2AysUaNQzK8FE=; b=afSuhIr7lWdtRwmPB1Z9Sbq8DdHUPMcnPSYfaW4g3sqSRnyCgD2B6/lNNYC4OBwZCN mJmo3eY7b8NZbsMChweAoef7R89tyLpF2OEY7qwiFIwe8fSIZSYhk1sQ3mCEmQYChqQM 8fLlziCZ0N6CPmodnSXq8FqNh+yHmSyeHrvjoPlo8Uf6/Budrmmg57wLdCtoun72L7Ms k9DmpjUtR0NzWZgB4/6fzetULDIJRWalSpCU8YXj7McANZp6ZiR70Sd6z+lRhPkTpRqH WNdlpdK3/0Gv+6U8rXZ5wm8IpQEe2jqd504JPVjAVOFtJLaA6iCem9M2vr/6JHS0MWZ5 Qf5w== X-Forwarded-Encrypted: i=1; AJvYcCWsT2A5IpjEsSX/XIAaCunip4UGEPQ999OVN77/GKg1/P0uSyPtceuZeJaM7xPM1U24sspi7N1WtsSC0t4=@vger.kernel.org X-Gm-Message-State: AOJu0YyhWsRRoZpqeytVlexHpGlxqMiTI5QaYwUUGUiAc39LHthEBP51 di//F+XIrRq4+cij4Cq7OA88c1eDEhXHCtSNDN9zm6Mqme7PqsKSyxHHTHaos/03 X-Gm-Gg: ASbGnctWmeOBy+U5mpHyidHy3x1o/crbu+7UUKYbuarRLDdUOS+sqslimtfZlzONbIP WT/URtE2hqKfWhQ1uJ6jh2nZiz7A5N77wFhuM50QiyF3ewZjsHAmZn+wNo1/CgZneaPqk/yQTYb Yz0QZKFJkLYjn9joZOwluXPiiThkx8aeQ/V+KZr3KXqQob18uQCud2rrbaMLy+XjcnaHTnF3Pf0 aXW0NvvOoOWdzy3l8bvbaiijT6OfhpEsWZRi21EXszHAfTp1ur0qH3P1qdh0SxL/qWSrLelDH7q SNhfNxo6MYtvuBOa7HjI8ODNl8eUkSVaOWHlsA7VdXl12JLtO3HWY6cqdmY2+dkNalYdLqgMQGO MojwO2/rY6IiYLw== X-Google-Smtp-Source: AGHT+IEtt/pIK1WIPwVGQ9SXq1VbD9Q8gG6yoTAhFI10CqjXq6u18HuGGeUSFm269n/4g6ehQz9EQQ== X-Received: by 2002:a05:6512:3c87:b0:553:2927:985f with SMTP id 2adb3069b0e04-5550b860bafmr4259106e87.5.1751308562315; Mon, 30 Jun 2025 11:36:02 -0700 (PDT) Received: from SC-WS-02452.corp.sbercloud.ru ([37.78.230.218]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5550b255a51sm1530793e87.88.2025.06.30.11.36.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Jun 2025 11:36:02 -0700 (PDT) From: Sergey Bashirov To: Christoph Hellwig , Trond Myklebust , Anna Schumaker Cc: linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org, Konstantin Evtushenko , Sergey Bashirov Subject: [PATCH 1/4] pNFS: Fix uninited ptr deref in block/scsi layout Date: Mon, 30 Jun 2025 21:35:26 +0300 Message-ID: <20250630183537.196479-2-sergeybashirov@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250630183537.196479-1-sergeybashirov@gmail.com> References: <20250630183537.196479-1-sergeybashirov@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The error occurs on the third attempt to encode extents. When function ext_tree_prepare_commit() reallocates a larger buffer to retry encoding extents, the "layoutupdate_pages" page array is initialized only after the retry loop. But ext_tree_free_commitdata() is called on every iteration and tries to put pages in the array, thus dereferencing uninitialized pointers. An additional problem is that there is no limit on the maximum possible buffer_size. When there are too many extents, the client may create a layoutcommit that is larger than the maximum possible RPC size accepted by the server. During testing, we observed two typical scenarios. First, one memory page for extents is enough when we work with small files, append data to the end of the file, or preallocate extents before writing. But when we fill a new large file without preallocating, the number of extents can be huge, and counting the number of written extents in ext_tree_encode_commit() does not help much. Since this number increases even more between unlocking and locking of ext_tree, the reallocated buffer may not be large enough again and again. Co-developed-by: Konstantin Evtushenko Signed-off-by: Konstantin Evtushenko Signed-off-by: Sergey Bashirov Reviewed-by: Christoph Hellwig --- fs/nfs/blocklayout/extent_tree.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/fs/nfs/blocklayout/extent_tree.c b/fs/nfs/blocklayout/extent_t= ree.c index 8f7cff7a4293..0add0f329816 100644 --- a/fs/nfs/blocklayout/extent_tree.c +++ b/fs/nfs/blocklayout/extent_tree.c @@ -552,6 +552,15 @@ static int ext_tree_encode_commit(struct pnfs_block_la= yout *bl, __be32 *p, return ret; } =20 +/** + * ext_tree_prepare_commit - encode extents that need to be committed + * @arg: layout commit data + * + * Return values: + * %0: Success, all required extents are encoded + * %-ENOSPC: Some extents are encoded, but not all, due to RPC size limit + * %-ENOMEM: Out of memory, extents not encoded + */ int ext_tree_prepare_commit(struct nfs4_layoutcommit_args *arg) { @@ -568,12 +577,12 @@ ext_tree_prepare_commit(struct nfs4_layoutcommit_args= *arg) start_p =3D page_address(arg->layoutupdate_page); arg->layoutupdate_pages =3D &arg->layoutupdate_page; =20 -retry: - ret =3D ext_tree_encode_commit(bl, start_p + 1, buffer_size, &count, &arg= ->lastbytewritten); + ret =3D ext_tree_encode_commit(bl, start_p + 1, buffer_size, + &count, &arg->lastbytewritten); if (unlikely(ret)) { ext_tree_free_commitdata(arg, buffer_size); =20 - buffer_size =3D ext_tree_layoutupdate_size(bl, count); + buffer_size =3D NFS_SERVER(arg->inode)->wsize; count =3D 0; =20 arg->layoutupdate_pages =3D @@ -588,7 +597,8 @@ ext_tree_prepare_commit(struct nfs4_layoutcommit_args *= arg) return -ENOMEM; } =20 - goto retry; + ret =3D ext_tree_encode_commit(bl, start_p + 1, buffer_size, + &count, &arg->lastbytewritten); } =20 *start_p =3D cpu_to_be32(count); @@ -608,7 +618,7 @@ ext_tree_prepare_commit(struct nfs4_layoutcommit_args *= arg) } =20 dprintk("%s found %zu ranges\n", __func__, count); - return 0; + return ret; } =20 void --=20 2.43.0 From nobody Wed Oct 8 07:40:24 2025 Received: from mail-lf1-f51.google.com (mail-lf1-f51.google.com [209.85.167.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C784F28C2C7; Mon, 30 Jun 2025 18:36:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751308573; cv=none; b=lh8wxtM1Xo2/6nYwygkHM8Z9E6CKNhs87nFB2k8kOV1/BM6Z/fX2v4pxCz9J7GiZlyVgD+DiZI42m8JFdbyNQ6E4h5wP3Zo3YViFHxKVsi5M0l0Xa31yVgMaxtWtBPOZPq11ZjTUP5Agy6nW0SyxOU49orjSL7G4SaLI65oN1AE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751308573; c=relaxed/simple; bh=ZxZLnWtmmUilKIymsjRaHEtJE+C4+MCqJFqKLECf+So=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RuqhGSnQhsqVzngT5CnzJZzSXgG3c0GGq7t8F+VrXMkoqkJKmZYOjGJDKba3V/stV5LEwgjTTcpzc/LlQJdLqwk0uDRGxBE0SY/FOOIqQbdW2k1wmxC/Eyjpa+xRhKOCkZgecrMEkGm7fJs+znoFU36O1txZ48zm6icX1gafbnU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=nio9rovU; arc=none smtp.client-ip=209.85.167.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="nio9rovU" Received: by mail-lf1-f51.google.com with SMTP id 2adb3069b0e04-553b82f3767so2732788e87.3; Mon, 30 Jun 2025 11:36:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1751308570; x=1751913370; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=BnL+VKcG6vtnAyOcHVA/msL4mcR1nmGy9AOG7qAyXtg=; b=nio9rovU5ofSrh5eIU3SnFUC/3r2nIbh1lF0lCvnbLkIHAPG0hQqq1akVGNhwkerAt mCwAbzucvmlfWtJWJAPxzZ7TLxFPvWzimzAjqFYU20sNXWft0Egonuq/jsT1+yXCHOhf wlwkl2mmDcsbS1+hD1sGugY5z9NO3IjhGGohdC6cLAnWNL95IzyfNyQVajq1+SBeGFsf JuugBQmmClo7NMdsxj5ruEpAVs1K/QMALCaOHxKZnIP892Rq8GqDpzAN2tdb72eGHJqT bG0Uhv+8XejG9Eqo1aeqDHE3UQDUJ8YdCtJaI39KVA75HWJBCj6QEc6pjSp70gl51aGS xarw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751308570; x=1751913370; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BnL+VKcG6vtnAyOcHVA/msL4mcR1nmGy9AOG7qAyXtg=; b=SxurVFLpeAKUQtUERiQ6uZWomKAOtOA6dHkrbcwQ7W/pVJK0VcshSc/URfGBzSjZHB fmX6q7G80AWXJUe5RhNhep9ztV5UESL6zsHrRFgoUnD2eKl16F55e3UBDkAvi+j1hrJa XY3R4sLVHlYy62n8RZVWBZ8eEy/bWhC3Ck2GN+wXRU8H9GHh3Q7lHjfNX38kq/VUd/Jm kfGzpGH031dn5eWhKeSHUIq3t21vDzAL1lQnLy2201PRCQUEv4+LuYFrfBXcF4AhiArM xEbD2zbT9PhVJYRBJ89fjzyk6T2VIT44V5HuQUIw0eUyou4pYdz5tGcOSZJuBpLEUEeq qe6w== X-Forwarded-Encrypted: i=1; AJvYcCW6ywlBCaN9dmaAPVinmYphXpxvcy+npNCHVjis7D54BmPhNJMbRkB6RkY0F7SOSVzGQvFeyUdtEZYTcM4=@vger.kernel.org X-Gm-Message-State: AOJu0YzxrZBvcrqgrASAFdkiSdOxUsyJ/sZmi2Xp/PWYYqT3AXjJFj6B UD+pZ7t49Umo3LG2amHkXUUPJ3rnYGH01UMrJfjfZarFuwva3KLPp05a X-Gm-Gg: ASbGncvr88icvfRmNGsUyymmJf2Y8ENNWoZ0y4XmwtMtJqGDp8Q9dFJ8Mg3hBG2B423 YS79RtJB3Qs5TOyzxrXhsFGgGw5Mvcc5gPgDe50Ed3SzQ+53/FlznUKBiQhg4vVQXGmxkf1ohHi S1vK1fJTrJ/dmjmRRPafO4Mw1AJ2ya2wsZzzpB8Q3FdI0jEs+W+Ji3pE9s1hw7+UCIYz4IBSkY+ vzI6J1gLGVoB78kLojh4d4vdMwOzQ+KIplHCYfEJl3dxRM0DHDva+J3pLSkfVAQIwdNwCPK4+yg 54ql7TlfjRToWuhN2XmvKz6jF6H/RfpzZ6xbM/o1cZWvRvug30iJTJxhk5atRBBRrJkp64QLLtZ U8BZr49xo4cX91g== X-Google-Smtp-Source: AGHT+IFiEi1lzg3OKTfZ7KElVz9E/tSmTqGl9ImbBdSyLZcLeyCqOQm4aFQ6bSDiNTvBlrTSY41q6g== X-Received: by 2002:a05:6512:3ba6:b0:553:d910:933d with SMTP id 2adb3069b0e04-5550ba23b5fmr3911409e87.48.1751308569578; Mon, 30 Jun 2025 11:36:09 -0700 (PDT) Received: from SC-WS-02452.corp.sbercloud.ru ([37.78.230.218]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5550b255a51sm1530793e87.88.2025.06.30.11.36.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Jun 2025 11:36:09 -0700 (PDT) From: Sergey Bashirov To: Christoph Hellwig , Trond Myklebust , Anna Schumaker Cc: linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org, Konstantin Evtushenko , Sergey Bashirov Subject: [PATCH 2/4] pNFS: Fix extent encoding in block/scsi layout Date: Mon, 30 Jun 2025 21:35:27 +0300 Message-ID: <20250630183537.196479-3-sergeybashirov@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250630183537.196479-1-sergeybashirov@gmail.com> References: <20250630183537.196479-1-sergeybashirov@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The ext_tree_encode_commit() function may be called multiple times for the same file, layout, and last written byte if the provided buffer is not large enough to encode all extents in it. The first problem is that the last written byte field must be zeroed only on a successful call, otherwise we will lose its actual value and get an integer overflow on the next encoding attempt. The second problem is that we can't count and encode in one pass. The extent state changes during encoding, so if we return -ENOSPC but have already encoded some extents into a small buffer, they will not be re-encoded into a new larger buffer on the next try. As a result, the client never commits these extents to the server. Co-developed-by: Konstantin Evtushenko Signed-off-by: Konstantin Evtushenko Signed-off-by: Sergey Bashirov Reviewed-by: Christoph Hellwig --- fs/nfs/blocklayout/extent_tree.c | 80 +++++++++++++++++++++++++++++--- 1 file changed, 74 insertions(+), 6 deletions(-) diff --git a/fs/nfs/blocklayout/extent_tree.c b/fs/nfs/blocklayout/extent_t= ree.c index 0add0f329816..faccd5caa149 100644 --- a/fs/nfs/blocklayout/extent_tree.c +++ b/fs/nfs/blocklayout/extent_tree.c @@ -520,10 +520,71 @@ static __be32 *encode_scsi_range(struct pnfs_block_ex= tent *be, __be32 *p) return xdr_encode_hyper(p, be->be_length << SECTOR_SHIFT); } =20 -static int ext_tree_encode_commit(struct pnfs_block_layout *bl, __be32 *p, +/** + * ext_tree_try_encode_commit - try to encode all extents into the buffer + * @bl: pointer to the layout + * @p: pointer to the output buffer + * @buffer_size: size of the output buffer + * @count: output pointer to the number of encoded extents + * @lastbyte: output pointer to the last written byte + * + * Return values: + * %0: Success, all required extents encoded, outputs are valid + * %-ENOSPC: Buffer too small, nothing encoded, outputs are invalid + */ +static int +ext_tree_try_encode_commit(struct pnfs_block_layout *bl, __be32 *p, size_t buffer_size, size_t *count, __u64 *lastbyte) { struct pnfs_block_extent *be; + + spin_lock(&bl->bl_ext_lock); + for (be =3D ext_tree_first(&bl->bl_ext_rw); be; be =3D ext_tree_next(be))= { + if (be->be_state !=3D PNFS_BLOCK_INVALID_DATA || + be->be_tag !=3D EXTENT_WRITTEN) + continue; + + (*count)++; + if (ext_tree_layoutupdate_size(bl, *count) > buffer_size) { + spin_unlock(&bl->bl_ext_lock); + return -ENOSPC; + } + } + for (be =3D ext_tree_first(&bl->bl_ext_rw); be; be =3D ext_tree_next(be))= { + if (be->be_state !=3D PNFS_BLOCK_INVALID_DATA || + be->be_tag !=3D EXTENT_WRITTEN) + continue; + + if (bl->bl_scsi_layout) + p =3D encode_scsi_range(be, p); + else + p =3D encode_block_extent(be, p); + be->be_tag =3D EXTENT_COMMITTING; + } + *lastbyte =3D (bl->bl_lwb !=3D 0) ? bl->bl_lwb - 1 : U64_MAX; + bl->bl_lwb =3D 0; + spin_unlock(&bl->bl_ext_lock); + + return 0; +} + +/** + * ext_tree_encode_commit - encode as much as possible extents into the bu= ffer + * @bl: pointer to the layout + * @p: pointer to the output buffer + * @buffer_size: size of the output buffer + * @count: output pointer to the number of encoded extents + * @lastbyte: output pointer to the last written byte + * + * Return values: + * %0: Success, all required extents encoded, outputs are valid + * %-ENOSPC: Buffer too small, some extents are encoded, outputs are val= id + */ +static int +ext_tree_encode_commit(struct pnfs_block_layout *bl, __be32 *p, + size_t buffer_size, size_t *count, __u64 *lastbyte) +{ + struct pnfs_block_extent *be, *be_prev; int ret =3D 0; =20 spin_lock(&bl->bl_ext_lock); @@ -534,9 +595,9 @@ static int ext_tree_encode_commit(struct pnfs_block_lay= out *bl, __be32 *p, =20 (*count)++; if (ext_tree_layoutupdate_size(bl, *count) > buffer_size) { - /* keep counting.. */ + (*count)--; ret =3D -ENOSPC; - continue; + break; } =20 if (bl->bl_scsi_layout) @@ -544,9 +605,16 @@ static int ext_tree_encode_commit(struct pnfs_block_la= yout *bl, __be32 *p, else p =3D encode_block_extent(be, p); be->be_tag =3D EXTENT_COMMITTING; + be_prev =3D be; + } + if (!ret) { + *lastbyte =3D (bl->bl_lwb !=3D 0) ? bl->bl_lwb - 1 : U64_MAX; + bl->bl_lwb =3D 0; + } else { + *lastbyte =3D be_prev->be_f_offset + be_prev->be_length; + *lastbyte <<=3D SECTOR_SHIFT; + *lastbyte -=3D 1; } - *lastbyte =3D bl->bl_lwb - 1; - bl->bl_lwb =3D 0; spin_unlock(&bl->bl_ext_lock); =20 return ret; @@ -577,7 +645,7 @@ ext_tree_prepare_commit(struct nfs4_layoutcommit_args *= arg) start_p =3D page_address(arg->layoutupdate_page); arg->layoutupdate_pages =3D &arg->layoutupdate_page; =20 - ret =3D ext_tree_encode_commit(bl, start_p + 1, buffer_size, + ret =3D ext_tree_try_encode_commit(bl, start_p + 1, buffer_size, &count, &arg->lastbytewritten); if (unlikely(ret)) { ext_tree_free_commitdata(arg, buffer_size); --=20 2.43.0 From nobody Wed Oct 8 07:40:24 2025 Received: from mail-lf1-f45.google.com (mail-lf1-f45.google.com [209.85.167.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6B63C2E718B; Mon, 30 Jun 2025 18:36:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751308576; cv=none; b=mYzofunr0nT6obz8T7bhZlnuCSCDFHqP3Ki13VLCaOW2xk44voVJz4gG6p+INMGdlgrUna9sESoofhK/4T0xBVtzRp3lzxoMuJJYUmPH9DTo8twVAya+HGpJd7AkJy8krq/tAVpv9FvuNycTjESvQ6y3f5gK+1gyVYMDt8GgFmU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751308576; c=relaxed/simple; bh=dtVyVF5MNOMBsCDa1CoBOom+uvndZq8R2JSHuPZeVIE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BIyIArYMJg8fa6w+h3fVtEZDomFRCrCppqzZGTSIah2HIo3aJc8vPzmGtm1zrTvY+tsGzL03Ar+OCzdTphjYDuvqgvuNwJ/T4lDkTr1G+IwfY4tXOCbkx9MTvCHAmN3VuaZLR1Me7LMBh4y7Pn9FvwN4OOpss5JbM2CW0Yj0OMY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Gz6svb68; arc=none smtp.client-ip=209.85.167.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Gz6svb68" Received: by mail-lf1-f45.google.com with SMTP id 2adb3069b0e04-5561d41fc96so612644e87.1; Mon, 30 Jun 2025 11:36:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1751308572; x=1751913372; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=KEaFTdp9vPJydEyqwmi3nr/Hucoz77t8PqXx+J2O80U=; b=Gz6svb68q0MWpaKBDenuPhE9t5wy86SEeRt5cridRmWhL5bFypg4DwS8gBQa5EedRe KSm26dt5wbWFnYqYwxsPdY1FRsL1tcfuTOq9HsgcLrhvmDjm8lpuS6Idlj6OAR5VdKMa BAs5rFm5LP4fhd4gHZWvta+Rb8wHByI4bFs36rhQNkNvIMSap+3uOwHYWj4mx3GybGUM UaoDV97pJraJhhVvttS3KdOC/gPQ2pJHGtAl3RsPMaDRAq2JMeMrfgyUKh2WSDB4HJn6 vKMg+eVKKn2rX7dWO9vAFLyy1A+KOhywNT1VNEXDsvyYb8LXssWkei0yng9i30WjnqOG hAmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751308572; x=1751913372; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KEaFTdp9vPJydEyqwmi3nr/Hucoz77t8PqXx+J2O80U=; b=iXVskG8TMfhRETZ9FUdc9zh+XKHM1Z29e5ultuYIjJ07qD0g0fZwp9q6bnR34OQiz6 2A9/X0SYslHm98jCUSDhilEe07v/NulLfj/Z65RaDvvyhNf9UioWlHi00B+eE8u9bxH9 VdUWH1y5ibKd06H9pRY43chZ/0V0rfl+VutiZ9Ypu6Q6V8uBvb7cBv6kHYmHKjVwNDE9 AIAF693Gqp7P2cWAy0WDs9scnOmSRnUI5VeHzOxSoG6Lb/jWFwDKEOKQTYb0KHR0yxlX uaW1+9UomctE+rq1uufHicQU60OQDHfnncA/ednqOjwhbXI9GhQect9NSNUAEB1CKCRS X4JA== X-Forwarded-Encrypted: i=1; AJvYcCUh5zloDPvTR2ZofEB3HMKkOaxhhL47lx/KtW2Pwa708/KCvx8ki6QXjmsruc3qcCelxrkf3B6TKbii35s=@vger.kernel.org X-Gm-Message-State: AOJu0Yzgb8oDQXNeCoM84XKTtbyruDCyVdpGYLEadyHb+27GYXwigcSP SOIGUfhDhvVX6dJ4pUxbD/OSo6Z360TrWRe3NJtxouhaYoc49R3GTD4s X-Gm-Gg: ASbGncv1DMEt7YnY5kZcQ2URwvNNrqh1lnaGQIEcTuypZnnJzRL3aXCTk7q6wQ9+wFU CF/cdxx6JWVuetxjaHz+FUfcOtCU5qCpMQBM6udpS9WF1BUmDzeZuBPPMVKUK5EJxiMAFs3TG4s XXgyoFK8HjFpxZWG/xy1Fu4G/85ZUKt0r0Cp7eDRZ1JnZ3tIk8DkLRXA4myC1uA1xyWe7QRvgK8 nx//BVxE57tz6h30efATqr7//2XxbFEJQ7hcQKOw5cmsgMPdK3Hvtsg7/0XJnn20CGMvY0FExl3 BVR7M9YYJXfohZ/Jz2zXfDxqxrQ4lFaL9jMqqqj13rz2FKJZG0RiN1qA5nFxdUy0Q+dCKwOiVKR wnkW/D6mbxc1w3w== X-Google-Smtp-Source: AGHT+IHzuNMWICB1FM4QDZ/ppAnASXDHHwOSIgNZHwXP+gll20SBH910lX8ibFhrkIwk1DipdDkhmQ== X-Received: by 2002:a05:6512:1396:b0:553:37e7:867c with SMTP id 2adb3069b0e04-5550b8d15b8mr5022270e87.50.1751308572272; Mon, 30 Jun 2025 11:36:12 -0700 (PDT) Received: from SC-WS-02452.corp.sbercloud.ru ([37.78.230.218]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5550b255a51sm1530793e87.88.2025.06.30.11.36.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Jun 2025 11:36:12 -0700 (PDT) From: Sergey Bashirov To: Christoph Hellwig , Trond Myklebust , Anna Schumaker Cc: linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org, Konstantin Evtushenko , Sergey Bashirov Subject: [PATCH 3/4] pNFS: Add prepare commit trace to block/scsi layout Date: Mon, 30 Jun 2025 21:35:28 +0300 Message-ID: <20250630183537.196479-4-sergeybashirov@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250630183537.196479-1-sergeybashirov@gmail.com> References: <20250630183537.196479-1-sergeybashirov@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Replace dprintk with trace event in ext_tree_prepare_commit() function. Co-developed-by: Konstantin Evtushenko Signed-off-by: Konstantin Evtushenko Signed-off-by: Sergey Bashirov Reviewed-by: Christoph Hellwig --- fs/nfs/blocklayout/extent_tree.c | 6 +++--- fs/nfs/nfs4trace.c | 1 + fs/nfs/nfs4trace.h | 34 ++++++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/fs/nfs/blocklayout/extent_tree.c b/fs/nfs/blocklayout/extent_t= ree.c index faccd5caa149..315949a7e92d 100644 --- a/fs/nfs/blocklayout/extent_tree.c +++ b/fs/nfs/blocklayout/extent_tree.c @@ -6,6 +6,7 @@ #include =20 #include "blocklayout.h" +#include "../nfs4trace.h" =20 #define NFSDBG_FACILITY NFSDBG_PNFS_LD =20 @@ -637,8 +638,6 @@ ext_tree_prepare_commit(struct nfs4_layoutcommit_args *= arg) __be32 *start_p; int ret; =20 - dprintk("%s enter\n", __func__); - arg->layoutupdate_page =3D alloc_page(GFP_NOFS); if (!arg->layoutupdate_page) return -ENOMEM; @@ -685,7 +684,8 @@ ext_tree_prepare_commit(struct nfs4_layoutcommit_args *= arg) } } =20 - dprintk("%s found %zu ranges\n", __func__, count); + trace_bl_ext_tree_prepare_commit(ret, count, + arg->lastbytewritten, !!ret); return ret; } =20 diff --git a/fs/nfs/nfs4trace.c b/fs/nfs/nfs4trace.c index 389941ccc9c9..3caa0720ef68 100644 --- a/fs/nfs/nfs4trace.c +++ b/fs/nfs/nfs4trace.c @@ -31,6 +31,7 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(ff_layout_read_error); EXPORT_TRACEPOINT_SYMBOL_GPL(ff_layout_write_error); EXPORT_TRACEPOINT_SYMBOL_GPL(ff_layout_commit_error); =20 +EXPORT_TRACEPOINT_SYMBOL_GPL(bl_ext_tree_prepare_commit); EXPORT_TRACEPOINT_SYMBOL_GPL(bl_pr_key_reg); EXPORT_TRACEPOINT_SYMBOL_GPL(bl_pr_key_reg_err); EXPORT_TRACEPOINT_SYMBOL_GPL(bl_pr_key_unreg); diff --git a/fs/nfs/nfs4trace.h b/fs/nfs/nfs4trace.h index deab4c0e21a0..9b1c5e7f3e9c 100644 --- a/fs/nfs/nfs4trace.h +++ b/fs/nfs/nfs4trace.h @@ -2163,6 +2163,40 @@ TRACE_EVENT(ff_layout_commit_error, ) ); =20 +TRACE_EVENT(bl_ext_tree_prepare_commit, + TP_PROTO( + int ret, + size_t count, + u64 lwb, + bool not_all_ranges + ), + + TP_ARGS(ret, count, lwb, not_all_ranges), + + TP_STRUCT__entry( + __field(int, ret) + __field(size_t, count) + __field(u64, lwb) + __field(bool, not_all_ranges) + ), + + TP_fast_assign( + __entry->ret =3D ret; + __entry->count =3D count; + __entry->lwb =3D lwb; + __entry->not_all_ranges =3D not_all_ranges; + ), + + TP_printk( + "ret=3D%d, found %zu ranges, lwb=3D%llu%s", + __entry->ret, + __entry->count, + __entry->lwb, + __entry->not_all_ranges ? ", not all ranges encoded" : + "" + ) +); + DECLARE_EVENT_CLASS(pnfs_bl_pr_key_class, TP_PROTO( const struct block_device *bdev, --=20 2.43.0 From nobody Wed Oct 8 07:40:24 2025 Received: from mail-lj1-f174.google.com (mail-lj1-f174.google.com [209.85.208.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A084D2E8E09; Mon, 30 Jun 2025 18:36:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751308579; cv=none; b=E0imloS+qR+JbkPLSjmat/T/BjwP5Oe563g6llu5iiVHBau0InJa664yupCsiv4Bij26LlD0uXmgxVJEXTZ05UnTTFs1Thvkp0BxcLMNqPRkrI1ifYYWs0iS6mS9ZXjpU6g/WKT9NtvJ2qD8pdso1Htu24ofbS+Px54V9M/gceY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751308579; c=relaxed/simple; bh=U28c1RXkqh10GW9CK4xixFeE0J/V/nDijiPpI5MU/EU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fkm47+OKSTqhKXyalr0kj3vRV0YPnLxkZdknmoPk6Zho9sYfvHJgOVLqn4qTKIozqZbZ140AJrs62fhG3pzzV4sgm+a/NiuKC/a4USKJEjecAJ+iBKMR3a4ELfG/bf9Ublx0HnANjgCshxnH1T26lAKlklQdnR4vPdHSjnQRhyU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Fi9iqNMT; arc=none smtp.client-ip=209.85.208.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Fi9iqNMT" Received: by mail-lj1-f174.google.com with SMTP id 38308e7fff4ca-32adebb15c5so17500141fa.3; Mon, 30 Jun 2025 11:36:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1751308576; x=1751913376; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YCL9/dAc5/TdNkuoOspnQXjRpLf/CLT8PSLRWLBfWSc=; b=Fi9iqNMTNScJWBvXDwGP6jCx+2+oZKOFbhH8SWQZqO6mIfVIM+UxxGilz1gvWgeKXB AQmNL+90eTq/2w7cbPtBzdrfEwzv1oWmYwc6hD3GxuH4lgbU3rK5azo0zDN1LwAxJTkG er0XbTxyITxYvMQAH3zo5E1d60CkabzE6rONL2D9GWp+6/tZjMU9igwywkRgT35fq7K7 MyB+q73eoRXaw8v3ER/ZGuYg1SJGsoalD2ygkdgqm7qw/+bkHJKUQFBhWGxF6OobJosH 1Hk+lcONatUoDTv6/NA+h7nlsIJUr3rW7jeJ61sNTwKNBodEJFsuXkDhLVzYGemXnOIj FoAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751308576; x=1751913376; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YCL9/dAc5/TdNkuoOspnQXjRpLf/CLT8PSLRWLBfWSc=; b=T2V7HLdjkE0gh5fYxw31w3iztrM01erjZ7H1npJKpeusmTXMrFNFyOlxiiPOsf9+ea jTsCauO8fh7kL+fPaHlMHC4h4wrtTuV2V3/o5S3/t3PWMQ6AUEBFw7GhBPF/KXwK7FWn 5s3qRJo+6DXgWHysDro1Ls5eQ8oeukWhLdE8YqSJNNbfoEBUGR11M7s2TLXYA3PoUAPV hdIp4xxDC9Y4/10FbJaaUOOeKusPhp2fIQEqrfP+kQP5CgdahgbicjoxvvC2DAqYPHax u4jiyYtP4OvbHgNc2Ow8n3ZW06nEODo4xbG8tv+EwWQ+YUzCefdu5EyEEM2xiDgeH/bc Ig7A== X-Forwarded-Encrypted: i=1; AJvYcCWObMNdDj8/yEN4f+kzlmOzRo9YtEhGe3rynn0TQciLvJ1m1N1lP/kEOsc3WwiTTwvVf40w5TYyq0hcPYc=@vger.kernel.org X-Gm-Message-State: AOJu0Yx0injdo5MlHRoj+camvCylEH0EtTtYzvmUz/ybea5q5CfqFW9n E5/UQFvOiogNDirCXMIBkBoIXIZ5DZ9UmUHP+EgpWJw4bzJ+5EmpJfVGkDN9ouPT X-Gm-Gg: ASbGncvmOh3cNVTxvuahQJ+g32e4NFJGwy/oxZIewmx4TRKzN5q1+2phVdNzskmo5Kk dwfloc3IT/RIkJeHS4aWkBtFimHzxOYHa+Ais7v5UnRbTXvezlGjXp4VAOXIFDqSn/dWFKB5y82 q7N21VN3lTgr23qjlrNm+Wg1BUrKNQDIbuusN88PC7ymcK+MVUxpLyvbIWTY4k0kBurt8PKJxVP a8GXbPUSAQUxYr1uRiJT87AkzG7NuSF8zkSMtJrMQpy2BCYYw6+S/tmHn84YIwGIEyV0tOlAN94 +/Vm8sOVsGwtMxlKzir98PX8O69iwfT8zzeFzSnBbXWMndJNR1i0b+2KYTuFNte68WbseetXCyL yjbQtUxuv1ZU9zg== X-Google-Smtp-Source: AGHT+IEcOnQNdP8n6PBUMzpigd0z6qZdoKKaEMwGaglK0GRbVqi4/4+cA6g1yChm2wWfR/FCJKgu0w== X-Received: by 2002:a05:6512:128a:b0:553:2ce7:a201 with SMTP id 2adb3069b0e04-5550b8475edmr4929509e87.19.1751308575475; Mon, 30 Jun 2025 11:36:15 -0700 (PDT) Received: from SC-WS-02452.corp.sbercloud.ru ([37.78.230.218]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5550b255a51sm1530793e87.88.2025.06.30.11.36.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Jun 2025 11:36:15 -0700 (PDT) From: Sergey Bashirov To: Christoph Hellwig , Trond Myklebust , Anna Schumaker Cc: linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org, Konstantin Evtushenko , Sergey Bashirov Subject: [PATCH 4/4] pNFS: Handle RPC size limit for layoutcommits Date: Mon, 30 Jun 2025 21:35:29 +0300 Message-ID: <20250630183537.196479-5-sergeybashirov@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250630183537.196479-1-sergeybashirov@gmail.com> References: <20250630183537.196479-1-sergeybashirov@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When there are too many block extents for a layoutcommit, they may not all fit into the maximum-sized RPC. This patch allows the generic pnfs code to properly handle -ENOSPC returned by the block/scsi layout driver and trigger additional layoutcommits if necessary. Co-developed-by: Konstantin Evtushenko Signed-off-by: Konstantin Evtushenko Signed-off-by: Sergey Bashirov Reviewed-by: Christoph Hellwig --- fs/nfs/pnfs.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/fs/nfs/pnfs.c b/fs/nfs/pnfs.c index 3adb7d0dbec7..48dc22916f06 100644 --- a/fs/nfs/pnfs.c +++ b/fs/nfs/pnfs.c @@ -3338,6 +3338,7 @@ pnfs_layoutcommit_inode(struct inode *inode, bool syn= c) struct nfs_inode *nfsi =3D NFS_I(inode); loff_t end_pos; int status; + bool mark_as_dirty =3D false; =20 if (!pnfs_layoutcommit_outstanding(inode)) return 0; @@ -3389,19 +3390,23 @@ pnfs_layoutcommit_inode(struct inode *inode, bool s= ync) if (ld->prepare_layoutcommit) { status =3D ld->prepare_layoutcommit(&data->args); if (status) { - put_cred(data->cred); + if (status !=3D -ENOSPC) + put_cred(data->cred); spin_lock(&inode->i_lock); set_bit(NFS_INO_LAYOUTCOMMIT, &nfsi->flags); if (end_pos > nfsi->layout->plh_lwb) nfsi->layout->plh_lwb =3D end_pos; - goto out_unlock; + if (status !=3D -ENOSPC) + goto out_unlock; + spin_unlock(&inode->i_lock); + mark_as_dirty =3D true; } } =20 =20 status =3D nfs4_proc_layoutcommit(data, sync); out: - if (status) + if (status || mark_as_dirty) mark_inode_dirty_sync(inode); dprintk("<-- %s status %d\n", __func__, status); return status; --=20 2.43.0