From nobody Sun Nov 24 22:48:13 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=1720181290; cv=none; d=zohomail.com; s=zohoarc; b=NwS2Nof4wF0xQuEG1YZLdYcvQRzbmN6Dito3RPvcUb5dsxNNfuT2OVFUyN1dPwMa4ZojNKzU10ZjSqbgKtpVEiiJlbFO0ICQKozuhg6hlXi6x6bxO4EzGBdDODYH/13msF6rFi0vbJUp5n+Q585MOL9hyh8Yqph1oa0E7rLfIkE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1720181290; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=DCShP5wU6EyhAbIR7eRM6yl2kToIsdUxKJmIgooU6Gg=; b=RgnmXeIfOs94d7f74JhlA8oT5gpMPnNRwuhICpNTQeBAvFd3vF0K9O6cy2BWfGvgh9Sr32eBV2MGr/jonsdbFsmila5SKwj8VFc06FuEdu2kl3+cHs5Ur32Crbv0iVVZreY2uS+mKT4bOSFE2vfVRLoTOMFKIf5y9NgrzflKP4M= 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 1720181290861295.1706278246762; Fri, 5 Jul 2024 05:08:10 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sPhjE-0007Se-PU; Fri, 05 Jul 2024 08:07:52 -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 1sPhjD-0007Rm-OI for qemu-devel@nongnu.org; Fri, 05 Jul 2024 08:07:51 -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 1sPhjB-0003lx-OZ for qemu-devel@nongnu.org; Fri, 05 Jul 2024 08:07:51 -0400 Received: from mail.maildlp.com (unknown [172.18.186.216]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4WFsh65v07z6HJcl; Fri, 5 Jul 2024 20:07:02 +0800 (CST) Received: from lhrpeml500005.china.huawei.com (unknown [7.191.163.240]) by mail.maildlp.com (Postfix) with ESMTPS id 4CC9D140C98; Fri, 5 Jul 2024 20:07:45 +0800 (CST) Received: from SecurePC-101-06.china.huawei.com (10.122.19.247) by lhrpeml500005.china.huawei.com (7.191.163.240) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Fri, 5 Jul 2024 13:07:44 +0100 To: , , CC: Davidlohr Bueso , Hyeonggon Yoo <42.hyeyoo@gmail.com>, Fan Ni Subject: [PATCH 2/4] hw/cxl/mbox: replace sanitize_running() with cxl_dev_media_disabled() Date: Fri, 5 Jul 2024 13:06:41 +0100 Message-ID: <20240705120643.959422-3-Jonathan.Cameron@huawei.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240705120643.959422-1-Jonathan.Cameron@huawei.com> References: <20240705120643.959422-1-Jonathan.Cameron@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.122.19.247] X-ClientProxiedBy: lhrpeml100002.china.huawei.com (7.191.160.241) 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_H3=0.001, RCVD_IN_MSPIKE_WL=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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1720181291244100001 Content-Type: text/plain; charset="utf-8" From: Hyeonggon Yoo <42.hyeyoo@gmail.com> The spec states that reads/writes should have no effect and a part of commands should be ignored when the media is disabled, not when the sanitize command is running. Introduce cxl_dev_media_disabled() to check if the media is disabled and replace sanitize_running() with it. Make sure that the media has been correctly disabled during sanitation by adding an assert to __toggle_media(). Now, enabling when already enabled or vice versa results in an assert() failure. Suggested-by: Davidlohr Bueso Signed-off-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> Link: https://lore.kernel.org/r/20231222090051.3265307-4-42.hyeyoo@gmail.com Signed-off-by: Jonathan Cameron --- Fix added to ensure the state sanity check only applies on type3 devices --- include/hw/cxl/cxl_device.h | 10 +++++----- hw/cxl/cxl-mailbox-utils.c | 29 +++++++++++++++++------------ hw/mem/cxl_type3.c | 4 ++-- 3 files changed, 24 insertions(+), 19 deletions(-) diff --git a/include/hw/cxl/cxl_device.h b/include/hw/cxl/cxl_device.h index b5beb7f90e..42a622197e 100644 --- a/include/hw/cxl/cxl_device.h +++ b/include/hw/cxl/cxl_device.h @@ -397,14 +397,14 @@ static inline void __toggle_media(CXLDeviceState *cxl= _dstate, int val) #define cxl_dev_enable_media(cxlds) \ do { __toggle_media((cxlds), 0x1); } while (0) =20 -static inline bool scan_media_running(CXLCCI *cci) +static inline bool cxl_dev_media_disabled(CXLDeviceState *cxl_dstate) { - return !!cci->bg.runtime && cci->bg.opcode =3D=3D 0x4304; + uint64_t dev_status_reg =3D cxl_dstate->mbox_reg_state64[R_CXL_MEM_DEV= _STS]; + return FIELD_EX64(dev_status_reg, CXL_MEM_DEV_STS, MEDIA_STATUS) =3D= =3D 0x3; } - -static inline bool sanitize_running(CXLCCI *cci) +static inline bool scan_media_running(CXLCCI *cci) { - return !!cci->bg.runtime && cci->bg.opcode =3D=3D 0x4400; + return !!cci->bg.runtime && cci->bg.opcode =3D=3D 0x4304; } =20 typedef struct CXLError { diff --git a/hw/cxl/cxl-mailbox-utils.c b/hw/cxl/cxl-mailbox-utils.c index 6a60f81794..adeb71071c 100644 --- a/hw/cxl/cxl-mailbox-utils.c +++ b/hw/cxl/cxl-mailbox-utils.c @@ -2115,6 +2115,7 @@ int cxl_process_cci_message(CXLCCI *cci, uint8_t set,= uint8_t cmd, int ret; const struct cxl_cmd *cxl_cmd; opcode_handler h; + CXLDeviceState *cxl_dstate; =20 *len_out =3D 0; cxl_cmd =3D &cci->cxl_cmd_set[set][cmd]; @@ -2135,18 +2136,22 @@ int cxl_process_cci_message(CXLCCI *cci, uint8_t se= t, uint8_t cmd, return CXL_MBOX_BUSY; } =20 - /* forbid any selected commands while overwriting */ - if (sanitize_running(cci)) { - if (h =3D=3D cmd_events_get_records || - h =3D=3D cmd_ccls_get_partition_info || - h =3D=3D cmd_ccls_set_lsa || - h =3D=3D cmd_ccls_get_lsa || - h =3D=3D cmd_logs_get_log || - h =3D=3D cmd_media_get_poison_list || - h =3D=3D cmd_media_inject_poison || - h =3D=3D cmd_media_clear_poison || - h =3D=3D cmd_sanitize_overwrite) { - return CXL_MBOX_MEDIA_DISABLED; + /* forbid any selected commands while the media is disabled */ + if (object_dynamic_cast(OBJECT(cci->d), TYPE_CXL_TYPE3)) { + cxl_dstate =3D &CXL_TYPE3(cci->d)->cxl_dstate; + + if (cxl_dev_media_disabled(cxl_dstate)) { + if (h =3D=3D cmd_events_get_records || + h =3D=3D cmd_ccls_get_partition_info || + h =3D=3D cmd_ccls_set_lsa || + h =3D=3D cmd_ccls_get_lsa || + h =3D=3D cmd_logs_get_log || + h =3D=3D cmd_media_get_poison_list || + h =3D=3D cmd_media_inject_poison || + h =3D=3D cmd_media_clear_poison || + h =3D=3D cmd_sanitize_overwrite) { + return CXL_MBOX_MEDIA_DISABLED; + } } } =20 diff --git a/hw/mem/cxl_type3.c b/hw/mem/cxl_type3.c index 62956a0403..925c88ac5d 100644 --- a/hw/mem/cxl_type3.c +++ b/hw/mem/cxl_type3.c @@ -1127,7 +1127,7 @@ MemTxResult cxl_type3_read(PCIDevice *d, hwaddr host_= addr, uint64_t *data, return MEMTX_ERROR; } =20 - if (sanitize_running(&ct3d->cci)) { + if (cxl_dev_media_disabled(&ct3d->cxl_dstate)) { qemu_guest_getrandom_nofail(data, size); return MEMTX_OK; } @@ -1149,7 +1149,7 @@ MemTxResult cxl_type3_write(PCIDevice *d, hwaddr host= _addr, uint64_t data, return MEMTX_ERROR; } =20 - if (sanitize_running(&ct3d->cci)) { + if (cxl_dev_media_disabled(&ct3d->cxl_dstate)) { return MEMTX_OK; } =20 --=20 2.43.0