Received: by 2002:ac0:e34a:0:0:0:0:0 with SMTP id g10csp330167imn; Thu, 28 Jul 2022 01:48:56 -0700 (PDT) X-Google-Smtp-Source: AGRyM1s8lPVMD4t7MuMgW4EwhauXFuBT/dBP6m1nsT6H0RlvE7U8GVBKZFD2rKEC2CPwmvUc0eHa X-Received: by 2002:a17:906:cc13:b0:72b:31d5:a899 with SMTP id ml19-20020a170906cc1300b0072b31d5a899mr20403960ejb.184.1658998135885; Thu, 28 Jul 2022 01:48:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658998135; cv=none; d=google.com; s=arc-20160816; b=dKWBpjVYH7/Lcy8KNp1tY5xYcKqeqwjB2IOnMMORO+1UlBqvge5QUPjuH6+5WBmLHL DOLv2bwptmGEw1xgcNsxOPnRGlUJDY9erS+vsXl+MVBH83YzMlERFrpvuYR3iGbia07N 10d+sCDt+3urrc+NuzyhIryPEOMjZT/4szjzl3RHaFu3xsxitgBTR5uBj2D+iO3rb6SD jLf6d2DZZyhksrBwwE4Ih9gvP/8PXUZcX/l5CZjRckDBjyuszuZpoZJZMbr1xZcrEG/O oO+xav6GVBij/Y5SoFOVbz6nye5hmy/jUONEtmAfH49ENXGpBnuP12a/Lk47oGAY7ptI QmCQ== 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=L69tTE2sH+PMx280GbvtDkw3gNuAyH0o9/0HeA0+XoA=; b=RQwPvjhCZHTFO4DjI6AxL3hm1kfQtS7S7WerI042yXci/8OmD2ShCYsy9BM1iQnT2O vC+8R15ebeOqJGkvOyAwwubn86R39WNItZgdBnNGPVVmdey+XxLSRH54s7upePq0Cgp6 ZMPK1ROcv5JSahme5sra1eRpPqyZW3T43n0DeDnw+OE/1P1I5RXtvYGRcn6chURlrzdo 3VPxWyHaOD9uSGcqh7fkuPo1NVhjGoeNamHf3htfZZRKGG24Q8cIAl1V2tuCO/FftAeg AnbpbxUrJy1gG9cGjXFE3I1KiJIizzv7M9tEMW4CY46dMpTE3PT7e+IkgrR4yeKdefqY RDaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="j/c5UpIF"; 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 ho33-20020a1709070ea100b00722e6c16c85si261727ejc.969.2022.07.28.01.48.31; Thu, 28 Jul 2022 01:48:55 -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="j/c5UpIF"; 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 S234819AbiG1Imb (ORCPT + 99 others); Thu, 28 Jul 2022 04:42:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52806 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234631AbiG1Im3 (ORCPT ); Thu, 28 Jul 2022 04:42:29 -0400 Received: from mail-vs1-xe36.google.com (mail-vs1-xe36.google.com [IPv6:2607:f8b0:4864:20::e36]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD12262A60 for ; Thu, 28 Jul 2022 01:42:28 -0700 (PDT) Received: by mail-vs1-xe36.google.com with SMTP id t28so977384vsr.11 for ; Thu, 28 Jul 2022 01:42:28 -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=L69tTE2sH+PMx280GbvtDkw3gNuAyH0o9/0HeA0+XoA=; b=j/c5UpIF73D7K3bcNVXSTIOMPDPw1ZZIwrFEIHGEmQ2hfCs63+1CtBLnwvtBjNcHIT W/R6yLZZlLhLjUBi0wstREns8Vn6JQNPqmYAJoK9jU3jJhhuXZT5P6P3Jeup5fcHa4mm xSzvcnkeWa1v1ggGp791wpOThlGf35ucdfr8bqJeQcUKz1speVD2qtWFDYGJ41Ay1DXH lNSj+PW0I4YOKeH0heh12zUvSg+cR3/8+X0U1mVkoRbdHUX+hyX6j1g/CymkL0M17yOF b4ePaT4/tswlLBf3LDopM8gfJZvgN9qdMbwbrN2ql7ZWxQW7rhlmpQLBfC8Y7Q/ynbfR 3d8g== 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=L69tTE2sH+PMx280GbvtDkw3gNuAyH0o9/0HeA0+XoA=; b=78FOPjYoTx0LiEoeQsRyAigQ/XkXnfNCGr0am7tBTUGDxGpxEqUY16qL4WbW92y2Sh hZWeeIaPf9VqvwmHBUyzKfh2Keqc0OJXH7vCDJ1gyuZ6OcfevWvs1nMHF7CcMSE5fIly pHqp6NljnINK/7LbWNcU50T9PJ+YuhfMrUPODAP4VbA5PoxywG7e099G3ZbRMFi6zvRI rlzLaIRGHwS6g2kZNmOoWAhjXIKbr24s3xqcuXfS0LNhTXzL4PflKJOJ53lOBD3gxSHp TqIutCGFnGEIJvofMBnd9iPzM0Q1Fok3GEVgIOAm+u+4wTwm+hwf1xeUaaxu+H4bKOaO GGFQ== X-Gm-Message-State: AJIora+wjrjLvc6w9lHO1r6KEMqB0o7IuwoLihmAXpd23gb2gGcc1vxx +nqxl63+DA/9EbmvosJSgbbufZoanww437J0BwaDpg== X-Received: by 2002:a67:c191:0:b0:358:5ca6:f98d with SMTP id h17-20020a67c191000000b003585ca6f98dmr6818737vsj.71.1658997747795; Thu, 28 Jul 2022 01:42:27 -0700 (PDT) MIME-Version: 1.0 References: <20220713005221.1926290-1-davidgow@google.com> In-Reply-To: From: David Gow Date: Thu, 28 Jul 2022 16:42:16 +0800 Message-ID: Subject: Re: [PATCH] module: kunit: Load .kunit_test_suites section when CONFIG_KUNIT=m To: Luis Chamberlain Cc: Daniel Latypov , Brendan Higgins , Shuah Khan , Jeremy Kerr , linux-modules@vger.kernel.org, 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, 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 Thu, Jul 21, 2022 at 4:29 AM Luis Chamberlain wrote: > > On Wed, Jul 20, 2022 at 05:26:02PM +0800, David Gow wrote: > > On Wed, Jul 20, 2022 at 1:58 AM Luis Chamberlain wrote: > > > > > > On Wed, Jul 13, 2022 at 08:24:32AM -0700, Daniel Latypov wrote: > > > > On Tue, Jul 12, 2022 at 5:52 PM David Gow wrote: > > > > > > > > > > The new KUnit module handling has KUnit test suites listed in a > > > > > .kunit_test_suites section of each module. This should be loaded when > > > > > the module is, but at the moment this only happens if KUnit is built-in. > > > > > > > > > > Also load this when KUnit is enabled as a module: it'll not be usable > > > > > unless KUnit is loaded, but such modules are likely to depend on KUnit > > > > > anyway, so it's unlikely to ever be loaded needlessly. > > > > > > > > This seems reasonable to me. > > > > > > > > Question: what happens in this case? > > > > 1. insmod > > > > 2. insmod kunit > > > > 3. rmmod > > > > > > > > I think on 3, we'll call the cleanup code, __kunit_test_suites_exit(), > > > > for , I think? > > > > But we never called __kunit_test_suites_init(). > > > > My fear is what breaks as a result of this precondition break. > > > > I don't think this should be possible: any module with KUnit tests > > will depend on the 'kunit' module (or, at least, kunit symbols), so > > shouldn't load without kunit already present. > > > > If modprobe is used, kunit will automatically be loaded. If insmod is > > used directly, loading the first module should error out with > > something like: > > [ 82.393629] list_test: loading test module taints kernel. > > [ 82.409607] list_test: Unknown symbol kunit_binary_ptr_assert_format (err -2) > > [ 82.409657] list_test: Unknown symbol kunit_do_failed_assertion (err -2) > > [ 82.409799] list_test: Unknown symbol kunit_binary_assert_format (err -2) > > [ 82.409820] list_test: Unknown symbol kunit_unary_assert_format (err -2) > > insmod: ERROR: could not insert module > > /lib/modules/5.19.0-rc1-15284-g9ec67db0c271/kernel/lib/list-test.ko: > > Unknown symbol in module > > This can be fixed with a request_module() call. And since this is a > generic requirement, you can have the wrappers do it for you. > I'm not convinced that this is worth the trouble, particularly since KUnit needs to be loaded already before any test-specific code in a module is run. _Maybe_ we could put it in the code which looks for the .kunit_test_suites section, but even then it seems like a bit of an ugly hack. Personally, I'm not particularly concerned about test modules failing to load if KUnit isn't already present -- if people want all of a module's dependencies loaded, that's what modprobe is for. That being said, if you feel particularly strongly about it, this is something we can look at. Let's do so in a separate patch though: this one does fix a regression as-is. > > Maybe you could get into some trouble by force-removing modules at > > various points, but you're in undefined behaviour generally at that > > point, so I don't think there's much point going out-of-our-way to try > > to support that. > > You can prevent that by refcounting the kunit module / symbols, by each test. > Again, I don't think KUnit is any more special than any other module here. I don't think we need to do this ourselves, as it shouldn't be possible to remove kunit without first removing any dependent modules. Of course, happy to look into this again if anyone can come up with an actual crash, but I'd rather get this fix in first. At the very least, this patch shouldn't introduce any _new_ issues. Cheers, -- David > Luis