Received: by 2002:ab2:6991:0:b0:1f7:f6c3:9cb1 with SMTP id v17csp659460lqo; Wed, 8 May 2024 10:41:55 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVUPe3EFuiJcisI7NkH9hZ7f1Zydr3vsIu/b28oatvbdbygT37q32IPiCxrrU211X4W1r0zoQPiNButV3X4aKYwKfA9eO2Zn9WzT91tBQ== X-Google-Smtp-Source: AGHT+IF7p472irElywhhq6lLPMGtYeUF1bHVBP30W8QB83qzYYEul8/5Sr4wA/b0sXtZp2X43D71 X-Received: by 2002:a05:620a:126a:b0:792:9652:5a1d with SMTP id af79cd13be357-792b28523d4mr340046185a.66.1715190114895; Wed, 08 May 2024 10:41:54 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715190114; cv=pass; d=google.com; s=arc-20160816; b=O5lvcQn/XHZ/EZUuR3xj/KHCBWncX3R6jDyEXf3yg7/793+YYULMmP+EcAtJSsFHym 0Wz+kw9f5pGiBykUCzj4bQ/kSGQS3t7yE4Cl7ZjZwJCtm3ryZT/5D5xv2o7SIozEroDK VT8HSFNcIgLz4p7ucoEVjoLjFNuwKAxf8Qgnb6nLyA15iTCOhirdcFQmY3bqj51LwT0v C9cAhaf+inNPqhRwOCbsA9gIZnBLPtjsDkn3GnQsw51Df3kaTv8Db776KB7JDrkXFzJ/ ZZuaDMB+FK7t6YbqT8HlOHpyW007brx1JygaLQRRo4L7Db/611Px9IiYu66ki76pXP3N M3Qw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=SOJNho+VRhSE+48vSA0Z0GxI1ApE1Uw/XOa1wvD9TU8=; fh=Jm256tzRRTVX3Ts4s97zGiIOk6WKPnmTv8sZ8hLufHY=; b=lFFT90GUjCNzQzUEwPqI6nZkbAM6PDTcsrxtoZoDrsxHAdJI4S3IkAlt5hoSMKGwh1 Du5mYEU10Z6oCurGJYEW+IBKKy0IaZNn11+19Eh9YS9xdCLeBzBkrVmL3tZ5UNfpWmxh I5HL2+B+beDW2q1qYJxaV1VBK1ruXfxfGi7CZRXzHp+BVaIx88qAaYPBQLRZO4ZIfGSQ E1yVrsPwTl+SCMxd3vjoF3eOnYiXCWR9cuoS0MQxX+L+UPfWEKBagOvaRHH9G0H1K0JO WU4c3jgs/sZtM9pVWF8yogsoNCwMA0p5xUDcuSzvLctQdxW/fvQCjoRipR6IFrW8mN7v yBJA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gaisler.com header.s=unoeuro header.b=jWCfjxFS; arc=pass (i=1 spf=pass spfdomain=gaisler.com dkim=pass dkdomain=gaisler.com dmarc=pass fromdomain=gaisler.com); spf=pass (google.com: domain of linux-kernel+bounces-173649-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-173649-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gaisler.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id m2-20020a05620a214200b00792bca02592si27365qkm.358.2024.05.08.10.41.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 May 2024 10:41:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-173649-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gaisler.com header.s=unoeuro header.b=jWCfjxFS; arc=pass (i=1 spf=pass spfdomain=gaisler.com dkim=pass dkdomain=gaisler.com dmarc=pass fromdomain=gaisler.com); spf=pass (google.com: domain of linux-kernel+bounces-173649-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-173649-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gaisler.com 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 8B6B51C23747 for ; Wed, 8 May 2024 17:41:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 379D78627B; Wed, 8 May 2024 17:41:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=gaisler.com header.i=@gaisler.com header.b="jWCfjxFS" Received: from smtp-out3.simply.com (smtp-out3.simply.com [94.231.106.210]) (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 B11AB2E3E8; Wed, 8 May 2024 17:41:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=94.231.106.210 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715190108; cv=none; b=cdD4Sxe8ZH0gf4aZRTnGfBtKtvWzqF7gLZfwvXwF36VfXHEp6mSIvGmKGpnlNCScF/dv8uJFln7fDUbe/hiS7dfEMI/Fobl9206bOTDDaecOXmlKC942camYtahsqhvFkOgcd6G71JyYityrs6t5KOz8X0Z0ha39XMvwMx2RH7M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715190108; c=relaxed/simple; bh=IiR4SdqEVfpLMIvkfN2nNdhAA3VmaICpuxaPIz4gPUk=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=abG/sUXTGr7TGUsPazGVQ6OrwT/19ZfzOCRiHvyHVZlUsFIeIYb70I0/uaGD/v0M3lPBPetyw8fzA5010SRQHTyfz+wFpPOZFNG0heJAi7ATv9lVxvkvl/zTI8FxjxwEBmPSrG1TJCXEnv4DCxuWh9nRAYOvMSQOrFAxQWQQhNA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gaisler.com; spf=pass smtp.mailfrom=gaisler.com; dkim=pass (1024-bit key) header.d=gaisler.com header.i=@gaisler.com header.b=jWCfjxFS; arc=none smtp.client-ip=94.231.106.210 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gaisler.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gaisler.com Received: from localhost (localhost [127.0.0.1]) by smtp.simply.com (Simply.com) with ESMTP id 4VZMf30Vgvz682x; Wed, 8 May 2024 19:32:11 +0200 (CEST) Received: from [192.168.0.25] (h-98-128-223-123.NA.cust.bahnhof.se [98.128.223.123]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by smtp.simply.com (Simply.com) with ESMTPSA id 4VZMf24mdQz67yg; Wed, 8 May 2024 19:32:09 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gaisler.com; s=unoeuro; t=1715189531; bh=SOJNho+VRhSE+48vSA0Z0GxI1ApE1Uw/XOa1wvD9TU8=; h=Date:Subject:To:Cc:References:From:In-Reply-To; b=jWCfjxFScjkVKzG2nqlG9dJ7VWlkyRAwKbivcZ3G2H5sVAamIndSrr4HGjRwtzXsT R7y0BqnKNiIaJCVCOri/6Pm3BbADtvI8omJS9HwBOzBJFqPM7XGdBKGliN7tVmwprU 1fCQe8gV2uuY7hpELd9UbctyXfRg0K5bE/mQdlBU= Message-ID: Date: Wed, 8 May 2024 19:32:08 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v4 1/5] sparc/srmmu: Remove on-stack cpumask var To: Dawei Li , davem@davemloft.net Cc: sparclinux@vger.kernel.org, linux-kernel@vger.kernel.org, sam@ravnborg.org References: <20240424025548.3765250-1-dawei.li@shingroup.cn> <20240424025548.3765250-2-dawei.li@shingroup.cn> Content-Language: en-US From: Andreas Larsson In-Reply-To: <20240424025548.3765250-2-dawei.li@shingroup.cn> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 2024-04-24 04:55, Dawei Li wrote: > 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); > } Reviewed-by: Andreas Larsson Tested-by: Andreas Larsson Picking this up to my for-next. Thanks, Andreas