Received: by 2002:a89:48b:0:b0:1f5:f2ab:c469 with SMTP id a11csp163482lqd; Tue, 23 Apr 2024 19:57:55 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWnm6r07iFr01G89OA9wixIlxkr6LG0plCCTglRnUpT/J4A66PDu9abf8fJH6U32poVs2HOg7v6tKvyHJJ36O0wiqt+ZycSJbWgngdFXQ== X-Google-Smtp-Source: AGHT+IG29MkICyPHPxmdJ5n7CadwmH/v2oOJN1G/mYl+CGdZ4dAtNgK5IWIxuNYiSpKdsV/JoPtp X-Received: by 2002:a05:6000:188:b0:343:7b6b:dcc6 with SMTP id p8-20020a056000018800b003437b6bdcc6mr686245wrx.30.1713927475366; Tue, 23 Apr 2024 19:57:55 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713927475; cv=pass; d=google.com; s=arc-20160816; b=lY/HwNAAPiqzQOA5bD2v8S/YCP5seWP+PN1CKBguM3Gxr1W22gEDeCJigNHIgBoYh7 8WbJfexA9LzzBXuP3dC6sn7VlkAPzkKeBQPh7/Gtm7E/YQzXqaHiKZ8F5NDFlcvo2KOx ULf+TjiYLsDmE2Uxdu7bkayjBCWDoFaY0vg33gZDgH4PvmrJjzoh8keAlY2jTBkUJRTh SKV0hLjjWHcKiYoj2TFaeh3P1ArCDnRN5W05Ga05CdT5CpbwLvx+JSu/vsd9CRR57QIe pNbsAP++dk+3svR071yebwfU+00+pLmWs+4HZun1XYO3Eg0MyRYosnGklKaghYnSUwu1 KoBA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=feedback-id:content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=NU9DxjYb8bQdrSZFXbkHCwY/+nProQOjy/2DmsRo8H4=; fh=G+96+g6i3+MsNX6tI5HdBwIuZ4Gw9WUIhLzaUYuKmBE=; b=B6AxaVwH9dBCioEcTITzViK/CSk5SaPMU3H5ozFy3FKSfN8U1p1zSXzLwgzrPaDVQc pqNFopW3ouRpu6I4im6NtZWV+wcaIaQWiCSju3j0xi98eIOFufUGdRn/xzoE/+ICUIvl Asb9qYFktRTBXF5r6eo8EQWCSoVBaHfL7MXffjPj9F2p3H9dYJ60I97G4384YB5Mchmi qHAY9HGtkIwetaHC06gBT6kG/+oP8NdGAzbXw10KAyziBOAs5xoJaDhhm1E+zk1IfIDZ yEjQuWexcrKjBQJW347zLEGgHsj8NcyU2LXeG4IN9JDZ/71CabAZQ7Ev/m9PP7ScUvVw 8tcw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=shingroup.cn dmarc=pass fromdomain=shingroup.cn); spf=pass (google.com: domain of linux-kernel+bounces-156182-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-156182-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=shingroup.cn Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id gs20-20020a170906f19400b00a58782f112dsi1947691ejb.769.2024.04.23.19.57.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Apr 2024 19:57:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-156182-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=shingroup.cn dmarc=pass fromdomain=shingroup.cn); spf=pass (google.com: domain of linux-kernel+bounces-156182-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-156182-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=shingroup.cn Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 1B0971F21BD8 for ; Wed, 24 Apr 2024 02:57:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CDEFD84FD3; Wed, 24 Apr 2024 02:56:49 +0000 (UTC) Received: from smtpbgbr1.qq.com (smtpbgbr1.qq.com [54.207.19.206]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 50423142E8A; Wed, 24 Apr 2024 02:56:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=54.207.19.206 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713927409; cv=none; b=UfoBdgJmWYsGwxMxMm719EeovRzaz2JmoVN7zvZFDpCanwxQ9JuSJwhxbkLXpHKDQV5dQ+NPlKJ2WEUihrU7VvhkLsZAjUS95QJMxc/g2TA8R8P9v0h9HgDdrPkpj4uqz2SKG2MWZde05gWZDifQGwS1f2AFj0jAxW/vOCRtd2g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713927409; c=relaxed/simple; bh=eGgBQtvqHszHLZjEaVNOzyrzgGeymXRzgL/zYDf5Cj0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=KNQy4N9Dn3a4oj10A5Em/wwhqPNBJ7pm0fA2muHGonHN83//qHLx5d6oq8dOdQUQK0Qx2oICgz6VZLPVI8O0NjW/5438YFYtnRfz8M9ounedx7J4Qf+n92yeSNwBSnNhTxYLy6Sl6wI0ZRexRr04Rm0h2RBmx+e0drX2IJ3pj3Q= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=shingroup.cn; spf=pass smtp.mailfrom=shingroup.cn; arc=none smtp.client-ip=54.207.19.206 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=shingroup.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=shingroup.cn X-QQ-mid: bizesmtpsz11t1713927362tuq3f5 X-QQ-Originating-IP: r4SzD00NWbLMn6CzY4bmfQwvShdm3liWPDr3PAhKA8A= Received: from localhost ( [112.0.147.129]) by bizesmtp.qq.com (ESMTP) with id ; Wed, 24 Apr 2024 10:56:00 +0800 (CST) X-QQ-SSF: 01400000000000903000000A0000000 X-QQ-FEAT: KdN0SWBFoH4pfnOT4RnGCvcbVf07FHD8cWXeImdce+6Iq6YSHyIsvsSoD9y27 KsCp8ccVwDj4QBYvvGKjf2vJo47SQ71YVQg6KR9FhTDlnqPerN9/7ootNfd27xVFJ7cvdRx 2UUjtH9BGHDlTiNkxS2IahGAstKxKzxunZslIzg78B8RA7AuptFCH3hALQG716tHPqUNRwW JpGE5jooPD+tao1IM1lufWUHtfP04D1+7ipsmORCb38Qv/PtsFa2WYWNW5ha5nTfPByBkOd Bgo5kMP6eTUtHWH/NfCpMSIKsrjnPAk8OzhpWnVoI3o26rY3ShOeBfVHHRHT5ta4K5Noctu D2BbhREYfzRh0J4/X8hutImW2ZK/eQ5Qqo134AujtK9Xtre+ZrvZ3yK/6d96+KjbX29MJwl mliS/JVPpFFGmun6FL8YYQ== X-QQ-GoodBg: 2 X-BIZMAIL-ID: 17482992141322820079 From: Dawei Li To: davem@davemloft.net, andreas@gaisler.com Cc: sparclinux@vger.kernel.org, linux-kernel@vger.kernel.org, sam@ravnborg.org, Dawei Li Subject: [PATCH v4 1/5] sparc/srmmu: Remove on-stack cpumask var Date: Wed, 24 Apr 2024 10:55:44 +0800 Message-Id: <20240424025548.3765250-2-dawei.li@shingroup.cn> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240424025548.3765250-1-dawei.li@shingroup.cn> References: <20240424025548.3765250-1-dawei.li@shingroup.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtpsz:shingroup.cn:qybglogicsvrgz:qybglogicsvrgz5a-1 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 Signed-off-by: Dawei Li --- arch/sparc/mm/srmmu.c | 40 ++++++++++++---------------------------- 1 file changed, 12 insertions(+), 28 deletions(-) diff --git a/arch/sparc/mm/srmmu.c b/arch/sparc/mm/srmmu.c index 852085ada368..9df51a62333d 100644 --- a/arch/sparc/mm/srmmu.c +++ b/arch/sparc/mm/srmmu.c @@ -1653,13 +1653,15 @@ static void smp_flush_tlb_all(void) local_ops->tlb_all(); } +static bool any_other_mm_cpus(struct mm_struct *mm) +{ + return cpumask_any_but(mm_cpumask(mm), smp_processor_id()) < nr_cpu_ids; +} + static void smp_flush_cache_mm(struct mm_struct *mm) { if (mm->context != NO_CONTEXT) { - cpumask_t cpu_mask; - cpumask_copy(&cpu_mask, mm_cpumask(mm)); - cpumask_clear_cpu(smp_processor_id(), &cpu_mask); - if (!cpumask_empty(&cpu_mask)) + if (any_other_mm_cpus(mm)) xc1(local_ops->cache_mm, (unsigned long)mm); local_ops->cache_mm(mm); } @@ -1668,10 +1670,7 @@ static void smp_flush_cache_mm(struct mm_struct *mm) static void smp_flush_tlb_mm(struct mm_struct *mm) { if (mm->context != NO_CONTEXT) { - cpumask_t cpu_mask; - cpumask_copy(&cpu_mask, mm_cpumask(mm)); - cpumask_clear_cpu(smp_processor_id(), &cpu_mask); - if (!cpumask_empty(&cpu_mask)) { + if (any_other_mm_cpus(mm)) { xc1(local_ops->tlb_mm, (unsigned long)mm); if (atomic_read(&mm->mm_users) == 1 && current->active_mm == mm) cpumask_copy(mm_cpumask(mm), @@ -1688,10 +1687,7 @@ static void smp_flush_cache_range(struct vm_area_struct *vma, struct mm_struct *mm = vma->vm_mm; if (mm->context != NO_CONTEXT) { - cpumask_t cpu_mask; - cpumask_copy(&cpu_mask, mm_cpumask(mm)); - cpumask_clear_cpu(smp_processor_id(), &cpu_mask); - if (!cpumask_empty(&cpu_mask)) + if (any_other_mm_cpus(mm)) xc3(local_ops->cache_range, (unsigned long)vma, start, end); local_ops->cache_range(vma, start, end); @@ -1705,10 +1701,7 @@ static void smp_flush_tlb_range(struct vm_area_struct *vma, struct mm_struct *mm = vma->vm_mm; if (mm->context != NO_CONTEXT) { - cpumask_t cpu_mask; - cpumask_copy(&cpu_mask, mm_cpumask(mm)); - cpumask_clear_cpu(smp_processor_id(), &cpu_mask); - if (!cpumask_empty(&cpu_mask)) + if (any_other_mm_cpus(mm)) xc3(local_ops->tlb_range, (unsigned long)vma, start, end); 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) struct mm_struct *mm = vma->vm_mm; if (mm->context != NO_CONTEXT) { - cpumask_t cpu_mask; - cpumask_copy(&cpu_mask, mm_cpumask(mm)); - cpumask_clear_cpu(smp_processor_id(), &cpu_mask); - if (!cpumask_empty(&cpu_mask)) + if (any_other_mm_cpus(mm)) xc2(local_ops->cache_page, (unsigned long)vma, page); local_ops->cache_page(vma, page); } @@ -1734,10 +1724,7 @@ static void smp_flush_tlb_page(struct vm_area_struct *vma, unsigned long page) struct mm_struct *mm = vma->vm_mm; if (mm->context != NO_CONTEXT) { - cpumask_t cpu_mask; - cpumask_copy(&cpu_mask, mm_cpumask(mm)); - cpumask_clear_cpu(smp_processor_id(), &cpu_mask); - if (!cpumask_empty(&cpu_mask)) + if (any_other_mm_cpus(mm)) xc2(local_ops->tlb_page, (unsigned long)vma, page); local_ops->tlb_page(vma, page); } @@ -1759,10 +1746,7 @@ static void smp_flush_page_to_ram(unsigned long page) static void smp_flush_sig_insns(struct mm_struct *mm, unsigned long insn_addr) { - cpumask_t cpu_mask; - cpumask_copy(&cpu_mask, mm_cpumask(mm)); - cpumask_clear_cpu(smp_processor_id(), &cpu_mask); - if (!cpumask_empty(&cpu_mask)) + if (any_other_mm_cpus(mm)) xc2(local_ops->sig_insns, (unsigned long)mm, insn_addr); local_ops->sig_insns(mm, insn_addr); } -- 2.27.0