From patchwork Mon Jul 18 19:28:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 12921669 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 E2D77C433EF for ; Mon, 18 Jul 2022 19:29:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6BC53940007; Mon, 18 Jul 2022 15:28:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 670CB94000D; Mon, 18 Jul 2022 15:28:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2A5F1940007; Mon, 18 Jul 2022 15:28:59 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 13A7A940007 for ; Mon, 18 Jul 2022 15:28:59 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay13.hostedemail.com (Postfix) with ESMTP id DA22760B5C for ; Mon, 18 Jul 2022 19:28:58 +0000 (UTC) X-FDA: 79701208356.29.C12B2FF Received: from mail-qt1-f176.google.com (mail-qt1-f176.google.com [209.85.160.176]) by imf11.hostedemail.com (Postfix) with ESMTP id 779D240093 for ; Mon, 18 Jul 2022 19:28:58 +0000 (UTC) Received: by mail-qt1-f176.google.com with SMTP id c20so9503751qtw.8 for ; Mon, 18 Jul 2022 12:28:58 -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=3XYQv40S3S5GPzbQg2pMTtfGv4eD74y+tQ/YBLA8hPI=; b=TByPl+Xwiw2xqd6sHhrukw9bBi6aYZ9/z4hJI5n//rUO3S0J3LYVyW846tuoecx0/P +mwSlwBGZWSeexadVQp08LKtTu3yhD9GwqRpcIaZI+JTvwBTqsldLUYP7cMYJCj0qmee qzWvSzxAj6hHk8lfZ/znqRQjr8YYK6LhI35e/XjH607M4tjQzo2HZoBMdEmvG4Au2nUw 7VRp/BbOQlyMaiQHsMqpMueyXN70vJlljWT7heZMwoRcxsr+t7a84MhXDH0oqg1RW59u ELUqUPatBeLpVq9tLx/9dMB7Lb9eBn1unJzFEZ12o7YFpej8nHIclhzYzEdXcPOn0e7U PU/w== 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=3XYQv40S3S5GPzbQg2pMTtfGv4eD74y+tQ/YBLA8hPI=; b=VFpM05ulAfTIr8oB7J2opjyENoaqEcpNTcX0ctWSgpISTmzdyhD2QH8uwrGlTft+9p hlZwBccs3GVz4Qwyqa3Vpt7J6V9gAEH+h52rBAbJz0LXtJwuLuSTBVA7PRulvvbUTTEV gJEjD34So1kAD3L7yTzP/AcbnpXy9aP+NdfVhZP0mmyKBXpPUl7nBqu7tw1wyWHhPSXu HdfKR35j/zAJggWdoNImTpPR8+BX1lDXZQIvmPA3KWuiEE6WOEpUFsRSsRQHhdkR0kYE MuKcRnhSz/RKmpB8/n6vc0QMvLAEzUT2Uv4xJgg7DLdeiitLmGT/fxgysJds5i5Meh0m oklA== X-Gm-Message-State: AJIora8SLieGXrRHG5nRGA5UNUF9cvx3vtC99bVuz1rYhfUcqwJ2ch+I VeoVFQriBGSxrHNAqczIZV4= X-Google-Smtp-Source: AGRyM1sbR5MtKZUL9t8F0KGlqcEkHR0jVinkErRs9JvmFXVZhVXEvlih/lkWGgZ5SUq5r6VMJWzeKg== X-Received: by 2002:ac8:5cca:0:b0:31e:f51f:dd97 with SMTP id s10-20020ac85cca000000b0031ef51fdd97mr3070736qta.47.1658172538023; Mon, 18 Jul 2022 12:28:58 -0700 (PDT) Received: from localhost ([2601:4c1:c100:1230:ab01:d009:465a:5ab1]) by smtp.gmail.com with ESMTPSA id m13-20020ac8688d000000b0031bf484079esm8937407qtq.18.2022.07.18.12.28.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Jul 2022 12:28:57 -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 10/16] sched: optimize __set_cpus_allowed_ptr_locked() Date: Mon, 18 Jul 2022 12:28:38 -0700 Message-Id: <20220718192844.1805158-11-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=1658172538; a=rsa-sha256; cv=none; b=XhitkIX5OWRmdogOSsD/9qW5cOBI7BHykXH0gPkf7YhjT4HDcXzD1wEsm+34q2NtkiORYx zYs5iaInF7rAKTzei5k40N7T2tKtQFXke+4S8UjRzUhNimOtJk/KOP6D9b5HmW4j7jGnfW XAcAE4HHowU5D8qttViaWmSe/F0EWro= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=TByPl+Xw; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf11.hostedemail.com: domain of yury.norov@gmail.com designates 209.85.160.176 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=1658172538; 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=3XYQv40S3S5GPzbQg2pMTtfGv4eD74y+tQ/YBLA8hPI=; b=RM0Dyzxdub6TqGKMfbg7maHepWPc8QLod1Sf1teB14x9T0nl122V0Sv9ycGmrk1zMB9pJm vSHG9YefINgoRELls6bskSVPUTjjKFxA09g+hmzEluIheAyE+dk87EnPlCrjz2QTsSoGSy G/5OWlENow2QXDqKKBlp8+Jvucc3w2U= X-Rspam-User: Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=TByPl+Xw; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf11.hostedemail.com: domain of yury.norov@gmail.com designates 209.85.160.176 as permitted sender) smtp.mailfrom=yury.norov@gmail.com X-Rspamd-Queue-Id: 779D240093 X-Rspamd-Server: rspam12 X-Stat-Signature: gx48rxuuaechhob7f543wkmkttxkddk5 X-HE-Tag: 1658172538-544695 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: Don't call cpumask_subset(new_mask, cpu_allowed_mask) if new_mask is cpu_allowed_mask. Caught with CONFIG_DEBUG_BITMAP: [ 0.132174] Call trace: [ 0.132189] __bitmap_check_params+0x144/0x250 [ 0.132216] __set_cpus_allowed_ptr_locked+0x8c/0x2c0 [ 0.132241] sched_init_smp+0x80/0xd8 [ 0.132273] kernel_init_freeable+0x12c/0x28c [ 0.132299] kernel_init+0x28/0x13c [ 0.132325] ret_from_fork+0x10/0x20 [ 0.132354] ---[ end trace 0000000000000000 ]--- [ 0.132378] b1: ffffcd0c07819a58 [ 0.132388] b2: ffffcd0c07819a58 [ 0.132397] b3: 0 [ 0.132405] nbits: 256 [ 0.132414] start: 0 [ 0.132422] off: 0 [ 0.132444] Bitmap: parameters check failed [ 0.132467] include/linux/bitmap.h [468]: bitmap_subset Signed-off-by: Yury Norov --- kernel/sched/core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index da0bf6fe9ecd..d6424336ef2d 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -2874,7 +2874,8 @@ static int __set_cpus_allowed_ptr_locked(struct task_struct *p, cpu_valid_mask = cpu_online_mask; } - if (!kthread && !cpumask_subset(new_mask, cpu_allowed_mask)) { + if (!kthread && new_mask != cpu_allowed_mask && + !cpumask_subset(new_mask, cpu_allowed_mask)) { ret = -EINVAL; goto out; }