Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp2794659lqt; Tue, 23 Apr 2024 01:31:57 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXL5w6Hi2zN9Q7tVMk6vJPIuySWeFv+dWIGG1dYthJaaL+Y0/VgDMczLEEaJoyC5mje1825pcekpT63UHl+C5M3DWgVt4gkGB8/0eeWKA== X-Google-Smtp-Source: AGHT+IFxaC9XYsj0OLbT3zxJpCbW7zemXgPsmJskY7JBVlT+iATYZlNBROP+R2D/Kaq6djpRmebg X-Received: by 2002:a17:902:e5c2:b0:1e8:92:c5e2 with SMTP id u2-20020a170902e5c200b001e80092c5e2mr19604783plf.47.1713861116888; Tue, 23 Apr 2024 01:31:56 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713861116; cv=pass; d=google.com; s=arc-20160816; b=QPVPigoOGlgOXgCTpMJL22T9M4ic3/fv7PX6WAB7IHBbYr9C7MVm9p0BpLbPNIxKhb mawCaSNrmUJoIAz1nf5CdjdCR3YIR3sPXuNWGE2UGMnSkxX+FEClDbs2ZL4/vRN1gQD/ 6hW7eB5mt8RB6k4mQlL8BtB/TDzsOqLTC1gLHRs/ekKKiJd63KPftzwYn+xHkBWe5w2a 4nHd9t+KklpHNqHrktsyObxMAl6TKiS3k0JpukOuxpXjB9v3wUaM6sV+o2Ldq/h01TXG XQ7n4BM0Bcap1ODi4WoNWFUNC5Nc/m+CKan5QIfWNrwCBZ8UuyH6wzHmhOPmsVClDrl0 ed8Q== 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=y7aCaaWSvh03WjenPQIb7zurIecjdlCUL2NolOnEJg7ZWS4HDZRHLr7+roBYEmhCIF 1UVavqQoz0jrJdY0/tyd20mPbP1AmMghDsKWGmU5tu+xBoQONw1nVFIZOpoxmVcKWe4x sgqSdDoPkhuXE/tbyilKxU5eecDw5jwRMpCqe6xeBRPcaDzK5VOMFtEX/qjslIzvwdv3 vjKQlX84QnF8NaXu1gky7RCf0l59FJc1vKAEakia4Yax2Jk4x6fpeYxLhO3u5G2WIXbB Z0Y0okVsAc6cIieWkfN7KsEeJMVEhNJci4GDCygi/jNLMsPVMgxaI2Ur4i4tzPjIze4z txzA==; 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-154686-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-154686-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=shingroup.cn Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id j6-20020a170903024600b001e813d8b0c0si9042218plh.124.2024.04.23.01.31.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Apr 2024 01:31:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-154686-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; 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-154686-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-154686-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 2D3EC282038 for ; Tue, 23 Apr 2024 08:31:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1823055C33; Tue, 23 Apr 2024 08:31:45 +0000 (UTC) Received: from smtpbgsg2.qq.com (smtpbgsg2.qq.com [54.254.200.128]) (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 D497D79D3; Tue, 23 Apr 2024 08:31:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=54.254.200.128 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713861104; cv=none; b=imwsumO9XqomoKXWOsQirIzfZ5cWF4v4wPmMA8+y1i4R3Lw4kh2Vs7Lx0QcjtcGOl0Ax1sDTOEV5CscwpsZDq+9R8+6y3HWvOmuddz+qdrda/MejnnVtKmxEL1n/8gxLzCoAz9chOXFDkrPRvb7MbzI2I70D82CqUBBmHZe42rw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713861104; c=relaxed/simple; bh=eGgBQtvqHszHLZjEaVNOzyrzgGeymXRzgL/zYDf5Cj0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=eTWgdPYEuLzSv88+tdnSh7515TxlmqF47Lb+OYuYv+s3n4Lw1Egn57bzAOu4T6OTV43o8qsHNvXAWRUUP48U9NH5jlKCG6s6yFtlFJqPudnY50XXMHUQxD3Wx9YmQRw+T2HboXaYY/24j3NE1TTyfAYGwnx1Ns23Yw26BzAvXlE= 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.254.200.128 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: bizesmtp82t1713861067tou125gg X-QQ-Originating-IP: 51OwVtAtuarwI4cCOTceEqcV9mknxm2HbvPOgPobPo0= Received: from localhost ( [112.0.147.129]) by bizesmtp.qq.com (ESMTP) with id ; Tue, 23 Apr 2024 16:31:05 +0800 (CST) X-QQ-SSF: 01400000000000903000000A0000000 X-QQ-FEAT: j86OQQvu8eQ1KhrGmCdEjrtfAbzGLSdea3066tUtHFRZeB3xbcnbrMa6/vNVC qrSR54Kjk6fKefvit8IzvrooMnYPYRldF/GLWR3VBzoNXJDegfDGxizLpcW5z8RAkdnEOqt +u5QwNny/+pQvYGlX5aXNN5X10gLT4fdxQvBOgBde5x+mfYFFoP3lsEba7xyM59vv6tHNzR odb+ahZYquwTveFuVonFYmjHqFZizYWVTnBy33DpzDA4ErmqvAS8Lw4z3SfvdBK3t26FJP+ CNXbFhfNr9+r3NFdR/Nhuy9TFIHpdyXronYd9V+Mgv/mvkXCocZ6vr86HNSkMfm51gmWKoj 2h5hHsqqc4Brr5j4aFah4xry9zGQEtJRkbjvVbbb514WM2qdUxmb11BhkiyIltY7SLDREfd UFtB97v3rjRrcqHuYo6p8g== X-QQ-GoodBg: 2 X-BIZMAIL-ID: 7545835907098097455 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 v3 1/6] sparc/srmmu: Remove on-stack cpumask var Date: Tue, 23 Apr 2024 16:30:38 +0800 Message-Id: <20240423083043.3735921-2-dawei.li@shingroup.cn> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240423083043.3735921-1-dawei.li@shingroup.cn> References: <20240423083043.3735921-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: bizesmtp: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