From patchwork Thu Jan 26 05:37:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ira Weiny X-Patchwork-Id: 13116691 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 450A2C54E94 for ; Thu, 26 Jan 2023 05:37:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235894AbjAZFhd (ORCPT ); Thu, 26 Jan 2023 00:37:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56088 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230064AbjAZFhc (ORCPT ); Thu, 26 Jan 2023 00:37:32 -0500 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE7A851C7B for ; Wed, 25 Jan 2023 21:37:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1674711451; x=1706247451; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=wbtXIUSQfh3quDpVU0waBxAZRw2Bard66Q1jLzQ6/v4=; b=BD8R+xnVfWQazYMhefT/Xnkkdyo2CZtS+ul7UCaMr2Iccl4mvunhiTsH fmIqDKF3sP4LrNIXAw8EmunqnT7K2GHXDAip9OT71AZiQsxJ06t2hK9T5 Ky73Zd0uBf5Ct4+uPSAhURu4PSpzR5ZcDP3SzaoenlIHwD46X9k4U4xlH hxPHHeJPVl1OVCs+3HJO7scy8vMf1HGAQLkSNqRRSz9BZ3oGmgSsNIPJe Wkc+lewShvUIUdOJiS7sF1gE6zZ3vXlG57j8qZ+cJ1aW6I60YAVyhgdVw HQsKs5nygjy9EituR2PIRRQv7EPhc3YAZteprmICXYgEtDdXXRGI7jDjJ w==; X-IronPort-AV: E=McAfee;i="6500,9779,10601"; a="310328966" X-IronPort-AV: E=Sophos;i="5.97,247,1669104000"; d="scan'208";a="310328966" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jan 2023 21:37:31 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10601"; a="786704008" X-IronPort-AV: E=Sophos;i="5.97,247,1669104000"; d="scan'208";a="786704008" Received: from iweiny-mobl.amr.corp.intel.com (HELO localhost) ([10.212.115.122]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jan 2023 21:37:30 -0800 From: Ira Weiny Date: Wed, 25 Jan 2023 21:37:27 -0800 Subject: [PATCH 1/2] hw/cxl: Fix event log time stamp fields MIME-Version: 1.0 Message-Id: <20230125-ira-cxl-events-fixups-2023-01-11-v1-1-1931378515f5@intel.com> References: <20230125-ira-cxl-events-fixups-2023-01-11-v1-0-1931378515f5@intel.com> In-Reply-To: <20230125-ira-cxl-events-fixups-2023-01-11-v1-0-1931378515f5@intel.com> To: Jonathan Cameron Cc: Michael Tsirkin , Ben Widawsky , Peter Maydell , qemu-devel@nongnu.org, linux-cxl@vger.kernel.org, Ira Weiny , Jonathan Cameron X-Mailer: b4 0.12-dev-cc11a X-Developer-Signature: v=1; a=ed25519-sha256; t=1674711449; l=4001; i=ira.weiny@intel.com; s=20221211; h=from:subject:message-id; bh=wbtXIUSQfh3quDpVU0waBxAZRw2Bard66Q1jLzQ6/v4=; b=JpcOxvvrvGTjf1ozWyWNB8NAoCkavbUxwTNnrwrTW2etv+OTwmsLyC1AIdK3RSrHAyhHDeJi2uX2 W+v3cP5pDMx3sWgkF4r1iPVz2StVtOHh+YNn+81GTRBQVWZkiR4f X-Developer-Key: i=ira.weiny@intel.com; a=ed25519; pk=noldbkG+Wp1qXRrrkfY1QJpDf7QsOEthbOT7vm0PqsE= Precedence: bulk List-ID: X-Mailing-List: linux-cxl@vger.kernel.org CXL 3.0 8.2.9.4.2 Set Timestamp and 8.2.9.4.1 Get Timestamp define the way for software to set and get the time stamp of a device. Events should use a time stamp consistent with the Get Timestamp mailbox command. In addition avoid setting the time stamp twice. Fixes: fb64c5661d5f ("hw/cxl/events: Wire up get/clear event mailbox commands") Reported-by: Jonathan Cameron Signed-off-by: Ira Weiny --- hw/cxl/cxl-device-utils.c | 15 +++++++++++++++ hw/cxl/cxl-events.c | 4 +++- hw/cxl/cxl-mailbox-utils.c | 11 +---------- hw/mem/cxl_type3.c | 1 - include/hw/cxl/cxl_device.h | 2 ++ 5 files changed, 21 insertions(+), 12 deletions(-) diff --git a/hw/cxl/cxl-device-utils.c b/hw/cxl/cxl-device-utils.c index 7f29d40be04a..5876a3703e85 100644 --- a/hw/cxl/cxl-device-utils.c +++ b/hw/cxl/cxl-device-utils.c @@ -325,3 +325,18 @@ void cxl_device_register_init_swcci(CXLDeviceState *cxl_dstate) cxl_initialize_mailbox(cxl_dstate, true); } + +uint64_t cxl_device_get_timestamp(CXLDeviceState *cxl_dstate) +{ + uint64_t time, delta; + uint64_t final_time = 0; + + if (cxl_dstate->timestamp.set) { + /* First find the delta from the last time the host set the time. */ + time = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); + delta = time - cxl_dstate->timestamp.last_set; + final_time = cxl_dstate->timestamp.host_set + delta; + } + + return final_time; +} diff --git a/hw/cxl/cxl-events.c b/hw/cxl/cxl-events.c index 08fd52b66188..2536aafc55fb 100644 --- a/hw/cxl/cxl-events.c +++ b/hw/cxl/cxl-events.c @@ -100,7 +100,7 @@ bool cxl_event_insert(CXLDeviceState *cxlds, enum cxl_event_log_type log_type, struct cxl_event_record_raw *event) { - uint64_t time = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); + uint64_t time; struct cxl_event_log *log; CXLEvent *entry; @@ -108,6 +108,8 @@ bool cxl_event_insert(CXLDeviceState *cxlds, return false; } + time = cxl_device_get_timestamp(cxlds); + log = &cxlds->event_logs[log_type]; QEMU_LOCK_GUARD(&log->lock); diff --git a/hw/cxl/cxl-mailbox-utils.c b/hw/cxl/cxl-mailbox-utils.c index 75703023434b..0e64873c2395 100644 --- a/hw/cxl/cxl-mailbox-utils.c +++ b/hw/cxl/cxl-mailbox-utils.c @@ -394,17 +394,8 @@ static CXLRetCode cmd_timestamp_get(struct cxl_cmd *cmd, CXLDeviceState *cxl_dstate, uint16_t *len) { - uint64_t time, delta; - uint64_t final_time = 0; - - if (cxl_dstate->timestamp.set) { - /* First find the delta from the last time the host set the time. */ - time = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); - delta = time - cxl_dstate->timestamp.last_set; - final_time = cxl_dstate->timestamp.host_set + delta; - } + uint64_t final_time = cxl_device_get_timestamp(cxl_dstate); - /* Then adjust the actual time */ stq_le_p(cmd->payload, final_time); *len = 8; diff --git a/hw/mem/cxl_type3.c b/hw/mem/cxl_type3.c index a7b587780af2..42e291dd9f76 100644 --- a/hw/mem/cxl_type3.c +++ b/hw/mem/cxl_type3.c @@ -1291,7 +1291,6 @@ static void cxl_assign_event_header(struct cxl_event_record_hdr *hdr, hdr->flags[0] = flags; hdr->length = length; memcpy(&hdr->id, uuid, sizeof(hdr->id)); - hdr->timestamp = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); } static const QemuUUID gen_media_uuid = { diff --git a/include/hw/cxl/cxl_device.h b/include/hw/cxl/cxl_device.h index cbb37c541c44..31579af342f1 100644 --- a/include/hw/cxl/cxl_device.h +++ b/include/hw/cxl/cxl_device.h @@ -426,4 +426,6 @@ CXLRetCode cxl_event_clear_records(CXLDeviceState *cxlds, void cxl_event_irq_assert(CXLType3Dev *ct3d); +uint64_t cxl_device_get_timestamp(CXLDeviceState *cxlds); + #endif From patchwork Thu Jan 26 05:37:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ira Weiny X-Patchwork-Id: 13116692 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D0C1AC61D9D for ; Thu, 26 Jan 2023 05:37:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230064AbjAZFhe (ORCPT ); Thu, 26 Jan 2023 00:37:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56090 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235936AbjAZFhd (ORCPT ); Thu, 26 Jan 2023 00:37:33 -0500 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 640193E60B for ; Wed, 25 Jan 2023 21:37:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1674711452; x=1706247452; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=TmttUS7xwD55ClAuoEUKjKv5YzYGUkVO9chKYEHMpSM=; b=IK4aUwUGcUppelgleGIgFYFXx41McT+uB4UDix7dCN1gIfRc6CzOR1eM RFR4yjqU63pTRfDizGvVgaRKWQhL6UeAkrSNolJM5uX94hAVrYhTeglEQ SVT+HGaZe9zQCXot2zR7WMR/xXIaNAGx3pa/1yHyAWTwgD7f236gCOJ3w wHGHBAfBIY9T0I0KsQ/yw3xMhHSg1BIqx++I/f/XDdbZe6qW/WuiE+gZh YPzutBLJU+QEkuD1Vn7YAga6JB67s1Cxht4NWWhzYBg17ItLIVjyitJai CS71N01eriK23sVx2KLE+mjZ5G9w7Fnux7xzQx0HfSSYvp+ZaH9rFBBrz Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10601"; a="310328973" X-IronPort-AV: E=Sophos;i="5.97,247,1669104000"; d="scan'208";a="310328973" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jan 2023 21:37:32 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10601"; a="786704012" X-IronPort-AV: E=Sophos;i="5.97,247,1669104000"; d="scan'208";a="786704012" Received: from iweiny-mobl.amr.corp.intel.com (HELO localhost) ([10.212.115.122]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jan 2023 21:37:31 -0800 From: Ira Weiny Date: Wed, 25 Jan 2023 21:37:28 -0800 Subject: [PATCH 2/2] hw/cxl: Remove check for g_new0() failure MIME-Version: 1.0 Message-Id: <20230125-ira-cxl-events-fixups-2023-01-11-v1-2-1931378515f5@intel.com> References: <20230125-ira-cxl-events-fixups-2023-01-11-v1-0-1931378515f5@intel.com> In-Reply-To: <20230125-ira-cxl-events-fixups-2023-01-11-v1-0-1931378515f5@intel.com> To: Jonathan Cameron Cc: Michael Tsirkin , Ben Widawsky , Peter Maydell , qemu-devel@nongnu.org, linux-cxl@vger.kernel.org, Ira Weiny , Jonathan Cameron X-Mailer: b4 0.12-dev-cc11a X-Developer-Signature: v=1; a=ed25519-sha256; t=1674711449; l=923; i=ira.weiny@intel.com; s=20221211; h=from:subject:message-id; bh=TmttUS7xwD55ClAuoEUKjKv5YzYGUkVO9chKYEHMpSM=; b=SjGQo8fu61yc0Hc9DTQNnWEmFHvaMA+6yZUN5MNbr+XC/5Y4Y9tYlIYgSAF92Whod51le4rB/Lcu QWYpyEVjCThrmtlIlECwrqzdZobehQV/tJuhyHNkq75KK8DlcxkY X-Developer-Key: i=ira.weiny@intel.com; a=ed25519; pk=noldbkG+Wp1qXRrrkfY1QJpDf7QsOEthbOT7vm0PqsE= Precedence: bulk List-ID: X-Mailing-List: linux-cxl@vger.kernel.org g_new0() will terminate the application if it fails. Remove the check. Fixes: fb64c5661d5f ("hw/cxl/events: Wire up get/clear event mailbox commands") Reported-by: Jonathan Cameron Signed-off-by: Ira Weiny --- hw/cxl/cxl-events.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/hw/cxl/cxl-events.c b/hw/cxl/cxl-events.c index 2536aafc55fb..4cbc838e8ff4 100644 --- a/hw/cxl/cxl-events.c +++ b/hw/cxl/cxl-events.c @@ -124,13 +124,7 @@ bool cxl_event_insert(CXLDeviceState *cxlds, } entry = g_new0(CXLEvent, 1); - if (!entry) { - error_report("Failed to allocate memory for event log entry"); - return false; - } - memcpy(&entry->data, event, sizeof(*event)); - entry->data.hdr.handle = cpu_to_le16(log->next_handle); log->next_handle++; /* 0 handle is never valid */