From ad42423088517c92258482e9bd7fee4102bc877e Mon Sep 17 00:00:00 2001 From: Wang ShaoBo Date: Wed, 24 Feb 2021 11:14:49 +0800 Subject: [PATCH] arm64/mpam: Support cdp on allocating monitors hulk inclusion category: feature bugzilla: 34278 CVE: NA ------------------------------------------------- This prepares for simultaneously monitoring LxDATA and LxCODE when cdp is open, under our implementation, LxDATA and LxCODE is allocated closid and closid+1, so we should keep two monitor once time for each. Why there needs one monitors for each closid when cdp is open, but not switch one between the two LxDATA and LxCODE is because this monitor kept by target closid maybe busy for a long time, it would cause inaccuracy if we force switching. Signed-off-by: Wang ShaoBo Reviewed-by: Xiongfeng Wang Reviewed-by: Cheng Jian Signed-off-by: Yang Yingliang Signed-off-by: Cheng Jian --- arch/arm64/kernel/mpam/mpam_mon.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/arch/arm64/kernel/mpam/mpam_mon.c b/arch/arm64/kernel/mpam/mpam_mon.c index f952e9aa20c2..297169b41ea3 100644 --- a/arch/arm64/kernel/mpam/mpam_mon.c +++ b/arch/arm64/kernel/mpam/mpam_mon.c @@ -93,20 +93,28 @@ void mon_init(void) int alloc_mon(void) { - u32 mon = ffs(mon_free_map); + u32 mon = 0; + u32 times, flag; + hw_alloc_times_validate(mon, times, flag); + + mon = ffs(mon_free_map); if (mon == 0) return -ENOSPC; mon--; - mon_free_map &= ~(1 << mon); + mon_free_map &= ~(GENMASK(mon, mon + times - 1)); return mon; } void free_mon(u32 mon) { - mon_free_map |= 1 << mon; + u32 times, flag; + + hw_alloc_times_validate(mon, times, flag); + + mon_free_map |= GENMASK(mon, mon + times - 1); } /* -- GitLab