Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2345100imm; Mon, 28 May 2018 06:27:01 -0700 (PDT) X-Google-Smtp-Source: AB8JxZo/ortxzv4Dxxz6H7n6vSLrP6czfcgmU6KVoEkDD1p0AENRxStCsZu+eUn77hJsP6WYZI5M X-Received: by 2002:a65:5946:: with SMTP id g6-v6mr10520254pgu.391.1527514021579; Mon, 28 May 2018 06:27:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527514021; cv=none; d=google.com; s=arc-20160816; b=m6jemPYfekdnbH85ilC4Fc1ThWnSY5ogLBrwpk43Ynqj9ZqzcSV0k3SNZ+Qmgb499O s6tUoHmQaGOSHhHKXmaEQ7WqKq5qvOVZzKvVbZI2ntUuFeAYZMV/pjdsmI3ORVNR5Gcq G3KZrroEr2lmy565LkV5J23Hjl5ezLgFpq7W2fCRYFSA2QuxwiX5dS4lNaEWyV8DSguW fvqdefA/LRQngybBBhVY31m0B+9W1e9dVRin0wiM3nWaxheoZ7JnSoZRWrn/FZ45FQm3 YVjVmbx3N68gXY8feeFjYD0CDQAeE0CVt0+vIrVmJBuFWNGPwHu5omTHDgk36acCjXWi 7X+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=acXglJBlcszkJiM/amoR4WwtGRbV0aZIujHzFwvHrHc=; b=BXxA2naA8anqqQOvUfA5sqDh6YJpBC9TTGnTj0BBGgHLY1oPqCqW49JTB8h9C/iyFR lCo4oYNF5Paw+PTLEoAd0HaxTW9X03qTM03FFUlRIJtzERsVbNMmQlHqpRUvwaR1yYJW 0mJc2ykrvAktzjul8XHOfQcMPci5SaWA2OEGsZXXHjMAwvgZ4ge7jha6Yi9PWHk5efk+ 9xFEWbORIa9WvPS1td0Lakc4wLUAv6cmXg9ilMJjSZBPYxLIoOYj4bdsGrBksGGdZ1CD p2ro0LK+nP6fmlNgoUq4b+OwNWCvMyym9c43gcK6KdNuDOfZW1rB+xwebvIRw09qiMkA o2IQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=weEcPaif; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y125-v6si7712873pfb.284.2018.05.28.06.26.47; Mon, 28 May 2018 06:27:01 -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; dkim=pass header.i=@kernel.org header.s=default header.b=weEcPaif; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1163477AbeE1NZB (ORCPT + 99 others); Mon, 28 May 2018 09:25:01 -0400 Received: from mail.kernel.org ([198.145.29.99]:38332 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1163345AbeE1KsZ (ORCPT ); Mon, 28 May 2018 06:48:25 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9C688204EE; Mon, 28 May 2018 10:48:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527504505; bh=16GOGFoRKL9NtkqHCwrSC4z4ZJvWTjta/hDp+ALaT1g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=weEcPaiffRGs8KsK6fIfqDXSUOaia4oqkzuw2/izik+FfvNAIpG3XOuFw2oKW+y9F /OuerubM2++tdZZFVqGbq86oKJRA1ScNgaWuE9iEQ6UPmfjzpDOfncS99rsI0UK/pv 0wPoixcW/MMcAQUFCIC1WtqkE2+/Q9/s28Dpegmo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Matthias Ferdinand , Tang Junhui , Michael Lyle , Jens Axboe , Sasha Levin Subject: [PATCH 4.14 162/496] bcache: fix kcrashes with fio in RAID5 backend dev Date: Mon, 28 May 2018 11:59:07 +0200 Message-Id: <20180528100326.698626166@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180528100319.498712256@linuxfoundation.org> References: <20180528100319.498712256@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Tang Junhui [ Upstream commit 60eb34ec5526e264c2bbaea4f7512d714d791caf ] Kernel crashed when run fio in a RAID5 backend bcache device, the call trace is bellow: [ 440.012034] kernel BUG at block/blk-ioc.c:146! [ 440.012696] invalid opcode: 0000 [#1] SMP NOPTI [ 440.026537] CPU: 2 PID: 2205 Comm: md127_raid5 Not tainted 4.15.0 #8 [ 440.027441] Hardware name: HP ProLiant MicroServer Gen8, BIOS J06 07/16 /2015 [ 440.028615] RIP: 0010:put_io_context+0x8b/0x90 [ 440.029246] RSP: 0018:ffffa8c882b43af8 EFLAGS: 00010246 [ 440.029990] RAX: 0000000000000000 RBX: ffffa8c88294fca0 RCX: 0000000000 0f4240 [ 440.031006] RDX: 0000000000000004 RSI: 0000000000000286 RDI: ffffa8c882 94fca0 [ 440.032030] RBP: ffffa8c882b43b10 R08: 0000000000000003 R09: ffff949cb8 0c1700 [ 440.033206] R10: 0000000000000104 R11: 000000000000b71c R12: 00000000000 01000 [ 440.034222] R13: 0000000000000000 R14: ffff949cad84db70 R15: ffff949cb11 bd1e0 [ 440.035239] FS: 0000000000000000(0000) GS:ffff949cba280000(0000) knlGS: 0000000000000000 [ 440.060190] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 440.084967] CR2: 00007ff0493ef000 CR3: 00000002f1e0a002 CR4: 00000000001 606e0 [ 440.110498] Call Trace: [ 440.135443] bio_disassociate_task+0x1b/0x60 [ 440.160355] bio_free+0x1b/0x60 [ 440.184666] bio_put+0x23/0x30 [ 440.208272] search_free+0x23/0x40 [bcache] [ 440.231448] cached_dev_write_complete+0x31/0x70 [bcache] [ 440.254468] closure_put+0xb6/0xd0 [bcache] [ 440.277087] request_endio+0x30/0x40 [bcache] [ 440.298703] bio_endio+0xa1/0x120 [ 440.319644] handle_stripe+0x418/0x2270 [raid456] [ 440.340614] ? load_balance+0x17b/0x9c0 [ 440.360506] handle_active_stripes.isra.58+0x387/0x5a0 [raid456] [ 440.380675] ? __release_stripe+0x15/0x20 [raid456] [ 440.400132] raid5d+0x3ed/0x5d0 [raid456] [ 440.419193] ? schedule+0x36/0x80 [ 440.437932] ? schedule_timeout+0x1d2/0x2f0 [ 440.456136] md_thread+0x122/0x150 [ 440.473687] ? wait_woken+0x80/0x80 [ 440.491411] kthread+0x102/0x140 [ 440.508636] ? find_pers+0x70/0x70 [ 440.524927] ? kthread_associate_blkcg+0xa0/0xa0 [ 440.541791] ret_from_fork+0x35/0x40 [ 440.558020] Code: c2 48 00 5b 41 5c 41 5d 5d c3 48 89 c6 4c 89 e7 e8 bb c2 48 00 48 8b 3d bc 36 4b 01 48 89 de e8 7c f7 e0 ff 5b 41 5c 41 5d 5d c3 <0f> 0b 0f 1f 00 0f 1f 44 00 00 55 48 8d 47 b8 48 89 e5 41 57 41 [ 440.610020] RIP: put_io_context+0x8b/0x90 RSP: ffffa8c882b43af8 [ 440.628575] ---[ end trace a1fd79d85643a73e ]-- All the crash issue happened when a bypass IO coming, in such scenario s->iop.bio is pointed to the s->orig_bio. In search_free(), it finishes the s->orig_bio by calling bio_complete(), and after that, s->iop.bio became invalid, then kernel would crash when calling bio_put(). Maybe its upper layer's faulty, since bio should not be freed before we calling bio_put(), but we'd better calling bio_put() first before calling bio_complete() to notify upper layer ending this bio. This patch moves bio_complete() under bio_put() to avoid kernel crash. [mlyle: fixed commit subject for character limits] Reported-by: Matthias Ferdinand Tested-by: Matthias Ferdinand Signed-off-by: Tang Junhui Reviewed-by: Michael Lyle Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/md/bcache/request.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/drivers/md/bcache/request.c +++ b/drivers/md/bcache/request.c @@ -651,11 +651,11 @@ static void do_bio_hook(struct search *s static void search_free(struct closure *cl) { struct search *s = container_of(cl, struct search, cl); - bio_complete(s); if (s->iop.bio) bio_put(s->iop.bio); + bio_complete(s); closure_debug_destroy(cl); mempool_free(s, s->d->c->search); }