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: 10642455 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 D4709157A for ; Mon, 15 Oct 2018 20:34:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C58CD28ABB for ; Mon, 15 Oct 2018 20:34:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B99D428B0A; Mon, 15 Oct 2018 20:34:15 +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=ham 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 1877928ABB for ; Mon, 15 Oct 2018 20:34:14 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A92B989B67; Mon, 15 Oct 2018 20:34:13 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) by gabe.freedesktop.org (Postfix) with ESMTPS id 8FFE289B97 for ; Mon, 15 Oct 2018 20:34:12 +0000 (UTC) Received: by mail-pf1-x444.google.com with SMTP id l81-v6so10263772pfg.3 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=HRi7aYCgwgMS2D1jDPVNH9WKGP9i4mJte3lUKqZUGgc3LJ8lMgfwThGwqpGo5OZ4NE EoxaHKNGhMKeKUopB6M+PNyQR9DU2fV+1CCi54ze7oneNaSGsiZXr+RNY4xucw5x5nY5 fYCJ7J1yuvW9u9pyS6s5hj0yD/ida9zcO/Y/pFgLtviXQHA/GuHft3/+f3/83+C39lUD ec77mKW1wQ8GtDTAnD/0d59ChE8NydHvKjKdx+Ag6thH9RduDM2CsfEvjSf+7gKMCeol HhG0ydcEa6z7xA8Alya1ESCDjqi9a0vsggzDHgfKza+Y7YWQmLHd2a97e+YJokWMfPRR BRgg== X-Gm-Message-State: ABuFfoj37wUvWgCPI/LwRvX5SEokeMWg+dOfM5SreEy3nJUUymX0kL0u xxUeeEJVHDFXo4uSCaMoLkgL5Q== 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 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 Subject: [Intel-gfx] [PATCH] drm/i915: Silence build error with UBSAN X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Intel graphics driver community testing & 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: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" 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;