Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp2864416rdg; Mon, 16 Oct 2023 18:28:18 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGKXQMzxfbhPa/6tdhp24wsjFCgnKXmU+qopzaIyX1hf/D1KDhBhDxP+K+pXhemvelv1RIt X-Received: by 2002:a67:e044:0:b0:455:c426:1b22 with SMTP id n4-20020a67e044000000b00455c4261b22mr936960vsl.16.1697506098558; Mon, 16 Oct 2023 18:28:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697506098; cv=none; d=google.com; s=arc-20160816; b=FU+MFgguoj5pXOZmqHLBlyVFNEB6UQLHA4itihGs5PK9smcfeIMaxtagv5PDgN7FQW b+NjJmh/c7omB98E5vQBG+U3n+AeMjUoy4XKGtrDM9oD+d5fYYQikWYjLf6E8hVwUVtu 7zbtgi3pw0kxvvzn0rW7MAmtl9zxOMIm9H7R53Bhcs7gz4bQrzd8G117CPzTlyEzTieg Pk29UV2iYuvoRk+oHTfYjpHcLHKEivFzY4WHW0nJDB9t4xZkhHN6h6ybf2mW93gw8NjY AiUL6D+RoZeOHylnWAGDbGdnr6Rh2Kay+slfs30FViu3PgjWIfSaB6IKlGc8JHaJSgRy jHvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=MikJOUOvNew9m9qAfgEPGGJRaD3/g5R99aEH/31UNdM=; fh=O+9kBcLPL1pO8i3s+ipmh8iS/OO4nMjm96XgdLiQD3o=; b=NJGmDzrCURpEbALRRKGtC4/oBq6e0KgpRx2jT/lDhOF6qJywTZLSqmW9ILWnuaBEJq pQXoJZh/o0QnqauuWDHL85CZaUCj4Xg6R/HOVjxDMiLbGsgikUps5sSp48uZkUcrrxUJ WLo0Rdrmc8JBFOVXZ9VqB4E/R0l8R5IFoo/S+7iV/L9xLX7Lw/1au4JELSmNqZcJz3ln T0mK4uKowFdaMjAMbR9TlD1qxjHlh222zpVaVnD2o/CJ+1xgJU3usmr5W87ZaXrHsU7A SU0jE+KSMBC0xKnsz0PgiU4bWxX5uaJcApFzLfz3jKb52r467R1sg4XKD/QbGWfqIBxe qgFg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id i2-20020a63b302000000b00589884fef91si590807pgf.740.2023.10.16.18.28.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 18:28:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 451888042840; Mon, 16 Oct 2023 18:28:16 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233330AbjJQB2J (ORCPT + 99 others); Mon, 16 Oct 2023 21:28:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52314 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231955AbjJQB2J (ORCPT ); Mon, 16 Oct 2023 21:28:09 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3661A9B; Mon, 16 Oct 2023 18:28:07 -0700 (PDT) Received: from kwepemi500008.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4S8bqV47KFzVlCL; Tue, 17 Oct 2023 09:24:22 +0800 (CST) Received: from [10.67.109.254] (10.67.109.254) by kwepemi500008.china.huawei.com (7.221.188.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Tue, 17 Oct 2023 09:28:00 +0800 Message-ID: <8f08ef23-bbe1-bebb-eee5-e202c98dbb44@huawei.com> Date: Tue, 17 Oct 2023 09:28:00 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.2.0 Subject: Re: [PATCH] kunit: run test suites only after module initialization completes Content-Language: en-US To: Marco Pagani , Brendan Higgins , David Gow , Rae Moar , Shuah Khan CC: , , References: <20231016203548.21993-1-marpagan@redhat.com> From: Jinjie Ruan In-Reply-To: <20231016203548.21993-1-marpagan@redhat.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.67.109.254] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemi500008.china.huawei.com (7.221.188.139) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.1 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,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 howler.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 (howler.vger.email [0.0.0.0]); Mon, 16 Oct 2023 18:28:16 -0700 (PDT) On 2023/10/17 4:35, Marco Pagani wrote: > Commit 2810c1e99867 ("kunit: Fix wild-memory-access bug in > kunit_free_suite_set()") is causing all test suites to run (when > built as modules) while still in MODULE_STATE_COMING. In that state, > test modules are not fully initialized and lack sysfs kobjects. > This behavior can cause a crash if the test module tries to register > fake devices. > > This patch restores the normal execution flow, waiting for the module > initialization to complete before running the test suites. > The issue reported in the commit mentioned above is addressed using > virt_addr_valid() to detect if the module loading has failed > and mod->kunit_suites has not been allocated using kmalloc_array(). > > Fixes: 2810c1e99867 ("kunit: Fix wild-memory-access bug in kunit_free_suite_set()") > Signed-off-by: Marco Pagani > --- > lib/kunit/test.c | 8 +++++--- > 1 file changed, 5 insertions(+), 3 deletions(-) > > diff --git a/lib/kunit/test.c b/lib/kunit/test.c > index 421f13981412..1a49569186fc 100644 > --- a/lib/kunit/test.c > +++ b/lib/kunit/test.c > @@ -769,12 +769,14 @@ static void kunit_module_exit(struct module *mod) > }; > const char *action = kunit_action(); > > + if (!suite_set.start || !virt_addr_valid(suite_set.start)) > + return; > + > if (!action) > __kunit_test_suites_exit(mod->kunit_suites, > mod->num_kunit_suites); If the module state is from MODULE_STATE_LIVE to MODULE_STATE_GOING, in kunit_module_init() the kunit_exec_run_tests() is executed when action is NULL whether kunit_filter_suites() succeeds or not. But in kunit_module_exit() __kunit_test_suites_exit() will not be executed when action is NULL if kunit_filter_suites() fails. > > - if (suite_set.start) > - kunit_free_suite_set(suite_set); > + kunit_free_suite_set(suite_set); > } > > static int kunit_module_notify(struct notifier_block *nb, unsigned long val, > @@ -784,12 +786,12 @@ static int kunit_module_notify(struct notifier_block *nb, unsigned long val, > > switch (val) { > case MODULE_STATE_LIVE: > + kunit_module_init(mod); > break; > case MODULE_STATE_GOING: > kunit_module_exit(mod); > break; > case MODULE_STATE_COMING: > - kunit_module_init(mod); > break; > case MODULE_STATE_UNFORMED: > break;