From patchwork Tue Jan 26 05:02:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Fomichev X-Patchwork-Id: 12045281 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9F7DDC433DB for ; Tue, 26 Jan 2021 05:04:25 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 155E422573 for ; Tue, 26 Jan 2021 05:04:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 155E422573 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:39806 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l4GWe-0005jw-30 for qemu-devel@archiver.kernel.org; Tue, 26 Jan 2021 00:04:24 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:34634) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l4GVD-0004R2-SV; Tue, 26 Jan 2021 00:02:55 -0500 Received: from esa6.hgst.iphmx.com ([216.71.154.45]:37780) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l4GVC-00072U-5X; Tue, 26 Jan 2021 00:02:55 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1611637375; x=1643173375; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=PazIAxzY1coeVGKSvAemX3zmcaI4GM9KFwOf0jflDUk=; b=LQpCv6+sQ+dYIpEAOGuwfI37prdMKO/RNJlDfxoXInqZdT+4lXlIr309 qROEc3kwNEwrxrbyclQAFenHrsG1OwpPYA30iyTYdxCec48Qr3nUzlOgW RNZKSf8tOYvLWCZzCmpHkGcMgt1SScAVrrZRF8b0x+IiXybYbV/wSJGUM 94MGAgRflQMUNxpRMfIW4lw6/9v+5ZR40tLPIwhjec5lsDNjqeedgd6j4 6rrB4BgGQYGWrIGrEpcoD7ve6PMDH94FcJsqalAyZlaxrZ3HhtQVHG92j XmHJ1LBlUxhm9GZEu+iY8LPWNwTYmvITEcxaK1zzKS/QObWHNHLJYKK0M A==; IronPort-SDR: e8yeI+TLli1VsKfEp5Xo2kzgl9T7NIm0/EMLs01feHsS8gBBe4RCjOwH1z8ShpaboQwqyPLujb eaVGpfyPiqKr2mMYn85jNs0PdlTqK6cXBj0TLWUZf5itiNqxVKkjArhk+O2RQT1hML8fae4HTy df+wWS1aFhQRRtfaTO51Gtw1lqMgkxr5TPGtsS6UmjuZFPjUKT9nIU+BK0A7NO4fkuq4Ej1Mal MO4tK5tftUJC9bLrz9neD5ULcdSQd/VqIlEjA1hItZKYs1vl6S5Ph35zLc+S4K+q94l3UZQC1N DBU= X-IronPort-AV: E=Sophos;i="5.79,375,1602518400"; d="scan'208";a="159493361" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 26 Jan 2021 13:02:53 +0800 IronPort-SDR: /0yg73+OCfHB8VP0/zo3S55FZJ13WFKfzF/uKox+pU9TSneSGDwQbTSsoY27rJJXR48nyBdlME HENe0+rMiJAIz0qfYbD2zpJnGw9pgYEFcO2GifeOCKE//WQ8UB+NpWELiA61TwY35zVXDgxmn2 DlIrZZDC2KFzucXRHWIHZeKM3WYQqDrSbVXAQ1o7AhCEa/YIg8GN4Zj01HdcVEXILX7yFzB9Pq jn8MgD8S20Bsu3tkw2t4bHuu+6hyXFvHcqnZJz6406WL+jS/LjPD5hSl7g4WgtdEEAfbm6oXWg ajevpxCgXWqCMPupfxIsgDOd Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jan 2021 20:47:19 -0800 IronPort-SDR: P8LlA+BZzfBTOBfvKQp/NQ4ZBybgm3MMgNu8pnyrYJPSo1cg5Dp1Q6V4koV0n8BM87x808E+4X yWjQbSKMiY6yOlaq1/XUbPuL5Wlw4Fc0pXyQ4ZKL7irLPHVZWxMFSn6rTE1t3wf/8rpXPCjYE+ S/0FriLYLcwRt0/KDH6cmW8ZuHhcIqPbdbJhT4FslyH7IgIAGmS70NAF2uqpgry5cG33TM5wLM pMq1bAtsjTJ42VZXY6Gvn3KPFf8zfbNDJGeRSOmMUgJQDB/6czvUQZ7IW463GD1TUzIRtq/nv9 y/I= WDCIronportException: Internal Received: from unknown (HELO redsun50.ssa.fujisawa.hgst.com) ([10.149.66.24]) by uls-op-cesaip02.wdc.com with ESMTP; 25 Jan 2021 21:02:51 -0800 From: Dmitry Fomichev To: Klaus Jensen , Keith Busch , Kevin Wolf , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Max Reitz , qemu-devel@nongnu.org Subject: [PATCH 1/3] hw/block/nvme: Check for zone boundary during append Date: Tue, 26 Jan 2021 14:02:46 +0900 Message-Id: <20210126050248.9077-2-dmitry.fomichev@wdc.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20210126050248.9077-1-dmitry.fomichev@wdc.com> References: <20210126050248.9077-1-dmitry.fomichev@wdc.com> MIME-Version: 1.0 Received-SPF: pass client-ip=216.71.154.45; envelope-from=prvs=653775e38=dmitry.fomichev@wdc.com; helo=esa6.hgst.iphmx.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Dmitry Fomichev , Niklas Cassel , Damien Le Moal , qemu-block@nongnu.org Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" It is observed that with the existing code it is possible to keep appending to a zone indefinitely. To fix, add the missing check to verify that the zone append is not going to write beyond zone capacity. Reported-by: Niklas Cassel Signed-off-by: Dmitry Fomichev --- hw/block/nvme.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/hw/block/nvme.c b/hw/block/nvme.c index f64676a930..67538010ef 100644 --- a/hw/block/nvme.c +++ b/hw/block/nvme.c @@ -1135,9 +1135,10 @@ static uint16_t nvme_check_zone_write(NvmeCtrl *n, NvmeNamespace *ns, NvmeZone *zone, uint64_t slba, uint32_t nlb, bool append) { + uint64_t bndry = nvme_zone_wr_boundary(zone); uint16_t status; - if (unlikely((slba + nlb) > nvme_zone_wr_boundary(zone))) { + if (unlikely(slba + nlb > bndry)) { status = NVME_ZONE_BOUNDARY_ERROR; } else { status = nvme_check_zone_state_for_write(zone); @@ -1151,8 +1152,9 @@ static uint16_t nvme_check_zone_write(NvmeCtrl *n, NvmeNamespace *ns, if (unlikely(slba != zone->d.zslba)) { trace_pci_nvme_err_append_not_at_start(slba, zone->d.zslba); status = NVME_INVALID_FIELD; - } - if (nvme_l2b(ns, nlb) > (n->page_size << n->zasl)) { + } else if (unlikely(zone->w_ptr + nlb > bndry)) { + status = NVME_ZONE_BOUNDARY_ERROR; + } else if (nvme_l2b(ns, nlb) > (n->page_size << n->zasl)) { trace_pci_nvme_err_append_too_large(slba, nlb, n->zasl); status = NVME_INVALID_FIELD; } From patchwork Tue Jan 26 05:02:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Fomichev X-Patchwork-Id: 12045283 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 40A59C433E0 for ; Tue, 26 Jan 2021 05:04:28 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D41F822573 for ; Tue, 26 Jan 2021 05:04:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D41F822573 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:40010 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l4GWg-0005p8-UA for qemu-devel@archiver.kernel.org; Tue, 26 Jan 2021 00:04:26 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:34660) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l4GVG-0004UZ-Mx; Tue, 26 Jan 2021 00:02:58 -0500 Received: from esa6.hgst.iphmx.com ([216.71.154.45]:37779) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l4GVE-00071d-5N; Tue, 26 Jan 2021 00:02:58 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1611637377; x=1643173377; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=2xqzGNg8YFv3IDuzA9g+Xxo6ggjr7TLgWBd/SJdf3wU=; b=LWV1ESpLB9by3zIc72/2BM5F02B9DYMf1j6g+dR5GS5U4NmjPDF8ZD/T 2oqrXTDF6cEmpKuRDqDp/R6YL8+hAp+b02CgJE3But52lc0ZrMLg2pPKP d1nK8bRv0e5wey7bOqtICNt+8MWx1sWCzCqIGTnh9tfLuTWNTKcNdtKBx 7tX13nF9Z3QoXzKZz3wfuOgVhQyJchaM8G32zbrGftAMQ7Sr+u2T3OpN6 W7boVgFkbDN16HPNrMZ9lZGSjDBz+FfsH/eC86Ctgparxopvhb9q9mCCP 0gVSwu24vM/KL16aFzDkmTHf0i+UhrUy5maHeBsN5HRksuQD9mZaHRwS4 g==; IronPort-SDR: pcqk3UehO+9zmOE1wNT1X8UFVKutqhyQe1BlDxP/GdoUHhEI8JA2kXO8Tl5uGUVUx6LLZMRKje mQTcZM+wqO7tfRjkVWcrc90R8HBgfIEOiElK1UzZRsGgaOVtxae+5SrRIc3rwTrGV7B5SqDyLT WBBZhtCWPqe5HD+6Mx4X4EZFwp4yR3MUMSC+ppx1/ucpsoVNJeQvuOF+L+EmBb3Lr244WXG5fZ 50xUkXlAnEahKgeBrwhbS1J6SVeA2TxOzJQhanPO6IFj454H/HEuf2JWQ+GyIZ8DoxxqCnHOAL sn8= X-IronPort-AV: E=Sophos;i="5.79,375,1602518400"; d="scan'208";a="159493363" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 26 Jan 2021 13:02:55 +0800 IronPort-SDR: voYvmmCJHvxIRnkgMQeIj8BFVcYy8taS3M27AFhbpHRR+xDJjGWngHftrXb7nzsgohesKyZ5cr 5/BvpKPHD9YEUOdnClvCajXSlJ7bQsbsslZYlX8cDr3a0Vg8JgVDaLG+XR9msN/mUrfckQja9C aCm2e6khBL1MQFbALcIAyP4Q98GvJ61wB2Yt4m6dZFSwSF9pSVqzYsG3dZ820CdddYGODiXOyK lsp2zqEB4vxnXxw3rHTdG0y9djqfifwhYkCWUJoKoT116G7p/VbVdyiI9HxNQys21y0v1S6rv5 Td4W9li0X0RqvX4uuFeOqckw Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jan 2021 20:47:21 -0800 IronPort-SDR: vaanmxd7t/gA1WVbHt9Y9DCR67RFY9dvGsrTN6aMKJB2OITiRJomy/S9vpDKWn3KHPj+imzUVA Pq0egGiwuq9G+xie6fsOxF3oyVuPvTkHz1g4tOWYND37utezTMhzNcfVf/d//t0ihwaA2uNLJp x5mKOo3dRrTfplx0TX0QHlZUrpdSzEPkhjbHRJ24f8ugBmTgFdGhTE0m74G/ggn7OetZUWG+fK kSEUjT964m+UnTYdNIVvzX6A9V5ZScHmjF9PsXlUraLQey8QHOxXr9sX2+/ijndguf+jpnWiHd 5VM= WDCIronportException: Internal Received: from unknown (HELO redsun50.ssa.fujisawa.hgst.com) ([10.149.66.24]) by uls-op-cesaip02.wdc.com with ESMTP; 25 Jan 2021 21:02:53 -0800 From: Dmitry Fomichev To: Klaus Jensen , Keith Busch , Kevin Wolf , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Max Reitz , qemu-devel@nongnu.org Subject: [PATCH 2/3] hw/block/nvme: Check zone state before checking boundaries Date: Tue, 26 Jan 2021 14:02:47 +0900 Message-Id: <20210126050248.9077-3-dmitry.fomichev@wdc.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20210126050248.9077-1-dmitry.fomichev@wdc.com> References: <20210126050248.9077-1-dmitry.fomichev@wdc.com> MIME-Version: 1.0 Received-SPF: pass client-ip=216.71.154.45; envelope-from=prvs=653775e38=dmitry.fomichev@wdc.com; helo=esa6.hgst.iphmx.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Dmitry Fomichev , Niklas Cassel , Damien Le Moal , qemu-block@nongnu.org Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" The code in nvme_check_zone_write() first checks for zone boundary condition violation and only after that it proceeds to verify that the zone state is suitable the write to happen. This is not consistent with nvme_check_zone_read() flow - in that function, zone state is checked before making any boundary checks. Besides, checking that ZSLBA + NLB does not cross the write boundary is now redundant for Zone Append and only needs to be done for writes. Move the check in the code to be performed for Write and Write Zeroes commands only and to occur after zone state checks. Signed-off-by: Dmitry Fomichev --- hw/block/nvme.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/hw/block/nvme.c b/hw/block/nvme.c index 67538010ef..b712634c27 100644 --- a/hw/block/nvme.c +++ b/hw/block/nvme.c @@ -1138,13 +1138,8 @@ static uint16_t nvme_check_zone_write(NvmeCtrl *n, NvmeNamespace *ns, uint64_t bndry = nvme_zone_wr_boundary(zone); uint16_t status; - if (unlikely(slba + nlb > bndry)) { - status = NVME_ZONE_BOUNDARY_ERROR; - } else { - status = nvme_check_zone_state_for_write(zone); - } - - if (status != NVME_SUCCESS) { + status = nvme_check_zone_state_for_write(zone); + if (status) { trace_pci_nvme_err_zone_write_not_ok(slba, nlb, status); } else { assert(nvme_wp_is_valid(zone)); @@ -1158,10 +1153,14 @@ static uint16_t nvme_check_zone_write(NvmeCtrl *n, NvmeNamespace *ns, trace_pci_nvme_err_append_too_large(slba, nlb, n->zasl); status = NVME_INVALID_FIELD; } - } else if (unlikely(slba != zone->w_ptr)) { - trace_pci_nvme_err_write_not_at_wp(slba, zone->d.zslba, - zone->w_ptr); - status = NVME_ZONE_INVALID_WRITE; + } else { + if (unlikely(slba != zone->w_ptr)) { + trace_pci_nvme_err_write_not_at_wp(slba, zone->d.zslba, + zone->w_ptr); + status = NVME_ZONE_INVALID_WRITE; + } else if (unlikely(slba + nlb > bndry)) { + status = NVME_ZONE_BOUNDARY_ERROR; + } } } From patchwork Tue Jan 26 05:02:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Fomichev X-Patchwork-Id: 12045291 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNWANTED_LANGUAGE_BODY, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 91E79C433DB for ; Tue, 26 Jan 2021 05:07:46 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 17C1F221E7 for ; Tue, 26 Jan 2021 05:07:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 17C1F221E7 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:45612 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l4GZt-0008HM-2c for qemu-devel@archiver.kernel.org; Tue, 26 Jan 2021 00:07:45 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:34674) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l4GVK-0004ar-AF; Tue, 26 Jan 2021 00:03:02 -0500 Received: from esa6.hgst.iphmx.com ([216.71.154.45]:37779) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l4GVI-00071d-43; Tue, 26 Jan 2021 00:03:01 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1611637381; x=1643173381; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=DmTUrqYYwUpxdJYIRerxbN/Gkdmpgr5jd5TqXbBcEyU=; b=nDXy51pq+SDundHy+zJFxdcHudC/e6MIgLiL9TkNVE4WLrAotUaTPnks Jc/rfAD+WiYyKkT9RCdXedxl4Ab0IlwLbK4MyPzfA5j8OH8o4Ik2PrOlp Jvb3hsBdxuLIs3mdAJzFZw/2B2l62uzVEF25r3py8kNsHTMhtqsBx6WQD xgRO0MPYyFWaCK7qTfQP+2O/szkzlfzy8sk/yWVw1SYnvk1+4GBmK5IX8 VIdnGCam54Hs6YJDmpNDGecH6qbfGEAfQizQZJoMU5bNmwevhAIfqj8FZ GqUMgWUOYkka0ZW86qrD5jEnBAKXOj2VhTAdC/oXnQDOHOR3TsIw1w0NL A==; IronPort-SDR: sJys/COk46y1BSJ7a5KMzW6NL0AhTO4G2chiNfmTFka6sMRp+OhcDJ6iTumoCvqZttyfKBFuml 3xkx2u3gHEuywgYT8QM9+MM/D2MdTa34BM6i0LwE1VOoX6V+nav6Mz8G5AymOxQCCeVvGWuO7r 4NbG2HjTvl/CjI8sZKHld7y7ekBu76xda7Y8NyTbZ28R1IdyuPhmT9Zlsp4T4bPyR29xflW1S4 1THUpwAga+nGagaxxQz8Y/b1yS1ZVCCFk1RRg/cPI7NQFfJi/jm49L2LV4a4FRklN0MjF/i8uf oOI= X-IronPort-AV: E=Sophos;i="5.79,375,1602518400"; d="scan'208";a="159493365" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 26 Jan 2021 13:03:00 +0800 IronPort-SDR: Om6iSOPGGa2uy/m2x19u2ATNPGYP1LKTmgjPNh/VL3i9oZa1325sjoRf7n3nu5K8L068mxXKdD 1lyaklCH6NxUv8VZ4VmHuLH0XXsFeyJ0L8KnixAxQZ0Mt95HyMvMKNfLBFvOgmiWWgMNT2OWMk XWjCi/D8x/h6xd4Q2aAiwjgw8k3KTXlIARJoVrj8xTYpWxBAKih8WDh5VV71j+fMhWp9NWygwM qBAkVHWmChrzCIa9QC6pXcG0SJmgErmUkUO7l3R7u6rTt3i5mTDCr13Qj7wMxl/e7dOOBgNMKn Ojs9294DKWN+2y/svn1Lgh81 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jan 2021 20:47:26 -0800 IronPort-SDR: cKDfX0HMx+NBDLYBCBlf4J8ChoPhmB2sG8SLhp8X1onjcgKv5R7dj3m2zVWtHnDISdkuuaGvpZ WLbHhu2O6cJJtRgvnJKq63MG+xMoqUDdxigiHRjl+SQqX/QneahET/AL9OeZW+atf4hYqTfm/x 4RCMdO8kFvq/b8/3MdWhmT9o1B2wGplOP52SfT3txwwnWrpoDX2qMMAuTtjL9ScMn4fEKD0nkz ZskcF9VzJLgH/jLzn+Kn/ackMintaUfryB9ECiL/6UesPazsplXv09kBffks8bPdUhRQTMCBgm q+U= WDCIronportException: Internal Received: from unknown (HELO redsun50.ssa.fujisawa.hgst.com) ([10.149.66.24]) by uls-op-cesaip02.wdc.com with ESMTP; 25 Jan 2021 21:02:55 -0800 From: Dmitry Fomichev To: Klaus Jensen , Keith Busch , Kevin Wolf , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Max Reitz , qemu-devel@nongnu.org Subject: [PATCH 3/3] hw/block/nvme: Add trace events for zone boundary violations Date: Tue, 26 Jan 2021 14:02:48 +0900 Message-Id: <20210126050248.9077-4-dmitry.fomichev@wdc.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20210126050248.9077-1-dmitry.fomichev@wdc.com> References: <20210126050248.9077-1-dmitry.fomichev@wdc.com> MIME-Version: 1.0 Received-SPF: pass client-ip=216.71.154.45; envelope-from=prvs=653775e38=dmitry.fomichev@wdc.com; helo=esa6.hgst.iphmx.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Dmitry Fomichev , Niklas Cassel , Damien Le Moal , qemu-block@nongnu.org Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Add three new trace events to be raised in case of zone boundary violations during Read, Write(Zeroes) and Zone Append. Signed-off-by: Dmitry Fomichev --- hw/block/nvme.c | 8 ++++++-- hw/block/trace-events | 3 +++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/hw/block/nvme.c b/hw/block/nvme.c index b712634c27..4059bd72e6 100644 --- a/hw/block/nvme.c +++ b/hw/block/nvme.c @@ -1148,6 +1148,8 @@ static uint16_t nvme_check_zone_write(NvmeCtrl *n, NvmeNamespace *ns, trace_pci_nvme_err_append_not_at_start(slba, zone->d.zslba); status = NVME_INVALID_FIELD; } else if (unlikely(zone->w_ptr + nlb > bndry)) { + trace_pci_nvme_err_append_across_boundary(slba, nlb, + zone->w_ptr, bndry); status = NVME_ZONE_BOUNDARY_ERROR; } else if (nvme_l2b(ns, nlb) > (n->page_size << n->zasl)) { trace_pci_nvme_err_append_too_large(slba, nlb, n->zasl); @@ -1159,6 +1161,7 @@ static uint16_t nvme_check_zone_write(NvmeCtrl *n, NvmeNamespace *ns, zone->w_ptr); status = NVME_ZONE_INVALID_WRITE; } else if (unlikely(slba + nlb > bndry)) { + trace_pci_nvme_err_write_across_boundary(slba, nlb, bndry); status = NVME_ZONE_BOUNDARY_ERROR; } } @@ -1200,9 +1203,10 @@ static uint16_t nvme_check_zone_read(NvmeNamespace *ns, uint64_t slba, status = nvme_check_zone_state_for_read(zone); if (status != NVME_SUCCESS) { - ; + trace_pci_nvme_err_zone_read_not_ok(slba, nlb, status); } else if (unlikely(end > bndry)) { if (!ns->params.cross_zone_read) { + trace_pci_nvme_err_read_across_boundary(slba, nlb, bndry); status = NVME_ZONE_BOUNDARY_ERROR; } else { /* @@ -1213,6 +1217,7 @@ static uint16_t nvme_check_zone_read(NvmeNamespace *ns, uint64_t slba, zone++; status = nvme_check_zone_state_for_read(zone); if (status != NVME_SUCCESS) { + trace_pci_nvme_err_zone_read_not_ok(slba, nlb, status); break; } } while (end > nvme_zone_rd_boundary(ns, zone)); @@ -1624,7 +1629,6 @@ static uint16_t nvme_read(NvmeCtrl *n, NvmeRequest *req) if (ns->params.zoned) { status = nvme_check_zone_read(ns, slba, nlb); if (status != NVME_SUCCESS) { - trace_pci_nvme_err_zone_read_not_ok(slba, nlb, status); goto invalid; } } diff --git a/hw/block/trace-events b/hw/block/trace-events index 955ee4860f..18bbe560fc 100644 --- a/hw/block/trace-events +++ b/hw/block/trace-events @@ -127,6 +127,9 @@ pci_nvme_err_unaligned_zone_cmd(uint8_t action, uint64_t slba, uint64_t zslba) " pci_nvme_err_invalid_zone_state_transition(uint8_t action, uint64_t slba, uint8_t attrs) "action=0x%"PRIx8", slba=%"PRIu64", attrs=0x%"PRIx32"" pci_nvme_err_write_not_at_wp(uint64_t slba, uint64_t zone, uint64_t wp) "writing at slba=%"PRIu64", zone=%"PRIu64", but wp=%"PRIu64"" pci_nvme_err_append_not_at_start(uint64_t slba, uint64_t zone) "appending at slba=%"PRIu64", but zone=%"PRIu64"" +pci_nvme_err_append_across_boundary(uint64_t slba, uint32_t nlb, uint64_t wp, uint64_t bndry) "slba=%"PRIu64", nlb=%"PRIu32", w_ptr=%"PRIu64", bndry=%"PRIu64"" +pci_nvme_err_write_across_boundary(uint64_t slba, uint32_t nlb, uint64_t bndry) "slba=%"PRIu64", nlb=%"PRIu32", bndry=%"PRIu64"" +pci_nvme_err_read_across_boundary(uint64_t slba, uint32_t nlb, uint64_t bndry) "slba=%"PRIu64", nlb=%"PRIu32", bndry=%"PRIu64"" pci_nvme_err_zone_write_not_ok(uint64_t slba, uint32_t nlb, uint32_t status) "slba=%"PRIu64", nlb=%"PRIu32", status=0x%"PRIx16"" pci_nvme_err_zone_read_not_ok(uint64_t slba, uint32_t nlb, uint32_t status) "slba=%"PRIu64", nlb=%"PRIu32", status=0x%"PRIx16"" pci_nvme_err_append_too_large(uint64_t slba, uint32_t nlb, uint8_t zasl) "slba=%"PRIu64", nlb=%"PRIu32", zasl=%"PRIu8""