From patchwork Mon Aug 17 15:11:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 247792 Delivered-To: patch@linaro.org Received: by 2002:a54:3b12:0:0:0:0:0 with SMTP id j18csp2437969ect; Mon, 17 Aug 2020 08:25:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzZTucl8sqBqX5t/3F7PqJKKHQyPlrecgxVeEX2XgXqTqtJLA7EUwezWAbglHmPYJ2xPcu5 X-Received: by 2002:a17:906:401b:: with SMTP id v27mr15437495ejj.300.1597677928799; Mon, 17 Aug 2020 08:25:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597677928; cv=none; d=google.com; s=arc-20160816; b=yJF0iPnrLUBoyrC9wZJjRODqbuwtuzyAQzN6nYtJZm3XstVXJA/xQnTU46c/lCAa/H eS9prN8YbkVO4pG4XG60JAD5EElIuvYdY6OmcJnGoYmujBW7oy/FWDD4xAlwkPku6MmL cecs+0s1Zjymv1anAE62j8cIj3s+akjgX/wcu6yK1DlKVr3KoQYhz+ArFcxBEJvqyUFD Be8eH6zf+9j7/1u5aJH96qZd4c0I3BR1BbiKhtSUJag4ApcoiXSUxA5d+N6QzIWnE8mo QnP8cR/lvmqXiZmCCoOdJPXerYYmRqJvduB6vk9eS7/UHxPxuGRzDQR47skE6dRcElUx hqWQ== 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:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=KY/28G5gN5lV6C1KHKOe22S8ZYB4iWTpP4n9DRtSKMA=; b=AffCN+oVA3vSs8wPL7ATy5/iV3XOiFDTBI9qIu0HD8/Z/jtaXn+oodprwQAzL3xJYN XbxJ3FpOA8+/e3b4xZmGE677NSJCA9mxb3ZCR+sQDz77WbHTvVVmbCYDcA7Okk+7Wt7i kmtXKRFxzexgecDVuwRUo/8Kq4MxAhARNfEtThOiQJ/y5u5WkhlIXqsUd+ZDst7IEG1R 01BJDnBmDn8NeQpohVJO312XYYHHEg3RH/7FHJGrPql0aJ4BY4Vy3/SuopI9I9gCM2dt 4AfHtSAqlKlQ/BCSzwEJWejGoi9FMN/to9xojyYqieYaOVcKu6lo/shNtp+myvlL46N/ 6LHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=QsTt300W; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c21si11094048ejb.724.2020.08.17.08.25.28; Mon, 17 Aug 2020 08:25:28 -0700 (PDT) Received-SPF: pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=QsTt300W; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729732AbgHQPZY (ORCPT + 15 others); Mon, 17 Aug 2020 11:25:24 -0400 Received: from mail.kernel.org ([198.145.29.99]:59068 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729726AbgHQPZW (ORCPT ); Mon, 17 Aug 2020 11:25:22 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 883EB23333; Mon, 17 Aug 2020 15:25:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597677921; bh=A7WEO00NBgNA67+f8S0LHnXokPYYK/LbMQpTTHWvqJE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QsTt300Wksu9U0qoFPOje5dNvditFkODO77J06HbJLJHyUuwxlNHgbD/EQUzpWJMT 0Un4E7rvaS8jDHuBwIXd6k1JrW50O1uaymwLov+dcJc2cAj8bcTvEQyEPGfX+lkHrh loup0e0FT5mkZ3cdsq30hOW8hOka+gddSlt3xnyE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Arnd Bergmann , David Woodhouse , Dmitry Golovin , Linus Torvalds , Nick Desaulniers , Thomas Gleixner , Sedat Dilek , Dennis Zhou , Sasha Levin Subject: [PATCH 5.8 126/464] x86/uaccess: Make __get_user_size() Clang compliant on 32-bit Date: Mon, 17 Aug 2020 17:11:19 +0200 Message-Id: <20200817143839.845895637@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200817143833.737102804@linuxfoundation.org> References: <20200817143833.737102804@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Nick Desaulniers [ Upstream commit 158807de5822d1079e162a3762956fd743dd483e ] Clang fails to compile __get_user_size() on 32-bit for the following code: long long val; __get_user(val, usrptr); with: error: invalid output size for constraint '=q' GCC compiles the same code without complaints. The reason is that GCC and Clang are architecturally different, which leads to subtle issues for code that's invalid but clearly dead, i.e. with code that emulates polymorphism with the preprocessor and sizeof. GCC will perform semantic analysis after early inlining and dead code elimination, so it will not warn on invalid code that's dead. Clang strictly performs optimizations after semantic analysis, so it will warn for dead code. Neither Clang nor GCC like this very much with -m32: long long ret; asm ("movb $5, %0" : "=q" (ret)); However, GCC can tolerate this variant: long long ret; switch (sizeof(ret)) { case 1: asm ("movb $5, %0" : "=q" (ret)); break; case 8:; } Clang, on the other hand, won't accept that because it validates the inline asm for the '1' case before the optimisation phase where it realises that it wouldn't have to emit it anyway. If LLVM (Clang's "back end") fails such as during instruction selection or register allocation, it cannot provide accurate diagnostics (warnings / errors) that contain line information, as the AST has been discarded from memory at that point. While there have been early discussions about having C/C++ specific language optimizations in Clang via the use of MLIR, which would enable such earlier optimizations, such work is not scoped and likely a multi-year endeavor. It was discussed to change the asm output constraint for the one byte case from "=q" to "=r". While it works for 64-bit, it fails on 32-bit. With '=r' the compiler could fail to chose a register accessible as high/low which is required for the byte operation. If that happens the assembly will fail. Use a local temporary variable of type 'unsigned char' as output for the byte copy inline asm and then assign it to the real output variable. This prevents Clang from failing the semantic analysis in the above case. The resulting code for the actual one byte copy is not affected as the temporary variable is optimized out. [ tglx: Amended changelog ] Reported-by: Arnd Bergmann Reported-by: David Woodhouse Reported-by: Dmitry Golovin Reported-by: Linus Torvalds Signed-off-by: Nick Desaulniers Signed-off-by: Thomas Gleixner Tested-by: Sedat Dilek Acked-by: Linus Torvalds Acked-by: Dennis Zhou Link: https://bugs.llvm.org/show_bug.cgi?id=33587 Link: https://github.com/ClangBuiltLinux/linux/issues/3 Link: https://github.com/ClangBuiltLinux/linux/issues/194 Link: https://github.com/ClangBuiltLinux/linux/issues/781 Link: https://lore.kernel.org/lkml/20180209161833.4605-1-dwmw2@infradead.org/ Link: https://lore.kernel.org/lkml/CAK8P3a1EBaWdbAEzirFDSgHVJMtWjuNt2HGG8z+vpXeNHwETFQ@mail.gmail.com/ Link: https://lkml.kernel.org/r/20200720204925.3654302-12-ndesaulniers@google.com Signed-off-by: Sasha Levin --- arch/x86/include/asm/uaccess.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) -- 2.25.1 diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h index 18dfa07d3ef0d..2f3e8f2a958f6 100644 --- a/arch/x86/include/asm/uaccess.h +++ b/arch/x86/include/asm/uaccess.h @@ -314,11 +314,14 @@ do { \ #define __get_user_size(x, ptr, size, retval) \ do { \ + unsigned char x_u8__; \ + \ retval = 0; \ __chk_user_ptr(ptr); \ switch (size) { \ case 1: \ - __get_user_asm(x, ptr, retval, "b", "=q"); \ + __get_user_asm(x_u8__, ptr, retval, "b", "=q"); \ + (x) = x_u8__; \ break; \ case 2: \ __get_user_asm(x, ptr, retval, "w", "=r"); \