Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp93904imn; Fri, 29 Jul 2022 00:17:11 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tOj0s8ubH9Tv6th7H8Xa5E9qCSTAoAKKOM0hBLxMfR4Z+AqRR4MAwzboiKNP16u0YYrC5z X-Received: by 2002:aa7:94b4:0:b0:52b:b93b:95e9 with SMTP id a20-20020aa794b4000000b0052bb93b95e9mr2136112pfl.31.1659079031717; Fri, 29 Jul 2022 00:17:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659079031; cv=none; d=google.com; s=arc-20160816; b=OZhTX4k+ojggYwc7DBiGLCyRDiBAIpyBh3slYeITDfeVSmwqGSYqInjbe8Wjmm9Cte w8mGQ7Bcaq5K8jRJni2LE+ARlZ7ctB/mz2xJh5e+a2VQ0Xs3Kaz7yYIVdP273l8g7L05 tpbc6JPXygGoMj6kpo0JzvD5gyObyqjeoVdshnx6m23wMwKxDRZOZ7DoSixaiZ1vvcwC U9LEDRyJAT6jzYx+yPnlBDijBX+Kwt/FMRUzNxGjOnDB9TgLTmKRyMxBlubxpZm3x433 q5US+K46HauQNHqWsBrzZLSZpvasJXkD7yZzAH58NxpviYtk3VW53/WH4w/AdjmO4IIA QubA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=J/enTjqwQ6ehBMZ4hE1b6W8ThYSd1GY4baEv+hNepcQ=; b=Y/xglB5x1nIXFU4apaIFet1e2r1mJHhZODJYvf9khOtP0MlTSRt6HL6ndABBCrRNKm qzh+cJz9tJfXZd+TTUYsQ1CnAbpMkbzGee5VFKCCRwiPIqmHUe3IOIMf3tSLsW2hgO5A iN9fNigWlOdhAUCnu6Zrk8Ffve67vU1G4JdLTlA4G/ZZ3+mJOYGX6ZIRxDfVy83oUdAF wjiWaKmqkIIvGN4P85eAdRmJF+bNZlhLkR1ePE2BbGOcvA7ks1iQcNzeBZbvc38CNsoh O8GDoq07vKAATizs5SMdLa8XlF+BEy94mrnHJHWKnZQOpTxCrYRsZzpL6cICaJJJ0X3P QgUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@svanheule.net header.s=mail1707 header.b=u21q9ipj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=svanheule.net Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q3-20020a17090311c300b0016d6a067437si3641333plh.419.2022.07.29.00.16.52; Fri, 29 Jul 2022 00:17:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@svanheule.net header.s=mail1707 header.b=u21q9ipj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=svanheule.net Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233985AbiG2HBj (ORCPT + 99 others); Fri, 29 Jul 2022 03:01:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229973AbiG2HBi (ORCPT ); Fri, 29 Jul 2022 03:01:38 -0400 Received: from polaris.svanheule.net (polaris.svanheule.net [84.16.241.116]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D08272F39D for ; Fri, 29 Jul 2022 00:01:35 -0700 (PDT) Received: from terra.. (unknown [IPv6:2a02:a03f:eaf9:8401:aa9f:5d01:1b2a:e3cd]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: sander@svanheule.net) by polaris.svanheule.net (Postfix) with ESMTPSA id AF672302C2B; Fri, 29 Jul 2022 09:01:31 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=svanheule.net; s=mail1707; t=1659078092; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=J/enTjqwQ6ehBMZ4hE1b6W8ThYSd1GY4baEv+hNepcQ=; b=u21q9ipjDdR8JP3owajA06bnZHsjqv2mVp6Dj2nGJfa9uSTXFXFba4JgbABjlx/Yl25C/A yfoERyj1fFhOC1MSipyqV9UBWCrR/rD4mQJAXcF7jJnvM9Ll78y0lUg3BPTluWn07PceD/ mkSFlaWLGa9cUVW3gwH+YH8uvFtFQIgNAbucBt/5WMHK2xb/fBvWdSflZ6qs+Un2VsxJhr sSz8YvwLuuOqxfSdiXSLHHVvauZcxDSn93cQdnipQB+2XVyznalU/6DfOU1HDB1KhoC9GQ 69A7/x6QrwnuX3OsEg2Et4u2WUg0qgd9l7e2lOyX5mSG+wknM1VhnlGL97tWYA== From: Sander Vanheule To: linux-kernel@vger.kernel.org, Andrew Morton Cc: Andy Shevchenko , Brendan Higgins , Dave Hansen , David Gow , Borislav Petkov , Greg Kroah-Hartman , "H . Peter Anvin" , Ingo Molnar , =?UTF-8?q?Ma=C3=ADra=20Canal?= , Marco Elver , Peter Zijlstra , Thomas Gleixner , Valentin Schneider , Yury Norov , Sander Vanheule Subject: [PATCH v5 0/5] cpumask: fix invalid uniprocessor assumptions Date: Fri, 29 Jul 2022 09:01:17 +0200 Message-Id: X-Mailer: git-send-email 2.37.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_PASS, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On uniprocessor builds, it is currently assumed that any cpumask will contain the single CPU: cpu0. This assumption is used to provide optimised implementations. The current assumption also appears to be wrong, by ignoring the fact that users can provide empty cpumasks. This can result in bugs as explained in [1] - for_each_cpu() will run one iteration of the loop even when passed an empty cpumask. This series introduces some basic tests, and updates the optimisations for uniprocessor builds. The x86 patch was written after the kernel test robot [2] ran into a failed build. I have tried to list the files potentially affected by the changes to cpumask.h, in an attempt to find any other cases that fail on !SMP. I've gone through some of the files manually, and ran a few cross builds, but nothing else popped up. I (build) checked about half of the potientally affected files, but I do not have the resources to do them all. I hope we can fix other issues if/when they pop up later. [1] https://lore.kernel.org/all/20220530082552.46113-1-sander@svanheule.net/ [2] https://lore.kernel.org/all/202206060858.wA0FOzRy-lkp@intel.com/ Changes since v4: Link: https://lore.kernel.org/all/cover.1656777646.git.sander@svanheule.net/ - Move new for_each_*_cpu() optimisations ahead, so they come before the fixes. - Update test cases for cpu_possible_mask for nr_cpu_ids < CONFIG_NR_CPUS - Improve KUnit style compliance on tests - Collect tags and add Cc: tags Changes since v3: Link: https://lore.kernel.org/all/cover.1654410109.git.sander@svanheule.net/ - Guard against CPU hotplugging while testing cpu online/present masks - Add fix for cpu_llc_shared_map on x86 Changes since v2: Link: https://lore.kernel.org/all/cover.1654362935.git.sander@svanheule.net/ - Put new tests after patch fixes - Update for_each_* macros Changes since v1: Link: https://lore.kernel.org/all/cover.1654201862.git.sander@svanheule.net/ - Place tests in lib/test_cpumask.c - Drop the modified UP code in favor of the generic SMP implementation - Update declaration of cpumask_next_wrap() Sander Vanheule (5): x86/cacheinfo: move shared cache map definitions cpumask: add UP optimised for_each_*_cpu versions cpumask: fix invalid uniprocessor mask assumption lib/test: introduce cpumask KUnit test suite cpumask: update cpumask_next_wrap() signature arch/x86/kernel/cpu/cacheinfo.c | 6 ++ arch/x86/kernel/smpboot.c | 4 - include/linux/cpumask.h | 108 ++++++----------------- lib/Kconfig.debug | 12 +++ lib/Makefile | 4 +- lib/cpumask.c | 2 + lib/cpumask_test.c | 147 ++++++++++++++++++++++++++++++++ 7 files changed, 196 insertions(+), 87 deletions(-) create mode 100644 lib/cpumask_test.c -- 2.37.1