Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp547287pxb; Thu, 24 Mar 2022 02:15:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJySnhv/SIaaxxj4iZAbB2DR6Uml4MJDa+tdYqU18JkI8F8tZuYJsYn5CElqK+rlxoRmVGBJ X-Received: by 2002:a17:907:7b86:b0:6e0:5c28:4f5f with SMTP id ne6-20020a1709077b8600b006e05c284f5fmr4437030ejc.675.1648113346290; Thu, 24 Mar 2022 02:15:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648113346; cv=none; d=google.com; s=arc-20160816; b=YJZCz0ShXW5AiQ8hOzhiGX2F/jeBnYR5PIgCPUQ51YnpOGJc56bvWFx6WxI7z2VZJr qsPSIv/prfVCZrn7VMgiaL2HFfswVrEgZFqqRBYUIt0Thv8senGuLQmdL8Mn+ZpPIyAI 17JaWFtcVCqQD0akOQFrMb3zYczQC9J/ZJQH4OZDA9+m/BjWsQ0d55vNPv5U/dso2FgT 5F/QFiUrl89L+7SklBj4+5RSPduOcgtXtUxpPtVZBonPvS0z4P5EGW5Rml4nrQTkPFgM fTag54DS9axfSPxd3FoMZdWFLhfS8mLnkbeUJ+ZvCbyQmrUYZvKShnFz1RLTAfepvFrp x6xQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=zb43V2bxAJ2SXfDM1H+R1ImG/pdyDgKYnKVKfixphNc=; b=BSnYIfQSg4NIEt+E2x3Kg23/uprAp5oazCFzs6GcH7KypsLg0qUWvOhzQsDexdAcAA XJX6d2vyUgpX6PJk5GNORgh+fV1FPABLXshbi38c03peYZvGYvGXtoa0FZFca+jhn1ny wYMjbOsQXsENRvgcsxmQKeJjkzYUTLWGG31iYyHERurD7DKe7uVquuUzRZu16lURHisp cw7Lu7Vy/KbO+Fp8nR7tqfiVVrg3PemSg2kb/ocQq7QyvBO/enHwEo+mhcxJ/PwBr4ZM xOrvobXsgm+7EdO4gxtJjFWztzOugwkezMOOo3/4Xgcp6XffqQaRAkXGMRaMOleW3ytG 6ZKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=lOuUK4cL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s5-20020a17090699c500b006df76385e3asi18904643ejn.730.2022.03.24.02.15.10; Thu, 24 Mar 2022 02:15:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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=pass header.i=@google.com header.s=20210112 header.b=lOuUK4cL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344136AbiCWTWW (ORCPT + 99 others); Wed, 23 Mar 2022 15:22:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42090 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231397AbiCWTWV (ORCPT ); Wed, 23 Mar 2022 15:22:21 -0400 Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [IPv6:2a00:1450:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F3EBD887B1 for ; Wed, 23 Mar 2022 12:20:50 -0700 (PDT) Received: by mail-ej1-x635.google.com with SMTP id qa43so4816536ejc.12 for ; Wed, 23 Mar 2022 12:20:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=zb43V2bxAJ2SXfDM1H+R1ImG/pdyDgKYnKVKfixphNc=; b=lOuUK4cL7xU5D7fHvTqAKQiL1oJNrs4SwK1hRG9/cCbcOQqImp41ziRDXpXiKekQwx +heK6sgT1fSj17OVyCiQV2yaRGzYOiFU6smhslUFR19Yr9X9KYfh5bz9mv570CLA5Wol qKsu2qocf1lbePzG3eOGonFsWFo6QkccOBQuGmDDerWDbztqi8MYV5hTkBL3D/KT1uvd +oNEj3ddAaPn/MJ2jrIWSUX+yVr6cCJ7WxYgxJGRvRbmr/+Y8HGL9FTbW8CUwXz+XDQI cWndUH1IsRLxedvRZWiEOqB7He8W/o/NnORxtJojb4BHckQmtqmo07/eRJ0kn2r4e4Ik N3yA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=zb43V2bxAJ2SXfDM1H+R1ImG/pdyDgKYnKVKfixphNc=; b=PShgFbSLJp51rQmZHT/xYa6jqFpKUuqI2fpClxut8jr6Fhit/831xRQbbviGz+iEOO yqXVhly2zM5kjVUoywpH5MKq2R4fzKvhgW2krKEJByeYkGanDJRB5NKWR4P7qAHDp+Um jgHqZa02ds9w+iqogia5xipetUZiHqpbsIHdGsP/H8y2/6jmUlqF0JlvRSH43Vi7CI4h 0AnIWS1B6cODuzVYQuhh7n0/f9JNWSy0Bc3S3I0Bs59jUdarsLcyIIP6z2bWH7Uf5Zn5 G53DpGHZrVS6NfJMAAt5LeiKQfaDo2Dfw+4XvFKF7cQBXRtAh5iukt6F31esf2AMCfMi emkw== X-Gm-Message-State: AOAM5307ZbnU8myy+mun4iPjPITwGPcbd0SCUxOdsH9P7Qd7jWxJbKkn ip0kx7YnFi2sjPAyo/a6GESkfZDypw2BUCMlfWmvBg== X-Received: by 2002:a17:906:c282:b0:6ce:369d:3d5 with SMTP id r2-20020a170906c28200b006ce369d03d5mr1783232ejz.425.1648063249321; Wed, 23 Mar 2022 12:20:49 -0700 (PDT) MIME-Version: 1.0 References: <20220319055600.3471875-1-davidgow@google.com> In-Reply-To: From: Daniel Latypov Date: Wed, 23 Mar 2022 14:20:37 -0500 Message-ID: Subject: Re: [PATCH] kunit: Rework kunit_resource allocation policy To: Brendan Higgins Cc: David Gow , Shuah Khan , KUnit Development , "open list:KERNEL SELFTEST FRAMEWORK" , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL 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-kernel@vger.kernel.org On Wed, Mar 23, 2022 at 2:22 AM Brendan Higgins wrote: > > > > The latter ~never need to get "found" (e.g. kunit_kmalloc() users). > > The one exception: when people use kunit_kfree() to free things early, > > which requires us to "find" these resources we otherwise wouldn't care > > about. > > > > So I don't know how we can split the API unless we get rid of kunit_kfree(). > > Its presence means kunit_kmalloc() and friends need refcounting. > > Do we need to choose between dropping kunit_kfree() and refcounting? I > think this is semantically different from other findable resources, > and I think it fairly obviously entails the complexity of using it. Yes, they're different. We could do something different and just have a atomic bool "is_freed" for the kunit_kmalloc() style resources. But is it worth it? Currently kunit_kfree() is defined as 697:void kunit_kfree(struct kunit *test, const void *ptr) 698-{ 699- struct kunit_resource *res; 700- 701- res = kunit_find_resource(test, kunit_resource_instance_match, 702- (void *)ptr); 703- 704- /* 705- * Removing the resource from the list of resources drops the 706- * reference count to 1; the final put will trigger the free. 707- */ 708- kunit_remove_resource(test, res); 709- 710- kunit_put_resource(res); 711- 712-} i.e. the overhead of using a refcount is that we need to call kunit_put_resource() bc we called kunit_find_resource(). IMO, this less semantic overhead than adding a different mechanism specifically for kunit_kfree(). Tangent: Huh, it segfaults if you call kunit_kfree() on a non-kunit allocated ptr. res == NULL on 701 in that case, but kunit_remove_resource() doesn't guard against that. It also happens if you call kunit_free() twice. That's analogous to how kfree() works, so I guess that's fine. A difference though is kfree(NULL); // is fine kunit_free(test, NULL); // segfaults, res == NULL above But thinking on it more, someone could register a resource w/ data == NULL. I.e. a named resource which just acts as a flag via presence/absence. kunit_kfree(test, NULL) would the most recent such resource though. Should we do the trick/hack where we check the free function first in kunit_kfree() to avoid such confusion?