From nobody Tue May 13 16:16:56 2025 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