From patchwork Thu Jul 20 20:37:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "nifan@outlook.com" X-Patchwork-Id: 13321039 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 3949DC0015E for ; Thu, 20 Jul 2023 20:38:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229452AbjGTUii (ORCPT ); Thu, 20 Jul 2023 16:38:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229683AbjGTUih (ORCPT ); Thu, 20 Jul 2023 16:38:37 -0400 Received: from APC01-TYZ-obe.outbound.protection.outlook.com (mail-tyzapc01olkn2058.outbound.protection.outlook.com [40.92.107.58]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 48302271E for ; Thu, 20 Jul 2023 13:38:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MWUXVJEWl2frjECw3/4bYzHXPupcZud7oFZydAXpEpcCEV4i5q0aoEM3ZJNIFIRzO+pSPZzm/aoEHvs1naQy6xO9U/+sfu5J+z3DLAr3bWvr3KpbmZdZYm70SefzEq7Tp40sRaJ7GO52XV+JNRfAT0TyGxH05YLG0gcYnEMjgWqw7yotrdzLwlL3zwDj5O5JfNliURGCYTSz2Hg33Dg1HD01aF/WRguUMR24q0cIhs4yimBTX1RHhzSF9/eq0cY4tXCO/YdAwJI7AhKhLGp3cBpTUmuGfNeYpLgsJWmoKZcqx3CWpXThZAyl//YQ+XHF2p0tX/uWahf3BCvgF0VfBw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=zc3snFHch0Yog7PbxZY00Kvf0mJgyeR3W6EURrCYLtA=; b=BjnMrhmHNw0zuttPLpBjl20Gn4adv8IgG30Cqq+VMngfMMqp4FUFDb9/9MzOXbm6PXF4RH3BETd/mrZd23aodouOBAgEONEvcU7/LP0MK0bIyL6XMbcb/+MhRfjPQtqFauTYx84VDAnieoQHLnH/NU8PZm/tIWz+373IUXgIYxXNO6qpwcJy0KdMG2mtQ4zqUnZC0TCGkyu7q42HVpDR+QGIH/pmA0ixcvD6ZiYW4+mKQm9yJh/LXhs8io6xCfWWeV9TT/35n4JTAUA70j0zf0wHrxnBO37ten31GBMm+vJKkdMruoYaAU8PC9nQAzhRCPSudaS5LdD1jAFwlFsE2Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=zc3snFHch0Yog7PbxZY00Kvf0mJgyeR3W6EURrCYLtA=; b=lLzvTZAfrIMAgl7dylTM7viNJlTsvXTLMSrp3vXEqn2pYDrVC8Qm8lJbknH/bdlAxnkMC8INGfXaHij+L7txGEOTmHnqUHeBujT8u581xO+Ynx7IG9g5xfDIf13ppuNybIIm8Jup0w2gdl0vOikKGa59ZACMkD4qPGg0SfzffqR9wdgqEg7fz2ubC2uJqFZZKNQ+0ebuFF183HmXXEJlBuarJWown8Lthu6rur4rgxwYX0lKzg3IX261q8JUEq1qBPRlUf8oZYmpJN/4UnPg56oDpnwJ54Tt79pajgdTPVwgnw4IsmUDnqpUg8u7URcmIrm+iRRgFsxjliKGDrHoeQ== Received: from SG2PR06MB3397.apcprd06.prod.outlook.com (2603:1096:4:7a::17) by KL1PR0601MB4100.apcprd06.prod.outlook.com (2603:1096:820:24::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6609.24; Thu, 20 Jul 2023 20:38:29 +0000 Received: from SG2PR06MB3397.apcprd06.prod.outlook.com ([fe80::450:9c8c:9058:c94c]) by SG2PR06MB3397.apcprd06.prod.outlook.com ([fe80::450:9c8c:9058:c94c%5]) with mapi id 15.20.6609.024; Thu, 20 Jul 2023 20:38:29 +0000 From: nifan@outlook.com To: qemu-devel@nongnu.org Cc: jonathan.cameron@huawei.com, linux-cxl@vger.kernel.org, gregory.price@memverge.com, hchkuo@avery-design.com.tw, cbrowy@avery-design.com, ira.weiny@intel.com, dan.j.williams@intel.com, a.manzanares@samsung.com, dave@stgolabs.net, nmtadam.samsung@gmail.com, Fan Ni , Fan Ni Subject: [PATCH 1/9] hw/cxl/cxl-mailbox-utils: Add dc_event_log_size field to output payload of identify memory device command Date: Thu, 20 Jul 2023 13:37:00 -0700 Message-ID: X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230720203708.25825-1-nifan@outlook.com> References: <20230720203708.25825-1-nifan@outlook.com> X-TMN: [ZWUtNriF/S9k+E5ELQxCU4jKTSI1uvfD] X-ClientProxiedBy: BYAPR03CA0008.namprd03.prod.outlook.com (2603:10b6:a02:a8::21) To SG2PR06MB3397.apcprd06.prod.outlook.com (2603:1096:4:7a::17) X-Microsoft-Original-Message-ID: <20230720203708.25825-2-nifan@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SG2PR06MB3397:EE_|KL1PR0601MB4100:EE_ X-MS-Office365-Filtering-Correlation-Id: 0b7c0c3b-d6db-40e2-e421-08db89612440 X-MS-Exchange-SLBlob-MailProps: quCBMN2EvO/qzAKd82WE1LuLgf/v/GCyttTW/NfaJ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QJ8d0MWtWo4FtqhjmGrNK4IjNVWGTxrwVY2WUJuU8kQjC3hWzTTJR2WY+JOlC3Yp5V0HR9jxHnG2a+ydFuN7AbR9HkKMw3iMAcn/zOTb3PH5Fsk0LAMJSKSy7awhIbTUkw5mgbGfYVZOdG2daWqHozHulXBsi4QHn5pRWE/uXqIKAUA67DFBK/InqdisN4wNRgIW/FJ3mWlAMEPzj0UJUJ3z631mqh0AFMlFSmP0FN129RPiiz3sZwvxydRj5vFitGErJtzYe78e72SUhOqLK1n0lz2N3i8GqKVbXTJ055TOarUsKRjT0PjcO0J10JbJKzKJPXz4WKE/0c8RF78Vw5fTC6yYzkcGwtgyS0gvdgteoM/whxuiJDthKO3rHJ6EOs8WWPqoPXONkNM9q3hsOW2GaDYKZ5H6EJAHNIeQnthQgYpUCBoTNtWetCHf8ComZmssTfcK5iZFMcBsPH/fgBM4gIKWw== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0b7c0c3b-d6db-40e2-e421-08db89612440 X-MS-Exchange-CrossTenant-AuthSource: SG2PR06MB3397.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Jul 2023 20:37:31.8432 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: KL1PR0601MB4100 Precedence: bulk List-ID: X-Mailing-List: linux-cxl@vger.kernel.org From: Fan Ni Based on CXL spec 3.0 Table 8-94 (Identify Memory Device Output Payload), dynamic capacity event log size should be part of output of the Identify command. Add dc_event_log_size to the output payload for the host to get the info. Signed-off-by: Fan Ni --- hw/cxl/cxl-mailbox-utils.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/hw/cxl/cxl-mailbox-utils.c b/hw/cxl/cxl-mailbox-utils.c index ad7a6116e4..b013e30314 100644 --- a/hw/cxl/cxl-mailbox-utils.c +++ b/hw/cxl/cxl-mailbox-utils.c @@ -21,6 +21,8 @@ #include "sysemu/hostmem.h" #define CXL_CAPACITY_MULTIPLIER (256 * MiB) +/* Experimental value: dynamic capacity event log size */ +#define CXL_DC_EVENT_LOG_SIZE 8 /* * How to add a new command, example. The command set FOO, with cmd BAR. @@ -519,8 +521,9 @@ static CXLRetCode cmd_identify_memory_device(struct cxl_cmd *cmd, uint16_t inject_poison_limit; uint8_t poison_caps; uint8_t qos_telemetry_caps; + uint16_t dc_event_log_size; } QEMU_PACKED *id; - QEMU_BUILD_BUG_ON(sizeof(*id) != 0x43); + QEMU_BUILD_BUG_ON(sizeof(*id) != 0x45); CXLType3Dev *ct3d = container_of(cxl_dstate, CXLType3Dev, cxl_dstate); CXLType3Class *cvc = CXL_TYPE3_GET_CLASS(ct3d); @@ -543,6 +546,7 @@ static CXLRetCode cmd_identify_memory_device(struct cxl_cmd *cmd, st24_le_p(id->poison_list_max_mer, 256); /* No limit - so limited by main poison record limit */ stw_le_p(&id->inject_poison_limit, 0); + stw_le_p(&id->dc_event_log_size, CXL_DC_EVENT_LOG_SIZE); *len = sizeof(*id); return CXL_MBOX_SUCCESS; From patchwork Thu Jul 20 20:37:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "nifan@outlook.com" X-Patchwork-Id: 13321042 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 152ACEB64DA for ; Thu, 20 Jul 2023 20:38:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229683AbjGTUin (ORCPT ); Thu, 20 Jul 2023 16:38:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35738 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229576AbjGTUim (ORCPT ); Thu, 20 Jul 2023 16:38:42 -0400 Received: from APC01-TYZ-obe.outbound.protection.outlook.com (mail-tyzapc01olkn2098.outbound.protection.outlook.com [40.92.107.98]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 40D5E271D for ; Thu, 20 Jul 2023 13:38:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=D6emttcPdsGW6RkrGUomlRA4fRdrcAgtyiAWW7THqZjNOqQfh3VEYrEPZiTjrpHwTVmAKPpPzB0uFDcZdgwhOWCaE0TwnWBEtr2QQ9jUpoAtk4ORffPUK9wuXyUSVo2gTmgueP93+4IyrjmIuw6r6TKcnsbAQR3FJJUlLFzTDPcNBxcyU/zfpdRQHrxxfKYZIFyUjbq6lbxvbeF25UUJDzRCjqtZBS0zV5ZaMIwmyBikJJheV7gOM9lx8k3WiE60KjTNI2hyN8Ehtep7lWLhvzpkJN75VVL7FzSCPtSjDIc+8hMQ/NzAgXDVbNi2JafiB1saVAp/Hrnlnpf/sDHrkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=oY7kfGbbEytWCbfjZot/RU8TYd4HEhxmSgEpD80bDJE=; b=mLXcxGeaTkHo8Gs48yR3q9YVfw4NWb9fOqKwrlh59vGXPC87sfFX4ZtZhRhjlB45TVdUGA2zZ9d1Nqr2KWY+aRdinLO98TDr574YMjswzLVZdKVWOT5S1tYymlS1wi8VWWSuAU8nEJ7m+Sa2DRTmbOPTJVrSgpAMG4j8rF7Ow19rxK1b6WYrbRxkyo4vpKgYkyGU32gCHgANmbQ2wpUryHvyE/o0+XCfo6Cirdu09FUq3nUkEODp2d4y+Bfb3T4QPAOdINGv+5ndffBsO7lgdNHI2DFdXvCapvfL+7lmi89HeLGwIoiXkjAgLCSAnjNp9hrQFsX/bB4+JHC+Wu7McA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=oY7kfGbbEytWCbfjZot/RU8TYd4HEhxmSgEpD80bDJE=; b=q/nHieKz4kRU+7etamJip9hJFtId5hpMd+MEr2Pxo0RIWOu2OHb3KMR0zTyTAGpc58RbMxHwOYeioke/ul3fMFYGVWqNgKjFxx9hoZFLaiBrR3dFtoFNY/951kVQrmAnl/dhwIPCkYejJo6CqqX/yJw7Fz/pwmiW1uxk8GaE8SzdeWQwWmAnvsf7BRS5UYseO4O4QY9cj7dDgrdUqDVyK3NXSqwHwou0LkverpFgtf7fOjK2/yIY6TRU3BeQQPZV+VOgSr/PwZILxtGuwk0p4UzGLB/zuOKvYsBnOS+TDjY9QYdHsn4P8hNBf1t2mnzsvX3qPDFfHKaH0YbOHF1G/w== Received: from SG2PR06MB3397.apcprd06.prod.outlook.com (2603:1096:4:7a::17) by KL1PR0601MB4100.apcprd06.prod.outlook.com (2603:1096:820:24::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6609.24; Thu, 20 Jul 2023 20:38:30 +0000 Received: from SG2PR06MB3397.apcprd06.prod.outlook.com ([fe80::450:9c8c:9058:c94c]) by SG2PR06MB3397.apcprd06.prod.outlook.com ([fe80::450:9c8c:9058:c94c%5]) with mapi id 15.20.6609.024; Thu, 20 Jul 2023 20:38:29 +0000 From: nifan@outlook.com To: qemu-devel@nongnu.org Cc: jonathan.cameron@huawei.com, linux-cxl@vger.kernel.org, gregory.price@memverge.com, hchkuo@avery-design.com.tw, cbrowy@avery-design.com, ira.weiny@intel.com, dan.j.williams@intel.com, a.manzanares@samsung.com, dave@stgolabs.net, nmtadam.samsung@gmail.com, Fan Ni , Fan Ni Subject: [PATCH 2/9] hw/cxl/cxl-mailbox-utils: Add dynamic capacity region representative and mailbox command support Date: Thu, 20 Jul 2023 13:37:01 -0700 Message-ID: X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230720203708.25825-1-nifan@outlook.com> References: <20230720203708.25825-1-nifan@outlook.com> X-TMN: [JfKFZllsWyqFtH/yVDeEVw7AUOekIUP4] X-ClientProxiedBy: BYAPR03CA0008.namprd03.prod.outlook.com (2603:10b6:a02:a8::21) To SG2PR06MB3397.apcprd06.prod.outlook.com (2603:1096:4:7a::17) X-Microsoft-Original-Message-ID: <20230720203708.25825-3-nifan@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SG2PR06MB3397:EE_|KL1PR0601MB4100:EE_ X-MS-Office365-Filtering-Correlation-Id: d030f563-b0de-4e6f-d442-08db89612662 X-MS-Exchange-SLBlob-MailProps: quCBMN2EvO/qzAKd82WE1LuLgf/v/GCykgkpUJblvxC/cpJDnoTwdLPg9tGpQxIL/PhVJiySk5Ul+C9C1KRY4Ki5UzGUitZihcFKHqMGg81i74Ek+/MRVMjrXDjZDXoEbAcpCloIg9tsE/nhyCs1gPOtDt8I9t1IuAPGeOAj4J+Olwa7M4YqutsQROLltpZ0FUhcOPhzSSS30cTIKGLgOEigqbNxPpBM8YPoeISK3dD3OEtN3HuTQGiRVyxtQhdVO4BXxkZAsDXxPnDVR5fgVlmijUhIswXWaxQBHMmnFKLea7DSL6fe98Vvx/eBXB7Wt2ESE2JzZQXH2fnGbhBQNNaSUoTS2M5/IWRF9Hv3wKv94zj5/2Ff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UT/e9x2YwpV3t8PAk7Irg7/glO5wEtBFpxVDeeUcqWzrbsctq/re+AcHyVV4qyscK37AuzJvEIoTuGS4DKWN925h6s9jPrXBjaDNTC55UVqVOYHkvNiTHV8+4R2B0DAmGaifIwi6uDoVXeUKAn3DgfG1e/4Cual6g4d7iiWAfWJcuAsHcA== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: d030f563-b0de-4e6f-d442-08db89612662 X-MS-Exchange-CrossTenant-AuthSource: SG2PR06MB3397.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Jul 2023 20:37:35.4065 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: KL1PR0601MB4100 Precedence: bulk List-ID: X-Mailing-List: linux-cxl@vger.kernel.org From: Fan Ni Per cxl spec 3.0, add dynamic capacity region representative based on Table 8-126 and extend the cxl type3 device definition to include dc region information. Also, based on info in 8.2.9.8.9.1, add 'Get Dynamic Capacity Configuration' mailbox support. Signed-off-by: Fan Ni --- hw/cxl/cxl-mailbox-utils.c | 69 +++++++++++++++++++++++++++++++++++++ include/hw/cxl/cxl_device.h | 16 +++++++++ 2 files changed, 85 insertions(+) diff --git a/hw/cxl/cxl-mailbox-utils.c b/hw/cxl/cxl-mailbox-utils.c index b013e30314..41e43ec231 100644 --- a/hw/cxl/cxl-mailbox-utils.c +++ b/hw/cxl/cxl-mailbox-utils.c @@ -81,6 +81,8 @@ enum { #define GET_POISON_LIST 0x0 #define INJECT_POISON 0x1 #define CLEAR_POISON 0x2 + DCD_CONFIG = 0x48, /*r3.0: 8.2.9.8.9*/ + #define GET_DC_CONFIG 0x0 PHYSICAL_SWITCH = 0x51 #define IDENTIFY_SWITCH_DEVICE 0x0 }; @@ -939,6 +941,71 @@ static CXLRetCode cmd_media_clear_poison(struct cxl_cmd *cmd, return CXL_MBOX_SUCCESS; } +/* + * cxl spec 3.0: 8.2.9.8.9.1 + * Get Dynamic Capacity Configuration + **/ +static CXLRetCode cmd_dcd_get_dyn_cap_config(struct cxl_cmd *cmd, + CXLDeviceState *cxl_dstate, + uint16_t *len) +{ + struct get_dyn_cap_config_in_pl { + uint8_t region_cnt; + uint8_t start_region_id; + } QEMU_PACKED; + + struct get_dyn_cap_config_out_pl { + uint8_t num_regions; + uint8_t rsvd1[7]; + struct { + uint64_t base; + uint64_t decode_len; + uint64_t region_len; + uint64_t block_size; + uint32_t dsmadhandle; + uint8_t flags; + uint8_t rsvd2[3]; + } QEMU_PACKED records[]; + } QEMU_PACKED; + + struct get_dyn_cap_config_in_pl *in = (void *)cmd->payload; + struct get_dyn_cap_config_out_pl *out = (void *)cmd->payload; + struct CXLType3Dev *ct3d = container_of(cxl_dstate, CXLType3Dev, + cxl_dstate); + uint16_t record_count = 0, i; + uint16_t out_pl_len; + uint8_t start_region_id = in->start_region_id; + + if (start_region_id >= ct3d->dc.num_regions) { + return CXL_MBOX_INVALID_INPUT; + } + + record_count = MIN(ct3d->dc.num_regions - in->start_region_id, + in->region_cnt); + + out_pl_len = sizeof(*out) + record_count * sizeof(out->records[0]); + assert(out_pl_len <= CXL_MAILBOX_MAX_PAYLOAD_SIZE); + + memset(out, 0, out_pl_len); + out->num_regions = record_count; + for (i = 0; i < record_count; i++) { + stq_le_p(&out->records[i].base, + ct3d->dc.regions[start_region_id + i].base); + stq_le_p(&out->records[i].decode_len, + ct3d->dc.regions[start_region_id + i].decode_len); + stq_le_p(&out->records[i].region_len, + ct3d->dc.regions[start_region_id + i].len); + stq_le_p(&out->records[i].block_size, + ct3d->dc.regions[start_region_id + i].block_size); + stl_le_p(&out->records[i].dsmadhandle, + ct3d->dc.regions[start_region_id + i].dsmadhandle); + out->records[i].flags = ct3d->dc.regions[start_region_id + i].flags; + } + + *len = out_pl_len; + return CXL_MBOX_SUCCESS; +} + #define IMMEDIATE_CONFIG_CHANGE (1 << 1) #define IMMEDIATE_DATA_CHANGE (1 << 2) #define IMMEDIATE_POLICY_CHANGE (1 << 3) @@ -977,6 +1044,8 @@ static struct cxl_cmd cxl_cmd_set[256][256] = { cmd_media_inject_poison, 8, 0 }, [MEDIA_AND_POISON][CLEAR_POISON] = { "MEDIA_AND_POISON_CLEAR_POISON", cmd_media_clear_poison, 72, 0 }, + [DCD_CONFIG][GET_DC_CONFIG] = { "DCD_GET_DC_CONFIG", + cmd_dcd_get_dyn_cap_config, 2, 0 }, }; static struct cxl_cmd cxl_cmd_set_sw[256][256] = { diff --git a/include/hw/cxl/cxl_device.h b/include/hw/cxl/cxl_device.h index cd7f28dba8..bf564f4a0b 100644 --- a/include/hw/cxl/cxl_device.h +++ b/include/hw/cxl/cxl_device.h @@ -382,6 +382,17 @@ typedef struct CXLPoison { typedef QLIST_HEAD(, CXLPoison) CXLPoisonList; #define CXL_POISON_LIST_LIMIT 256 +#define DCD_MAX_REGION_NUM 8 + +typedef struct CXLDCD_Region { + uint64_t base; + uint64_t decode_len; /* in multiples of 256MB */ + uint64_t len; + uint64_t block_size; + uint32_t dsmadhandle; + uint8_t flags; +} CXLDCD_Region; + struct CXLType3Dev { /* Private */ PCIDevice parent_obj; @@ -413,6 +424,11 @@ struct CXLType3Dev { unsigned int poison_list_cnt; bool poison_list_overflowed; uint64_t poison_list_overflow_ts; + + struct dynamic_capacity { + uint8_t num_regions; /* 0-8 regions */ + struct CXLDCD_Region regions[DCD_MAX_REGION_NUM]; + } dc; }; #define TYPE_CXL_TYPE3 "cxl-type3" From patchwork Thu Jul 20 20:37:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "nifan@outlook.com" X-Patchwork-Id: 13321040 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 47971EB64DD for ; Thu, 20 Jul 2023 20:38:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229681AbjGTUij (ORCPT ); Thu, 20 Jul 2023 16:38:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35718 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229642AbjGTUij (ORCPT ); Thu, 20 Jul 2023 16:38:39 -0400 Received: from APC01-TYZ-obe.outbound.protection.outlook.com (mail-tyzapc01olkn2058.outbound.protection.outlook.com [40.92.107.58]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E968D1731 for ; Thu, 20 Jul 2023 13:38:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fhqe5WwifhNAEfA/zRqXb6DYXC3sH/iRcIP2L4nznXvhMYtKY8D1Ohc5gousEd/YnNFd0ran+e3EAFAsu1l+POSUHcwqf0SIyZ8BZq47MlS0D2xt+cS4jIp1k8L8LlfYnkriKcsT13pD//MPlnq8JL7pg1KI+2kTSdpiciwuMPjhwhUPlmPjloHn5hYzHAb8CrJYVq7lKC+meDbjuDOX2bCg02MA+PHn/7hrsphZxjvL5wf31/3569hyXRTOpB5Vt3sTO1HtA5gyn5lBo0KPC2DKKQuUd77FRZ9y0WtmrYFRdIfawwmrfvczh9JdLc+sTUfRpYGXpuHHXGCZ9urvtw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=p1Ls8RaUR8iOs9aFBBtVavJgh3k6/iM7CXqLOqQfHho=; b=TJgn+6/dUP5S6kxP2pv14gKc/j7nlUPr/NqRUhzlQ8XclkMsvraQc08Bh9KFg8FcoS1asEj+xwMh8koL2LKnjFLM/SYevyorKeedE4GaLKCfrZNf15kS6R+9k+hE9ix/vhOm62d5bK7lubxNwMuuAEpSGlC5E30UdtELhPfZg3ws8lkldDBxzXbItOX4C3uwUqOS8GqFciXeG2FG3foD7ZKzBmqV0febs37sxL3w+YvjR8BXT0Ipkrx+AZLni+v1C/kQIN+Cjn+mHz+3rtV953dj8PIh7k4wVFD5Eyfm5vagY4RFK+/dV1JS6zv/fDM91EW2KNMp1II5PA37SiKGRw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=p1Ls8RaUR8iOs9aFBBtVavJgh3k6/iM7CXqLOqQfHho=; b=NHAGkTE7f0ie4jflXGZmEsyrJZYjjKEf59pAybk3zeV5eIDZfD4ROfZxPlQhvqUHxZZFWkoywcdRasiT0JAmdYXHy2D1mI6DkK8fDmr6Vf8nfxVzxPwL8Tk2fxCIxg8v9m7oTz9Z+2T/8zOeTgfbg8RPOTGC6tlJCxP/lB5d/yj097xJ6bFbD4I3LWGU7oAN/XrhuMAISyZzFuvIfq86fhc1W6huQNB37F3YnnlVBU9VZ3+w2+QBYchRCyDqPQNzgbrAHdjI7y0jWJVWC68QzY7MUJvvIOSKwkrVFM0DG2RB9iGFyfjbVN7PJQ7KPVG9moVEmuMhhOhWXOPnFB3wdQ== Received: from SG2PR06MB3397.apcprd06.prod.outlook.com (2603:1096:4:7a::17) by KL1PR0601MB4100.apcprd06.prod.outlook.com (2603:1096:820:24::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6609.24; Thu, 20 Jul 2023 20:38:30 +0000 Received: from SG2PR06MB3397.apcprd06.prod.outlook.com ([fe80::450:9c8c:9058:c94c]) by SG2PR06MB3397.apcprd06.prod.outlook.com ([fe80::450:9c8c:9058:c94c%5]) with mapi id 15.20.6609.024; Thu, 20 Jul 2023 20:38:30 +0000 From: nifan@outlook.com To: qemu-devel@nongnu.org Cc: jonathan.cameron@huawei.com, linux-cxl@vger.kernel.org, gregory.price@memverge.com, hchkuo@avery-design.com.tw, cbrowy@avery-design.com, ira.weiny@intel.com, dan.j.williams@intel.com, a.manzanares@samsung.com, dave@stgolabs.net, nmtadam.samsung@gmail.com, Fan Ni , Fan Ni Subject: [PATCH 3/9] include/hw/cxl/cxl_device: Rename mem_size as static_mem_size for type3 memory devices Date: Thu, 20 Jul 2023 13:37:02 -0700 Message-ID: X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230720203708.25825-1-nifan@outlook.com> References: <20230720203708.25825-1-nifan@outlook.com> X-TMN: [vAKZQcoDvyBdDGL92Wqx4vXCLo+YG/1/] X-ClientProxiedBy: BYAPR03CA0008.namprd03.prod.outlook.com (2603:10b6:a02:a8::21) To SG2PR06MB3397.apcprd06.prod.outlook.com (2603:1096:4:7a::17) X-Microsoft-Original-Message-ID: <20230720203708.25825-4-nifan@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SG2PR06MB3397:EE_|KL1PR0601MB4100:EE_ X-MS-Office365-Filtering-Correlation-Id: 4320e7b0-b47e-46ff-26b6-08db89612887 X-MS-Exchange-SLBlob-MailProps: quCBMN2EvO/qzAKd82WE1LuLgf/v/GCyfCN3eiEvalunYMK4N9yliiWxkhPIwJNy+TfDmzQCvhqgkpCJ3BGxzkL0IIqUs3zNwVyqQ7FfV9ueVkLGLitN/HsXVLCPZxXm2lOJNp/b/s25KdgeS06pYufuxafwPYddkMFrrEp/Ds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TzMRYVbJIexTqHizPWYWjRaF6jYshl+03tCYeLJqJDVTKK4PD0rBL4h6QefJ/pM+xUSUzes2rRO0LPIGT+QfWmwghqmAXI0jtFH3AIYuX69YAfjOKGF4wwhUgEAYJAfnlNh1ABTTMtDTHd6/127GbGYZnZhPZm7uZJvpSwxCBphm/NZObKNGxf89y3QHRjp1/8wrB0y+T3JiyekmCeYpoStSs2u0/fsUhng9oxH13d3CycqM93eFpg6lF5XZ8JMOp1gpyzVm7tT3PJM2CS0haaPNYOWq4RYPAmQYHT8XDlOSaQRzvlpBU76qrOf9H/nNTqHe8MaRkPunWulJUTtRIpGdYeLm+LDBmrHRYl9rX+AVtaP9/jQVPJXpZSZ5ElhQWSWsMGZE4pdeUrzw== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4320e7b0-b47e-46ff-26b6-08db89612887 X-MS-Exchange-CrossTenant-AuthSource: SG2PR06MB3397.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Jul 2023 20:37:39.0356 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: KL1PR0601MB4100 Precedence: bulk List-ID: X-Mailing-List: linux-cxl@vger.kernel.org From: Fan Ni Rename mem_size as static_mem_size for type3 memdev to cover static RAM and pmem capacity, preparing for the introduction of dynamic capacity to support dynamic capacity devices. Signed-off-by: Fan Ni --- hw/cxl/cxl-mailbox-utils.c | 5 +++-- hw/mem/cxl_type3.c | 8 ++++---- include/hw/cxl/cxl_device.h | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/hw/cxl/cxl-mailbox-utils.c b/hw/cxl/cxl-mailbox-utils.c index 41e43ec231..59d57ae245 100644 --- a/hw/cxl/cxl-mailbox-utils.c +++ b/hw/cxl/cxl-mailbox-utils.c @@ -540,7 +540,8 @@ static CXLRetCode cmd_identify_memory_device(struct cxl_cmd *cmd, snprintf(id->fw_revision, 0x10, "BWFW VERSION %02d", 0); - stq_le_p(&id->total_capacity, cxl_dstate->mem_size / CXL_CAPACITY_MULTIPLIER); + stq_le_p(&id->total_capacity, + cxl_dstate->static_mem_size / CXL_CAPACITY_MULTIPLIER); stq_le_p(&id->persistent_capacity, cxl_dstate->pmem_size / CXL_CAPACITY_MULTIPLIER); stq_le_p(&id->volatile_capacity, cxl_dstate->vmem_size / CXL_CAPACITY_MULTIPLIER); stl_le_p(&id->lsa_size, cvc->get_lsa_size(ct3d)); @@ -879,7 +880,7 @@ static CXLRetCode cmd_media_clear_poison(struct cxl_cmd *cmd, struct clear_poison_pl *in = (void *)cmd->payload; dpa = ldq_le_p(&in->dpa); - if (dpa + CXL_CACHE_LINE_SIZE > cxl_dstate->mem_size) { + if (dpa + CXL_CACHE_LINE_SIZE > cxl_dstate->static_mem_size) { return CXL_MBOX_INVALID_PA; } diff --git a/hw/mem/cxl_type3.c b/hw/mem/cxl_type3.c index 862107c5ef..237b544b9c 100644 --- a/hw/mem/cxl_type3.c +++ b/hw/mem/cxl_type3.c @@ -748,7 +748,7 @@ static bool cxl_setup_memory(CXLType3Dev *ct3d, Error **errp) } address_space_init(&ct3d->hostvmem_as, vmr, v_name); ct3d->cxl_dstate.vmem_size = memory_region_size(vmr); - ct3d->cxl_dstate.mem_size += memory_region_size(vmr); + ct3d->cxl_dstate.static_mem_size += memory_region_size(vmr); g_free(v_name); } @@ -771,7 +771,7 @@ static bool cxl_setup_memory(CXLType3Dev *ct3d, Error **errp) } address_space_init(&ct3d->hostpmem_as, pmr, p_name); ct3d->cxl_dstate.pmem_size = memory_region_size(pmr); - ct3d->cxl_dstate.mem_size += memory_region_size(pmr); + ct3d->cxl_dstate.static_mem_size += memory_region_size(pmr); g_free(p_name); } @@ -984,7 +984,7 @@ static int cxl_type3_hpa_to_as_and_dpa(CXLType3Dev *ct3d, return -EINVAL; } - if (*dpa_offset > ct3d->cxl_dstate.mem_size) { + if (*dpa_offset > ct3d->cxl_dstate.static_mem_size) { return -EINVAL; } @@ -1142,7 +1142,7 @@ static bool set_cacheline(CXLType3Dev *ct3d, uint64_t dpa_offset, uint8_t *data) return false; } - if (dpa_offset + CXL_CACHE_LINE_SIZE > ct3d->cxl_dstate.mem_size) { + if (dpa_offset + CXL_CACHE_LINE_SIZE > ct3d->cxl_dstate.static_mem_size) { return false; } diff --git a/include/hw/cxl/cxl_device.h b/include/hw/cxl/cxl_device.h index bf564f4a0b..a32ee6d6ba 100644 --- a/include/hw/cxl/cxl_device.h +++ b/include/hw/cxl/cxl_device.h @@ -209,7 +209,7 @@ typedef struct cxl_device_state { } timestamp; /* memory region size, HDM */ - uint64_t mem_size; + uint64_t static_mem_size; uint64_t pmem_size; uint64_t vmem_size; From patchwork Thu Jul 20 20:37:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "nifan@outlook.com" X-Patchwork-Id: 13321041 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 61711C0015E for ; Thu, 20 Jul 2023 20:38:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229642AbjGTUil (ORCPT ); Thu, 20 Jul 2023 16:38:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35728 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229576AbjGTUik (ORCPT ); Thu, 20 Jul 2023 16:38:40 -0400 Received: from APC01-TYZ-obe.outbound.protection.outlook.com (mail-tyzapc01olkn2058.outbound.protection.outlook.com [40.92.107.58]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4056D12F for ; Thu, 20 Jul 2023 13:38:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fZADlUvaGAQobXDMx268vc/R1Gzgbt4areglWItLF5Z1oVAKgEyfR0W0FMR0gL3t+10JeBaLY/WBuilU9VmfKjYL25rNklcrle3CTUVXZ6voR/TLn/MyE2F0I8uZdT+gr3H96WaO266VYwqr34VYJPyubot/uRCfP/TyTLQBLjcUZkzH5leSYuV8I3csEQ27Tyr90wgB+eIYijPBL2LdtyHCpTKLc+w90xgXqCqD3f3EpZMFvb9Hhs0NpX4qIIEyfScXl6dvRc78NDgcAQap6jh40EvOyJFFt0oG1VhOTs2ylOg7flReT+sNSFTr798Z0zGczrLeRQfz1p+uXO1BYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=3wmXxe1gyKy7AQ4oFe0GksrcExFDiVNkf0Ah1Nc6Hp8=; b=LUWlmF41GkI4w8EZ7zxxDGusk/Gj8zsO/J8u3xJWzNklTfmUDrSOqZZAwef2vtRJA6CN40U/pDP2v3xD+3vMcx/dFPA7bD6EnOudyMAk06VNTyPi8nHN5UhvXCusX9YzPkqhE+jN3ZgFzaqbFyV/jphPivq5GVfyEO4jPf2bgg0Qmdnj8bytAUSkJCVzpGRjD6EUSB7ySTfnj9RDM7CdNQED7L2qeueiBdPFdL2M0X6gjJgrCvKToqHHCQ/lfHff+ggYYOCKNrlEChaLtWYnBJpDSz0HpW6wtoUPnXgOJxtmRyBJQ2EWJTqwWGbW4VzTAEimmoe9YQiAV5t0n91qoQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=3wmXxe1gyKy7AQ4oFe0GksrcExFDiVNkf0Ah1Nc6Hp8=; b=q697sDWz3IZdylaW4azGZMdg2zgJBxruwWxYIZCRNzv9vKkSGAp8Iio30cMkQRhxqP89MR2oudnF7bEE+VmRP9+V4VLac22HS5q5OjZw0bAtfeC0kXtw4VMWqkLwif5nrPjNocu1iCVQAmAKC5n/yKaWyQnJfWkgzJXa4/920qHfltsdZKK6S1/NZ7437oEyHtEpab4rfe/WCAcwFu9pK0kOOLxzgzeiwzwb5ft2TO1fWHop19gEH8IdMI+D3xsGg6DlaaUjAKZf25CWR3A19nidAfQjkQYzafk3XLMqiEK3uddWsn5gi0v27Dg4lvWVMbAG+nBXhc1Y9bBTtWlk4w== Received: from SG2PR06MB3397.apcprd06.prod.outlook.com (2603:1096:4:7a::17) by KL1PR0601MB4100.apcprd06.prod.outlook.com (2603:1096:820:24::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6609.24; Thu, 20 Jul 2023 20:38:31 +0000 Received: from SG2PR06MB3397.apcprd06.prod.outlook.com ([fe80::450:9c8c:9058:c94c]) by SG2PR06MB3397.apcprd06.prod.outlook.com ([fe80::450:9c8c:9058:c94c%5]) with mapi id 15.20.6609.024; Thu, 20 Jul 2023 20:38:31 +0000 From: nifan@outlook.com To: qemu-devel@nongnu.org Cc: jonathan.cameron@huawei.com, linux-cxl@vger.kernel.org, gregory.price@memverge.com, hchkuo@avery-design.com.tw, cbrowy@avery-design.com, ira.weiny@intel.com, dan.j.williams@intel.com, a.manzanares@samsung.com, dave@stgolabs.net, nmtadam.samsung@gmail.com, Fan Ni , Fan Ni Subject: [PATCH 4/9] hw/mem/cxl_type3: Add support to create DC regions to type3 memory devices Date: Thu, 20 Jul 2023 13:37:03 -0700 Message-ID: X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230720203708.25825-1-nifan@outlook.com> References: <20230720203708.25825-1-nifan@outlook.com> X-TMN: [5N0zCWzcSMM0hWh2ySV3mmZ1xAp0XQzV] X-ClientProxiedBy: BYAPR03CA0008.namprd03.prod.outlook.com (2603:10b6:a02:a8::21) To SG2PR06MB3397.apcprd06.prod.outlook.com (2603:1096:4:7a::17) X-Microsoft-Original-Message-ID: <20230720203708.25825-5-nifan@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SG2PR06MB3397:EE_|KL1PR0601MB4100:EE_ X-MS-Office365-Filtering-Correlation-Id: 5f346219-a653-4afe-10d7-08db89612b06 X-MS-Exchange-SLBlob-MailProps: 9IecXKUgicAYce+YIvRqgnoEwnxu+bmnqdflpIQ3k/CEHtXQ09WBJacqPfWQMr2f9LcZyJFw1Jt94o/U+oh1vWaxKqpmSgUyccXMCYnP4JP+30LlbrMVjUXcWM+qbnOcl5cPI1KHvO2YuVG7gIzC62mcnjl1T9/JL0ZAqTTtuOC5tVGnxLypYJtYxZ68sDep3W/wxESKIETstpaY7/zsjB+TRPJJ0G+33Q9lhRnsjbITiEgRZSzqLfcEUjey46bOkNKjfcVssTb1PjUbywvq44mt2obxEaGPjEhSeJHjBAaP2CSuZg1j/BKhuo2qv9aQNtxhx7nQ0cBNY9yOFTUuMOwv9dkPDQcrglRGO+2zj4RKXTvXFL3uylcaY9R6M7Da18OrTl2mfgQ/pniiJE1vFuZsR4GMKglDI6DhJhshhtsInZ9i2cyxnvL5EdLDrZNcbodCRVaQzNriBdkH4wr801Ekf1iIsCQMUOQKkemM6gH5yXwlWuTvzd1USdjNYlrneeMbZCQw6E7EVNRI6VN8yKsM1KqpuRL3I7g0Ju41HCpeEwJwTtiuN90UICo90xt4j2eJw9HVOAWjDByr+XfpI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TZA== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5f346219-a653-4afe-10d7-08db89612b06 X-MS-Exchange-CrossTenant-AuthSource: SG2PR06MB3397.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Jul 2023 20:37:43.2976 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: KL1PR0601MB4100 Precedence: bulk List-ID: X-Mailing-List: linux-cxl@vger.kernel.org From: Fan Ni With the change, when setting up memory for type3 memory device, we can create DC regions A property 'num-dc-regions' is added to ct3_props to allow users to pass the number of DC regions to create. To make it easier, other region parameters like region base, length, and block size are hard coded. If needed, these parameters can be added easily. With the change, we can create DC regions with proper kernel side support as below: region=$(cat /sys/bus/cxl/devices/decoder0.0/create_dc_region) echo $region> /sys/bus/cxl/devices/decoder0.0/create_dc_region echo 256 > /sys/bus/cxl/devices/$region/interleave_granularity echo 1 > /sys/bus/cxl/devices/$region/interleave_ways echo "dc0" >/sys/bus/cxl/devices/decoder2.0/mode echo 0x40000000 >/sys/bus/cxl/devices/decoder2.0/dpa_size echo 0x40000000 > /sys/bus/cxl/devices/$region/size echo "decoder2.0" > /sys/bus/cxl/devices/$region/target0 echo 1 > /sys/bus/cxl/devices/$region/commit echo $region > /sys/bus/cxl/drivers/cxl_region/bind Signed-off-by: Fan Ni --- hw/mem/cxl_type3.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/hw/mem/cxl_type3.c b/hw/mem/cxl_type3.c index 237b544b9c..27b5920f7d 100644 --- a/hw/mem/cxl_type3.c +++ b/hw/mem/cxl_type3.c @@ -707,6 +707,34 @@ static void ct3d_reg_write(void *opaque, hwaddr offset, uint64_t value, } } +/* + * Create a dc region to test "Get Dynamic Capacity Configuration" command. + */ +static int cxl_create_dc_regions(CXLType3Dev *ct3d) +{ + int i; + uint64_t region_base = (ct3d->hostvmem ? ct3d->hostvmem->size : 0) + + (ct3d->hostpmem ? ct3d->hostpmem->size : 0); + uint64_t region_len = (uint64_t)2 * 1024 * 1024 * 1024; + uint64_t decode_len = 4; /* 4*256MB */ + uint64_t blk_size = 2 * 1024 * 1024; + struct CXLDCD_Region *region; + + for (i = 0; i < ct3d->dc.num_regions; i++) { + region = &ct3d->dc.regions[i]; + region->base = region_base; + region->decode_len = decode_len; + region->len = region_len; + region->block_size = blk_size; + /* dsmad_handle is set when creating cdat table entries */ + region->flags = 0; + + region_base += region->len; + } + + return 0; +} + static bool cxl_setup_memory(CXLType3Dev *ct3d, Error **errp) { DeviceState *ds = DEVICE(ct3d); @@ -775,6 +803,10 @@ static bool cxl_setup_memory(CXLType3Dev *ct3d, Error **errp) g_free(p_name); } + if (cxl_create_dc_regions(ct3d)) { + return false; + } + return true; } @@ -1062,6 +1094,7 @@ static Property ct3_props[] = { DEFINE_PROP_UINT64("sn", CXLType3Dev, sn, UI64_NULL), DEFINE_PROP_STRING("cdat", CXLType3Dev, cxl_cstate.cdat.filename), DEFINE_PROP_UINT16("spdm", CXLType3Dev, spdm_port, 0), + DEFINE_PROP_UINT8("num-dc-regions", CXLType3Dev, dc.num_regions, 0), DEFINE_PROP_END_OF_LIST(), }; From patchwork Thu Jul 20 20:37:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "nifan@outlook.com" X-Patchwork-Id: 13321043 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 9B2E0EB64DD for ; Thu, 20 Jul 2023 20:38:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229737AbjGTUin (ORCPT ); Thu, 20 Jul 2023 16:38:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35748 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229744AbjGTUim (ORCPT ); Thu, 20 Jul 2023 16:38:42 -0400 Received: from APC01-TYZ-obe.outbound.protection.outlook.com (mail-tyzapc01olkn2058.outbound.protection.outlook.com [40.92.107.58]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 738611731 for ; Thu, 20 Jul 2023 13:38:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GHJ2o2RkVxIdHIKSmi6s8hTMvrwSWHsHu2vugXa33PWmXIxp+fvoySayzkvd1ZtlCDOcUnO7lzrFAOywPH42Kn21rZRhP1kfSQOqbrgSpqiG1gvE6C6jmhuDOEipwgEnHb06vLlIk7TJGh7kEEQpDT6PPcSBGMrRubXzo7yqp/9TUDdcvq8tjvqe3gyJrvysRZmE6iN1F0ZMjpBasekPj+LkHTCYbYWnDmc73wPKxaG7fuvhC6xBhShhsy1LHnA0+87m9sqZlM2y9Q+DDCwAjmC2r7c/TZtgU4BW7rSTQEEjXOi1f/QYppKB4ja0FLsAPD0hQ9U57TFrzjCaQ6EdGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=E5orTEgp313dgjIIm1iwcaXWxROhyMBCbIEjzU3IuzM=; b=DziEoSh9Av2h++iVBNsCgvj0tF7B4l34Azp3ghsYKEnS28gm3U5x6GjB0S5+5iQ9oFS1GDhuD8Bq88rpzU3jJ/0EUY6myJxYRaY5PscBbWLEi2aZ9r/9hScZ5lJDZsHEKgX5FNzGECXrUA8WdKue6cZvMWwzVzpgYvFRqNOb/xyErk34pCTBYdGB70SYbiuAPHBfsa+TqclK0TgYxM5a9BXhQe8ruCaABQyETpftIcG9BgOyzw1SbDGSyxiNK2iebkJhfBg7AWuoZmnpGbzfYDhYJEvkFigmyUoSGg2+eC9hGt8u3yBkYKm5Dm8IvLNijTMDjkL9ZfEIGVx62wBevw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=E5orTEgp313dgjIIm1iwcaXWxROhyMBCbIEjzU3IuzM=; b=VeLiYgkk0cZ0Pub5pVhHlEg4DK2UKCYtnk8cCaRhPM9uuZr0hP4fhlvftm5GqolL7OAsZIMRIt7y872uyQGwiCmBHSYcjtrkepFzvqcYF1ZYZkT6QBoAoOTuNMmvdMsvWDT1W3H51sd8DKXuO8I3hNDU7pyBGwomOAtgZmzKyTgIFRNOF8kcUim+S7M6AlZJTx/bbGJsOGAFQdlJV09oQgJPXBIGJsr8fnaiU4nVnWf/1Ge9/CeCX4zwPkMMb6ps63MaHyA/2d/0LJdX8O1mxvEKcXzlrOdj8iqqHv4dWSRUQXYMGd6tbR9GSGUx5v7h1EaJVAoLKxIZHAgj7RNH1w== Received: from SG2PR06MB3397.apcprd06.prod.outlook.com (2603:1096:4:7a::17) by KL1PR0601MB4100.apcprd06.prod.outlook.com (2603:1096:820:24::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6609.24; Thu, 20 Jul 2023 20:38:31 +0000 Received: from SG2PR06MB3397.apcprd06.prod.outlook.com ([fe80::450:9c8c:9058:c94c]) by SG2PR06MB3397.apcprd06.prod.outlook.com ([fe80::450:9c8c:9058:c94c%5]) with mapi id 15.20.6609.024; Thu, 20 Jul 2023 20:38:31 +0000 From: nifan@outlook.com To: qemu-devel@nongnu.org Cc: jonathan.cameron@huawei.com, linux-cxl@vger.kernel.org, gregory.price@memverge.com, hchkuo@avery-design.com.tw, cbrowy@avery-design.com, ira.weiny@intel.com, dan.j.williams@intel.com, a.manzanares@samsung.com, dave@stgolabs.net, nmtadam.samsung@gmail.com, Fan Ni , Fan Ni Subject: [PATCH 5/9] hw/mem/cxl_type3: Add host backend and address space handling for DC regions Date: Thu, 20 Jul 2023 13:37:04 -0700 Message-ID: X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230720203708.25825-1-nifan@outlook.com> References: <20230720203708.25825-1-nifan@outlook.com> X-TMN: [C1sYar+TzjFE9yql5CsFQUwMDkFYDzDL] X-ClientProxiedBy: BYAPR03CA0008.namprd03.prod.outlook.com (2603:10b6:a02:a8::21) To SG2PR06MB3397.apcprd06.prod.outlook.com (2603:1096:4:7a::17) X-Microsoft-Original-Message-ID: <20230720203708.25825-6-nifan@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SG2PR06MB3397:EE_|KL1PR0601MB4100:EE_ X-MS-Office365-Filtering-Correlation-Id: 5cfba9b9-558a-4948-b121-08db89612d38 X-MS-Exchange-SLBlob-MailProps: 9IecXKUgicAYce+YIvRqgnoEwnxu+bmn4WK0pvigUmRttW27tsG+DQnjrdGjJmgyRqkXVwSm/1WIMw8/qJSodpRrL27KyBUBmgzQfkhDpoE18z7dgg8TwDqKIQisVxRH7O2tBm0KOKZtLCqW7vNdBP3sEGgOnwBizw99GUlwv3WvKMfor1YuRZSd1VCItPmo5FSbxoUcaaxgmmHJMqm2dDx21ttjLIHXZWseSOrld2v2gfYAiLSE0bZsvvjMw7AWTv+y87/Qir8+CV8by1kVP3t8r5Ar7uoNyYi7z5b2oNIWZVL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e1jIao6d2tg86rHwU5ytOYyEkEvUFL8N5MFfvtNtL+K/7Q6yLChTeNj5ccT+ScMNQe/ghotCpRlB0G0KpCRidw/mtjroBXa4zaCKxLY2unTdPetabbogmCtrQ3hq2CCnS6SmYEaDGweoqu3ozxaTSiHOib91QtCVZHLIITEMoQV8XyNWUUpY3ibshOicC/fS5wqVQmwSClYdypPSqe9//0kWrspSgk/4ldbChuPm+CKzW4W7OSJ2YiI7tQNLLG3XkFzaHxqakqmNH6ZhHzLHllxRUct91Q== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5cfba9b9-558a-4948-b121-08db89612d38 X-MS-Exchange-CrossTenant-AuthSource: SG2PR06MB3397.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Jul 2023 20:37:46.9303 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: KL1PR0601MB4100 Precedence: bulk List-ID: X-Mailing-List: linux-cxl@vger.kernel.org From: Fan Ni Add (file/memory backed) host backend, all the dynamic capacity regions will share a single, large enough host backend. Set up address space for DC regions to support read/write operations to dynamic capacity for DCD. With the change, following supports are added: 1. add a new property to type3 device "nonvolatile-dc-memdev" to point to host memory backend for dynamic capacity; 2. add namespace for dynamic capacity for read/write support; 3. create cdat entries for each dynamic capacity region; 4. fix dvsec range registers to include DC regions. Signed-off-by: Fan Ni --- hw/cxl/cxl-mailbox-utils.c | 19 +++- hw/mem/cxl_type3.c | 203 +++++++++++++++++++++++++++++------- include/hw/cxl/cxl_device.h | 4 + 3 files changed, 185 insertions(+), 41 deletions(-) diff --git a/hw/cxl/cxl-mailbox-utils.c b/hw/cxl/cxl-mailbox-utils.c index 59d57ae245..c497298a1d 100644 --- a/hw/cxl/cxl-mailbox-utils.c +++ b/hw/cxl/cxl-mailbox-utils.c @@ -388,9 +388,11 @@ static CXLRetCode cmd_firmware_update_get_info(struct cxl_cmd *cmd, char fw_rev4[0x10]; } QEMU_PACKED *fw_info; QEMU_BUILD_BUG_ON(sizeof(*fw_info) != 0x50); + CXLType3Dev *ct3d = container_of(cxl_dstate, CXLType3Dev, cxl_dstate); if ((cxl_dstate->vmem_size < CXL_CAPACITY_MULTIPLIER) || - (cxl_dstate->pmem_size < CXL_CAPACITY_MULTIPLIER)) { + (cxl_dstate->pmem_size < CXL_CAPACITY_MULTIPLIER) || + (ct3d->dc.total_capacity < CXL_CAPACITY_MULTIPLIER)) { return CXL_MBOX_INTERNAL_ERROR; } @@ -531,7 +533,8 @@ static CXLRetCode cmd_identify_memory_device(struct cxl_cmd *cmd, CXLType3Class *cvc = CXL_TYPE3_GET_CLASS(ct3d); if ((!QEMU_IS_ALIGNED(cxl_dstate->vmem_size, CXL_CAPACITY_MULTIPLIER)) || - (!QEMU_IS_ALIGNED(cxl_dstate->pmem_size, CXL_CAPACITY_MULTIPLIER))) { + (!QEMU_IS_ALIGNED(cxl_dstate->pmem_size, CXL_CAPACITY_MULTIPLIER)) || + (!QEMU_IS_ALIGNED(ct3d->dc.total_capacity, CXL_CAPACITY_MULTIPLIER))) { return CXL_MBOX_INTERNAL_ERROR; } @@ -566,9 +569,11 @@ static CXLRetCode cmd_ccls_get_partition_info(struct cxl_cmd *cmd, uint64_t next_pmem; } QEMU_PACKED *part_info = (void *)cmd->payload; QEMU_BUILD_BUG_ON(sizeof(*part_info) != 0x20); + CXLType3Dev *ct3d = container_of(cxl_dstate, CXLType3Dev, cxl_dstate); if ((!QEMU_IS_ALIGNED(cxl_dstate->vmem_size, CXL_CAPACITY_MULTIPLIER)) || - (!QEMU_IS_ALIGNED(cxl_dstate->pmem_size, CXL_CAPACITY_MULTIPLIER))) { + (!QEMU_IS_ALIGNED(cxl_dstate->pmem_size, CXL_CAPACITY_MULTIPLIER)) || + (!QEMU_IS_ALIGNED(ct3d->dc.total_capacity, CXL_CAPACITY_MULTIPLIER))) { return CXL_MBOX_INTERNAL_ERROR; } @@ -880,7 +885,13 @@ static CXLRetCode cmd_media_clear_poison(struct cxl_cmd *cmd, struct clear_poison_pl *in = (void *)cmd->payload; dpa = ldq_le_p(&in->dpa); - if (dpa + CXL_CACHE_LINE_SIZE > cxl_dstate->static_mem_size) { + if (dpa + CXL_CACHE_LINE_SIZE >= cxl_dstate->static_mem_size + && ct3d->dc.num_regions == 0) { + return CXL_MBOX_INVALID_PA; + } + + if (ct3d->dc.num_regions && dpa + CXL_CACHE_LINE_SIZE >= + cxl_dstate->static_mem_size + ct3d->dc.total_capacity) { return CXL_MBOX_INVALID_PA; } diff --git a/hw/mem/cxl_type3.c b/hw/mem/cxl_type3.c index 27b5920f7d..af1d919be3 100644 --- a/hw/mem/cxl_type3.c +++ b/hw/mem/cxl_type3.c @@ -20,6 +20,7 @@ #include "hw/pci/spdm.h" #define DWORD_BYTE 4 +#define CXL_CAPACITY_MULTIPLIER (256 * MiB) /* Default CDAT entries for a memory region */ enum { @@ -33,8 +34,8 @@ enum { }; static int ct3_build_cdat_entries_for_mr(CDATSubHeader **cdat_table, - int dsmad_handle, MemoryRegion *mr, - bool is_pmem, uint64_t dpa_base) + int dsmad_handle, uint8_t flags, + uint64_t dpa_base, uint64_t size) { g_autofree CDATDsmas *dsmas = NULL; g_autofree CDATDslbis *dslbis0 = NULL; @@ -53,9 +54,9 @@ static int ct3_build_cdat_entries_for_mr(CDATSubHeader **cdat_table, .length = sizeof(*dsmas), }, .DSMADhandle = dsmad_handle, - .flags = is_pmem ? CDAT_DSMAS_FLAG_NV : 0, + .flags = flags, .DPA_base = dpa_base, - .DPA_length = memory_region_size(mr), + .DPA_length = size, }; /* For now, no memory side cache, plausiblish numbers */ @@ -137,9 +138,9 @@ static int ct3_build_cdat_entries_for_mr(CDATSubHeader **cdat_table, * NV: Reserved - the non volatile from DSMAS matters * V: EFI_MEMORY_SP */ - .EFI_memory_type_attr = is_pmem ? 2 : 1, + .EFI_memory_type_attr = flags ? 2 : 1, .DPA_offset = 0, - .DPA_length = memory_region_size(mr), + .DPA_length = size, }; /* Header always at start of structure */ @@ -158,21 +159,28 @@ static int ct3_build_cdat_table(CDATSubHeader ***cdat_table, void *priv) g_autofree CDATSubHeader **table = NULL; CXLType3Dev *ct3d = priv; MemoryRegion *volatile_mr = NULL, *nonvolatile_mr = NULL; + MemoryRegion *dc_mr = NULL; int dsmad_handle = 0; int cur_ent = 0; int len = 0; int rc, i; + uint64_t vmr_size = 0, pmr_size = 0; - if (!ct3d->hostpmem && !ct3d->hostvmem) { + if (!ct3d->hostpmem && !ct3d->hostvmem && !ct3d->dc.num_regions) { return 0; } + if (ct3d->hostpmem && ct3d->hostvmem && ct3d->dc.host_dc) { + warn_report("The device has static ram and pmem and dynamic capacity"); + } + if (ct3d->hostvmem) { volatile_mr = host_memory_backend_get_memory(ct3d->hostvmem); if (!volatile_mr) { return -EINVAL; } len += CT3_CDAT_NUM_ENTRIES; + vmr_size = volatile_mr->size; } if (ct3d->hostpmem) { @@ -181,6 +189,19 @@ static int ct3_build_cdat_table(CDATSubHeader ***cdat_table, void *priv) return -EINVAL; } len += CT3_CDAT_NUM_ENTRIES; + pmr_size = nonvolatile_mr->size; + } + + if (ct3d->dc.num_regions) { + if (ct3d->dc.host_dc) { + dc_mr = host_memory_backend_get_memory(ct3d->dc.host_dc); + if (!dc_mr) { + return -EINVAL; + } + len += CT3_CDAT_NUM_ENTRIES * ct3d->dc.num_regions; + } else { + return -EINVAL; + } } table = g_malloc0(len * sizeof(*table)); @@ -190,8 +211,8 @@ static int ct3_build_cdat_table(CDATSubHeader ***cdat_table, void *priv) /* Now fill them in */ if (volatile_mr) { - rc = ct3_build_cdat_entries_for_mr(table, dsmad_handle++, volatile_mr, - false, 0); + rc = ct3_build_cdat_entries_for_mr(table, dsmad_handle++, + 0, 0, vmr_size); if (rc < 0) { return rc; } @@ -200,14 +221,37 @@ static int ct3_build_cdat_table(CDATSubHeader ***cdat_table, void *priv) if (nonvolatile_mr) { rc = ct3_build_cdat_entries_for_mr(&(table[cur_ent]), dsmad_handle++, - nonvolatile_mr, true, - (volatile_mr ? - memory_region_size(volatile_mr) : 0)); + CDAT_DSMAS_FLAG_NV, vmr_size, pmr_size); if (rc < 0) { goto error_cleanup; } cur_ent += CT3_CDAT_NUM_ENTRIES; } + + if (dc_mr) { + uint64_t region_base = vmr_size + pmr_size; + + /* + * Currently we create cdat entries for each region, should we only + * create dsmas table instead?? + * We assume all dc regions are non-volatile for now. + * + */ + for (i = 0; i < ct3d->dc.num_regions; i++) { + rc = ct3_build_cdat_entries_for_mr(&(table[cur_ent]) + , dsmad_handle++ + , CDAT_DSMAS_FLAG_NV | CDAT_DSMAS_FLAG_DYNAMIC_CAP + , region_base, ct3d->dc.regions[i].len); + if (rc < 0) { + goto error_cleanup; + } + ct3d->dc.regions[i].dsmadhandle = dsmad_handle - 1; + + cur_ent += CT3_CDAT_NUM_ENTRIES; + region_base += ct3d->dc.regions[i].len; + } + } + assert(len == cur_ent); *cdat_table = g_steal_pointer(&table); @@ -435,11 +479,24 @@ static void build_dvsecs(CXLType3Dev *ct3d) range2_size_hi = ct3d->hostpmem->size >> 32; range2_size_lo = (2 << 5) | (2 << 2) | 0x3 | (ct3d->hostpmem->size & 0xF0000000); + } else if (ct3d->dc.host_dc) { + range2_size_hi = ct3d->dc.host_dc->size >> 32; + range2_size_lo = (2 << 5) | (2 << 2) | 0x3 | + (ct3d->dc.host_dc->size & 0xF0000000); } - } else { + } else if (ct3d->hostpmem) { range1_size_hi = ct3d->hostpmem->size >> 32; range1_size_lo = (2 << 5) | (2 << 2) | 0x3 | (ct3d->hostpmem->size & 0xF0000000); + if (ct3d->dc.host_dc) { + range2_size_hi = ct3d->dc.host_dc->size >> 32; + range2_size_lo = (2 << 5) | (2 << 2) | 0x3 | + (ct3d->dc.host_dc->size & 0xF0000000); + } + } else { + range1_size_hi = ct3d->dc.host_dc->size >> 32; + range1_size_lo = (2 << 5) | (2 << 2) | 0x3 | + (ct3d->dc.host_dc->size & 0xF0000000); } dvsec = (uint8_t *)&(CXLDVSECDevice){ @@ -708,7 +765,8 @@ static void ct3d_reg_write(void *opaque, hwaddr offset, uint64_t value, } /* - * Create a dc region to test "Get Dynamic Capacity Configuration" command. + * Create dc regions. + * TODO: region parameters are hard coded, may need to change in the future. */ static int cxl_create_dc_regions(CXLType3Dev *ct3d) { @@ -739,7 +797,8 @@ static bool cxl_setup_memory(CXLType3Dev *ct3d, Error **errp) { DeviceState *ds = DEVICE(ct3d); - if (!ct3d->hostmem && !ct3d->hostvmem && !ct3d->hostpmem) { + if (!ct3d->hostmem && !ct3d->hostvmem && !ct3d->hostpmem + && !ct3d->dc.num_regions) { error_setg(errp, "at least one memdev property must be set"); return false; } else if (ct3d->hostmem && ct3d->hostpmem) { @@ -807,6 +866,50 @@ static bool cxl_setup_memory(CXLType3Dev *ct3d, Error **errp) return false; } + ct3d->dc.total_capacity = 0; + if (ct3d->dc.host_dc) { + MemoryRegion *dc_mr; + char *dc_name; + uint64_t total_region_size = 0; + int i; + + dc_mr = host_memory_backend_get_memory(ct3d->dc.host_dc); + if (!dc_mr) { + error_setg(errp, "dynamic capacity must have backing device"); + return false; + } + /* FIXME: set dc as nonvolatile for now */ + memory_region_set_nonvolatile(dc_mr, true); + memory_region_set_enabled(dc_mr, true); + host_memory_backend_set_mapped(ct3d->dc.host_dc, true); + if (ds->id) { + dc_name = g_strdup_printf("cxl-dcd-dpa-dc-space:%s", ds->id); + } else { + dc_name = g_strdup("cxl-dcd-dpa-dc-space"); + } + address_space_init(&ct3d->dc.host_dc_as, dc_mr, dc_name); + + for (i = 0; i < ct3d->dc.num_regions; i++) { + total_region_size += ct3d->dc.regions[i].len; + } + /* Make sure the host backend is large enough to cover all dc range */ + if (total_region_size > memory_region_size(dc_mr)) { + error_setg(errp, + "too small host backend size, increase to %lu MiB or more", + total_region_size / 1024 / 1024); + return false; + } + + if (dc_mr->size % CXL_CAPACITY_MULTIPLIER != 0) { + error_setg(errp, "DC region size is unaligned to %lx", + CXL_CAPACITY_MULTIPLIER); + return false; + } + + ct3d->dc.total_capacity = total_region_size; + g_free(dc_name); + } + return true; } @@ -916,6 +1019,9 @@ err_release_cdat: err_free_special_ops: g_free(regs->special_ops); err_address_space_free: + if (ct3d->dc.host_dc) { + address_space_destroy(&ct3d->dc.host_dc_as); + } if (ct3d->hostpmem) { address_space_destroy(&ct3d->hostpmem_as); } @@ -935,6 +1041,9 @@ static void ct3_exit(PCIDevice *pci_dev) cxl_doe_cdat_release(cxl_cstate); spdm_sock_fini(ct3d->doe_spdm.socket); g_free(regs->special_ops); + if (ct3d->dc.host_dc) { + address_space_destroy(&ct3d->dc.host_dc_as); + } if (ct3d->hostpmem) { address_space_destroy(&ct3d->hostpmem_as); } @@ -999,16 +1108,24 @@ static int cxl_type3_hpa_to_as_and_dpa(CXLType3Dev *ct3d, AddressSpace **as, uint64_t *dpa_offset) { - MemoryRegion *vmr = NULL, *pmr = NULL; + MemoryRegion *vmr = NULL, *pmr = NULL, *dc_mr = NULL; + uint64_t vmr_size = 0, pmr_size = 0, dc_size = 0; if (ct3d->hostvmem) { vmr = host_memory_backend_get_memory(ct3d->hostvmem); + vmr_size = memory_region_size(vmr); } if (ct3d->hostpmem) { pmr = host_memory_backend_get_memory(ct3d->hostpmem); + pmr_size = memory_region_size(pmr); + } + if (ct3d->dc.host_dc) { + dc_mr = host_memory_backend_get_memory(ct3d->dc.host_dc); + /* Do we want dc_size to be dc_mr->size or not?? */ + dc_size = ct3d->dc.total_capacity; } - if (!vmr && !pmr) { + if (!vmr && !pmr && !dc_mr) { return -ENODEV; } @@ -1016,19 +1133,19 @@ static int cxl_type3_hpa_to_as_and_dpa(CXLType3Dev *ct3d, return -EINVAL; } - if (*dpa_offset > ct3d->cxl_dstate.static_mem_size) { + if ((*dpa_offset >= vmr_size + pmr_size + dc_size) || + (*dpa_offset >= vmr_size + pmr_size && ct3d->dc.num_regions == 0)) { return -EINVAL; } - if (vmr) { - if (*dpa_offset < memory_region_size(vmr)) { - *as = &ct3d->hostvmem_as; - } else { - *as = &ct3d->hostpmem_as; - *dpa_offset -= memory_region_size(vmr); - } - } else { + if (*dpa_offset < vmr_size) { + *as = &ct3d->hostvmem_as; + } else if (*dpa_offset < vmr_size + pmr_size) { *as = &ct3d->hostpmem_as; + *dpa_offset -= vmr_size; + } else { + *as = &ct3d->dc.host_dc_as; + *dpa_offset -= (vmr_size + pmr_size); } return 0; @@ -1095,6 +1212,8 @@ static Property ct3_props[] = { DEFINE_PROP_STRING("cdat", CXLType3Dev, cxl_cstate.cdat.filename), DEFINE_PROP_UINT16("spdm", CXLType3Dev, spdm_port, 0), DEFINE_PROP_UINT8("num-dc-regions", CXLType3Dev, dc.num_regions, 0), + DEFINE_PROP_LINK("nonvolatile-dc-memdev", CXLType3Dev, dc.host_dc, + TYPE_MEMORY_BACKEND, HostMemoryBackend *), DEFINE_PROP_END_OF_LIST(), }; @@ -1161,33 +1280,43 @@ static void set_lsa(CXLType3Dev *ct3d, const void *buf, uint64_t size, static bool set_cacheline(CXLType3Dev *ct3d, uint64_t dpa_offset, uint8_t *data) { - MemoryRegion *vmr = NULL, *pmr = NULL; + MemoryRegion *vmr = NULL, *pmr = NULL, *dc_mr = NULL; AddressSpace *as; + uint64_t vmr_size = 0, pmr_size = 0, dc_size = 0; if (ct3d->hostvmem) { vmr = host_memory_backend_get_memory(ct3d->hostvmem); + vmr_size = memory_region_size(vmr); } if (ct3d->hostpmem) { pmr = host_memory_backend_get_memory(ct3d->hostpmem); + pmr_size = memory_region_size(pmr); } + if (ct3d->dc.host_dc) { + dc_mr = host_memory_backend_get_memory(ct3d->dc.host_dc); + dc_size = ct3d->dc.total_capacity; + } - if (!vmr && !pmr) { + if (!vmr && !pmr && !dc_mr) { return false; } - if (dpa_offset + CXL_CACHE_LINE_SIZE > ct3d->cxl_dstate.static_mem_size) { + if (dpa_offset >= vmr_size + pmr_size + dc_size) { + return false; + } + if (dpa_offset + CXL_CACHE_LINE_SIZE >= vmr_size + pmr_size + && ct3d->dc.num_regions == 0) { return false; } - if (vmr) { - if (dpa_offset < memory_region_size(vmr)) { - as = &ct3d->hostvmem_as; - } else { - as = &ct3d->hostpmem_as; - dpa_offset -= memory_region_size(vmr); - } - } else { + if (dpa_offset < vmr_size) { + as = &ct3d->hostvmem_as; + } else if (dpa_offset < vmr_size + pmr_size) { as = &ct3d->hostpmem_as; + dpa_offset -= vmr->size; + } else { + as = &ct3d->dc.host_dc_as; + dpa_offset -= (vmr_size + pmr_size); } address_space_write(as, dpa_offset, MEMTXATTRS_UNSPECIFIED, &data, diff --git a/include/hw/cxl/cxl_device.h b/include/hw/cxl/cxl_device.h index a32ee6d6ba..ddb24271a8 100644 --- a/include/hw/cxl/cxl_device.h +++ b/include/hw/cxl/cxl_device.h @@ -426,6 +426,10 @@ struct CXLType3Dev { uint64_t poison_list_overflow_ts; struct dynamic_capacity { + HostMemoryBackend *host_dc; + AddressSpace host_dc_as; + uint64_t total_capacity; /* 256M aligned */ + uint8_t num_regions; /* 0-8 regions */ struct CXLDCD_Region regions[DCD_MAX_REGION_NUM]; } dc; From patchwork Thu Jul 20 20:37:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "nifan@outlook.com" X-Patchwork-Id: 13321044 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 6F186C0015E for ; Thu, 20 Jul 2023 20:38:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229744AbjGTUio (ORCPT ); Thu, 20 Jul 2023 16:38:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35764 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229576AbjGTUin (ORCPT ); Thu, 20 Jul 2023 16:38:43 -0400 Received: from APC01-TYZ-obe.outbound.protection.outlook.com (mail-tyzapc01olkn2098.outbound.protection.outlook.com [40.92.107.98]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 33FF22726 for ; Thu, 20 Jul 2023 13:38:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mzM4xvm4gb/YGNflkXd59nN7/nMp5HR5A/+Yr1c1wPCAIXmwHuaw6zx5Fz2nrMhAKriFirvOomrLyPypcycaUKcM5yFYdeBtC2atddnzngSKYVkx6/fa4oTfnZBX9Sv1wliPmVcOAbJrpm/wlt3jiYeUmKszIMjyHdolXGWkyEJho9YBNImdUEB+oYY4sR32JuGgigEbLiv8+MGS5hHjQHgRES1SxorJpOox7ZOAQ8NQf5dG86Tm4Ef+/ZB2jkGT8G1yxF9ocrLCrmmZgp+TvgWtvs42ow4mKa3HPNciORSEgpEUlWwPKpTJXIrcEUhhcnctKpy59VwKNGcLyyRUxw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=xchX4tF+wgvfzrYJrYOEhfjyoDWDLGbRTx5w9dajLqU=; b=BMGggIrqB+FBi+gNw6QdMXOIHXBTrc0E1cO1RFvdDT5yTSi0kXaZ1l0opQX9/xizBQuk5eptw4mWdalel9O1Zw766EQJheYYLEDJBFrsbxYbP3EeFL8zyRU/b+naupWEHLNHj9ePJj4IKubNzT5yTApjqz1ejQwhM98oatemX5n7bGggi4DvmHQcM3FGcoufL/Ew+nKk+4DeH04Acm8U8UBijjcd/Mb371t8nQudpJ1lp+XegAO4ya+Jp5orYygih/f59t3eUNm2g0kOQy2odjFZXWrCqd0DRiLvDAu+XAssHvk8fGJ90YHzIAkm7SlbfyEGq9byVWd19wYIkL/fKQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=xchX4tF+wgvfzrYJrYOEhfjyoDWDLGbRTx5w9dajLqU=; b=P7X/lgo+cxZqg9shNWaEXBuYxP6h+93iXgTfXcJB/WW6/Hdk/C0TGGh0AO7oiw/YwcS+nSvxYdpPXxbtPgPbdrYqea7lrvSjLR8X+c+DZWDZRF8kQirQo6bSG6IJwMMEJUbsKA1crNCY1fWvM5VhcQeVv9nZP6fqY+b2CutwBitdAdTG07QlVBR6enDRcYEJMrJpGMPHJTNZSA8Nrn4DVI5XVEjkFxvPS4CsTCRqJ/pgc3fDM6tTeUG8cd3ydfYlCXtooL7yGlJ8rg3uU4iMcICl2vEe+yRyTPz8OUODENvS+X26yeS5VraZOCefVL9DFG6mGXCMfZ++XvuPBO95SQ== Received: from SG2PR06MB3397.apcprd06.prod.outlook.com (2603:1096:4:7a::17) by KL1PR0601MB4100.apcprd06.prod.outlook.com (2603:1096:820:24::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6609.24; Thu, 20 Jul 2023 20:38:32 +0000 Received: from SG2PR06MB3397.apcprd06.prod.outlook.com ([fe80::450:9c8c:9058:c94c]) by SG2PR06MB3397.apcprd06.prod.outlook.com ([fe80::450:9c8c:9058:c94c%5]) with mapi id 15.20.6609.024; Thu, 20 Jul 2023 20:38:32 +0000 From: nifan@outlook.com To: qemu-devel@nongnu.org Cc: jonathan.cameron@huawei.com, linux-cxl@vger.kernel.org, gregory.price@memverge.com, hchkuo@avery-design.com.tw, cbrowy@avery-design.com, ira.weiny@intel.com, dan.j.williams@intel.com, a.manzanares@samsung.com, dave@stgolabs.net, nmtadam.samsung@gmail.com, Fan Ni , Fan Ni Subject: [PATCH 6/9] hw/mem/cxl_type3: Add DC extent list representative and get DC extent list mailbox support Date: Thu, 20 Jul 2023 13:37:05 -0700 Message-ID: X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230720203708.25825-1-nifan@outlook.com> References: <20230720203708.25825-1-nifan@outlook.com> X-TMN: [uVeTdj6vuyl39quOT07lJpFu7L+ffF0K] X-ClientProxiedBy: BYAPR03CA0008.namprd03.prod.outlook.com (2603:10b6:a02:a8::21) To SG2PR06MB3397.apcprd06.prod.outlook.com (2603:1096:4:7a::17) X-Microsoft-Original-Message-ID: <20230720203708.25825-7-nifan@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SG2PR06MB3397:EE_|KL1PR0601MB4100:EE_ X-MS-Office365-Filtering-Correlation-Id: b3b6f487-3e13-464a-039e-08db89612f5d X-MS-Exchange-SLBlob-MailProps: quCBMN2EvO/qzAKd82WE1LuLgf/v/GCyEduUCc1jlcU90pe+mvHZutQxPkLDk+gMaZSWh+3JH4erfU/KBdCUWUS1kWuF/TVTx7o39JDWEDhATrSyHm1bvTXc5FHTIOlfpJSHSuhuDN+5X6dbEJav/2DXhE25h/zumpkW4+cTpk5UZ8V1O9jw9qYWs7hFzWMc354jLhdeENOkFkvDbijgqb6B1RxmSuBJ/pa7umC4iB7wev8e63lnxvc835a7TAEKMty70O8lo41+e4xy1N0iTJ8nBNccbiM5g3diZcSFa6Vm7r68+2kS2SHq0tluYpCoIphXYcdCqHExE9zNFWf3X/GF+Lk1WCI81d5VwBnoPTNuDKTaZEyh40pIZWqiKsuFgq4KzQxII4J6CJvDuyjuPb1MQSp85NDYp0PHq+PbeidqI+PoorzXKRdi0WLzyzThXWWcmSf4oMGl2H+Pn5sS90PHRvQw7zG26mAyTpZpdW6yCBhwbiPpIRbfCCJB2HPlPk5n+cL7/hWUZfXw0MA5hACDZsIxlIAkGiUet9X7+RYdIpyuj+NP8cXJuFb2xrQvzIRTgdvsH+2Y3eEh8+ELbLMgj0oLjTSUyVpk2QYIy0dOmuVZrIlPiaXMqIZqiCe18Cp1WN0b90MxteE+N/OD52lKlK4u4HpQNmXHhP/6AL2DtgR05LbhdFJxrjaJrYu2BUzfl7bjuPRWUvsqQkFvfw== X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: bml133tPTVYts+cFHP5oz4sutaFfyJ40nadWmrvhCw2/qCFIbj5ZWBY9yy1vHTfXXH/PJxjqBvGeqLaWiq8bOZoZVe4mmFgerqkw0ZkePEzGQIaw5e7VX0g7w6A5unGsMJU525act5hCcbwH2HZZODJBL0GNm25ukLVtsAUOmKDzjlngJuBsW6sG2MgEYx3kiYlKm9S8W7xRTBEag3fqwrUVChs4mu19aMikXvwXD1szcBBPV3KG97/4+rqi2HYF384cU9EnQ7B6PBCsqZfIJ0WHweJCqU1xtCehzOVJvnZwdV7s/Eir/famBMtPUzCB7tb8IZcWL62TM6VochsfR+TI4V4MKAS4mp/EnugPFO7ONU2kAU76bQ69urZtcazPvT2K/VVwWBh6pi5k0yRdUj95g+nBwHmYeWMvCqayxm+p/ZX2AabNVMUnooZ6WqCEsNYDKp5myvss/Z9YT+yUypkAxJBK2eycTu6yGdn3i1aeE4fCex/0oJSduhCyIckmD8aT8awVnu0b8DT0m6Weu1COsAVDyk7cn4SKBZpjaugODfeh8RKeZHQY7BuKQXgm0Ied4tM0M335nul6Lriaw3X5vfZYwooSyly3R7+2Tg2FfjYhQT6OdCsCTzaJsBgH X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: veK6YQ3sGVJFybsQdWbgQ6oanVKvgy6PaOHvI+iPpk9TLR+moAUzi2+S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rEGbEFBv3VBoPg/1tczShdgGBP/sSfZjEgKsS/dLMs7FYdPyJvOBajLzCmfmiqbj/NKPRDgs7Y/pxG6HmKpYEqhqdUNI8WD4M25lyzsRztdPw== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: b3b6f487-3e13-464a-039e-08db89612f5d X-MS-Exchange-CrossTenant-AuthSource: SG2PR06MB3397.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Jul 2023 20:37:50.4786 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: KL1PR0601MB4100 Precedence: bulk List-ID: X-Mailing-List: linux-cxl@vger.kernel.org From: Fan Ni Add dynamic capacity extent list representative to the definition of CXLType3Dev and add get DC extent list mailbox command per CXL.spec.3.0:.8.2.9.8.9.2. Signed-off-by: Fan Ni --- hw/cxl/cxl-mailbox-utils.c | 71 +++++++++++++++++++++++++++++++++++++ hw/mem/cxl_type3.c | 1 + include/hw/cxl/cxl_device.h | 23 ++++++++++++ 3 files changed, 95 insertions(+) diff --git a/hw/cxl/cxl-mailbox-utils.c b/hw/cxl/cxl-mailbox-utils.c index c497298a1d..754ab68b78 100644 --- a/hw/cxl/cxl-mailbox-utils.c +++ b/hw/cxl/cxl-mailbox-utils.c @@ -83,6 +83,7 @@ enum { #define CLEAR_POISON 0x2 DCD_CONFIG = 0x48, /*r3.0: 8.2.9.8.9*/ #define GET_DC_CONFIG 0x0 + #define GET_DYN_CAP_EXT_LIST 0x1 PHYSICAL_SWITCH = 0x51 #define IDENTIFY_SWITCH_DEVICE 0x0 }; @@ -1018,6 +1019,73 @@ static CXLRetCode cmd_dcd_get_dyn_cap_config(struct cxl_cmd *cmd, return CXL_MBOX_SUCCESS; } +/* + * cxl spec 3.0: 8.2.9.8.9.2 + * Get Dynamic Capacity Extent List (Opcode 4810h) + */ +static CXLRetCode cmd_dcd_get_dyn_cap_ext_list(struct cxl_cmd *cmd, + CXLDeviceState *cxl_dstate, + uint16_t *len) +{ + struct get_dyn_cap_ext_list_in_pl { + uint32_t extent_cnt; + uint32_t start_extent_id; + } QEMU_PACKED; + + struct get_dyn_cap_ext_list_out_pl { + uint32_t count; + uint32_t total_extents; + uint32_t generation_num; + uint8_t rsvd[4]; + CXLDCExtent_raw records[]; + } QEMU_PACKED; + + struct get_dyn_cap_ext_list_in_pl *in = (void *)cmd->payload; + struct get_dyn_cap_ext_list_out_pl *out = (void *)cmd->payload; + struct CXLType3Dev *ct3d = container_of(cxl_dstate, CXLType3Dev, + cxl_dstate); + uint16_t record_count = 0, i = 0, record_done = 0; + CXLDCDExtentList *extent_list = &ct3d->dc.extents; + CXLDCD_Extent *ent; + uint16_t out_pl_len; + uint32_t start_extent_id = in->start_extent_id; + + if (start_extent_id > ct3d->dc.total_extent_count) { + return CXL_MBOX_INVALID_INPUT; + } + + record_count = MIN(in->extent_cnt, + ct3d->dc.total_extent_count - start_extent_id); + + out_pl_len = sizeof(*out) + record_count * sizeof(out->records[0]); + /* May need more processing here in the future */ + assert(out_pl_len <= CXL_MAILBOX_MAX_PAYLOAD_SIZE); + + memset(out, 0, out_pl_len); + stl_le_p(&out->count, record_count); + stl_le_p(&out->total_extents, ct3d->dc.total_extent_count); + stl_le_p(&out->generation_num, ct3d->dc.ext_list_gen_seq); + + if (record_count > 0) { + QTAILQ_FOREACH(ent, extent_list, node) { + if (i++ < start_extent_id) { + continue; + } + stq_le_p(&out->records[record_done].start_dpa, ent->start_dpa); + stq_le_p(&out->records[record_done].len, ent->len); + memcpy(&out->records[record_done].tag, ent->tag, 0x10); + stw_le_p(&out->records[record_done].shared_seq, ent->shared_seq); + record_done++; + if (record_done == record_count) { + break; + } + } + } + + *len = out_pl_len; + return CXL_MBOX_SUCCESS; +} + #define IMMEDIATE_CONFIG_CHANGE (1 << 1) #define IMMEDIATE_DATA_CHANGE (1 << 2) #define IMMEDIATE_POLICY_CHANGE (1 << 3) @@ -1058,6 +1126,9 @@ static struct cxl_cmd cxl_cmd_set[256][256] = { cmd_media_clear_poison, 72, 0 }, [DCD_CONFIG][GET_DC_CONFIG] = { "DCD_GET_DC_CONFIG", cmd_dcd_get_dyn_cap_config, 2, 0 }, + [DCD_CONFIG][GET_DYN_CAP_EXT_LIST] = { + "DCD_GET_DYNAMIC_CAPACITY_EXTENT_LIST", cmd_dcd_get_dyn_cap_ext_list, + 8, 0 }, }; static struct cxl_cmd cxl_cmd_set_sw[256][256] = { diff --git a/hw/mem/cxl_type3.c b/hw/mem/cxl_type3.c index af1d919be3..608063ac52 100644 --- a/hw/mem/cxl_type3.c +++ b/hw/mem/cxl_type3.c @@ -789,6 +789,7 @@ static int cxl_create_dc_regions(CXLType3Dev *ct3d) region_base += region->len; } + QTAILQ_INIT(&ct3d->dc.extents); return 0; } diff --git a/include/hw/cxl/cxl_device.h b/include/hw/cxl/cxl_device.h index ddb24271a8..a9cfe4e904 100644 --- a/include/hw/cxl/cxl_device.h +++ b/include/hw/cxl/cxl_device.h @@ -384,6 +384,25 @@ typedef QLIST_HEAD(, CXLPoison) CXLPoisonList; #define DCD_MAX_REGION_NUM 8 +typedef struct CXLDCD_Extent_raw { + uint64_t start_dpa; + uint64_t len; + uint8_t tag[0x10]; + uint16_t shared_seq; + uint8_t rsvd[0x6]; +} QEMU_PACKED CXLDCExtent_raw; + +typedef struct CXLDCD_Extent { + uint64_t start_dpa; + uint64_t len; + uint8_t tag[0x10]; + uint16_t shared_seq; + uint8_t rsvd[0x6]; + + QTAILQ_ENTRY(CXLDCD_Extent) node; +} CXLDCD_Extent; +typedef QTAILQ_HEAD(, CXLDCD_Extent) CXLDCDExtentList; + typedef struct CXLDCD_Region { uint64_t base; uint64_t decode_len; /* in multiples of 256MB */ @@ -432,6 +451,10 @@ struct CXLType3Dev { uint8_t num_regions; /* 0-8 regions */ struct CXLDCD_Region regions[DCD_MAX_REGION_NUM]; + CXLDCDExtentList extents; + + uint32_t total_extent_count; + uint32_t ext_list_gen_seq; } dc; }; From patchwork Thu Jul 20 20:37:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "nifan@outlook.com" X-Patchwork-Id: 13321045 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 41BE5C00528 for ; Thu, 20 Jul 2023 20:38:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229576AbjGTUip (ORCPT ); Thu, 20 Jul 2023 16:38:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35770 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229685AbjGTUio (ORCPT ); Thu, 20 Jul 2023 16:38:44 -0400 Received: from APC01-TYZ-obe.outbound.protection.outlook.com (mail-tyzapc01olkn2058.outbound.protection.outlook.com [40.92.107.58]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C91DC12F for ; Thu, 20 Jul 2023 13:38:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=T0MLuahxJW1EJkL392rbUBMPRPXHQlddHiaBrwfdcdWOxQrE/ucjorGrDpzaa2+0is38De5KI6Adb3mRFO0gQyPkFdQw4R98ioOASpymJ9enUr2cfJQjfN6uxaWKjeqzP9yMt1zqReFrUKwbrT3/b3eBhr7S6STXGEw5gpbMl1hP+11TDykOwQnOH1jlq7NNnFEEldRom3FxFDExjYcgooNJWzh4UxF78K1cSn+fcgMKATcVBf6JSHmlONfc92XbF1kzjTuW7ZjO+yI3ehYNQC0t/7XMjF4j0lVMQgDSZcDmRLxvJvzc49z18acQSsM4FJnZ7nii3npNOYJH5V/R7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=zFF1nbNGj3AAxJToXnITbaV8vQWbstQCqbAHwBy5ip0=; b=jxIXgHl6QknrX5j2QcR4ZzBLU90lHZCrGx/sOgVmtM9zXdUeiVJQYBgiRaqzcLSbQmagTMoYo2io1e8EsvUllkvmAQ7oB743KNfvTKWgB++c3iyKne6/KKb5oSDINIJcITysHc0R1j7SPkUHaiT146xzQlCzca7DSHzNE5tjezq7w2KUMXfbuFOxp2J9nTMqeydirS3Kt+Byqj2c2GIfzvDUfvBk1TeypwARcc0qRqSzODenU/pNFjUlRNWSwjYpKvQm9XFIoipbJHTGDP8twnEruSlqjDaSUIxh3tmtl6ACZhVlhkGSmxh8590NkE3RpxDJII9FMwYESwOfv60rKQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=zFF1nbNGj3AAxJToXnITbaV8vQWbstQCqbAHwBy5ip0=; b=ap4wAmpFWcdZC2Uxk904bcyw0DxlfvBrHnDqRdjzMimGuC7gXpY4VHw0KFO1oPHhGFE88Wb299xDFaAEepRITEI/uI7oaMsv5P/RO2dK/EPNTIRvlezZF+lG55+toS5/+SkAeKo9/CeImBh2U5bQx2T6aEL3d+cWs9YacopTPQCiNZNsB9nTFTOaHa3mWhbBEwSeWySEegyGVIRDGy4KYFJQ74VTIGmRWxdWuij60cgfww9JgXHDopydSAkg6Qsk6d2iw4ZBgR1kncDAFZNxn5h54UkP5hzyA859aEqUK85sCaeKZFq0kn3mpSlE08I5egCM/9gXxFZLhMFz47oUKQ== Received: from SG2PR06MB3397.apcprd06.prod.outlook.com (2603:1096:4:7a::17) by KL1PR0601MB4100.apcprd06.prod.outlook.com (2603:1096:820:24::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6609.24; Thu, 20 Jul 2023 20:38:32 +0000 Received: from SG2PR06MB3397.apcprd06.prod.outlook.com ([fe80::450:9c8c:9058:c94c]) by SG2PR06MB3397.apcprd06.prod.outlook.com ([fe80::450:9c8c:9058:c94c%5]) with mapi id 15.20.6609.024; Thu, 20 Jul 2023 20:38:32 +0000 From: nifan@outlook.com To: qemu-devel@nongnu.org Cc: jonathan.cameron@huawei.com, linux-cxl@vger.kernel.org, gregory.price@memverge.com, hchkuo@avery-design.com.tw, cbrowy@avery-design.com, ira.weiny@intel.com, dan.j.williams@intel.com, a.manzanares@samsung.com, dave@stgolabs.net, nmtadam.samsung@gmail.com, Fan Ni , Fan Ni Subject: [PATCH 7/9] hw/cxl/cxl-mailbox-utils: Add mailbox commands to support add/release dynamic capacity response Date: Thu, 20 Jul 2023 13:37:06 -0700 Message-ID: X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230720203708.25825-1-nifan@outlook.com> References: <20230720203708.25825-1-nifan@outlook.com> X-TMN: [tOBKb2hYzxa+4UvpSITWmuPe2Rk/5Vii] X-ClientProxiedBy: BYAPR03CA0008.namprd03.prod.outlook.com (2603:10b6:a02:a8::21) To SG2PR06MB3397.apcprd06.prod.outlook.com (2603:1096:4:7a::17) X-Microsoft-Original-Message-ID: <20230720203708.25825-8-nifan@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SG2PR06MB3397:EE_|KL1PR0601MB4100:EE_ X-MS-Office365-Filtering-Correlation-Id: 1c415240-ed86-428c-f3c9-08db8961317e X-MS-Exchange-SLBlob-MailProps: 9IecXKUgicAYce+YIvRqgnoEwnxu+bmnb+JDpc9/iTTOP9ozNsAulVhyCddRZrdAydHlx9zkKjivmylR3sUpgdc6OS1qLfr3YHf49zkPZC8GXfYZCmByzls9RWqlXS8OGt6G6hz+QAvtWbzLNhLVUS8eC2lQIdLH2MYedaT7NI8FsO/deRnBmw3vLk2Ia4xs1XKI+IeyrUnlTlsH+GaCqyzmJSNdk0FXyRDEicA6IjVTFayGg216dwJLfHfR8qidXT7WcsHLc3aUrUwsGtID3+t2JbrhhdMt2Z0GgBqsdhv5Pomd4/lBifntId+cYqfWA8/8UXCE2Piz7xikJGWizYs5ZlMiGsTguSWpVQO5F1wwJMK5Rm6B3rs4ZRjXuNKxgtrtxntgwiBB+nPKOIHnIyPJRfk4U5DPJLndz+nCTomqfkVE06rRicfABKud51sER3YaLqx+UI8vOAMUmiGBQ81/crpZGtNsU5iID70j/Mwgq8QaMk6TkkO7KCmTGgdSpO243s9M2W+6KFFz/pL50HIBYiqB1USOHIsiOdgAjB10RyKaAvIhci7yl2wxsy533ulbZZwlg/a0snS6aEiG8E7g5q0PvcJDurfbiWgz/MLh7AXQDE/QX73UvwMHCBzjWjTWZgwQhexpM6ze72J6139NCtwxXtcABF0v4nDSxZcreupGf65ZK4R6TtC6LXOO30+ELrT1EpMnFIJK5kDq0RhF85Gl1B2nKMLk9U6eruhP1hvUkng7aQ== X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: MK9d7FwlqkcKIqQf7pVFQSNfMPoLG/OjKIJncVDLGxmZ9KmNUM+UCM20yR1BPlit96SHgEI9lEHRiLdzg79nT5lOdGNVrWE4se15nM/nJfURm7tOe2FdYp2T/XmfsSoU+PCrJ3+noTT80jY8vL15ZHboshE2fo1h1WrjzozsF6GvVtYPOpud6ldrLQ3XqVZEAWsF1H6LmB3nfalf9l+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G0ZIU07t0OOR6AJKu30+U7VDMW9PWY00z9jGY2ddbrKGA3ISqB0mXT9nLhWJ/UteU+v9poBxkKRMtiR1S2xlK9DSpH5t4T1TUpYz0j5cjbruJCHAeiOBkhamPAt8qgBYB5/Qifx8zRJOL8ne0VtVUA9DhhYKyrKAQhsZqrzYhPmGEBSCHTmEc9hS3S1Z9Z6nAf8zB1YDDKm7tnyeZpxJCzqEWMDnuukKalHqM+BEf96EWEuDsTabkHSQT2piffkTs4ja3RGfhLSbe3Fqstvv7ZcejD0CLdMtgWeduRMAWZUUw3SpFL5xrDPuzQrdkkbqwqS5fZ0npascK3qZumaGXGtB6mLXLUq7MmpXk+p3SHa6SJTA5wyX1xbKCsj3VzFJ5vRqfquc3n7+ZzDwdYFjc4/UuJWKGzEckLeiGcdVPEBuPZZLN7likx6vxXFNP0fO4WcTz9S/HBGYiwpqMFjvpWdj+EFpLJPQAfPCewgdtWAJG6JPKPiYdxgvXiw3hRHJcc0oEn4EaJNB10rZ93+RWVOYw/c1eajPP9MY43W3wHs6YloeZMF6qb0rR+jRhhtz7nwpuaOGkgF67NmSiOMsOuR0d/SeESPZ0v+6ja/Ru3bvIc1IzIFfwTVs5x+FiJngKjFbVNuK2w== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1c415240-ed86-428c-f3c9-08db8961317e X-MS-Exchange-CrossTenant-AuthSource: SG2PR06MB3397.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Jul 2023 20:37:54.1269 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: KL1PR0601MB4100 Precedence: bulk List-ID: X-Mailing-List: linux-cxl@vger.kernel.org From: Fan Ni Per CXL spec 3.0, two mailbox commands are implemented: Add Dynamic Capacity Response (Opcode 4802h) 8.2.9.8.9.3, and Release Dynamic Capacity (Opcode 4803h) 8.2.9.8.9.4. Signed-off-by: Fan Ni --- hw/cxl/cxl-mailbox-utils.c | 253 ++++++++++++++++++++++++++++++++++++ include/hw/cxl/cxl_device.h | 3 +- 2 files changed, 255 insertions(+), 1 deletion(-) diff --git a/hw/cxl/cxl-mailbox-utils.c b/hw/cxl/cxl-mailbox-utils.c index 754ab68b78..d547385ba7 100644 --- a/hw/cxl/cxl-mailbox-utils.c +++ b/hw/cxl/cxl-mailbox-utils.c @@ -84,6 +84,8 @@ enum { DCD_CONFIG = 0x48, /*r3.0: 8.2.9.8.9*/ #define GET_DC_CONFIG 0x0 #define GET_DYN_CAP_EXT_LIST 0x1 + #define ADD_DYN_CAP_RSP 0x2 + #define RELEASE_DYN_CAP 0x3 PHYSICAL_SWITCH = 0x51 #define IDENTIFY_SWITCH_DEVICE 0x0 }; @@ -1086,6 +1088,251 @@ static CXLRetCode cmd_dcd_get_dyn_cap_ext_list(struct cxl_cmd *cmd, return CXL_MBOX_SUCCESS; } +/* + * Check whether the bits at addr between [nr, nr+size) are all set, + * return 1 if all 1s, else return 0 + */ +static inline int test_bits(const unsigned long *addr, int nr, int size) +{ + unsigned long res = find_next_zero_bit(addr, size + nr, nr); + + return (res >= nr + size) ? 1 : 0; +} + +/* + * Find dynamic capacity region id based on dpa range [dpa, dpa+len) + */ +static uint8_t find_region_id(struct CXLType3Dev *dev, uint64_t dpa, + uint64_t len) +{ + int8_t i = dev->dc.num_regions - 1; + + while (i > 0 && dpa < dev->dc.regions[i].base) { + i--; + } + + if (dpa < dev->dc.regions[i].base + || dpa + len > dev->dc.regions[i].base + dev->dc.regions[i].len) { + return dev->dc.num_regions; + } + + return i; +} + +static void insert_extent_to_extent_list(CXLDCDExtentList *list, uint64_t dpa, + uint64_t len, uint8_t *tag, uint16_t shared_seq) +{ + CXLDCD_Extent *extent; + extent = g_new0(CXLDCD_Extent, 1); + extent->start_dpa = dpa; + extent->len = len; + if (tag) { + memcpy(extent->tag, tag, 0x10); + } else { + memset(extent->tag, 0, 0x10); + } + extent->shared_seq = shared_seq; + + QTAILQ_INSERT_TAIL(list, extent, node); +} + +typedef struct updated_dc_extent_list_in_pl { + uint32_t num_entries_updated; + uint8_t rsvd[4]; + struct { /* r3.0: Table 8-130 */ + uint64_t start_dpa; + uint64_t len; + uint8_t rsvd[8]; + } QEMU_PACKED updated_entries[]; +} QEMU_PACKED updated_dc_extent_list_in_pl; + +/* + * The function only check the input extent list against itself. + */ +static CXLRetCode detect_malformed_extent_list(CXLType3Dev *dev, + const updated_dc_extent_list_in_pl *in) +{ + unsigned long *blk_bitmap; + uint64_t min_block_size = dev->dc.regions[0].block_size; + struct CXLDCD_Region *region = &dev->dc.regions[0]; + uint32_t i; + uint64_t dpa, len; + uint8_t rid; + CXLRetCode ret; + + for (i = 1; i < dev->dc.num_regions; i++) { + region = &dev->dc.regions[i]; + if (min_block_size > region->block_size) { + min_block_size = region->block_size; + } + } + + blk_bitmap = bitmap_new((region->len + region->base + - dev->dc.regions[0].base) / min_block_size); + + for (i = 0; i < in->num_entries_updated; i++) { + dpa = in->updated_entries[i].start_dpa; + len = in->updated_entries[i].len; + + rid = find_region_id(dev, dpa, len); + if (rid == dev->dc.num_regions) { + ret = CXL_MBOX_INVALID_PA; + goto out; + } + + region = &dev->dc.regions[rid]; + if (dpa % region->block_size || len % region->block_size) { + ret = CXL_MBOX_INVALID_EXTENT_LIST; + goto out; + } + /* the dpa range already covered by some other extents in the list */ + if (test_bits(blk_bitmap, dpa / min_block_size, len / min_block_size)) { + ret = CXL_MBOX_INVALID_EXTENT_LIST; + goto out; + } + bitmap_set(blk_bitmap, dpa / min_block_size, len / min_block_size); + } + + ret = CXL_MBOX_SUCCESS; + +out: + g_free(blk_bitmap); + return ret; +} + +/* + * cxl spec 3.0: 8.2.9.8.9.3 + * Add Dynamic Capacity Response (opcode 4802h) + * Assume an extent is added only after the response is processed successfully + * TODO: for better extent list validation, a better solution would be + * maintaining a pending extent list and use it to verify the extent list in + * the response. + */ +static CXLRetCode cmd_dcd_add_dyn_cap_rsp(struct cxl_cmd *cmd, + CXLDeviceState *cxl_dstate, uint16_t *len_unused) +{ + updated_dc_extent_list_in_pl *in = (void *)cmd->payload; + struct CXLType3Dev *ct3d = container_of(cxl_dstate, CXLType3Dev, + cxl_dstate); + CXLDCDExtentList *extent_list = &ct3d->dc.extents; + CXLDCD_Extent *ent; + uint32_t i; + uint64_t dpa, len; + CXLRetCode ret; + + if (in->num_entries_updated == 0) { + ret = CXL_MBOX_SUCCESS; + goto out; + } + + ret = detect_malformed_extent_list(ct3d, in); + if (ret != CXL_MBOX_SUCCESS) { + goto out; + } + + for (i = 0; i < in->num_entries_updated; i++) { + dpa = in->updated_entries[i].start_dpa; + len = in->updated_entries[i].len; + + /* + * Check if the DPA range of the to-be-added extent overlaps with + * existing extent list maintained by the device. + */ + QTAILQ_FOREACH(ent, extent_list, node) { + if (ent->start_dpa == dpa && ent->len == len) { + ret = CXL_MBOX_INVALID_PA; + goto out; + } else if (ent->start_dpa <= dpa + && dpa + len <= ent->start_dpa + ent->len) { + ret = CXL_MBOX_INVALID_PA; + goto out; + } else if ((dpa < ent->start_dpa + ent->len + && dpa + len > ent->start_dpa + ent->len) + || (dpa < ent->start_dpa && dpa + len > ent->start_dpa)) { + ret = CXL_MBOX_INVALID_PA; + goto out; + } + } + + /* + * TODO: add a pending extent list based on event log record and verify + * the input response + */ + + insert_extent_to_extent_list(extent_list, dpa, len, NULL, 0); + } + ret = CXL_MBOX_SUCCESS; + +out: + return ret; +} + +/* + * Spec 3.0: 8.2.9.8.9.4 + * Release Dynamic Capacity (opcode 4803h) + **/ +static CXLRetCode cmd_dcd_release_dyn_cap(struct cxl_cmd *cmd, + CXLDeviceState *cxl_dstate, + uint16_t *len_unused) +{ + updated_dc_extent_list_in_pl *in = (void *)cmd->payload; + struct CXLType3Dev *ct3d = container_of(cxl_dstate, CXLType3Dev, + cxl_dstate); + CXLDCDExtentList *extent_list = &ct3d->dc.extents; + CXLDCD_Extent *ent; + uint32_t i; + uint64_t dpa, len; + CXLRetCode ret; + + if (in->num_entries_updated == 0) { + return CXL_MBOX_INVALID_INPUT; + } + + ret = detect_malformed_extent_list(ct3d, in); + if (ret != CXL_MBOX_SUCCESS) { + return ret; + } + + for (i = 0; i < in->num_entries_updated; i++) { + dpa = in->updated_entries[i].start_dpa; + len = in->updated_entries[i].len; + + QTAILQ_FOREACH(ent, extent_list, node) { + if (ent->start_dpa == dpa && ent->len == len) { + break; + } else if (ent->start_dpa < dpa + && dpa + len <= ent->start_dpa + ent->len) { + /* remove partial extent */ + uint64_t len1 = dpa - ent->start_dpa; + uint64_t len2 = ent->start_dpa + ent->len - dpa - len; + + if (len1) { + insert_extent_to_extent_list(extent_list, ent->start_dpa, + len1, NULL, 0); + } + if (len2) { + insert_extent_to_extent_list(extent_list, dpa + len, len2, + NULL, 0); + } + break; + } else if ((dpa < ent->start_dpa + ent->len + && dpa + len > ent->start_dpa + ent->len) + || (dpa < ent->start_dpa && dpa + len > ent->start_dpa)) + return CXL_MBOX_INVALID_EXTENT_LIST; + } + + if (ent) { + QTAILQ_REMOVE(extent_list, ent, node); + g_free(ent); + } else { + /* Try to remove a non-existing extent */ + return CXL_MBOX_INVALID_PA; + } + } + + return CXL_MBOX_SUCCESS; +} + #define IMMEDIATE_CONFIG_CHANGE (1 << 1) #define IMMEDIATE_DATA_CHANGE (1 << 2) #define IMMEDIATE_POLICY_CHANGE (1 << 3) @@ -1129,6 +1376,12 @@ static struct cxl_cmd cxl_cmd_set[256][256] = { [DCD_CONFIG][GET_DYN_CAP_EXT_LIST] = { "DCD_GET_DYNAMIC_CAPACITY_EXTENT_LIST", cmd_dcd_get_dyn_cap_ext_list, 8, 0 }, + [DCD_CONFIG][ADD_DYN_CAP_RSP] = { + "ADD_DCD_DYNAMIC_CAPACITY_RESPONSE", cmd_dcd_add_dyn_cap_rsp, + ~0, IMMEDIATE_DATA_CHANGE }, + [DCD_CONFIG][RELEASE_DYN_CAP] = { + "RELEASE_DCD_DYNAMIC_CAPACITY", cmd_dcd_release_dyn_cap, + ~0, IMMEDIATE_DATA_CHANGE }, }; static struct cxl_cmd cxl_cmd_set_sw[256][256] = { diff --git a/include/hw/cxl/cxl_device.h b/include/hw/cxl/cxl_device.h index a9cfe4e904..5bf1dd4024 100644 --- a/include/hw/cxl/cxl_device.h +++ b/include/hw/cxl/cxl_device.h @@ -130,7 +130,8 @@ typedef enum { CXL_MBOX_INCORRECT_PASSPHRASE = 0x14, CXL_MBOX_UNSUPPORTED_MAILBOX = 0x15, CXL_MBOX_INVALID_PAYLOAD_LENGTH = 0x16, - CXL_MBOX_MAX = 0x17 + CXL_MBOX_INVALID_EXTENT_LIST = 0x1E, /* cxl r3.0: Table 8-34*/ + CXL_MBOX_MAX = 0x1F } CXLRetCode; struct cxl_cmd; From patchwork Thu Jul 20 20:37:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "nifan@outlook.com" X-Patchwork-Id: 13321046 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 700CEC001DE for ; Thu, 20 Jul 2023 20:38:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229756AbjGTUiq (ORCPT ); Thu, 20 Jul 2023 16:38:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229751AbjGTUip (ORCPT ); Thu, 20 Jul 2023 16:38:45 -0400 Received: from APC01-TYZ-obe.outbound.protection.outlook.com (mail-tyzapc01olkn2098.outbound.protection.outlook.com [40.92.107.98]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D8B6C271D for ; Thu, 20 Jul 2023 13:38:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EXsOOlTNpA/ZeR0I3v8+6Jw2brL6uHwo/GcACLJwTHyGDDGCAf2563B3dG9+HXeBaENWAEwXsIFxy1G5n02bvLBydANGZ8GZuC9mZsmMMWFVkVfrvQqFG+GkutONccQFr1jbfKko/ysO6A027uSLtutFgyB55CdN+knY0kJRghBWnKdXvFmhf4uO7GWkVlMeEvFKat60ORctu9PCf0ixrngLmD3pO51LMXNsJ3/5xjEZw8odBleHX0Vlb+RrqyMbe9XhaK8BKyR56JczsiTY5C6DT9KrdTzGp9hpZfWKOB7kqhRR2P++2hJVo5c1/fsDakB0ctCl19XCi/ZEYm1ctQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=90ziaoiq/m1HqxdkBxLqRSdvriBHEYoBvHYlkoDeh9w=; b=Fvhu8FBEjUhahIqtdfHY212EC/OeVUVv32Q9muCm2iGlWpiqaE9ci5h1b6lQagK+bt3LBw2HUfIWq1ibrbM85zlMGl4qe+1Eufnarw198yIk4zMcQn++PLvHtN4VBGNhUcoyj4ygPtH96pTbTLhvwo0ncULEOdhkGFT7y1y/laYpdbrIv/oXM9lqhEQt88EYsuHsfpsRdQUlkTDP+eugvykfXfuB/PbiJAGRzGphcaA741P4CuRYhN2fDNsGilOTYs/iQ+06kLZTmp9ubYZ0EoISMVJasneZw+t3rLbiTymXrMM+wfN9NYbpDMZxuiVn23m6MXNyGYGb942e1vP8VQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=90ziaoiq/m1HqxdkBxLqRSdvriBHEYoBvHYlkoDeh9w=; b=Dp7/TMj6vMd5jtVoPscejXsxksTJ74+YgGYioypcejFLgevsBkKoxX7dChTv5grY2f4MsGkbKsuIzZQE0/EGdgnvwj2pJxOoVz41H6ScXlPf2T0yVhiO3xvwucgCf2aG+VqBC3T9C8yQjzgG3CZk6PlgykX1NmyY0Ze1sUclfKfDekXR/lKem0v/SZIHpO8OXzy6arzjmfmV/vtRNEaWNvZy3oSPujV5fdK1PE9yUUUnOIb+FaGpSqzClCRZqjweCaotgpBMjjV6zKeKUUPxMo8KomgE4WOXlp5bkUREHW+kffuZg+x6+Cd1919gGdqX8lHpGdusAnU6a+cA5p9D/w== Received: from SG2PR06MB3397.apcprd06.prod.outlook.com (2603:1096:4:7a::17) by KL1PR0601MB4100.apcprd06.prod.outlook.com (2603:1096:820:24::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6609.24; Thu, 20 Jul 2023 20:38:33 +0000 Received: from SG2PR06MB3397.apcprd06.prod.outlook.com ([fe80::450:9c8c:9058:c94c]) by SG2PR06MB3397.apcprd06.prod.outlook.com ([fe80::450:9c8c:9058:c94c%5]) with mapi id 15.20.6609.024; Thu, 20 Jul 2023 20:38:33 +0000 From: nifan@outlook.com To: qemu-devel@nongnu.org Cc: jonathan.cameron@huawei.com, linux-cxl@vger.kernel.org, gregory.price@memverge.com, hchkuo@avery-design.com.tw, cbrowy@avery-design.com, ira.weiny@intel.com, dan.j.williams@intel.com, a.manzanares@samsung.com, dave@stgolabs.net, nmtadam.samsung@gmail.com, Fan Ni , Fan Ni Subject: [PATCH 8/9] hw/cxl/events: Add qmp interfaces to add/release dynamic capacity extents Date: Thu, 20 Jul 2023 13:37:07 -0700 Message-ID: X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230720203708.25825-1-nifan@outlook.com> References: <20230720203708.25825-1-nifan@outlook.com> X-TMN: [cBjt15ghAnLmumpRyfOUEfEoZ/IRdx0e] X-ClientProxiedBy: BYAPR03CA0008.namprd03.prod.outlook.com (2603:10b6:a02:a8::21) To SG2PR06MB3397.apcprd06.prod.outlook.com (2603:1096:4:7a::17) X-Microsoft-Original-Message-ID: <20230720203708.25825-9-nifan@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SG2PR06MB3397:EE_|KL1PR0601MB4100:EE_ X-MS-Office365-Filtering-Correlation-Id: 49369720-3f38-4618-cf7a-08db896133ac X-MS-Exchange-SLBlob-MailProps: 9IecXKUgicAYce+YIvRqgnoEwnxu+bmn3AnhMUBFieGGYFasq7+cboh4s0BhU5+qsNgpAtEX6OQgrM1lYwnUY24pe+3hp8xjWJHT8yTZsJugHJmY0mcHfegb1kgjAC36bm+248XTz9nKDcnIWYIoSjQ+C7LYFDkGQZz0f3dnecnr0FfsmRiivvSHep9HiGTffaGhKcFnBmiBv6jW+oSh/KJ/qWb8Z8GadYleMHBswNW3aw9tDuHRUShfznCqF9kVyh0Xtn/pyskQb9xiSf+F5rbQpT7F+MMdWEInqCqbkKrCbQxDvq3ln1qiVOaTyf/ZNh3VcJf+ti+bp3lMKqKoSpTBZUr3iKbrAfQeVNWxfIM+hJaO3EFzIzluoQyFYK4zX8XEn8DfgPS2NKLvZy8XwJXQAMRtAiDd9PfNxQXUj5u12DyOiecLTnzfnd2P9o557qFxsAuf+5oqxBZveDfOt3+QVdt0aEuh6Qg2oBv22Jn0M47uYGpLtUnPovSQzj8Erunm61+KqmJKuhpb6Yg+vR8lqJTDIFoFxKhi/VHYwnQp6m65rAmregfkYZ72qReMjt2W+Tx05QRlyRVLB3n5FxcRMAuCPi62odm0NlFZXf2PQ8DNbSOgSOtQiLmBlJju7FjT9FcaP9n7BErIr62ylPl6iwgMWU5cDPO20LgePQDH0DKzuiaUJlXfTfkGM4I0RJGX/FzCSh/j8v5DML8isadNKFirHCDx3iEX/gnAmgmnUYo2l/4JZQ== X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: GX8hUyrarleUkGK+z6nrNtiK+STf6OdleQqVb8tG/6dlCg2wYQLRDvk9bmB9nEigNK7LVD61qyfaP/FGlP+X4B4TA5mAFvQ44Ut3shobx6YUV+P6vMfe4p1dkzVW+QPcCFbjkugGhfqKP2mnThSMGdkb/qOs+QCALhcLMC+tdwdRT4USkf0jNeMrTggiDCMa5v615riWmP4rUaxue0ZyruxECaJn3bhX7zKFYSXTgGiJrnL5Su4GZx50oqWtIjix0XhbDkkOvh3r4ojoC2zAFNom4jvyCyRadbPbg03pEPXiK9sTGmNzeKTPo39QVxK+OmSRbcxWgITScUc9MxJfTM2Ija+5pNCghczyM9P+JLmd3+EiOW5JjnuFNw34qaHVaeJ8c9nZXf9s0b3j7KWAhPavdsGj+SNxFXS8foYcbg0PNUY/rw2bPp1CqIpoUvRVLrLb37IF7H4hzByJIJi5gfDaqcquaWMXRxbetC9xdTWQ27XD57RCmYtpmjZIKL3taGLGASL7ncJTESjs6fixnN983vpMMHGt0akiRuikbOVdmo4Pp44jC5Slal323ZNxQ6tYqbeVRM/Wx/yjNau+x7b4JfYVHqkw9Mca3cBkY5UADBY30hLVH01FgWK0XFL5 X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: LH5nTTj5nt6bgCJNrnLCBhW/5Lf4JZTqNAMuiUBaclIpeMFeuMP4gDtNKGBgOBEr60udtSyN7HlC/NYqL15vFH7Z5WefavD6cXRbH2WQcGbnP9pXffhUqk8IBQuvzqPoyM3vNqWf1MfhmNzCGUJcjbqyRestyaMxmvr93Zo4p0VI6bMB8X43fY2p+3vlIAtfwRCNSkpPrP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369720-3f38-4618-cf7a-08db896133ac X-MS-Exchange-CrossTenant-AuthSource: SG2PR06MB3397.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Jul 2023 20:37:57.7587 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: KL1PR0601MB4100 Precedence: bulk List-ID: X-Mailing-List: linux-cxl@vger.kernel.org From: Fan Ni Since fabric manager emulation is not supported yet, the change implements the functions to add/release dynamic capacity extents as QMP interfaces. 1. Add dynamic capacity extents: For example, the command to add two continuous extents (each is 128MB long) to region 0 (starting at dpa offset 0 and 128MB) looks like below: { "execute": "qmp_capabilities" } { "execute": "cxl-add-dynamic-capacity-event", "arguments": { "path": "/machine/peripheral/cxl-dcd0", "extents": [ { "region-id": 0, "dpa": 0, "len": 128 }, { "region-id": 0, "dpa": 128, "len": 128 } ] } } 2. Release dynamic capacity extents: For example, the command to release an extent of size 128MB from region 0 (starting at dpa offset 128MB) look like below: { "execute": "cxl-release-dynamic-capacity-event", "arguments": { "path": "/machine/peripheral/cxl-dcd0", "extents": [ { "region-id": 0, "dpa": 128, "len": 128 } ] } } Signed-off-by: Fan Ni --- hw/mem/cxl_type3.c | 145 ++++++++++++++++++++++++++++++++++++ hw/mem/cxl_type3_stubs.c | 6 ++ include/hw/cxl/cxl_events.h | 16 ++++ qapi/cxl.json | 49 ++++++++++++ 4 files changed, 216 insertions(+) diff --git a/hw/mem/cxl_type3.c b/hw/mem/cxl_type3.c index 608063ac52..cb1f9182e6 100644 --- a/hw/mem/cxl_type3.c +++ b/hw/mem/cxl_type3.c @@ -1811,6 +1811,151 @@ void qmp_cxl_inject_memory_module_event(const char *path, CxlEventLog log, } } +static const QemuUUID dynamic_capacity_uuid = { + .data = UUID(0xca95afa7, 0xf183, 0x4018, 0x8c, 0x2f, + 0x95, 0x26, 0x8e, 0x10, 0x1a, 0x2a), +}; + +/* + * cxl r3.0: Table 8-47 + * 00h: add capacity + * 01h: release capacity + * 02h: forced capacity release + * 03h: region configuration updated + * 04h: Add capacity response + * 05h: capacity released + */ +enum DC_Event_Type { + DC_EVENT_ADD_CAPACITY, + DC_EVENT_RELEASE_CAPACITY, + DC_EVENT_FORCED_RELEASE_CAPACITY, + DC_EVENT_REGION_CONFIG_UPDATED, + DC_EVENT_ADD_CAPACITY_RSP, + DC_EVENT_CAPACITY_RELEASED, + DC_EVENT_NUM +}; + +#define MEM_BLK_SIZE_MB 128 +static void qmp_cxl_process_dynamic_capacity_event(const char *path, + CxlEventLog log, enum DC_Event_Type type, + uint16_t hid, CXLDCExtentRecordList *records, Error **errp) +{ + Object *obj = object_resolve_path(path, NULL); + CXLEventDynamicCapacity dCap; + CXLEventRecordHdr *hdr = &dCap.hdr; + CXLDeviceState *cxlds; + CXLType3Dev *dcd; + uint8_t flags = 1 << CXL_EVENT_TYPE_INFO; + uint32_t num_extents = 0; + CXLDCExtentRecordList *list = records; + CXLDCExtent_raw *extents; + uint64_t dpa, len; + uint8_t rid; + int i; + + if (!obj) { + error_setg(errp, "Unable to resolve path"); + return; + } + if (!object_dynamic_cast(obj, TYPE_CXL_TYPE3)) { + error_setg(errp, "Path not point to a valid CXL type3 device"); + return; + } + + dcd = CXL_TYPE3(obj); + cxlds = &dcd->cxl_dstate; + memset(&dCap, 0, sizeof(dCap)); + + if (!dcd->dc.num_regions) { + error_setg(errp, "No dynamic capacity support from the device"); + return; + } + + while (list) { + dpa = list->value->dpa * 1024 * 1024; + len = list->value->len * 1024 * 1024; + rid = list->value->region_id; + + if (rid >= dcd->dc.num_regions) { + error_setg(errp, "region id is too large"); + return; + } + + if (dpa % dcd->dc.regions[rid].block_size + || len % dcd->dc.regions[rid].block_size) { + error_setg(errp, "dpa or len is not aligned to region block size"); + return; + } + + if (dpa + len > dcd->dc.regions[rid].decode_len * 256 * 1024 * 1024) { + error_setg(errp, "extent range is beyond the region end"); + return; + } + + num_extents++; + list = list->next; + } + + i = 0; + list = records; + extents = g_new0(CXLDCExtent_raw, num_extents); + while (list) { + dpa = list->value->dpa * 1024 * 1024; + len = list->value->len * 1024 * 1024; + rid = list->value->region_id; + + extents[i].start_dpa = dpa + dcd->dc.regions[rid].base; + extents[i].len = len; + memset(extents[i].tag, 0, 0x10); + extents[i].shared_seq = 0; + + list = list->next; + i++; + } + + /* + * 8.2.9.1.5 + * All Dynamic Capacity event records shall set the Event Record + * Severity field in the Common Event Record Format to Informational + * Event. All Dynamic Capacity related events shall be logged in the + * Dynamic Capacity Event Log. + */ + cxl_assign_event_header(hdr, &dynamic_capacity_uuid, flags, sizeof(dCap), + cxl_device_get_timestamp(&dcd->cxl_dstate)); + + dCap.type = type; + stw_le_p(&dCap.host_id, hid); + /* only valid for DC_REGION_CONFIG_UPDATED event */ + dCap.updated_region_id = rid; + for (i = 0; i < num_extents; i++) { + memcpy(&dCap.dynamic_capacity_extent, &extents[i] + , sizeof(CXLDCExtent_raw)); + + if (cxl_event_insert(cxlds, CXL_EVENT_TYPE_DYNAMIC_CAP, + (CXLEventRecordRaw *)&dCap)) { + cxl_event_irq_assert(dcd); + } + } + + g_free(extents); +} + +void qmp_cxl_add_dynamic_capacity_event(const char *path, + struct CXLDCExtentRecordList *records, + Error **errp) +{ + qmp_cxl_process_dynamic_capacity_event(path, CXL_EVENT_LOG_INFORMATIONAL, + DC_EVENT_ADD_CAPACITY, 0, records, errp); +} + +void qmp_cxl_release_dynamic_capacity_event(const char *path, + struct CXLDCExtentRecordList *records, + Error **errp) +{ + qmp_cxl_process_dynamic_capacity_event(path, CXL_EVENT_LOG_INFORMATIONAL, + DC_EVENT_RELEASE_CAPACITY, 0, records, errp); +} + static void ct3_class_init(ObjectClass *oc, void *data) { DeviceClass *dc = DEVICE_CLASS(oc); diff --git a/hw/mem/cxl_type3_stubs.c b/hw/mem/cxl_type3_stubs.c index f3e4a9fa72..482229f3bd 100644 --- a/hw/mem/cxl_type3_stubs.c +++ b/hw/mem/cxl_type3_stubs.c @@ -56,3 +56,9 @@ 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_event(const char *path, + struct CXLDCExtentRecordList *records, Error **errp) {} + +void qmp_cxl_release_dynamic_capacity_event(const char *path, + struct CXLDCExtentRecordList *records, Error **errp) {} diff --git a/include/hw/cxl/cxl_events.h b/include/hw/cxl/cxl_events.h index 089ba2091f..3baf745f8d 100644 --- a/include/hw/cxl/cxl_events.h +++ b/include/hw/cxl/cxl_events.h @@ -165,4 +165,20 @@ typedef struct CXLEventMemoryModule { uint8_t reserved[0x3d]; } QEMU_PACKED CXLEventMemoryModule; +/* + * Dynamic Capacity Event Record + * CXL Rev 3.0 Section 8.2.9.2.1.5: Table 8-47 + * All fields little endian. + */ +typedef struct CXLEventDynamicCapacity { + CXLEventRecordHdr hdr; + uint8_t type; + uint8_t reserved1; + uint16_t host_id; + uint8_t updated_region_id; + uint8_t reserved2[3]; + uint8_t dynamic_capacity_extent[0x28]; /* defined in cxl_device.h */ + uint8_t reserved[0x20]; +} QEMU_PACKED CXLEventDynamicCapacity; + #endif /* CXL_EVENTS_H */ diff --git a/qapi/cxl.json b/qapi/cxl.json index 05c560cfe5..fb04ec4c41 100644 --- a/qapi/cxl.json +++ b/qapi/cxl.json @@ -369,3 +369,52 @@ ## {'command': 'cxl-inject-correctable-error', 'data': {'path': 'str', 'type': 'CxlCorErrorType'}} + +## +# @CXLDCExtentRecord: +# +# Record of a single extent to add/release +# +# @region-id: id of the region where the extent to add/release +# @dpa: start dpa (in MiB) of the extent, related to region base address +# @len: extent size (in MiB) +# +# Since: 8.0 +## +{ 'struct': 'CXLDCExtentRecord', + 'data': { + 'region-id': 'uint8', + 'dpa':'uint64', + 'len': 'uint64' + } +} + +## +# @cxl-add-dynamic-capacity-event: +# +# Command to add dynamic capacity extent event +# +# @path: CXL DCD canonical QOM path +# @extents: Extents to add +# +## +{ 'command': 'cxl-add-dynamic-capacity-event', + 'data': { 'path': 'str', + 'extents': [ 'CXLDCExtentRecord' ] + } +} + +## +# @cxl-release-dynamic-capacity-event: +# +# Command to release dynamic capacity extent event +# +# @path: CXL DCD canonical QOM path +# @extents: Extents to release +# +## +{ 'command': 'cxl-release-dynamic-capacity-event', + 'data': { 'path': 'str', + 'extents': [ 'CXLDCExtentRecord' ] + } +} From patchwork Thu Jul 20 20:37:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "nifan@outlook.com" X-Patchwork-Id: 13321047 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 B9ECAEB64DD for ; Thu, 20 Jul 2023 20:38:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229685AbjGTUir (ORCPT ); Thu, 20 Jul 2023 16:38:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229785AbjGTUiq (ORCPT ); Thu, 20 Jul 2023 16:38:46 -0400 Received: from APC01-TYZ-obe.outbound.protection.outlook.com (mail-tyzapc01olkn2058.outbound.protection.outlook.com [40.92.107.58]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8E066271E for ; Thu, 20 Jul 2023 13:38:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FlDaaNdEGkltMSJ8F4vJWChgQyHScQ7BexnXmQq0K2n+asBIskHUSK5Z6q5kMvxUXROMwnzuWVD2eM0Z1Ev9nMTKquOsZx8eK/l+UXC/XtNfMm4us7pFv2pzq/N+6FMtf0TzXWr4F+tlhQXTF8SGYOZ1T9OafsjOzu6cFcoxtTNMDVRahb3cuXxF0vaMLVnD8B2RAd23KHt2CKlzet1oUm/SLe42uu4UIHLDerAM92nep8BT71DW4PnjmQoTMkNQ1SvqHuhKkwk1iTqqWWl+5psoGV00jm1IB1v+TnLH9s0fNQ+yfATitA9RgPD1BdYWrfz6nPtsPb8Ek3SSwdC6hQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Gsh8kP1EgJWpxeSgOgVo0+O5DAGAipoxDYWpKkWlfSA=; b=WS3y++p5SKmHACKqkx3qS0c2eymLf/awHOPhiAGifCwP5CoYzX4D+TyDGyFQk8cs9iy0KkJPRJVgBTopXtOZpH874+yCqGbUnN56mIwCK8JCjpxnZNi8Xhv6w/CQc/mqGDwuKXInSrozeMuHm3VfPHtCW7lv/FndvFFIqk6j/Bktt8mNnBu9WdqzkLlT7x5fkr4bV2BYgSAbRD6c+0XhbnyFeIBTbsCayy/qs1+dHXXwsf8yAieEJU8DF/f7xIyVRu6jdlFrhQ3n52x6rPT7AHe1XR5r4RqPANe22LQwr7aXC4YkKOj2JPTcplRKYw7KA6fE+Gs2EYM5zLpgrWaLGg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Gsh8kP1EgJWpxeSgOgVo0+O5DAGAipoxDYWpKkWlfSA=; b=UZ2/0PnKJFjGt94EN86uRjw1SKh1AcSu5XOvOwo6d4Tacd/Y+tGhdorQH09V4VXaUXGxoIWGwbfwmhQoTG+865Ip82Ed7sw4fvrcEFnbCIag2WdMsNaK15T02MIyGi3W+qbVu23Eyhx5hw14kbD1WM9Am9SzFuoovck64jxc5miC5ldLiL+hZyLSu1K9st3c4MovswmsFmTndamL+cGF3sgvngNILNN7QmbyBm2xh6uyj3yPtq5p7+Oj5JBsKLkR48Sm+vjj+c5ohbLTf2gm9aJekPUh1jKEx2MExVvMzATwgq8VKurSSa4cT5SgVdwbCO4GAg62i+rFatV094VC+Q== Received: from SG2PR06MB3397.apcprd06.prod.outlook.com (2603:1096:4:7a::17) by KL1PR0601MB4100.apcprd06.prod.outlook.com (2603:1096:820:24::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6609.24; Thu, 20 Jul 2023 20:38:33 +0000 Received: from SG2PR06MB3397.apcprd06.prod.outlook.com ([fe80::450:9c8c:9058:c94c]) by SG2PR06MB3397.apcprd06.prod.outlook.com ([fe80::450:9c8c:9058:c94c%5]) with mapi id 15.20.6609.024; Thu, 20 Jul 2023 20:38:33 +0000 From: nifan@outlook.com To: qemu-devel@nongnu.org Cc: jonathan.cameron@huawei.com, linux-cxl@vger.kernel.org, gregory.price@memverge.com, hchkuo@avery-design.com.tw, cbrowy@avery-design.com, ira.weiny@intel.com, dan.j.williams@intel.com, a.manzanares@samsung.com, dave@stgolabs.net, nmtadam.samsung@gmail.com, Fan Ni , Fan Ni Subject: [PATCH 9/9] hw/mem/cxl_type3: Add dpa range validation for accesses to dc regions Date: Thu, 20 Jul 2023 13:37:08 -0700 Message-ID: X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230720203708.25825-1-nifan@outlook.com> References: <20230720203708.25825-1-nifan@outlook.com> X-TMN: [qQh3J7BVfZZjI22LtyqYFNIiJcuDM0LM] X-ClientProxiedBy: BYAPR03CA0008.namprd03.prod.outlook.com (2603:10b6:a02:a8::21) To SG2PR06MB3397.apcprd06.prod.outlook.com (2603:1096:4:7a::17) X-Microsoft-Original-Message-ID: <20230720203708.25825-10-nifan@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SG2PR06MB3397:EE_|KL1PR0601MB4100:EE_ X-MS-Office365-Filtering-Correlation-Id: ecd02a43-139c-4f61-a922-08db896135f9 X-MS-Exchange-SLBlob-MailProps: quCBMN2EvO/qzAKd82WE1LuLgf/v/GCyTnXHa0xOAKujNjF/WtriZQzWycWlXTo22N0ZO2+HWeLpml0qDhHRs/60ayRrGSU+pJzrtU5Ys/ltqVlfrzdvzjtFRXH8OFP5VifuekEiWharz1r8MW5y8UGJ4HSMElVcrRHGpxVFmBZqvksu/XS0YxdYd6oSROzUymy4a1CeNim6uy8b6E8M5qT6wN/niNn5DQ78yoTstu9BJacfyYWvWzelUQEU2h+8ZoOKpWQ3ZL4MfYyRYql33KHxO376xaFLdfjwYds8fgQDhdxYeTwzqjaugoQgWStsBEkT5BPcsMoeWDO7z5NqAwI79RIsBg8W5/Rb2J0Ii5u3w0XuZu+gHUBreP4v4+rR3y5f830oiNurjBgAB70gNLhCPRP4TFlkdr/e/if5ZVldB9VRqrVZtkyHWJmxpQe6nid0kfdDqwAflYlGicA25wO6lF0O5dQqnn10+Qr4kqf2bltLeeXksjWwaNQEPvUYcZyJn7i7i9AN2dQ5RA8Ut8FMi1GxSie/bTiDnanaF1PKYQ3AMG7xyGR+aGKyZQsnv5a4FmzaiTsWuzso39vWv2Dnxeg0xbbhXzKR2TahCUV2J0G6Dti8bXC21jszqThZs5QuQvcA/LqlzpoSkdxSnEEfY100cBxqjyiQyp0bfpNjg8WAos65SIugEdyjVc/d1aIrie585i+hmakINjfsNA== X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: +4ulVeJUOwea+cd/6gt/TTBgdqI9Fy1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dkDwU6UzvXPiwq48Clio56utUWAh4ergAKcgJTDBzdECA6JtpaX9hqeR5Vo9TMkFZOIcsWGAGkXufwJM0k/QA9RFKNGZqWKSzn8z/u2k/WOqW102nf/PKMw18i80eEUBguErmWifUfwc7PGqvvPkeGWnIRhZx0GVVv3ZkICxOnddzrpeO4k91t9E1COqhPxPuGWSEr91Lv2FdZQUskhOoQfjPo6n1Y0TmdLgKjdHPM2i//iTaFuCuWUSiYfC/WfUaIxgvwL5oHw7KlFULh8AcYJKEiPybQBxB9fl2GYlo6wIP0L07SIaMpSD5F+LXvfiVFdhZUkyOoehl22i9iJyX49fGeo685vJa7fAb3Dn6XkCTTNtL0y9abAmMp71RrhUYXjTs8CyXEwhrTkfF0ssF/dX6YjEmD3a/EBQyUPu/E4ZTW5hIEYslRHIIIAx8emtIWvShn9orejLLRSNvWtKjwQXOwdJ3CrTms/fQ0hsmb3aw5ZfHIzpsdrgiTfJQMy7LcoR8zqnZlhJaEo5w8iT5xgW+FU+4H9gJXzmB5G/mcRW+zlXTv0a5WGohSaD3xSFdzksDCKB4SGJ8EJtlnI0saMHF0wtA2TGM25yuOaNglkarS3Ne/n1wcUdweKM/iJQeKThxSZEu8ksIV4wloSW23qP9SZIKoF02QdeWlDLBlKW/6K8AN9ZxanLrjBsTVxbclXGHQ8jO/dFzaQQbsojZWk4/lffWmBc0mM/zL62yrA5APOQNBaeGRI5zl64hVjKofzPtOBhHtU6goZyAGMNJvnyVGoLuMPsFiCPreOLu9QJlzY9Y371pqQ== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: ecd02a43-139c-4f61-a922-08db896135f9 X-MS-Exchange-CrossTenant-AuthSource: SG2PR06MB3397.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Jul 2023 20:38:01.6097 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: KL1PR0601MB4100 Precedence: bulk List-ID: X-Mailing-List: linux-cxl@vger.kernel.org From: Fan Ni Not all dpa range in the dc regions is valid to access until an extent covering the range has been added. Add a bitmap for each region to record whether a dc block in the region has been backed by dc extent. For the bitmap, a bit in the bitmap represents a dc block. When a dc extent is added, all the bits of the blocks in the extent will be set, which will be cleared when the extent is released. Signed-off-by: Fan Ni --- hw/mem/cxl_type3.c | 155 ++++++++++++++++++++++++++++++++++++ include/hw/cxl/cxl_device.h | 1 + 2 files changed, 156 insertions(+) diff --git a/hw/mem/cxl_type3.c b/hw/mem/cxl_type3.c index cb1f9182e6..e673287804 100644 --- a/hw/mem/cxl_type3.c +++ b/hw/mem/cxl_type3.c @@ -787,13 +787,37 @@ static int cxl_create_dc_regions(CXLType3Dev *ct3d) /* dsmad_handle is set when creating cdat table entries */ region->flags = 0; + region->blk_bitmap = bitmap_new(region->len / region->block_size); + if (!region->blk_bitmap) { + break; + } + region_base += region->len; } + + if (i < ct3d->dc.num_regions) { + while (--i >= 0) { + g_free(ct3d->dc.regions[i].blk_bitmap); + } + return -1; + } + QTAILQ_INIT(&ct3d->dc.extents); return 0; } +static void cxl_destroy_dc_regions(CXLType3Dev *ct3d) +{ + int i; + struct CXLDCD_Region *region; + + for (i = 0; i < ct3d->dc.num_regions; i++) { + region = &ct3d->dc.regions[i]; + g_free(region->blk_bitmap); + } +} + static bool cxl_setup_memory(CXLType3Dev *ct3d, Error **errp) { DeviceState *ds = DEVICE(ct3d); @@ -1021,6 +1045,7 @@ err_free_special_ops: g_free(regs->special_ops); err_address_space_free: if (ct3d->dc.host_dc) { + cxl_destroy_dc_regions(ct3d); address_space_destroy(&ct3d->dc.host_dc_as); } if (ct3d->hostpmem) { @@ -1043,6 +1068,7 @@ static void ct3_exit(PCIDevice *pci_dev) spdm_sock_fini(ct3d->doe_spdm.socket); g_free(regs->special_ops); if (ct3d->dc.host_dc) { + cxl_destroy_dc_regions(ct3d); address_space_destroy(&ct3d->dc.host_dc_as); } if (ct3d->hostpmem) { @@ -1053,6 +1079,110 @@ static void ct3_exit(PCIDevice *pci_dev) } } +/* + * This function will marked the dpa range [dpa, dap + len) to be backed and + * accessible, this happens when a dc extent is added and accepted by the + * host. + */ +static void set_region_block_backed(CXLType3Dev *ct3d, uint64_t dpa, + uint64_t len) +{ + int i; + CXLDCD_Region *region = &ct3d->dc.regions[0]; + + if (dpa < region->base + || dpa >= region->base + ct3d->dc.total_capacity) + return; + + /* + * spec 3.0 9.13.3: Regions are used in increasing-DPA order, with + * Region 0 being used for the lowest DPA of Dynamic Capacity and + * Region 7 for the highest DPA. + * So we check from the last region to find where the dpa belongs. + * access across multiple regions is not allowed. + **/ + for (i = ct3d->dc.num_regions - 1; i >= 0; i--) { + region = &ct3d->dc.regions[i]; + if (dpa >= region->base) { + break; + } + } + + bitmap_set(region->blk_bitmap, (dpa - region->base) / region->block_size, + len / region->block_size); +} + +/* + * This function check whether a dpa range [dpa, dpa + len) has been backed + * with dc extents, used when validating read/write to dc regions + */ +static bool test_region_block_backed(CXLType3Dev *ct3d, uint64_t dpa, + uint64_t len) +{ + int i; + CXLDCD_Region *region = &ct3d->dc.regions[0]; + uint64_t nbits; + long nr; + + if (dpa < region->base + || dpa >= region->base + ct3d->dc.total_capacity) + return false; + + /* + * spec 3.0 9.13.3: Regions are used in increasing-DPA order, with + * Region 0 being used for the lowest DPA of Dynamic Capacity and + * Region 7 for the highest DPA. + * So we check from the last region to find where the dpa belongs. + * access across multiple regions is not allowed. + */ + for (i = ct3d->dc.num_regions - 1; i >= 0; i--) { + region = &ct3d->dc.regions[i]; + if (dpa >= region->base) { + break; + } + } + + nr = (dpa - region->base) / region->block_size; + nbits = len / region->block_size; + return find_next_zero_bit(region->blk_bitmap, nbits, nr) >= nr + nbits; +} + +/* + * This function will marked the dpa range [dpa, dap + len) to be unbacked and + * inaccessible, this happens when a dc extent is added and accepted by the + * host. + */ +static void clear_region_block_backed(CXLType3Dev *ct3d, uint64_t dpa, + uint64_t len) +{ + int i; + CXLDCD_Region *region = &ct3d->dc.regions[0]; + uint64_t nbits; + long nr; + + if (dpa < region->base + || dpa >= region->base + ct3d->dc.total_capacity) + return; + + /* + * spec 3.0 9.13.3: Regions are used in increasing-DPA order, with + * Region 0 being used for the lowest DPA of Dynamic Capacity and + * Region 7 for the highest DPA. + * So we check from the last region to find where the dpa belongs. + * access across multiple regions is not allowed. + */ + for (i = ct3d->dc.num_regions - 1; i >= 0; i--) { + region = &ct3d->dc.regions[i]; + if (dpa >= region->base) { + break; + } + } + + nr = (dpa - region->base) / region->block_size; + nbits = len / region->block_size; + bitmap_clear(region->blk_bitmap, nr, nbits); +} + static bool cxl_type3_dpa(CXLType3Dev *ct3d, hwaddr host_addr, uint64_t *dpa) { uint32_t *cache_mem = ct3d->cxl_cstate.crb.cache_mem_registers; @@ -1145,6 +1275,10 @@ static int cxl_type3_hpa_to_as_and_dpa(CXLType3Dev *ct3d, *as = &ct3d->hostpmem_as; *dpa_offset -= vmr_size; } else { + if (!test_region_block_backed(ct3d, *dpa_offset, size)) { + return -ENODEV; + } + *as = &ct3d->dc.host_dc_as; *dpa_offset -= (vmr_size + pmr_size); } @@ -1938,6 +2072,27 @@ static void qmp_cxl_process_dynamic_capacity_event(const char *path, } g_free(extents); + + /* Another choice is to do the set/clear after getting mailbox response*/ + list = records; + while (list) { + dpa = list->value->dpa * 1024 * 1024; + len = list->value->len * 1024 * 1024; + rid = list->value->region_id; + + switch (type) { + case DC_EVENT_ADD_CAPACITY: + set_region_block_backed(dcd, dpa, len); + break; + case DC_EVENT_RELEASE_CAPACITY: + clear_region_block_backed(dcd, dpa, len); + break; + default: + error_setg(errp, "DC event type not handled yet"); + break; + } + list = list->next; + } } void qmp_cxl_add_dynamic_capacity_event(const char *path, diff --git a/include/hw/cxl/cxl_device.h b/include/hw/cxl/cxl_device.h index 5bf1dd4024..40ae96d824 100644 --- a/include/hw/cxl/cxl_device.h +++ b/include/hw/cxl/cxl_device.h @@ -411,6 +411,7 @@ typedef struct CXLDCD_Region { uint64_t block_size; uint32_t dsmadhandle; uint8_t flags; + unsigned long *blk_bitmap; } CXLDCD_Region; struct CXLType3Dev {