From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=40.93.194.7 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796110371; b=3hktvcGCp+M7N6GDNXtwFDOjk224b3Xkvn5M4AoTT0h152xJ/kIR+8j873ZIfjT8DF6/ /Ibb5dVTpkvXMrV6q1b7kDGwVye1Yj+zOuJ0WNlUdKGOyOLd4LzzwpnRuPZzN/i+5RC1D 6gDm4685T9O4TlJykwk7fcSBWlh2StEpXhAy/UF8Fe8Y5fYOhIbu0UIIfXUViz5EuL+qX sni48Ic3ILFOE3DAal47niDunesIIYWWjyJSs6hN4HQjhHrTHB9+lcIZOLrQyOzvGVa57 qWVL4daeMlgmd43yPKQ5CIYN+x9cN0j87CO+m/TAUbXBtC4R+aAZnYQxKDWOuu3bt+w== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796110371; h=DMARC-Filter:DKIM-Signature:Received:Received:Message-ID:Date: User-Agent:Subject:To:Cc:References:Content-Language:From:In-Reply-To: Content-Type:X-ClientProxiedBy:MIME-Version:X-MS-PublicTrafficType: X-MS-TrafficTypeDiagnostic:X-MS-Office365-Filtering-Correlation-Id: X-MS-Exchange-AtpMessageProperties:X-MS-Exchange-SenderADCheck: X-MS-Exchange-AntiSpam-Relay:X-Microsoft-Antispam: X-Microsoft-Antispam-Message-Info:X-Forefront-Antispam-Report: X-MS-Exchange-AntiSpam-MessageData-ChunkCount: X-MS-Exchange-AntiSpam-MessageData-0:X-OriginatorOrg: X-MS-Exchange-CrossTenant-Network-Message-Id: X-MS-Exchange-CrossTenant-AuthSource:X-MS-Exchange-CrossTenant-AuthAs: X-MS-Exchange-CrossTenant-OriginalArrivalTime: X-MS-Exchange-CrossTenant-FromEntityHeader: X-MS-Exchange-CrossTenant-Id:X-MS-Exchange-CrossTenant-MailboxType: X-MS-Exchange-CrossTenant-UserPrincipalName: X-MS-Exchange-Transport-CrossTenantHeadersStamped; bh=olC1+O21J7O3trIIHLoY12JQniVopA9lA3Si02N+AcA=; b=Hv5Kqd/spkJncjBQpU0FWFf6z+FPbXFmiaYXrTgzyRKWNERhZC+/NCl23BJGlxyh7vCI AW0dYtnbkwuiW58mHoFWwgwbVc0Sjm6pdNvalZaaFGeucw5kwDjT2GbE7G6/H72xC/YQ+ MJDA/LZbtHeNPwBEEZTO7BuXtiK15pBJXp/jG2LEqxwnnpm5HcOHR5569rHbop+duDg56 cSoO8+FitAzDhg+PASfLzPO1n/q0PCvpDSGFtnVRzYrp0vEhOrPX5wW6OjhBN6JaKC0Gt aWBFKR5uUlP7Q22OF8meVGS2G9mtQAjo+JaFeDMAAemIsKAs9ZxN0xBWY/gjPM2EY5g== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass header.from=altera.com; spf=pass smtp.mailfrom=altera.com; dkim=pass header.d=altera.com header.i=@altera.com header.a=rsa-sha256 header.s=selector2 header.b=juTYO+oS; arc=pass header.oldest-pass=0 smtp.remote-ip=40.93.194.7 Received: from SN4PR0501CU005.outbound.protection.outlook.com (mail-southcentralusazon11011007.outbound.protection.outlook.com [40.93.194.7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (secp384r1) server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 37D34606A329; Tue, 1 Dec 2026 07:32:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 37D34606A329 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=altera.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=altera.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=altera.com header.i=@altera.com header.a=rsa-sha256 header.s=selector2 header.b=juTYO+oS ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=BobxGeil8VmSeQwsVTd65cEkvytQwXZLgw4alEMbXxrkTkc8HBA5yESHlRNCQwpQLwmu5vM/gRIDuMRBAYboP41maPOhuurxAurqA8yyo40ARwLOin4WJ3MIb6ev8+mfCtF6qUccZYqbJNWp0zJB13pIvlYV02ksDJn2BqlRir7Ik0UNbkKnr2p883uif118qjPWgxg3iF3xFtdKVMhlbbbV9jSAof5SoUYERdgC7oHiOX8uN/zorBvhcuZutL7E4wh+nO2B0a+R86QjY4hz+aYIWiE1FudLZ5MjG4T8DXsfIWkhczlDSQ+YdCNm+n7HXgI8/cR16ah2AcZH7VGgSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=olC1+O21J7O3trIIHLoY12JQniVopA9lA3Si02N+AcA=; b=gEl6Qzwj93+keKuyFLCIfBLMofuqa8YDm6WuSy2inP8Oe2yahkS+ncWoDxt9K/ibpKkGEK9b67fu+ysKqoWV5qn/rVsRVtEIcjg3FLHScq8DqvPL1dfof3Eax5+hS5nSyCROaacGWbtEoayWWNKsF6I+7xjrRloCzCmrD+cVHVrn3DibNVNItFXHds+PeVBbor5j/FUmO1oCGIbuSRe06/JpKvhTYzMNglNsTP63YQiUz6du3EDaWZzum5CL3f0ACxq7EVBPetD0deJh8ZwKQ2LPCBD6hJtmpXEXSErKXb0o+kFCov1Fam/VYrtcBJSxyoHlLgA3gMIFkDFnwE4S7A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=altera.com; dmarc=pass action=none header.from=altera.com; dkim=pass header.d=altera.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=altera.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=olC1+O21J7O3trIIHLoY12JQniVopA9lA3Si02N+AcA=; b=juTYO+oSrGrGM9wBPZoUAf3L8qRgr/9EIl4wbs3GE7qwRZ5JnioieIC/fYm7iW6GAm/RhDsjHdKB0mrIZgxLLcXoH38XaQf2uFSkrl+GBbzn9ugWI4WSQoWQblp4W5Bxm8xqv8fiymTxONbnR0aSLOxgwelKsVH9wj8O8+wis929f2RDFiX241wqNo/ueb1KAXt7+t4ITG4Z+FA4ljWVb4H2FnroPwy4bAP17+ch0yPqwcCtH+Z1RxG5k8FOq4+GJGyKT/7Gi2mFOaUdKk9VP+vjspRXj4zODqG8Zuuq2C2bbVGbeiSj69wW+GpTJANfCS+pKxhjLUOrX3/KB/k8tg== Authentication-Results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=altera.com; Received: from SJ0PR03MB5950.namprd03.prod.outlook.com (2603:10b6:a03:2d3::20) by LV3PR03MB7564.namprd03.prod.outlook.com (2603:10b6:408:28d::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.662.13; Tue, 1 Dec 2026 07:32:45 +0000 Received: from SJ0PR03MB5950.namprd03.prod.outlook.com ([fe80::53a0:bf93:6b6b:de01]) by SJ0PR03MB5950.namprd03.prod.outlook.com ([fe80::53a0:bf93:6b6b:de01%3]) with mapi id 15.21.0662.007; Tue, 1 Dec 2026 07:32:44 +0000 Message-ID: <17e00dfd-c744-45e3-aba9-e404210bc481@altera.com> Date: Tue, 1 Dec 2026 15:32:38 +0800 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2] fpga: altera-cvp: Handle truncated bitstream with padding buffer To: Xu Yilun Cc: Moritz Fischer , Xu Yilun , Tom Rix , linux-fpga@vger.kernel.org, linux-kernel@vger.kernel.org References: <3c1bb384cb9cd5bb35b3c7e68a4feab95ef4ad60.1794987679.git.tze.yee.ng@altera.com> Content-Language: en-US From: "NG, TZE YEE" In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed X-ClientProxiedBy: SG2P153CA0054.APCP153.PROD.OUTLOOK.COM (2603:1096:4:c6::23) To SJ0PR03MB5950.namprd03.prod.outlook.com (2603:10b6:a03:2d3::20) X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR03MB5950:EE_|LV3PR03MB7564:EE_ X-MS-Office365-Filtering-Correlation-Id: 33693809-0e23-41da-7b0b-08df4f7d4a48 X-MS-Exchange-AtpMessageProperties: SA X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|1800799024|366016|23010399003|11063799006|5023799004|4143699003|6133799003|261009223027099003|22082099003|18002099003|55112099003|4133799003|10067099003|261026140227099003|56012099006|261102123227099003|261026121527099003|261028144727099003|261021135927099003|261026135527099003|261021123027099003|261022105027099003|261021121427099003|261021130227099003|261021133027099003|261026130827099003|261022075727099003|261022115727099003|261022113327099003; X-Microsoft-Antispam-Message-Info: 4yQBsT9YWPFDWm+4H9kDXy8iwVI2ye0KbBlPUHllVDkj/3rgR0l4K7paJwqGEHzCNz7QubtZ3MKkrztt/ydujhibYhmLAM4yQ0ZVy09i5e8RVWKAhUUmEO3ubUBuzKHxAyY0VkuX8YalEqDEGNMl+b7A4QKVY/LkO+PFKUL/mzjylSMg3H77sN5yhC0pytN3by9Fp3xBW3wn70bKGJaF/KiNByKUp6xE4MplQ/XWQduuE/6y2sEkN0ybSerApsdxET+rLFQOyE4Xj/F01dHwbk9+y28GA4k+bHwFeZD9cYONxoi26fU6kwOQxkmJ1PYw3LbPKfLfxfwcu1g3K5xERllNNAGMbCaCtalNbuwelsGan4WybMRGJVqayPgEu4j+iBdn+czUlgbO2pgOrna9FeAx2aLcOd1o3sQz77TTM14QSNdwE+CoxRt3h6mtOGGPaqJRMNfSyRDRlSF5BvYTIbK2mOBfW2hjUHBlnC1bWJDbB6pyrp2VI2FkhLBz7S9Tfpe1cI63S7by+E7iXwlgKDaQQb9Yk5LKo1RsZrLnBG+owTqvFm3kyAf490zeZmx0aYZ20QsjY7J/Ryd/XHnn+KPTCSlyY3Tak+cCQL+li9Q= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SJ0PR03MB5950.namprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(376014)(1800799024)(366016)(23010399003)(11063799006)(5023799004)(4143699003)(6133799003)(261009223027099003)(22082099003)(18002099003)(55112099003)(4133799003)(10067099003)(261026140227099003)(56012099006)(261102123227099003)(261026121527099003)(261028144727099003)(261021135927099003)(261026135527099003)(261021123027099003)(261022105027099003)(261021121427099003)(261021130227099003)(261021133027099003)(261026130827099003)(261022075727099003)(261022115727099003)(261022113327099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?Y1FYQlkyUU1SMzlDdlZ3V2N1SDN4MTJGU0orcFFHT1g0WlliWmhIVEJkaWJa?= =?utf-8?B?c2hUNGk1OXZja2E2WkhNTWF3TWpCVGszNmFyQldHOTd1blliYnhXN0FHVWFt?= =?utf-8?B?bDI4UEpiYnU5ZGRuMlM1aGprRStud1hsa2FEeHdzUzM3T3NQcEtqUFJKWUp3?= =?utf-8?B?Mmw4YnpWSmNJVE44cXhXdnVRMXYwbUxwNkJFS2loNWovN2dETVl1dXVlSmRC?= =?utf-8?B?MlRBZ21XWlZISUFVZmdNOG43eFVQTWg0RnNwL2Q3Q2lKeUtVWW81OWtrM3pl?= =?utf-8?B?V1RlL3NESTZDYXdHakZnQXArQ1ozaWdMVVhnTXFtbHZM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FT0pSdWhzcEdVaXlSZWFGaWpobFVPVm9DSWtSeWJFSGFM?= =?utf-8?B?YWJONm5md2NQZzBTTTJYWGxWN2xWZGtlMG80TFZ1VzR2UUc2M0pRYWRkYlEr?= =?utf-8?B?NmdPM3p6YUV5NzZ6QTYyRE16RjRRQlA4S2dMQUJvTUQwK25NczV4TGs2OWxq?= =?utf-8?B?QVpaY05meHMrTHp4b1ZEOGZETUkwTUxlSTUvQUlQcks3M0g5TmJQZz09?= X-OriginatorOrg: altera.com X-MS-Exchange-CrossTenant-Network-Message-Id: 33693809-0e23-41da-7b0b-08df4f7d4a48 X-MS-Exchange-CrossTenant-AuthSource: SJ0PR03MB5950.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Dec 2026 07:32:44.8111 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: fbd72e03-d4a5-4110-adce-614d51f2077a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 8bAKgXx03ST/6T9nJEIWHhTtwn+Yv9XhPmf+GlkQ3oj/M2l11F3DHJX6sxY1jRZHRbXW0sEDhtt09hy/0dwg9Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV3PR03MB7564 Hi Yilun, Thanks for the review. On 28/11/2026 10:15 pm, Xu Yilun wrote: > On Wed, Nov 18, 2026 at 03:43:15PM +0800, tze.yee.ng@altera.com wrote: >> From: Nazim Amirul >> >> The AIB CvP firmware requires a minimum transfer size of 4096 bytes. >> When a bitstream smaller than this is sent, the firmware DMA engine > > Only when < 4096? E.g. if a bitstream is 4096 + 1, it is good? > No, the log was wrong. The CvP firmware moves data in 4096-byte blocks, one per TX credit, and requires the host to send exactly 4096 bytes per block. The driver sends the last block with only the remaining bytes, so any image whose size is not a multiple of 4096 stalls on the last block, 4096 + 1 included. I'll correct this in v3. >> stalls waiting for the remaining data, causing a hang. >> >> Allocate a 4096-byte send_buf at probe time and copy host data into >> it before each block transfer, ensuring the full block size is always >> sent regardless of the actual data length. Also improve error >> detection in write_complete() by checking VSE_CVP_STATUS_CFG_ERR >> instead of VSE_UNCOR_ERR_CVP_CFG_ERR to catch truncated or >> mismatched bitstream errors. > > What VSE_CVP_STATUS_CFG_ERR checks? and what VSE_UNCOR_ERR_CVP_CFG_ERR > checks? why it is an improvement? Please specify in log. > VSE_UNCOR_ERR_CVP_CFG_ERR (CVP_CONFIG_ERROR_LATCHED) is a sticky RW1CS copy of CVP_CONFIG_ERROR, set whenever CVP_CONFIG_ERROR rises in CvP mode. The driver never clears it, so after one failed configuration every later attempt is reported as failed, even with a good image. On newer devices it is also only reported on PCIe port 0. VSE_CVP_STATUS_CFG_ERR (CVP_CONFIG_ERROR) is driven by the configuration firmware, which keeps it set until the next configuration starts, so it is still valid in write_complete(). Since the latched bit is only a sticky copy of it, checking CVP_CONFIG_ERROR covers every error the latched bit reports. I'll explain this in the v3 log. >> >> Signed-off-by: Nazim Amirul >> Signed-off-by: Tze Yee Ng >> --- >> Note: I am taking over this patch from Nazim Amirul, who is no longer >> working on it. Nazim is kept as the author. >> >> Changes in v2: >> - Rebase from linux-fpga/for-next without code changes. > > I'm wondering if you agree with all his code/log so you don't change, or > you just wait for me to find all the issues anyway. > That's fair. I should have reviewed the patch properly before resending it instead of only rebasing it. I've gone through it now and reworked it as described below. >> >> v1: https://lore.kernel.org/all/20260619040811.20038-1-muhammad.nazim.amirul.nazle.asmade@altera.com/ >> --- >> drivers/fpga/altera-cvp.c | 18 +++++++++++++----- >> 1 file changed, 13 insertions(+), 5 deletions(-) >> >> diff --git a/drivers/fpga/altera-cvp.c b/drivers/fpga/altera-cvp.c >> index 103446465e0c..c9357cbe7fc0 100644 >> --- a/drivers/fpga/altera-cvp.c >> +++ b/drivers/fpga/altera-cvp.c >> @@ -82,6 +82,7 @@ struct altera_cvp_conf { >> u8 numclks; >> u32 sent_packets; >> u32 vsec_offset; >> + u8 *send_buf; >> const struct cvp_priv *priv; >> }; >> >> @@ -518,7 +519,9 @@ static int altera_cvp_write(struct fpga_manager *mgr, const char *buf, >> } >> >> len = min(conf->priv->block_size, remaining); >> - altera_cvp_send_block(conf, data, len); >> + memcpy(conf->send_buf, data, len); > > So you copied the whole bitstream just because of some bytes of unalignment? > Agreed, that was unnecessary. The copy was there so the last block could be sent at full length without reading past the end of the image. It also meant the last block was padded with leftover data from the previous block rather than zeros. v3 drops it: full blocks are written directly from the image buffer, and the last short block is completed with zero words in altera_cvp_send_block(), so nothing is read beyond the data. V1 devices use a 4-byte block size and are not affected. > Frankly speaking, I really think the image or the firmware should fix, > you can't produce a image that the FW can't handle. > The firmware side has been fixed: when the host terminates early, the firmware now completes the session, reports CVP_CONFIG_ERROR, and accepts a new configuration afterwards. But the CvP host interface requires every block to be exactly 4096 bytes, and the driver currently breaks that rule for the last block. With full blocks, a truncated image is rejected with CVP_CONFIG_ERROR and a good image can be loaded afterwards. Without them, the firmware is left waiting for the rest of the last block and the device cannot be reconfigured. A truncated or corrupted image is input the driver can't rule out, so it should report an error rather than leave the device stuck. >> + altera_cvp_send_block(conf, (const u32 *)conf->send_buf, >> + conf->priv->block_size); >> data += len / sizeof(u32); >> done += len; >> remaining -= len; >> @@ -557,10 +560,10 @@ static int altera_cvp_write_complete(struct fpga_manager *mgr, >> if (ret) >> return ret; >> >> - /* STEP 16 - check CVP_CONFIG_ERROR_LATCHED bit */ >> - altera_read_config_dword(conf, VSE_UNCOR_ERR_STATUS, &val); >> - if (val & VSE_UNCOR_ERR_CVP_CFG_ERR) { >> - dev_err(&mgr->dev, "detected CVP_CONFIG_ERROR_LATCHED!\n"); >> + /* STEP 16 - check CVP_CONFIG_ERROR bit */ >> + ret = altera_read_config_dword(conf, VSE_CVP_STATUS, &val); >> + if (ret || (val & VSE_CVP_STATUS_CFG_ERR)) { >> + dev_err(&mgr->dev, "CVP_CONFIG_ERROR!\n"); > > Why we don't check the ret before and now we do check? Why there are > many other reads that don't check? > > And I find nearly exact the same 5 lines, any reason to duplicate them. > There was no good reason to open-code it. The lines duplicate altera_cvp_chk_error(), so v3 calls that helper instead. The helper treats a failed read as an error, as it already does for the checks in write(). That makes no practical difference here, because a failed config read returns all ones, so the error bit would read as set anyway. I've left the other reads as they are, since changing them is unrelated to this fix. I'll send out v3 later. Thanks, Tze Yee >> return -EPROTO; >> } >> >> @@ -729,6 +732,11 @@ static int altera_cvp_probe(struct pci_dev *pdev, >> >> pci_set_drvdata(pdev, mgr); >> >> + conf->send_buf = devm_kzalloc(&pdev->dev, conf->priv->block_size, GFP_KERNEL); >> + if (!conf->send_buf) { >> + ret = -ENOMEM; >> + goto err_unmap; >> + } >> return 0; >> >> err_unmap: >> -- >> 2.43.7 >> >>