From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 2AC043446A4 for ; Mon, 12 Jan 2026 21:51:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768254701; cv=none; b=Cx+c9wYBHhWK6TeJg5k8vrO1Y4MNgGiAPvpF64wiUts2/v9SzNNrYScryVRupg5QNGsvbgXa9vI71h+NxY+CjjMPsGAABvOlH3ItxXGoNTeADv6M9/qpKI3NSh3TcSSa7HtUzB9okpfLdN06I6yceyk81czMJo6EWtn9NezqLGA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768254701; c=relaxed/simple; bh=TXs7PPk1XpD3PbNMDGbvon5nP0IW/mjZS0LoOHcZP8g=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=dwNLsc+doR5tmMG9+K8cUfGlslg3Vms+6iM/1Zy4sS/wFOnU2IZBySiY3QcVFuhNOFSA8Igu8U5TqUuvOBmrlArl18AsRkenb5rmz0t8BzOXcD/FAOu01jWawq3hKBjuJeG/r9j9nJ+yGth/12QyWoUx/IxRGo1f+2e2NMOtwXw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Y4FyfB1E; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=Z9w/IMki; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Y4FyfB1E"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="Z9w/IMki" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1768254699; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lG/xt+Zo6w++4JbumRD15X/stpwb03QCR9/DiPk31F0=; b=Y4FyfB1EAqNB9K16bMcwyi8QxCO3cGv3FD2CcDge0FZw1p3GF9s79oR5JTpfVlMTe7ElOd PQKcOB5JOo3Frj5vpZ6MJpxxvx0Jo70tXYetnIZxyWekGgLXP1gt07vP4YfqgNQIIjxWzJ AXVEhZGjBK6lGRo+YN1eYPoXXGKkygo= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-694-B04yMkcRPfiUxLEODXwFbw-1; Mon, 12 Jan 2026 16:51:27 -0500 X-MC-Unique: B04yMkcRPfiUxLEODXwFbw-1 X-Mimecast-MFC-AGG-ID: B04yMkcRPfiUxLEODXwFbw_1768254686 Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-8bc4493d315so1799489985a.1 for ; Mon, 12 Jan 2026 13:51:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1768254686; x=1768859486; darn=vger.kernel.org; h=user-agent:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=lG/xt+Zo6w++4JbumRD15X/stpwb03QCR9/DiPk31F0=; b=Z9w/IMki4n0AAkkjKcJxoanCsImqMeAEZFQEAsP7uvYzPJpS2pzMOBqWfzWydFKAR7 V0PBjwMtXSliAyL7KmXzZelgE3hsJFmXtOqDcT2/I/I9D57+32kbLB++js5BLhdxT9fm MQcjG0o60VzQ+8CSX1p6K5y7BNOMZ7Tgay/sR5m2l6OQ18pMUU+UIgY62sOJT1b+yKtG Igfl7GxQNodkF8NNrcYFnBxxr7duElUnMjPMCSOI9F3mIPaBf0EfB8EEUs/aNt/uMrVZ 5iBby+Oz8aXqybDXn5jdFGJbelYGTTmLu7sXx9DHcCLDd5oam9VgRJAYUy5DEtb1Tpxr Lbag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768254686; x=1768859486; h=user-agent:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=lG/xt+Zo6w++4JbumRD15X/stpwb03QCR9/DiPk31F0=; b=QmtlwI3LSrkuo+ARf+UBv9wC5XG/5a+VTfgjyp/4ktOhRlugXVbKKko62JcnLToWPA F51gaRsjpFZT8rME7zmx55w4vrszG8xoC7CTFVa3jpVr/4ln39CssXRsMd1al6VyEbWI iP4L5oWDs+1oFN+cJahzevQT6twA4ur1KYuIJ6zDQcEqlS+bW2WdF2fKIGwp9YE054ce mmSMOcWs5XtOL5ved2IPE/2oiBYOWW2w7Jb0G82A5mWAk8zmkH2lJLn9569EeyvA6zkl /DhcJovZvDXbHRtRnK0XYGbDcob6BIzb/iX9R43lyDCTfR17hxVkz7zjqJ+WE13sVG5o 2onQ== X-Gm-Message-State: AOJu0YyJaSwTE98blzfE7lrcpGxug9GU3MVDfHeBVzsHcpyAj+VJx6Do eE/k5532QEcFw72rrRN4I0iYqgk6epnZJBY6qdUdUA+Q23HNEmOfXhRKTZtbVbIZy6PP1iSGtIr dmJblbvzlqqvQcrF7IK5KIuAIExWSfCK1ZusNGp2EOtbRIZSYVtbQ0QSO6m4qgkZW1Q== X-Gm-Gg: AY/fxX5csSYQaEDm0ze+9+bVe3it5L3KTIsTd6Mrm88PxD24gnH1aHzYzwSrVOArJHB hotH6uWlLHrYsEqXY4RmAhXowtdTYKK1YSonkq4mbSift7vDfpFSQpoAm5Kh+YF5TpqUQtonl54 bxKShTvSFLhN9A5l7XeTAP1dUsJEsrRNKtwzDOXs0TasBAWuaP07j0Gk+QXcE2d1+CMz/tnJooW 5Mi6U0O7tJ16HYO6q5B5mrxB2MMdXTz0+D6QITMZH9kj2mXR1wVEocJdRDHewwtyeN3OFeWHN5N XlCF9nyTRwifXMeZK9an0qXm1eAO3IaWLNnbONwrWxJWeVfKzsDtO+NQZo7MrYgpG/dgLJm5lyq aI8gFCWpU X-Received: by 2002:a05:620a:7101:b0:8b2:eb66:c64 with SMTP id af79cd13be357-8c38938daaemr2617949885a.29.1768254686482; Mon, 12 Jan 2026 13:51:26 -0800 (PST) X-Google-Smtp-Source: AGHT+IGCkpe49S++VqEffSBOBVXTkUb2yNggyXQirptPBh8ES7ItwAnLFAB24ZEcsyfb77ysP4HDOw== X-Received: by 2002:a05:620a:7101:b0:8b2:eb66:c64 with SMTP id af79cd13be357-8c38938daaemr2617947385a.29.1768254686087; Mon, 12 Jan 2026 13:51:26 -0800 (PST) Received: from redhat.com ([2600:382:771e:5aa5:103f:e4ff:d734:7cd4]) by smtp.gmail.com with ESMTPSA id af79cd13be357-8c37f51ceb5sm1676840685a.35.2026.01.12.13.51.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Jan 2026 13:51:25 -0800 (PST) Date: Mon, 12 Jan 2026 16:51:22 -0500 From: Brian Masney To: david.laight.linux@gmail.com Cc: linux-kernel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, Alexander Viro , Andreas Dilger , Christian Brauner , Kees Cook , Miklos Szeredi , OGAWA Hirofumi , Theodore Ts'o Subject: Re: [PATCH 30/44] fs: use min() or umin() instead of min_t() Message-ID: References: <20251119224140.8616-1-david.laight.linux@gmail.com> <20251119224140.8616-31-david.laight.linux@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20251119224140.8616-31-david.laight.linux@gmail.com> User-Agent: Mutt/2.2.14 (2025-02-20) Hi David, On Wed, Nov 19, 2025 at 10:41:26PM +0000, david.laight.linux@gmail.com wrote: > From: David Laight > > min_t(unsigned int, a, b) casts an 'unsigned long' to 'unsigned int'. > Use min(a, b) instead as it promotes any 'unsigned int' to 'unsigned long' > and so cannot discard significant bits. > > A couple of places need umin() because of loops like: > nfolios = DIV_ROUND_UP(ret + start, PAGE_SIZE); > > for (i = 0; i < nfolios; i++) { > struct folio *folio = page_folio(pages[i]); > ... > unsigned int len = umin(ret, PAGE_SIZE - start); > ... > ret -= len; > ... > } > where the compiler doesn't track things well enough to know that > 'ret' is never negative. > > The alternate loop: > for (i = 0; ret > 0; i++) { > struct folio *folio = page_folio(pages[i]); > ... > unsigned int len = min(ret, PAGE_SIZE - start); > ... > ret -= len; > ... > } > would be equivalent and doesn't need 'nfolios'. > > Most of the 'unsigned long' actually come from PAGE_SIZE. > > Detected by an extra check added to min_t(). > > Signed-off-by: David Laight When doing a mips cross compile from an arm64 host (via ARCH=mips CROSS_COMPILE=mips64-linux-gnu- make), the following build error occurs in linux-next and goes away when I revert this commit. In file included from : In function ‘fuse_wr_pages’, inlined from ‘fuse_perform_write’ at fs/fuse/file.c:1347:27: ././include/linux/compiler_types.h:667:45: error: call to ‘__compiletime_assert_405’ declared with attribute error: min(((pos + len - 1) >> 12) - (pos >> 12) + 1, max_pages) signedness error 667 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__) | ^ ././include/linux/compiler_types.h:648:25: note: in definition of macro ‘__compiletime_assert’ 648 | prefix ## suffix(); \ | ^~~~~~ ././include/linux/compiler_types.h:667:9: note: in expansion of macro ‘_compiletime_assert’ 667 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__) | ^~~~~~~~~~~~~~~~~~~ ./include/linux/build_bug.h:39:37: note: in expansion of macro ‘compiletime_assert’ 39 | #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg) | ^~~~~~~~~~~~~~~~~~ ./include/linux/minmax.h:93:9: note: in expansion of macro ‘BUILD_BUG_ON_MSG’ 93 | BUILD_BUG_ON_MSG(!__types_ok(ux, uy), \ | ^~~~~~~~~~~~~~~~ ./include/linux/minmax.h:98:9: note: in expansion of macro ‘__careful_cmp_once’ 98 | __careful_cmp_once(op, x, y, __UNIQUE_ID(x_), __UNIQUE_ID(y_)) | ^~~~~~~~~~~~~~~~~~ ./include/linux/minmax.h:105:25: note: in expansion of macro ‘__careful_cmp’ 105 | #define min(x, y) __careful_cmp(min, x, y) | ^~~~~~~~~~~~~ fs/fuse/file.c:1326:16: note: in expansion of macro ‘min’ 1326 | return min(((pos + len - 1) >> PAGE_SHIFT) - (pos >> PAGE_SHIFT) + 1, | ^~~ This is on a cento-stream-10 host running gcc version 14.3.1 20250617 (Red Hat 14.3.1-2) (GCC). I didn't look into this in detail, and I'm not entirely sure what the correct fix here should be. Brian