Received: by 2002:a05:6500:1b45:b0:1f5:f2ab:c469 with SMTP id cz5csp1217930lqb; Thu, 18 Apr 2024 03:51:18 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV4DxAnecFIyIC+ObCcM4oIHTwLCrGEiqNyh8p2wFV0z71jVVdB/M6EnLUhXKjJQt4VZEp449AUxp4Mg1Z4A/S7xhAKdcSASaMxsFv8/g== X-Google-Smtp-Source: AGHT+IGLhQeeHDNdVzQNDxgf/yrnNMSjVkbsVaybCHzelEDM/0ldR0Z3l1Vxp+w3Gy9GAuXYyNmg X-Received: by 2002:a05:6a20:dca0:b0:1a7:5a84:98f3 with SMTP id ky32-20020a056a20dca000b001a75a8498f3mr2474962pzb.54.1713437478583; Thu, 18 Apr 2024 03:51:18 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713437478; cv=pass; d=google.com; s=arc-20160816; b=woEXmKlbgKc3TvSzEx6BT8mQNzD+xjzmNcVGiold1rmaAPEKTqgIVwlnhkMbYk1lyC AmD/KLOmq2ZQBBhGtA5N8lkwDjgV2gplQ8yk+2ne0yEGR+YTjA60M7T2A01nkkJXZwV+ wI5Pph9FqnfguAMeRYW0AXjaj/tgtE6yBprJWLjNYdfY6gEfIkf49gd1Tx3ShCjOWZO1 YGnu9UUFWkJW6sDFN2Wqe6rv92y80UHjQbLP9fwwUgNOcvAbyCRnOFZJ/pAlvd9nkUEY wZGcVS7Shlti53srgzbRbV4HuDl9Kp88BHm3ErC4lYLRUDrRnKyMIvEepZPzHDNUtTX3 +CWg== 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=ubYkpe9uzkbQsZrbX/Awr1L8ZgJrFSpaahHOUA006fM=; fh=wqGtaQRaft9D0zUHMyMQXhnocNBrwjPdMyctoUHVbL0=; b=mgdfL7/OrIVNbZaXa9unPwqm8SS2tnjdIveki4+gA6+M5dvrq3d1O0K+CMUHWlhu0Z TBphNer+IQm4GcThPqvXNSyC9YbsiAesW8gDSxEmlrY5LIQ8BT9zEI2a0DAyGcV8y1cB 57P/xXYq7pc9P8Ni+EAbfe2QmEISVtg/HSyByaryxAiaA9UwQJj/Yl8gOxLZfIspw8Ge pq4hHHPbJJiwvnikr6tkg0BQ5TzzvsSOBSzVmWKfGmRYfd6Bh9bjYDeFtE6AboGrJLDq +MnLvB9K5/Lj2sTgS+zVIrVqeBAkUqAeZB+bm1VYp+gedGt7le9OOAZEoFvLVSNAEbCd 0alA==; 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-149912-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-149912-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. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id k145-20020a628497000000b006ecfc9da8c3si1272402pfd.49.2024.04.18.03.51.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Apr 2024 03:51:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-149912-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; 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-149912-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-149912-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 37E842823E0 for ; Thu, 18 Apr 2024 10:51:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8997B15E5B0; Thu, 18 Apr 2024 10:50:42 +0000 (UTC) Received: from smtpbgau2.qq.com (smtpbgau2.qq.com [54.206.34.216]) (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 2AC9615E217; Thu, 18 Apr 2024 10:50:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=54.206.34.216 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713437442; cv=none; b=JeCTJvJZAK23qYndQKvAwCxPE2vWC8sxtYYl/wtiLUOLIRA4JEjEgHWKmn8Ykb9zYwoOP1QJSASQAieebJ528CYDU4iOWxc2PKsaeS1Lfhtvewsb+21VURsVOI967IZ/fwrHFEsB28khRzPa5yMS/TeEVgnIcwGRXpZkdZkKaA0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713437442; c=relaxed/simple; bh=QCiswgDcN2bu7vT24ZZH99mPoKGsyGfGASAPrK1ZAqg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=VTdAgbRMEtGbBTqGFsIJ8kb0rsemu394dhy8KNch7WmQVdCWcUji5n0PSr2/W3qC8WPmk8C3Y8dfaqSeY8NfSNWVS/R0wNyYMvQ1pjE2Yv7rZK2GUiN9j/PGQUaM1SfQ3W2Vahkj/9IaJSZbo5fKasHPcsTzc8mWUWFCaWQURNk= 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.206.34.216 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: bizesmtp82t1713437406t45jvzb7 X-QQ-Originating-IP: pEXvRM19b7upCM+fX9YdXWbEzjRXRZIJQhdLs2Q5RBM= Received: from localhost ( [112.0.147.129]) by bizesmtp.qq.com (ESMTP) with id ; Thu, 18 Apr 2024 18:50:05 +0800 (CST) X-QQ-SSF: 01400000000000903000000A0000000 X-QQ-FEAT: 7YFKcddXaggfOZmy1nBedkwTPeeppd0uj9KwyxJOD37uhSD0tytPREuyoB+QB G4XjMxb0W6DCZrZHw8Z4rnFNCPeV233kpQUjFNNOcoh5wWgZXRndIb/Lrg5x9Xe0Y7la+pr tGLd3NCCWFluxBKN9pFWCzCayoTEBbNeUXWPbGE55YDcJ6Zg6eNvoM9039hAAHt/M61RA33 wu/OM8Ln/+YchbXAZt2s7V/wbNvtwbo7wSSF/gK6PhpwR37vryHA1ENh/xtZSd9wbYJSXlk bvuOsk3r2UY90P8zB1mBg9WPEExQkc6De4RHQu16wrzrWFTM2wImWRpl1tZu4DgbA8wh9W2 M9eKUKcZs8vFM9rhh1EX4RNNoAifAHKSEVVsaZsTW+T8RooMWMEQeVAXQCexpwqCqc1C7JC BEYh4Tt+heWpO9eDjGd1Iw== X-QQ-GoodBg: 2 X-BIZMAIL-ID: 9509053346379215880 From: Dawei Li To: davem@davemloft.net, andreas@gaisler.com Cc: sparclinux@vger.kernel.org, linux-kernel@vger.kernel.org, Dawei Li Subject: [PATCH 1/5] sparc/srmmu: Remove on-stack cpumask var Date: Thu, 18 Apr 2024 18:49:45 +0800 Message-Id: <20240418104949.3606645-2-dawei.li@shingroup.cn> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240418104949.3606645-1-dawei.li@shingroup.cn> References: <20240418104949.3606645-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. 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..86fd20c878ae 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 cpumask_any_but_current(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 (cpumask_any_but_current(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 (cpumask_any_but_current(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 (cpumask_any_but_current(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 (cpumask_any_but_current(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 (cpumask_any_but_current(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 (cpumask_any_but_current(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 (cpumask_any_but_current(mm)) xc2(local_ops->sig_insns, (unsigned long)mm, insn_addr); local_ops->sig_insns(mm, insn_addr); } -- 2.27.0