mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Paul Menzel <pmenzel@molgen.mpg.de>
To: "J. Bruce Fields" <bfields@redhat.com>, Jeff Layton <jlayton@kernel.org>
Cc: Chris Tracy <ctracy@engr.scu.edu>,
	linux-nfs@vger.kernel.org, LKML <linux-kernel@vger.kernel.org>,
	it+linux-nfs@molgen.mpg.de
Subject: [PATCH] nfsd: Fix overflow causing non-working mounts on 1 TB machines
Date: Wed, 3 Jul 2019 14:54:43 +0200	[thread overview]
Message-ID: <17f8948d-19b9-beac-cab1-e4bc587d9612@molgen.mpg.de> (raw)
In-Reply-To: <860b4d19-49bd-5d76-aa06-c2d9aeffb452@molgen.mpg.de>

[-- Attachment #1: Type: text/plain, Size: 2416 bytes --]

Date: Wed, 3 Jul 2019 13:28:15 +0200

Since commit 10a68cdf10 (nfsd: fix performance-limiting session
calculation) (Linux 5.1-rc1 and 4.19.31), shares from NFS servers with
1 TB of memory cannot be mounted anymore. The mount just hangs on the
client.

The gist of commit 10a68cdf10 is the change below.

    -avail = clamp_t(int, avail, slotsize, avail/3);
    +avail = clamp_t(int, avail, slotsize, total_avail/3);

Here are the macros.

    #define min_t(type, x, y)       __careful_cmp((type)(x), (type)(y), <)
    #define clamp_t(type, val, lo, hi) min_t(type, max_t(type, val, lo), hi)

`total_avail` is 8,434,659,328 on the 1 TB machine. `clamp_t()` casts
the values to `int`, which for 32-bit integers can only hold values
−2,147,483,648 (−2^31) through 2,147,483,647 (2^31 − 1).

`avail` (in the function signature) is just 65536, so that no overflow
was happening. Before the commit the assignment would result in 21845,
and `num = 4`.

When using `total_avail`, it is causing the assignment to be
18446744072226137429 (printed as %lu), and `num` is then 4164608182.

My next guess is, that `nfsd_drc_mem_used` is then exceeded, and the
server thinks there is no memory available any more for this client.

Updating the arguments of `clamp_t()` and `min_t()` to `unsigned long`
fixes the issue.

Now, `avail = 65536` (before commit 10a68cdf10 `avail = 21845`), but
`num = 4` remains the same.

Fixes: 10a68cdf10 (nfsd: fix performance-limiting session calculation)
Cc: stable@vger.kernel.org
Signed-off-by: Paul Menzel <pmenzel@molgen.mpg.de>
---

1.  No, idea if `min_t()` arguments also need updating.
2.  Instead of `unsigned long`, should `size_t` be used?

 fs/nfsd/nfs4state.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index 618e66078ee5..1a0cdeb3b875 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -1563,7 +1563,7 @@ static u32 nfsd4_get_drc_mem(struct nfsd4_channel_attrs *ca)
 	 * Never use more than a third of the remaining memory,
 	 * unless it's the only way to give this client a slot:
 	 */
-	avail = clamp_t(int, avail, slotsize, total_avail/3);
+	avail = clamp_t(unsigned long, avail, slotsize, total_avail/3);
 	num = min_t(int, num, avail / slotsize);
 	nfsd_drc_mem_used += num * slotsize;
 	spin_unlock(&nfsd_drc_lock);
-- 
2.22.0


[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 5174 bytes --]

  reply	other threads:[~2019-07-03 12:54 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20190702165107.93C8A2067CFDD@mx.molgen.mpg.de>
     [not found] ` <8c3e0249-b17f-4bd2-4a46-afd4d35f4763@molgen.mpg.de>
2019-07-02 21:59   ` Regression caused by commit c54f24e3 (nfsd: fix performance-limiting session calculation) Paul Menzel
2019-07-03  9:56     ` Paul Menzel
2019-07-03 12:54       ` Paul Menzel [this message]
2019-07-03 15:56         ` [PATCH] nfsd: Fix overflow causing non-working mounts on 1 TB machines J. Bruce Fields
2019-07-03 16:03           ` Paul Menzel
2019-07-03 16:43             ` J. Bruce Fields

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=17f8948d-19b9-beac-cab1-e4bc587d9612@molgen.mpg.de \
    --to=pmenzel@molgen.mpg.de \
    --cc=bfields@redhat.com \
    --cc=ctracy@engr.scu.edu \
    --cc=it+linux-nfs@molgen.mpg.de \
    --cc=jlayton@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®