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: 13503108 Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8099DD2E0 for ; Fri, 22 Dec 2023 09:01:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Ybl6Zi6c" Received: by mail-pf1-f175.google.com with SMTP id d2e1a72fcca58-6d39132d6baso1017322b3a.0 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=vger.kernel.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=Ybl6Zi6cP8l0vBsPjx8LZjmCH8iZ4HcrBY3upOZBh+6xPXh3VIgQpzAlPhWs2VqhaT O4PleaX1IUn+Oc+rqgHD160JGEE1cnK5DlB7umBeEv2uQ+/7e522oGMhfX1rNOugEZxb UQ6J104vAfIWRFE/3l786kOx2/+rVl00bwe4KxkGC/w4GU0qOgZP8qdm3LcBpzsEHjMM ILe5HzVAHtVbvQSHcqrec8Z2HZqAm+RsLPkKeJyOLn2+sBM9oE9YJ9dv0yqBGK7H6t2K 5yhFx9kbaY/X7zoOJSxlH/0fWOz9G6kUXAGJXjExhl0cLM1ax/sDLQFndzQASlBcf7rQ LK1w== 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=JeVvKHR4WpFK3ANsYjORaCWRjM1dCyKEwp4J7B3mrRBmYrNT2QESde1DdaZmXL0w6b XqB2CgyMT8P/ibfK12SuklYovs5y9T6PrXFwlNOjPBDOdE9ohk+GPhGnPsGchzG9UOUS 8NSP3yqEiRvTHagxfTB4One3HaLclnOgeGzGqFeoIoDK4wI5NgkWZ8rnqXGC/oMZy6mz Q8O/r7iCCp0jXjY4Tu6aaKCgZ87ypwf/cF/QTk+UtieSWc8HBX7DMrieFkWl9B9BxPIx sQUvEQGqiOHa7Dx1H4ff4BwXNQeW/UnN2Od4LTXuInhOeMXNSnujevOYScR3M5gqgMzK KWlg== X-Gm-Message-State: AOJu0YyZuwhX4icKBWakyakQjW11Etk7nvfb0QR2Fbsohlo/BOJDcpB3 lq+i5CYSBwZ5UL+/ywSqTUw= 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> Precedence: bulk X-Mailing-List: linux-cxl@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: 13503109 Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 567D8D2F4 for ; Fri, 22 Dec 2023 09:01:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="FRPmkEbI" Received: by mail-pf1-f175.google.com with SMTP id d2e1a72fcca58-6d939e2f594so1536201b3a.3 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=vger.kernel.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=FRPmkEbI/O6c2H6qGxHngBuMT4m9oC7gIsLPUefO6KtfRYnxjaDOoBV5LN4zPC+P9/ 0yesOSAumxx0pqBl9GxXZzJPH60YrLlbkiFa66sPkabYBvz8MAA9qL1nOEhA0VvnXn8C pcZEv8iDldqbHaC038LPZzXUXNoVxy1xu1Q/M0SafR20l81Ixw6oNz84Qwb//vGoqi2m fT39mrT42ZulrKTksPqtZktPX2X3w1CCunIrFag2GoEgKUKWrEf2MCKfFlKJc/YrUgRR HCmkDPny2aelZM5lGksrIzepPqglp8QMp8XPwRs3LRvmV8XB6ao2XJOVWsRtvM//1sv/ XKLw== 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=K5FmkO3gjjTg6dkEy1jny2IEJNYrCOj7a2voFQ5lnHOi7M/tvutMDcB3d/hNG8U+3w q8WyvC+xgU1AHqejweTAEC9Mc0gPu7KWPiYYsW4ZFslNhE/wrq4R0dr4pm34SEdjezws 0UuvnQ9osGpKPNOsjUlfD6qOAQpkcCqYqOGLx4BRvbkEX25lUng5sa1Cbdjt3XopwISC tBivOXvfpm9KRskgLWwHkThlMCT9cqJ1M8pzh5mpCMsPuV2ku0Af4xsCdwkBdRpKHWwH qpjlr+HTwsHqdSmuZGWSpWT5BtvVvoEXy18el2a6Q6GNwKNu6VA2q5JSXfQj+M6triJ9 gSIA== X-Gm-Message-State: AOJu0Ywyb5vZMna4RhCuWH1+LqOPlo736qhRxEAFEaXK1NgIhvHzazDx wrrjQtfYIXrQnOT2mvF9YBc= 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> Precedence: bulk X-Mailing-List: linux-cxl@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: 13503110 Received: from mail-pg1-f170.google.com (mail-pg1-f170.google.com [209.85.215.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 69427D2E0 for ; Fri, 22 Dec 2023 09:01:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Lo8frDS/" Received: by mail-pg1-f170.google.com with SMTP id 41be03b00d2f7-5c6839373f8so1151132a12.0 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=vger.kernel.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=Lo8frDS/KtPs0i4o93skisg2u3sZFjlt79JtHBcyOPSGyCW6WOUpDQZUN1u8rB15EX nKjOwUScYSTfcxz8K1ItRDa9KCbo4yCijn3BBPbUCnaNUHYEMVV4UaNMB9zbORtVLmm7 RkWQt8+Syr8VjmDyWh1i3L1lB0WFgI1gPHE3K3yN01LCa4UGcI+IqwoNQX4KJyr/iO8q YRPs/PGV7zxx9f5faOjNpphE7PnP7uKivDV6qcdxrAlCXb2f+4jFqYli1OS0q2i6ZOpA fo+ORv4EAFH9ocmdOYA4RclJ2TPH2Aa18G+6rYutXCBP42va9/1KdUtaTPGCwlQ4VMDi MgcA== 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=i6PyQ0hAhkrr/Bh0FjjA7RhE9cSLD8C8P+/1/EapgOZddT40pIpbYKf+J5RcGw/CBm BXsmce9tR7wJC+f0e4ykNhvGbZrTp27xkGf3HjKAzIlV7/rftpPaoPIbQzttyIRcblU0 9omTrxWhzu7swsym6Nw8oRMFde7czXQomsxat7JyXlXYpFQjn32uqb9UA4Fiqj4W5rja eWFnoRPpvt7pmC3V7pGpb9LfQ8tdaRNdY7dfpxLEJmdzo047zJjUpT1Mcb96KMW1FMHa ehlT0vqsv0apRK9kG9qYLIN8aP8P/GQ6pacXNdBaKgfdIqJArXWCwKLB8cu+DlAUtBfE 7fbg== X-Gm-Message-State: AOJu0YwEgo26VzJMFMsQySxHh1xqoF8SudfJipkOnfWfR5zduhOGa2jh edUUkABFTBkcqNuFf3uBEws= 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> Precedence: bulk X-Mailing-List: linux-cxl@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: 13503111 Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7000AD2E7 for ; Fri, 22 Dec 2023 09:01:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="lmt9VmVA" Received: by mail-pf1-f174.google.com with SMTP id d2e1a72fcca58-6d7f1109abcso1069339b3a.3 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=vger.kernel.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=lmt9VmVAaeVUuBDp6cGGmDiom88QTP9/UDAwhWEy7l7W74hzs74dWAmLAgqOD7IWLF czZTQawvwwbnRH0A87zmDpu61ww/GUVIsU3NNYqMGD6my3Kn7ZJFGLxRNNdMhwGmXdR7 qVnSlSFBW03uFvmidlA6vTTSBrfhKrilhOXZFY859gSRvh6D6OjC5PGAsg5k/RigyBDm d2AEteml15U9xufbxTqjPcR2x1mQJgOesKwnQgvlE9Hr7UEk93nxJNXW0S9mtk69/oJR 3M8maR4WYKVY4sM5bAjYorVK+1h900Gbz73mAEV+ZUgZmOq7biEmqv5uZ4yXkm1PLLhL RBoA== 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=ekV9jC959UesXco1wKZQwjqaGhQi0RmoKH1ea0C13G1U7nkZnD+AgEIdlT4WQM0F5H WVfoiUvEqt8PsARDUDtM5swp7sOcTKJc57BVjSbeLwJ3g0JHXpt0Ge1TQtC/6WNJbLLJ o91n+V2dvZjLxoH4ekLWZzAQu8swfDY4izXL74VzDcOXWFKfNsRF/MXhRtWsc2lm9nAE JI7Y3GnCr6hqMa+iyYL9aiy/0mRnXIJmOA+KmbCrRuCMF2D97VwI4clkZUnI1G0/7bjr IGBlxqVHACAKML/hXpgzBibcX3yWEK7fQeVJPCiRZ2/0SbDCcnJyrn1M0x99GTlyQqZ5 mlIg== X-Gm-Message-State: AOJu0Yy0aXb38k4CA0BbG+PKpOtBhv1svO+HN/ltjgYbSCfBfEuy31JI JISzqWdcJOPCNt96DbnZ1Go= 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> Precedence: bulk X-Mailing-List: linux-cxl@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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);