* [PATCH] drm/i915: Silence build error with UBSAN
@ 2018-10-15 20:34 Stephen Boyd
2018-10-16 9:59 ` Jani Nikula
0 siblings, 1 reply; 4+ messages in thread
From: Stephen Boyd @ 2018-10-15 20:34 UTC (permalink / raw)
To: Jani Nikula, Joonas Lahtinen, Rodrigo Vivi
Cc: linux-kernel, intel-gfx, dri-devel, Masahiro Yamada,
Michal Marek, Andrey Ryabinin
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 <yamada.masahiro@socionext.com>
Cc: Michal Marek <michal.lkml@markovi.net>
Cc: Andrey Ryabinin <aryabinin@virtuozzo.com>
Signed-off-by: Stephen Boyd <swboyd@chromium.org>
---
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;
--
Sent by a computer through tubes
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] drm/i915: Silence build error with UBSAN
2018-10-15 20:34 [PATCH] drm/i915: Silence build error with UBSAN Stephen Boyd
@ 2018-10-16 9:59 ` Jani Nikula
2018-10-16 10:07 ` Chris Wilson
0 siblings, 1 reply; 4+ messages in thread
From: Jani Nikula @ 2018-10-16 9:59 UTC (permalink / raw)
To: Stephen Boyd, Joonas Lahtinen, Rodrigo Vivi
Cc: linux-kernel, intel-gfx, dri-devel, Masahiro Yamada,
Michal Marek, Andrey Ryabinin
On Mon, 15 Oct 2018, Stephen Boyd <swboyd@chromium.org> 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 <yamada.masahiro@socionext.com>
> Cc: Michal Marek <michal.lkml@markovi.net>
> Cc: Andrey Ryabinin <aryabinin@virtuozzo.com>
> Signed-off-by: Stephen Boyd <swboyd@chromium.org>
> ---
> 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
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] drm/i915: Silence build error with UBSAN
2018-10-16 9:59 ` Jani Nikula
@ 2018-10-16 10:07 ` Chris Wilson
2018-10-16 11:48 ` Jani Nikula
0 siblings, 1 reply; 4+ messages in thread
From: Chris Wilson @ 2018-10-16 10:07 UTC (permalink / raw)
To: Jani Nikula, Joonas Lahtinen, Rodrigo Vivi, Stephen Boyd
Cc: Michal Marek, intel-gfx, linux-kernel, dri-devel,
Masahiro Yamada, Andrey Ryabinin
Quoting Jani Nikula (2018-10-16 10:59:42)
> On Mon, 15 Oct 2018, Stephen Boyd <swboyd@chromium.org> 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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] drm/i915: Silence build error with UBSAN
2018-10-16 10:07 ` Chris Wilson
@ 2018-10-16 11:48 ` Jani Nikula
0 siblings, 0 replies; 4+ messages in thread
From: Jani Nikula @ 2018-10-16 11:48 UTC (permalink / raw)
To: Chris Wilson, Joonas Lahtinen, Rodrigo Vivi, Stephen Boyd
Cc: Michal Marek, intel-gfx, linux-kernel, dri-devel,
Masahiro Yamada, Andrey Ryabinin
On Tue, 16 Oct 2018, Chris Wilson <chris@chris-wilson.co.uk> wrote:
> Quoting Jani Nikula (2018-10-16 10:59:42)
>> 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
D'oh. Thanks. I was sure there was one, I looked for it, but my git
greps were all upper case. :/
I'll spin a new version, along with the other clang build fix.
BR,
Jani.
--
Jani Nikula, Intel Open Source Graphics Center
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2018-10-16 11:48 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-15 20:34 [PATCH] drm/i915: Silence build error with UBSAN Stephen Boyd
2018-10-16 9:59 ` Jani Nikula
2018-10-16 10:07 ` Chris Wilson
2018-10-16 11:48 ` Jani Nikula
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).