From nobody Tue Dec 23 10:51:30 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1684506883; cv=none; d=zohomail.com; s=zohoarc; b=QIzJzyT7NQDBCRGp43Cb06xS8gEaZyYDPDsELBM3hyIZW6hCJ7gQHfkSoUhDlXInyuyn4iqi8xrdb2w1qjHgEr5eVmvyyFve5AbztCdHBM0SWu3PkwNBi8rCoZEof+FBzmUpn4I6B0YcLm5kNvbWx7RJ08ecjgwCAmRB6kWDjVo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1684506883; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=WffbT/XwD45iIBUQyjxKxCYIRLTLMvvCNFS/OK9I6Gs=; b=O827KDpWxm3WUpFlDMoK4QAXMHmYdgf4PN/y9vebiCTwepcS9BF8Qgj4EZv1K9Jy6pQbTet0iTPuMyOxV3nJhsVs9FENhSkGWZLi6HAcYg8j0CI4J7Pc+EMk7I7aL7lAOJj/1WqqOqI9M+ll3hveFA2EvrXn7PYWvAn1ROsJ2vs= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1684506883680113.01923823158347; Fri, 19 May 2023 07:34:43 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q01BY-0000j5-Hf; Fri, 19 May 2023 10:34:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q01BX-0000ib-D5 for qemu-devel@nongnu.org; Fri, 19 May 2023 10:34:23 -0400 Received: from frasgout.his.huawei.com ([185.176.79.56]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q01BU-0000Mb-AN for qemu-devel@nongnu.org; Fri, 19 May 2023 10:34:22 -0400 Received: from lhrpeml500005.china.huawei.com (unknown [172.18.147.207]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4QN8Pd6Lpvz6J7HT; Fri, 19 May 2023 22:29:57 +0800 (CST) Received: from SecurePC-101-06.china.huawei.com (10.122.247.231) by lhrpeml500005.china.huawei.com (7.191.163.240) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Fri, 19 May 2023 15:34:17 +0100 To: , Michael Tsirkin , Fan Ni CC: , , Ira Weiny , Michael Roth , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Dave Jiang , Markus Armbruster , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Eric Blake , Mike Maslenkin , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Thomas Huth Subject: [PATCH v6 7/7] hw/cxl/events: Add injection of Memory Module Events Date: Fri, 19 May 2023 15:30:43 +0100 Message-ID: <20230519143043.30191-8-Jonathan.Cameron@huawei.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230519143043.30191-1-Jonathan.Cameron@huawei.com> References: <20230519143043.30191-1-Jonathan.Cameron@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.122.247.231] X-ClientProxiedBy: lhrpeml100001.china.huawei.com (7.191.160.183) To lhrpeml500005.china.huawei.com (7.191.163.240) X-CFilter-Loop: Reflected Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=185.176.79.56; envelope-from=jonathan.cameron@huawei.com; helo=frasgout.his.huawei.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Jonathan Cameron From: Jonathan Cameron via Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1684506884708100001 Content-Type: text/plain; charset="utf-8" These events include a copy of the device health information at the time of the event. Actually using the emulated device health would require a lot of controls to manipulate that state. Given the aim of this injection code is to just test the flows when events occur, inject the contents of the device health state as well. Future work may add more sophisticate device health emulation including direct generation of these records when events occur (such as a temperature threshold being crossed). That does not reduce the usefulness of this more basic generation of the events. Reviewed-by: Ira Weiny Signed-off-by: Jonathan Cameron --- hw/mem/cxl_type3.c | 62 +++++++++++++++++++++++++++++++++++++ hw/mem/cxl_type3_stubs.c | 12 +++++++ include/hw/cxl/cxl_events.h | 19 ++++++++++++ qapi/cxl.json | 35 +++++++++++++++++++++ 4 files changed, 128 insertions(+) diff --git a/hw/mem/cxl_type3.c b/hw/mem/cxl_type3.c index 0353425b17..34eac58b48 100644 --- a/hw/mem/cxl_type3.c +++ b/hw/mem/cxl_type3.c @@ -1201,6 +1201,11 @@ static const QemuUUID dram_uuid =3D { 0x4e, 0x9b, 0xfb, 0x5c, 0x96, 0x24), }; =20 +static const QemuUUID memory_module_uuid =3D { + .data =3D UUID(0xfe927475, 0xdd59, 0x4339, 0xa5, 0x86, + 0x79, 0xba, 0xb1, 0x13, 0xb7, 0x74), +}; + #define CXL_GMER_VALID_CHANNEL BIT(0) #define CXL_GMER_VALID_RANK BIT(1) #define CXL_GMER_VALID_DEVICE BIT(2) @@ -1408,6 +1413,63 @@ void qmp_cxl_inject_dram_event(const char *path, Cxl= EventLog log, uint8_t flags, return; } =20 +void qmp_cxl_inject_memory_module_event(const char *path, CxlEventLog log, + uint8_t flags, uint8_t type, + uint8_t health_status, + uint8_t media_status, + uint8_t additional_status, + uint8_t life_used, + int16_t temperature, + uint32_t dirty_shutdown_count, + uint32_t corrected_volatile_error_= count, + uint32_t corrected_persistent_erro= r_count, + Error **errp) +{ + Object *obj =3D object_resolve_path(path, NULL); + CXLEventMemoryModule module; + CXLEventRecordHdr *hdr =3D &module.hdr; + CXLDeviceState *cxlds; + CXLType3Dev *ct3d; + uint8_t enc_log; + int rc; + + if (!obj) { + error_setg(errp, "Unable to resolve path"); + return; + } + if (!object_dynamic_cast(obj, TYPE_CXL_TYPE3)) { + error_setg(errp, "Path does not point to a CXL type 3 device"); + return; + } + ct3d =3D CXL_TYPE3(obj); + cxlds =3D &ct3d->cxl_dstate; + + rc =3D ct3d_qmp_cxl_event_log_enc(log); + if (rc < 0) { + error_setg(errp, "Unhandled error log type"); + return; + } + enc_log =3D rc; + + memset(&module, 0, sizeof(module)); + cxl_assign_event_header(hdr, &memory_module_uuid, flags, sizeof(module= ), + cxl_device_get_timestamp(&ct3d->cxl_dstate)); + + module.type =3D type; + module.health_status =3D health_status; + module.media_status =3D media_status; + module.additional_status =3D additional_status; + module.life_used =3D life_used; + stw_le_p(&module.temperature, temperature); + stl_le_p(&module.dirty_shutdown_count, dirty_shutdown_count); + stl_le_p(&module.corrected_volatile_error_count, corrected_volatile_er= ror_count); + stl_le_p(&module.corrected_persistent_error_count, corrected_persisten= t_error_count); + + if (cxl_event_insert(cxlds, enc_log, (CXLEventRecordRaw *)&module)) { + cxl_event_irq_assert(ct3d); + } +} + static void ct3_class_init(ObjectClass *oc, void *data) { DeviceClass *dc =3D DEVICE_CLASS(oc); diff --git a/hw/mem/cxl_type3_stubs.c b/hw/mem/cxl_type3_stubs.c index 235c171264..2196bd841c 100644 --- a/hw/mem/cxl_type3_stubs.c +++ b/hw/mem/cxl_type3_stubs.c @@ -26,6 +26,18 @@ void qmp_cxl_inject_dram_event(const char *path, CxlEven= tLog log, uint8_t flags, bool has_correction_mask, uint64List *corre= ction_mask, Error **errp) {} =20 +void qmp_cxl_inject_memory_module_event(const char *path, CxlEventLog log, + uint8_t flags, uint8_t type, + uint8_t health_status, + uint8_t media_status, + uint8_t additional_status, + uint8_t life_used, + int16_t temperature, + uint32_t dirty_shutdown_count, + uint32_t corrected_volatile_error_= count, + uint32_t corrected_persistent_erro= r_count, + Error **errp) {} + void qmp_cxl_inject_poison(const char *path, uint64_t start, uint64_t leng= th, Error **errp) { diff --git a/include/hw/cxl/cxl_events.h b/include/hw/cxl/cxl_events.h index a39e30d973..089ba2091f 100644 --- a/include/hw/cxl/cxl_events.h +++ b/include/hw/cxl/cxl_events.h @@ -146,4 +146,23 @@ typedef struct CXLEventDram { uint8_t reserved[0x17]; } QEMU_PACKED CXLEventDram; =20 +/* + * Memory Module Event Record + * CXL Rev 3.0 Section 8.2.9.2.1.3: Table 8-45 + * All fields little endian. + */ +typedef struct CXLEventMemoryModule { + CXLEventRecordHdr hdr; + uint8_t type; + uint8_t health_status; + uint8_t media_status; + uint8_t additional_status; + uint8_t life_used; + int16_t temperature; + uint32_t dirty_shutdown_count; + uint32_t corrected_volatile_error_count; + uint32_t corrected_persistent_error_count; + uint8_t reserved[0x3d]; +} QEMU_PACKED CXLEventMemoryModule; + #endif /* CXL_EVENTS_H */ diff --git a/qapi/cxl.json b/qapi/cxl.json index 5e82097e76..0636f34d56 100644 --- a/qapi/cxl.json +++ b/qapi/cxl.json @@ -90,6 +90,41 @@ '*column': 'uint16', '*correction-mask': [ 'uint64' ] }} =20 +## +# @cxl-inject-memory-module-event: +# +# Inject an event record for a Memory Module Event (CXL r3.0 8.2.9.2.1.3) +# This event includes a copy of the Device Health info at the time of +# the event. +# +# @path: CXL type 3 device canonical QOM path +# @log: Event Log to add the event to +# @flags: header flags +# @type: Device Event Type (see spec for permitted values) +# @health-status: Overall health summary bitmap (see spec for permitted bi= ts) +# @media-status: Overall media health summary (see spec for permitted valu= es) +# @additional-status: Complex field (see spec for meaning) +# @life-used: Percentage (0-100) of factory expected life span +# @temperature: Device temperature in degrees Celsius +# @dirty-shutdown-count: Counter incremented whenever device is unable +# to determine if data loss may have occurred. +# @corrected-volatile-error-count: Total number of correctable errors in +# volatile memory +# @corrected-persistent-error-count: Total number correctable errors in +# persistent memory +# +# Since: 8.1 +## +{ 'command': 'cxl-inject-memory-module-event', + 'data': { 'path': 'str', 'log': 'CxlEventLog', 'flags' : 'uint8', + 'type': 'uint8', 'health-status': 'uint8', + 'media-status': 'uint8', 'additional-status': 'uint8', + 'life-used': 'uint8', 'temperature' : 'int16', + 'dirty-shutdown-count': 'uint32', + 'corrected-volatile-error-count': 'uint32', + 'corrected-persistent-error-count': 'uint32' + }} + ## # @cxl-inject-poison: # --=20 2.39.2