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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E8F5AC77B7A for ; Tue, 6 Jun 2023 16:06:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232450AbjFFQGo (ORCPT ); Tue, 6 Jun 2023 12:06:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43576 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232466AbjFFQGn (ORCPT ); Tue, 6 Jun 2023 12:06:43 -0400 Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 138B810F0 for ; Tue, 6 Jun 2023 09:06:42 -0700 (PDT) Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-656923b7c81so1807133b3a.1 for ; Tue, 06 Jun 2023 09:06:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1686067601; x=1688659601; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=jXVTDSdMiB3zR+OG3uqHC+1FYr882xcnuexC20tqUf4=; b=OTV/d/3V9GKnT/dcqqO8flI4mpv1dP4tP9CFIaVB6G0rytjsEJgQTuPWtyXzNbNwgS E1Ho9sMMXWiaFpl8kcvxnvxMf0yFUKnQc980CQFmA8t/7Rechuy1hwp09WtJK7iu6/db PBAjm1AWrfoBCxxhEWbn15NVpEo7vUM4fBm5A= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686067601; x=1688659601; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=jXVTDSdMiB3zR+OG3uqHC+1FYr882xcnuexC20tqUf4=; b=P6904U+gPIfr73zUzhvH6w36dJN/YmT99VG+7cLNvXIuutxo5qwkle4PVIsdhBSL1/ EZGzyA4OhD+Mh6q5GiIYruYfZIa+IAM8fK1xAh+Hiq1gnklOa9pGbQCLJvh888f5fgd0 s2ZKLSAetWMbN8zfQST/G7RFSy7Aoh81xXuDHJko/vKtKZ7X0d6x0XLrQ9tExxbwFDYD 8V1BpiYG1LZp6KrvOCqVV7SWaciIaJ5fg40UOChDCtuIaMPrZHjD4TDWat0wfrOFfqNi 5PsNVQkbMdPqy4zx3l7FwqgfUknZZeaxnqGjdmL6JFvhpAtO8zULvIpCoamqqTRuplh0 PJZA== X-Gm-Message-State: AC+VfDxld7+5p3ohrZ9EpGm2X0SXlG2RUxaXIXHDjxJm9pSAInkGa+QD 6YO2W0f5tKOyFT4N11EjIQCxbQ== X-Google-Smtp-Source: ACHHUZ6cYdmDBapnKOceAX0mWmnjv+B38a56qd7Z1gqNRVORPZxwME6q3J5Iovn641WlwRY1BVEmaw== X-Received: by 2002:a05:6a00:1994:b0:643:59ed:5dc9 with SMTP id d20-20020a056a00199400b0064359ed5dc9mr1249055pfl.12.1686067601499; Tue, 06 Jun 2023 09:06:41 -0700 (PDT) Received: from www.outflux.net (198-0-35-241-static.hfc.comcastbusiness.net. [198.0.35.241]) by smtp.gmail.com with ESMTPSA id x42-20020a056a000bea00b0064fd8b3dd10sm7037375pfu.109.2023.06.06.09.06.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jun 2023 09:06:41 -0700 (PDT) Date: Tue, 6 Jun 2023 09:06:40 -0700 From: Kees Cook To: Linus Torvalds Cc: Peter Zijlstra , gregkh@linuxfoundation.org, pbonzini@redhat.com, linux-kernel@vger.kernel.org, ojeda@kernel.org, ndesaulniers@google.com, mingo@redhat.com, will@kernel.org, longman@redhat.com, boqun.feng@gmail.com, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, bristot@redhat.com, vschneid@redhat.com, paulmck@kernel.org, frederic@kernel.org, quic_neeraju@quicinc.com, joel@joelfernandes.org, josh@joshtriplett.org, mathieu.desnoyers@efficios.com, jiangshanlai@gmail.com, rcu@vger.kernel.org, tj@kernel.org, tglx@linutronix.de, linux-toolchains@vger.kernel.org Subject: Re: [PATCH v2 0/2] Lock and Pointer guards Message-ID: <202306060835.51CE77CCC@keescook> References: <20230526205204.861311518@infradead.org> <20230530092342.GA149947@hirez.programming.kicks-ass.net> <20230606094251.GA907347@hirez.programming.kicks-ass.net> <20230606134005.GE905437@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-toolchains@vger.kernel.org On Tue, Jun 06, 2023 at 07:50:47AM -0700, Linus Torvalds wrote: > So you could have something like > > #define RAII(type, var, init, exit) \ > __RAII(type, var, init, exit, __UNIQUE_ID(fn) > > #define __RAII(type, var, init, exit, exitname) \ > void exitname(type *p) { exit } \ > type var __attribute__((__cleanup__(exitname))) = (init) > > and do all of the above with > > RAII(struct fd, fd, fdget(f), fdput(fd)); "fdput(fd)" needs to be "fdput(*p)", since otherwise "fdput(fd)" is referencing "fd" before it has been declared. But regardless, yes, Clang is angry about the nested function. Also, while my toy[1] example doesn't show it, GCC may also generate code that requires an executable stack for some instances (or at least it did historically) that need trampolines. [1] https://godbolt.org/z/WTjx6Gs7x Also, more nits on naming: isn't this more accurately called Scope-based Resource Management (SBRM) not RAII? (RAII is technically object lifetime, and SBRM is scope entry/exit.) -- Kees Cook