Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp7548786rdb; Wed, 3 Jan 2024 22:57:57 -0800 (PST) X-Google-Smtp-Source: AGHT+IF/pIN1B10UTDqPyM6PjMY7dVaVgWYaEsyMoa4dVtFWVCbjNcPw22ZNlFXUhMmN8fJtrbO1 X-Received: by 2002:a9d:6e92:0:b0:6db:cffe:8e8b with SMTP id a18-20020a9d6e92000000b006dbcffe8e8bmr266433otr.10.1704351477745; Wed, 03 Jan 2024 22:57:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704351477; cv=none; d=google.com; s=arc-20160816; b=ia+GNo4YEf+J0hcyySkRw9FUOH7rp+pw7gsPfugGzK+LafJdxftHSx0waroNo9Q0Bp N/y+AA3RLGQJJWJnOKmgGmNw+LvzpBiDzruylGV1Eby206OebLcPFK+j4IpJzVaMIjdY VLnhGpaMYVUmuZ+r5KeY6QuKeMY6tDpLx+eKY5Bh9z6kBb4fhzj0HdVUd738RGxi7OS6 EyoSnV8WHUIfQ+XEEOGSicZn9e9ZLymA4LP8JWE7HSn6t8Nzl8nePA4xXi4FwaMvVf6v w+xiosZ3TKgZx1Vo9KhHwzhMv0hrDx3vGwOpZQo3GcZGYwtHxGMFAZimCoLzTfrQhic4 ejDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=user-agent:in-reply-to:content-disposition:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:references :message-id:subject:cc:to:from:date; bh=KkIqKZhS3iQpBZGwLamcvr76Fd3kpYJXWIXA/ojdur0=; fh=HjFJC0jzZPl7YYHfiOXCCqMmA6U/PC+ZMaE7gwuBMqo=; b=WPeeCaLDA5S0uV+Lptn/2ZWAMRYvdT3hbVdZYg6MPFR+kcDTiKwwr5JQMH1fv6egaf 3dJJQPZs3YgBwdpkSzzz72iCLusmfCYL0aV3z2yMPiBNLHHPF8zh54GKC5ppFCZmBVRB epUasiHiA9DBk5Isv2XYoBqUyc5dqXyz8hpnrdteUU1DtFjOzkDNmXXm7uQ0NQ07t09H FysvlxSobJ0dApAsnMcpI1dEFKsj3kHHGFWw+zM6JwQpB5BN42+7fADFZGQ+xVTflqtf SUJO1/EZzUSbRmnfbT+9YWrJOOHVKRVWki9jGKrryFAAb5o+oYwSsyqNMwOBdmJd5khn YhKg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-16298-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-16298-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 8-20020a630c48000000b005b896ecd1efsi23120411pgm.172.2024.01.03.22.57.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jan 2024 22:57:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-16298-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-16298-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-16298-linux.lists.archive=gmail.com@vger.kernel.org" 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 5C211287D20 for ; Thu, 4 Jan 2024 06:57:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0E7881DDEE; Thu, 4 Jan 2024 06:57:51 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from bmailout1.hostsharing.net (bmailout1.hostsharing.net [83.223.95.100]) (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 ACEC41F94D for ; Thu, 4 Jan 2024 06:57:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=wunner.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=h08.hostsharing.net Received: from h08.hostsharing.net (h08.hostsharing.net [IPv6:2a01:37:1000::53df:5f1c:0]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "*.hostsharing.net", Issuer "RapidSSL TLS RSA CA G1" (verified OK)) by bmailout1.hostsharing.net (Postfix) with ESMTPS id 61C6930000D09; Thu, 4 Jan 2024 07:57:44 +0100 (CET) Received: by h08.hostsharing.net (Postfix, from userid 100393) id 4131E24ADCF; Thu, 4 Jan 2024 07:57:44 +0100 (CET) Date: Thu, 4 Jan 2024 07:57:44 +0100 From: Lukas Wunner To: Peter Zijlstra Cc: Greg Kroah-Hartman , Dan Williams , linux-coco@lists.linux.dev, Andrew Morton , x86@kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 4/5] mm/slab: Add __free() support for kvfree Message-ID: <20240104065744.GA6055@wunner.de> References: <169199898909.1782217.10899362240465838600.stgit@dwillia2-xfh.jf.intel.com> <169199901230.1782217.9803098171993981037.stgit@dwillia2-xfh.jf.intel.com> <2023081449-blurry-bath-248e@gregkh> <20230814161731.GN776869@hirez.programming.kicks-ass.net> 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=us-ascii Content-Disposition: inline In-Reply-To: <20230814161731.GN776869@hirez.programming.kicks-ass.net> User-Agent: Mutt/1.10.1 (2018-07-13) On Mon, Aug 14, 2023 at 06:17:31PM +0200, Peter Zijlstra wrote: > On Mon, Aug 14, 2023 at 05:31:27PM +0200, Greg Kroah-Hartman wrote: > > On Mon, Aug 14, 2023 at 12:43:32AM -0700, Dan Williams wrote: > > > Allow for the declaration of variables that trigger kvfree() when they > > > go out of scope. > > > > > > Cc: Andrew Morton > > > Cc: Peter Zijlstra > > > Cc: Greg Kroah-Hartman > > > Signed-off-by: Dan Williams > > > --- > > > include/linux/slab.h | 2 ++ > > > 1 file changed, 2 insertions(+) > > > > > > diff --git a/include/linux/slab.h b/include/linux/slab.h > > > index 848c7c82ad5a..241025367943 100644 > > > --- a/include/linux/slab.h > > > +++ b/include/linux/slab.h > > > @@ -746,6 +746,8 @@ static inline __alloc_size(1, 2) void *kvcalloc(size_t n, size_t size, gfp_t fla > > > extern void *kvrealloc(const void *p, size_t oldsize, size_t newsize, gfp_t flags) > > > __realloc_size(3); > > > extern void kvfree(const void *addr); > > > +DEFINE_FREE(kvfree, void *, if (_T) kvfree(_T)) > > > > No need to check _T before calling this, right (as was also pointed out > > earlier). > > Well, that does mean you get an unconditional call to kvfree() in the > success case. Linus argued against this. > > This way the compiler sees: > > buf = NULL; > if (buf) > kvfree(buf); > > and goes: 'let me clean that up for you'. And all is well. Have you actually verified that assumption in the generated Assembler code? The kernel is compiled with -fno-delete-null-pointer-checks since commit a3ca86aea507 ("Add '-fno-delete-null-pointer-checks' to gcc CFLAGS"). So NULL pointer checks are *not* optimized away even if the compiler knows that a pointer is NULL. Background story: https://lwn.net/Articles/342330/ Thanks, Lukas