From patchwork Wed Oct 16 23:02:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nick Desaulniers X-Patchwork-Id: 176537 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp102531ill; Wed, 16 Oct 2019 16:02:40 -0700 (PDT) X-Google-Smtp-Source: APXvYqx52I0u5QXiEvDVKoYNzTsBvsD7SHz5bcSDLCz9uAXCoTA6E8hiV+Y2HlYPB1TGLuFiHNI9 X-Received: by 2002:a17:906:35cb:: with SMTP id p11mr767403ejb.128.1571266960559; Wed, 16 Oct 2019 16:02:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571266960; cv=none; d=google.com; s=arc-20160816; b=Z0SbFaZZY7Ug63eQBrn9HI5oojxvB/5AVqp2S56fKYodZYNfboBYCAJB0y2wryriVA b7QzqdK9OJk3O+euy3O2j6TRW6ISpCsVnIG7w2skqNfrCUqXHDAQ3ZJXaxRa0+2HMkTp 2LvQv00sCAUBcXViDzNLCegzCJOy0RbqURsuZ2L119qx0Srw9GOLWIn7CKfWwewa3/5C 6czxCidkx9hPsOuHaBnQAkV3b2kCNhFz+vkIeR9HFGmtmu+JFJYVckqxW+VUFahCzdyl sL7rI6zpLJ+RWJ4JpB1GOYfRTblhWrFEMtAdchusfUr820pp5Wh/2cPSJHcmQwCG/vrj hbTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:references :mime-version:message-id:in-reply-to:date:dkim-signature; bh=+9wE/YnttgoSYQLeI+fM6xNhxWRLjwkrvMn1N+1ady8=; b=BXQbW+WDnwQYpYeakzvy8z9S1YVjD13lpl4U/8d9W7G09upMiII8Oy+byq65rsFUaL I7oN1dDQC/4hZ3CN4sao04uPVVV5Dgr+kNfUG4p9kbAh39wyolmGzoyZ6KsBOsIulb3n WGJE+RFylOW9oZ582th7tIs4Nlc9z48ldFevWl36Lvm6nRyFhq7e/T3xY3jRe42nEueC tfKDBtSoRU7pcfX7KOk7u/z1RJTU+S3SjTfBb3djqAP83BLKcGjipKekgL+8TGiUaFvr t9vSy14CVub+Eqxil1m4DoXeiU7JQc65epdjyColBZI+rGW9b1KOV2UCpOMufM4wtzzk uEFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="KWxGWHf/"; 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 g17si297346ejd.123.2019.10.16.16.02.40; Wed, 16 Oct 2019 16:02:40 -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="KWxGWHf/"; 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 S2395085AbfJPXCj (ORCPT + 26 others); Wed, 16 Oct 2019 19:02:39 -0400 Received: from mail-pl1-f201.google.com ([209.85.214.201]:45295 "EHLO mail-pl1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391366AbfJPXCh (ORCPT ); Wed, 16 Oct 2019 19:02:37 -0400 Received: by mail-pl1-f201.google.com with SMTP id t12so151622plo.12 for ; Wed, 16 Oct 2019 16:02:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=+9wE/YnttgoSYQLeI+fM6xNhxWRLjwkrvMn1N+1ady8=; b=KWxGWHf/P+f67fdjVt7CHFaUPxIFnuczkzjPcZZra9YWURUHteNwdscbJ2znQA8eDV goEv3nDRQ4QVE54XSj97jGZSKnPPJYm/Ov6TLOC4DeDckmJ9hHj8QLEgDKRumt4d1Wnb 2fHWw5wBhp4xYmQWaql25ZVWU2ghWSggTBnMoDugXAH+1CekRsI4PmfIgmjNGx+fQQKi gO+rfcHvncvjMPD1muXY+aVIPjcsFjSyHleTPM06S5sISHbiSqlBsdVMUZE2yXEoXMpv Bz7Apmfek4PX7D1+ys3wMXOK7h2IXkN+PV4JxSSfBH/QpzCu4c/AagQYlV5ooJOlylQn wLuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=+9wE/YnttgoSYQLeI+fM6xNhxWRLjwkrvMn1N+1ady8=; b=SIJXMHkDHFXDCky4zS4cnz0JUPSChGqwht7LgFnqLJZ4XYowEFY16tRqd18MXNCXuY DTUzO3k1J+oI6L9xRLwW8DkObQXYKnJHzOCdr24r8DHyf8M3Tv3fbdjiiHa88V/XCwr9 JJX+dleHrF3lhgQ8zAKi7ZqTtfwpIN92mQarXA6jF75Y4bVOtDbhgu3NG8iGhUjHt592 FjB11S+cGZO/VdVKxUyAR4V10FNlUNgXkygRYNOtYvRMdwy5XAbJr/SmsXMAwEIgyAz8 Mf2wMH+/+zojUstf6QLsunAYez6gYtRhLOSwWFEt1Lpjb9qBeM6sOQ1CfZE8Smbq3DI3 +YOQ== X-Gm-Message-State: APjAAAUoMmNziWfUpu6zoaYBD+SFWUkkz/I/fRPUd1b+gkni5wLHyQOR tQMeM0h0TkLcMwxPIMGHhIg0NZ/dhJd4BEi3eZY= X-Received: by 2002:a63:e057:: with SMTP id n23mr640963pgj.94.1571266956495; Wed, 16 Oct 2019 16:02:36 -0700 (PDT) Date: Wed, 16 Oct 2019 16:02:07 -0700 In-Reply-To: <20191016230209.39663-1-ndesaulniers@google.com> Message-Id: <20191016230209.39663-2-ndesaulniers@google.com> Mime-Version: 1.0 References: <20191016230209.39663-1-ndesaulniers@google.com> X-Mailer: git-send-email 2.23.0.700.g56cf767bdb-goog Subject: [PATCH 1/3] drm/amdgpu: fix stack alignment ABI mismatch for Clang From: Nick Desaulniers To: harry.wentland@amd.com, alexander.deucher@amd.com Cc: yshuiv7@gmail.com, andrew.cooper3@citrix.com, arnd@arndb.de, clang-built-linux@googlegroups.com, mka@google.com, shirish.s@amd.com, David1.Zhou@amd.com, christian.koenig@amd.com, amd-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org, Nick Desaulniers Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The x86 kernel is compiled with an 8B stack alignment via `-mpreferred-stack-boundary=3` for GCC since 3.6-rc1 via commit d9b0cde91c60 ("x86-64, gcc: Use -mpreferred-stack-boundary=3 if supported") or `-mstack-alignment=8` for Clang. Parts of the AMDGPU driver are compiled with 16B stack alignment. Generally, the stack alignment is part of the ABI. Linking together two different translation units with differing stack alignment is dangerous, particularly when the translation unit with the smaller stack alignment makes calls into the translation unit with the larger stack alignment. While 8B aligned stacks are sometimes also 16B aligned, they are not always. Multiple users have reported General Protection Faults (GPF) when using the AMDGPU driver compiled with Clang. Clang is placing objects in stack slots assuming the stack is 16B aligned, and selecting instructions that require 16B aligned memory operands. At runtime, syscall handlers with 8B aligned stack call into code that assumes 16B stack alignment. When the stack is a multiple of 8B but not 16B, these instructions result in a GPF. Remove the code that added compatibility between the differing compiler flags, as it will result in runtime GPFs when built with Clang. Cleanups for GCC will be sent in later patches in the series. Link: https://github.com/ClangBuiltLinux/linux/issues/735 Debugged-by: Yuxuan Shui Reported-by: Shirish S Reported-by: Yuxuan Shui Suggested-by: Andrew Cooper Signed-off-by: Nick Desaulniers --- drivers/gpu/drm/amd/display/dc/calcs/Makefile | 10 ++++------ drivers/gpu/drm/amd/display/dc/dcn20/Makefile | 10 ++++------ drivers/gpu/drm/amd/display/dc/dcn21/Makefile | 10 ++++------ drivers/gpu/drm/amd/display/dc/dml/Makefile | 10 ++++------ drivers/gpu/drm/amd/display/dc/dsc/Makefile | 10 ++++------ 5 files changed, 20 insertions(+), 30 deletions(-) -- 2.23.0.700.g56cf767bdb-goog Tested-by: Shirish S Reported-by: Shirish S Reported-by: Yuxuan Shui Signed-off-by: Nick Desaulniers diff --git a/drivers/gpu/drm/amd/display/dc/calcs/Makefile b/drivers/gpu/drm/amd/display/dc/calcs/Makefile index 985633c08a26..4b1a8a08a5de 100644 --- a/drivers/gpu/drm/amd/display/dc/calcs/Makefile +++ b/drivers/gpu/drm/amd/display/dc/calcs/Makefile @@ -24,13 +24,11 @@ # It calculates Bandwidth and Watermarks values for HW programming # -ifneq ($(call cc-option, -mpreferred-stack-boundary=4),) - cc_stack_align := -mpreferred-stack-boundary=4 -else ifneq ($(call cc-option, -mstack-alignment=16),) - cc_stack_align := -mstack-alignment=16 -endif +calcs_ccflags := -mhard-float -msse -calcs_ccflags := -mhard-float -msse $(cc_stack_align) +ifdef CONFIG_CC_IS_GCC +calcs_ccflags += -mpreferred-stack-boundary=4 +endif ifdef CONFIG_CC_IS_CLANG calcs_ccflags += -msse2 diff --git a/drivers/gpu/drm/amd/display/dc/dcn20/Makefile b/drivers/gpu/drm/amd/display/dc/dcn20/Makefile index ddb8d5649e79..5fe3eb80075d 100644 --- a/drivers/gpu/drm/amd/display/dc/dcn20/Makefile +++ b/drivers/gpu/drm/amd/display/dc/dcn20/Makefile @@ -10,13 +10,11 @@ ifdef CONFIG_DRM_AMD_DC_DSC_SUPPORT DCN20 += dcn20_dsc.o endif -ifneq ($(call cc-option, -mpreferred-stack-boundary=4),) - cc_stack_align := -mpreferred-stack-boundary=4 -else ifneq ($(call cc-option, -mstack-alignment=16),) - cc_stack_align := -mstack-alignment=16 -endif +CFLAGS_$(AMDDALPATH)/dc/dcn20/dcn20_resource.o := -mhard-float -msse -CFLAGS_$(AMDDALPATH)/dc/dcn20/dcn20_resource.o := -mhard-float -msse $(cc_stack_align) +ifdef CONFIG_CC_IS_GCC +CFLAGS_$(AMDDALPATH)/dc/dcn20/dcn20_resource.o += -mpreferred-stack-boundary=4 +endif ifdef CONFIG_CC_IS_CLANG CFLAGS_$(AMDDALPATH)/dc/dcn20/dcn20_resource.o += -msse2 diff --git a/drivers/gpu/drm/amd/display/dc/dcn21/Makefile b/drivers/gpu/drm/amd/display/dc/dcn21/Makefile index ef673bffc241..7057e20748b9 100644 --- a/drivers/gpu/drm/amd/display/dc/dcn21/Makefile +++ b/drivers/gpu/drm/amd/display/dc/dcn21/Makefile @@ -3,13 +3,11 @@ DCN21 = dcn21_hubp.o dcn21_hubbub.o dcn21_resource.o -ifneq ($(call cc-option, -mpreferred-stack-boundary=4),) - cc_stack_align := -mpreferred-stack-boundary=4 -else ifneq ($(call cc-option, -mstack-alignment=16),) - cc_stack_align := -mstack-alignment=16 -endif +CFLAGS_$(AMDDALPATH)/dc/dcn21/dcn21_resource.o := -mhard-float -msse -CFLAGS_$(AMDDALPATH)/dc/dcn21/dcn21_resource.o := -mhard-float -msse $(cc_stack_align) +ifdef CONFIG_CC_IS_GCC +CFLAGS_$(AMDDALPATH)/dc/dcn21/dcn21_resource.o += -mpreferred-stack-boundary=4 +endif ifdef CONFIG_CC_IS_CLANG CFLAGS_$(AMDDALPATH)/dc/dcn21/dcn21_resource.o += -msse2 diff --git a/drivers/gpu/drm/amd/display/dc/dml/Makefile b/drivers/gpu/drm/amd/display/dc/dml/Makefile index 5b2a65b42403..1bd6e307b7f8 100644 --- a/drivers/gpu/drm/amd/display/dc/dml/Makefile +++ b/drivers/gpu/drm/amd/display/dc/dml/Makefile @@ -24,13 +24,11 @@ # It provides the general basic services required by other DAL # subcomponents. -ifneq ($(call cc-option, -mpreferred-stack-boundary=4),) - cc_stack_align := -mpreferred-stack-boundary=4 -else ifneq ($(call cc-option, -mstack-alignment=16),) - cc_stack_align := -mstack-alignment=16 -endif +dml_ccflags := -mhard-float -msse -dml_ccflags := -mhard-float -msse $(cc_stack_align) +ifdef CONFIG_CC_IS_GCC +dml_ccflags += -mpreferred-stack-boundary=4 +endif ifdef CONFIG_CC_IS_CLANG dml_ccflags += -msse2 diff --git a/drivers/gpu/drm/amd/display/dc/dsc/Makefile b/drivers/gpu/drm/amd/display/dc/dsc/Makefile index b456cd23c6fa..932c3055230e 100644 --- a/drivers/gpu/drm/amd/display/dc/dsc/Makefile +++ b/drivers/gpu/drm/amd/display/dc/dsc/Makefile @@ -1,13 +1,11 @@ # # Makefile for the 'dsc' sub-component of DAL. -ifneq ($(call cc-option, -mpreferred-stack-boundary=4),) - cc_stack_align := -mpreferred-stack-boundary=4 -else ifneq ($(call cc-option, -mstack-alignment=16),) - cc_stack_align := -mstack-alignment=16 -endif +dsc_ccflags := -mhard-float -msse -dsc_ccflags := -mhard-float -msse $(cc_stack_align) +ifdef CONFIG_CC_IS_GCC +dsc_ccflags += -mpreferred-stack-boundary=4 +endif ifdef CONFIG_CC_IS_CLANG dsc_ccflags += -msse2