Received: by 2002:a05:7412:b130:b0:e2:908c:2ebd with SMTP id az48csp1089630rdb; Sat, 18 Nov 2023 02:41:57 -0800 (PST) X-Google-Smtp-Source: AGHT+IHdC9rMNh+L0ZnI6yf8aqJVGXbgGOf/liZ5OHoFY+ms6mXesXIcppXGip+HeeoubKhPDvgz X-Received: by 2002:a81:4e46:0:b0:5bf:5741:517f with SMTP id c67-20020a814e46000000b005bf5741517fmr2558369ywb.22.1700304117200; Sat, 18 Nov 2023 02:41:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700304117; cv=none; d=google.com; s=arc-20160816; b=nrnjUQ9a7j4Mz/B/mg03prM/r4RwkPEltuWVBZai76bXPqwgQKKsy6RNzrGndB2ot3 UsxVHoQXBLzKPaLWZtAnu5m7dNOdZC3vLfrthv9PJsTR2GfNRT2TdLqDl4WHGnogadQS gtzbqh5L1Su2J6Lvvl5XafBUo5U+14OlTdua8GV5TWgUH9ymLqVke+HHIIwS2FvMiz4d qCW7/QZr70pZs3oR6todz+wcR/8ZAJofbHyEwseBOcJHdiXaScVWziwjetWowQYYqV+q zgETonN7bTTu6QeCw2CsGX++xENLJIEIZuCe+HzkzPCh9u+VwbpSuEyEZYgKKoxaz1o2 iEaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:to:from; bh=c8RU4+4enPOty60L0e8x8N8kzJouTJ+DOw6/gBsM2eQ=; fh=cKgRupAwAqvDHHS6VAzGoPs3pyLdUCOVkk/Q20cDUOo=; b=KiSl2GJbpMM4adkccLLOu3j+buOYf9M67zHTmYIJ9zhGueD1YVGCkoIGwfi+/yoxFm MU3Cz/WJixA/UnCdMN5HjzxnZavR/KLuse5rusCDFqBRPbvFh7CkNSWzKKxJFciou+vi PjyxKlWKfB+atfgCSPYZYKClaeQt3SxLQXrw+L59SAw/0DFlEKXtqf0NAZtbljygbnf9 SkJjda2U1usIa7YmLSktFd+blcYzbkPoZ/hQRLP/TCvBGo1d9IVTiWPprZSPrbKOQ+O2 4lax9LME5rrjY8GDZJL9ohwFrmX8Os6d55cEWY5I20a6Il8l4nhOikNdrmjbZDyIGZls iLNg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id 9-20020a630b09000000b005ad11a5ac8fsi4078257pgl.323.2023.11.18.02.41.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Nov 2023 02:41:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 90C5C804C6FC; Sat, 18 Nov 2023 02:41:55 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232920AbjKRKls (ORCPT + 99 others); Sat, 18 Nov 2023 05:41:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229515AbjKRKlm (ORCPT ); Sat, 18 Nov 2023 05:41:42 -0500 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4185510D0; Sat, 18 Nov 2023 02:41:38 -0800 (PST) Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4SXVgb3bkfz4f3lfh; Sat, 18 Nov 2023 18:41:31 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 9BC8C1A0176; Sat, 18 Nov 2023 18:41:35 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.101.107]) by APP1 (Coremail) with SMTP id cCh0CgDn6hDQlFhlQPAFBQ--.58135S9; Sat, 18 Nov 2023 18:41:35 +0800 (CST) From: Zhang Xiaoxu To: zhangxiaoxu5@huawei.com, weiyongjun1@huawei.com, linux-kernel@vger.kernel.org, broonie@kernel.org, rostedt@goodmis.org, mingo@redhat.com, frowand.list@gmail.com, linux-spi@vger.kernel.org Subject: [PATCH -next 05/14] kddv/core: Support kernel memory leak detector Date: Sat, 18 Nov 2023 18:40:31 +0800 Message-Id: <20231118104040.386381-6-zhangxiaoxu@huaweicloud.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231118104040.386381-1-zhangxiaoxu@huaweicloud.com> References: <20231118104040.386381-1-zhangxiaoxu@huaweicloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: cCh0CgDn6hDQlFhlQPAFBQ--.58135S9 X-Coremail-Antispam: 1UD129KBjvJXoWxAw4kCry3tr43tFW8Cr48JFb_yoW5XF1xpa n5Kr1agF17uF13Krs3tF1UWFWF9rs7GF48tF97Jw45Wry3JFyYyr43t3W2vFyfW3s5t393 A3y0gr42krWUJaDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUvEb4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUAV Cq3wA2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0 rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVW7JVWDJwA2z4x0Y4vE2Ix0cI8IcVCY1x0267 AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E 14v26rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7 xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Y z7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7 v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF 1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_JFI_Gr1lIx AIcVC0I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI 42IY6I8E87Iv67AKxVW8JVWxJwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWI evJa73UjIFyTuYvjxUFgAwUUUUU X-CM-SenderInfo: x2kd0wp0ld053x6k3tpzhluzxrxghudrp/ X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Sat, 18 Nov 2023 02:41:55 -0800 (PST) From: Zhang Xiaoxu Check the kmemleak before return from test case, fail the test case if a kmemleak is detected. Signed-off-by: Wei Yongjun Signed-off-by: Zhang Xiaoxu --- tools/testing/kddv/kddv/core/environ.py | 13 ++++++++- tools/testing/kddv/kddv/core/memleak.py | 39 +++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100755 tools/testing/kddv/kddv/core/memleak.py diff --git a/tools/testing/kddv/kddv/core/environ.py b/tools/testing/kddv/kddv/core/environ.py index d57e33a6ac6e..68c98e8c44da 100755 --- a/tools/testing/kddv/kddv/core/environ.py +++ b/tools/testing/kddv/kddv/core/environ.py @@ -9,20 +9,31 @@ import logging from .dmesg import KernelMessage +from .memleak import Kmemleak logger = logging.getLogger(__name__) class Environ(object): def __init__(self): self.kmsg = KernelMessage() + self.leak = Kmemleak() def setup(self): self.kmsg.setup() + self.leak.setup() def teardown(self): + self.leak.teardown() self.kmsg.teardown() + def enable_kmemleak(self): + """Enable Kernel memory leak detector""" + self.leak.enabled = True + def check_failure(self): - return self.kmsg.check_failure() + msg = self.kmsg.check_failure() + if msg: + return msg + return self.leak.check_failure() environ = Environ() diff --git a/tools/testing/kddv/kddv/core/memleak.py b/tools/testing/kddv/kddv/core/memleak.py new file mode 100755 index 000000000000..7ff67997560f --- /dev/null +++ b/tools/testing/kddv/kddv/core/memleak.py @@ -0,0 +1,39 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0 +# +# Kernel device driver verification +# +# Copyright (C) 2022-2023 Huawei Technologies Co., Ltd +# Author: Wei Yongjun + +import os +import logging +import pathlib + +KMEMLEAK = '/sys/kernel/debug/kmemleak' + +logger = logging.getLogger(__name__) + +class Kmemleak(object): + def __init__(self): + self.has_feature = os.path.exists(KMEMLEAK) + self.ctrl = pathlib.Path(KMEMLEAK) + self.enabled = False + + def setup(self): + if not self.has_feature or not self.enabled: + return + self.ctrl.write_text('clear') + + def teardown(self): + if not self.has_feature or not self.enabled: + return + self.ctrl.write_text('clear') + + def check_failure(self): + if not self.has_feature or not self.enabled: + return None + logger.debug('check kernel memleak') + self.ctrl.write_text('scan') + self.ctrl.write_text('scan') + return self.ctrl.read_text().rstrip() -- 2.34.1