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 CB274C636CC for ; Fri, 17 Feb 2023 01:39:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230083AbjBQBjP (ORCPT ); Thu, 16 Feb 2023 20:39:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51634 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229460AbjBQBjN (ORCPT ); Thu, 16 Feb 2023 20:39:13 -0500 Received: from mail-oi1-x232.google.com (mail-oi1-x232.google.com [IPv6:2607:f8b0:4864:20::232]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 251165356C; Thu, 16 Feb 2023 17:39:12 -0800 (PST) Received: by mail-oi1-x232.google.com with SMTP id bh15so3584685oib.4; Thu, 16 Feb 2023 17:39:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=VXQ5NrgvHcnTZDrYMA7luKxwlYKnjw3ntxCLdrLg57U=; b=gYvzaviFtqImQ3zUrVvJmoLWnxgJkoUH+uQVlf3ZPNK+gFO9Qcg//Tb5sdXRlRP/fL tk1XGt/RFgKLRqV4DW5him6L2tAzFpn7HmQF6EXRwER1S1w+fBKTaMHXYzskpk/Jb2gP Qp79v0eejOd0i+jXCHWxaGVZUvTs4BePZ9v13MrLZKugqdsuHsEbNKte6ygjoBcnAgEt 8DkibJueUqgu4kJUvn3atA7afhXE4uLvK7bIO7fBHuuCxb7/UjbuL65eGdIP/nz5Wpx+ mk0xPywsi3xRi5GgUdIAVbFwB+9TkiJgXCpjwybA1KTXop6mTziZ8OHyps8NdsR/m0qR GZUA== 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=VXQ5NrgvHcnTZDrYMA7luKxwlYKnjw3ntxCLdrLg57U=; b=Vo5sANe2nKL5RUvKYL7338f/g5bHrFN889pzQU6vopWCIS9D6siwGZvxv8/LZbNaG2 bNE0yCgatBCL6XvGecl4YKtS4RRylIUETEtuP+T1R+xSWgZ0kOIiAKLEK2JwvxXy/XXZ CanHg2lXQUdlqV8ojuctR6fYEXY/vzlS8JhKG4t+ZtxYslxtYBzwV8usE+9nv3G6yJYg eG0Mk4t4G8zGQ2QbFbtHMbuSyHi03nvZ4QC68ZB0fV7MBTFWNXxowzKPoTLCkvzamn5s 4jL4oaY1dDzP4EQ/Ye7Qs/xZZV5tImQMIwa19Xr2ZMkKVvZGeo/1M/NS4TDneOwIkvlj 3/qw== X-Gm-Message-State: AO0yUKU0XAzISQc6whFgYNfQ6ttngYQWsAioXNclM9gZPAK7yMC5wqoX E1WYWorecXmwrnaYbFj3JGIO7G5zxxY= X-Google-Smtp-Source: AK7set8drcacu6OsYNi6+44bXIOT2XIdpYwoXbf6odYP67GCPakNkgeQBA5IfD5qhYUu3W78NJdfPw== X-Received: by 2002:aca:f11:0:b0:37f:b2dd:73a with SMTP id 17-20020aca0f11000000b0037fb2dd073amr102656oip.24.1676597950923; Thu, 16 Feb 2023 17:39:10 -0800 (PST) Received: from localhost ([12.97.180.36]) by smtp.gmail.com with ESMTPSA id r204-20020acac1d5000000b0037834b1a20bsm1235358oif.0.2023.02.16.17.39.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Feb 2023 17:39:10 -0800 (PST) Date: Thu, 16 Feb 2023 17:39:08 -0800 From: Yury Norov To: linux-kernel@vger.kernel.org, "David S. Miller" , Andy Shevchenko , Barry Song , Ben Segall , Bruno Goncalves , Dietmar Eggemann , Gal Pressman , Greg Kroah-Hartman , Haniel Bristot de Oliveira , Heiko Carstens , Ingo Molnar , Jacob Keller , Jakub Kicinski , Jason Gunthorpe , Jesse Brandeburg , Jonathan Cameron , Juri Lelli , Kees Cook , Leon Romanovsky , Linus Torvalds , Mel Gorman , Peter Lafreniere , Peter Zijlstra , Rasmus Villemoes , Saeed Mahameed , Steven Rostedt , Tariq Toukan , Tariq Toukan , Tony Luck , Valentin Schneider , Vincent Guittot Cc: linux-crypto@vger.kernel.org, netdev@vger.kernel.org, linux-rdma@vger.kernel.org Subject: Re: [PATCH 3/9] sched: add sched_numa_find_nth_cpu() Message-ID: References: <20230121042436.2661843-1-yury.norov@gmail.com> <20230121042436.2661843-4-yury.norov@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230121042436.2661843-4-yury.norov@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Jakub, Can you please fold-in the following patch? Thanks, Yury From: Yury Norov Date: Thu, 16 Feb 2023 17:03:30 -0800 Subject: [PATCH] sched/topology: fix KASAN warning in hop_cmp() Despite that prev_hop is used conditionally on curr_hop is not the first hop, it's initialized unconditionally. Because initialization implies dereferencing, it might happen that the code dereferences uninitialized memory, which has been spotted by KASAN. Fix it by reorganizing hop_cmp() logic. Reported-by: Bruno Goncalves Signed-off-by: Yury Norov --- kernel/sched/topology.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c index 48838a05c008..c21b8b1f3537 100644 --- a/kernel/sched/topology.c +++ b/kernel/sched/topology.c @@ -2081,14 +2081,19 @@ struct __cmp_key { static int hop_cmp(const void *a, const void *b) { - struct cpumask **prev_hop = *((struct cpumask ***)b - 1); - struct cpumask **cur_hop = *(struct cpumask ***)b; + struct cpumask **prev_hop, **cur_hop = *(struct cpumask ***)b; struct __cmp_key *k = (struct __cmp_key *)a; if (cpumask_weight_and(k->cpus, cur_hop[k->node]) <= k->cpu) return 1; - k->w = (b == k->masks) ? 0 : cpumask_weight_and(k->cpus, prev_hop[k->node]); + if (b == k->masks) { + k->w = 0; + return 0; + } + + prev_hop = *((struct cpumask ***)b - 1); + k->w = cpumask_weight_and(k->cpus, prev_hop[k->node]); if (k->w <= k->cpu) return 0; -- 2.34.1