Received: by 2002:a05:6500:1b8f:b0:1fa:5c73:8e2d with SMTP id df15csp1010165lqb; Wed, 29 May 2024 18:50:29 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU7OkOIu7Cg+uZJrYjHReiQ5B17kepxJ09vBvWZwKpjhMzIpq9mnazPs6/7975QDWniqkzJPrIceJpZtS4xqy5UFobsDI+BAw7r71+48w== X-Google-Smtp-Source: AGHT+IEvuKckqt0dfDLeG8FoSW/fp+znvPlxW6GvSfwML2AsZDWej5HX9mMK+o3uQxGxJEq0Jimy X-Received: by 2002:a50:8e15:0:b0:578:5771:dc2c with SMTP id 4fb4d7f45d1cf-57a177cf233mr466857a12.3.1717033829541; Wed, 29 May 2024 18:50:29 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717033829; cv=pass; d=google.com; s=arc-20160816; b=JzMEYzawSPZCQ5SaHJedu22l91yUQgsVoaZ1QuYCwBnR61qBjQnQlU+O+Wt+J+WMAK PGhTVojbOWj+mDdp3Tf72nHJylVWAcCCr0G+OO34U1Zaz3dNnNvJbmISK/KiC/oXdhqB N5AWanCMq2UAyCPYce18UmlH1RoSRP/ME8xDID8Vyxx1oPqPvzlEs8N7mxonSARuGP24 uXelZwOra57+D4nbqqAroON6OqNHleS6CIzChK3hdh2tKtwuI0UsRPyqD696TNC50VGA fZe8A8B6ZEhuv/W8yas5BGnNqNXw5R6IXfNQarrQhRnQyR39e4d1l419i8tK9mbubf4k HfRA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=CfMw9tHy0aaB3TSiLd6z9f6QlIhExqYTyd8E+3PAqVs=; fh=UP51phbADgXC+8ErlnaoMytvtNjRjoJjhsfv58xEhaA=; b=Cctk0f5PZ4wkrXf/i6XxH1O4kWfDUpQ+53HiuAVzwJ3vLTE9XnFWmMeQHggmcO+ALV SA920iuUqqzAg8aFL/68zeYjGgaIFdfPIKSBLxGu3ZeZK0Dzod0kupMSgD4YKGhthXUE EDiFIMw+8XPe/+FajH29zWlNZyMLYH/5VBa78JwBkJGsuPknjY2i1+AAggL+YLXP1v/6 1/VaSUoJECO3kB07Pn4J4AENmeA65LCL1wp4Yx+kdFp7BPEIH+2PPyxGFYVGbPciVgTm pAFxIpHhNLx/XDSlPvo62cJ3Y52GwTI7XJqA5l8tXCsFK6Or13gRWaW117mltp2tUXXP pgJQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=kTuOxVbY; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-194858-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-194858-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-57864b38394si6129997a12.661.2024.05.29.18.50.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 May 2024 18:50:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-194858-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=kTuOxVbY; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-194858-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-194858-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev 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 am.mirrors.kernel.org (Postfix) with ESMTPS id 46FE21F22A2B for ; Thu, 30 May 2024 01:50:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4C59A1799D; Thu, 30 May 2024 01:50:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="kTuOxVbY" Received: from out-189.mta0.migadu.com (out-189.mta0.migadu.com [91.218.175.189]) (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 D25968C13 for ; Thu, 30 May 2024 01:50:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.189 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717033821; cv=none; b=Ald8LhBJDRZBSQTbLHlelzo/C2ZsPCdAxYD+eAYlR5VwqY1ySj5EM9Iv34BdiVUkpgdt+Rr02WuQgsEQ37z79raOBbPo0joqhpD6TH1DYDFfZceUYljnBsADXbLki0aY2acZdkm/ebw1CdF0fyxeN4IEYi0FJEq3V20Gip0Cz90= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717033821; c=relaxed/simple; bh=dJzhMKWwI+p3fkyvY8ReszvnKdJxHAls86oOxh6MzBY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CitJ7oSuakMiiK+Wc4fBHp4Q4VkWD//H5l+oGuuXoc62f65+FzsKNN+aYDu1FVg4NP+GdDLmTshnxW+Zr2Bur5ADhdWqg+lVQlVgP5eCAJ6ih5Oe+Zq3lMtLu3P1eE+pteP3aQ8rFfxdduiMAySYS19e1s+pOPqLxQsxFMCOPec= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=kTuOxVbY; arc=none smtp.client-ip=91.218.175.189 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev X-Envelope-To: viro@zeniv.linux.org.uk DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1717033815; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CfMw9tHy0aaB3TSiLd6z9f6QlIhExqYTyd8E+3PAqVs=; b=kTuOxVbYol232cWSsWqR7clknZ080/pkBgkwBM0aNmpo4MirTY1k+9TzbkG2yq+LG3q0Re 4EcUyYeIgsbWdTw+fh60oB39sx7eYNDRUV29yxSTFzHc/+AEzoBsBFsr808fb3ctbYV7RK 3zXhkDgNKqZ9c4pHVGGatnuHOV7dLI0= X-Envelope-To: brauner@kernel.org X-Envelope-To: jack@suse.cz X-Envelope-To: linux-fsdevel@vger.kernel.org X-Envelope-To: linux-kernel@vger.kernel.org X-Envelope-To: yuntao.wang@linux.dev X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Yuntao Wang To: viro@zeniv.linux.org.uk Cc: brauner@kernel.org, jack@suse.cz, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, yuntao.wang@linux.dev Subject: Re: [PATCH] fs/file: fix the check in find_next_fd() Date: Thu, 30 May 2024 09:50:03 +0800 Message-ID: <20240530015003.237210-1-yuntao.wang@linux.dev> In-Reply-To: <20240529190328.GP2118490@ZenIV> References: <20240529190328.GP2118490@ZenIV> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT On Wed, 29 May 2024 20:03:28 +0100, Al Viro wrote: > On Thu, May 30, 2024 at 12:06:56AM +0800, Yuntao Wang wrote: > > The maximum possible return value of find_next_zero_bit(fdt->full_fds_bits, > > maxbit, bitbit) is maxbit. This return value, multiplied by BITS_PER_LONG, > > gives the value of bitbit, which can never be greater than maxfd, it can > > only be equal to maxfd at most, so the following check 'if (bitbit > maxfd)' > > will never be true. > > > > Moreover, when bitbit equals maxfd, it indicates that there are no unused > > fds, and the function can directly return. > > > > Fix this check. > > Hmm... The patch is correct, AFAICS. I _think_ what happened is that > Linus decided to play it safe around the last word. In the reality > ->max_fds is always a multiple of BITS_PER_LONG, so there's no boundary > effects - a word can not cross the ->max_fds boundary, so "no zero > bits in full_fds_bits under max_fds/BITS_PER_LONG" does mean there's > no point checking in range starting at round_down(max_fds, BITS_PER_LONG). Yes. > Perhaps a comment along the lines of > > unsigned int maxfd = fdt->max_fds; // always a multiple of BITS_PER_LONG > > would be useful in there... Actually, we can simplify this issue. When 'bitbit >= maxfd', it indicates that there are no unused fds in 'fdt->open_fds', and we can directly return maxfd, regardless of whether maxfd is a multiple of BITS_PER_LONG or not. Therefore, I think this comment may not be very necessary. Of course, I don't oppose adding this comment.