From patchwork Sat Aug 10 14:39:35 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akira Hayakawa X-Patchwork-Id: 2842427 Return-Path: X-Original-To: patchwork-dm-devel@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 3D5039F271 for ; Sat, 10 Aug 2013 14:43:50 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 123F42022D for ; Sat, 10 Aug 2013 14:43:49 +0000 (UTC) Received: from mx3-phx2.redhat.com (mx3-phx2.redhat.com [209.132.183.24]) by mail.kernel.org (Postfix) with ESMTP id 23C6120225 for ; Sat, 10 Aug 2013 14:43:48 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx3-phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r7AEdgSn011843; Sat, 10 Aug 2013 10:39:44 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r7AEdg8T002941 for ; Sat, 10 Aug 2013 10:39:42 -0400 Received: from mx1.redhat.com (ext-mx15.extmail.prod.ext.phx2.redhat.com [10.5.110.20]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r7AEdfMP009076 for ; Sat, 10 Aug 2013 10:39:42 -0400 Received: from mail-pa0-f53.google.com (mail-pa0-f53.google.com [209.85.220.53]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r7AEdecb021126 for ; Sat, 10 Aug 2013 10:39:41 -0400 Received: by mail-pa0-f53.google.com with SMTP id lb1so5973636pab.26 for ; Sat, 10 Aug 2013 07:39:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:cc:subject :content-type:content-transfer-encoding; bh=gE9pb0MO0MOSq5WOXpnW26E6rfaJX0zjzFBa/9NQDB8=; b=dzjrB5XMnYoby3F1kVsVJp7YHYN+e/VuL5Jfp8nMj/63R6PRwxOwXC3QL9r1zSBtia UjuppblY3LNF2p0DzyMNDdEb4CpNtPzLyIB+gaWmXRIMY6S5jmsROaY6ncpdwyn7VtQw LUMJmI94YJrQC0HqfrlZQifktXq+PKuqOjxeoFcPmLI2qGVbHuTz45lr3/Rebkmh9Djk 1xytco1IuOl0ZU4S81/PWHAugMZP92nupJMHwKVmSVu5r2WxwXJ5EC5Uyt43n1NQpYa1 g5wyC3RZRCP5YVfmPEwBsZSgc9tvHaqpqbEtjeKEEFeUBcNkOnFc9iVKqrfryaZRlJW9 x/gg== X-Received: by 10.68.211.138 with SMTP id nc10mr16414782pbc.162.1376145580157; Sat, 10 Aug 2013 07:39:40 -0700 (PDT) Received: from Akira-Hayakawas-MacBook-Pro.local (em117-55-65-133.emobile.ad.jp. [117.55.65.133]) by mx.google.com with ESMTPSA id eq5sm26279713pbc.15.2013.08.10.07.39.37 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sat, 10 Aug 2013 07:39:39 -0700 (PDT) Message-ID: <520650A7.4030408@gmail.com> Date: Sat, 10 Aug 2013 23:39:35 +0900 From: Akira Hayakawa User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:17.0) Gecko/20130801 Thunderbird/17.0.8 MIME-Version: 1.0 To: device-mapper development X-RedHat-Spam-Score: -3.1 (BAYES_00, DCC_REPUT_00_12, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS) X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-Scanned-By: MIMEDefang 2.68 on 10.5.110.20 X-loop: dm-devel@redhat.com Cc: =?UTF-8?B?6LydIOaXqeW3nQ==?= Subject: [dm-devel] [PATCH] bugfix: map_context->ptr must be nullify in no-cache path. X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk Reply-To: device-mapper development List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, 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 Hi, Please apply this patch after the previous patch. This will fix bug. First, sorry to forget adding signed-off to that patch. When running prepare script, the kernel sometimes halt was my annoying problem. I may solve this with this patch. lc_end_io is a callback of a splitted bio. It atomic_dec some reference count if map_context->ptr is not NULL. dmsetup create first calls lc_ctr and seems to submit few bios to the device just created. At this stage, the device is without cache and it will later attach to cache. Without cache, said atomic_dec is not only needless but also crash the kernel by NULL access. Maybe, map_context->ptr where map_context is per_bio_data within bio is NOT initialized zero-filled and that makes the process sometimes run through atomic_dec even though without cache. Moving the line assigning NULL to map_context->ptr in lc_map to before "no-cache" path can solve this problem. After this patch applied, the kernel halt did not recur. Akira Signed-off-by: Akira Hayakawa --- drivers/md/dm-lc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/md/dm-lc.c b/drivers/md/dm-lc.c index b70ab38..8f76383 100644 --- a/drivers/md/dm-lc.c +++ b/drivers/md/dm-lc.c @@ -1889,6 +1889,9 @@ static int lc_map(struct dm_target *ti, struct bio *bio) struct lc_device *lc = ti->private; struct dm_dev *orig = lc->device; + map_context = dm_per_bio_data(bio, ti->per_bio_data_size); + map_context->ptr = NULL; + if (!lc->cache) { bio_remap(bio, orig, bio->bi_sector); return DM_MAPIO_REMAPPED; @@ -1918,9 +1921,6 @@ static int lc_map(struct dm_target *ti, struct bio *bio) return DM_MAPIO_SUBMITTED; } - map_context = dm_per_bio_data(bio, ti->per_bio_data_size); - map_context->ptr = NULL; - bio_count = bio->bi_size >> SECTOR_SHIFT; bio_fullsize = (bio_count == (1 << 3)); bio_offset = bio->bi_sector % (1 << 3);