From patchwork Mon Jul 18 19:28:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 12921666 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 39D3DC433EF for ; Mon, 18 Jul 2022 19:29:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 61FCC94000A; Mon, 18 Jul 2022 15:28:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5D104940007; Mon, 18 Jul 2022 15:28:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 470C494000A; Mon, 18 Jul 2022 15:28:57 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 35D23940007 for ; Mon, 18 Jul 2022 15:28:57 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 0C5E520B05 for ; Mon, 18 Jul 2022 19:28:57 +0000 (UTC) X-FDA: 79701208314.14.4E8F5E9 Received: from mail-qt1-f170.google.com (mail-qt1-f170.google.com [209.85.160.170]) by imf16.hostedemail.com (Postfix) with ESMTP id B2B01180049 for ; Mon, 18 Jul 2022 19:28:56 +0000 (UTC) Received: by mail-qt1-f170.google.com with SMTP id y9so6164428qtv.5 for ; Mon, 18 Jul 2022 12:28:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=RIuxtr8d+TB6goTZIrQnEqj0NYsoVNuGdOrD+16hKvE=; b=K6FLy4kdLZiOyB3bLUhszl5Zd1puGwKh81hdQ6rMAxhulKYqedp7eUmoIZR0afJcpb nkiXT9uXP0O9WHgoCSQ2IR/sDvIeb+YkvalAFfr8I5dYLsp+gO1RFi5HdpTv9xwEjdQ2 auToBt5qQGIID9AHzaDc+sYfyIwWA0/KGjjZxYfmJ39gMRAk2oUkonyTSXkmCxoD4Fux yUPBSSyh4zYo4dxNsy901oFcH5LCqM2CA0xbWm/ZpSmbLWp+HfPmCnB1q1t1r0vv+BNU aNYNiAkMVnc3um9vm7dDymoR9WWvElT0wUSR1fdH1muLCWOWVQ3EyjMKXAO1Br2kBR00 Vx+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=RIuxtr8d+TB6goTZIrQnEqj0NYsoVNuGdOrD+16hKvE=; b=R41BV6851LgjoYP6fEGhbOCGd1X/gm50QHwJaqo6oMfCKFN1QPS/CGAZ+EuQmHoL5y eFReWVLVSFwvFK1OHlao8om9VZ++gsad+hWwrQZAiSAfcjSc55uE1h9PJt+7gEhSkgq1 IALuMGHjwOsIqBVyrlL4COjrQQOSvB7NfSd7wcEFU3JUT8pz/ghNBnvRfyrj+E3gojmC 4n7fwJSmcYGWvnp0qMWTr9ZbMLExTaWqprRiuzS6Qpf5P2ez34LBDbJv1NWk7ylvz3Q6 QHCLDvUS5ACoNeZ8/nFf9b8Nygj/leCTRU6oYesR9uIUleppCSQSEA2H3HD/EzQwg8PP 952g== X-Gm-Message-State: AJIora8lIfKePypDhmk7deAqDw4Qi+xIMf/VF3UOrEd2O0V/u6n5g9Un h7bMvYbzku/fPW2b7biMZ94= X-Google-Smtp-Source: AGRyM1t1sw1jCN1ieW37kpkYQIAyMtVdPUyvBuYOD3/FMPrCUNrO4liqD1XLniGG0iHGpMVX+tZbUg== X-Received: by 2002:ac8:7e89:0:b0:31e:e0dd:9084 with SMTP id w9-20020ac87e89000000b0031ee0dd9084mr10850238qtj.37.1658172535998; Mon, 18 Jul 2022 12:28:55 -0700 (PDT) Received: from localhost ([2601:4c1:c100:1230:ab01:d009:465a:5ab1]) by smtp.gmail.com with ESMTPSA id bi14-20020a05620a318e00b006b5f85f8fa8sm1114706qkb.125.2022.07.18.12.28.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Jul 2022 12:28:55 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org, Alexander Lobakin , Alexei Starovoitov , Alexey Klimov , Andrew Morton , Andrii Nakryiko , Andy Shevchenko , Ben Segall , Christoph Lameter , Dan Williams , Daniel Borkmann , Daniel Bristot de Oliveira , Dennis Zhou , Dietmar Eggemann , Eric Dumazet , Frederic Weisbecker , Guenter Roeck , Ingo Molnar , Isabella Basso , John Fastabend , Josh Poimboeuf , Juergen Gross , Juri Lelli , KP Singh , Kees Cook , Martin KaFai Lau , Mel Gorman , Miroslav Benes , Nathan Chancellor , "Paul E . McKenney" , Peter Zijlstra , Randy Dunlap , Rasmus Villemoes , Sebastian Andrzej Siewior , Song Liu , Steven Rostedt , Tejun Heo , Thomas Gleixner , Valentin Schneider , Vincent Guittot , Vlastimil Babka , Yonghong Song , Yury Norov , linux-mm@kvack.org, netdev@vger.kernel.org, bpf@vger.kernel.org Subject: [PATCH 08/16] smp: optimize smp_call_function_many_cond() for more Date: Mon, 18 Jul 2022 12:28:36 -0700 Message-Id: <20220718192844.1805158-9-yury.norov@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220718192844.1805158-1-yury.norov@gmail.com> References: <20220718192844.1805158-1-yury.norov@gmail.com> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1658172536; a=rsa-sha256; cv=none; b=Qp6Ycg9BXbhV7WVEzcCgpoEYOdFjQDSXKv+XvyR045eh8C8wutLvKUsoa00oGo5Xqi5PUR sJDSh1eehiBSE0OdwghxcxJZjGsMIwLhz/GjGw9VYzDxYhp3Ei1PJSiRK+nSU0Qv0XmYvO 2G/DQT4jxmZ/azW1Fs9Ejth0gkKGK/k= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=K6FLy4kd; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf16.hostedemail.com: domain of yury.norov@gmail.com designates 209.85.160.170 as permitted sender) smtp.mailfrom=yury.norov@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1658172536; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=RIuxtr8d+TB6goTZIrQnEqj0NYsoVNuGdOrD+16hKvE=; b=z47Ffhi5GRsNrSXZDPCwrWWD6843GKrzT17A62AabHpwxAHZpHq4HUACboWTg+ILjeanQ9 nIF/8B5fqf77zfqlYVeZQ3QwzEbtF3XltbMYrzEZzyRvv4RCIHFLd0Yu5FcGUch8Fpc+0C ylUEK5KWEQ2viWOaNw2PPpH9BLPWG6Y= X-Rspamd-Queue-Id: B2B01180049 X-Rspam-User: Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=K6FLy4kd; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf16.hostedemail.com: domain of yury.norov@gmail.com designates 209.85.160.170 as permitted sender) smtp.mailfrom=yury.norov@gmail.com X-Rspamd-Server: rspam08 X-Stat-Signature: w5dhnk69bfdqo46gym3s8aoh1yo1nz1e X-HE-Tag: 1658172536-637056 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: smp_call_function_many_cond() is often passed with cpu_online_mask. If it's the case, we can use cpumask_copy instead of cpumask_and, which is faster. Caught with CONFIG_DEBUG_BITMAP: [ 7.830337] Call trace: [ 7.830397] __bitmap_check_params+0x1d8/0x260 [ 7.830499] smp_call_function_many_cond+0x1e8/0x45c [ 7.830607] kick_all_cpus_sync+0x44/0x80 [ 7.830698] bpf_int_jit_compile+0x34c/0x5cc [ 7.830796] bpf_prog_select_runtime+0x118/0x190 [ 7.830900] bpf_prepare_filter+0x3dc/0x51c [ 7.830995] __get_filter+0xd4/0x170 [ 7.831145] sk_attach_filter+0x18/0xb0 [ 7.831236] sock_setsockopt+0x5b0/0x1214 [ 7.831330] __sys_setsockopt+0x144/0x170 [ 7.831431] __arm64_sys_setsockopt+0x2c/0x40 [ 7.831541] invoke_syscall+0x48/0x114 [ 7.831634] el0_svc_common.constprop.0+0x44/0xfc [ 7.831745] do_el0_svc+0x30/0xc0 [ 7.831825] el0_svc+0x2c/0x84 [ 7.831899] el0t_64_sync_handler+0xbc/0x140 [ 7.831999] el0t_64_sync+0x18c/0x190 [ 7.832086] ---[ end trace 0000000000000000 ]--- [ 7.832375] b1: ffff24d1ffd98a48 [ 7.832385] b2: ffffa65533a29a38 [ 7.832393] b3: ffffa65533a29a38 [ 7.832400] nbits: 256 [ 7.832407] start: 0 [ 7.832412] off: 0 [ 7.832418] smp: Bitmap: parameters check failed [ 7.832432] smp: include/linux/bitmap.h [363]: bitmap_and Signed-off-by: Yury Norov --- kernel/smp.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/kernel/smp.c b/kernel/smp.c index 7ed2b9b12f74..f96fdf944b4a 100644 --- a/kernel/smp.c +++ b/kernel/smp.c @@ -942,7 +942,11 @@ static void smp_call_function_many_cond(const struct cpumask *mask, if (run_remote) { cfd = this_cpu_ptr(&cfd_data); - cpumask_and(cfd->cpumask, mask, cpu_online_mask); + if (mask == cpu_online_mask) + cpumask_copy(cfd->cpumask, cpu_online_mask); + else + cpumask_and(cfd->cpumask, mask, cpu_online_mask); + __cpumask_clear_cpu(this_cpu, cfd->cpumask); cpumask_clear(cfd->cpumask_ipi);