From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id D5A65C77B7C for ; Tue, 9 May 2023 18:53:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1DC846B0071; Tue, 9 May 2023 14:53:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 18C456B0072; Tue, 9 May 2023 14:53:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 053DC6B0074; Tue, 9 May 2023 14:53:56 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id E99A06B0071 for ; Tue, 9 May 2023 14:53:56 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 99FEA1208AE for ; Tue, 9 May 2023 18:53:56 +0000 (UTC) X-FDA: 80771616072.07.DDDD0E5 Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11]) by imf01.hostedemail.com (Postfix) with ESMTP id 753004001A for ; Tue, 9 May 2023 18:53:54 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=fail ("headers rsa verify failed") header.d=mit.edu header.s=outgoing header.b=T0Ymu5pe; spf=pass (imf01.hostedemail.com: domain of tytso@mit.edu designates 18.9.28.11 as permitted sender) smtp.mailfrom=tytso@mit.edu; dmarc=pass (policy=none) header.from=mit.edu ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1683658434; h=from:from:sender: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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=KZxEablCgEx3gfZJr0RJObjL9zAKTAvOj4M64WHGy50=; b=IBFf7vZcXWbI1cQF9g6I8KkpSmsh6jbSLE78mGjpwwntt+Zyx2De2vPigJmAbIgOUfFsrL 9xVjAR1rttSnrBQGhP+8cCiz/WUPG9QU4JLeTpccew79dNDa6I+z+r1+EUFlAUQ0JEEv/t 3SRrIxafsX+GXrAJ1vYjolqo/dNbzV8= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=fail ("headers rsa verify failed") header.d=mit.edu header.s=outgoing header.b=T0Ymu5pe; spf=pass (imf01.hostedemail.com: domain of tytso@mit.edu designates 18.9.28.11 as permitted sender) smtp.mailfrom=tytso@mit.edu; dmarc=pass (policy=none) header.from=mit.edu ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1683658434; a=rsa-sha256; cv=none; b=0j86gpK2DGI+4KlF4yPCWu+wU0LbgxMuO1dn3Hs6tTjQlP4osxPpsfp/gHntpI+WlD+E2H cS5H/wlJ5SfY3QwMfZIWgXCtwPMMbfgRRKlvei7zgIveKsmruSP2m5rZAE1KYqn2wvj/Jn /DHPr0p7B8imMj1Xug4sXP6JW4GHd6g= Received: from letrec.thunk.org (vancouverconventioncentre.com [72.28.92.215] (may be forged)) (authenticated bits=0) (User authenticated as tytso@ATHENA.MIT.EDU) by outgoing.mit.edu (8.14.7/8.12.4) with ESMTP id 349Irg9g026634 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 9 May 2023 14:53:44 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mit.edu; s=outgoing; t=1683658426; bh=KZxEablCgEx3gfZJr0RJObjL9zAKTAvOj4M64WHGy50=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=T0Ymu5peezw+ttc+oZOtm7QdJfWjzldInNAKBP4QuKy7qNWUaBdSywgqWIwiPk6Xw fwaWO6w3M13oXTClaJXn8lxIi5AfNQ1vkJ0zcPd5+qh9hRpJyTM44xq/hRD4+9OAGP LNQO+0cSPK9re2Tg0Tb2L4h075MUiHsgoKFv3di7rvnDBckTAUP8KPipUzZN5Uoy0/ f11TpWDjH465j49mXYPUJAK6I4Mr1lSv83FNpcyQVEhRRq7UZBK4LgqGF7rXQhxVvJ gSbxYXVgdGZ13lDlRHAL4dx1YLAtf0rm23+93KXsf4qM7FM2pY1oXU5ASGCS4KynMi GA4a2O8xR4liw== Received: by letrec.thunk.org (Postfix, from userid 15806) id 2E99D8C03CB; Tue, 9 May 2023 14:53:41 -0400 (EDT) Date: Tue, 9 May 2023 14:53:41 -0400 From: "Theodore Ts'o" To: Matthew Wilcox Cc: Tudor Ambarus , adilger.kernel@dilger.ca, linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org, joneslee@google.com, linux-mm@kvack.org Subject: Re: [PATCH] ext4: remove superfluous check that pointer is not NULL Message-ID: References: <20230508151337.79304-1-tudor.ambarus@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspam-User: X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 753004001A X-Stat-Signature: mkick9uj59o1awt53fhsaqz1s4x71qd4 X-HE-Tag: 1683658434-409008 X-HE-Meta: U2FsdGVkX1/UKm8I1teedoLXWZcKFg79gTYDz2yre/zrEb2N4jkcPNfwOwtolvQ0CI4tD/w0WOpfyzirrjislNcozPfSdkjGVt4c9rBfIT/BOVUjrMmlSFl4UEBsSU4tKa/CtWt3THq8dTgWg4dkgYLIAUW9fAf0MlxJk02wzLXUSLkKVTdC289dn1XLWtYp/al8KY6QpCB2jZnDvz53EL51PCNeL59Qqu8vWNHI0OOFDBH1sPKHFhi5a7pxK6+ndWVJKmP02eqIttLsTMcKrInw+wIrN1KMahX2fZtRdW9sgg/V3dEQK4umh3uLzMvpbqu538MxMUHRt6sgAjc/B9xVXkTVmogBR82C4jJDnrBZuSelSHP5XiJ25vJS+OAUsNZcl+sqXpm/Zar2/DBm3XxOajVsKaY161eflTOKJmotN++V3ZFttZyhi9Z8huZPKartQVjZ4W7huIQEgbei5z7zJq7kq33ZtC1p9MyuND2fVEwqOQItYDKzlW7X5uBK9JvKdm3K0PAv7YrRp2ciOQpwJUkmrWFQsPQtApGugwm38VHsWFAe4fdrA+M3Jbnt7qRjdW3TVqZeG1Fe7RjwLcTwfnhM476/S6WsbiLDoe+Qr2yiaTlLWCzXQgTkIceHLkIlce+22R6k4jIfYuCBHLcoE3bchJ1X3Cu/wDmTFvBpP9jOiGVcWh5p68BgT/MVpB5EzuQjwdNP0Fhbd+2CTUJxep38Sp13Dco00p9EFuihqjDLH6B9PZB3yW5W45QYE/nxefhho4EOO0oFiGwtZ+dwvI38/DmHPESFHkg1Oi/qtszSXay5dauA1yGi0BqMcUX3gJbA4wcsH9x1LSt8yCH+D4s4wnyvePZgpHsB0/9gsoO7t3N7PbvvC75UbERMJ2RKQb48flCRgLDkdlBuosImm7cAuZTxz05voXtkmWw0eJMqVLrJ2KL/aJqAsJvy8e86qOwnciVv4KjaYr3 uPz+Dvvf Nae+u0/vAnl/QG7598S2/t2qmPBIkfImjUNLY1U6Efn66XRx+H97tI9s9dBL3lWqDx+wLEi0tHpWOyI0iOvLR7HyTDANkrp+B2yK4BJYNPvUz4lILme3N43paLKalXFkTa1v36yVE5JNCIUL7GHI3SypLQH3AztxU5egwUalhb3hCpytANIFVZyqyb6PkRnFrgRxoMDbd+JKMVQtcQ6bKUnej3g== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Mon, May 08, 2023 at 10:13:27PM +0100, Matthew Wilcox wrote: > > > > I was looking at this just a few weeks ago, and I couldn't find any > > actual *documentation* that it was safe to call vfree(NIILL) or > > kvfree(NULL). The problem is there are a lot of architecture-specific > > functions, and unlike with kfree() there is no top-level "if (ptr == > > NULL) return;" in the top-level vfree() and kvfree(). > > There doesn't need to be in kvfree(). is_vmalloc_addr() returns 'false' > for NULL, so it calls kfree(), which as you note has an explicit check > for ZERO_OR_NULL_PTR(). is_vmalloc_addr() also returns false for the > ZERO pointer, fwiw. > > I agree that this should be explicitly documented as allowed, since it's > not reasonable to expect users to dig through these functions to verify > that such a change is safe. I seem to recall at one point looking at kvfree_rcu (at least the one argument variant), and I *thought* it would unconditionally allocate memory so it could be put on a linked list to be freed after an RCU grace period had elapsed. But I tried tracing through the huge numbers of cpp macros and other layers of #ifdef's and other abstractions, and in my conference-induced sleep depreviation, it caused my head to spin, and I gave up trying to trace it down so I had 100% confidence. So if someone could document *all* of the k[v]free_* variants whether it is safe/optimal to pass NULL to them, that would be great, thanks. - Ted