Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3787111ybi; Mon, 29 Jul 2019 12:36:47 -0700 (PDT) X-Google-Smtp-Source: APXvYqxeBmenPPEZUnMjASHoterWvxPbEbiweF2u8NbQI/jvs+sbYgqNiTaFVNo9x7jTAPxEmb3m X-Received: by 2002:a17:90a:4803:: with SMTP id a3mr116052879pjh.58.1564429007010; Mon, 29 Jul 2019 12:36:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564429007; cv=none; d=google.com; s=arc-20160816; b=WJ5W//8wnUtBiPj6YWHFmH+YV8kdzJou2tj0Zr0scMsOsruHNVI6ICUdXTdY2F5lW/ qqFXHonXtdrVx7CDqIizQD/7pkJzWGr1Djp0qLS/J3/YJxoAuAA0Ki+/qwfjWzSihOu7 rtnyd8OALi5WCfzS4nKJdnefQGCeemi5TlhFSCzx5NGHvdPgRE9kVBpftvo6w2Cmz9ja LzqkWee3+eov4qBU06AnifebxM9bbHJ2HOmmGB+YcJ7iXHvK5N6ZhJZJr8SzlHSxUjEJ epp4vVuIALQwRfDIplojJBaazYzosiXnxax5NyZLGqxc0yLEFZN8ADlX1+h/rIS7RQoJ djZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=X2oZKrhdj16zWfWFLEHBwNX79DfXGGIh2xyjDJZbdws=; b=wiJFq4xgmdSto+2x8xB5nXKfYaa8qgNd8wY696OqbJvDgmcQN/4A6HdXWMCro/KlZg O4UiyairGbxoLmP9yoooXu+wyQ1gcChN/dxPiwbpdSr1Xgv1AQTUgYbBbcaFtyIx+hTG RJ8WgvirjfgwyAau18Nq6lycDeeHb2PckR672yncIrxRmF4mjFbVOkxnsdAJ1xRPDrp3 f8xmquTaV6eDI7+TV+W0/UBpaz950d41ECCOxJV4s8gLXHRaSPb3DcnFt5EpadPmZmfv aXwkC9GVeoQE9hx2W0xL175Tl+MClgET2GSFrNaTxS42ql4Os+kubF7uIP4TwrSa0fe7 l1OQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=HVXhqoOn; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d9si29665232pgv.577.2019.07.29.12.36.32; Mon, 29 Jul 2019 12:36:47 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=HVXhqoOn; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388515AbfG2TfJ (ORCPT + 99 others); Mon, 29 Jul 2019 15:35:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:49366 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388477AbfG2Te7 (ORCPT ); Mon, 29 Jul 2019 15:34:59 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 70D3721773; Mon, 29 Jul 2019 19:34:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564428898; bh=CeUhq4u7hoiRDwWUD7AM1Gg4yNUO7s/cPGRFzV5zmOA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HVXhqoOn5EiPcn3k0N2ssaGWhcRATOO8UEMMY/9KQNcCWbSAqqEueWE96SeSsipfE +kSJW3r1tMf0tp7/WHdv/FNIYhpTyASUe6tZqRjxpRyEQ9b2HAfFwc5I/wH7+r+Jt2 5BbbaaoDoa9PnJo7HNJiQ05pnNKwK4EvOQVjkQCo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Paul Menzel , "J. Bruce Fields" , Sasha Levin Subject: [PATCH 4.14 220/293] nfsd: Fix overflow causing non-working mounts on 1 TB machines Date: Mon, 29 Jul 2019 21:21:51 +0200 Message-Id: <20190729190841.368516511@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190729190820.321094988@linuxfoundation.org> References: <20190729190820.321094988@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit 3b2d4dcf71c4a91b420f835e52ddea8192300a3b ] 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: c54f24e338ed (nfsd: fix performance-limiting session calculation) Cc: stable@vger.kernel.org Signed-off-by: Paul Menzel Signed-off-by: J. Bruce Fields Signed-off-by: Sasha Levin --- 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 0bf88876c889..87ee9cbf7dcb 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -1511,7 +1511,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.20.1