Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp6223374rwr; Tue, 9 May 2023 12:00:58 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ79yqL7EojCVOymuh7RlVxNz6M4e54ONnoP+Gq93u0jBd+CNEMb3Ttr0+v1kzARMz1kD5YB X-Received: by 2002:a05:6a21:6d8f:b0:100:d5dc:3aff with SMTP id wl15-20020a056a216d8f00b00100d5dc3affmr8085057pzb.48.1683658858273; Tue, 09 May 2023 12:00:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683658858; cv=none; d=google.com; s=arc-20160816; b=GZhWWNv0ymxlywpKBbUogTDfF751e58CEPI9WtDsoh9xPhFIarT+HHng6J1pDiuvkk b9AT0eSS4DQRWtdL1IdwHaNe3inBe45/G7wEEf7i3S59aCsH6pe3+9g7Wv83+BOZrgHp IAOcmj0gqEnO0lzsWGC9f6fGQXuLOZTKnNInuAsliLGjiQYxQi7Xusx0bVv7KynQw7U+ gIb+rKv5D04PTbxQ3rlXdJLJNWqy02f2ZY6hPWqXuZIgDktra9y+adbFX9Nvl+ScKIZJ zgPjJfFiuDTv+y+aA85EMgihcgOHcOVp+iUj1X89VcjAbZi9YzkHXZRUx0e7oM6IQZR7 fuCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=KZxEablCgEx3gfZJr0RJObjL9zAKTAvOj4M64WHGy50=; b=KQag82RjL1lKgM+0WvtQ4Toui3XlcZVvjqPZMLkacjIW7Z27+rImXbRwM+cGVJY+5L VPBggRhM9BTpP/3yVElpFlDnzxQO8RXtORqpYTwntulZYJmaKCDU/sDu3dd2DpbojcQG 21s9jrqwgfvRuBcH+/fy9Yq2XxNd3BBMbo5bRyHNsI1m4OIy9WzP0RpR1nyfik7Hjqqi RVQyeknyxEvZ0HU8rHN2P1K5naeUjKHx3rHP9dNJuQBQp2zOuhyBSQN9mNtgHFmmY6Kv +X/pL5mnubWMeVNVWfomeFgWXQKNM4djgQFoKfyx9+qSwMpinpxxBufBX9Hls0XlNah/ kdTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@mit.edu header.s=outgoing header.b=T0Ymu5pe; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mit.edu Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bs123-20020a632881000000b0052872c32995si1924870pgb.724.2023.05.09.12.00.44; Tue, 09 May 2023 12:00:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=fail header.i=@mit.edu header.s=outgoing header.b=T0Ymu5pe; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mit.edu Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234743AbjEISyF (ORCPT + 99 others); Tue, 9 May 2023 14:54:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34662 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229549AbjEISyE (ORCPT ); Tue, 9 May 2023 14:54:04 -0400 Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F1B83C15 for ; Tue, 9 May 2023 11:53:59 -0700 (PDT) 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-Spam-Status: No, score=-4.0 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAY_BE_FORGED,RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org 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