From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=198.175.65.12 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796216382; b=uxmAvI2ZxKHdLHZ1+7GkJmoyhOmDkM+UCtjkeuNrV7b2hhGJ5oOBBGRmuFr+IDQQMWRb MtW3Dm0br3Ru8svMa1k/tKtYVkCv3xblNCvdW5d3cpmFdeN5ofv+igkQqNg5VgnJSjGoU 6TKBoJagRd0eBgq2Mgw/lcVHPIJ2VJNqeSP1ZP6zQrfmcXSUQO6XF6IPN4EPwD4NcTidG NsbM/hjHanl/2GwKd1EpYJUzMhQAsRftAr6nqhJeiB+qbRorwgrsEvOL2oghif/TQ75pr YZMo5VZilTCqzoGwjcoL5A9rDFHBk7s8ltGEh3SZ0nCs1nnW1HGXP342zR6rIkFykGg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796216382; h=DMARC-Filter:DKIM-Signature:X-CSE-ConnectionGUID:X-CSE-MsgGUID: X-IronPort-AV:X-IronPort-AV:Received:X-CSE-ConnectionGUID: X-CSE-MsgGUID:X-ExtLoop1:X-IronPort-AV:Received:Date:From:To:Cc: Subject:Message-ID:References:MIME-Version:Content-Type: Content-Disposition:In-Reply-To; bh=owEpxqGKzoGGpMagmbclQsL8s36T+Z0mmLXMV8Q7rMU=; b=L8FGs4604GR5sO8ZcpdnDvCVhT2n+6MknLMWnWtMSpOAB4KNzoWFuFZUsvMs3iEqltBW 0LXJlyc1rDyDrmnmBvZSs/CW3SecMAg8RANBoIJdJwJciJLgqiBLyDs7RXovRrz5PqpyG rCc9bmKJOJv3ac3XmVqh7C36GIDmzfAeWFhMctAf9l9BWduXXXAkbEU9nkvKHN+f/skU9 xHdRKp8OnwqyE9XjEMMtGiAKP+p+izlNDoAlqYuisHgyPkyrAcEYvvEZMHXTYuYzb1K5+ RGd0jqlN1aQFxgHmzF9LQAc26OEKratXZwdP6DdH8GiUqc483ufMa3HjLStkGucUCVQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=FZg6bsHA; arc=none smtp.remote-ip=198.175.65.12 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.12]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8D482606A32A; Wed, 2 Dec 2026 12:59:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 8D482606A32A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=FZg6bsHA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796216382; x=1827752382; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=owEpxqGKzoGGpMagmbclQsL8s36T+Z0mmLXMV8Q7rMU=; b=FZg6bsHAvCMgkzg4V7dZWzB59w3i4N09QFlUjaSeqW1EB/gsQyi6LCLf v+GMs9aY9a0ij3895/yjNtDC91TaLsSJ6wacb2sokRTAycPlMDI4MD2eP HHpxm4oBa9rV5YIVqwB6FTDC1hvUzEbb1K2U9dsoWhwvsUh/71pdTvF3/ f5uWZY8F3bWxr8jCUd3YRr0xVcIAo8H+ALmD31tXsIhnk/3Fna20ejCr9 OxyJzxx1MdeCsN8nb5PNllFmKkpDOh6EBlEYD9SygrTfrkeqyrqWMd42r n5/catKpZhs+qcgCB/5D2vro0hhf8zW+mRMxaFFjVLp5xTh0V/0iwEEMn A==; X-CSE-ConnectionGUID: lBZUlv3XRQCuRZtg6PrD4g== X-CSE-MsgGUID: jnm73E9HS2ycB7SbvBKu8w== X-IronPort-AV: E=McAfee;i="6800,10657,11984"; a="5052876" X-IronPort-AV: E=Sophos;i="6.27,246,1787036400"; d="scan'208";a="5052876" Received: from fmviesa012.fm.intel.com ([10.60.135.152]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Dec 2026 04:59:42 -0800 X-CSE-ConnectionGUID: szUwxpnMSL6oA6pE8XjyWw== X-CSE-MsgGUID: enmN0PqTSSSaIIvgQKOdYQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,246,1787036400"; d="scan'208";a="15170399" Received: from yilunxu-optiplex-7050.sh.intel.com (HELO localhost) ([10.239.47.46]) by fmviesa012.fm.intel.com with ESMTP; 02 Dec 2026 04:59:39 -0800 Date: Wed, 2 Dec 2026 20:48:43 +0800 From: Xu Yilun To: "NG, TZE YEE" Cc: Moritz Fischer , Xu Yilun , Tom Rix , linux-fpga@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] fpga: altera-cvp: Handle truncated bitstream with padding buffer Message-ID: References: <3c1bb384cb9cd5bb35b3c7e68a4feab95ef4ad60.1794987679.git.tze.yee.ng@altera.com> <17e00dfd-c744-45e3-aba9-e404210bc481@altera.com> 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 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <17e00dfd-c744-45e3-aba9-e404210bc481@altera.com> On Tue, Dec 01, 2026 at 03:32:38PM +0800, NG, TZE YEE wrote: > 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. Then what's the connection to this 4096-byte requirement? Other errors doesn't trigger VSE_UNCOR_ERR_CVP_CFG_ERR? > > > > > > > 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 No, it's not the driver's responsibility. If you want the rule, the image should obey the rule, otherwise it's a broken image. > 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. The corrupted image are expected to fail, is it? As you said the firmware can already fail the case correctly. Why adding zero words?