Received: by 2002:a05:6358:111d:b0:dc:6189:e246 with SMTP id f29csp446718rwi; Mon, 31 Oct 2022 03:38:01 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7brTC7VgF+4jYhOfZ7RnoLDYMlz5feujks0fZvESsn5we46TBbKUaDQxG/UezC9n4kRUeH X-Received: by 2002:a17:907:7f8e:b0:7aa:7598:126d with SMTP id qk14-20020a1709077f8e00b007aa7598126dmr12557826ejc.289.1667212681003; Mon, 31 Oct 2022 03:38:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667212680; cv=none; d=google.com; s=arc-20160816; b=FR+1yaSQ5v/liKEUrSdOtK848yECKlBQAl4PlhQRnk7BKuXiY1eJEmYbmySbv5ouLp F4gD2NZhAaqEX8TZ32HxiF9snGpUFiHSD+BUYQ8CyYStO9PXyGJTB2v8V8hOM9xAa7EY bqE4z/iLR1MB1Jn4EyJ/jmHDV5NMyODFDFQbgX6IUDRUB0GlMZ5+T5QxDNbrGluyxCMD +E6eGyESzZGnmViKs1eH6DFiXcQAIKJsgQLAz+iNid1mAURmAuWFRAlodPGENjj3qeQZ hBepL3FPNM+HC82DKZvnS2rmd/ymSwtn8kop3lFzrNN1wStVcdfuDPA7oyKOwbIwoyTx wU2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=Ij0opVplOZ4JlIp6K8xwI+xLgpGAyEZHWtU1AyZKEUo=; b=AvLhstBx8y/SE0bcTV6MNFSDuA8O9nwRrRcFlh3n8YKf48dU3iAn0yEqqOv/rNhFhY cRLvhiISpBncaP+bbozsAiozuMiMYO3cCavRL2xvux1O/iqzCQkm0UBju7V4uxRIr4hZ 9vrQTddUKVkWeeHYUO79HrL7WOU5JPkN7ybSC4UDhFWJaWl9BTXPWlJ5JKmD15fktT/6 mwMrbbU4sznnfoQpXq7kX8A2fMrmjIcC/xQSPLB0SSnt0FRqQfMnq/Y2Nl3mTpF1+bhV yQXAJCASV2eoBjOrzPDSr9wo5y7R4kakMCd8G3If13zOWL+GvGjvwuF1Rm2GLbkbmSfZ 0RGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=NVMInip0; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hd37-20020a17090796a500b0079bf804c0c4si9164743ejc.103.2022.10.31.03.37.37; Mon, 31 Oct 2022 03:38:00 -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=@ventanamicro.com header.s=google header.b=NVMInip0; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229718AbiJaKDd (ORCPT + 99 others); Mon, 31 Oct 2022 06:03:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60190 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229505AbiJaKDb (ORCPT ); Mon, 31 Oct 2022 06:03:31 -0400 Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AF3789FD0 for ; Mon, 31 Oct 2022 03:03:30 -0700 (PDT) Received: by mail-ej1-x62f.google.com with SMTP id n12so27980097eja.11 for ; Mon, 31 Oct 2022 03:03:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=Ij0opVplOZ4JlIp6K8xwI+xLgpGAyEZHWtU1AyZKEUo=; b=NVMInip05i3j2Mewd8/9DA5VH9moDODkHGKksq2V35DG4ZziDSBIvUuAT9vkgpRf0d 21cfnb+Ic7yb0fKpaQko2/3X06kq6xe/XCHQEYDl6OhLI2/0FrdGqDZUQd1J7/senkcv DOl89eFWBJftp3vto1gh5cWgUBeCTuph9SIKiz0krDlDYUjX/89nzBZ1SkCF6yXeBQ5L oy/FLx+eyQ0Wt0BTeHJp3vkdt0LtCHU4KDi4RBqwOyUiIBl9/k/dAugnydtOxw9EUUT/ ArMtYe3iEM2RkUy0/xdIxnvFPevgupjBBbMoUxHQvvlem6IUyPz4BSgqjGCJMagdWnvZ oKCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=Ij0opVplOZ4JlIp6K8xwI+xLgpGAyEZHWtU1AyZKEUo=; b=0j70KPmh+LzbZtTVjrr/AHPs/sOVjC86eqBtQ8+OJD8G400CSnoVqx6te8Eo/2vOGJ mYEw4HjQUsxg4ekbciASytWoQ4KgDvHP2btFmTDn5y4p1BzOatk+9USkuCoPjabBopLc RuIpeQ7BXfdNbFuI07+6KHAf430iAnPEJKw0R6d0CFGXiH5FnCJvLnuTBVj9fuiHTNUt 8bUcvBWVK6UF2gpqahurl8b9nfbhJvNBhZEnVW6qHeR8qEXeufmfbOa82dOtUbtvOKSW 1mGXRVaSlhnICE+CbKKkrqEOBSg/sIcgAAlwjkucvFiPmQAodtnPvbgCU7E3jWlCXmgL StWA== X-Gm-Message-State: ACrzQf16O3RlpAzjsH9AX7CtmngHU8MdH2m38JALvHUpm1n20sA2okgK +d3F+/0M5Q1UD1oz1OvvuWu3YA== X-Received: by 2002:a17:906:9745:b0:78d:480f:cee7 with SMTP id o5-20020a170906974500b0078d480fcee7mr11952970ejy.192.1667210609260; Mon, 31 Oct 2022 03:03:29 -0700 (PDT) Received: from localhost (cst2-173-61.cust.vodafone.cz. [31.30.173.61]) by smtp.gmail.com with ESMTPSA id eh22-20020a0564020f9600b00461bacee867sm3048302edb.25.2022.10.31.03.03.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Oct 2022 03:03:28 -0700 (PDT) Date: Mon, 31 Oct 2022 11:03:27 +0100 From: Andrew Jones To: Borislav Petkov Cc: Yury Norov , x86@kernel.org, linux-riscv , Linux Kernel Mailing List , Thomas Gleixner , Ingo Molnar , Dave Hansen , Palmer Dabbelt , Paul Walmsley , Albert Ou , Jonas Bonn , Stefan Kristiansson , Stafford Horne , openrisc@lists.librecores.org, Michael Ellerman , "open list:LINUX FOR POWERPC PA SEMI PWRFICIENT" , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , linux-s390@vger.kernel.org Subject: Re: [PATCH v3 2/2] x86: Fix /proc/cpuinfo cpumask warning Message-ID: <20221031100327.r7tswmpszvs5ot5n@kamzik> References: <20221014155845.1986223-1-ajones@ventanamicro.com> <20221014155845.1986223-3-ajones@ventanamicro.com> <20221028074828.b66uuqqfbrnjdtab@kamzik> <20221031080604.6xei6c4e3ckhsvmy@kamzik> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,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 Mon, Oct 31, 2022 at 09:58:57AM +0100, Borislav Petkov wrote: > On Mon, Oct 31, 2022 at 09:06:04AM +0100, Andrew Jones wrote: > > The valid cpumask range is [0, nr_cpu_ids) and cpumask_next() always > > returns a CPU ID greater than its input, which results in its input > > range being [-1, nr_cpu_ids - 1). Ensure showing CPU info avoids > > triggering error conditions in cpumask_next() by stopping its loop > > What error conditions? > > What would happen if @n is outside of the valid range? Currently (after the revert of 78e5a3399421) with DEBUG_PER_CPU_MAPS we'll get a warning splat when the cpu is outside the range [-1, nr_cpu_ids) and cpumask_next() will call find_next_bit() with the input plus one anyway. find_next_bit() doesn't explicity document what happens when an input is outside the range, but it currently returns the bitmap size without any side effects, which means cpumask_next() will return nr_cpu_ids. show_cpuinfo() doesn't try to show anything in that case and stops its loop, or, IOW, things work fine now with an input of nr_cpu_ids - 1. But, show_cpuinfo() is just getting away with a violated cpumask_next() contract, which 78e5a3399421 exposed. How about a new commit message like this seq_read_iter() and cpuinfo's start and next seq operations implement a pattern like n = cpumask_next(n - 1, mask); show(n); while (1) { ++n; n = cpumask_next(n - 1, mask); if (n >= nr_cpu_ids) break; show(n); } which loops until cpumask_next() identifies its CPU ID input is out of its valid range, [-1, nr_cpu_ids - 1). seq_read_iter() assumes the result of an invalid input is to return nr_cpu_ids or larger without any side effects, however the cpumask API does not document that and it reserves the right to change how it responds to invalid inputs. Ensure inputs from seq_read_iter() are valid. Thanks, drew