Skip to content

Commit 7aba3a8

Browse files
Dawei Liandreas-gaisler
authored andcommitted
sparc/srmmu: Remove on-stack cpumask var
In general it's preferable to avoid placing cpumasks on the stack, as for large values of NR_CPUS these can consume significant amounts of stack space and make stack overflows more likely. Use cpumask_any_but() to avoid the need for a temporary cpumask on the stack and simplify code. Reviewed-by: Sam Ravnborg <[email protected]> Signed-off-by: Dawei Li <[email protected]> Reviewed-by: Andreas Larsson <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Andreas Larsson <[email protected]>
1 parent 48d85ac commit 7aba3a8

File tree

1 file changed

+12
-28
lines changed

1 file changed

+12
-28
lines changed

arch/sparc/mm/srmmu.c

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1653,13 +1653,15 @@ static void smp_flush_tlb_all(void)
16531653
local_ops->tlb_all();
16541654
}
16551655

1656+
static bool any_other_mm_cpus(struct mm_struct *mm)
1657+
{
1658+
return cpumask_any_but(mm_cpumask(mm), smp_processor_id()) < nr_cpu_ids;
1659+
}
1660+
16561661
static void smp_flush_cache_mm(struct mm_struct *mm)
16571662
{
16581663
if (mm->context != NO_CONTEXT) {
1659-
cpumask_t cpu_mask;
1660-
cpumask_copy(&cpu_mask, mm_cpumask(mm));
1661-
cpumask_clear_cpu(smp_processor_id(), &cpu_mask);
1662-
if (!cpumask_empty(&cpu_mask))
1664+
if (any_other_mm_cpus(mm))
16631665
xc1(local_ops->cache_mm, (unsigned long)mm);
16641666
local_ops->cache_mm(mm);
16651667
}
@@ -1668,10 +1670,7 @@ static void smp_flush_cache_mm(struct mm_struct *mm)
16681670
static void smp_flush_tlb_mm(struct mm_struct *mm)
16691671
{
16701672
if (mm->context != NO_CONTEXT) {
1671-
cpumask_t cpu_mask;
1672-
cpumask_copy(&cpu_mask, mm_cpumask(mm));
1673-
cpumask_clear_cpu(smp_processor_id(), &cpu_mask);
1674-
if (!cpumask_empty(&cpu_mask)) {
1673+
if (any_other_mm_cpus(mm)) {
16751674
xc1(local_ops->tlb_mm, (unsigned long)mm);
16761675
if (atomic_read(&mm->mm_users) == 1 && current->active_mm == mm)
16771676
cpumask_copy(mm_cpumask(mm),
@@ -1688,10 +1687,7 @@ static void smp_flush_cache_range(struct vm_area_struct *vma,
16881687
struct mm_struct *mm = vma->vm_mm;
16891688

16901689
if (mm->context != NO_CONTEXT) {
1691-
cpumask_t cpu_mask;
1692-
cpumask_copy(&cpu_mask, mm_cpumask(mm));
1693-
cpumask_clear_cpu(smp_processor_id(), &cpu_mask);
1694-
if (!cpumask_empty(&cpu_mask))
1690+
if (any_other_mm_cpus(mm))
16951691
xc3(local_ops->cache_range, (unsigned long)vma, start,
16961692
end);
16971693
local_ops->cache_range(vma, start, end);
@@ -1705,10 +1701,7 @@ static void smp_flush_tlb_range(struct vm_area_struct *vma,
17051701
struct mm_struct *mm = vma->vm_mm;
17061702

17071703
if (mm->context != NO_CONTEXT) {
1708-
cpumask_t cpu_mask;
1709-
cpumask_copy(&cpu_mask, mm_cpumask(mm));
1710-
cpumask_clear_cpu(smp_processor_id(), &cpu_mask);
1711-
if (!cpumask_empty(&cpu_mask))
1704+
if (any_other_mm_cpus(mm))
17121705
xc3(local_ops->tlb_range, (unsigned long)vma, start,
17131706
end);
17141707
local_ops->tlb_range(vma, start, end);
@@ -1720,10 +1713,7 @@ static void smp_flush_cache_page(struct vm_area_struct *vma, unsigned long page)
17201713
struct mm_struct *mm = vma->vm_mm;
17211714

17221715
if (mm->context != NO_CONTEXT) {
1723-
cpumask_t cpu_mask;
1724-
cpumask_copy(&cpu_mask, mm_cpumask(mm));
1725-
cpumask_clear_cpu(smp_processor_id(), &cpu_mask);
1726-
if (!cpumask_empty(&cpu_mask))
1716+
if (any_other_mm_cpus(mm))
17271717
xc2(local_ops->cache_page, (unsigned long)vma, page);
17281718
local_ops->cache_page(vma, page);
17291719
}
@@ -1734,10 +1724,7 @@ static void smp_flush_tlb_page(struct vm_area_struct *vma, unsigned long page)
17341724
struct mm_struct *mm = vma->vm_mm;
17351725

17361726
if (mm->context != NO_CONTEXT) {
1737-
cpumask_t cpu_mask;
1738-
cpumask_copy(&cpu_mask, mm_cpumask(mm));
1739-
cpumask_clear_cpu(smp_processor_id(), &cpu_mask);
1740-
if (!cpumask_empty(&cpu_mask))
1727+
if (any_other_mm_cpus(mm))
17411728
xc2(local_ops->tlb_page, (unsigned long)vma, page);
17421729
local_ops->tlb_page(vma, page);
17431730
}
@@ -1759,10 +1746,7 @@ static void smp_flush_page_to_ram(unsigned long page)
17591746

17601747
static void smp_flush_sig_insns(struct mm_struct *mm, unsigned long insn_addr)
17611748
{
1762-
cpumask_t cpu_mask;
1763-
cpumask_copy(&cpu_mask, mm_cpumask(mm));
1764-
cpumask_clear_cpu(smp_processor_id(), &cpu_mask);
1765-
if (!cpumask_empty(&cpu_mask))
1749+
if (any_other_mm_cpus(mm))
17661750
xc2(local_ops->sig_insns, (unsigned long)mm, insn_addr);
17671751
local_ops->sig_insns(mm, insn_addr);
17681752
}

0 commit comments

Comments
 (0)