Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1216206ybv; Thu, 20 Feb 2020 15:42:57 -0800 (PST) X-Google-Smtp-Source: APXvYqyn/rwf2TKedIr0Gtd6yqEx6Ky+NR4J9MwkreRMDGNhaVvBsgpN9H2ARxLGfwRMind4PBKK X-Received: by 2002:a05:6830:1353:: with SMTP id r19mr26324508otq.288.1582242176920; Thu, 20 Feb 2020 15:42:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582242176; cv=none; d=google.com; s=arc-20160816; b=LX/NBU1J1nTggyb2kRDmXH2CHrGcDq2X2xPh7FxdZSc/0jsFHPcZayg9M/6zdYeibh WYWL2KLkjQON4bVNPar7dXwWpPI+E5b8VqYCvhFhM170xAMP0Ha38RFIwaObgDblaoAd 9zX28lOiuitHcxNd4wjzwJ02ee7LsWr6HOZ44amDicvaGe9g2u4srMqn4EVy2IF3Fv9M Gg/hFF3C1FuVpUDuVrHHJh3OuY85VlRmew1qtBoucrVVdJ7LA5i96xu3NuuLMqB97eYH LP2+mBr7NNSSMnqxsH0U7faALlA7eov8gScvILMHb/ZpRQzxfaVeF6cpBqdOsvmp4hHL 8huA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=7FzECIoWmkTb4/abn5eV9Q3RdOU/PqnT/XPfJdQsEBE=; b=MAlI4GqEmy3sKA247TgGYdPaBXhnX40IZcynTZJA/YF3mVwCJIMlKaly98nQQV1735 jDNClQtgzn+fi4wTSyCuu/bJ86+BnEOFv85GWk7JtPdcMIqFvcdn3mvIUbsfwYP/WvMA tcEb1lTTkK9mhGDem+iwtMQAhRedq1Icpnxs/EckztUPYrxEVBmQj08G+KVCkUQW1CXu FcaIz7IJjMJb1r+FycQwF1fST8xC+8y824lw8L9iExRjsYQriyhA4X2p2/D0f24DmVMD mq34xkKhCj+BjGqxTDouIRoa78hYaKEAP4A0/vK30BKW1HxHJZNVQyfqX5Gf4zbFycNk i/dQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=La4IJsdn; 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 d15si522359otl.82.2020.02.20.15.42.44; Thu, 20 Feb 2020 15:42:56 -0800 (PST) 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=La4IJsdn; 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 S1729417AbgBTXmP (ORCPT + 99 others); Thu, 20 Feb 2020 18:42:15 -0500 Received: from mail-pj1-f68.google.com ([209.85.216.68]:51467 "EHLO mail-pj1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729392AbgBTXmO (ORCPT ); Thu, 20 Feb 2020 18:42:14 -0500 Received: by mail-pj1-f68.google.com with SMTP id fa20so183026pjb.1 for ; Thu, 20 Feb 2020 15:42:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to; bh=7FzECIoWmkTb4/abn5eV9Q3RdOU/PqnT/XPfJdQsEBE=; b=La4IJsdnldRGbfdjU9f/pqYDP/RLb1PwT3aUwAiXTY8MtUIsYRozdqHGvVDKOCLSRx kwsWSzgkfb7n2wrAKKbpIdJl59krWqvmkfBydZV3gWJHR3RDJPewKa8pVjremcOiFOZQ oFriUzJBwcFdgSQbFWPke8cXQqWZWx9Q8DAGY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=7FzECIoWmkTb4/abn5eV9Q3RdOU/PqnT/XPfJdQsEBE=; b=Wwnug/3G1eOm1KBzzkS6TkElvP0ZPV7Dp4S3MW2B+ZoEvOzWoYUEnnRj8sYsnKwG0Y FaK3MK6L56rKDVxlZLxdhytlFwJ7St2kDd0EQfWGJpXKUMrB7HpTTgCeh06OZyMECP7k kgVYlRmUs4x/ZLJWcMP+9/R/E11SiheSWPFzZKJ56wAwxjmmbmIOTXKtQ2beGMaZs0ac 9INZO+6is2EIjJsU3JgqPiareR7gefn23xmchQNegl2TJKXYzclb42lwljpMDeh4fAQT lE1hCYJbnJkR4rNqoptgnINJ7qCJnPj/VOvLemK78gLc1WweBgFGNFZvELrDoaNpX5wv BW8Q== X-Gm-Message-State: APjAAAUW+QSuZMalTysvP3RFYECPaTE03tL0vEBWLCEIkU/Le9jAT4Hs 6RkPk/g2Q/tI1BNNyEDyex6Kjg== X-Received: by 2002:a17:90a:8806:: with SMTP id s6mr6040144pjn.141.1582242133573; Thu, 20 Feb 2020 15:42:13 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id m15sm385729pgn.40.2020.02.20.15.42.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Feb 2020 15:42:12 -0800 (PST) Date: Thu, 20 Feb 2020 15:42:11 -0800 From: Kees Cook To: Jani Nikula Cc: Joonas Lahtinen , Rodrigo Vivi , Alexander Potapenko , intel-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] drm/i915: Distribute switch variables for initialization Message-ID: <202002201541.1B5347ABAD@keescook> References: <20200220062258.68854-1-keescook@chromium.org> <877e0hv9t1.fsf@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <877e0hv9t1.fsf@intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Feb 20, 2020 at 12:21:14PM +0200, Jani Nikula wrote: > On Wed, 19 Feb 2020, Kees Cook wrote: > > Variables declared in a switch statement before any case statements > > cannot be automatically initialized with compiler instrumentation (as > > they are not part of any execution flow). With GCC's proposed automatic > > stack variable initialization feature, this triggers a warning (and they > > don't get initialized). Clang's automatic stack variable initialization > > (via CONFIG_INIT_STACK_ALL=y) doesn't throw a warning, but it also > > doesn't initialize such variables[1]. Note that these warnings (or silent > > skipping) happen before the dead-store elimination optimization phase, > > so even when the automatic initializations are later elided in favor of > > direct initializations, the warnings remain. > > > > To avoid these problems, move such variables into the "case" where > > they're used or lift them up into the main function body. > > > > drivers/gpu/drm/i915/display/intel_display.c: In function ‘check_digital_port_conflicts’: > > drivers/gpu/drm/i915/display/intel_display.c:12963:17: warning: statement will never be executed [-Wswitch-unreachable] > > 12963 | unsigned int port_mask; > > | ^~~~~~~~~ > > > > drivers/gpu/drm/i915/intel_pm.c: In function ‘vlv_get_fifo_size’: > > drivers/gpu/drm/i915/intel_pm.c:474:7: warning: statement will never be executed [-Wswitch-unreachable] > > 474 | u32 dsparb, dsparb2, dsparb3; > > | ^~~~~~ > > drivers/gpu/drm/i915/intel_pm.c: In function ‘vlv_atomic_update_fifo’: > > drivers/gpu/drm/i915/intel_pm.c:1997:7: warning: statement will never be executed [-Wswitch-unreachable] > > 1997 | u32 dsparb, dsparb2, dsparb3; > > | ^~~~~~ > > > > [1] https://bugs.llvm.org/show_bug.cgi?id=44916 > > > > Signed-off-by: Kees Cook > > Reviewed-by: Jani Nikula Thanks! > > If you look at i915/Makefile, you'll see that we don't shy away from > enabling lots of extra warnings, and we run our CI with -Werror to keep > it clean. It does not seem like -Wswitch-unreachable does me any good, > though... is it new? It's already enabled by default, but the GCC feature that tweaks it doesn't exist yet. But it points out a problem that exists for Clang today, but Clang doesn't actually warn on (yet). So this is a fix to avoid the silent Clang problem and fix future warnings before they happen. -Kees > > BR, > Jani. > > > > --- > > drivers/gpu/drm/i915/display/intel_display.c | 6 ++++-- > > drivers/gpu/drm/i915/intel_pm.c | 4 ++-- > > 2 files changed, 6 insertions(+), 4 deletions(-) > > > > diff --git a/drivers/gpu/drm/i915/display/intel_display.c b/drivers/gpu/drm/i915/display/intel_display.c > > index 064dd99bbc49..c829cd26f99e 100644 > > --- a/drivers/gpu/drm/i915/display/intel_display.c > > +++ b/drivers/gpu/drm/i915/display/intel_display.c > > @@ -12960,14 +12960,15 @@ static bool check_digital_port_conflicts(struct intel_atomic_state *state) > > WARN_ON(!connector_state->crtc); > > > > switch (encoder->type) { > > - unsigned int port_mask; > > case INTEL_OUTPUT_DDI: > > if (WARN_ON(!HAS_DDI(to_i915(dev)))) > > break; > > /* else, fall through */ > > case INTEL_OUTPUT_DP: > > case INTEL_OUTPUT_HDMI: > > - case INTEL_OUTPUT_EDP: > > + case INTEL_OUTPUT_EDP: { > > + unsigned int port_mask; > > + > > port_mask = 1 << encoder->port; > > > > /* the same port mustn't appear more than once */ > > @@ -12976,6 +12977,7 @@ static bool check_digital_port_conflicts(struct intel_atomic_state *state) > > > > used_ports |= port_mask; > > break; > > + } > > case INTEL_OUTPUT_DP_MST: > > used_mst_ports |= > > 1 << encoder->port; > > diff --git a/drivers/gpu/drm/i915/intel_pm.c b/drivers/gpu/drm/i915/intel_pm.c > > index bd2d30ecc030..17d8833787c4 100644 > > --- a/drivers/gpu/drm/i915/intel_pm.c > > +++ b/drivers/gpu/drm/i915/intel_pm.c > > @@ -469,9 +469,9 @@ static void vlv_get_fifo_size(struct intel_crtc_state *crtc_state) > > struct vlv_fifo_state *fifo_state = &crtc_state->wm.vlv.fifo_state; > > enum pipe pipe = crtc->pipe; > > int sprite0_start, sprite1_start; > > + u32 dsparb, dsparb2, dsparb3; > > > > switch (pipe) { > > - u32 dsparb, dsparb2, dsparb3; > > case PIPE_A: > > dsparb = I915_READ(DSPARB); > > dsparb2 = I915_READ(DSPARB2); > > @@ -1969,6 +1969,7 @@ static void vlv_atomic_update_fifo(struct intel_atomic_state *state, > > const struct vlv_fifo_state *fifo_state = > > &crtc_state->wm.vlv.fifo_state; > > int sprite0_start, sprite1_start, fifo_size; > > + u32 dsparb, dsparb2, dsparb3; > > > > if (!crtc_state->fifo_changed) > > return; > > @@ -1994,7 +1995,6 @@ static void vlv_atomic_update_fifo(struct intel_atomic_state *state, > > spin_lock(&uncore->lock); > > > > switch (crtc->pipe) { > > - u32 dsparb, dsparb2, dsparb3; > > case PIPE_A: > > dsparb = intel_uncore_read_fw(uncore, DSPARB); > > dsparb2 = intel_uncore_read_fw(uncore, DSPARB2); > > > > -- > Jani Nikula, Intel Open Source Graphics Center -- Kees Cook