From patchwork Wed Apr 26 02:14:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Davidlohr Bueso X-Patchwork-Id: 13223987 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C6C6BC77B73 for ; Wed, 26 Apr 2023 02:46:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230435AbjDZCqM (ORCPT ); Tue, 25 Apr 2023 22:46:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38698 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239047AbjDZCqK (ORCPT ); Tue, 25 Apr 2023 22:46:10 -0400 Received: from bird.elm.relay.mailchannels.net (bird.elm.relay.mailchannels.net [23.83.212.17]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EA6AD189 for ; Tue, 25 Apr 2023 19:46:08 -0700 (PDT) X-Sender-Id: dreamhost|x-authsender|dave@stgolabs.net Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 0DE6264201F; Wed, 26 Apr 2023 02:46:08 +0000 (UTC) Received: from pdx1-sub0-mail-a207.dreamhost.com (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 7014364203A; Wed, 26 Apr 2023 02:46:07 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1682477167; a=rsa-sha256; cv=none; b=e5mNtXPZ+0aLOIulmKUYrntmo6ZZlcm9bRi9aZosI61/Fs3mRJgPMdHxTy7aQGFjzgW9y4 G+rq9Rcd0rKIgdrtv/URaV5jYB10fG2aYBXcHROoNGW/PV6VT6nuuL2TNvZgZFrZ7yHmgo rnTeHvOkTjUHCC2WdSxdE2kBL2Xarih/tiLA9KNEPUhWcsidXsCMiLVe8WIxoBikTsijKH M4KP2tGx4TQmrT18qqJ/MHIgBPppNrJL5PTcDWMqzWQGHqFLwN2pNmtf2KUarYYflZwKmK yqoaq9veMrqoCJMmcgubo5sNlRlXCuCQD8f5Th3ItF7Uf+FwBr0/KQ6HaZEnTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1682477167; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=cDlBBkIQrKGmh/G7kK0lYtW2tyvUghmmcSfwFxPE5Lc=; b=TO0yevNRjJZw2tqFmB5zLiPZY7x5MVIQAKEqka3OFmiHRwjXAC/Px6w85CJ3lgKWqCbu9N ZVG3NjLPxzzfgnHFughdIMXCJ8d1Vv1WjC1m/1AL8yKrL94yhixc9dRNMZTuuWqXSi5dUn i85Ojc/TBhrTXrccw3S+1aiuZGdW7uEl9TbO+MzlFLSwWm1OKyEENNJLmBNQ9yMLWyECI2 HsBr4D5TV2g8IK70jQaleH6IYBCg/AzRy8v4sBH0KuEfZufaQTUdwEQ0aurNCaUpocU9+Y TVVpwC9P1IhIuka6WZWmjwYlN9neHqKrf3iiPOtpAIrAxsTy0RQs+uOUIAoQKQ== ARC-Authentication-Results: i=1; rspamd-7f66b7b68c-lplmj; auth=pass smtp.auth=dreamhost smtp.mailfrom=dave@stgolabs.net X-Sender-Id: dreamhost|x-authsender|dave@stgolabs.net X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|dave@stgolabs.net X-MailChannels-Auth-Id: dreamhost X-Suffer-Zesty: 14151f2a617b606e_1682477167833_1586177106 X-MC-Loop-Signature: 1682477167833:3360432559 X-MC-Ingress-Time: 1682477167833 Received: from pdx1-sub0-mail-a207.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.109.138.52 (trex/6.7.2); Wed, 26 Apr 2023 02:46:07 +0000 Received: from localhost.localdomain (ip72-199-50-187.sd.sd.cox.net [72.199.50.187]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: dave@stgolabs.net) by pdx1-sub0-mail-a207.dreamhost.com (Postfix) with ESMTPSA id 4Q5jt659lpz4s; Tue, 25 Apr 2023 19:46:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=stgolabs.net; s=dreamhost; t=1682477167; bh=cDlBBkIQrKGmh/G7kK0lYtW2tyvUghmmcSfwFxPE5Lc=; h=From:To:Cc:Subject:Date:Content-Transfer-Encoding; b=bOx4cn/ofOIqIhnxtd+8YuP6TGsv4TftkYcvDf7ingxOcCMZw2ENF/PBdQGj6b86O n0fwnIWwYAbLS3pF1iXR+In2tmSzavF8cW+9rGYWWf+sDudu0/kDQHliYe+lFiSuWU L1GgqgT+AQlxhqO/I6Nln8t3bWwFR7CUEqfqxxQ6RhyGIKzN6Qw496xogdz8HWeofu PHuceEjd25yMYU+Lh8QaYbT1qG5cbTo22g7IHPl9hG/W5HGhIhqIOWhfd6ZFm6kVuk ajd2BxlPlk+JVaoRty2RTauw9/hEOa+H6sqZdmVSD3gWU7QB41w/kYtcUJ7cJpwMFR H+NOV/+8yhi/Q== From: Davidlohr Bueso To: Jonathan.Cameron@huawei.com Cc: alison.schofield@intel.com, ira.weiny@intel.com, dan.j.williams@intel.com, fan.ni@samsung.com, a.manzanares@samsung.com, dave@stgolabs.net, linux-cxl@vger.kernel.org Subject: [PATCH 1/3] hw/cxl: Add get scan media capabilities mailbox command support Date: Tue, 25 Apr 2023 19:14:16 -0700 Message-Id: <20230426021418.10186-2-dave@stgolabs.net> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230426021418.10186-1-dave@stgolabs.net> References: <20230426021418.10186-1-dave@stgolabs.net> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-cxl@vger.kernel.org Use simple heuristics to determine the cost of scanning any given chunk, assuming cost is even across the whole device. Signed-off-by: Davidlohr Bueso --- hw/cxl/cxl-mailbox-utils.c | 45 +++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/hw/cxl/cxl-mailbox-utils.c b/hw/cxl/cxl-mailbox-utils.c index 0849cfbc2a4c..f346aa8ce3b2 100644 --- a/hw/cxl/cxl-mailbox-utils.c +++ b/hw/cxl/cxl-mailbox-utils.c @@ -79,6 +79,7 @@ enum { #define GET_POISON_LIST 0x0 #define INJECT_POISON 0x1 #define CLEAR_POISON 0x2 + #define GET_SCAN_MEDIA_CAPABILITIES 0x3 PHYSICAL_SWITCH = 0x51 #define IDENTIFY_SWITCH_DEVICE 0x0 }; @@ -882,7 +883,7 @@ static CXLRetCode cmd_media_clear_poison(struct cxl_cmd *cmd, return CXL_MBOX_INTERNAL_ERROR; } } - + QLIST_FOREACH(ent, poison_list, node) { /* * Test for contained in entry. Simpler than general case @@ -934,6 +935,45 @@ static CXLRetCode cmd_media_clear_poison(struct cxl_cmd *cmd, return CXL_MBOX_SUCCESS; } +static CXLRetCode +cmd_media_get_scan_media_capabilities(struct cxl_cmd *cmd, + CXLDeviceState *cxl_dstate, uint16_t *len) +{ + struct get_scan_media_capabilities_pl { + uint64_t pa; + uint64_t length; + } QEMU_PACKED; + struct get_scan_media_capabilities_out_pl { + uint32_t estimated_runtime_ms; + } QEMU_PACKED; + struct get_scan_media_capabilities_pl *in = (void *)cmd->payload; + struct get_scan_media_capabilities_out_pl *out = (void *)cmd->payload; + uint64_t query_start; + uint64_t query_length; + + query_start = ldq_le_p(&in->pa); + /* 64 byte alignment required */ + if (query_start & 0x3f) { + return CXL_MBOX_INVALID_INPUT; + } + query_length = ldq_le_p(&in->length) * 64; + + if (query_start + query_length > cxl_dstate->mem_size) { + return CXL_MBOX_INVALID_PA; + } + + /* + * Just use 400 nanosecond access/read latency + 100 ns for + * the cost of updating the poison list. For small enough + * chunks return at least 1 ms. + */ + stq_le_p(&out->estimated_runtime_ms, + MAX(1, query_length * (0.0005L/64))); + + *len = sizeof(*out); + return CXL_MBOX_SUCCESS; +} + #define IMMEDIATE_CONFIG_CHANGE (1 << 1) #define IMMEDIATE_DATA_CHANGE (1 << 2) #define IMMEDIATE_POLICY_CHANGE (1 << 3) @@ -972,6 +1012,9 @@ static struct cxl_cmd cxl_cmd_set[256][256] = { cmd_media_inject_poison, 8, 0 }, [MEDIA_AND_POISON][CLEAR_POISON] = { "MEDIA_AND_POISON_CLEAR_POISON", cmd_media_clear_poison, 72, 0 }, + [MEDIA_AND_POISON][GET_SCAN_MEDIA_CAPABILITIES] = { "MEDIA_AND_POISON_GET_SCAN_MEDIA_CAPABILITIES", + cmd_media_get_scan_media_capabilities, 16, 0 }, + }; static struct cxl_cmd cxl_cmd_set_sw[256][256] = { From patchwork Wed Apr 26 02:14:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Davidlohr Bueso X-Patchwork-Id: 13223989 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EE490C7EE22 for ; Wed, 26 Apr 2023 02:46:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238459AbjDZCqO (ORCPT ); Tue, 25 Apr 2023 22:46:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38702 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239148AbjDZCqL (ORCPT ); Tue, 25 Apr 2023 22:46:11 -0400 Received: from bee.birch.relay.mailchannels.net (bee.birch.relay.mailchannels.net [23.83.209.14]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 64831E4E for ; Tue, 25 Apr 2023 19:46:09 -0700 (PDT) X-Sender-Id: dreamhost|x-authsender|dave@stgolabs.net Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id AAC1214209B; Wed, 26 Apr 2023 02:46:08 +0000 (UTC) Received: from pdx1-sub0-mail-a207.dreamhost.com (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 2484414210F; Wed, 26 Apr 2023 02:46:08 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1682477168; a=rsa-sha256; cv=none; b=L+Yz/lqkY136DmXD1m4H+mgzGH93ujZS30k42QXSQPeRU6Y+b+q+v3vhXCIxqrl4clQy5r KjDwaF0SX2598ZCm4DWIcudl1ph3aG365Bq3TqqwdUVxZTS89ktWwUUWTgt3Xju+c1OzwT J2JF9EmNDQOL3/Z7jX4ta990Kl9EZWCqMqLTjxdhrb9vSGW6HN3dY78F5DptlMSSI8F/eO Adh8uDyVelpxyrLJ8urnxWn15tuF8XeuuIUzscfKrwomCDUaS9KDT4W0FYDt22y8Ojif1Y lHtePhf5JDJ1XV42x9ShQEMTeARf27S/0+KZPxgfOC2pwu9JJaU+RnCwcKeTpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1682477168; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Mo5Jn/1gaGS61VTLzTNXj3Xkfua0BqkOYJZiyRfUnnU=; b=hdm1mx6S502LgalNehdQqeZggLsA5M9jfZcnDap8NV7MkHJhNzQzf4ZAjFdjTePsAhT9zh qSNNL7nmXtKGyNMj39NJ672mRCu/a7iTJ5Ir2HCOOB5jbaB7T+Ps4Std+ite1fYHnGNhEn ROfU1bInQFfK/Ic+Xlw9LnuqABrGdLynVxEn9G42xjVFIJWiTlT+rSGaB2rNsso7pPUpCg S5fHp1/9z6U5lsceYy8JmmddCqOciB1pVA1Fj3rLgu98aEkAKhZGMs0+ihZjW0wfGKiYPH MDnTqOcbJkcjHsXysL9vm4vnU7f9n0a4QfOCHn9swqBGjPQ+BpJSWDFj+UD7Mg== ARC-Authentication-Results: i=1; rspamd-7f66b7b68c-cprm2; auth=pass smtp.auth=dreamhost smtp.mailfrom=dave@stgolabs.net X-Sender-Id: dreamhost|x-authsender|dave@stgolabs.net X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|dave@stgolabs.net X-MailChannels-Auth-Id: dreamhost X-Lettuce-Squirrel: 55846071328113bf_1682477168457_4066903198 X-MC-Loop-Signature: 1682477168457:11221307 X-MC-Ingress-Time: 1682477168456 Received: from pdx1-sub0-mail-a207.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.127.59.20 (trex/6.7.2); Wed, 26 Apr 2023 02:46:08 +0000 Received: from localhost.localdomain (ip72-199-50-187.sd.sd.cox.net [72.199.50.187]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: dave@stgolabs.net) by pdx1-sub0-mail-a207.dreamhost.com (Postfix) with ESMTPSA id 4Q5jt72zcrz9s; Tue, 25 Apr 2023 19:46:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=stgolabs.net; s=dreamhost; t=1682477167; bh=Mo5Jn/1gaGS61VTLzTNXj3Xkfua0BqkOYJZiyRfUnnU=; h=From:To:Cc:Subject:Date:Content-Transfer-Encoding; b=F2JuKiT6P3Iad5qepODOqo4W/Df6gHQhDIVniGb0jSTCmaK69P4oWMYlI7fcUs1ix coeSly9wix9mYun2aKngHc/vS6xsZ7h1G474Nefcrn+PabW4Et7wIERcTpe7XSNMAv uvm5cqPFbYywIOEvoDESnelvK1bheehZ9CYnnfMPARSwjiNYNQQIC5zf/4Zw4NXCAh 658Dq7gagYOD4DLRAZFVfSUSwlu/TlUOgS2RoqkTKU8oJcI3ZSzPSbTRlVTMgVB86j jUqOLgSFYWu3BsG7EkDBI1vysmDeUr72p8gQlvydIXji0mXvriIwY4aafgD5Hz98C/ IyQ5aqYwzcZiQ== From: Davidlohr Bueso To: Jonathan.Cameron@huawei.com Cc: alison.schofield@intel.com, ira.weiny@intel.com, dan.j.williams@intel.com, fan.ni@samsung.com, a.manzanares@samsung.com, dave@stgolabs.net, linux-cxl@vger.kernel.org Subject: [PATCH 2/3] hw/cxl: Add scan media mailbox command support Date: Tue, 25 Apr 2023 19:14:17 -0700 Message-Id: <20230426021418.10186-3-dave@stgolabs.net> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230426021418.10186-1-dave@stgolabs.net> References: <20230426021418.10186-1-dave@stgolabs.net> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-cxl@vger.kernel.org Trigger the background command and when done go about adding entries to the poison list, or not. Randonly decide how many random addresses to generate. Currently never udpate DRAM Event Log. Signed-off-by: Davidlohr Bueso --- hw/cxl/cxl-mailbox-utils.c | 127 +++++++++++++++++++++++++++++++++++- hw/mem/cxl_type3.c | 3 + include/hw/cxl/cxl_device.h | 8 +++ 3 files changed, 135 insertions(+), 3 deletions(-) diff --git a/hw/cxl/cxl-mailbox-utils.c b/hw/cxl/cxl-mailbox-utils.c index f346aa8ce3b2..7f29b840a2c9 100644 --- a/hw/cxl/cxl-mailbox-utils.c +++ b/hw/cxl/cxl-mailbox-utils.c @@ -80,6 +80,7 @@ enum { #define INJECT_POISON 0x1 #define CLEAR_POISON 0x2 #define GET_SCAN_MEDIA_CAPABILITIES 0x3 + #define SCAN_MEDIA 0x4 PHYSICAL_SWITCH = 0x51 #define IDENTIFY_SWITCH_DEVICE 0x0 }; @@ -852,6 +853,9 @@ static CXLRetCode cmd_media_inject_poison(struct cxl_cmd *cmd, */ QLIST_INSERT_HEAD(poison_list, p, node); ct3d->poison_list_cnt++; + if (scan_media_running(cxl_dstate)) { + ct3d->poison_list_dirty = true; + } return CXL_MBOX_SUCCESS; } @@ -932,6 +936,10 @@ static CXLRetCode cmd_media_clear_poison(struct cxl_cmd *cmd, /* Any fragments have been added, free original entry */ g_free(ent); + if (scan_media_running(cxl_dstate)) { + ct3d->poison_list_dirty = true; + } + return CXL_MBOX_SUCCESS; } @@ -974,6 +982,103 @@ cmd_media_get_scan_media_capabilities(struct cxl_cmd *cmd, return CXL_MBOX_SUCCESS; } +static void __do_scan_media(CXLDeviceState *cxl_dstate) +{ + CXLType3Dev *ct3d = container_of(cxl_dstate, CXLType3Dev, cxl_dstate); + CXLPoisonList *poison_list = &ct3d->poison_list; + CXLPoison *ent, *p; + uint64_t dpa = 0; + int n_dpas; + GRand *rand; + + rand = g_rand_new(); + + /* how many dpas to "detect" and add to the poison list */ + n_dpas = g_random_int_range(0, CXL_MBOX_INJECT_POISON_LIMIT/4); + + do { + /* + * TODO: limit it within the device dpa space (same for + * inject poison). For now generate some random address. + */ + retry_dpa: + dpa = (uint64_t)g_rand_int(rand) << 32 |(uint64_t)g_rand_int(rand); + /* 64 byte alignment required */ + if (dpa & 0x3f) { + goto retry_dpa; + } + + QLIST_FOREACH(ent, poison_list, node) { + if (dpa >= ent->start && + dpa + 64 <= ent->start + ent->length) { + goto retry_dpa; + } + } + + p = g_new0(CXLPoison, 1); + + p->length = 64; + p->start = dpa; + p->type = CXL_POISON_TYPE_SCANMEDIA; + + QLIST_INSERT_HEAD(poison_list, p, node); + ct3d->poison_list_cnt++; + } while (--n_dpas); + + g_rand_free(rand); +} + +static CXLRetCode +cmd_media_scan_media(struct cxl_cmd *cmd, + CXLDeviceState *cxl_dstate, uint16_t *len) +{ + struct scan_media_pl { + uint64_t pa; + uint64_t length; + uint8_t flags; + } QEMU_PACKED; + struct scan_media_pl *in = (void *)cmd->payload; + CXLType3Dev *ct3d = container_of(cxl_dstate, CXLType3Dev, cxl_dstate); + uint64_t query_start; + uint64_t query_length; + + query_start = ldq_le_p(&in->pa); + /* 64 byte alignment required */ + if (query_start & 0x3f) { + return CXL_MBOX_INVALID_INPUT; + } + query_length = ldq_le_p(&in->length) * 64; + + /* + * TODO: Any previous Scan Media results are discarded by + * the device upon receiving a new Scan Media command. + */ + + /* + * The host should use this command only if the poison list + * has overflowed and is no longer a complete list of the + * memory errors that exist on the media. + */ + if (ct3d->poison_list_cnt == CXL_POISON_LIST_LIMIT) { + ct3d->poison_list_cnt = 0; + } + + if (query_start + query_length > cxl_dstate->mem_size) { + return CXL_MBOX_INVALID_PA; + } + + if (in->flags == 0) { /* TODO */ + qemu_log_mask(LOG_UNIMP, + "Scan Media Event Log is unsupported\n"); + } + + cxl_dstate->bg.runtime = MAX(1, query_length * (0.0005L/64)); + ct3d->poison_list_dirty = false; + + *len = 0; + return CXL_MBOX_BG_STARTED; +} + #define IMMEDIATE_CONFIG_CHANGE (1 << 1) #define IMMEDIATE_DATA_CHANGE (1 << 2) #define IMMEDIATE_POLICY_CHANGE (1 << 3) @@ -1014,7 +1119,8 @@ static struct cxl_cmd cxl_cmd_set[256][256] = { cmd_media_clear_poison, 72, 0 }, [MEDIA_AND_POISON][GET_SCAN_MEDIA_CAPABILITIES] = { "MEDIA_AND_POISON_GET_SCAN_MEDIA_CAPABILITIES", cmd_media_get_scan_media_capabilities, 16, 0 }, - + [MEDIA_AND_POISON][SCAN_MEDIA] = { "MEDIA_AND_POISON_SCAN_MEDIA", + cmd_media_scan_media, 17, 0 }, }; static struct cxl_cmd cxl_cmd_set_sw[256][256] = { @@ -1048,7 +1154,7 @@ void cxl_process_mailbox(CXLDeviceState *cxl_dstate) opcode_handler h; uint8_t bg_started = 0; uint64_t command_reg = cxl_dstate->mbox_reg_state64[R_CXL_DEV_MAILBOX_CMD]; - + CXLType3Dev *ct3d = container_of(cxl_dstate, CXLType3Dev, cxl_dstate); uint8_t set = FIELD_EX64(command_reg, CXL_DEV_MAILBOX_CMD, COMMAND_SET); uint8_t cmd = FIELD_EX64(command_reg, CXL_DEV_MAILBOX_CMD, COMMAND); uint16_t len = FIELD_EX64(command_reg, CXL_DEV_MAILBOX_CMD, LENGTH); @@ -1064,6 +1170,20 @@ void cxl_process_mailbox(CXLDeviceState *cxl_dstate) ret = CXL_MBOX_BUSY; goto done; } + + /* + * If the device updates its Poison List while the + * Scan Media operation is executing, the device + * shall indicate that a media scan is in progress + * if Get Poison List is called during the scan. + */ + if (ct3d->poison_list_dirty) { + if (h == cmd_media_get_poison_list) { + ret = CXL_MBOX_BUSY; + goto done; + } + } + /* forbid any selected commands while overwriting */ if (sanitize_running(cxl_dstate)) { if (h == cmd_events_get_records || @@ -1157,7 +1277,8 @@ static void bg_timercb(void *opaque) __do_sanitization(cxl_dstate); cxl_dev_enable_media(cxl_dstate); break; - case 0x4304: /* TODO: scan media */ + case 0x4304: /* scan media */ + __do_scan_media(cxl_dstate); break; default: __builtin_unreachable(); diff --git a/hw/mem/cxl_type3.c b/hw/mem/cxl_type3.c index 3e63dbd83551..0bc017061f30 100644 --- a/hw/mem/cxl_type3.c +++ b/hw/mem/cxl_type3.c @@ -1213,6 +1213,9 @@ void qmp_cxl_inject_poison(const char *path, uint64_t start, uint64_t length, QLIST_INSERT_HEAD(&ct3d->poison_list, p, node); ct3d->poison_list_cnt++; + if (scan_media_running(&ct3d->cxl_dstate)) { + ct3d->poison_list_dirty = true; + } } /* For uncorrectable errors include support for multiple header recording */ diff --git a/include/hw/cxl/cxl_device.h b/include/hw/cxl/cxl_device.h index cd7f28dba884..8db63c1f7cd1 100644 --- a/include/hw/cxl/cxl_device.h +++ b/include/hw/cxl/cxl_device.h @@ -376,12 +376,18 @@ typedef struct CXLPoison { #define CXL_POISON_TYPE_EXTERNAL 0x1 #define CXL_POISON_TYPE_INTERNAL 0x2 #define CXL_POISON_TYPE_INJECTED 0x3 +#define CXL_POISON_TYPE_SCANMEDIA 0x4 QLIST_ENTRY(CXLPoison) node; } CXLPoison; typedef QLIST_HEAD(, CXLPoison) CXLPoisonList; #define CXL_POISON_LIST_LIMIT 256 +static inline bool scan_media_running(CXLDeviceState *cxl_dstate) +{ + return cxl_dstate->bg.runtime && cxl_dstate->bg.opcode == 0x4304; +} + struct CXLType3Dev { /* Private */ PCIDevice parent_obj; @@ -413,6 +419,8 @@ struct CXLType3Dev { unsigned int poison_list_cnt; bool poison_list_overflowed; uint64_t poison_list_overflow_ts; + /* list modified while doing scan media */ + bool poison_list_dirty; }; #define TYPE_CXL_TYPE3 "cxl-type3" From patchwork Wed Apr 26 02:14:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Davidlohr Bueso X-Patchwork-Id: 13223988 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 349FFC77B78 for ; Wed, 26 Apr 2023 02:46:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239029AbjDZCqN (ORCPT ); Tue, 25 Apr 2023 22:46:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38700 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239104AbjDZCqL (ORCPT ); Tue, 25 Apr 2023 22:46:11 -0400 Received: from bee.birch.relay.mailchannels.net (bee.birch.relay.mailchannels.net [23.83.209.14]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E64DDE69 for ; Tue, 25 Apr 2023 19:46:09 -0700 (PDT) X-Sender-Id: dreamhost|x-authsender|dave@stgolabs.net Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 64554540BD1; Wed, 26 Apr 2023 02:46:09 +0000 (UTC) Received: from pdx1-sub0-mail-a207.dreamhost.com (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id DA575541234; Wed, 26 Apr 2023 02:46:08 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1682477169; a=rsa-sha256; cv=none; b=3JJ60ndLA6ZsSUICVYfnaoUS69xMcOKCckn4uj2Cf52RbHIBIQjOgEbuWZxJH6cpvWyHzQ EaS5L02lKKzUSzo/ImUkDmdPfh8PdzdEr3+KL8wJNS8M+MKvNbBJHW4OMzOlz5j8PAeAf3 NBeq64bSYzUPDTlsOnRngsWxh11Vwl5PzjcxZZ5f06If+8NgJ8xztxx/0Miw5p6K+gZy/b KvDeURn5z1462d5WzHVpsSD/rvuza0d5ySWq3349nAzNpeoOxARmjUYKPSZSxikdgIMn4D xjwVfmOhZyq2TnB/47nBzLp1emcxChiPNe8qOTespHnOPe21uT5xoqvahuaGbA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1682477168; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=3scxXsTcK2ZsqkI/Sa/VJOB5q8oBKP9/01gBFYOd5LQ=; b=44WQmvEXkNRk1k/GEeq0560ycl8Ryz/Fo2ZnY3H7cgR3VESHepF2itj1Z8l8pYX5+AHaNj OuG51znW98IGB0VtEAsQ6DnpXdfCIfYyzKLMbUKXVWIAq0/jJMD3BqkmIO1XC41bpu1zK2 6gX/PpqheN17Qm2Sk32HhMmFg3CvNUJysLsbJD6dyBBsc/yeSNd1/Pev9eW1P5aooahdoz tI9IcS6aMRf+MRqrwaes6sU2DWx5E66ubHyJT0iqVtX/0J8IY5vFHRfhBW9bih6qWz26/c W0l5JUh61yhlvtPUk7FDnuHApE2Pw4YN85rgpL1B2t24ahU2MGuDHZ7HjkmnSA== ARC-Authentication-Results: i=1; rspamd-7f66b7b68c-zn4rt; auth=pass smtp.auth=dreamhost smtp.mailfrom=dave@stgolabs.net X-Sender-Id: dreamhost|x-authsender|dave@stgolabs.net X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|dave@stgolabs.net X-MailChannels-Auth-Id: dreamhost X-Bored-Eight: 120e6e2b6681b129_1682477169208_713630856 X-MC-Loop-Signature: 1682477169208:1352998720 X-MC-Ingress-Time: 1682477169208 Received: from pdx1-sub0-mail-a207.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.126.30.62 (trex/6.7.2); Wed, 26 Apr 2023 02:46:09 +0000 Received: from localhost.localdomain (ip72-199-50-187.sd.sd.cox.net [72.199.50.187]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: dave@stgolabs.net) by pdx1-sub0-mail-a207.dreamhost.com (Postfix) with ESMTPSA id 4Q5jt80sXLz4s; Tue, 25 Apr 2023 19:46:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=stgolabs.net; s=dreamhost; t=1682477168; bh=3scxXsTcK2ZsqkI/Sa/VJOB5q8oBKP9/01gBFYOd5LQ=; h=From:To:Cc:Subject:Date:Content-Transfer-Encoding; b=H01CDvH1a4acgLEfbs1RnkofEMb+jzYAFvdjwUvA6V1eByj8e31deDyXUVrj9oofq G6OmvlYm+v3aWRa/38k2m4lDxCOvLRLAsbvjAGMIZjK0HFFHynYHY4VzF/65eEPjKl gClQyGUV5An+JG8f4ZfVWsm+Ton22ftPmHTSH94oPVFuHOhmpw4B9wJhFHEV5fc3vw qebEMAZSi84MsTA10Nb7UQE++ANNZVpGUa/owyE4Yd6KEck+7/HvWBlRaxGFdJm6sx vTAbdFALm7JJX9fughnXtzJN9Veoj8AcmFWk6TzMsxbzJ8+UguXBg06cn0aLinOvPc von00TAknLFqw== From: Davidlohr Bueso To: Jonathan.Cameron@huawei.com Cc: alison.schofield@intel.com, ira.weiny@intel.com, dan.j.williams@intel.com, fan.ni@samsung.com, a.manzanares@samsung.com, dave@stgolabs.net, linux-cxl@vger.kernel.org Subject: [PATCH 3/3] hw/cxl: Add scan media mailbox command support Date: Tue, 25 Apr 2023 19:14:18 -0700 Message-Id: <20230426021418.10186-4-dave@stgolabs.net> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230426021418.10186-1-dave@stgolabs.net> References: <20230426021418.10186-1-dave@stgolabs.net> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-cxl@vger.kernel.org Allow the caller to retrieve the results of a previous scan media operation, with similar semantics to the get poison list command. Number of returned records is to the max payload output size. Signed-off-by: Davidlohr Bueso --- hw/cxl/cxl-mailbox-utils.c | 55 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/hw/cxl/cxl-mailbox-utils.c b/hw/cxl/cxl-mailbox-utils.c index 7f29b840a2c9..f978180d8e21 100644 --- a/hw/cxl/cxl-mailbox-utils.c +++ b/hw/cxl/cxl-mailbox-utils.c @@ -81,6 +81,7 @@ enum { #define CLEAR_POISON 0x2 #define GET_SCAN_MEDIA_CAPABILITIES 0x3 #define SCAN_MEDIA 0x4 + #define GET_SCAN_MEDIA_RESULTS 0x5 PHYSICAL_SWITCH = 0x51 #define IDENTIFY_SWITCH_DEVICE 0x0 }; @@ -1079,6 +1080,58 @@ cmd_media_scan_media(struct cxl_cmd *cmd, return CXL_MBOX_BG_STARTED; } +static CXLRetCode cmd_media_get_scan_media_results(struct cxl_cmd *cmd, + CXLDeviceState *cxl_dstate, + uint16_t *len) +{ + struct get_scan_media_results_out_pl { + uint64_t dpa_restart; + uint64_t length; + uint8_t flags; + uint8_t rsvd1; + uint16_t count; + uint8_t rsvd2[20]; + struct { + uint64_t addr; + uint32_t length; + uint32_t resv; + } QEMU_PACKED records[]; + } QEMU_PACKED; + struct get_scan_media_results_out_pl *out = (void *)cmd->payload; + CXLType3Dev *ct3d = container_of(cxl_dstate, CXLType3Dev, cxl_dstate); + uint16_t record_count = 0, i = 0; + CXLPoisonList *poison_list = &ct3d->poison_list; + CXLPoison *ent; + uint16_t out_pl_len; + + QLIST_FOREACH(ent, poison_list, node) { + if (ent->type == CXL_POISON_TYPE_SCANMEDIA) { + record_count++; + } + } + + out_pl_len = sizeof(*out) + record_count * sizeof(out->records[0]); + assert(out_pl_len <= CXL_MAILBOX_MAX_PAYLOAD_SIZE); + + memset(out, 0, out_pl_len); + QLIST_FOREACH(ent, poison_list, node) { + if (ent->type == CXL_POISON_TYPE_SCANMEDIA) { + uint64_t start, stop; + + start = ent->start & 0xffffffffffffffc0; + stop = ent->start & 0xffffffffffffffc0; + stq_le_p(&out->records[i].addr, start | (ent->type & 0x7)); + stl_le_p(&out->records[i].length, (stop - start) / 64); + i++; + } + } + + stw_le_p(&out->count, record_count); + + *len = out_pl_len; + return CXL_MBOX_SUCCESS; +} + #define IMMEDIATE_CONFIG_CHANGE (1 << 1) #define IMMEDIATE_DATA_CHANGE (1 << 2) #define IMMEDIATE_POLICY_CHANGE (1 << 3) @@ -1121,6 +1174,8 @@ static struct cxl_cmd cxl_cmd_set[256][256] = { cmd_media_get_scan_media_capabilities, 16, 0 }, [MEDIA_AND_POISON][SCAN_MEDIA] = { "MEDIA_AND_POISON_SCAN_MEDIA", cmd_media_scan_media, 17, 0 }, + [MEDIA_AND_POISON][GET_SCAN_MEDIA_RESULTS] = { "MEDIA_AND_POISON_GET_SCAN_MEDIA_RESULTS", + cmd_media_get_scan_media_results, 0, 0 }, }; static struct cxl_cmd cxl_cmd_set_sw[256][256] = {