From nobody Sun Nov 10 22:49:10 2024 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=1704985172; cv=none; d=zohomail.com; s=zohoarc; b=Dbm8ro/9WOiv0GsFx/y++ztxWsF/y2o6+Wu7kuvk0f3bnEmK5TdwJQDv7uaXfHSXbdUjn7M1WRBvfi3SZQfYG+xpH621Y50KGefrgFCmkEH+bIev1a/Yyche6KmOMTBYzr/ruUOeecF7gJFasqZlIJJDK508gvowg2ltd3emklI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1704985172; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:Sender:Subject:Subject:To:To:Message-Id; bh=MlOmg2Wn1fmONx92k1lymIka7bX6JFsT9XP6JO1Zj3U=; b=T4MkJcpxpDBp9k09IN3PsYnNBflfGkQFwSs1QUCjoysVQQglsLfVs8ptsuWyT5ubodp8qyZVK0+PCUUe32b1lBL5q2Zsf7zcoTvXyY7HdPgur/wl4xFsr4ktxzxqK/GX7Nf09pY36jbOujYZ0gkHUvTxEOW9l1TwgvObU5fyfvI= 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 1704985172340215.66707975495262; Thu, 11 Jan 2024 06:59:32 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rNwWR-0000a9-TN; Thu, 11 Jan 2024 09:59:08 -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 1rNwWQ-0000Zp-JF for qemu-devel@nongnu.org; Thu, 11 Jan 2024 09:59:06 -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 1rNwWN-0003Vm-Sf for qemu-devel@nongnu.org; Thu, 11 Jan 2024 09:59:06 -0500 Received: from mail.maildlp.com (unknown [172.18.186.216]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4T9nml3B1Dz6J6C1; Thu, 11 Jan 2024 22:56:23 +0800 (CST) Received: from lhrpeml500005.china.huawei.com (unknown [7.191.163.240]) by mail.maildlp.com (Postfix) with ESMTPS id DB8EA140CB9; Thu, 11 Jan 2024 22:59:00 +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.35; Thu, 11 Jan 2024 14:59:00 +0000 To: , , Davidlohr Bueso , Hyeonggon Yoo <42.hyeyoo@gmail.com>, Fan Ni CC: Subject: [PATCH v2 qemu] hw/cxl/device: read from register values in mdev_reg_read() Date: Thu, 11 Jan 2024 14:59:05 +0000 Message-ID: <20240111145905.19797-1-Jonathan.Cameron@huawei.com> X-Mailer: git-send-email 2.39.2 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) 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, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, 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: 1704985174707100009 Content-Type: text/plain; charset="utf-8" From: Hyeonggon Yoo <42.hyeyoo@gmail.com> In the current mdev_reg_read() implementation, it consistently returns that the Media Status is Ready (01b). This was fine until commit 25a52959f99d ("hw/cxl: Add support for device sanitation") because the media was presumed to be ready. However, as per the CXL 3.0 spec "8.2.9.8.5.1 Sanitize (Opcode 4400h)", during sanitation, the Media State should be set to Disabled (11b). The mentioned commit correctly sets it to Disabled, but mdev_reg_read() still returns Media Status as Ready. To address this, update mdev_reg_read() to read register values instead of returning dummy values. Note __toggle_media() was overwriting the mailbox capability register, but nothing was reading that after this so that bug had no obvious effect unless the driver was reloaded. Fixes: commit 25a52959f99d ("hw/cxl: Add support for device sanitation") Signed-off-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> Link: https://lore.kernel.org/r/20231222090051.3265307-3-42.hyeyoo@gmail.com Signed-off-by: Jonathan Cameron -- Hyeonggon - I've kept your sign-off. Let me know if this is ok. Dropped RBs etc as this has changed quite a bit. I plan to send out a group of fixes including this soon, but given I've been pointing out the original fix didn't work thought I'd send this one out for early review! Reviewed-by: Fan Ni --- include/hw/cxl/cxl_device.h | 9 +++++++-- hw/cxl/cxl-device-utils.c | 17 +++++++++++------ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/include/hw/cxl/cxl_device.h b/include/hw/cxl/cxl_device.h index befb5f884b..31d2afcd3d 100644 --- a/include/hw/cxl/cxl_device.h +++ b/include/hw/cxl/cxl_device.h @@ -202,6 +202,9 @@ typedef struct cxl_device_state { }; }; =20 + /* Stash the memory device status value */ + uint64_t memdev_status; + struct { bool set; uint64_t last_set; @@ -353,8 +356,10 @@ static inline void __toggle_media(CXLDeviceState *cxl_= dstate, int val) { uint64_t dev_status_reg; =20 - dev_status_reg =3D FIELD_DP64(0, CXL_MEM_DEV_STS, MEDIA_STATUS, val); - cxl_dstate->mbox_reg_state64[R_CXL_MEM_DEV_STS] =3D dev_status_reg; + dev_status_reg =3D cxl_dstate->memdev_status; + dev_status_reg =3D FIELD_DP64(dev_status_reg, CXL_MEM_DEV_STS, MEDIA_S= TATUS, + val); + cxl_dstate->memdev_status =3D dev_status_reg; } #define cxl_dev_disable_media(cxlds) \ do { __toggle_media((cxlds), 0x3); } while (0) diff --git a/hw/cxl/cxl-device-utils.c b/hw/cxl/cxl-device-utils.c index 61a3c4dc2e..40b619ffd9 100644 --- a/hw/cxl/cxl-device-utils.c +++ b/hw/cxl/cxl-device-utils.c @@ -229,12 +229,9 @@ static void mailbox_reg_write(void *opaque, hwaddr off= set, uint64_t value, =20 static uint64_t mdev_reg_read(void *opaque, hwaddr offset, unsigned size) { - uint64_t retval =3D 0; - - retval =3D FIELD_DP64(retval, CXL_MEM_DEV_STS, MEDIA_STATUS, 1); - retval =3D FIELD_DP64(retval, CXL_MEM_DEV_STS, MBOX_READY, 1); + CXLDeviceState *cxl_dstate =3D opaque; =20 - return retval; + return cxl_dstate->memdev_status; } =20 static void ro_reg_write(void *opaque, hwaddr offset, uint64_t value, @@ -371,7 +368,15 @@ static void mailbox_reg_init_common(CXLDeviceState *cx= l_dstate) cxl_dstate->mbox_msi_n =3D msi_n; } =20 -static void memdev_reg_init_common(CXLDeviceState *cxl_dstate) { } +static void memdev_reg_init_common(CXLDeviceState *cxl_dstate) +{ + uint64_t memdev_status_reg; + + memdev_status_reg =3D FIELD_DP64(0, CXL_MEM_DEV_STS, MEDIA_STATUS, 1); + memdev_status_reg =3D FIELD_DP64(memdev_status_reg, CXL_MEM_DEV_STS, + MBOX_READY, 1); + cxl_dstate->memdev_status =3D memdev_status_reg; +} =20 void cxl_device_register_init_t3(CXLType3Dev *ct3d) { --=20 2.39.2