From owner-freebsd-hackers@freebsd.org Sat Feb 17 15:38:20 2018 Return-Path: Delivered-To: freebsd-hackers@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 55AC9F198C7 for ; Sat, 17 Feb 2018 15:38:20 +0000 (UTC) (envelope-from oshogbo.vx@gmail.com) Received: from mail-lf0-x22d.google.com (mail-lf0-x22d.google.com [IPv6:2a00:1450:4010:c07::22d]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id A293585C77 for ; Sat, 17 Feb 2018 15:38:19 +0000 (UTC) (envelope-from oshogbo.vx@gmail.com) Received: by mail-lf0-x22d.google.com with SMTP id h78so7783319lfg.6 for ; Sat, 17 Feb 2018 07:38:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=ATKsVdUIJk6Vr1tpxNKi1PSD+vnONmnhgXFaDrishs0=; b=l72JkXUPsdB16MxtjGxPcd3ZkD69Jn8cmzTF+e+K+h3kAnGj213sAxDiJOVroAW5rs IUUx9N5lLf3bPPEdXqvztqu6RO6VdF2IncHrU1ukSfNZnTRj+jY4gbsG9isCOGyHKE/Q xpSHVhGRoxiOiXfqLgUPqFOES1aUW+Odv+675lrUnDAazYVEK82HIchI7N8t+b/ejacT H2QmKIGT9BHc1L3HjsaBOpeHX6RsQZ0ZKoBMViP7RuuSlAbVjnvRcH6kg6Hj9LswNHJ+ ruUHC0ygaNeURsc3ZpV8Utek8Hbawh8zsxXst/aSfCL+LLn0PeJs8iZxltL79ayZL0Hr G7qw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to:user-agent; bh=ATKsVdUIJk6Vr1tpxNKi1PSD+vnONmnhgXFaDrishs0=; b=oVDfmY6Hzogqwzk8lSzZ2R49PnK6B7hiGh6bAwrTWkW5NjurWNlA44OvCxagcWueBz 7uJJF/bqXTTo1v/8p+Emt+Gu28PMWNLkhpkZGl/D1dN6tO1DVoodS9AoQrAT1fOwwn9E ByhuKhboLvz9+ADL75moenHkX5ljZNM4e4i9jVNMxkExw6sEPYyuivSpWKsUTsngG88V S4fml+Rop4Nb8YqXVP113ttbJ82av5ruzU0x//astgXibIgWoai4/fJYq90uBrzzQ3Vz NG57e+GAJgmfZ4gdVLX8/8kez1Gk6c3BzrflMlwKEOb6FRGlbztMFvW5j1qdJcCDkWc9 HGdw== X-Gm-Message-State: APf1xPBb1Dslkj8+9hFfKiBAsBMiJujhVoNH+meZrY2HIcdubDaj6SJZ t2ptqPjTfRL91nX34xr3WcU= X-Google-Smtp-Source: AH8x224rw2Vfj2My6YpgQscWJPCYzaehd39imiJFwB2ye7sU28M2Qx8R0XGnRrKqrjqhbrLsehhFbg== X-Received: by 10.25.205.148 with SMTP id d142mr6217020lfg.9.1518881898334; Sat, 17 Feb 2018 07:38:18 -0800 (PST) Received: from x-wing (87-206-170-77.dynamic.chello.pl. [87.206.170.77]) by smtp.gmail.com with ESMTPSA id r9sm3990927ljc.18.2018.02.17.07.38.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 17 Feb 2018 07:38:17 -0800 (PST) Sender: Mariusz Zaborski Date: Sat, 17 Feb 2018 16:38:25 +0100 From: Mariusz Zaborski To: Mateusz Guzik Cc: freebsd-hackers@freebsd.org Subject: Re: Where KASASERT fd < fdp->fd_nfiles should be? Message-ID: <20180217153825.GB61118@x-wing> References: <20180217150224.GA61118@x-wing> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="6sX45UoQRIJXqkqR" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.2 (2017-12-15) X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 17 Feb 2018 15:38:20 -0000 --6sX45UoQRIJXqkqR Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sat, Feb 17, 2018 at 04:23:40PM +0100, Mateusz Guzik wrote: > On Sat, Feb 17, 2018 at 04:02:24PM +0100, Mariusz Zaborski wrote: > > > > KASSERT(fd >=3D 0 && fd < fdp->fd_nfiles, > > ("%s: invalid fd=3D%d", __func__, fd)); > > > > > > My question and problem is do we need this KASSERT? > > The fdget_locked checks if the fd is not larger then fd_lastfile. > > But the code from fdinit suggest that fd_lastfile can be larger then > fd_nfiles. > > pjd@ suggested that it can go over size of the table fd_ofiles array: > > while (fdp->fd_lastfile >=3D newfdp->fd_nfiles) { > > FILEDESC_SUNLOCK(fdp); > > fdgrowtable(newfdp, fdp->fd_lastfile + 1); > > FILEDESC_SLOCK(fdp); > > } > > > > So the question is do we need this assertion here or maybe should we mo= ve > it to > > the fget_locked()/fdget_locked() functions? > > >=20 > While the assertion arguably can be removed, it is most definitely > valid. >=20 > fd_nfiles signifies the size of the table, while fd_lastfile the highest > used slot. By definition it must fit the table. >=20 > The code sample is used on fork where the existing table is duplicated. > Allocation of the new table is performed with locks dropped, which means > the old one can grow in the meantime. The while loop ensures the new > table will have the right size no matter what. So maybe we should go in more general approach and move this KASSERT to the fget_locked and fdget_locked functions? Thanks, --=20 Mariusz Zaborski oshogbo//vx | http://oshogbo.vexillium.org FreeBSD commiter | https://freebsd.org Software developer | http://wheelsystems.com If it's not broken, let's fix it till it is!!1 --6sX45UoQRIJXqkqR Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEkD1x0xkJXVVY1Gwf38KEGuLGxWQFAlqITG0ACgkQ38KEGuLG xWRtrQ/+IsfQ4Z3+6tVzIsPzRAlRh6h6dxydBcZn0EsgJDLt+m2IJ/7aKflltWTv FhC8uf01sY/32f7lBODHDGYcToUS3gxmS/QRNkm4kV86fzXVmz8q2/nsPVajFJZa Wz0zoBfOIsf/4/BReG89w2kQE9qMXI5fy2H2t/3CWs6MjO38KaEVK7KGhZJtfvjM eROaJdz6qJeD1lbxvE2jeMWT1HU6pysttoV8ra1MUUJpGs5vVUT1sWD16O3YVSRK KdtmGIATIjzRHCiaMZoXr1ul1vrKOjV/O8kaF01lptneKkOJ6H7l5t6CSestUfFG KupLQYhvsUhGXXU+BoPDmIao4tUbwxIjHtR5BRM60lqUFeQr47Rflnyz2u67fQXz YzeVIr6zXKCzwALmYbPS6CBr/SM9rToUobjQlN+RLNG9qZ5LMAqm7uB9BfXT0gpU TkgQFvVCRHrrtGt0v3asCJvBCgLVTC4CxzAR1SBfJwv0VOamb5yiaEZ+AF6A2/Fu psgZUEgnfbsvfj6QWXHMvYO9j3xebCmEFL+xXUc65RyKmeKhXrLy3iVDU6Npsqma gI7grNnxisVfs/WdR2+3GH85Aoh8dH1ARehq6PXGqfcX/rHlpeiQNvkZpp/TkxJf 10HjrYpoh5jB7fKOpVELMc+BV6ptSh7qeMl1LtJZal/ECvyNsfU= =LrUW -----END PGP SIGNATURE----- --6sX45UoQRIJXqkqR--