From patchwork Fri Jan 15 03:27:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: zhenwei pi X-Patchwork-Id: 12021291 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 6EEBDC433E0 for ; Fri, 15 Jan 2021 03:28:23 +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 A206120825 for ; Fri, 15 Jan 2021 03:28:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A206120825 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=bytedance.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:44534 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l0Fmf-0007KJ-DH for qemu-devel@archiver.kernel.org; Thu, 14 Jan 2021 22:28:21 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50414) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l0Flf-0005vV-0T for qemu-devel@nongnu.org; Thu, 14 Jan 2021 22:27:19 -0500 Received: from mail-pf1-x436.google.com ([2607:f8b0:4864:20::436]:45715) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1l0Flc-0000fm-Oy for qemu-devel@nongnu.org; Thu, 14 Jan 2021 22:27:18 -0500 Received: by mail-pf1-x436.google.com with SMTP id c13so4603597pfi.12 for ; Thu, 14 Jan 2021 19:27:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Ew8cu4iWibVSoFd8U1aw0x9TqKwKGBm+oggzSrlqzRs=; b=zkwQhwHW56AgBn3/EpEYzRbMQrFN7wF+lsCPVzdIwESowFCV60ySH4EdeM6E5a+qXp JmJ7bD0R8bSqqLzvbxcNWFLZ01K3t4Fap6BebcrdPeipiKQ5R11o4AVQB4IIDL6GAtAV twLYe1C/upJ5shvZPY0gzG727xWP/I7qxpww0y69Cpkurn8cdwD49PTVjFzwEmlo2nEz WxIwta3JgxUT+Zf0dW+qYQ09DX0cglHHMI8glb8d17rhxswaCh7WWp6H8AyGkEIx7V8x XbHbAJZoD/bPmviwMRBdxx9GGIh6UrcUz5ekHsdZuYMLaPawfFbbyPJ3kHLSjF5ZLZv9 UkzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Ew8cu4iWibVSoFd8U1aw0x9TqKwKGBm+oggzSrlqzRs=; b=FZK9HbJdfNWfz2AnEiYtu/eknxCV33ZjNmQWfuY8HZer3GtyxwGlZ20jCC0dtKZMSa bhMaaCXb8KYsktMhEADNuUV2a704RpbkDsP47ANHC9dgychO9N9SgiZebeKgaGvyAw6+ BIPB48F7hYdOm/AKzheBJyEENolwTPJqSL/IKQ4kNeKIX7gLJC6GU4JdABAW/toLB5ZT lnoNbHIM/rBJBUzH40QVgnsSTW7ZlL2+JewXVoZe5pbNZyz27evHxRYublJZxEidOpSD eEd7B0+KCiVJUF+fLpXmqT2CZEtv0hXKKP3Uj6TFaIwsX9T2g1DcFjtNktvoLxv0iPD+ gBsQ== X-Gm-Message-State: AOAM532aH4Tx8DnBNQWU5o0Yq/mEimH83DECrm/+2+WISZt15BCKYo47 IEWSA6YoTeqzzUsV6Qy93ynm0w== X-Google-Smtp-Source: ABdhPJz2mzt58x3F961KTfvbvefute37Ujx6BR5hwBiWsRlFEdvuyC/4nIC2+Z7WHhAyt5oYUbRYvw== X-Received: by 2002:a62:ca:0:b029:19e:67a9:f0f2 with SMTP id 193-20020a6200ca0000b029019e67a9f0f2mr10485116pfa.60.1610681235475; Thu, 14 Jan 2021 19:27:15 -0800 (PST) Received: from always-libai.bytedance.net ([61.120.150.71]) by smtp.gmail.com with ESMTPSA id j16sm6583662pjj.18.2021.01.14.19.27.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Jan 2021 19:27:14 -0800 (PST) From: zhenwei pi To: kbusch@kernel.org, its@irrelevant.dk, kwolf@redhat.com, mreitz@redhat.com Subject: [PATCH v4 1/3] block/nvme: introduce bit 5 for critical warning Date: Fri, 15 Jan 2021 11:27:00 +0800 Message-Id: <20210115032702.466631-2-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210115032702.466631-1-pizhenwei@bytedance.com> References: <20210115032702.466631-1-pizhenwei@bytedance.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::436; envelope-from=pizhenwei@bytedance.com; helo=mail-pf1-x436.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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: zhenwei pi , philmd@redhat.com, qemu-devel@nongnu.org, qemu-block@nongnu.org Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" According to NVMe spec 1.4 section , introduce bit 5 for "Persistent Memory Region has become read-only or unreliable". Signed-off-by: zhenwei pi Reviewed-by: Philippe Mathieu-Daudé --- include/block/nvme.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/block/nvme.h b/include/block/nvme.h index 9494246f1f..0baf4b27cd 100644 --- a/include/block/nvme.h +++ b/include/block/nvme.h @@ -789,6 +789,7 @@ enum NvmeSmartWarn { NVME_SMART_RELIABILITY = 1 << 2, NVME_SMART_MEDIA_READ_ONLY = 1 << 3, NVME_SMART_FAILED_VOLATILE_MEDIA = 1 << 4, + NVME_SMART_PMR_UNRELIABLE = 1 << 5, }; typedef struct NvmeEffectsLog { From patchwork Fri Jan 15 03:27:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: zhenwei pi X-Patchwork-Id: 12021295 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 B15FDC433DB for ; Fri, 15 Jan 2021 03:28:35 +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 E5DBF20825 for ; Fri, 15 Jan 2021 03:28:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E5DBF20825 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=bytedance.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:45066 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l0Fmr-0007XQ-Qu for qemu-devel@archiver.kernel.org; Thu, 14 Jan 2021 22:28:33 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50438) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l0Flj-00062T-1G for qemu-devel@nongnu.org; Thu, 14 Jan 2021 22:27:23 -0500 Received: from mail-pj1-x102d.google.com ([2607:f8b0:4864:20::102d]:36307) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1l0Flh-0000hS-9R for qemu-devel@nongnu.org; Thu, 14 Jan 2021 22:27:22 -0500 Received: by mail-pj1-x102d.google.com with SMTP id l23so4409015pjg.1 for ; Thu, 14 Jan 2021 19:27:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=jNuSz+nFqys03+vNsU/AA8pxB86XfjreXgHeY68HruQ=; b=no2QQ7dfLQKBvb2ALUAkfmZV2cCaHUyk1rZDOcjS9gO0gId7gKc2/hpA/OKmmlDnGc Kg52go37vOV4/98VAAov56esz4qKl5+uaVNOvZC6TFS9fCTpVfowz0D+Sh4eZUrXhOSa PDXmBb6nmc8uLsbF9Aw+Ymoqu5eEPXEBG6z2wP9PVAZJzNUVe54P8rhBMQSQjWUKaQHx 5ZwLdIHETW0uyK1t6l9lnOmLUJ70FKmcJpxbcKVErL59TGn6ILeEl+V/NniqCXL8O4MB 5/gDw0sVq/t+T61/Nki6vo1pYIIeeaZmgeJs83XFBXYdovxvhcWmPLl2lGfDHr0rwSwq 5GhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=jNuSz+nFqys03+vNsU/AA8pxB86XfjreXgHeY68HruQ=; b=AELJwEUtyUeb6D+YN2cLOaisDZJLSN9ZczMeYVKO1xbbeqnTz6uSq3dtqawFcT/ob+ sH9BJW90K1OkZULXBdHax6arx8fQ0mOBFi1BqhJKYyEKIjSxEIe7lyfpRmy1yYsV9TsF 4omPpdrDRXU9jF27vOWm6hAEN01b2/fhpmu1qyD4ro2/AW4ywMjGfspVVOQ7hqRQDEdM kXvdowD9SNcJMJivVv2cvHB4yZqTBjJGUIyfAaySUPvk+1WL70bbAmKiMoNFtbf3SBtv XNZ8MR5dIZcm8/QkCXO3k/Et9b+IvhitxBCcC+CQBldtb5PLSB05+BPEaXpEuHj2HkVy SeLw== X-Gm-Message-State: AOAM530RHmjkagbXmbNzQ5UMqgSekEeltzQbKlNHx11ZVjcEouYvx0Y6 zAJv8R4TiGXJTMcGITkGjnlJLg== X-Google-Smtp-Source: ABdhPJzS/fUj/CuviCgZ/WTSyJE0+7tRGeCCo5GO5pwQLMYRcF3Qa34LNc30QKihqaFskaWjs0uAfw== X-Received: by 2002:a17:90a:f0c5:: with SMTP id fa5mr8396621pjb.144.1610681239952; Thu, 14 Jan 2021 19:27:19 -0800 (PST) Received: from always-libai.bytedance.net ([61.120.150.71]) by smtp.gmail.com with ESMTPSA id j16sm6583662pjj.18.2021.01.14.19.27.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Jan 2021 19:27:19 -0800 (PST) From: zhenwei pi To: kbusch@kernel.org, its@irrelevant.dk, kwolf@redhat.com, mreitz@redhat.com Subject: [PATCH v4 2/3] hw/block/nvme: add smart_critical_warning property Date: Fri, 15 Jan 2021 11:27:01 +0800 Message-Id: <20210115032702.466631-3-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210115032702.466631-1-pizhenwei@bytedance.com> References: <20210115032702.466631-1-pizhenwei@bytedance.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102d; envelope-from=pizhenwei@bytedance.com; helo=mail-pj1-x102d.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=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: zhenwei pi , philmd@redhat.com, qemu-devel@nongnu.org, qemu-block@nongnu.org Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" There is a very low probability that hitting physical NVMe disk hardware critical warning case, it's hard to write & test a monitor agent service. For debugging purposes, add a new 'smart_critical_warning' property to emulate this situation. The orignal version of this change is implemented by adding a fixed property which could be initialized by QEMU command line. Suggested by Philippe & Klaus, rework like current version. Test with this patch: 1, change smart_critical_warning property for a running VM: #virsh qemu-monitor-command nvme-upstream '{ "execute": "qom-set", "arguments": { "path": "/machine/peripheral-anon/device[0]", "property": "smart_critical_warning", "value":16 } }' 2, run smartctl in guest #smartctl -H -l error /dev/nvme0n1 === START OF SMART DATA SECTION === SMART overall-health self-assessment test result: FAILED! - volatile memory backup device has failed Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: zhenwei pi --- hw/block/nvme.c | 45 +++++++++++++++++++++++++++++++++++++++++--- hw/block/nvme.h | 1 + include/block/nvme.h | 1 + 3 files changed, 44 insertions(+), 3 deletions(-) diff --git a/hw/block/nvme.c b/hw/block/nvme.c index 0854ee3072..2d71ebeb30 100644 --- a/hw/block/nvme.c +++ b/hw/block/nvme.c @@ -2425,6 +2425,7 @@ static uint16_t nvme_smart_info(NvmeCtrl *n, uint8_t rae, uint32_t buf_len, } trans_len = MIN(sizeof(smart) - off, buf_len); + smart.critical_warning = n->smart_critical_warning; smart.data_units_read[0] = cpu_to_le64(DIV_ROUND_UP(stats.units_read, 1000)); @@ -4346,6 +4347,40 @@ static Property nvme_props[] = { DEFINE_PROP_END_OF_LIST(), }; +static void nvme_get_smart_warning(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + NvmeCtrl *n = NVME(obj); + uint8_t value = n->smart_critical_warning; + + visit_type_uint8(v, name, &value, errp); +} + +static void nvme_set_smart_warning(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + NvmeCtrl *n = NVME(obj); + uint8_t value, cap = 0; + + if (!visit_type_uint8(v, name, &value, errp)) { + return; + } + + cap = NVME_SMART_SPARE | NVME_SMART_TEMPERATURE | NVME_SMART_RELIABILITY + | NVME_SMART_MEDIA_READ_ONLY | NVME_SMART_FAILED_VOLATILE_MEDIA; + if (NVME_CAP_PMR(n->bar.cap)) { + cap |= NVME_SMART_PMR_UNRELIABLE; + } + + if ((value & cap) != value) { + error_setg(errp, "unsupported smart critical warning bits: 0x%x", + value & ~cap); + return; + } + + n->smart_critical_warning = value; +} + static const VMStateDescription nvme_vmstate = { .name = "nvme", .unmigratable = 1, @@ -4369,13 +4404,17 @@ static void nvme_class_init(ObjectClass *oc, void *data) static void nvme_instance_init(Object *obj) { - NvmeCtrl *s = NVME(obj); + NvmeCtrl *n = NVME(obj); - if (s->namespace.blkconf.blk) { - device_add_bootindex_property(obj, &s->namespace.blkconf.bootindex, + if (n->namespace.blkconf.blk) { + device_add_bootindex_property(obj, &n->namespace.blkconf.bootindex, "bootindex", "/namespace@1,0", DEVICE(obj)); } + + object_property_add(obj, "smart_critical_warning", "uint8", + nvme_get_smart_warning, + nvme_set_smart_warning, NULL, NULL); } static const TypeInfo nvme_info = { diff --git a/hw/block/nvme.h b/hw/block/nvme.h index b7fbcca39d..bd5a2b416f 100644 --- a/hw/block/nvme.h +++ b/hw/block/nvme.h @@ -145,6 +145,7 @@ typedef struct NvmeCtrl { uint64_t timestamp_set_qemu_clock_ms; /* QEMU clock time */ uint64_t starttime_ms; uint16_t temperature; + uint8_t smart_critical_warning; HostMemoryBackend *pmrdev; diff --git a/include/block/nvme.h b/include/block/nvme.h index 0baf4b27cd..520bc2e4cf 100644 --- a/include/block/nvme.h +++ b/include/block/nvme.h @@ -60,6 +60,7 @@ enum NvmeCapMask { #define NVME_CAP_CSS(cap) (((cap) >> CAP_CSS_SHIFT) & CAP_CSS_MASK) #define NVME_CAP_MPSMIN(cap)(((cap) >> CAP_MPSMIN_SHIFT) & CAP_MPSMIN_MASK) #define NVME_CAP_MPSMAX(cap)(((cap) >> CAP_MPSMAX_SHIFT) & CAP_MPSMAX_MASK) +#define NVME_CAP_PMR(cap) (((cap) >> CAP_PMR_SHIFT) & CAP_PMR_MASK) #define NVME_CAP_SET_MQES(cap, val) (cap |= (uint64_t)(val & CAP_MQES_MASK) \ << CAP_MQES_SHIFT) From patchwork Fri Jan 15 03:27:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhenwei pi X-Patchwork-Id: 12021297 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 22442C433E0 for ; Fri, 15 Jan 2021 03:30:02 +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 7AEAE23AAC for ; Fri, 15 Jan 2021 03:30:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7AEAE23AAC Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=bytedance.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:49386 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l0FoG-0000tf-Cy for qemu-devel@archiver.kernel.org; Thu, 14 Jan 2021 22:30:00 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50466) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l0Fln-0006Ft-SW for qemu-devel@nongnu.org; Thu, 14 Jan 2021 22:27:27 -0500 Received: from mail-pg1-x536.google.com ([2607:f8b0:4864:20::536]:43418) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1l0Fll-0000iu-C5 for qemu-devel@nongnu.org; Thu, 14 Jan 2021 22:27:27 -0500 Received: by mail-pg1-x536.google.com with SMTP id n10so5118178pgl.10 for ; Thu, 14 Jan 2021 19:27:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kOtGR0l9culuvWtAiNHBapDt7mXNg97Y6uu3/6Dz/7U=; b=GPnylN9A1FyxFKOSNxWSHtagPQlW9mmCwTJ/LdLniGMwS+xmZ03Q7HeopyosJIGUou YgFraWluaO152KqbsEIoue5LERtDIy6Jww+ykzkWKnYSfzj4hCCXY20l4VU6i1CACVBf UUyaSBTQ7Tdsn+a5T/4+T9HaV1/HPjdRGjnq0+ugFVFX59XaY2/YCy8Va6gVXumgtuxK FfsrtJ2duGn4D48vTn3x3DIKx5ppXOy/t6jQr1Kv+witH/03vvbhD6ajMkf4nCLo5ytb o66rU80+Q9Rl/oaZePVzUlxHhQRhJniEJa60PBEoqBEQe34OP5rXLMnK8BiWbc/HDFCV YhaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=kOtGR0l9culuvWtAiNHBapDt7mXNg97Y6uu3/6Dz/7U=; b=a88WOeGeDIWgZ6lYfZBJyi9y4EcfveuZfelt4zvG+iLsflk9mTIFWAk0SiS7AnBngq nGtBtd3F381rj7fHUO0/CtV4DciGA6ULbmwrdBvNe3R5TbUVCQQ5x3Y9ci3jhzudA81y G71bOt9sO6Q2Gi0UGkLJwTOk2+ILzWMu2QURjMCNDOech7XtG5EihM/mlRuj8sivVG5w NviuvxD4Ur4dxrpyvrZVY5h5aRzRtnd/yJUFfBWNsNNjbGW9JRb4rRed9EbZEIacK7OY iXbbah5KQwqZcGpXi3eBLhdpXub6NDuQeY8WxVV5Zx15HKHLaBwxU0QHjIwzvf8Wdcp7 /9Zw== X-Gm-Message-State: AOAM531uykwUg8AJBRYkVHKl3hL+pWYNYfSI3DBvyh7zJA3IEv4Pbkqu 8KORFRQ4dNBljdENjiIjOE3ang== X-Google-Smtp-Source: ABdhPJwM9rsXFl56F70SLLbwFly9oNAr1XoYTMCwyQ3mxdwpQfAkQJlFAgTjoiTIOTepHk0P1+bYKw== X-Received: by 2002:a62:5205:0:b029:19e:a0f:2c81 with SMTP id g5-20020a6252050000b029019e0a0f2c81mr10568707pfb.50.1610681244181; Thu, 14 Jan 2021 19:27:24 -0800 (PST) Received: from always-libai.bytedance.net ([61.120.150.71]) by smtp.gmail.com with ESMTPSA id j16sm6583662pjj.18.2021.01.14.19.27.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Jan 2021 19:27:23 -0800 (PST) From: zhenwei pi To: kbusch@kernel.org, its@irrelevant.dk, kwolf@redhat.com, mreitz@redhat.com Subject: [PATCH v4 3/3] hw/blocl/nvme: trigger async event during injecting smart warning Date: Fri, 15 Jan 2021 11:27:02 +0800 Message-Id: <20210115032702.466631-4-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210115032702.466631-1-pizhenwei@bytedance.com> References: <20210115032702.466631-1-pizhenwei@bytedance.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::536; envelope-from=pizhenwei@bytedance.com; helo=mail-pg1-x536.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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: zhenwei pi , philmd@redhat.com, qemu-devel@nongnu.org, qemu-block@nongnu.org Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" During smart critical warning injection by setting property from QMP command, also try to trigger asynchronous event. Suggested by Keith, if a event has already been raised, there is no need to enqueue the duplicate event any more. Signed-off-by: zhenwei pi --- hw/block/nvme.c | 48 +++++++++++++++++++++++++++++++++++++------- include/block/nvme.h | 1 + 2 files changed, 42 insertions(+), 7 deletions(-) diff --git a/hw/block/nvme.c b/hw/block/nvme.c index 2d71ebeb30..f72a30b499 100644 --- a/hw/block/nvme.c +++ b/hw/block/nvme.c @@ -980,6 +980,35 @@ static void nvme_enqueue_event(NvmeCtrl *n, uint8_t event_type, nvme_process_aers(n); } +static void nvme_smart_event(NvmeCtrl *n, uint8_t event) +{ + uint8_t aer_info; + + /* Ref SPEC */ + if (!(NVME_AEC_SMART(n->features.async_config) & event)) { + return; + } + + switch (event) { + case NVME_SMART_SPARE: + aer_info = NVME_AER_INFO_SMART_SPARE_THRESH; + break; + case NVME_SMART_TEMPERATURE: + aer_info = NVME_AER_INFO_SMART_TEMP_THRESH; + break; + case NVME_SMART_RELIABILITY: + case NVME_SMART_MEDIA_READ_ONLY: + case NVME_SMART_FAILED_VOLATILE_MEDIA: + case NVME_SMART_PMR_UNRELIABLE: + aer_info = NVME_AER_INFO_SMART_RELIABILITY; + break; + default: + return; + } + + nvme_enqueue_event(n, NVME_AER_TYPE_SMART, aer_info, NVME_LOG_SMART_INFO); +} + static void nvme_clear_events(NvmeCtrl *n, uint8_t event_type) { n->aer_mask &= ~(1 << event_type); @@ -3238,12 +3267,9 @@ static uint16_t nvme_set_feature(NvmeCtrl *n, NvmeRequest *req) return NVME_INVALID_FIELD | NVME_DNR; } - if (((n->temperature >= n->features.temp_thresh_hi) || - (n->temperature <= n->features.temp_thresh_low)) && - NVME_AEC_SMART(n->features.async_config) & NVME_SMART_TEMPERATURE) { - nvme_enqueue_event(n, NVME_AER_TYPE_SMART, - NVME_AER_INFO_SMART_TEMP_THRESH, - NVME_LOG_SMART_INFO); + if ((n->temperature >= n->features.temp_thresh_hi) || + (n->temperature <= n->features.temp_thresh_low)) { + nvme_smart_event(n, NVME_AER_INFO_SMART_TEMP_THRESH); } break; @@ -4360,7 +4386,7 @@ static void nvme_set_smart_warning(Object *obj, Visitor *v, const char *name, void *opaque, Error **errp) { NvmeCtrl *n = NVME(obj); - uint8_t value, cap = 0; + uint8_t value, old_value, cap = 0, index, event; if (!visit_type_uint8(v, name, &value, errp)) { return; @@ -4378,7 +4404,15 @@ static void nvme_set_smart_warning(Object *obj, Visitor *v, const char *name, return; } + old_value = n->smart_critical_warning; n->smart_critical_warning = value; + + /* only inject new bits of smart critical warning */ + for (index = 0; index < NVME_SMART_WARN_MAX; index++) { + event = 1 << index; + if (value & ~old_value & event) + nvme_smart_event(n, event); + } } static const VMStateDescription nvme_vmstate = { diff --git a/include/block/nvme.h b/include/block/nvme.h index 520bc2e4cf..0adccaf5b4 100644 --- a/include/block/nvme.h +++ b/include/block/nvme.h @@ -784,6 +784,7 @@ typedef struct QEMU_PACKED NvmeSmartLog { uint8_t reserved2[320]; } NvmeSmartLog; +#define NVME_SMART_WARN_MAX 6 enum NvmeSmartWarn { NVME_SMART_SPARE = 1 << 0, NVME_SMART_TEMPERATURE = 1 << 1,