Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp4962463imm; Tue, 16 Oct 2018 03:01:44 -0700 (PDT) X-Google-Smtp-Source: ACcGV63ud7f6wy1gH0LbqxD/FEZZiWPPmtiqVeuzgc1JKx+R2isXZKSJHOR6+63n1dGAibqrUTGt X-Received: by 2002:a62:3a43:: with SMTP id h64-v6mr21228628pfa.119.1539684103959; Tue, 16 Oct 2018 03:01:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539684103; cv=none; d=google.com; s=arc-20160816; b=HIPbkPb1BbStofe08OI1EzFF3g+Ibk9XzT3VYF7eLAMFyQW/26iTRtgSCOLLRB0bht ucUGbKDNsDEtxJGa3DW8u36G8eM2xzVSc9/sh80hwQJKS6bGb0Kwj4rp2GRPo9XNJbGL m4JDdlErUXoKKlN97FYWIiBidCYLaCwYbJw0opJvr7bVK/tz4ZgEAtcpN17eNAn9vZQL 6jWmWEWBbQZE3Ou52fSQNXFUytcURoC7uKCanTS95vVyISxAq/y2J7T8qQlRiROU/XzZ 5TBoTGq2eGg5ZwGHXxCq+svIVkKBLLwoqlZgDautp2wPKpd6ryCCP5Tidg+s1fySdmPV svSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:references :organization:in-reply-to:subject:cc:to:from; bh=21MDX/QmIC2oIcycJdTEm8BsuLlzmxHjTkjBtwXZyQw=; b=XRC8NhITWF91sWEtp5e4/xeX9bI8JkpOqyRgZsKfRdFqa038BnzwM56coRxArlWj/N wfuiMOVl8vEQbfXbPeOHBRZaLajEXxQ+ZxNlVw9CdeTFmY2OY1ulleJkxTrWbjjvl9xz mynav5za3e9XQO5+o57uxOZrNl/KtmNSpcafasEoIBW222jJ0Jt7JW0qZHF8lmbyf86I nCBYcEZI3v9JVFJXXvh5877Mh83YRbQMcXegeONrQvW0rj+pk2763O0zQfb5GiqcrIb+ RGFSG02TmprQBy4nYOcbxhsrUAxDwzXALNH1KBMZhTwOFRp5Iug/+ELspoJjCFwqEH63 0Jgw== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 145-v6si14737423pgd.509.2018.10.16.03.01.25; Tue, 16 Oct 2018 03:01:43 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727045AbeJPRtm (ORCPT + 99 others); Tue, 16 Oct 2018 13:49:42 -0400 Received: from mga07.intel.com ([134.134.136.100]:11670 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726083AbeJPRtm (ORCPT ); Tue, 16 Oct 2018 13:49:42 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Oct 2018 03:00:02 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,388,1534834800"; d="scan'208";a="99603654" Received: from jnikula-mobl3.fi.intel.com (HELO localhost) ([10.237.72.61]) by fmsmga001.fm.intel.com with ESMTP; 16 Oct 2018 02:59:59 -0700 From: Jani Nikula To: Stephen Boyd , Joonas Lahtinen , Rodrigo Vivi Cc: linux-kernel@vger.kernel.org, intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, Masahiro Yamada , Michal Marek , Andrey Ryabinin Subject: Re: [PATCH] drm/i915: Silence build error with UBSAN In-Reply-To: <20181015203410.155997-1-swboyd@chromium.org> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo References: <20181015203410.155997-1-swboyd@chromium.org> Date: Tue, 16 Oct 2018 12:59:42 +0300 Message-ID: <87sh16ky9d.fsf@intel.com> MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 15 Oct 2018, Stephen Boyd wrote: > When I enable UBSAN and compile this driver with clang I get the > following build error: > > drivers/gpu/drm/i915/intel_engine_cs.o: In function `intel_engine_init_execlist': > drivers/gpu/drm/i915/intel_engine_cs.c:411: undefined reference to `__compiletime_assert_411' > > from what I can figure out, the compiler can't optimize > execlists_num_ports() sufficiently enough at compile time to figure out > that the 'execlists->port_mask = 1' assignment one line above the > BUILD_BUG_ON_NOT_POWER_OF_2 check will make execlists_num_ports() return > 2. Most likely that's because UBSAN is going to check the load inside > execlists_num_ports() and that check isn't omitted so the optimizer > can't optimize away the whole function. See [1] for a better explanation. [1] http://mid.mail-archive.com/20181009171401.14980-1-natechancellor@gmail.com > So let's just change this check to cause a build error when the maximum > number of ports isn't a power of two. It looks like this is similar to > what's being checked here so this might work well enough. That's not the same thing. I guess I'd go with the below instead, similar to the check on the next line. I guess both of the checks could be static on gcc. BR, Jani. diff --git a/drivers/gpu/drm/i915/intel_engine_cs.c b/drivers/gpu/drm/i915/intel_engine_cs.c index f27dbe26bcc1..897d5a557d88 100644 --- a/drivers/gpu/drm/i915/intel_engine_cs.c +++ b/drivers/gpu/drm/i915/intel_engine_cs.c @@ -461,12 +461,14 @@ static void intel_engine_init_batch_pool(struct intel_engine_cs *engine) i915_gem_batch_pool_init(&engine->batch_pool, engine); } +#define IS_POWER_OF_2(n) ((n) != 0 && ((n) & ((n) - 1)) == 0) + static void intel_engine_init_execlist(struct intel_engine_cs *engine) { struct intel_engine_execlists * const execlists = &engine->execlists; execlists->port_mask = 1; - BUILD_BUG_ON_NOT_POWER_OF_2(execlists_num_ports(execlists)); + GEM_BUG_ON(!IS_POWER_OF_2(execlists_num_ports(execlists))); GEM_BUG_ON(execlists_num_ports(execlists) > EXECLIST_MAX_PORTS); execlists->queue_priority = INT_MIN; --- > > Cc: Masahiro Yamada > Cc: Michal Marek > Cc: Andrey Ryabinin > Signed-off-by: Stephen Boyd > --- > drivers/gpu/drm/i915/intel_engine_cs.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/gpu/drm/i915/intel_engine_cs.c b/drivers/gpu/drm/i915/intel_engine_cs.c > index 217ed3ee1cab..bdf75628ed83 100644 > --- a/drivers/gpu/drm/i915/intel_engine_cs.c > +++ b/drivers/gpu/drm/i915/intel_engine_cs.c > @@ -463,7 +463,7 @@ static void intel_engine_init_execlist(struct intel_engine_cs *engine) > struct intel_engine_execlists * const execlists = &engine->execlists; > > execlists->port_mask = 1; > - BUILD_BUG_ON_NOT_POWER_OF_2(execlists_num_ports(execlists)); > + BUILD_BUG_ON_NOT_POWER_OF_2(EXECLIST_MAX_PORTS); > GEM_BUG_ON(execlists_num_ports(execlists) > EXECLIST_MAX_PORTS); > > execlists->queue_priority = INT_MIN; -- Jani Nikula, Intel Open Source Graphics Center