Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp1461890ybb; Thu, 2 Apr 2020 00:58:55 -0700 (PDT) X-Google-Smtp-Source: APiQypJl1Be5MRGev3/zhHhnY1eQ3Z2JEqC0Qhc6PEnjJuls362bxIgzxJsvlmfb5xc+4Nw0Qygg X-Received: by 2002:a05:6830:1104:: with SMTP id w4mr1506514otq.54.1585814335127; Thu, 02 Apr 2020 00:58:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585814335; cv=none; d=google.com; s=arc-20160816; b=nOmGi27R5a8UU4FysgjrS8zZsIgJW8yj7egUr+L47IEnwyPeY8OVy7tdd8IGaKtnrz JcrtYCzSmTn4kJHpmF4Kxc8RahsYFBCxaZRaXy/KV89u0aLPKJWr7Yg+4/EHC7a2cgcv pqBqgySLmiyxz1A6rhAKWB7TS9JLcR8VXFvLahlV4TMXxwYDEZP+PAwXe2g+PyJfthok oJPZSlK72wihPhKBhwXB3DXccH6M4sTvzze0zAhwlOh5YSLt1BUqEdoFddzicr9XcmXk Rf2usWCu9Rp+7uhDWQb7rpUlMfYA2VAHxDJKMeES9HAxvNScbNoicF8H614XMRSsgweX C8jA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=NLxAfO/+CXjGBU0lneDYEfTm3/RVeCex0QsJS4HUhZc=; b=jhwtj7e6dKO37KbFpS6zHxfUXpBZRYoZ+AoeCbMDJ+H+DuG56RZrLJr6OcNVFGpscC ZNiY/KwFNF7/dO0daQodh0dvcFUNWM5+hiKSMofM3qh3gxThYlRQzr6mAnkkRCPsfEB/ 2VvjPIPBuPrhlrqTpRDx2Qn4AkuRwg+Fy+Fjgzi9Hb/uz8vdf1EkyLwCEY4rN8urzSZr WWmwEGyO8Cvd4b5NoaMefq1QXZVQt5Y8GcptXqI9H/ZU+alVmG2yb7WudiWN3o/eM7mT KF437M/cAWtMmC2pvi2GlJNusioczp2CIadyUlm1DCFKRUsMLtT9A72f7sOHJ3UzKGUE 31Kg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=RmbAMcl8; 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 v18si2211917oth.1.2020.04.02.00.58.43; Thu, 02 Apr 2020 00:58:55 -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=RmbAMcl8; 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 S2387599AbgDBH4t (ORCPT + 99 others); Thu, 2 Apr 2020 03:56:49 -0400 Received: from mail-lf1-f67.google.com ([209.85.167.67]:40054 "EHLO mail-lf1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725965AbgDBH4t (ORCPT ); Thu, 2 Apr 2020 03:56:49 -0400 Received: by mail-lf1-f67.google.com with SMTP id j17so1901317lfe.7 for ; Thu, 02 Apr 2020 00:56:46 -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:content-transfer-encoding; bh=NLxAfO/+CXjGBU0lneDYEfTm3/RVeCex0QsJS4HUhZc=; b=RmbAMcl888PHsTzOLIAl3LFnAF/LaClsZoOPozQJSeYjsZqb0oxpAyEx6/MxUb3vFY Q2kOTxQb/Gp67rDIH00o5g7ZBUV1U1VoYnaTHxaeGVwNWK6fkxOQODwh+Z2bnvv5ymsJ sijSpJjrPsy8TmsG2arBREV/jexcBBiKN+uhkIlwRKTF08AOQJKOujRbDytrEkKempwC hmbnjA5WnLz0YNt8y32d+aeA89hLAOiBH1eWsnssiGJIqFn8K+dZST9PfqBKJWg1FXy8 DnviHEtx46AAaVg5SurPy8EP3SIZDbX1Ukd8lM/iwKozhzQUzTok7u1zT18BzBpufgPQ LHNQ== 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:content-transfer-encoding; bh=NLxAfO/+CXjGBU0lneDYEfTm3/RVeCex0QsJS4HUhZc=; b=nK6Tn8Iy4368Fgaq/K7yNtylJoG3RpW95uYQMfDdzzF7znCQD6Um8Nbf0WHj2FKuy1 Z0QDBZ4Y/CHi/kqz//ak2CICCjcXRK7QjP6hpDo0aKgP3cknirWQBRbUGdScAEydB/PD k4uBse6CZP9Tq52nzqHSGes1q+WK2lcdKdv062mMvQMjEsqgvuC2X7i4smx4NOuFTfT7 uEpbd1Rwyz6RwKVcejYGGuqGylWKy0QTA+gDepw4t4w0auJ25oT4WuXIR/tQuFhUtee7 geUXSTgJWT+U6+bm5JGPiw+KdeGG3iEMg8lXfAJW7OZrLWwbkcDvHScFpz54ZinZFYYo fzjA== X-Gm-Message-State: AGi0Pua5zL2D0NcoQFHzEV8HYR0gvOtynbzHRTbMIyl1wnMVOV158BTf MRS3yUa4j5Cz5ERLhMhpxax92zO+sLudJOYI/a6mvg== X-Received: by 2002:a19:6e47:: with SMTP id q7mr1311472lfk.164.1585814204978; Thu, 02 Apr 2020 00:56:44 -0700 (PDT) MIME-Version: 1.0 References: <4c5fe55d-9db9-2f61-59b2-1fb2e1b45ed0@amd.com> In-Reply-To: <4c5fe55d-9db9-2f61-59b2-1fb2e1b45ed0@amd.com> From: Jann Horn Date: Thu, 2 Apr 2020 09:56:18 +0200 Message-ID: Subject: Re: AMD DC graphics display code enables -mhard-float, -msse, -msse2 without any visible FPU state protection To: =?UTF-8?Q?Christian_K=C3=B6nig?= Cc: Harry Wentland , Leo Li , amd-gfx@lists.freedesktop.org, Alex Deucher , "David (ChunMing) Zhou" , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , "the arch/x86 maintainers" , kernel list , Josh Poimboeuf , Andy Lutomirski Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Apr 2, 2020 at 9:34 AM Christian K=C3=B6nig wrote: > Am 02.04.20 um 04:34 schrieb Jann Horn: > > [x86 folks in CC so that they can chime in on the precise rules for thi= s stuff] > > I noticed that several makefiles under drivers/gpu/drm/amd/display/dc/ > > turn on floating-point instructions in the compiler flags > > (-mhard-float, -msse and -msse2) in order to make the "float" and > > "double" types usable from C code without requiring helper functions. > > > > However, as far as I know, code running in normal kernel context isn't > > allowed to use floating-point registers without special protection > > using helpers like kernel_fpu_begin() and kernel_fpu_end() (which also > > require that the protected code never blocks). If you violate that > > rule, that can lead to various issues - among other things, I think > > the kernel will clobber userspace FPU register state, and I think the > > kernel code can blow up if a context switch happens at the wrong time, > > since in-kernel task switches don't preserve FPU state. > > > > Is there some hidden trick I'm missing that makes it okay to use FPU > > registers here? > > > > I would try testing this, but unfortunately none of the AMD devices I > > have here have the appropriate graphics hardware... > > yes, using the floating point calculations in the display code has been > a source of numerous problems and confusion in the past. > > The calls to kernel_fpu_begin() and kernel_fpu_end() are hidden behind > the DC_FP_START() and DC_FP_END() macros which are supposed to hide the > architecture depend handling for x86 and PPC64. Hmm... but as far as I can tell, you're using those macros from inside functions that are already compiled with the FPU on: - drivers/gpu/drm/amd/display/dc/calcs/dcn_calcs.c uses the macros, but is already compiled with calcs_ccflags - drivers/gpu/drm/amd/display/dc/dcn20/dcn20_resource.c uses the macros, but is already compiled with "-mhard-float -msse -msse2" - drivers/gpu/drm/amd/display/dc/dcn21/dcn21_resource.c uses the macros, but is already compiled with "-mhard-float -msse -msse2" AFAIK as soon as you enter any function in any file compiled with FPU instructions, you may encounter SSE instructions, e.g. via things like compiler-generated memory-zeroing code - not just when you're actually using doubles or floats.