Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp402231imm; Tue, 7 Aug 2018 22:00:26 -0700 (PDT) X-Google-Smtp-Source: AA+uWPw5Ppa0hLyMsvatljvp8gePd0+/czwDQiwOQqf5s4q5x2vsxljhpuUwRYMcVl3s6hlfTO+S X-Received: by 2002:a63:5463:: with SMTP id e35-v6mr1057846pgm.115.1533704426369; Tue, 07 Aug 2018 22:00:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533704426; cv=none; d=google.com; s=arc-20160816; b=dqtkJqnE7m1+qX4J+l5FNENc+76Mi48+h1Wxqz9IamL0vDude+2zvKXiKRKVBtcVLC 81sqkW0tZcidc3oDmOesT46p0LwnLet9kKdb1vywjUpaXyGclNacdd3wx97JAOXwtHhK i7c5aZXNOBmx4B5yX7ieZOGHhLL3Xy2o0kUtgVmz/InA4E9Bthr9v53lHQ57pqLw119K eVRlbuhB4tJe6boiumzEZQR3at5JkSC6ZE775jj0pH6YGrz05xbrvbeIWCXxLZQgOnnM 4O5MTHGa7k/Ik+HpM3lEQafKj4qeNnRuDhAuseW9ZINmMDbRzXGv7Hm9jNA18BPGWX/9 976w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=eFBW+SMO/4ag/iK2ngeYsATFFVBN0iexrUBXO4e1aPw=; b=fsmv7wYIM9Clo8DNobt4gTItAFacv1Qz2VjVr6fTZvxTqZcLCZ7HzgankPVMKITylW xz1WjbLDQnLLklj00HXb30qMXMyxbnI8ykLFBCDvgeILgr/E6p1jNDc0G/tqaEDoSleI 51jUuiWZbHS0Udl22bgiH3loTtfGO+TpNsnvibyRwBaWqSaOlTyE36za3408Fj9QTDdh ibuQoSL4Ig94UKI2fndmFUrt2M+FOaAcOEtFs4ni/MzYieg+pgvA9qeGipOg2ZmWb3nf KzHUx1KaikxjLE9GVvkpW7pSOnkMnrE3DvKGo0SlCJG+joQoWsT1NdjO2cXCPbg5QCUt PVtA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q13-v6si3095777pgq.526.2018.08.07.22.00.09; Tue, 07 Aug 2018 22:00:26 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726875AbeHHHRH (ORCPT + 99 others); Wed, 8 Aug 2018 03:17:07 -0400 Received: from mga07.intel.com ([134.134.136.100]:1130 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726503AbeHHHRH (ORCPT ); Wed, 8 Aug 2018 03:17:07 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 07 Aug 2018 21:59:20 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,456,1526367600"; d="scan'208";a="61488669" Received: from shcsbb05.sh.intel.com ([10.239.147.132]) by fmsmga008.fm.intel.com with ESMTP; 07 Aug 2018 21:59:18 -0700 From: xiao jin To: agk@redhat.com, snitzer@redhat.com, dm-devel@redhat.com, linux-kernel@vger.kernel.org Cc: stable@vger.kernel.org, yanmin.zhang@intel.com, jin.xiao@intel.com Subject: [PATCH] dm-bufio: adjust the reserved buffer for dm-verify-target. Date: Wed, 8 Aug 2018 13:07:03 +0800 Message-Id: <1533704823-5448-1-git-send-email-jin.xiao@intel.com> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We hit the BUG() report at include/linux/scatterlist.h:144! The callback is as bellow: => verity_work => verity_hash_for_block => verity_verify_level => verity_hash => verity_hash_update => sg_init_one => sg_set_buf More debug shows the root cause. When creating dufio client it uses the __vmalloc() to allocate the buffer data for the reserved dm_buffer. The buffer that allocated by the __vmalloc() is invalid according to the __virt_addr_valid(). Mostly the reserved dm_buffer is not touched. But occasionally it might fail to allocate the dm_buffer data when we try to allocate in the __alloc_buffer_wait_no_callback(). Then it has to take the reserved dm_buffer for usage. Finally it reports the BUG() as virt_addr_valid() detects the buffer data address is invalid. The patch is to adjust the reserved buffer for dm-verity-target. We allocated two dm_buffers into the reserved buffers list when creating the buffer interface. The first dm_buffer in the reserved buffer list is allocated by the __vmalloc(), it's not used after that. The second dm_buffer in the reserved buffer list is allocated by the __get_free_pages() which can be consumed after that. Signed-off-by: xiao jin --- drivers/md/dm-bufio.c | 4 ++-- drivers/md/dm-verity-target.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/md/dm-bufio.c b/drivers/md/dm-bufio.c index dc385b7..3b7ca5e 100644 --- a/drivers/md/dm-bufio.c +++ b/drivers/md/dm-bufio.c @@ -841,7 +841,7 @@ static struct dm_buffer *__alloc_buffer_wait_no_callback(struct dm_bufio_client tried_noio_alloc = true; } - if (!list_empty(&c->reserved_buffers)) { + if (!c->need_reserved_buffers) { b = list_entry(c->reserved_buffers.next, struct dm_buffer, lru_list); list_del(&b->lru_list); @@ -1701,7 +1701,7 @@ struct dm_bufio_client *dm_bufio_client_create(struct block_device *bdev, unsign goto bad; } - while (c->need_reserved_buffers) { + if (list_empty(&c->reserved_buffers)) { struct dm_buffer *b = alloc_buffer(c, GFP_KERNEL); if (!b) { diff --git a/drivers/md/dm-verity-target.c b/drivers/md/dm-verity-target.c index 12decdbd7..40c66fc 100644 --- a/drivers/md/dm-verity-target.c +++ b/drivers/md/dm-verity-target.c @@ -1107,7 +1107,7 @@ static int verity_ctr(struct dm_target *ti, unsigned argc, char **argv) v->hash_blocks = hash_position; v->bufio = dm_bufio_client_create(v->hash_dev->bdev, - 1 << v->hash_dev_block_bits, 1, sizeof(struct buffer_aux), + 1 << v->hash_dev_block_bits, 2, sizeof(struct buffer_aux), dm_bufio_alloc_callback, NULL); if (IS_ERR(v->bufio)) { ti->error = "Cannot initialize dm-bufio"; -- 2.7.4