[{"id":3683410,"web_url":"http://patchwork.ozlabs.org/comment/3683410/","msgid":"<a19adcf8-de59-4c34-8e19-0234fa8e68d1@linaro.org>","list_archive_url":null,"date":"2026-04-28T11:54:53","subject":"Re: [PATCH] hw/i3c/dw-i3c: Fix incorrect BCR/DCR extraction during\n ENTDAA","submitter":{"id":85046,"url":"http://patchwork.ozlabs.org/api/people/85046/","name":"Philippe Mathieu-Daudé","email":"philmd@linaro.org"},"content":"Hi Ashish,\n\nOn 28/4/26 12:25, Ashish Anand wrote:\n> The target_info union in dw_i3c_addr_assign_cmd() declares pid, bcr,\n> and dcr as separate union members, causing them to all alias b[0]\n> rather than their correct positions in the ENTDAA response buffer.\n> This results in dw_i3c_update_char_table() being called with BCR and\n> DCR both read from b[0] instead of b[6] and b[7] respectively,\n> corrupting the device characteristics table on every ENTDAA operation.\n> \n> Fixed this by replacing the broken members with a nested struct using\n> uint8_t fields, matching the I3C spec wire format: six bytes of PID\n> followed by BCR and DCR.\n> \n> Signed-off-by: Ashish Anand <ashish.a6@samsung.com>\n> ---\n> \n> The nested struct approach avoids bitfields and __attribute__((packed)),\n> both of which introduce implementation-defined behavior for this layout.\n> \n> This bug was discovered during end-to-end ENTDAA testing where BCR and\n> DCR values observed in the char table register did not match the target's\n> actual BCR and DCR values.\n> \n> A follow-up patch adding a standalone DW I3C test machine and qtest\n> coverage for ENTDAA, private transfers, and IBI is planned.\n> \n>   hw/i3c/dw-i3c.c | 17 +++++++++++------\n>   1 file changed, 11 insertions(+), 6 deletions(-)\n> \n> diff --git a/hw/i3c/dw-i3c.c b/hw/i3c/dw-i3c.c\n> index d87d42be89..1c5e09ccbb 100644\n> --- a/hw/i3c/dw-i3c.c\n> +++ b/hw/i3c/dw-i3c.c\n> @@ -1507,9 +1507,11 @@ static void dw_i3c_addr_assign_cmd(DWI3C *s, DWI3CAddrAssignCmd cmd)\n>       for (i = 0; i < cmd.dev_count; i++) {\n>           uint8_t addr = dw_i3c_target_addr(s, cmd.dev_index + i);\n>           union {\n\n                uint64_t d;\n\n> -            uint64_t pid:48;\n> -            uint8_t bcr;\n> -            uint8_t dcr;\n> +            struct {\n> +                uint8_t pid[6];\n> +                uint8_t bcr;\n> +                uint8_t dcr;\n> +            };\n>               uint32_t w[2];\n>               uint8_t b[8];\n>           } target_info;\n> @@ -1544,9 +1546,12 @@ static void dw_i3c_addr_assign_cmd(DWI3C *s, DWI3CAddrAssignCmd cmd)\n>               err = DW_I3C_RESP_QUEUE_ERR_DAA_NACK;\n>               break;\n>           }\n> -        dw_i3c_update_char_table(s, cmd.dev_index + i,\n> -                                            target_info.pid, target_info.bcr,\n> -                                            target_info.dcr, addr);\n> +        uint64_t pid = 0;\n> +        for (int j = 0; j < 6; j++) {\n> +            pid |= (uint64_t)target_info.pid[j] << (j * 8);\n\nDirectly use .b[] instead of .pid[]?\n\n> +        }\n\nOr (untested):\n\n            dcr = target_info.b[0];\n            bcr = target_info.b[1];\n            pid = extract64(be64_to_cpu(target_info.d), 16, 48);\n\nor:\n            pid = be64_to_cpu(target_info.d) >> 16;\n\n> +        dw_i3c_update_char_table(s, cmd.dev_index + i, pid, target_info.bcr,\n> +                                 target_info.dcr, addr);\n>   \n>           /* Push the PID, BCR, and DCR to the RX queue. */\n>           dw_i3c_push_rx(s, target_info.w[0]);","headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256\n header.s=google header.b=wTqZFlBV;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org\n (client-ip=209.51.188.17; helo=lists1p.gnu.org;\n envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n receiver=patchwork.ozlabs.org)"],"Received":["from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17])\n\t(using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4g4f5c6mW4z1xrS\n\tfor <incoming@patchwork.ozlabs.org>; Tue, 28 Apr 2026 21:55:47 +1000 (AEST)","from localhost ([::1] helo=lists1p.gnu.org)\n\tby lists1p.gnu.org with esmtp (Exim 4.90_1)\n\t(envelope-from <qemu-devel-bounces@nongnu.org>)\n\tid 1wHh1p-0001Rq-Hn; Tue, 28 Apr 2026 07:55:03 -0400","from eggs.gnu.org ([2001:470:142:3::10])\n by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)\n (Exim 4.90_1) (envelope-from <philmd@linaro.org>) id 1wHh1n-0001RK-Qf\n for qemu-devel@nongnu.org; Tue, 28 Apr 2026 07:54:59 -0400","from mail-wr1-x431.google.com ([2a00:1450:4864:20::431])\n by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)\n (Exim 4.90_1) (envelope-from <philmd@linaro.org>) id 1wHh1l-0006JQ-Tq\n for qemu-devel@nongnu.org; Tue, 28 Apr 2026 07:54:59 -0400","by mail-wr1-x431.google.com with SMTP id\n ffacd0b85a97d-43cfce3a195so6446143f8f.2\n for <qemu-devel@nongnu.org>; Tue, 28 Apr 2026 04:54:56 -0700 (PDT)","from [192.168.69.210] (88-187-86-199.subs.proxad.net.\n [88.187.86.199]) by smtp.gmail.com with ESMTPSA id\n ffacd0b85a97d-4463d02f2a2sm6039790f8f.10.2026.04.28.04.54.53\n (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128);\n Tue, 28 Apr 2026 04:54:54 -0700 (PDT)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=linaro.org; s=google; t=1777377295; x=1777982095; darn=nongnu.org;\n h=content-transfer-encoding:in-reply-to:from:references:cc:to\n :content-language:subject:user-agent:mime-version:date:message-id\n :from:to:cc:subject:date:message-id:reply-to;\n bh=xew8rzhK4aE0pcnoV3Ux+s3LBwNRczYRxhIXYQRW+JQ=;\n b=wTqZFlBVfgzz3NuDAeLuxrlRhdmzBntq1WHDZx54RIGN2zsp6iHLEzYsKt9dPOyX2I\n jAjO3Mu81Ja9Jl1Xp5O0lRM5f9cSbcl1331JzCRHEJbldiGPg7UP54YoI6qwh6ZzbR9J\n rfsRL3BcU1d3JIMZhKS9Q9vk8D60Iy4qfd/OLLkZexO6EqUuMjayWo5bQExtuQYkL4Fk\n uMqArIqFO1wkzgfJ01NJwY33N4kD0hIyBZtKzYcwdKSvx1McjBUy+4EMNQcrkX9tyt9j\n XcwwwDStE6/EU8NPnnRhyhu6Qsw5NVjFtruwe8VSJ4EJ3Cmn/PSh4BegMaWYAKn0+4YZ\n uSTA==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1777377295; x=1777982095;\n h=content-transfer-encoding:in-reply-to:from:references:cc:to\n :content-language:subject:user-agent:mime-version:date:message-id\n :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id\n :reply-to;\n bh=xew8rzhK4aE0pcnoV3Ux+s3LBwNRczYRxhIXYQRW+JQ=;\n b=S3ShOB90Fn30obnMu+ne1q1TznuSvZ4KfA8Lkn8nx6I19ja/esCfOr9JhyVWSY5Cbi\n oQ+MNPtgMRZhwXnMyVHKqT/PEnQLeQLIXaf4hkpICMmGqM6UfBcHFDmsSzhh1qM/HNh3\n mNBuBIMnz242/18qsptSKe2w6XCZnI6mRx78ncDh/n0ynSE7sElvvZn2UFXWGDcM15XZ\n MTkIzAdtGYROCmVemfrgYDrMrNNORnR6zEBi0nnrrmu7bWwjtYNcEY4LJraHKYtGuST2\n xWoPO8H/0UVP5DcPFiiT7N7U2DrQwQZXKyur18tBZxI8uBEmrx8w6QAUwas7Fge3tCoo\n 69LA==","X-Forwarded-Encrypted":"i=1;\n AFNElJ91AX6YpEUr7BPLDjX3D0vswHhon6I+Hyx0v12Cc3U2imYRKt+YjP9VuX9UFzfrUVU5zvTM6qcYHAOI@nongnu.org","X-Gm-Message-State":"AOJu0YzYNT0RlPTSvRc2Y0hUYz+0cLfp5DFmLhOvVR4sRHMW4jb1XdnG\n 0n1uVEd2KdEDMfZqwyPo4y2y6/SneHu84F1Hjcwn77RCtDO1SBi1xLE8om3yy5U2z+s=","X-Gm-Gg":"AeBDieueuADaR2iYFT/UDwPewxcd/+SJD8+PbSec3xuZL+9nZ156yJ6PCaTQidFhKQZ\n f/9HeZjNXutQ73DID/Ait5gqKTwjbt+Gi4BB+tFYZ9ehtQ1XPbAR9B9i/GkWUK/W5kW9ky8qA+w\n GmoObETFdG43ZBYT8kVKTj4iCxMoMuvL69auGv8bpPi/yw+V0o5ESHehHJ6Y/VN5wd3Ls3ahooi\n hjmhSouNrT+5c8qvBcf8nh97qOz6mlFvJj7krSWo/UIL7QIS1Vwv3Nlj7Ll5v8q7vXR5mMmio8d\n x6MsPmfQmaiei3I6MiMPj0ocBHJRjRwxwRrR7JPI4plIvSyNKzqefFE7OoobpEOVTRATRZOZY7u\n CU1xkoPKM1MNLyFui3M1HMr5iPzSIDzG2vGC00v5iVQZsMsmkbRHVCooJIjWjOITT8iYEmvEW5W\n j7k6h7scTjrcjV0Ca2cBO/4gk7vPToV3khFJWgop2gtb/jFn82D5qcQDLC5DcgUvyCSW5W0kmmG\n oz3","X-Received":"by 2002:a5d:5c84:0:b0:43f:e990:2f5d with SMTP id\n ffacd0b85a97d-44649ba18ffmr5036283f8f.35.1777377294856;\n Tue, 28 Apr 2026 04:54:54 -0700 (PDT)","Message-ID":"<a19adcf8-de59-4c34-8e19-0234fa8e68d1@linaro.org>","Date":"Tue, 28 Apr 2026 13:54:53 +0200","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [PATCH] hw/i3c/dw-i3c: Fix incorrect BCR/DCR extraction during\n ENTDAA","Content-Language":"en-US","To":"Ashish Anand <ashish.a6@samsung.com>, qemu-devel@nongnu.org","Cc":"komlodi@google.com, clg@kaod.org, jamin_lin@aspeedtech.com,\n nabihestefan@google.com, saurabh@samsung.com, vishwa.mg@samsung.com,\n y.kaushal@samsung.com, ashish.anand202@gmail.com","References":"\n <CGME20260428102910epcas5p3980610701ef7374b681f74d75bc34f29@epcas5p3.samsung.com>\n <20260428102503.1641162-1-ashish.a6@samsung.com>","From":"=?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= <philmd@linaro.org>","In-Reply-To":"<20260428102503.1641162-1-ashish.a6@samsung.com>","Content-Type":"text/plain; charset=UTF-8; format=flowed","Content-Transfer-Encoding":"7bit","Received-SPF":"pass client-ip=2a00:1450:4864:20::431;\n envelope-from=philmd@linaro.org; helo=mail-wr1-x431.google.com","X-Spam_score_int":"-20","X-Spam_score":"-2.1","X-Spam_bar":"--","X-Spam_report":"(-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1,\n DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,\n RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001,\n SPF_PASS=-0.001 autolearn=ham autolearn_force=no","X-Spam_action":"no action","X-BeenThere":"qemu-devel@nongnu.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"qemu development <qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<https://lists.nongnu.org/archive/html/qemu-devel>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n <mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org"}}]