From patchwork Tue Feb 12 02:17:26 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: 10807201 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 96E3817E0 for ; Tue, 12 Feb 2019 02:17:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 883BD2B2B9 for ; Tue, 12 Feb 2019 02:17:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7A1092B2BC; Tue, 12 Feb 2019 02:17:37 +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=unavailable 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 D5A642B2BB for ; Tue, 12 Feb 2019 02:17:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727642AbfBLCRg (ORCPT ); Mon, 11 Feb 2019 21:17:36 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:36346 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727631AbfBLCRg (ORCPT ); Mon, 11 Feb 2019 21:17:36 -0500 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x1C2EQ1g023605; Tue, 12 Feb 2019 02:17:33 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=vL8NdaOmgooRh5/cpX3A62m9AJGRxu7XO/5y9iJNNfQ=; b=Jrl4f0x1w33M7tHM4u9YFUjKoDNE4u8mwi66K6WuUXrzHZSwIrErYL5VZJDIMug+U9mc FGElJ8J7DCH1+PtBctpqFsTW2g24RNvJmGdq/YpmS7qqaV8iFbBTq/hOpuEz2j0/wWYi 219huTBh77EvSVTLo6b7u65yzA1YRLPxk3xGbf4I5HrcOpUjtWO2U8DJsHnnUoQoZ5dV 8dVgha+tD1etv2iwvkg0n6Dni4/sG0SxwswJBqnDZT4yu/LnzBmd61t3Lq05EGliUdS1 I5LhBFDYkGwGG6FaslWdkbbx5ZgTd8X6Me3DFkO7Yv6rRy5+X2mLEEASuFPQVUd6T0gg Pg== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by userp2130.oracle.com with ESMTP id 2qhrek99kt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 12 Feb 2019 02:17:33 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id x1C2HR3N009997 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 12 Feb 2019 02:17:27 GMT Received: from abhmp0018.oracle.com (abhmp0018.oracle.com [141.146.116.24]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x1C2HRq7021699; Tue, 12 Feb 2019 02:17:27 GMT Received: from localhost (/10.159.237.14) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 11 Feb 2019 18:17:27 -0800 Subject: [PATCH 1/3] 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: Mon, 11 Feb 2019 18:17:26 -0800 Message-ID: <154993784666.1948.2898373791588046149.stgit@magnolia> In-Reply-To: <154993784038.1948.7502664832930298472.stgit@magnolia> References: <154993784038.1948.7502664832930298472.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9164 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=914 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1902120014 Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@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 location of the "is kmemleak enabled?" flag to use /tmp instead of RESULT_BASE, scanning for leaks after every test, and clarifying which functions get used when. Signed-off-by: Darrick J. Wong --- README | 2 ++ check | 7 +++++-- common/rc | 32 ++++++++++++++++++++++---------- 3 files changed, 29 insertions(+), 12 deletions(-) diff --git a/README b/README index 73f057f3..6e9aa34d 100644 --- a/README +++ b/README @@ -99,6 +99,8 @@ Preparing system for tests: that relevant results are compared. For example 'spinningrust' for configurations that use spinning disks and 'nvme' for tests using nvme drives. + - set USE_KMEMLEAK=yes to scan for memory leaks in the kernel + after every test, if the kernel supports kmemleak. - or add a case to the switch in common/config assigning these variables based on the hostname of your test diff --git a/check b/check index 77a06b00..20e95302 100755 --- a/check +++ b/check @@ -496,7 +496,7 @@ _expunge_test() return 0 } -_init_kmemleak +_detect_kmemleak _prepare_test_list if $OPTIONS_HAVE_SECTIONS; then @@ -771,9 +771,12 @@ 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 + # Scan for memory leaks after every test so that associating + # a leak to a particular test will be as accurate as possible. + _check_kmemleak || err=true + # test ends after all checks are done. $timestamp && _timestamp stop=`_wallclock` diff --git a/common/rc b/common/rc index b8ed1776..ab468adf 100644 --- a/common/rc +++ b/common/rc @@ -3500,7 +3500,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 @@ -3521,17 +3521,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 @@ -3541,17 +3544,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