Received: by 10.213.65.68 with SMTP id h4csp2144371imn; Sun, 8 Apr 2018 20:51:58 -0700 (PDT) X-Google-Smtp-Source: AIpwx48QDWIUQNtolYbloEqMx0Xdm+/xtMo8gUqcW9KwtUptSv96p9ZOHw0+1HGqMaFj+rW+awVg X-Received: by 10.98.210.7 with SMTP id c7mr27558386pfg.92.1523245918136; Sun, 08 Apr 2018 20:51:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523245918; cv=none; d=google.com; s=arc-20160816; b=yMoWF5hu67UMKG6troFlNnvocPM0jCTgOHgEsoUeANIK97dbonhrBXDZQkYKeq4h6Z /pv54KghWrTdbMSo065gU0sbvAzPL/GPtFoae3DSWDdce67ZDCJ+xLOecJx1VgrTaoJL 4uTbEj0nV4df2GFcgCZPp4j2asjDqS0r3kJlpMs2MwJWhEC2U2DkebpVcA+c0F9/Cqkd jyIp+GCXsQKVxGWPYmboThd5JksYJw5lpiuMbDpiivf7XgpZnZIoXNGM6dDdBz1eDnNY Eq67edmRi6Jwg9n1TlW3AQqCjoUfv0BCvuzd8onLaMWOEQoyQy7AwoOLtgkWYLZXt/1d RNbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=5++CBIP4cBLy7l7nsSgCVOxw24ekKBcrCrM2mLM1cRg=; b=RYJ5Kou5/YhSMgndMJcjbHRijRuqtE3nARVyUShJcUyDGD37yhbf32EchyuzrcEW59 nGpmZp1GiaM7yxqipyzjy5UICL5P+uSWaBxxbTjUZrRUqn6XMe95Z9BASu6BClMpatJv XvBZGNVmKAFenpHKTOXi4TAKEDjrNRHCRkxOY2DL/V9p9ypz7eOpsyA1kFugzTEo0Vq9 J62I+Ferkn3b6neJX+4nN3Vui0f9QXTXTnMnLy2c2c7ePhs6Uvy2oKXMaoRYFG6EZv4R jR0UiloqJGEgdpvaB2w+K36DaTxfdkl917K81jLNSI6mTNqrIbxY++yH446+wbGtDAFu ILIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=Uf9zqKuq; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 97-v6si14384764plc.713.2018.04.08.20.51.21; Sun, 08 Apr 2018 20:51:58 -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=@microsoft.com header.s=selector1 header.b=Uf9zqKuq; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754374AbeDIDqD (ORCPT + 99 others); Sun, 8 Apr 2018 23:46:03 -0400 Received: from mail-bn3nam01on0125.outbound.protection.outlook.com ([104.47.33.125]:5792 "EHLO NAM01-BN3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754190AbeDIAUQ (ORCPT ); Sun, 8 Apr 2018 20:20:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=5++CBIP4cBLy7l7nsSgCVOxw24ekKBcrCrM2mLM1cRg=; b=Uf9zqKuqCGlI+KM/t0QKos36RrysqGjM23IfLgTcU+LaFK02sPbaUnipC8yqiCwC4T2DUZQGy+PFRwRv2oOmdLE8MaFyZbGmqbt3H9ptGUZ+PKW1W3+oGuFoX/FTtIieHByR7ZzlJLr624RUUL3uA+7RyH6hmwsr9/WAYuv1mR8= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB0726.namprd21.prod.outlook.com (10.167.108.39) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.696.0; Mon, 9 Apr 2018 00:20:08 +0000 Received: from DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8109:aef0:a777:7059]) by DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8109:aef0:a777:7059%2]) with mapi id 15.20.0696.003; Mon, 9 Apr 2018 00:20:08 +0000 From: Sasha Levin To: "stable@vger.kernel.org" , "linux-kernel@vger.kernel.org" CC: Jens Axboe , Sasha Levin Subject: [PATCH AUTOSEL for 4.15 128/189] blk-mq: fix discard merge with scheduler attached Thread-Topic: [PATCH AUTOSEL for 4.15 128/189] blk-mq: fix discard merge with scheduler attached Thread-Index: AQHTz5hI4zQdhIBeb0q2Un8la4cAzA== Date: Mon, 9 Apr 2018 00:18:29 +0000 Message-ID: <20180409001637.162453-128-alexander.levin@microsoft.com> References: <20180409001637.162453-1-alexander.levin@microsoft.com> In-Reply-To: <20180409001637.162453-1-alexander.levin@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [52.168.54.252] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;DM5PR2101MB0726;7:O8ielq1WpIIXA1sRggvaL/+yKAelQ3keKgLsPsQOQI6Y0Rdt4hjcr7k30XK+pusxTmjI97KKrxkZbBFPG2KOw2UZvccigI6nbo6ctYuI7KXRpLiyszlGTMX7+ueETNcUlkwhL7QgsvxRwQy1plzK3Z9NF8R2diYkvSR2Snl1kgiJPuPaUqEKjLsLdoaAtQMWG2oI5ruw3b2pyaKoWZvMVhOumNRIPytpc9l/u7Rh5suAdCSzkpz69b1ABxNDuG9O;20:NDAeJ4KuJ1+kz3U0lMUfYJI0pMrR6QVdZpcKQO7fW8OttcIHWLneOvPRkyHVA2Tr3gfe/O45m6ZnsxRMRZjpuGteCXLkRonLhLHd7RA1dDa7yHK+dL910jTbEO2WIaf0cN6vIWBbqz6u66LRP+ecEJl9khkQazDhSWhCodTZ4Pw= x-ms-office365-filtering-ht: Tenant X-MS-Office365-Filtering-Correlation-Id: b4e4786f-871d-41e2-560e-08d59dafa67a x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7193020);SRVR:DM5PR2101MB0726; x-ms-traffictypediagnostic: DM5PR2101MB0726: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(89211679590171); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(61425038)(6040522)(2401047)(5005006)(8121501046)(93006095)(93001095)(3231221)(944501327)(52105095)(3002001)(10201501046)(6055026)(61426038)(61427038)(6041310)(20161123558120)(20161123562045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(6072148)(201708071742011);SRVR:DM5PR2101MB0726;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB0726; x-forefront-prvs: 0637FCE711 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(366004)(346002)(39380400002)(39860400002)(396003)(376002)(199004)(189003)(6486002)(26005)(6512007)(4326008)(81166006)(6666003)(6436002)(81156014)(8676002)(97736004)(186003)(36756003)(72206003)(53936002)(107886003)(2906002)(86362001)(575784001)(76176011)(110136005)(305945005)(10090500001)(486006)(551934003)(3660700001)(102836004)(5660300001)(14454004)(476003)(86612001)(446003)(99286004)(68736007)(66066001)(11346002)(54906003)(2616005)(1076002)(7736002)(5250100002)(25786009)(8936002)(478600001)(2900100001)(2501003)(3280700002)(105586002)(59450400001)(316002)(106356001)(22452003)(6506007)(3846002)(10290500003)(6116002)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB0726;H:DM5PR2101MB1032.namprd21.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: f4f0H8IKvKJHr12gZCh+1TA6c0uaPeGA8nF7g+r6LdmUnxdOrtU5nVCWOVda/KLNmbjYrI4HAaQlqKL/vG4dAySyfc1GNlXwRPkgdCYf6hFNotWFYOLBFHPgB6eCKir4fY+dz7cLr85gXgpXgGVfTLztRDrYOt7SyqFVqIkqZFI420e2g+VjgXb59WleU6bmH3FzSfzn0mcaCH7SbhsU8Rzzj2a1Ty0setlZrvwxbmjhmP9TWX6V6CPcAPATIi5A5XJ53KCZJmoG6hKV0KW1IC3AKWkZYjnceXn7hnkFDf8mTJCK32Jy3SI8D+RXpsRhAeme/EnsRPnniOCqp3CFVuLroaxp5kawtXXA/ScDjon9cBoxehj5f4NptHb3rdBmtxxh+IbgedKMpYJOYqRtHoP2gfR9C1BqpJenHWtYkl0= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: b4e4786f-871d-41e2-560e-08d59dafa67a X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Apr 2018 00:18:29.0664 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB0726 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jens Axboe [ Upstream commit 445251d0f4d329aa061f323546cd6388a3bb7ab5 ] I ran into an issue on my laptop that triggered a bug on the discard path: WARNING: CPU: 2 PID: 207 at drivers/nvme/host/core.c:527 nvme_setup_cmd+0x3= d3/0x430 Modules linked in: rfcomm fuse ctr ccm bnep arc4 binfmt_misc snd_hda_codec= _hdmi nls_iso8859_1 nls_cp437 vfat snd_hda_codec_conexant fat snd_hda_codec= _generic iwlmvm snd_hda_intel snd_hda_codec snd_hwdep mac80211 snd_hda_core= snd_pcm snd_seq_midi snd_seq_midi_event snd_rawmidi snd_seq x86_pkg_temp_t= hermal intel_powerclamp kvm_intel uvcvideo iwlwifi btusb snd_seq_device vid= eobuf2_vmalloc btintel videobuf2_memops kvm snd_timer videobuf2_v4l2 blueto= oth irqbypass videobuf2_core aesni_intel aes_x86_64 crypto_simd cryptd snd = glue_helper videodev cfg80211 ecdh_generic soundcore hid_generic usbhid hid= i915 psmouse e1000e ptp pps_core xhci_pci xhci_hcd intel_gtt CPU: 2 PID: 207 Comm: jbd2/nvme0n1p7- Tainted: G U 4.15.0+ #= 176 Hardware name: LENOVO 20FBCTO1WW/20FBCTO1WW, BIOS N1FET59W (1.33 ) 12/19/2= 017 RIP: 0010:nvme_setup_cmd+0x3d3/0x430 RSP: 0018:ffff880423e9f838 EFLAGS: 00010217 RAX: 0000000000000000 RBX: ffff880423e9f8c8 RCX: 0000000000010000 RDX: ffff88022b200010 RSI: 0000000000000002 RDI: 00000000327f0000 RBP: ffff880421251400 R08: ffff88022b200000 R09: 0000000000000009 R10: 0000000000000000 R11: 0000000000000000 R12: 000000000000ffff R13: ffff88042341e280 R14: 000000000000ffff R15: ffff880421251440 FS: 0000000000000000(0000) GS:ffff880441500000(0000) knlGS:00000000000000= 00 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 000055b684795030 CR3: 0000000002e09006 CR4: 00000000001606e0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 Call Trace: nvme_queue_rq+0x40/0xa00 ? __sbitmap_queue_get+0x24/0x90 ? blk_mq_get_tag+0xa3/0x250 ? wait_woken+0x80/0x80 ? blk_mq_get_driver_tag+0x97/0xf0 blk_mq_dispatch_rq_list+0x7b/0x4a0 ? deadline_remove_request+0x49/0xb0 blk_mq_do_dispatch_sched+0x4f/0xc0 blk_mq_sched_dispatch_requests+0x106/0x170 __blk_mq_run_hw_queue+0x53/0xa0 __blk_mq_delay_run_hw_queue+0x83/0xa0 blk_mq_run_hw_queue+0x6c/0xd0 blk_mq_sched_insert_request+0x96/0x140 __blk_mq_try_issue_directly+0x3d/0x190 blk_mq_try_issue_directly+0x30/0x70 blk_mq_make_request+0x1a4/0x6a0 generic_make_request+0xfd/0x2f0 ? submit_bio+0x5c/0x110 submit_bio+0x5c/0x110 ? __blkdev_issue_discard+0x152/0x200 submit_bio_wait+0x43/0x60 ext4_process_freed_data+0x1cd/0x440 ? account_page_dirtied+0xe2/0x1a0 ext4_journal_commit_callback+0x4a/0xc0 jbd2_journal_commit_transaction+0x17e2/0x19e0 ? kjournald2+0xb0/0x250 kjournald2+0xb0/0x250 ? wait_woken+0x80/0x80 ? commit_timeout+0x10/0x10 kthread+0x111/0x130 ? kthread_create_worker_on_cpu+0x50/0x50 ? do_group_exit+0x3a/0xa0 ret_from_fork+0x1f/0x30 Code: 73 89 c1 83 ce 10 c1 e1 10 09 ca 83 f8 04 0f 87 0f ff ff ff 8b 4d 20= 48 8b 7d 00 c1 e9 09 48 01 8c c7 00 08 00 00 e9 f8 fe ff ff <0f> ff 4c 89 = c7 41 bc 0a 00 00 00 e8 0d 78 d6 ff e9 a1 fc ff ff ---[ end trace 50d361cc444506c8 ]--- print_req_error: I/O error, dev nvme0n1, sector 847167488 Decoding the assembly, the request claims to have 0xffff segments, while nvme counts two. This turns out to be because we don't check for a data carrying request on the mq scheduler path, and since blk_phys_contig_segment() returns true for a non-data request, we decrement the initial segment count of 0 and end up with 0xffff in the unsigned short. There are a few issues here: 1) We should initialize the segment count for a discard to 1. 2) The discard merging is currently using the data limits for segments and sectors. Fix this up by having attempt_merge() correctly identify the request, and by initializing the segment count correctly for discards. This can only be triggered with mq-deadline on discard capable devices right now, which isn't a common configuration. Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- block/blk-core.c | 2 ++ block/blk-merge.c | 29 ++++++++++++++++++++++++++--- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/block/blk-core.c b/block/blk-core.c index b725d9e340c2..f6343ce5a80d 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -3260,6 +3260,8 @@ void blk_rq_bio_prep(struct request_queue *q, struct = request *rq, { if (bio_has_data(bio)) rq->nr_phys_segments =3D bio_phys_segments(q, bio); + else if (bio_op(bio) =3D=3D REQ_OP_DISCARD) + rq->nr_phys_segments =3D 1; =20 rq->__data_len =3D bio->bi_iter.bi_size; rq->bio =3D rq->biotail =3D bio; diff --git a/block/blk-merge.c b/block/blk-merge.c index f5dedd57dff6..8d60a5bbcef9 100644 --- a/block/blk-merge.c +++ b/block/blk-merge.c @@ -551,6 +551,24 @@ static bool req_no_special_merge(struct request *req) return !q->mq_ops && req->special; } =20 +static bool req_attempt_discard_merge(struct request_queue *q, struct requ= est *req, + struct request *next) +{ + unsigned short segments =3D blk_rq_nr_discard_segments(req); + + if (segments >=3D queue_max_discard_segments(q)) + goto no_merge; + if (blk_rq_sectors(req) + bio_sectors(next->bio) > + blk_rq_get_max_sectors(req, blk_rq_pos(req))) + goto no_merge; + + req->nr_phys_segments =3D segments + blk_rq_nr_discard_segments(next); + return true; +no_merge: + req_set_nomerge(q, req); + return false; +} + static int ll_merge_requests_fn(struct request_queue *q, struct request *r= eq, struct request *next) { @@ -684,9 +702,13 @@ static struct request *attempt_merge(struct request_qu= eue *q, * If we are allowed to merge, then append bio list * from next to rq and release next. merge_requests_fn * will have updated segment counts, update sector - * counts here. + * counts here. Handle DISCARDs separately, as they + * have separate settings. */ - if (!ll_merge_requests_fn(q, req, next)) + if (req_op(req) =3D=3D REQ_OP_DISCARD) { + if (!req_attempt_discard_merge(q, req, next)) + return NULL; + } else if (!ll_merge_requests_fn(q, req, next)) return NULL; =20 /* @@ -716,7 +738,8 @@ static struct request *attempt_merge(struct request_que= ue *q, =20 req->__data_len +=3D blk_rq_bytes(next); =20 - elv_merge_requests(q, req, next); + if (req_op(req) !=3D REQ_OP_DISCARD) + elv_merge_requests(q, req, next); =20 /* * 'next' is going away, so update stats accordingly --=20 2.15.1