Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp4508578ybg; Mon, 21 Oct 2019 10:03:22 -0700 (PDT) X-Google-Smtp-Source: APXvYqxo+CyavDFDtUtP53uIQsKymPx/xRwXZQ/3caN/WVu4s2dtSCtX7ciKijOS33rlYpRvs8FZ X-Received: by 2002:a50:f7cc:: with SMTP id i12mr14020192edn.81.1571677401980; Mon, 21 Oct 2019 10:03:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571677401; cv=none; d=google.com; s=arc-20160816; b=o6GQObx1WdQ9cdszd0hgql5BviVRDCmYYLu2r4wfggtZJqBRc/+d47ttN9BxwgJhRD o/TeFtol5JXAHq1Z5fefmQ4qQkwlkL1BYEiFGf49Oru14Q+8HLR18tXllqa11i5miX9O PwzGJ8CwQYwvl/Qfan0hpimBaYh3p9m1Yz0PEBthwOIAQurX9UJipKCSTUV1IRQ2cIzE sBXR9H0ekdZwp6FHy1PBahT/J37baYbaIBApU+HN/iPgYdiv3YG3OG+Euoilfh1iy/6s +Ctx+CjHyZu6DgCmb9QYRi5FyJLtdmnZNlZHS38IL8uG+CWOgejVqaoSvanoQAX9D1IM xwiA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=Y5hH+T0qVG92b2pjQ4AGR2b9Tlv1rtQ6rkilTn0xjxo=; b=w3UHRisAI5zjXiqGrpVsPIRZnjKpt7MILe52JChV0eIoV/azfaEYQYsUVBlfD2EYHk HuiFVwNwN08kLwexv9k7rsLsV7B48VJjByQ885xmQK+En2efA0X7UoJj//shOE+5zirr me4u0X2tZKEj2CF5W/mMeK+K5I4BtpR3PTa+qYfN/+yjRnKjrVXNX0UV8yZcMsqCRvFM NB5M+Ah18sWqzwCcza4KvQvAOFIv9H6zXEvlxJF6HgYaQCO9ji7J5b76Q3sX6dwWUGVK i4IyUZ/XWO8RWUaW0Nl8pTOCM1fN1Cyp0xgcuoC8w90AOb3WwyWdEsUl0rXYV+WOtL9A GfLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=JKTVSLuH; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o32si10039054edc.306.2019.10.21.10.02.56; Mon, 21 Oct 2019 10:03:21 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=JKTVSLuH; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728197AbfJURBt (ORCPT + 99 others); Mon, 21 Oct 2019 13:01:49 -0400 Received: from mail-io1-f68.google.com ([209.85.166.68]:45243 "EHLO mail-io1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726276AbfJURBs (ORCPT ); Mon, 21 Oct 2019 13:01:48 -0400 Received: by mail-io1-f68.google.com with SMTP id c25so16753459iot.12 for ; Mon, 21 Oct 2019 10:01:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Y5hH+T0qVG92b2pjQ4AGR2b9Tlv1rtQ6rkilTn0xjxo=; b=JKTVSLuHreGlK+DNaNPXgQFU0MjZAlChAWNGTb49EArjloGdlj7S8IJ6yzHT5E49dN IxXGQOucKaaEtVznUcwZsLZbqnqbdocCACK35ndCwhr+xU2A21HKdBFo0FkyvxH+c4Wc ShyHrwYGag5kIluIoGhTUSVvb4jcks7TMbQvU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Y5hH+T0qVG92b2pjQ4AGR2b9Tlv1rtQ6rkilTn0xjxo=; b=QoVkz+yZn0oVozmM1s4DmAo0zmEKd9FjeQ7+KC2ITRX5VkIdE6FMP/5By96ki4xkTK plrySopfXEesOdhjwZ5vc6lpuLok2ZwzO4GO9UHatBJlHVi0fOGHVfQlNwtfRNbdPJpC 8L6QxnF2Qpop5StAGwJEWHkl5/hJBDOFMD8YOErLXt8+fgZfhWRdy3LyoZ/NJE3UoHeM TuSNC5tJH09bjf9Xh1G4m+n+YtuJ9U6PmZQ/Y1TUB9NIKf6J2Kwx+qOaN71+5TFPt2xD SqTNRecxso7vOOZzh5+7dbBrkzaxI5daCYWXQOiKmiQU9B+hDAbOyYWXeOr4MCYpHZLA PD+w== X-Gm-Message-State: APjAAAVfSY4XS/ZNXHtTF8W32s8wkpaYj8D+PAGQXL1+YAVX/fPFT95X l7ILBhbuxO5tyDfcf5l8uP93R5J5OwE= X-Received: by 2002:a05:6602:119:: with SMTP id s25mr22859924iot.111.1571677307000; Mon, 21 Oct 2019 10:01:47 -0700 (PDT) Received: from mail-io1-f54.google.com (mail-io1-f54.google.com. [209.85.166.54]) by smtp.gmail.com with ESMTPSA id l21sm5088152iok.87.2019.10.21.10.01.46 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 21 Oct 2019 10:01:46 -0700 (PDT) Received: by mail-io1-f54.google.com with SMTP id 1so5463730iou.4 for ; Mon, 21 Oct 2019 10:01:46 -0700 (PDT) X-Received: by 2002:a02:b691:: with SMTP id i17mr23172933jam.132.1571677305848; Mon, 21 Oct 2019 10:01:45 -0700 (PDT) MIME-Version: 1.0 References: <20191021101057.23861-1-daniel.thompson@linaro.org> In-Reply-To: <20191021101057.23861-1-daniel.thompson@linaro.org> From: Doug Anderson Date: Mon, 21 Oct 2019 10:01:34 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2] kdb: Avoid array subscript warnings on non-SMP builds To: Daniel Thompson Cc: Jason Wessel , kgdb-bugreport@lists.sourceforge.net, LKML , Patch Tracking , kbuild test robot Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On Mon, Oct 21, 2019 at 3:11 AM Daniel Thompson wrote: > > Recent versions of gcc (reported on gcc-7.4) issue array subscript > warnings for builds where SMP is not enabled. > > kernel/debug/debug_core.c: In function 'kdb_dump_stack_on_cpu': > kernel/debug/debug_core.c:452:17: warning: array subscript is outside array > +bounds [-Warray-bounds] > if (!(kgdb_info[cpu].exception_state & DCPU_IS_SLAVE)) { > ~~~~~~~~~^~~~~ > kernel/debug/debug_core.c:469:33: warning: array subscript is outside array > +bounds [-Warray-bounds] > kgdb_info[cpu].exception_state |= DCPU_WANT_BT; > kernel/debug/debug_core.c:470:18: warning: array subscript is outside array > +bounds [-Warray-bounds] > while (kgdb_info[cpu].exception_state & DCPU_WANT_BT) > > There is no bug here but there is scope to improve the code > generation for non-SMP systems (whilst also silencing the warning). > > Reported-by: kbuild test robot > Fixes: 2277b492582d ("kdb: Fix stack crawling on 'running' CPUs that aren't the master") > Signed-off-by: Daniel Thompson > --- > > Notes: > Changes in v2: > > - Moved the IS_ENABLED(CONFIG_SMP) test to the first (slightly easier > to read the code, improves code generation a little) > - Sent out as a proper patch e-mail ;-) > > kernel/debug/debug_core.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c > index 70e86b4b4932..2b7c9b67931d 100644 > --- a/kernel/debug/debug_core.c > +++ b/kernel/debug/debug_core.c > @@ -444,7 +444,7 @@ int dbg_remove_all_break(void) > #ifdef CONFIG_KGDB_KDB > void kdb_dump_stack_on_cpu(int cpu) > { > - if (cpu == raw_smp_processor_id()) { > + if (cpu == raw_smp_processor_id() || !IS_ENABLED(CONFIG_SMP)) { At first I thought maybe your code would be less efficient than: if (!IS_ENABLED(CONFIG_SMP) || cpu == raw_smp_processor_id()) ...since the compiler would be still be required to "call" raw_smp_processor_id() in the non-SMP case. ...but then I realized that seems to be a macro in the non-SMP case and just resolves to 0. ...so while the compiler would still be "required" to execute the first part of the if test, it should be able to realize that it's a no-op. Reviewed-by: Douglas Anderson -Doug > dump_stack(); > return; > } > -- > 2.21.0 >