Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

powerpc/pseries/htmdump: Add htm info support to htmdump module

Support dumping system processor configuration from Hardware
Trace Macro (HTM) function via debugfs interface. Under
debugfs folder "/sys/kernel/debug/powerpc/htmdump", add
file "htminfo".

The interface allows only read of this file which will present the
content of HTM buffer from the hcall. The 16th offset of HTM
buffer has value for the number of entries for array of processors.
Use this information to copy data to the debugfs file

Signed-off-by: Athira Rajeev <atrajeev@linux.ibm.com>
Tested-by: Venkat Rao Bagalkote <venkat88@linux.ibm.com>
Signed-off-by: Madhavan Srinivasan <maddy@linux.ibm.com>
Link: https://patch.msgid.link/20250420180844.53128-6-atrajeev@linux.ibm.com

authored by

Athira Rajeev and committed by
Madhavan Srinivasan
dea7384e 627cf584

+51
+51
arch/powerpc/platforms/pseries/htmdump.c
··· 13 13 14 14 static void *htm_buf; 15 15 static void *htm_status_buf; 16 + static void *htm_info_buf; 16 17 static u32 nodeindex; 17 18 static u32 nodalchipindex; 18 19 static u32 coreindexonchip; ··· 254 253 .open = simple_open, 255 254 }; 256 255 256 + static ssize_t htminfo_read(struct file *filp, char __user *ubuf, 257 + size_t count, loff_t *ppos) 258 + { 259 + void *htm_info_buf = filp->private_data; 260 + long rc, ret; 261 + u64 *num_entries; 262 + u64 to_copy; 263 + 264 + /* 265 + * Invoke H_HTM call with: 266 + * - operation as htm status (H_HTM_OP_STATUS) 267 + * - last three values as addr, size and offset 268 + */ 269 + rc = htm_hcall_wrapper(nodeindex, nodalchipindex, coreindexonchip, 270 + htmtype, H_HTM_OP_DUMP_SYSPROC_CONF, virt_to_phys(htm_info_buf), 271 + PAGE_SIZE, 0); 272 + 273 + ret = htm_return_check(rc); 274 + if (ret <= 0) { 275 + pr_debug("H_HTM hcall failed for op: H_HTM_OP_DUMP_SYSPROC_CONF, returning %ld\n", ret); 276 + return ret; 277 + } 278 + 279 + /* 280 + * HTM status buffer, start of buffer + 0x10 gives the 281 + * number of HTM entries in the buffer. Each entry of processor 282 + * is 16 bytes. 283 + * 284 + * So total count to copy is: 285 + * 32 bytes (for first 5 fields) + (number of HTM entries * entry size) 286 + */ 287 + num_entries = htm_info_buf + 0x10; 288 + to_copy = 32 + (be64_to_cpu(*num_entries) * 16); 289 + return simple_read_from_buffer(ubuf, count, ppos, htm_info_buf, to_copy); 290 + } 291 + 292 + static const struct file_operations htminfo_fops = { 293 + .llseek = NULL, 294 + .read = htminfo_read, 295 + .open = simple_open, 296 + }; 297 + 257 298 DEFINE_SIMPLE_ATTRIBUTE(htmconfigure_fops, htmconfigure_get, htmconfigure_set, "%llu\n"); 258 299 DEFINE_SIMPLE_ATTRIBUTE(htmstart_fops, htmstart_get, htmstart_set, "%llu\n"); 259 300 ··· 333 290 return -ENOMEM; 334 291 } 335 292 293 + /* Debugfs interface file to present System Processor Configuration */ 294 + htm_info_buf = kmalloc(PAGE_SIZE, GFP_KERNEL); 295 + if (!htm_info_buf) { 296 + pr_err("Failed to allocate htm info buf\n"); 297 + return -ENOMEM; 298 + } 299 + 336 300 debugfs_create_file("htmstatus", 0400, htmdump_debugfs_dir, htm_status_buf, &htmstatus_fops); 301 + debugfs_create_file("htminfo", 0400, htmdump_debugfs_dir, htm_info_buf, &htminfo_fops); 337 302 338 303 return 0; 339 304 }