Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp1382820imm; Wed, 10 Oct 2018 13:42:32 -0700 (PDT) X-Google-Smtp-Source: ACcGV63LL7GWjy52I2sLsay0v18p7dhtpHsp+nbkTv32FlQYEHLMfqhxU2dHkD9JGq51xWWKKyQ9 X-Received: by 2002:a17:902:1121:: with SMTP id d30-v6mr33358463pla.250.1539204152277; Wed, 10 Oct 2018 13:42:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539204152; cv=none; d=google.com; s=arc-20160816; b=xvEjmstXL0HQn1OxvpPDaoq8PlpXgLPZ+5XLyyyvPnaL1rSM4gt55hR6dGwvfrip/3 YmwQlFk/CoWHudyPS9hCOQ2lq0tuH7LgPglklgWhELP//aoXPWUVhvU1cxLW9Gdmj1qj /u2XbQW4ghVRBphGCfnDVAHcO+mJJ3Pnd6QV2RHqs8+vH8pWQmBltb4Y/xHniP8qHvJl fzdt4Q2U/6PztwkPXqQS+hQYo408nD4CWazl0BYzkoEL3p7SMbgMY2ri86MEv+lp7GW+ l+0uNjfw+Yt9LoTi/waVfIF2moM1o39XkfL44+F/Mh1vzfeYlW7yMMxXPu0o8ANGpgEA 9LLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=Zouda5K5q/s7cngJMUA04fccxr43MQZEUh9/l7s4a00=; b=M+APiQTpMBDU0ilMAZqtIafThlqqzr+5IDTayC86mWzDL0Zfkgf6lgvAnF1QtB9BZp 3wTKDPmKrMOn9+tOxUGEQqqxRXHblTl/MOdEcJxN+iQlLuKfW5QEQokajMRSz5O7P632 8hCiJ7eTTb7B3/pWqvT6tzQlTH6x83GMZdsBIGFuWxgyDsvH5EVgJRBBlHENKJFyYxkB DWuMTPOL2ViCyvrq69KIwm3J0SxZWnHmdXfDs/f+z0J/3VQqKMpZUq0veUL/Rbb8qiiG iCmj+zbrA7klCRQ6Fdu17FRn0xRErThCKo69b8gw8FMyyXusdWQEYSEqebLEFZhp8PHw tAeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=AKl6uUtL; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h34-v6si27225615pld.49.2018.10.10.13.42.17; Wed, 10 Oct 2018 13:42:32 -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; dkim=pass header.i=@google.com header.s=20161025 header.b=AKl6uUtL; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726035AbeJKEFl (ORCPT + 99 others); Thu, 11 Oct 2018 00:05:41 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:40458 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725989AbeJKEFl (ORCPT ); Thu, 11 Oct 2018 00:05:41 -0400 Received: by mail-pg1-f195.google.com with SMTP id n31-v6so3053198pgm.7 for ; Wed, 10 Oct 2018 13:41:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Zouda5K5q/s7cngJMUA04fccxr43MQZEUh9/l7s4a00=; b=AKl6uUtLglAH+svEK0vsxHVGQwO42vIF8ISeh/hwocuzCAmPisG0Iy0FsbaeCcosww nCf7v5q3JvHdJ/uo/6Q7DkUmMvRt0qyqYXlJPoAoXNEAyslyvlk2q68zV0Lb70a4uArp 7HLspR/q5BOOP7pfxiCw57dXZGiffgWgZfP/mWo+4XIq4LCC3kfvtHE3NFJPPjxS46kI OrWcxT4S1VEsiIiDUIJ52blTOpXtPOHBVY+tIYp94li4ViKpNwMVJuJfXmbJ4o7S7Mft uCtxhu4+5Gl2ZpV34qHnp7R3nGRiOWunWiu8ELdyO9M6M2iDYocAXO55XGI9mLoqIUa9 P8Gw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Zouda5K5q/s7cngJMUA04fccxr43MQZEUh9/l7s4a00=; b=Mgop1IP0UiJ+xYOeadPfd0Ul9tIpBuQgAX17XyIUENQHqkxJWE8DJmJCEzRKZKXXlE jE57o/0RNMBEUBVwKB1x8DsJT1fdlKsMOKmY+LRxXFfUX+sjGXkY+Mb7OtrwxjSEB5Ne TJf8Fct/XI1JVfhyAkFmnqtiStx8IGAOBxVyzKPlP6E5r7hVlsKBGfuqZ7UL9G0aa8WJ a23LIxdNh1xMR+7A/DQIBgK0xwgG0dNJlq25XyEK5/DXU+5T6WCafLjqDKQFcKJXDhYR eae/oNe0oEDqK0Sw38O5rsIgZ1GL3F8+j1Uo++UG+BGolbqCLbgKEFVgodm9BoIBMI2W v6kA== X-Gm-Message-State: ABuFfohkhQprQlePiqnbPr+hJHETGWUaCzMGOc41liiNQ0bj8wh+PJqp HDD+9RZArh0ni7qXwwAY6V/Sp94c+Me8x2Lu7hghhRqD+58= X-Received: by 2002:a62:4b09:: with SMTP id y9-v6mr36169795pfa.93.1539204109045; Wed, 10 Oct 2018 13:41:49 -0700 (PDT) MIME-Version: 1.0 References: <20181009171401.14980-1-natechancellor@gmail.com> <87woqqm2mz.fsf@intel.com> In-Reply-To: From: Nick Desaulniers Date: Wed, 10 Oct 2018 13:41:37 -0700 Message-ID: Subject: Re: [Intel-gfx] [PATCH] drm/i915: Convert _print_param to a macro To: michal.wajdeczko@intel.com Cc: Nathan Chancellor , jani.nikula@linux.intel.com, intel-gfx@lists.freedesktop.org, LKML , dri-devel@lists.freedesktop.org, rodrigo.vivi@intel.com, lukas.bulwahn@gmail.com Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Oct 10, 2018 at 1:30 PM Michal Wajdeczko wrote: > > On Wed, 10 Oct 2018 14:01:40 +0200, Jani Nikula > wrote: > > > On Tue, 09 Oct 2018, Nick Desaulniers wrote: > >> On Tue, Oct 9, 2018 at 10:14 AM Nathan Chancellor > >> wrote: > >>> > >>> When building the kernel with Clang with defconfig and CONFIG_64BIT > >>> disabled, vmlinux fails to link because of the BUILD_BUG in > >>> _print_param. > >>> > >>> ld: drivers/gpu/drm/i915/i915_params.o: in function `i915_params_dump': > >>> i915_params.c:(.text+0x56): undefined reference to > >>> `__compiletime_assert_191' > >>> > >>> This function is semantically invalid unless the code is first inlined > >>> then constant folded, which doesn't work for Clang because semantic > >>> analysis happens before optimization/inlining. Converting this function > >>> to a macro avoids this problem and allows Clang to properly remove the > >>> BUILD_BUG during optimization. > >> > >> Thanks Nathan for the patch. To provide more context, Clang does > >> semantic analysis before optimization, where as GCC does these > >> together (IIUC). So the above link error is from the naked > >> BUILD_BUG(). Clang can't evaluate the __builtin_strcmp's statically > >> until inlining has occurred, but that optimization happens after > >> semantic analysis. To do the inlining before semantic analysis, we > >> MUST leverage the preprocessor, which runs before the compiler starts > >> doing semantic analysis. I suspect this code is not valid for GCC > >> unless optimizations are enabled (the kernel only does compile with > >> optimizations turned on). This change allows us to build this > >> translation unit with Clang. > >> > >> Acked-by: Nick Desaulniers > >> (Note: this is the change I suggested, so not sure whether Acked-by or > >> Reviewed-by is more appropriate). > > > > *Sad trombone* > > > > I'd rather see us converting more macros to static inlines than the > > other way round. > > > > I'll let others chime in if they have any better ideas, otherwise I'll > > apply this one. > > Option 1: Just drop BUILD_BUG() from _print_param() function. I was also thinking of this. > > Option 2: Use aliases instead of real types in param() macros. Will that affect other users of I915_PARAMS_FOR_EACH than _print_param? Either way, thanks for the help towards resolving this! We appreciate it! > > Aliases can be same as in linux/moduleparam.h (charp|int|uint|bool) > We can convert aliases back to real types but it will also allow > to construct proper names for dedicated functions - see [1] > > Michal > > [1] https://patchwork.freedesktop.org/patch/255928/ > > > > > > BR, > > Jani. > > > >> > >>> > >>> The output of 'objdump -D' is identically before and after this change > >>> for GCC regardless of if CONFIG_64BIT is set and allows Clang to link > >>> the kernel successfully with or without CONFIG_64BIT set. > >>> > >>> Link: https://github.com/ClangBuiltLinux/linux/issues/191 > >>> Suggested-by: Nick Desaulniers > >>> Signed-off-by: Nathan Chancellor > >>> --- > >>> drivers/gpu/drm/i915/i915_params.c | 29 +++++++++++++---------------- > >>> 1 file changed, 13 insertions(+), 16 deletions(-) > >>> > >>> diff --git a/drivers/gpu/drm/i915/i915_params.c > >>> b/drivers/gpu/drm/i915/i915_params.c > >>> index 295e981e4a39..a0f20b9b6f2d 100644 > >>> --- a/drivers/gpu/drm/i915/i915_params.c > >>> +++ b/drivers/gpu/drm/i915/i915_params.c > >>> @@ -174,22 +174,19 @@ i915_param_named(enable_dpcd_backlight, bool, > >>> 0600, > >>> i915_param_named(enable_gvt, bool, 0400, > >>> "Enable support for Intel GVT-g graphics virtualization host > >>> support(default:false)"); > >>> > >>> -static __always_inline void _print_param(struct drm_printer *p, > >>> - const char *name, > >>> - const char *type, > >>> - const void *x) > >>> -{ > >>> - if (!__builtin_strcmp(type, "bool")) > >>> - drm_printf(p, "i915.%s=%s\n", name, yesno(*(const bool > >>> *)x)); > >>> - else if (!__builtin_strcmp(type, "int")) > >>> - drm_printf(p, "i915.%s=%d\n", name, *(const int *)x); > >>> - else if (!__builtin_strcmp(type, "unsigned int")) > >>> - drm_printf(p, "i915.%s=%u\n", name, *(const unsigned > >>> int *)x); > >>> - else if (!__builtin_strcmp(type, "char *")) > >>> - drm_printf(p, "i915.%s=%s\n", name, *(const char **)x); > >>> - else > >>> - BUILD_BUG(); > >>> -} > >>> +#define _print_param(p, name, type, > >>> x) \ > >>> +do > >>> { > >>> \ > >>> + if (!__builtin_strcmp(type, > >>> "bool")) \ > >>> + drm_printf(p, "i915.%s=%s\n", name, yesno(*(const bool > >>> *)x)); \ > >>> + else if (!__builtin_strcmp(type, > >>> "int")) \ > >>> + drm_printf(p, "i915.%s=%d\n", name, *(const int > >>> *)x); \ > >>> + else if (!__builtin_strcmp(type, "unsigned > >>> int")) \ > >>> + drm_printf(p, "i915.%s=%u\n", name, *(const unsigned > >>> int *)x); \ > >>> + else if (!__builtin_strcmp(type, "char > >>> *")) \ > >>> + drm_printf(p, "i915.%s=%s\n", name, *(const char > >>> **)x); \ > >>> + > >>> else > >>> \ > >>> + > >>> BUILD_BUG(); \ > >>> +} while (0) > >>> > >>> /** > >>> * i915_params_dump - dump i915 modparams > >>> -- > >>> 2.19.0 > >>> -- Thanks, ~Nick Desaulniers