From nobody Fri Apr 26 11:48:39 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1675248665; cv=none; d=zohomail.com; s=zohoarc; b=lG4ld4hMKgaAIxUQUpzdWn1QMX7RxalASoG/cP0l/qAIUnOfmZ450ze/iaD5wnrp7vMdf0IubHOT3QZ1q29f633+S80vj9z2AUMS2Xn7kL0Mao4sELn0KuWqRgbuKHYe1uXM9fC3FeM/F0wPJUVmvvSCjMl0kVlds10Fz0F1zgI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675248665; 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=AsLRdMrbA7b8gBRqTez0LZFE4Bf314b1LPkcD/KENnA=; b=a5k5DAf8iR6tTvCCnKnMWIfYZE0vrRR1mll/xYzwlO83D9W84z6rcgRIig7RRr0D/csQecGNmqIvF/V0sY2Qy0/MX5r0J5IuDG6QjAmbWR9ksbZfN9+HS3bSBa6RU+p3mpDfwXm0bTSkiqZbES8xvHHMN5FZFsL9FSdetkctKjs= 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+importer2=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 167524866558657.535528313532836; Wed, 1 Feb 2023 02:51:05 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pNA13-0001B3-7N; Wed, 01 Feb 2023 05:06:57 -0500 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 1pN9yX-0000Kb-M5 for qemu-devel@nongnu.org; Wed, 01 Feb 2023 05:04:27 -0500 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 1pN9yV-0005dv-4X for qemu-devel@nongnu.org; Wed, 01 Feb 2023 05:04:21 -0500 Received: from lhrpeml500005.china.huawei.com (unknown [172.18.147.200]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4P6HVD4Fk7z6J6Dq; Wed, 1 Feb 2023 18:00:36 +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.2375.34; Wed, 1 Feb 2023 10:04:17 +0000 To: , Michael Tsirkin CC: Ben Widawsky , , , Ira Weiny , Alison Schofield Subject: [RFC PATCH v2 1/3] hw/cxl: QMP based poison injection support Date: Wed, 1 Feb 2023 10:03:48 +0000 Message-ID: <20230201100350.23263-2-Jonathan.Cameron@huawei.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230201100350.23263-1-Jonathan.Cameron@huawei.com> References: <20230201100350.23263-1-Jonathan.Cameron@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.122.247.231] X-ClientProxiedBy: lhrpeml500005.china.huawei.com (7.191.163.240) 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+importer2=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, RCVD_IN_MSPIKE_H2=-0.001, 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.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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZM-MESSAGEID: 1675248666349100001 Content-Type: text/plain; charset="utf-8" Inject poison using qmp command cxl-inject-poison to add an entry to the poison list. For now, the poison is not returned CXL.mem reads, but only via the mailbox command Get Poison List. See CXL rev 3.0, sec 8.2.9.8.4.1 Get Poison list (Opcode 4300h) Kernel patches to use this interface here: https://lore.kernel.org/linux-cxl/cover.1665606782.git.alison.schofield@int= el.com/ To inject poison using qmp (telnet to the qmp port) { "execute": "qmp_capabilities" } { "execute": "cxl-inject-poison", "arguments": { "path": "/machine/peripheral/cxl-pmem0", "start": 2048, "length": 256 } } Adjusted to select a device on your machine. Note that the poison list supported is kept short enough to avoid the complexity of state machine that is needed to handle the MORE flag. Signed-off-by: Jonathan Cameron --- v2: Moved to QMP to allow for single command. Update reference in coverletter Added specific setting of type for this approach to injection. Drop the unnecessary ct3d class get_poison_list callback. Block overlapping regions from being injected Handle list overflow Use Ira's utility function to get the timestamps --- hw/cxl/cxl-mailbox-utils.c | 82 +++++++++++++++++++++++++++++++++++++ hw/mem/cxl_type3.c | 56 +++++++++++++++++++++++++ hw/mem/cxl_type3_stubs.c | 3 ++ hw/mem/meson.build | 2 + include/hw/cxl/cxl_device.h | 20 +++++++++ qapi/cxl.json | 11 +++++ 6 files changed, 174 insertions(+) diff --git a/hw/cxl/cxl-mailbox-utils.c b/hw/cxl/cxl-mailbox-utils.c index 580366ed2f..cf3cfb10a1 100644 --- a/hw/cxl/cxl-mailbox-utils.c +++ b/hw/cxl/cxl-mailbox-utils.c @@ -62,6 +62,8 @@ enum { #define GET_PARTITION_INFO 0x0 #define GET_LSA 0x2 #define SET_LSA 0x3 + MEDIA_AND_POISON =3D 0x43, + #define GET_POISON_LIST 0x0 }; =20 struct cxl_cmd; @@ -267,6 +269,8 @@ static CXLRetCode cmd_identify_memory_device(struct cxl= _cmd *cmd, id->persistent_capacity =3D cxl_dstate->pmem_size / CXL_CAPACITY_MULTI= PLIER; id->volatile_capacity =3D cxl_dstate->vmem_size / CXL_CAPACITY_MULTIPL= IER; id->lsa_size =3D cvc->get_lsa_size(ct3d); + id->poison_list_max_mer[1] =3D 0x1; /* 256 poison records */ + id->inject_poison_limit =3D 0; /* No limit - so limited by main poison= record limit */ =20 *len =3D sizeof(*id); return CXL_MBOX_SUCCESS; @@ -356,6 +360,82 @@ static CXLRetCode cmd_ccls_set_lsa(struct cxl_cmd *cmd, return CXL_MBOX_SUCCESS; } =20 +/* + * This is very inefficient, but good enough for now! + * Also the payload will always fit, so no need to handle the MORE flag and + * make this stateful. We may want to allow longer poison lists to aid + * testing that kernel functionality. + */ +static CXLRetCode cmd_media_get_poison_list(struct cxl_cmd *cmd, + CXLDeviceState *cxl_dstate, + uint16_t *len) +{ + struct get_poison_list_pl { + uint64_t pa; + uint64_t length; + } QEMU_PACKED; + + struct get_poison_list_out_pl { + uint8_t flags; + uint8_t rsvd1; + uint64_t overflow_timestamp; + uint16_t count; + uint8_t rsvd2[0x14]; + struct { + uint64_t addr; + uint32_t length; + uint32_t resv; + } QEMU_PACKED records[]; + } QEMU_PACKED; + + struct get_poison_list_pl *in =3D (void *)cmd->payload; + struct get_poison_list_out_pl *out =3D (void *)cmd->payload; + CXLType3Dev *ct3d =3D container_of(cxl_dstate, CXLType3Dev, cxl_dstate= ); + uint16_t record_count =3D 0, i =3D 0; + uint64_t query_start =3D in->pa; + uint64_t query_length =3D in->length; + CXLPoisonList *poison_list =3D &ct3d->poison_list; + CXLPoison *ent; + uint16_t out_pl_len; + + QLIST_FOREACH(ent, poison_list, node) { + /* Check for no overlap */ + if (ent->start >=3D query_start + query_length || + ent->start + ent->length <=3D query_start) { + continue; + } + record_count++; + } + out_pl_len =3D sizeof(*out) + record_count * sizeof(out->records[0]); + assert(out_pl_len <=3D CXL_MAILBOX_MAX_PAYLOAD_SIZE); + + memset(out, 0, out_pl_len); + QLIST_FOREACH(ent, poison_list, node) { + uint64_t start, stop; + + /* Check for no overlap */ + if (ent->start >=3D query_start + query_length || + ent->start + ent->length <=3D query_start) { + continue; + } + + /* Deal with overlap */ + start =3D MAX(ent->start & 0xffffffffffffffc0, query_start); + stop =3D MIN((ent->start & 0xffffffffffffffc0) + ent->length, + query_start + query_length); + out->records[i].addr =3D start | (ent->type & 0x3); + out->records[i].length =3D (stop - start) / 64; + i++; + } + if (ct3d->poison_list_overflowed) { + out->flags =3D (1 << 1); + out->overflow_timestamp =3D ct3d->poison_list_overflow_ts; + } + out->count =3D record_count; + *len =3D 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) @@ -383,6 +463,8 @@ static struct cxl_cmd cxl_cmd_set[256][256] =3D { [CCLS][GET_LSA] =3D { "CCLS_GET_LSA", cmd_ccls_get_lsa, 8, 0 }, [CCLS][SET_LSA] =3D { "CCLS_SET_LSA", cmd_ccls_set_lsa, ~0, IMMEDIATE_CONFIG_CHANGE | IMMEDIATE_DATA_CHANGE }, + [MEDIA_AND_POISON][GET_POISON_LIST] =3D { "MEDIA_AND_POISON_GET_POISON= _LIST", + cmd_media_get_poison_list, 16, 0 }, }; =20 void cxl_process_mailbox(CXLDeviceState *cxl_dstate) diff --git a/hw/mem/cxl_type3.c b/hw/mem/cxl_type3.c index beb931d59a..20f8d8e8aa 100644 --- a/hw/mem/cxl_type3.c +++ b/hw/mem/cxl_type3.c @@ -925,6 +925,62 @@ static void set_lsa(CXLType3Dev *ct3d, const void *buf= , uint64_t size, */ } =20 +void cxl_set_poison_list_overflowed(CXLType3Dev *ct3d) +{ + ct3d->poison_list_overflowed =3D true; + ct3d->poison_list_overflow_ts =3D + cxl_device_get_timestamp(&ct3d->cxl_dstate); +} + +void qmp_cxl_inject_poison(const char *path, uint64_t start, uint64_t leng= th, + Error **errp) +{ + Object *obj =3D object_resolve_path(path, NULL); + CXLType3Dev *ct3d; + CXLPoison *p; + + if (length % 64) { + error_setg(errp, "Poison injection must be in multiples of 64 byte= s"); + return; + } + if (start % 64) { + error_setg(errp, "Poison start address must be 64 byte aligned"); + return; + } + 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); + + QLIST_FOREACH(p, &ct3d->poison_list, node) { + if (((start >=3D p->start) && (start < p->start + p->length)) || + ((start + length > p->start) && + (start + length <=3D p->start + p->length))) { + error_setg(errp, "Overlap with existing poisoned region not su= pported"); + return; + } + } + + if (ct3d->poison_list_cnt =3D=3D CXL_POISON_LIST_LIMIT) { + cxl_set_poison_list_overflowed(ct3d); + return; + } + + p =3D g_new0(CXLPoison, 1); + p->length =3D length; + p->start =3D start; + p->type =3D CXL_POISON_TYPE_INTERNAL; /* Different from injected via t= he mbox */ + + QLIST_INSERT_HEAD(&ct3d->poison_list, p, node); + ct3d->poison_list_cnt++; +} + /* For uncorrectable errors include support for multiple header recording = */ void qmp_cxl_inject_uncorrectable_errors(const char *path, CXLUncorErrorRecordList *errors, diff --git a/hw/mem/cxl_type3_stubs.c b/hw/mem/cxl_type3_stubs.c index b6b51ced54..6055190ca6 100644 --- a/hw/mem/cxl_type3_stubs.c +++ b/hw/mem/cxl_type3_stubs.c @@ -2,6 +2,9 @@ #include "qemu/osdep.h" #include "qapi/qapi-commands-cxl.h" =20 +void qmp_cxl_inject_poison(const char *path, uint64_t start, uint64_t leng= th, + Error **errp) {} + void qmp_cxl_inject_uncorrectable_errors(const char *path, CXLUncorErrorRecordList *errors, Error **errp) {} diff --git a/hw/mem/meson.build b/hw/mem/meson.build index 56c2618b84..930c67e390 100644 --- a/hw/mem/meson.build +++ b/hw/mem/meson.build @@ -10,3 +10,5 @@ softmmu_ss.add(when: 'CONFIG_ALL', if_true: files('cxl_ty= pe3_stubs.c')) softmmu_ss.add_all(when: 'CONFIG_MEM_DEVICE', if_true: mem_ss) =20 softmmu_ss.add(when: 'CONFIG_SPARSE_MEM', if_true: files('sparse-mem.c')) +softmmu_ss.add(when: 'CONFIG_CXL_MEM_DEVICE', if_false: files('cxl_type3_s= tubs.c')) +softmmu_ss.add(when: 'CONFIG_ALL', if_true: files('cxl_type3_stubs.c')) diff --git a/include/hw/cxl/cxl_device.h b/include/hw/cxl/cxl_device.h index 44fea2d649..3cb77fe8a5 100644 --- a/include/hw/cxl/cxl_device.h +++ b/include/hw/cxl/cxl_device.h @@ -270,6 +270,18 @@ typedef struct CXLError { =20 typedef QTAILQ_HEAD(, CXLError) CXLErrorList; =20 +typedef struct CXLPoison { + uint64_t start, length; + uint8_t type; +#define CXL_POISON_TYPE_EXTERNAL 0x1 +#define CXL_POISON_TYPE_INTERNAL 0x2 +#define CXL_POISON_TYPE_INJECTED 0x3 + QLIST_ENTRY(CXLPoison) node; +} CXLPoison; + +typedef QLIST_HEAD(, CXLPoison) CXLPoisonList; +#define CXL_POISON_LIST_LIMIT 256 + struct CXLType3Dev { /* Private */ PCIDevice parent_obj; @@ -292,6 +304,12 @@ struct CXLType3Dev { =20 /* Error injection */ CXLErrorList error_list; + + /* Poison Injection - cache */ + CXLPoisonList poison_list; + unsigned int poison_list_cnt; + bool poison_list_overflowed; + uint64_t poison_list_overflow_ts; }; =20 #define TYPE_CXL_TYPE3 "cxl-type3" @@ -317,4 +335,6 @@ MemTxResult cxl_type3_write(PCIDevice *d, hwaddr host_a= ddr, uint64_t data, =20 uint64_t cxl_device_get_timestamp(CXLDeviceState *cxlds); =20 +void cxl_set_poison_list_overflowed(CXLType3Dev *ct3d); + #endif diff --git a/qapi/cxl.json b/qapi/cxl.json index 3c18556ee8..5b995db255 100644 --- a/qapi/cxl.json +++ b/qapi/cxl.json @@ -5,6 +5,17 @@ # =3D CXL devices ## =20 +## +# @cxl-inject-poison: +# +# @path: CXL type 3 device canonical QOM path +# +# @start: Start address +# @length: Length of poison to inject +## +{ 'command': 'cxl-inject-poison', + 'data': { 'path': 'str', 'start': 'uint64', 'length': 'uint64' }} + ## # @CxlUncorErrorType: # --=20 2.37.2 From nobody Fri Apr 26 11:48:39 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1675247549; cv=none; d=zohomail.com; s=zohoarc; b=KOxpV1fs1tI3yHGrnBA53wcUHdZadQkfObUDP0NWlUJq7AsPcE2RFMvAEZ3c3TnC4KwFGhM0WikrP9ae3fUUCaSqjLMmxtWahHaFVuC7fWncFoJG44eTNKHaQceGU2ALiSRaXhmqpn8N2vlik+fFFNT1Or18cKJOdWNDDYmSq58= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675247549; 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=al/txR/p61z7FRZZLX1q2MT1TG6fY1uLxbDK39zY+Tc=; b=B3B3DHk/B2k32w2p+NKyU53C7Ilj0/R6qa5tm6qySaWA3otH8kAM+wpR6PhVFKZGlmmnFp1HWYO8iYJIuEpF5PHLtnA6PuZMI77LifbdtfjIR67YBctF9IV2cjiLhTGGyN4xJ9GYw5C0uH1CmTtKQy5LpoDHPwijU8nBOvY1/ug= 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+importer2=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 1675247549236613.7780275710437; Wed, 1 Feb 2023 02:32:29 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pNA0Y-0000tP-KE; Wed, 01 Feb 2023 05:06:26 -0500 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 1pN9z4-0000PI-4r for qemu-devel@nongnu.org; Wed, 01 Feb 2023 05:04:56 -0500 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 1pN9z2-0005i0-C2 for qemu-devel@nongnu.org; Wed, 01 Feb 2023 05:04:53 -0500 Received: from lhrpeml500005.china.huawei.com (unknown [172.18.147.207]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4P6HV83MGmz6J7f1; Wed, 1 Feb 2023 18:00:32 +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.2375.34; Wed, 1 Feb 2023 10:04:47 +0000 To: , Michael Tsirkin CC: Ben Widawsky , , , Ira Weiny , Alison Schofield Subject: [RFC PATCH v2 2/3] hw/cxl: Add poison injection via the mailbox. Date: Wed, 1 Feb 2023 10:03:49 +0000 Message-ID: <20230201100350.23263-3-Jonathan.Cameron@huawei.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230201100350.23263-1-Jonathan.Cameron@huawei.com> References: <20230201100350.23263-1-Jonathan.Cameron@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.122.247.231] X-ClientProxiedBy: lhrpeml500005.china.huawei.com (7.191.163.240) 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+importer2=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, RCVD_IN_MSPIKE_H2=-0.001, 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.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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZM-MESSAGEID: 1675247551398100003 Content-Type: text/plain; charset="utf-8" Very simple implementation to allow testing of corresponding kernel code. Note that for now we track each 64 byte section independently. Whilst a valid implementation choice, it may make sense to fuse entries so as to prove out more complex corners of the kernel code. Signed-off-by: Jonathan Cameron --- hw/cxl/cxl-mailbox-utils.c | 40 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/hw/cxl/cxl-mailbox-utils.c b/hw/cxl/cxl-mailbox-utils.c index cf3cfb10a1..7d3f7bcd3a 100644 --- a/hw/cxl/cxl-mailbox-utils.c +++ b/hw/cxl/cxl-mailbox-utils.c @@ -64,6 +64,7 @@ enum { #define SET_LSA 0x3 MEDIA_AND_POISON =3D 0x43, #define GET_POISON_LIST 0x0 + #define INJECT_POISON 0x1 }; =20 struct cxl_cmd; @@ -436,6 +437,43 @@ static CXLRetCode cmd_media_get_poison_list(struct cxl= _cmd *cmd, return CXL_MBOX_SUCCESS; } =20 +static CXLRetCode cmd_media_inject_poison(struct cxl_cmd *cmd, + CXLDeviceState *cxl_dstate, + uint16_t *len) +{ + CXLType3Dev *ct3d =3D container_of(cxl_dstate, CXLType3Dev, cxl_dstate= ); + CXLPoisonList *poison_list =3D &ct3d->poison_list; + CXLPoison *ent; + struct inject_poison_pl { + uint64_t dpa; + }; + struct inject_poison_pl *in =3D (void *)cmd->payload; + CXLPoison *p; + + QLIST_FOREACH(ent, poison_list, node) { + if (ent->start =3D=3D in->dpa && ent->length =3D=3D 64) { + return CXL_MBOX_SUCCESS; + } + } + + if (ct3d->poison_list_cnt =3D=3D CXL_POISON_LIST_LIMIT) { + return CXL_MBOX_INJECT_POISON_LIMIT; + } + p =3D g_new0(CXLPoison, 1); + + p->length =3D 64; + p->start =3D in->dpa; + p->type =3D CXL_POISON_TYPE_INJECTED; + + /* + * Possible todo: Merge with existing entry if next to it and if same = type + */ + QLIST_INSERT_HEAD(poison_list, p, node); + ct3d->poison_list_cnt++; + + return CXL_MBOX_SUCCESS; +} + #define IMMEDIATE_CONFIG_CHANGE (1 << 1) #define IMMEDIATE_DATA_CHANGE (1 << 2) #define IMMEDIATE_POLICY_CHANGE (1 << 3) @@ -465,6 +503,8 @@ static struct cxl_cmd cxl_cmd_set[256][256] =3D { ~0, IMMEDIATE_CONFIG_CHANGE | IMMEDIATE_DATA_CHANGE }, [MEDIA_AND_POISON][GET_POISON_LIST] =3D { "MEDIA_AND_POISON_GET_POISON= _LIST", cmd_media_get_poison_list, 16, 0 }, + [MEDIA_AND_POISON][INJECT_POISON] =3D { "MEDIA_AND_POISON_INJECT_POISO= N", + cmd_media_inject_poison, 8, 0 }, }; =20 void cxl_process_mailbox(CXLDeviceState *cxl_dstate) --=20 2.37.2 From nobody Fri Apr 26 11:48:39 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1675248195; cv=none; d=zohomail.com; s=zohoarc; b=HBMWOLOrF48IBtTQ08tAa+gY4xkncXgNYrPGt99o+FKaUdNl3Ur/3xGe6MbXtqEgEU7t8R9X0nuv0UDrIZ1r+Mrhfecg3iprI2/oZarSZv1tAujfB3cwNKS0LqR66k9Tfn7Qhnkee+5guDi6SQ7hSNZNn+bIvKX3AfGuc9poM38= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675248195; 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=SlFQa0XOXwkyW4QJi+W12zcM7flt94Fl1D178WHKIYs=; b=DA4aXZbAiCckH9K2XDPp8xwdEnxn7qbkGHlHa4FuL2OOeWzOolCYpDctRzsPzBQRXVeQgWID4j7iBFjDsBXeJsp+P4vaKsz38XQyM4lnR/cQ+FV0StK2h8DnJf/pPC1JpNvGZ6pRrmxqcvIRx+M1qoQmgM2TZgYoIGWNSD9xpjE= 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+importer2=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 1675248195024232.18649733589416; Wed, 1 Feb 2023 02:43:15 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pNA0Z-0000vN-TQ; Wed, 01 Feb 2023 05:06:27 -0500 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 1pN9zZ-0000RX-42 for qemu-devel@nongnu.org; Wed, 01 Feb 2023 05:05:29 -0500 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 1pN9zX-0005vg-7M for qemu-devel@nongnu.org; Wed, 01 Feb 2023 05:05:24 -0500 Received: from lhrpeml500005.china.huawei.com (unknown [172.18.147.207]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4P6HVk749lz6J7dd; Wed, 1 Feb 2023 18:01:02 +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.2375.34; Wed, 1 Feb 2023 10:05:18 +0000 To: , Michael Tsirkin CC: Ben Widawsky , , , Ira Weiny , Alison Schofield Subject: [RFC PATCH v2 3/3] hw/cxl: Add clear poison mailbox command support. Date: Wed, 1 Feb 2023 10:03:50 +0000 Message-ID: <20230201100350.23263-4-Jonathan.Cameron@huawei.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230201100350.23263-1-Jonathan.Cameron@huawei.com> References: <20230201100350.23263-1-Jonathan.Cameron@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.122.247.231] X-ClientProxiedBy: lhrpeml500005.china.huawei.com (7.191.163.240) 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+importer2=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, RCVD_IN_MSPIKE_H2=-0.001, 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.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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZM-MESSAGEID: 1675248195583100001 Content-Type: text/plain; charset="utf-8" Current implementation is very simple so many of the corner cases do not exist (e.g. fragmenting larger poison list entries) Signed-off-by: Jonathan Cameron --- hw/cxl/cxl-mailbox-utils.c | 77 +++++++++++++++++++++++++++++++++++++ hw/mem/cxl_type3.c | 36 +++++++++++++++++ include/hw/cxl/cxl_device.h | 1 + 3 files changed, 114 insertions(+) diff --git a/hw/cxl/cxl-mailbox-utils.c b/hw/cxl/cxl-mailbox-utils.c index 7d3f7bcd3a..f56c76b205 100644 --- a/hw/cxl/cxl-mailbox-utils.c +++ b/hw/cxl/cxl-mailbox-utils.c @@ -65,6 +65,7 @@ enum { MEDIA_AND_POISON =3D 0x43, #define GET_POISON_LIST 0x0 #define INJECT_POISON 0x1 + #define CLEAR_POISON 0x2 }; =20 struct cxl_cmd; @@ -474,6 +475,80 @@ static CXLRetCode cmd_media_inject_poison(struct cxl_c= md *cmd, return CXL_MBOX_SUCCESS; } =20 +static CXLRetCode cmd_media_clear_poison(struct cxl_cmd *cmd, + CXLDeviceState *cxl_dstate, + uint16_t *len) +{ + CXLType3Dev *ct3d =3D container_of(cxl_dstate, CXLType3Dev, cxl_dstate= ); + CXLPoisonList *poison_list =3D &ct3d->poison_list; + CXLType3Class *cvc =3D CXL_TYPE3_GET_CLASS(ct3d); + struct clear_poison_pl { + uint64_t dpa; + uint8_t data[64]; + }; + CXLPoison *ent; + + struct clear_poison_pl *in =3D (void *)cmd->payload; + + if (in->dpa + 64 > cxl_dstate->mem_size) { + return CXL_MBOX_INVALID_PA; + } + + QLIST_FOREACH(ent, poison_list, node) { + /* + * Test for contained in entry. Simpler than general case + * as clearing 64 bytes and entries 64 byte aligned + */ + if ((in->dpa < ent->start) || (in->dpa >=3D ent->start + ent->leng= th)) { + continue; + } + /* Do accounting early as we know one will go away */ + ct3d->poison_list_cnt--; + if (in->dpa > ent->start) { + CXLPoison *frag; + if (ct3d->poison_list_cnt =3D=3D CXL_POISON_LIST_LIMIT) { + cxl_set_poison_list_overflowed(ct3d); + break; + } + frag =3D g_new0(CXLPoison, 1); + + frag->start =3D ent->start; + frag->length =3D in->dpa - ent->start; + frag->type =3D ent->type; + + QLIST_INSERT_HEAD(poison_list, frag, node); + ct3d->poison_list_cnt++; + } + if (in->dpa + 64 < ent->start + ent->length) { + CXLPoison *frag; + + if (ct3d->poison_list_cnt =3D=3D CXL_POISON_LIST_LIMIT) { + cxl_set_poison_list_overflowed(ct3d); + break; + } + + frag =3D g_new0(CXLPoison, 1); + + frag->start =3D in->dpa + 64; + frag->length =3D ent->start + ent->length - frag->start; + frag->type =3D ent->type; + QLIST_INSERT_HEAD(poison_list, frag, node); + ct3d->poison_list_cnt++; + } + /* Any fragments have been added, free original entry */ + QLIST_REMOVE(ent, node); + g_free(ent); + break; + } + /* Clearing a region with no poison is not an error so always do so */ + if (cvc->set_cacheline) + if (!cvc->set_cacheline(ct3d, in->dpa, in->data)) { + return CXL_MBOX_INTERNAL_ERROR; + } + + return CXL_MBOX_SUCCESS; +} + #define IMMEDIATE_CONFIG_CHANGE (1 << 1) #define IMMEDIATE_DATA_CHANGE (1 << 2) #define IMMEDIATE_POLICY_CHANGE (1 << 3) @@ -505,6 +580,8 @@ static struct cxl_cmd cxl_cmd_set[256][256] =3D { cmd_media_get_poison_list, 16, 0 }, [MEDIA_AND_POISON][INJECT_POISON] =3D { "MEDIA_AND_POISON_INJECT_POISO= N", cmd_media_inject_poison, 8, 0 }, + [MEDIA_AND_POISON][CLEAR_POISON] =3D { "MEDIA_AND_POISON_CLEAR_POISON", + cmd_media_clear_poison, 72, 0 }, }; =20 void cxl_process_mailbox(CXLDeviceState *cxl_dstate) diff --git a/hw/mem/cxl_type3.c b/hw/mem/cxl_type3.c index 20f8d8e8aa..75ecf95a2d 100644 --- a/hw/mem/cxl_type3.c +++ b/hw/mem/cxl_type3.c @@ -925,6 +925,41 @@ static void set_lsa(CXLType3Dev *ct3d, const void *buf= , uint64_t size, */ } =20 +static bool set_cacheline(CXLType3Dev *ct3d, uint64_t dpa_offset, uint8_t = *data) +{ + MemoryRegion *vmr =3D NULL, *pmr =3D NULL; + AddressSpace *as; + + if (ct3d->hostvmem) { + vmr =3D host_memory_backend_get_memory(ct3d->hostvmem); + } + if (ct3d->hostpmem) { + pmr =3D host_memory_backend_get_memory(ct3d->hostpmem); + } + + if (!vmr && !pmr) { + return false; + } + + if (dpa_offset + 64 > int128_get64(ct3d->cxl_dstate.mem_size)) { + return false; + } + + if (vmr) { + if (dpa_offset <=3D int128_get64(vmr->size)) { + as =3D &ct3d->hostvmem_as; + } else { + as =3D &ct3d->hostpmem_as; + dpa_offset -=3D vmr->size; + } + } else { + as =3D &ct3d->hostpmem_as; + } + + address_space_write(as, dpa_offset, MEMTXATTRS_UNSPECIFIED, &data, 64); + return true; +} + void cxl_set_poison_list_overflowed(CXLType3Dev *ct3d) { ct3d->poison_list_overflowed =3D true; @@ -1146,6 +1181,7 @@ static void ct3_class_init(ObjectClass *oc, void *dat= a) cvc->get_lsa_size =3D get_lsa_size; cvc->get_lsa =3D get_lsa; cvc->set_lsa =3D set_lsa; + cvc->set_cacheline =3D set_cacheline; } =20 static const TypeInfo ct3d_info =3D { diff --git a/include/hw/cxl/cxl_device.h b/include/hw/cxl/cxl_device.h index 3cb77fe8a5..0a05f21e40 100644 --- a/include/hw/cxl/cxl_device.h +++ b/include/hw/cxl/cxl_device.h @@ -326,6 +326,7 @@ struct CXLType3Class { uint64_t offset); void (*set_lsa)(CXLType3Dev *ct3d, const void *buf, uint64_t size, uint64_t offset); + bool (*set_cacheline)(CXLType3Dev *ct3d, uint64_t dpa_offset, uint8_t = *data); }; =20 MemTxResult cxl_type3_read(PCIDevice *d, hwaddr host_addr, uint64_t *data, --=20 2.37.2