Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp3209110rdg; Tue, 17 Oct 2023 07:47:00 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGDS2r5MKjDqR2f0lZc9ocBPU27M0+/hysZK36dAGVJUNqSZxbIPr7+y8rT2/rnlSHlwsfm X-Received: by 2002:a05:6a21:32a5:b0:15c:b7ba:ea44 with SMTP id yt37-20020a056a2132a500b0015cb7baea44mr2442374pzb.60.1697554020329; Tue, 17 Oct 2023 07:47:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697554020; cv=none; d=google.com; s=arc-20160816; b=JDcK3g//5zpLSGKcM0M3tD49rdv+V9PBfZtbp2Sh9/2Yk6XvXweLcNOANPRIVgqwUE VE78qXLxRcvfp8oGJCS9S+W3cAalOUyCdZ5GbyoItefhGFqs39mHsBKB1NTYuUGm15Y/ qwXoZ7ZCUMQTb+b4N8A48445VicLSqvORe9hTZ1lWu70cVBoDFNpZWfo5IT2/qSEbcYn V+LsbdE4zSHOa/sLYZDxDdhr+SgUeoEhvcjb/YwzY4T54A0p/v+e9b26YpYbEKXlXtLG /DmJ//bjrkOZqcko4t5ahCwb9CXE9JA3pfZkRVE67Lkm8FORYKtxckmfK8cNq3Zuh+TJ hmgQ== 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 :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=hi5scT6l+4iUlT8QRaVBn+dMSlBcJjBBl25IBLpxzAY=; fh=LPGa6B9qxwLmvUOwIto34xRfDS+sCPTbm5VFxqVbjGU=; b=N4nFx6vqOYDVLW90Gc6u0pSR1XzfFvOPptXr4RT3rn6UvHStPJcztNgEtKbrI6RNF3 IhQo2Vo4gH0NpufEFMsae8+VbQQB/ycS+yxmbEIgkKFiqDlNuSJJXS31S+Tee3Mcd1OL YM0la27SxRORRfAGt127VUXiHYlxMOZ5b6xZDbZZE1/Eek5bVb8jCvHoq/1dEsHItQe5 j55bL+IKnQ63mqJH43KOMv9YFrnsT6J04OZ3QiEr4juu8Cr/8MQmV/Vk8VzkJln39Yao 5qxPUq1yLddS+boW54gx+lEmVVi4PQ+VEe40OIUqB9epPJTr0m3upHRV4U9luBdyvCCq gySA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=VivNTLQ8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id pf8-20020a17090b1d8800b0027d60ad5caesi1932901pjb.110.2023.10.17.07.46.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 07:47:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=VivNTLQ8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id E91B3807CF56; Tue, 17 Oct 2023 07:46:57 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343637AbjJQOqu (ORCPT + 99 others); Tue, 17 Oct 2023 10:46:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44968 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235025AbjJQOqt (ORCPT ); Tue, 17 Oct 2023 10:46:49 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3D670F5 for ; Tue, 17 Oct 2023 07:46:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697553963; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hi5scT6l+4iUlT8QRaVBn+dMSlBcJjBBl25IBLpxzAY=; b=VivNTLQ8BPfDhacRzF7REpl8ZSeizF6o+VuHYMmj4nAlNGOetxZjTHK8QEoJrn2bq8nWLE bz/0YHEDxZgzxrYm0WETzkdHKFZ1q2MpSfNVpek+2lYOBIljy7iJwoAYLUzLZCVNsNDeWE ia9zCPbiOhHCOqG6M92LhdFKQ0RqXtY= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-116-l4XMc_exMbGbJd9impZoxg-1; Tue, 17 Oct 2023 10:46:00 -0400 X-MC-Unique: l4XMc_exMbGbJd9impZoxg-1 Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-775d995f92aso753870685a.1 for ; Tue, 17 Oct 2023 07:46:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697553960; x=1698158760; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=hi5scT6l+4iUlT8QRaVBn+dMSlBcJjBBl25IBLpxzAY=; b=I11l/SgljBDt4njFcZE+CUaC21H+QX9rFYWZqtMRVApdis2sXgGPLEHptvEpWnOCCv DCORxZ3hROq3JdVwyOPFUndS+ZMUN4+gNar45ESx/F5HSEylvz5t/ZmVGy9xOwvcyWCw Do4ooG3JqI/QZXF5S1qq1/pHnMmMcNP3QMLkYxCoLJOMXdjecUpIYepITFDHvnog43qZ qMtZQMptqUy7q2/3C0OBD5CNEJ851LEGnmG+4AYWnfIA6Fz9yJ70Mvsga/GzFixlf+EQ 1zZr9+ABB2//4uGyXxMIzQrA0quDh3EWUekMWuv2b5sEQI/K2GLQmmUmmgdhrMjvwXny Kh/g== X-Gm-Message-State: AOJu0Yzy42QHbSN88eE2ockL+1eS+TQbnzapEii98BZHlpCl1WL+dWjr 10xD3ZH5wc5jBP9iF6Shvdb/RmnO48NeQtDeoVulviQFUspjXavsbjXUIRVbXXQlUG7eAEWx9m+ EFH4F7odBYKcjq2zpxKFKR2A= X-Received: by 2002:a05:620a:414b:b0:76f:6c6:f080 with SMTP id k11-20020a05620a414b00b0076f06c6f080mr2687489qko.37.1697553959807; Tue, 17 Oct 2023 07:45:59 -0700 (PDT) X-Received: by 2002:a05:620a:414b:b0:76f:6c6:f080 with SMTP id k11-20020a05620a414b00b0076f06c6f080mr2687466qko.37.1697553959481; Tue, 17 Oct 2023 07:45:59 -0700 (PDT) Received: from [192.168.9.16] (net-2-34-31-107.cust.vodafonedsl.it. [2.34.31.107]) by smtp.gmail.com with ESMTPSA id du19-20020a05620a47d300b007757eddae8bsm708939qkb.62.2023.10.17.07.45.57 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 17 Oct 2023 07:45:59 -0700 (PDT) Message-ID: Date: Tue, 17 Oct 2023 16:45:55 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] kunit: run test suites only after module initialization completes To: Jinjie Ruan Cc: Brendan Higgins , David Gow , Rae Moar , Shuah Khan , linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org References: <20231016203548.21993-1-marpagan@redhat.com> <8f08ef23-bbe1-bebb-eee5-e202c98dbb44@huawei.com> Content-Language: en-US From: Marco Pagani In-Reply-To: <8f08ef23-bbe1-bebb-eee5-e202c98dbb44@huawei.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,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 pete.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 (pete.vger.email [0.0.0.0]); Tue, 17 Oct 2023 07:46:58 -0700 (PDT) On 2023-10-17 03:28, Jinjie Ruan wrote: > > > 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. If kunit_filter_suites() fails in kunit_module_init(), suite_set is initialized to {0, 0}. Hence, kunit_exec_run_tests() will not execute the test suites since num_suites = suite_set->end - suite_set->start equals 0. > But in kunit_module_exit() __kunit_test_suites_exit() will not be executed when > action is NULL if kunit_filter_suites() fails. If kunit_filter_suites() has previously failed in kunit_module_init(),then kunit_module_exit() will return before calling __kunit_test_suites_exit() since suite_set.start has previously been set to 0. > >> >> - 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; >