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 C320FCE79A9 for ; Tue, 19 Sep 2023 19:35:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232808AbjISTfa (ORCPT ); Tue, 19 Sep 2023 15:35:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44210 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232790AbjISTf2 (ORCPT ); Tue, 19 Sep 2023 15:35:28 -0400 Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 03CCAF0 for ; Tue, 19 Sep 2023 12:35:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=Ya0NjT0hID8cNaHUIIbnzb7CSLwCFD+xdaWNcnIycUY=; b=FdcuBr5TM8FRW/ltzRkEy1H7H9 mPibmiHL/PsA6Q1i+6uQGZwmh0Z2ugC3FKG5OC+Huv+oWT/wMgS1RjOoEr6AyCT0VUv0q+61OlpN0 AKSjWnX8OQYFpSXALWWjSVRKrF3olJOa4ChlEbI5oBI/TqS2hdLL2OL7GI2QQ26GMIx9IVc/x5mNL 7FA8Qrp0ujYigEEwmvmHINTOQ80/3YwNamEFI/dsOQyF2+ohgozO5QkKaVInAzzeS67c7vk7leL2w 9IqDMlrS55zxFWZ+hiZgpllynPhmVPftQyJ7oJECwHkTENOuYHQUdz92CZDmgvRM4LzEPM9U5m0UH phBGdapQ==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1qigV9-00Dqne-15; Tue, 19 Sep 2023 19:35:17 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id 58E3A300348; Tue, 19 Sep 2023 21:35:16 +0200 (CEST) Date: Tue, 19 Sep 2023 21:35:16 +0200 From: Peter Zijlstra To: Linus Torvalds Cc: Bartosz Golaszewski , Alexey Dobriyan , linux-kernel@vger.kernel.org, Linus Walleij , akpm@linux-foundation.org Subject: Re: Buggy __free(kfree) usage pattern already in tree Message-ID: <20230919193516.GA20937@noisy.programming.kicks-ass.net> References: <20230915210851.GA23174@noisy.programming.kicks-ass.net> <20230915213231.GB23174@noisy.programming.kicks-ass.net> <20230915221332.GC23174@noisy.programming.kicks-ass.net> <20230919125752.GA39346@noisy.programming.kicks-ass.net> <20230919125954.GB39346@noisy.programming.kicks-ass.net> <20230919131038.GC39346@noisy.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230919131038.GC39346@noisy.programming.kicks-ass.net> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Sep 19, 2023 at 03:10:38PM +0200, Peter Zijlstra wrote: > This isn't exactly nice.. > > I tried something like: > > scoped_cond_guard (mutex_intr, return -EINTR, &task->signal->cred_guard_mutex) { > ... > } > > Which I can make work, but then I also tried to capture my other case: > > scoped_cond_guard (rwsem_down_intr, if (task) return -EINTR, > task ? &task->signal->exec_guard_mutex : NULL) { > > ... > } > > But I can't get that to work because of that extra if, the not case > doesn't fall through and do the body. > > Anyway, I'll poke more.. #define scoped_cond_guard(_name, _label, args...) \ for (CLASS(_name, scope)(args), \ *done = NULL; !done; done = (void *)1) \ if (!__guard_ptr(_name)(&scope)) goto _label; \ else Allows one to write: scoped_cond_guard (rwsem_down_intr, no_lock, task ? &task->signal->exec_guard_mutex : NULL) { if (0) { no_lock: if (task) return -EINTR; } ... block that holds exec_guard_mutex if task ... } Still not exactly pretty, but perhaps better than before...