Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp4970227imm; Tue, 16 Oct 2018 03:08:35 -0700 (PDT) X-Google-Smtp-Source: ACcGV63pMCU4yeZvZ38YwwYUAD0+mOPwGjHoH5n+vBGoDndn2zAlR105M8xjDpKfITcrtJMS0KsF X-Received: by 2002:a17:902:744c:: with SMTP id e12-v6mr20969275plt.186.1539684515917; Tue, 16 Oct 2018 03:08:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539684515; cv=none; d=google.com; s=arc-20160816; b=P3VaZnN14Aie6m+oNTElhMWoA1/2mWKDuvlsmJaU/9xhz1tWHveMYDmN4LWbacgHDr pOxdfJH8aH2yS/ASuZncAGS0EiUwiyKCLJPt7PMs906AKN7/9oYxtXOyOEzr/JqYw16n Bq2ykJyjID+laC8KvZxmUYW+MzRHkJYd/23snz/c9iJU2FD28AX2qZQ/uKs8W8WxdGDe YUJCzZfqkp1SeFyyN5GKJFYg64TBvo3VKVcCSvR6rpPURM8dB0hG1Exwtfaq4puGqEWf OVQHBAw4sGFHZPTUDbhuf0rN4cy2r+h00cfeCWHsvFMNsbW1Psr7fZW9UkR3Wn3pBG9b ElMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:date:subject:user-agent:message-id :references:cc:in-reply-to:from:to:content-transfer-encoding :mime-version; bh=W1j35Tg8rc6a/G/E4ogHVUCOW6zAhk1RtT0RJkHimOc=; b=zJhPVk3itDZdWq2Wv1MclT0MBEwWjCXwwuY2+Y7oq3zbSVqFJrXYPkm/UEpLzFm1uQ UBYsrnwh2UrIt1y7e5m7HsEeMqw0FlPz/Rgl5Bg+1+k7/J3sY0O1nsRsdgbPOA+1PxCt 43Zsl0wiSe7/HZmfnOEK7TJOS3T5H3gtrjgK5dPw8K8DEWXvT1EGpTvbiVTRPFb2NeX1 Gns+76A++uiIakgr/GGBaAUyfvyImw6qb8DVaVVN6sQZBSDlOBKYwW46SC0z0qfbXZJV iXrQmFc0os8NUCbWnrL9yw29SwnPrPSVMpbeWZd8UC6yxm/aX17vs39jB75IUaRAd68D OBhA== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d23-v6si13095164plr.127.2018.10.16.03.08.19; Tue, 16 Oct 2018 03:08:35 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727026AbeJPR52 convert rfc822-to-8bit (ORCPT + 99 others); Tue, 16 Oct 2018 13:57:28 -0400 Received: from mail.fireflyinternet.com ([109.228.58.192]:49284 "EHLO fireflyinternet.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726083AbeJPR52 (ORCPT ); Tue, 16 Oct 2018 13:57:28 -0400 X-Default-Received-SPF: pass (skip=forwardok (res=PASS)) x-ip-name=78.156.65.138; Received: from localhost (unverified [78.156.65.138]) by fireflyinternet.com (Firefly Internet (M1)) with ESMTP (TLS) id 14119058-1500050 for multiple; Tue, 16 Oct 2018 11:07:29 +0100 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8BIT To: Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Stephen Boyd From: Chris Wilson In-Reply-To: <87sh16ky9d.fsf@intel.com> Cc: Michal Marek , intel-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Masahiro Yamada , Andrey Ryabinin References: <20181015203410.155997-1-swboyd@chromium.org> <87sh16ky9d.fsf@intel.com> Message-ID: <153968444736.22931.7687263957265816381@skylake-alporthouse-com> User-Agent: alot/0.6 Subject: Re: [PATCH] drm/i915: Silence build error with UBSAN Date: Tue, 16 Oct 2018 11:07:27 +0100 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Quoting Jani Nikula (2018-10-16 10:59:42) > 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))); That should be happy with is_power_of_2() from log2.h -Chris