From patchwork Tue Jan 29 16:17:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 10786575 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0C3D71390 for ; Tue, 29 Jan 2019 16:17:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EED712D08D for ; Tue, 29 Jan 2019 16:17:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E2E2C2D320; Tue, 29 Jan 2019 16:17:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7CE7F2D2DB for ; Tue, 29 Jan 2019 16:17:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726913AbfA2QRa (ORCPT ); Tue, 29 Jan 2019 11:17:30 -0500 Received: from userp2120.oracle.com ([156.151.31.85]:43620 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727032AbfA2QRa (ORCPT ); Tue, 29 Jan 2019 11:17:30 -0500 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id x0TGEVY7010256; Tue, 29 Jan 2019 16:17:27 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=subject : from : to : cc : date : message-id : in-reply-to : references : mime-version : content-type : content-transfer-encoding; s=corp-2018-07-02; bh=dMC6y4reyBxcrzWE1x9mixh6QKz0rL+KfJ7/qqHXoZk=; b=2rX1kyFnS03N6CvChG74a7nDJGxad+bAQt6g4ONERWALjhBUfw/2ZOxw2ES2EBt33WV+ /kDOdH0mCV8Bjh1LUnufa4CstLjasvUI3yqt5NDXgQA1ExzeEQVc+gnIRGJagPm4NW4i KlORF1zbCy+XteHar3gyoqkFLWe0kfFWWeDqEvTq7RrHQKjNSf0JfsT9bXMimUvwlGXk itSMLrixHV3+/2zTxKBXRTgnkUBGLv6A2CTGHdsc+Jz87sXwHP9ZqsyB2gg9D/NXpBFK idn3rH6NPRJbJe6aCqsNEno9JINjqQAgi8clLr5fIOka79jwDIOiNmht0V8IuMbgIFV8 Ag== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp2120.oracle.com with ESMTP id 2q8g6r5bag-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 29 Jan 2019 16:17:27 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id x0TGHRUl021874 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 29 Jan 2019 16:17:27 GMT Received: from abhmp0010.oracle.com (abhmp0010.oracle.com [141.146.116.16]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x0TGHQLo009829; Tue, 29 Jan 2019 16:17:26 GMT Received: from localhost (/67.169.218.210) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 29 Jan 2019 08:17:26 -0800 Subject: [PATCH 3/4] common: fix kmemleak to work with sections From: "Darrick J. Wong" To: guaneryu@gmail.com, darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org, fstests@vger.kernel.org Date: Tue, 29 Jan 2019 08:17:25 -0800 Message-ID: <154877864538.9277.6249607598508212314.stgit@magnolia> In-Reply-To: <154877863279.9277.4463697450629081138.stgit@magnolia> References: <154877863279.9277.4463697450629081138.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9150 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=682 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1901290122 Sender: fstests-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Darrick J. Wong Refactor the kmemleak code to work correctly with sections. This requires changing the report location to use RESULT_DIR instead of RESULT_BASE, and clarifying which functions get used when. Signed-off-by: Darrick J. Wong --- check | 4 ++-- common/rc | 32 ++++++++++++++++++++++---------- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/check b/check index c0eee0aa..b9eb86cb 100755 --- a/check +++ b/check @@ -509,7 +509,7 @@ _expunge_test() return 0 } -_init_kmemleak +_detect_kmemleak _prepare_test_list if $OPTIONS_HAVE_SECTIONS; then @@ -793,8 +793,8 @@ for section in $HOST_OPTIONS_SECTIONS; do # and log messages that shouldn't be there. _check_filesystems _check_dmesg || err=true - _check_kmemleak || err=true fi + _check_kmemleak || err=true # test ends after all checks are done. $timestamp && _timestamp diff --git a/common/rc b/common/rc index 19e947df..75771f31 100644 --- a/common/rc +++ b/common/rc @@ -3514,7 +3514,7 @@ _check_dmesg() # capture the kmemleak report _capture_kmemleak() { - local kern_knob="${DEBUGFS_MNT}/kmemleak" + local kern_knob="$DEBUGFS_MNT/kmemleak" local leak_file="$1" # Tell the kernel to scan for memory leaks. Apparently the write @@ -3535,17 +3535,20 @@ ENDL echo "clear" > "$kern_knob" } -# set up kmemleak -_init_kmemleak() +# Figure out if the running kernel supports kmemleak; if it does, clear out +# anything that leaked before we even started testing. The leak checker only +# needs to be primed like this once per ./check invocation. +_detect_kmemleak() { - local kern_knob="${DEBUGFS_MNT}/kmemleak" + local kern_knob="$DEBUGFS_MNT/kmemleak" + KMEMLEAK_CHECK_FILE="/tmp/check_kmemleak" # Since kernel v4.19-rc3, the kmemleak knob exists even if kmemleak is # disabled, but returns EBUSY on write. So instead of relying on # existance of writable knob file, we use a test file to indicate that # _check_kmemleak() is enabled only if we actually managed to write to # the knob file. - rm -f ${RESULT_BASE}/check_kmemleak + rm -f "$KMEMLEAK_CHECK_FILE" if [ ! -w "$kern_knob" ]; then return 0 @@ -3555,17 +3558,26 @@ _init_kmemleak() # then dump all the leaks recorded so far. if echo "scan=off" > "$kern_knob" 2>/dev/null; then _capture_kmemleak /dev/null - touch ${RESULT_BASE}/check_kmemleak + touch "$KMEMLEAK_CHECK_FILE" fi } -# check kmemleak log +# Kick the kmemleak checker to scan for leaks. Background leak scan mode is +# not enabled, so we must call the kernel to ask for a scan and deal with the +# results appropriately. This we do after every test completes, whether or not +# it was successful. _check_kmemleak() { - local kern_knob="${DEBUGFS_MNT}/kmemleak" - local leak_file="${seqres}.kmemleak" + local kern_knob="$DEBUGFS_MNT/kmemleak" + local leak_file="$seqres.kmemleak" - if [ ! -f ${RESULT_BASE}/check_kmemleak ]; then + if [ ! -f "$KMEMLEAK_CHECK_FILE" ]; then + return 0 + fi + + # Not enabled, so discard any report of leaks found. + if [ "$USE_KMEMLEAK" != "yes" ]; then + _capture_kmemleak /dev/null return 0 fi