Skip to content

Commit 10817f2

Browse files
Shyam Sundar S Kjwrdegoede
authored andcommitted
platform/x86/amd/pmf: Add capability to sideload of policy binary
A policy binary is OS agnostic, and the same policies are expected to work across the OSes. At times it becomes difficult to debug when the policies inside the policy binaries starts to misbehave. Add a way to sideload such policies independently to debug them via a debugfs entry. Reviewed-by: Mario Limonciello <[email protected]> Signed-off-by: Shyam Sundar S K <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Hans de Goede <[email protected]> Signed-off-by: Hans de Goede <[email protected]>
1 parent 69e76c5 commit 10817f2

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

drivers/platform/x86/amd/pmf/pmf.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ struct amd_pmf_dev {
219219
bool cnqf_supported;
220220
struct notifier_block pwr_src_notifier;
221221
/* Smart PC solution builder */
222+
struct dentry *esbin;
222223
unsigned char *policy_buf;
223224
u32 policy_sz;
224225
struct tee_context *tee_ctx;

drivers/platform/x86/amd/pmf/tee-if.c

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* Author: Shyam Sundar S K <[email protected]>
99
*/
1010

11+
#include <linux/debugfs.h>
1112
#include <linux/tee_drv.h>
1213
#include <linux/uuid.h>
1314
#include "pmf.h"
@@ -16,9 +17,14 @@
1617

1718
/* Policy binary actions sampling frequency (in ms) */
1819
static int pb_actions_ms = MSEC_PER_SEC;
20+
/* Sideload policy binaries to debug policy failures */
21+
static bool pb_side_load;
22+
1923
#ifdef CONFIG_AMD_PMF_DEBUG
2024
module_param(pb_actions_ms, int, 0644);
2125
MODULE_PARM_DESC(pb_actions_ms, "Policy binary actions sampling frequency (default = 1000ms)");
26+
module_param(pb_side_load, bool, 0444);
27+
MODULE_PARM_DESC(pb_side_load, "Sideload policy binaries debug policy failures");
2228
#endif
2329

2430
static const uuid_t amd_pmf_ta_uuid = UUID_INIT(0x6fd93b77, 0x3fb8, 0x524d,
@@ -269,6 +275,57 @@ static int amd_pmf_start_policy_engine(struct amd_pmf_dev *dev)
269275
return 0;
270276
}
271277

278+
#ifdef CONFIG_AMD_PMF_DEBUG
279+
static ssize_t amd_pmf_get_pb_data(struct file *filp, const char __user *buf,
280+
size_t length, loff_t *pos)
281+
{
282+
struct amd_pmf_dev *dev = filp->private_data;
283+
unsigned char *new_policy_buf;
284+
int ret;
285+
286+
/* Policy binary size cannot exceed POLICY_BUF_MAX_SZ */
287+
if (length > POLICY_BUF_MAX_SZ || length == 0)
288+
return -EINVAL;
289+
290+
/* re-alloc to the new buffer length of the policy binary */
291+
new_policy_buf = kzalloc(length, GFP_KERNEL);
292+
if (!new_policy_buf)
293+
return -ENOMEM;
294+
295+
if (copy_from_user(new_policy_buf, buf, length))
296+
return -EFAULT;
297+
298+
kfree(dev->policy_buf);
299+
dev->policy_buf = new_policy_buf;
300+
dev->policy_sz = length;
301+
302+
ret = amd_pmf_start_policy_engine(dev);
303+
if (ret)
304+
return -EINVAL;
305+
306+
return length;
307+
}
308+
309+
static const struct file_operations pb_fops = {
310+
.write = amd_pmf_get_pb_data,
311+
.open = simple_open,
312+
};
313+
314+
static void amd_pmf_open_pb(struct amd_pmf_dev *dev, struct dentry *debugfs_root)
315+
{
316+
dev->esbin = debugfs_create_dir("pb", debugfs_root);
317+
debugfs_create_file("update_policy", 0644, dev->esbin, dev, &pb_fops);
318+
}
319+
320+
static void amd_pmf_remove_pb(struct amd_pmf_dev *dev)
321+
{
322+
debugfs_remove_recursive(dev->esbin);
323+
}
324+
#else
325+
static void amd_pmf_open_pb(struct amd_pmf_dev *dev, struct dentry *debugfs_root) {}
326+
static void amd_pmf_remove_pb(struct amd_pmf_dev *dev) {}
327+
#endif
328+
272329
static int amd_pmf_get_bios_buffer(struct amd_pmf_dev *dev)
273330
{
274331
dev->policy_buf = kzalloc(dev->policy_sz, GFP_KERNEL);
@@ -281,6 +338,9 @@ static int amd_pmf_get_bios_buffer(struct amd_pmf_dev *dev)
281338

282339
memcpy(dev->policy_buf, dev->policy_base, dev->policy_sz);
283340

341+
if (pb_side_load)
342+
amd_pmf_open_pb(dev, dev->dbgfs_dir);
343+
284344
return amd_pmf_start_policy_engine(dev);
285345
}
286346

@@ -393,6 +453,9 @@ int amd_pmf_init_smart_pc(struct amd_pmf_dev *dev)
393453

394454
void amd_pmf_deinit_smart_pc(struct amd_pmf_dev *dev)
395455
{
456+
if (pb_side_load)
457+
amd_pmf_remove_pb(dev);
458+
396459
kfree(dev->prev_data);
397460
kfree(dev->policy_buf);
398461
cancel_delayed_work_sync(&dev->pb_work);

0 commit comments

Comments
 (0)