From patchwork Sun Oct 19 12:43:54 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liu Bo X-Patchwork-Id: 5100881 Return-Path: X-Original-To: patchwork-fstests@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 4A00D9F30B for ; Sun, 19 Oct 2014 12:44:15 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 71D2420176 for ; Sun, 19 Oct 2014 12:44:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8A10220154 for ; Sun, 19 Oct 2014 12:44:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751876AbaJSMoN (ORCPT ); Sun, 19 Oct 2014 08:44:13 -0400 Received: from userp1040.oracle.com ([156.151.31.81]:27963 "EHLO userp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751869AbaJSMoM (ORCPT ); Sun, 19 Oct 2014 08:44:12 -0400 Received: from acsinet21.oracle.com (acsinet21.oracle.com [141.146.126.237]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id s9JCiAhn001589 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sun, 19 Oct 2014 12:44:11 GMT Received: from aserz7021.oracle.com (aserz7021.oracle.com [141.146.126.230]) by acsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id s9JCiAAr023662 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sun, 19 Oct 2014 12:44:10 GMT Received: from abhmp0014.oracle.com (abhmp0014.oracle.com [141.146.116.20]) by aserz7021.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id s9JCiAk0023651; Sun, 19 Oct 2014 12:44:10 GMT Received: from localhost.localdomain.localdomain (/202.106.79.10) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Sun, 19 Oct 2014 05:44:09 -0700 From: Liu Bo To: fstests@vger.kernel.org Cc: linux-btrfs Subject: [PATCH] fstests: fix memory corruption in aio-last-ref-held-by-io Date: Sun, 19 Oct 2014 20:43:54 +0800 Message-Id: <1413722634-25514-1-git-send-email-bo.li.liu@oracle.com> X-Mailer: git-send-email 1.8.1.4 X-Source-IP: acsinet21.oracle.com [141.146.126.237] Sender: fstests-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Liu Bo This's been detected by testing generic/323 on btrfs, it keeps producing chaos of checksum errors. It is because aio-last-ref-held-by-io uses a static buffer that is been used repeatedly for every io_submit() call, but we'll issue NUM_IOS(=16) io_sumbit() in a 'for' loop at a time, and when those data read by aio has not finish its endio(), its memory is likely to be used in the next io_submit, which ends up data corruption and numerous checksum errors. This allocates memory for each io_submit() and generic/323 runs fine after this. Signed-off-by: Liu Bo --- src/aio-dio-regress/aio-last-ref-held-by-io.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/aio-dio-regress/aio-last-ref-held-by-io.c b/src/aio-dio-regress/aio-last-ref-held-by-io.c index a73dc3b..7633831 100644 --- a/src/aio-dio-regress/aio-last-ref-held-by-io.c +++ b/src/aio-dio-regress/aio-last-ref-held-by-io.c @@ -109,7 +109,7 @@ aio_test_thread(void *data) ioctx_initted = 0; ios_submitted = 0; - ret = posix_memalign((void **)&buffer, getpagesize(), IOSIZE); + ret = posix_memalign((void **)&buffer, getpagesize(), IOSIZE * NUM_IOS); if (ret != 0) { printf("%lu: Failed to allocate buffer for IO: %d\n", pthread_self(), ret); @@ -137,7 +137,7 @@ aio_test_thread(void *data) struct iocb *iocb = &iocbs[i]; memset(iocb, 0, sizeof(*iocb)); - io_prep_pread(iocb, fd, buffer, + io_prep_pread(iocb, fd, (buffer + i * IOSIZE), IOSIZE, i * IOSIZE); if (io_submit(ioctx, 1, &iocb) != 1) { printf("%lu: failed to submit io #%d\n",