From mboxrd@z Thu Jan 1 00:00:00 1970 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7651CC6FD1D for ; Tue, 14 Mar 2023 22:41:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231294AbjCNWlw (ORCPT ); Tue, 14 Mar 2023 18:41:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230514AbjCNWlu (ORCPT ); Tue, 14 Mar 2023 18:41:50 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 5170D37F3D for ; Tue, 14 Mar 2023 15:41:48 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 715C12F4; Tue, 14 Mar 2023 15:42:31 -0700 (PDT) Received: from [10.57.64.116] (unknown [10.57.64.116]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 0F8C43F64C; Tue, 14 Mar 2023 15:41:46 -0700 (PDT) Message-ID: <7d026744-6bd6-6827-0471-b5e8eae0be3f@arm.com> Date: Tue, 14 Mar 2023 22:41:45 +0000 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.8.0 Content-Language: en-US From: Ryan Roberts To: Linus Torvalds , Yury Norov Cc: Linux Kernel Mailing List , linux-arm-kernel@lists.infradead.org Subject: [BUG] v6.3-rc2 regresses sched_getaffinity() for arm64 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Linus, I need to report a regression in v6.3-rc2 where sched_getaffinity() returns an incorrect cpu_set, at least when running on arm64. Git bisect shows this patch as the culprit, authored by you: 596ff4a09b89 cpumask: re-introduce constant-sized cpumask optimizations Apologies if this is the wrong channel for reporting this - I couldn't find a suitable mail on the list for this patch to reply to. Happy to direct it somewhere else if appropriate. Details: I'm running v6.3-rc2 kernel in a VM on Ampere Altra (arm64 system). The VM is assigned 8 vCPUs. The kernel is defconfig and I'm booting into an Ubuntu user-space. `nproc` returns a value that fluctuates from call to call in the range ~80-100. If I run with v6.2, nproc always returns 8, as expected. nproc is calling sched_getaffinity() with a 1024 entry cpu_set mask, then adds up all the set bits to find the number of CPUs. I wrote a test program and can see that the first 8 bits are always correctly set and most of the other bits are always correctly 0. But bits ~64-224 are randomly set/clear from call to call. Test program: #define _GNU_SOURCE /* See feature_test_macros(7) */ #include #include #define SET_SIZE 1024 static void print_cpu_set(cpu_set_t *cpu_set) { int ret, i, j, k; printf("cpu_count=%d\n", CPU_COUNT(cpu_set)); for (i = 0; i < SET_SIZE;) { printf("[%03d]: ", i); for (k = 0; k < 8; k++) { for (j = 0; j < 8; j++, i++) { printf("%d", CPU_ISSET(i, cpu_set)); } printf(" "); } printf("\n"); } } int main() { int ret; cpu_set_t *cpu_set; size_t size; cpu_set = CPU_ALLOC(SET_SIZE); size = CPU_ALLOC_SIZE(SET_SIZE); CPU_ZERO(cpu_set); printf("before:\n"); print_cpu_set(cpu_set); ret = sched_getaffinity(0, size, cpu_set); printf("ret=%d\n", ret); printf("after:\n"); print_cpu_set(cpu_set); return 0; } Broken output on v6.3-rc2: before: cpu_count=0 [000]: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [064]: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [128]: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [192]: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [256]: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [320]: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [384]: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [448]: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [512]: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [576]: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [640]: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [704]: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [768]: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [832]: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [896]: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [960]: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 ret=0 after: cpu_count=82 [000]: 11111111 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [064]: 00000100 10110111 00110010 01101001 11111111 11111111 00000000 00000000 [128]: 00010101 00001101 11011111 10001110 11110001 10100101 11111111 11111111 [192]: 00000000 00001000 00000000 00000100 00000000 00000000 00000000 00000000 [256]: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [320]: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [384]: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [448]: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [512]: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [576]: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [640]: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [704]: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [768]: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [832]: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [896]: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [960]: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 Correct output in v6.2: before: cpu_count=0 [000]: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [064]: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [128]: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [192]: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [256]: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [320]: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [384]: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [448]: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [512]: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [576]: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [640]: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [704]: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [768]: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [832]: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [896]: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [960]: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 ret=0 after: cpu_count=8 [000]: 11111111 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [064]: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [128]: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [192]: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [256]: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [320]: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [384]: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [448]: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [512]: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [576]: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [640]: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [704]: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [768]: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [832]: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [896]: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [960]: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 Thanks, Ryan