Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp1638626rdh; Mon, 25 Sep 2023 21:19:30 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGR9fkd7h/TpuKd8sLGz11R+XjMuIw+1jmAWvOnd97sFrcFgT8HuyeEvRPZXLP22Z6XJz3S X-Received: by 2002:a17:90a:890a:b0:267:fb26:32bd with SMTP id u10-20020a17090a890a00b00267fb2632bdmr7128916pjn.7.1695701970399; Mon, 25 Sep 2023 21:19:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695701970; cv=none; d=google.com; s=arc-20160816; b=REu2wNJrhowMuss/3KxJ+hdcvmYi0YXZZ4zrZsfluJtLWtDJj14NOrtidztpQe5qm6 sdsBtBkbUHlw6LG2TyvTSrMXBcPe7P+yzi3vozkpZgPlnj9SL1pTiEHZ/tshW9aQLiXA 0T8TNk/InC623UDydEaJyNm5PJjOdkM9fPZ9LDaTDHtNm2cbvobZmbQyP2ikaM4KglEL AMb1pvfTxjQiWtLDHRDDCi0Q67qwh5H2ZGUqcpeaT20Q+BVn3n8r5VE4H73QRn9cOuj2 PXZS4oDjpmGVxLnkFpjdJMs08OTYNRP4TXj2peZ2+54LRU+Qjt1aJguPcSX+3YMcC8Qw YVVQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:cc:to:from :subject:dkim-signature; bh=llOYuKpCGiFQykK3KHvx+udZobEsTzG8G8vb/AeL730=; fh=RrijT3tJL98V46dhGYxkE0am/XK+EBz9F1RrcTmm9Pc=; b=Rl3hVQJau8MSUkU2RNudc+sH4unjOR9pIFzryB3GqFk+c/wttjaazPmBLmlxSPs8g0 EIHuInuZRwb6TaG5IKr2OjtQ2KB4yh61hte0t82LDmbRk2DIu3T9jvIvM93xTS+M/Ojh F7Br6uM/cNi8nLXPoKcZvDtqIt/8fAHzDHmWojvJOvfPOtRzUqha3MRG67kHaUcqW0Xz eNcGc5SBqn4Gv8OZpT/Wjew1KhvM0Tcl4zu5SmQWPhfUz9P/V0seK646xMfSQkAoXkww J99KnNmTLdS8xQAm3PjaMUlE2cyiAL7XN/FgVSVfVLFP4uckhsK7attaj1CHTEjGm/TV KoAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=V8D8lo5+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id t5-20020a170902e1c500b001c60de17b50si5015952pla.182.2023.09.25.21.19.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 21:19:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=V8D8lo5+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id DE4AF8251725; Mon, 25 Sep 2023 21:18:05 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233662AbjIZERl (ORCPT + 99 others); Tue, 26 Sep 2023 00:17:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44652 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233633AbjIZERf (ORCPT ); Tue, 26 Sep 2023 00:17:35 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8E93012A for ; Mon, 25 Sep 2023 21:17:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695701843; x=1727237843; h=subject:from:to:cc:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=bDADOCK5y6EfdtJCioVa1Ksl06xw+gGHZUtfoSD5ALE=; b=V8D8lo5+1HG8X0EJ8TY7l4O2f2Ut1XoMIqARpvbUOonps/MGt51nPAFA ZWSI4/Sr8gZUeUuEzAMKsomMB/8SmaL5Y9iYcNBCqfgAhC1DwfvIeiLRK WE3Iy0IfgTwMnRKam6gHynFinm5i6EskerAty+aj/g2QSFz8cHfjLDJgG E7HSy6nDY9eTPhW50u8ROf1Ww+yrH3obyvrWEfVVhQoYf3yQDAkDLJ7jy 60ilYo5SbCuYral0ynHUL4wrIYoZ90qtr81UL+zphxvuVkYcH3tNeYlMN wRwjAPz00jeerQm7wPZkNO8kIOBVuNX/i3bOfscL/5h+KNCBq1C8R+5qu g==; X-IronPort-AV: E=McAfee;i="6600,9927,10843"; a="412395854" X-IronPort-AV: E=Sophos;i="6.03,177,1694761200"; d="scan'208";a="412395854" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Sep 2023 21:17:23 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10843"; a="814314534" X-IronPort-AV: E=Sophos;i="6.03,177,1694761200"; d="scan'208";a="814314534" Received: from fvivekku-mobl.amr.corp.intel.com (HELO dwillia2-xfh.jf.intel.com) ([10.251.18.72]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Sep 2023 21:17:22 -0700 Subject: [PATCH v4 4/6] mm/slab: Add __free() support for kvfree From: Dan Williams To: linux-coco@lists.linux.dev Cc: Andrew Morton , Peter Zijlstra , Greg Kroah-Hartman , Pankaj Gupta , Greg Kroah-Hartman , linux-kernel@vger.kernel.org, x86@kernel.org, dave.hansen@linux.intel.com Date: Mon, 25 Sep 2023 21:17:22 -0700 Message-ID: <169570184210.596431.3407746911924957078.stgit@dwillia2-xfh.jf.intel.com> In-Reply-To: <169570181657.596431.6178773442587231200.stgit@dwillia2-xfh.jf.intel.com> References: <169570181657.596431.6178773442587231200.stgit@dwillia2-xfh.jf.intel.com> User-Agent: StGit/0.18-3-g996c MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Mon, 25 Sep 2023 21:18:06 -0700 (PDT) Allow for the declaration of variables that trigger kvfree() when they go out of scope. The check for NULL and call to kvfree() can be elided by the compiler in most cases, otherwise without the NULL check an unnecessary call to kvfree() may be emitted. Peter proposed a comment for this detail [1]. Link: http://lore.kernel.org/r/20230816103102.GF980931@hirez.programming.kicks-ass.net [1] Cc: Andrew Morton Cc: Peter Zijlstra Cc: Greg Kroah-Hartman Acked-by: Pankaj Gupta Acked-by: 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 8228d1276a2f..df4c2d45bb86 100644 --- a/include/linux/slab.h +++ b/include/linux/slab.h @@ -763,6 +763,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)) + extern void kvfree_sensitive(const void *addr, size_t len); unsigned int kmem_cache_size(struct kmem_cache *s);