From patchwork Fri Dec 22 09:00:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hyeonggon Yoo <42.hyeyoo@gmail.com> X-Patchwork-Id: 13503106 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AFD1AC46CD4 for ; Fri, 22 Dec 2023 09:02:13 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rGbP2-0005BR-GQ; Fri, 22 Dec 2023 04:01: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 <42.hyeyoo@gmail.com>) id 1rGbP0-0005Ai-6P for qemu-devel@nongnu.org; Fri, 22 Dec 2023 04:01:06 -0500 Received: from mail-pf1-x42b.google.com ([2607:f8b0:4864:20::42b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <42.hyeyoo@gmail.com>) id 1rGbOy-0002Uw-Bl for qemu-devel@nongnu.org; Fri, 22 Dec 2023 04:01:05 -0500 Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-6d267461249so1000778b3a.3 for ; Fri, 22 Dec 2023 01:01:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703235663; x=1703840463; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=hvABOATJauSvkSqTnUfEfpb2YY1wUplxC8fyiFfoJNA=; b=BH1vDfg3sW66a5dscHJnKp3SlamjS7TDWRjuC2cxksXYkOHeMzQ34WHDYK7ZRj565z 4kggpQo0v7z4rFFJpNZiIc5SMSNrAzhC13Kwy8H2S61jKuy5N0wiX8lxbPguRIrXsJcz Cl3dx5jXChWplwUgjLq1PM2K7KL+mjO98De8YXJb7l0FulBAQ9JDmZ9h2mloCqRZOjST GnMoJm8Al5c2cbY+SbS3SkoU4+cCm86T31O3gnbU5b9WFcP7DF56NyWkeF8o43guh+oH PN8Y0/cdOOCMPrRez2KhvH78P+PlAnuaQ7y21fWZN5+n0yQRLVY5nHNZ/rkzJwvdUF8b VxQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703235663; x=1703840463; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hvABOATJauSvkSqTnUfEfpb2YY1wUplxC8fyiFfoJNA=; b=D4vajeyUbO4eTlDwePoISW/XBw5XWG9ICbFrGp9BFtugzlm7TszPsxmPaNk3I/a6Pv YqMKVbZqf2BGYMUoQNzP5rXroGXLtPFMq4P0ZQ03LOF9vpYtz+UmGs6+fIn6Gixs8HD6 F0V/tjDwR2BuHXYU3/pQbKmwe6iq4jhcfKlohiNVhT+XUe1dKnrgWgV0X4vjNJbbW7cl 6cIrtei0Bm/T+bKWMWWyVEYr43zl236/GniKcrX26oQkVY4tDT8H5FoVhRFRm+rRDEdt zoF0/V5+LLeV5zv9Urw0A3P/WAFSocMkEAyfrEqe6UWWWeKMDSNDEa6apYMLeQmiJsWp TJqA== X-Gm-Message-State: AOJu0Yw/CSO7kauiIokGVIiwjY1X6fK4E8rEmCnr5KQeeuGTDWhwblRT 4tWaIYys/mMAjIt70r/KDbQ= X-Google-Smtp-Source: AGHT+IGhWtEpqol/n70fWOtQPCv/l5/XQatLGGrbIXg+l4DVfnjYUXFwCLt1N6LEeqYA3c5Rp0nxYA== X-Received: by 2002:a05:6a00:993:b0:6b2:baa0:6d4c with SMTP id u19-20020a056a00099300b006b2baa06d4cmr732656pfg.33.1703235662524; Fri, 22 Dec 2023 01:01:02 -0800 (PST) Received: from localhost.localdomain ([1.245.180.67]) by smtp.gmail.com with ESMTPSA id f23-20020a056a000b1700b006d990040342sm400560pfu.155.2023.12.22.01.00.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Dec 2023 01:01:01 -0800 (PST) From: Hyeonggon Yoo <42.hyeyoo@gmail.com> To: Jonathan Cameron , Davidlohr Bueso , Fan Ni , "Michael S . Tsirkin" Cc: Hyeonggon Yoo <42.hyeyoo@gmail.com>, linux-cxl@vger.kernel.org, qemu-devel@nongnu.org Subject: [PATCH v2 1/4] hw/cxl: fix build error in cxl_type3_stubs.c Date: Fri, 22 Dec 2023 18:00:48 +0900 Message-Id: <20231222090051.3265307-2-42.hyeyoo@gmail.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20231222090051.3265307-1-42.hyeyoo@gmail.com> References: <20231222090051.3265307-1-42.hyeyoo@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42b; envelope-from=42.hyeyoo@gmail.com; helo=mail-pf1-x42b.google.com X-Spam_score_int: 0 X-Spam_score: -0.1 X-Spam_bar: / X-Spam_report: (-0.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, HK_RANDOM_ENVFROM=0.999, HK_RANDOM_FROM=0.999, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Fix build errors in cxl_type3_stubs.c due to a the incorrect definition of the qmp_cxl_{add,release}_dynamic_capacity functions. Signed-off-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> --- hw/mem/cxl_type3_stubs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/mem/cxl_type3_stubs.c b/hw/mem/cxl_type3_stubs.c index 1b54ec028c..d913b11b4d 100644 --- a/hw/mem/cxl_type3_stubs.c +++ b/hw/mem/cxl_type3_stubs.c @@ -68,14 +68,14 @@ void qmp_cxl_inject_correctable_error(const char *path, CxlCorErrorType type, error_setg(errp, "CXL Type 3 support is not compiled in"); } -void qmp_cxl_add_dynamic_capacity(const char *path, +void qmp_cxl_add_dynamic_capacity(const char *path, uint8_t region_id, CXLDCExtentRecordList *records, Error **errp) { error_setg(errp, "CXL Type 3 support is not compiled in"); } -void qmp_cxl_release_dynamic_capacity(const char *path, +void qmp_cxl_release_dynamic_capacity(const char *path, uint8_t region_id, CXLDCExtentRecordList *records, Error **errp) { From patchwork Fri Dec 22 09:00:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hyeonggon Yoo <42.hyeyoo@gmail.com> X-Patchwork-Id: 13503102 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 86479C41535 for ; Fri, 22 Dec 2023 09:01:53 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rGbP4-0005Bd-4P; Fri, 22 Dec 2023 04:01:10 -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 <42.hyeyoo@gmail.com>) id 1rGbP2-0005BU-Ol for qemu-devel@nongnu.org; Fri, 22 Dec 2023 04:01:08 -0500 Received: from mail-pf1-x434.google.com ([2607:f8b0:4864:20::434]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <42.hyeyoo@gmail.com>) id 1rGbP1-0002VB-3V for qemu-devel@nongnu.org; Fri, 22 Dec 2023 04:01:08 -0500 Received: by mail-pf1-x434.google.com with SMTP id d2e1a72fcca58-6d2350636d6so1535857b3a.2 for ; Fri, 22 Dec 2023 01:01:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703235665; x=1703840465; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=boKgDX4Lvl1vtOxGhAvwh9bjFCyA3++fBUjABFhAblo=; b=e/Ekofny4Zju95KkGLTyOfC/WKHN3geqraR5mowJw/5NdiPlnYx2YrPPTRXUenQr1l IiryBGKoINqJcBSxLmu0fjQl4LghNAflH8DnHPT2LuEgR/Q9V00SsNBvKBRMDO2sQvwo r3a0fO5l0FXhexCSJ0Aa68yeEVhE5c+Yv2UGqtGGJxqukGEAjBuUPSETbQNT1cr6g59k EUH67g7XGRRejkx3DtLYpDURMEKAGEnLh+Bitq3KTUcWi/oA596aMZ0Vahit3vcmjY2p GnmW8KHuPH4yGpKUZKDMbvRgQXuTQ7nl/FHWteafbrT8pI6EW2LbuXd2ssyRhieNqAdT 2c1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703235665; x=1703840465; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=boKgDX4Lvl1vtOxGhAvwh9bjFCyA3++fBUjABFhAblo=; b=XbGtCsA3f7xEq4UeedGEAwoQH6QoVAkEtmEOC5YAJDhUoG/ZrwQ+yJQJ1xpiCgJ3gq +5/5kkeekahDfOfVDTMq02fMU/h8Ay6qiEZnksiXiWQP2ImPAZb/EjMc3mggmFaaHFEk bFs5AQ2mV8p9/zPGVcrfuY3AVtHlhHlnhWjS7mk6eJTSaSriz4B8ml0fJnJVkHS8203h xwCPJ7RD0jsMwd+T4oi7/kLL15GTtNjNpwGawlHDegH+bw9FFYQHgRYiwzyoaiWbs4pB MpfQ2Z8rKHy36YRjbfNFjrchXfolxtjJLeummU+PL7uDl8rVvZbvM2DpXLmcKEUEF3mO Xxrw== X-Gm-Message-State: AOJu0YwFJG3aRp1oUFKBntZh9k6QC6udxNsAuN4o3Hoza1CZ3EjMgXU5 JXvxdsD/U8RYvzyZfmKZii0= X-Google-Smtp-Source: AGHT+IETskAy68zOVeR/Q/Oxdx5/PrTDs3S/QqTI7jdFInnq4s3g5TIrI8rTadDT8T3mGuNny9GHng== X-Received: by 2002:aa7:84d0:0:b0:6d9:5d0f:bee8 with SMTP id x16-20020aa784d0000000b006d95d0fbee8mr1106915pfn.10.1703235665406; Fri, 22 Dec 2023 01:01:05 -0800 (PST) Received: from localhost.localdomain ([1.245.180.67]) by smtp.gmail.com with ESMTPSA id f23-20020a056a000b1700b006d990040342sm400560pfu.155.2023.12.22.01.01.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Dec 2023 01:01:04 -0800 (PST) From: Hyeonggon Yoo <42.hyeyoo@gmail.com> To: Jonathan Cameron , Davidlohr Bueso , Fan Ni , "Michael S . Tsirkin" Cc: Hyeonggon Yoo <42.hyeyoo@gmail.com>, linux-cxl@vger.kernel.org, qemu-devel@nongnu.org Subject: [PATCH v2 2/4] hw/cxl/device: read from register values in mdev_reg_read() Date: Fri, 22 Dec 2023 18:00:49 +0900 Message-Id: <20231222090051.3265307-3-42.hyeyoo@gmail.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20231222090051.3265307-1-42.hyeyoo@gmail.com> References: <20231222090051.3265307-1-42.hyeyoo@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::434; envelope-from=42.hyeyoo@gmail.com; helo=mail-pf1-x434.google.com X-Spam_score_int: 0 X-Spam_score: -0.1 X-Spam_bar: / X-Spam_report: (-0.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, HK_RANDOM_ENVFROM=0.999, HK_RANDOM_FROM=0.999, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org 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. Fixes: commit 25a52959f99d ("hw/cxl: Add support for device sanitation") Reviewed-by: Davidlohr Bueso Signed-off-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> --- hw/cxl/cxl-device-utils.c | 17 +++++++++++------ include/hw/cxl/cxl_device.h | 4 +++- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/hw/cxl/cxl-device-utils.c b/hw/cxl/cxl-device-utils.c index 29de298117..ba3f80e6e7 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 offset, uint64_t value, static uint64_t mdev_reg_read(void *opaque, hwaddr offset, unsigned size) { - uint64_t retval = 0; - - retval = FIELD_DP64(retval, CXL_MEM_DEV_STS, MEDIA_STATUS, 1); - retval = FIELD_DP64(retval, CXL_MEM_DEV_STS, MBOX_READY, 1); + CXLDeviceState *cxl_dstate = opaque; - return retval; + return cxl_dstate->mbox_reg_state64[R_CXL_MEM_DEV_STS]; } static void ro_reg_write(void *opaque, hwaddr offset, uint64_t value, @@ -371,7 +368,15 @@ static void mailbox_reg_init_common(CXLDeviceState *cxl_dstate) cxl_dstate->mbox_msi_n = msi_n; } -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 = FIELD_DP64(0, CXL_MEM_DEV_STS, MEDIA_STATUS, 1); + memdev_status_reg = FIELD_DP64(memdev_status_reg, CXL_MEM_DEV_STS, + MBOX_READY, 1); + cxl_dstate->mbox_reg_state64[R_CXL_MEM_DEV_STS] = memdev_status_reg; +} void cxl_device_register_init_t3(CXLType3Dev *ct3d) { diff --git a/include/hw/cxl/cxl_device.h b/include/hw/cxl/cxl_device.h index b2cb280e16..b318d94b36 100644 --- a/include/hw/cxl/cxl_device.h +++ b/include/hw/cxl/cxl_device.h @@ -408,7 +408,9 @@ static inline void __toggle_media(CXLDeviceState *cxl_dstate, int val) { uint64_t dev_status_reg; - dev_status_reg = FIELD_DP64(0, CXL_MEM_DEV_STS, MEDIA_STATUS, val); + dev_status_reg = cxl_dstate->mbox_reg_state64[R_CXL_MEM_DEV_STS]; + dev_status_reg = FIELD_DP64(dev_status_reg, CXL_MEM_DEV_STS, MEDIA_STATUS, + val); cxl_dstate->mbox_reg_state64[R_CXL_MEM_DEV_STS] = dev_status_reg; } #define cxl_dev_disable_media(cxlds) \ From patchwork Fri Dec 22 09:00:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hyeonggon Yoo <42.hyeyoo@gmail.com> X-Patchwork-Id: 13503104 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B56B7C46CD4 for ; Fri, 22 Dec 2023 09:02:01 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rGbP7-0005CO-8l; Fri, 22 Dec 2023 04:01:13 -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 <42.hyeyoo@gmail.com>) id 1rGbP5-0005C1-SL for qemu-devel@nongnu.org; Fri, 22 Dec 2023 04:01:11 -0500 Received: from mail-pg1-x529.google.com ([2607:f8b0:4864:20::529]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <42.hyeyoo@gmail.com>) id 1rGbP4-0002VN-58 for qemu-devel@nongnu.org; Fri, 22 Dec 2023 04:01:11 -0500 Received: by mail-pg1-x529.google.com with SMTP id 41be03b00d2f7-5cd86e3a9afso1137891a12.1 for ; Fri, 22 Dec 2023 01:01:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703235669; x=1703840469; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Pze2Cv/T1AorC9TH3ggyhouTOliDmqm2cL056dpXiT8=; b=fCcmmmjXC3Ch8x+uAeGgSA0Jqtwc4oldQ3nAAilXa1EWBzuYreMEcieE9Ghl4lpjkE d3DjHVDrH2bRjJiqQM4UrHmypwQFHDy1B2lVD9rcgb6NtEulD1LMMLgO8hxLtMsJMte/ +KOY1NvCsmeA6KBG2djJ/10ZI+f94Ys+Z/mXI4qSr6y7jSWkX6AFqW+Yar/+oM4RMAmd BvAmQQFzZ1SkW1nmPQa1zHZHQVD4tR2aONALr0IKB6ywYIhJqeoxcc/lMasO6JX6ZUBN sKePe+lDlRqs6b/vNY9lUxvh8l5NSB350oAi8wnK2CVNbkyFmlYwu45oRKmpV6Hl5YsU tvXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703235669; x=1703840469; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Pze2Cv/T1AorC9TH3ggyhouTOliDmqm2cL056dpXiT8=; b=aWiJkoHalXT+ZSHh7w3AZxLNPcpF2AhUc8XjrxBrlsoM2qoZUJ5OXsz7sP66E+TZNz hCwHWhdjwQXrFa+fWVVlwq9UeqDiCG14pn9yGnG9cGHdySPDKqIf2dEuZ7FcrLMX4gnd GbIJPOA0FmKK0AV87AVC8NFCq/7xhvijw3WwzgT5nkVuKZ2MJzqL4nZR12uat7XZ3vJJ DfkV/8LG9NkvNE+K/EZhLF6emK4QS5ymTVo+qTKMlCM4ESlwVUOxo4i5qsCFrWEYoM3V skeAADfg4NR7bBnWFZvPabqDbLgUuD2iZckwbZmVYnnIrDExIfE7uZEcxVFNxKDVhs9M aBWQ== X-Gm-Message-State: AOJu0YxmEUnViir6hUqSn+tdEUGTail2pNi21uM/nPF2koYzb8VQsgmh fiZwjlwDPgsekBJHyF7ceYQ= X-Google-Smtp-Source: AGHT+IFugj/FMKrijP+kRxUM50nlGrQTcMl7Fd4knps99Pd2Lf7vMloX5ys0XXcnF4fFb4l4YI2U5g== X-Received: by 2002:a05:6a20:8814:b0:194:ffaa:a2c3 with SMTP id c20-20020a056a20881400b00194ffaaa2c3mr966439pzf.1.1703235668571; Fri, 22 Dec 2023 01:01:08 -0800 (PST) Received: from localhost.localdomain ([1.245.180.67]) by smtp.gmail.com with ESMTPSA id f23-20020a056a000b1700b006d990040342sm400560pfu.155.2023.12.22.01.01.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Dec 2023 01:01:07 -0800 (PST) From: Hyeonggon Yoo <42.hyeyoo@gmail.com> To: Jonathan Cameron , Davidlohr Bueso , Fan Ni , "Michael S . Tsirkin" Cc: Hyeonggon Yoo <42.hyeyoo@gmail.com>, linux-cxl@vger.kernel.org, qemu-devel@nongnu.org Subject: [PATCH v2 3/4] hw/cxl/mbox: replace sanitize_running() with cxl_dev_media_disabled() Date: Fri, 22 Dec 2023 18:00:50 +0900 Message-Id: <20231222090051.3265307-4-42.hyeyoo@gmail.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20231222090051.3265307-1-42.hyeyoo@gmail.com> References: <20231222090051.3265307-1-42.hyeyoo@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::529; envelope-from=42.hyeyoo@gmail.com; helo=mail-pg1-x529.google.com X-Spam_score_int: 0 X-Spam_score: -0.1 X-Spam_bar: / X-Spam_report: (-0.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, HK_RANDOM_ENVFROM=0.999, HK_RANDOM_FROM=0.999, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org 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> --- hw/cxl/cxl-mailbox-utils.c | 6 ++++-- hw/mem/cxl_type3.c | 4 ++-- include/hw/cxl/cxl_device.h | 11 ++++++----- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/hw/cxl/cxl-mailbox-utils.c b/hw/cxl/cxl-mailbox-utils.c index 11ec8b648b..efeb5f8174 100644 --- a/hw/cxl/cxl-mailbox-utils.c +++ b/hw/cxl/cxl-mailbox-utils.c @@ -2248,6 +2248,8 @@ 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 = &CXL_TYPE3(cci->intf)->cxl_dstate; + *len_out = 0; cxl_cmd = &cci->cxl_cmd_set[set][cmd]; @@ -2268,8 +2270,8 @@ int cxl_process_cci_message(CXLCCI *cci, uint8_t set, uint8_t cmd, return CXL_MBOX_BUSY; } - /* forbid any selected commands while overwriting */ - if (sanitize_running(cci)) { + /* forbid any selected commands while the media is disabled */ + if (cxl_dev_media_disabled(cxl_dstate)) { if (h == cmd_events_get_records || h == cmd_ccls_get_partition_info || h == cmd_ccls_set_lsa || diff --git a/hw/mem/cxl_type3.c b/hw/mem/cxl_type3.c index 85fc08f118..ecb525a608 100644 --- a/hw/mem/cxl_type3.c +++ b/hw/mem/cxl_type3.c @@ -1286,7 +1286,7 @@ MemTxResult cxl_type3_read(PCIDevice *d, hwaddr host_addr, uint64_t *data, return MEMTX_ERROR; } - if (sanitize_running(&ct3d->cci)) { + if (cxl_dev_media_disabled(&ct3d->cxl_dstate)) { qemu_guest_getrandom_nofail(data, size); return MEMTX_OK; } @@ -1314,7 +1314,7 @@ MemTxResult cxl_type3_write(PCIDevice *d, hwaddr host_addr, uint64_t data, return MEMTX_ERROR; } - if (sanitize_running(&ct3d->cci)) { + if (cxl_dev_media_disabled(&ct3d->cxl_dstate)) { return MEMTX_OK; } diff --git a/include/hw/cxl/cxl_device.h b/include/hw/cxl/cxl_device.h index b318d94b36..5618061ebe 100644 --- a/include/hw/cxl/cxl_device.h +++ b/include/hw/cxl/cxl_device.h @@ -411,6 +411,7 @@ static inline void __toggle_media(CXLDeviceState *cxl_dstate, int val) dev_status_reg = cxl_dstate->mbox_reg_state64[R_CXL_MEM_DEV_STS]; dev_status_reg = FIELD_DP64(dev_status_reg, CXL_MEM_DEV_STS, MEDIA_STATUS, val); + assert(dev_status_reg != cxl_dstate->mbox_reg_state64[R_CXL_MEM_DEV_STS]); cxl_dstate->mbox_reg_state64[R_CXL_MEM_DEV_STS] = dev_status_reg; } #define cxl_dev_disable_media(cxlds) \ @@ -418,14 +419,14 @@ static inline void __toggle_media(CXLDeviceState *cxl_dstate, int val) #define cxl_dev_enable_media(cxlds) \ do { __toggle_media((cxlds), 0x1); } while (0) -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 == 0x4304; + uint64_t dev_status_reg = cxl_dstate->mbox_reg_state64[R_CXL_MEM_DEV_STS]; + return FIELD_EX64(dev_status_reg, CXL_MEM_DEV_STS, MEDIA_STATUS) == 0x3; } - -static inline bool sanitize_running(CXLCCI *cci) +static inline bool scan_media_running(CXLCCI *cci) { - return !!cci->bg.runtime && cci->bg.opcode == 0x4400; + return !!cci->bg.runtime && cci->bg.opcode == 0x4304; } typedef struct CXLError { From patchwork Fri Dec 22 09:00:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hyeonggon Yoo <42.hyeyoo@gmail.com> X-Patchwork-Id: 13503103 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9493FC46CD4 for ; Fri, 22 Dec 2023 09:01:58 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rGbP9-0005CZ-Rt; Fri, 22 Dec 2023 04:01:15 -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 <42.hyeyoo@gmail.com>) id 1rGbP8-0005CR-R8 for qemu-devel@nongnu.org; Fri, 22 Dec 2023 04:01:14 -0500 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <42.hyeyoo@gmail.com>) id 1rGbP7-0002Va-7n for qemu-devel@nongnu.org; Fri, 22 Dec 2023 04:01:14 -0500 Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-6d7395ab92cso1070345b3a.2 for ; Fri, 22 Dec 2023 01:01:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703235672; x=1703840472; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=W2onsigAzJZV8OA9wsWeUj+BIGS+8SDO0C+tc8HGOhY=; b=RRYjoOaniViuTlPY5MinFrVurQSIuzE3HhzJoOX54x7rbcW/D0MMuWhIZ5m7PLaBea gn5KJZHEUgEeMwC2zFZuahj24md4ELyxnrcWif0Vap2gOHEc36pGfiovBNXKTlAAv/X3 7i+fzUMtmCSdIOYwIP8NLZ8l/wdSP0Tfs8Z7u+GZvqZbzU4lETk0wpaMjwLBO7Zts1YU LQXA/uaWjKYwW9ElIOjeaOQ6Vl9/Z1QRsgPNM5G4eQvH6VsY4EaTiF3D/OtDFDYXchrx QNd3mAMcW70uRYpAXPgQp6OYAoodj+Pp7Q25936YWQYKFadbBs0kPtEDtiSfdlSFhV6T Ja+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703235672; x=1703840472; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=W2onsigAzJZV8OA9wsWeUj+BIGS+8SDO0C+tc8HGOhY=; b=kyAexb8Un3PbJYVGV8N2vQD78h4kwO9cdbXAOZLXI9A8EO171TdV2H1zEKwI+nNaLQ JrN2ki8RkEY7e9rtwUCFgnqjizXvTy9DrH63BA/WWeQfDCmvOe5dpZgsemxfu6deWVxy R0ga2xCyYGr2if6at5M+oClfrw49OhhazQ0alfw7n0s7uRX3l9Wy06xQ4jZc2/G2yQwI /MbaKLPDqXtfrqiDBBYqJoKnOpwYnb1wtWYyieDnliTy7hDg2xVgnhHmKNFZPutyDfjZ GF+BzY5UFi17PhWQe9DZSnXMDm+Jj44BDFlWOjsZq+SwXfA8L3qvrCensYjSsnAD57Bd 3x8w== X-Gm-Message-State: AOJu0YwZ1AdiGnPspCo5t94fHUQlNIJV+3XfHf9sCt/8IG0H+YL6+Iff OkC5IHwEp65EZ/2JanUBdLU= X-Google-Smtp-Source: AGHT+IEQy6RlE35SipM9nNEMtU2PXXoNbifceNoOLuT+BPwv1mrmvRkw2/FTJSVF4OtWawIMnyR29g== X-Received: by 2002:a05:6a00:e07:b0:6d0:89be:e4a8 with SMTP id bq7-20020a056a000e0700b006d089bee4a8mr834227pfb.37.1703235671523; Fri, 22 Dec 2023 01:01:11 -0800 (PST) Received: from localhost.localdomain ([1.245.180.67]) by smtp.gmail.com with ESMTPSA id f23-20020a056a000b1700b006d990040342sm400560pfu.155.2023.12.22.01.01.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Dec 2023 01:01:10 -0800 (PST) From: Hyeonggon Yoo <42.hyeyoo@gmail.com> To: Jonathan Cameron , Davidlohr Bueso , Fan Ni , "Michael S . Tsirkin" Cc: Hyeonggon Yoo <42.hyeyoo@gmail.com>, linux-cxl@vger.kernel.org, qemu-devel@nongnu.org Subject: [PATCH v2 4/4] hw/cxl/events: discard all event records during sanitation Date: Fri, 22 Dec 2023 18:00:51 +0900 Message-Id: <20231222090051.3265307-5-42.hyeyoo@gmail.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20231222090051.3265307-1-42.hyeyoo@gmail.com> References: <20231222090051.3265307-1-42.hyeyoo@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42c; envelope-from=42.hyeyoo@gmail.com; helo=mail-pf1-x42c.google.com X-Spam_score_int: 0 X-Spam_score: -0.1 X-Spam_bar: / X-Spam_report: (-0.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, HK_RANDOM_ENVFROM=0.999, HK_RANDOM_FROM=0.999, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Per spec 8.2.9.9.5.1 Sanitize (Opcode 4400h), sanitize command should delete all event logs. Introduce cxl_discard_all_event_logs() and call this in __do_sanitization(). Signed-off-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> Reviewed-by: Davidlohr Bueso --- hw/cxl/cxl-events.c | 13 +++++++++++++ hw/cxl/cxl-mailbox-utils.c | 1 + include/hw/cxl/cxl_device.h | 1 + 3 files changed, 15 insertions(+) diff --git a/hw/cxl/cxl-events.c b/hw/cxl/cxl-events.c index bee6dfaf14..837b18ab47 100644 --- a/hw/cxl/cxl-events.c +++ b/hw/cxl/cxl-events.c @@ -141,6 +141,19 @@ bool cxl_event_insert(CXLDeviceState *cxlds, CXLEventLogType log_type, return cxl_event_count(log) == 1; } +void cxl_discard_all_event_records(CXLDeviceState *cxlds) +{ + CXLEventLogType log_type; + CXLEventLog *log; + + for (log_type = 0; log_type < CXL_EVENT_TYPE_MAX; log_type++) { + log = &cxlds->event_logs[log_type]; + while (!cxl_event_empty(log)) { + cxl_event_delete_head(cxlds, log_type, log); + } + } +} + CXLRetCode cxl_event_get_records(CXLDeviceState *cxlds, CXLGetEventPayload *pl, uint8_t log_type, int max_recs, size_t *len) diff --git a/hw/cxl/cxl-mailbox-utils.c b/hw/cxl/cxl-mailbox-utils.c index efeb5f8174..2ade351d82 100644 --- a/hw/cxl/cxl-mailbox-utils.c +++ b/hw/cxl/cxl-mailbox-utils.c @@ -1150,6 +1150,7 @@ static void __do_sanitization(CXLType3Dev *ct3d) memset(lsa, 0, memory_region_size(mr)); } } + cxl_discard_all_event_records(&ct3d->cxl_dstate); } /* diff --git a/include/hw/cxl/cxl_device.h b/include/hw/cxl/cxl_device.h index 5618061ebe..8f05dd9beb 100644 --- a/include/hw/cxl/cxl_device.h +++ b/include/hw/cxl/cxl_device.h @@ -604,6 +604,7 @@ CXLRetCode cxl_event_get_records(CXLDeviceState *cxlds, CXLGetEventPayload *pl, size_t *len); CXLRetCode cxl_event_clear_records(CXLDeviceState *cxlds, CXLClearEventPayload *pl); +void cxl_discard_all_event_records(CXLDeviceState *cxlds); void cxl_event_irq_assert(CXLType3Dev *ct3d);