From patchwork Mon Oct 15 20:34:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 10643163 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 31CAC925 for ; Tue, 16 Oct 2018 07:12:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 19FC929A1E for ; Tue, 16 Oct 2018 07:12:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0523829A22; Tue, 16 Oct 2018 07:12:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3FF7929A1E for ; Tue, 16 Oct 2018 07:12:39 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 99CF86E1AC; Tue, 16 Oct 2018 07:12:28 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pg1-x541.google.com (mail-pg1-x541.google.com [IPv6:2607:f8b0:4864:20::541]) by gabe.freedesktop.org (Postfix) with ESMTPS id 8802789B67 for ; Mon, 15 Oct 2018 20:34:12 +0000 (UTC) Received: by mail-pg1-x541.google.com with SMTP id g2-v6so9692112pgu.11 for ; Mon, 15 Oct 2018 13:34:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=mR/nT5nCH8r3TvWFMt9H5xUCBQQEUFMwnxIrguxIQ9I=; b=ufCK5OM8ANUAv8NVOdSgWgVW+EVZqBslFj/fUs6fYdJru99jgHe69pq1Xpy0oqfcou QpEDw/HmGZ/kWRz7YOpqU4v1rssIrqm4Vt+wjLnMl2xKIpcMEkr5pqC5PcrUigQTsYWG thTJnlwS23VMlc+xhlMvH6TNQ60wBiFAH8OiKE8+sO1GH8GhmYC1r1PkLUzeb02y99vP Dwam25f13FbPeqAO+78ef13AWVPdFOlCq3memTQN9AsqxypQH0adKDpVtOI1ps+CS7mD X0xVFzbah0T2W+cN4gPd9sacL5GnyetZkzQ+/Qrbt8OWUqZYoyun6MvnJopFQj7IALkF ngJA== X-Gm-Message-State: ABuFfognCpOWPkXEEUUlzFVEnCGqXyRRxOnS5hBPQCGd0RnOPw7sFXPu xkrR0Cp5rXJQ57aQDmMXZrj2Jw== X-Google-Smtp-Source: ACcGV61MlM8NEJUHupS9dc3+5rBJfHhgf6100fL48kR0c7MkFoxnUI8fS8nXOMXMje/SON0BKMIQNA== X-Received: by 2002:a63:5a54:: with SMTP id k20-v6mr17566147pgm.297.1539635652175; Mon, 15 Oct 2018 13:34:12 -0700 (PDT) Received: from smtp.gmail.com ([2620:15c:202:1:fed3:9637:a13a:6c15]) by smtp.gmail.com with ESMTPSA id j2-v6sm16011954pfj.91.2018.10.15.13.34.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Oct 2018 13:34:11 -0700 (PDT) From: Stephen Boyd To: Jani Nikula , Joonas Lahtinen , Rodrigo Vivi Subject: [PATCH] drm/i915: Silence build error with UBSAN Date: Mon, 15 Oct 2018 13:34:10 -0700 Message-Id: <20181015203410.155997-1-swboyd@chromium.org> X-Mailer: git-send-email 2.19.1.331.ge82ca0e54c-goog MIME-Version: 1.0 X-Mailman-Approved-At: Tue, 16 Oct 2018 07:12:13 +0000 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michal Marek , intel-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Masahiro Yamada , Andrey Ryabinin Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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. 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. 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;