Re: [PATCH v16 net-next 1/9] octeontx2-af: npc: cn20k: debugfs enhancements

From: Ratheesh Kannoth

Date: Fri May 22 2026 - 07:40:02 EST


On 2026-05-21 at 15:22:55, Ratheesh Kannoth (rkannoth@xxxxxxxxxxx) wrote:
> Improve MCAM visibility and field debugging for CN20K NPC.

[ ... ]
>> +#define DEFINE_OCTEONTX2_DEBUGFS_ATTRIBUTE_WITH_SIZE(__name, __size) \
>> +static int __name ## _open(struct inode *inode, struct file *file) \
>> +{ \
>> + return single_open_size(file, __name ## _show, inode->i_private, \
>> + __size); \
>> +} \
>> +__OCTEONTX2_DEBUGFS_ATTRIBUTE_FOPS(__name)
>[ ... ]
>> + delta = stats - dstats[bank][idx];
>> +
>> + snprintf(buff, sizeof(buff), "%u\t%#04x\t%llu\n",
>> + mcam_idx, pf, delta);
>> + seq_puts(s, buff);
>> +
>> + dstats[bank][idx] = stats;
>> + }
>> + }
>> +
>> + mutex_unlock(&stats_lock);
>> + return 0;
>> +}
>> +
+
>> +/* "%u\t%#04x\t%llu\n" needs less than 64 characters to print */
>> +#define TOTAL_SZ (MAX_NUM_BANKS * MAX_NUM_SUB_BANKS * MAX_SUBBANK_DEPTH * 64)
>> +DEFINE_OCTEONTX2_DEBUGFS_ATTRIBUTE_WITH_SIZE(npc_mcam_dstats, TOTAL_SZ);
>Does this code use single_open_size() to force a 1MB allocation to avoid
>seq_file buffer overflow?
>For dstats, the show function modifies state by updating dstats[bank][idx].
>If the seq_file buffer were to overflow and restart, it would skip entries
>or report zero deltas. Bypassing the seq_file dynamic resizing with a 1MB
>upfront allocation per file open wastes memory to hide a seq_file idempotency
>issue.
>>
if i understand it correctly, seq_file idempotency issue occurs only if .next() function
is a custom implementation. In our case, we are not using custom .next() function, so it wont
happen in this case.