Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp808086img; Mon, 18 Mar 2019 14:53:31 -0700 (PDT) X-Google-Smtp-Source: APXvYqw6hrA9/lQgW1h5sMw0dx7X/dmsbk36HHGH6jGzDtCosVaK8eE+1qRv8n1bNibvIQtIT92R X-Received: by 2002:a63:e70c:: with SMTP id b12mr4434875pgi.399.1552946011061; Mon, 18 Mar 2019 14:53:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552946011; cv=none; d=google.com; s=arc-20160816; b=KZaxle4KP15eacAbH5PABt2cioqIeKQF2+Ps1zl/syGvMXW6bXNK0EeEdOxQzXzGQc r97jL5Rnu6K423Ipwd7BRsY0aqlBBzOnNonTj36SX/SA3TjYH+C6fBJb0jby8gTem4yI dO+d7xzHDxuOLGIvDZIa49lSu9w3mNiz0kher61FoVGVk167+B+9NoK86DXLJjNhvQEh dtES5RrqnDQOFKbkBZWOgUNJHYclHg3zdUPyQFO12xAnp3+O0uwG+VuT+gWQA35s7oYa IesNakYST4SWS5N+T2dk/XsKdFEmVJOIXfFzruMGdl6pjOaZWPlmq9ZWCzcORCyfGBIr q45Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:from:cc:to:subject :content-transfer-encoding:mime-version:references:in-reply-to :user-agent:date; bh=oPTAtFdnuxhGIYunol/MaqzMIo428Sm8Y6RclU0UVno=; b=W8CF0PeHWRAcRSYEFPfjbzQh0uZyafZeCWL8hQOIPKEY6KbaFxvOg566+iqNAQ40Pa o3NB7IqmyhwL0o+rN8mVset0fGymIzuhzwNpsislt7Ltxkch3AfaQl1V6kqqkPMsIhuW a9Tp6q0vI1djCxUXCpXRwahE3y2fyC7WB2X8AQoZ9eEhrlMqdtzBoAJcZq4O331SM8Y6 sxosaXBFRJfUX093M2QP2ZZhBC0AFw6bkCUWwkUuzGnnCObT4FB3AzKJPDX4yighWmMM vwlOYVqv/lAnuVEY3yR9Q0JXe2ZXQk9rqZLW7okso67QnJzjBOciukPbRB2Q5LIfO6rn +Dxw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 42si10842793pla.391.2019.03.18.14.53.14; Mon, 18 Mar 2019 14:53:31 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727490AbfCRVvN convert rfc822-to-8bit (ORCPT + 99 others); Mon, 18 Mar 2019 17:51:13 -0400 Received: from terminus.zytor.com ([198.137.202.136]:52433 "EHLO mail.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727089AbfCRVvN (ORCPT ); Mon, 18 Mar 2019 17:51:13 -0400 Received: from [IPv6:2607:fb90:8435:e408:e1a9:1fde:6fc9:a6d9] ([IPv6:2607:fb90:8435:e408:e1a9:1fde:6fc9:a6d9]) (authenticated bits=0) by mail.zytor.com (8.15.2/8.15.2) with ESMTPSA id x2ILol0d3146907 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NO); Mon, 18 Mar 2019 14:50:48 -0700 Date: Mon, 18 Mar 2019 14:50:44 -0700 User-Agent: K-9 Mail for Android In-Reply-To: <20190318213113.GI112750@google.com> References: <20190318213113.GI112750@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8BIT Subject: Re: [PATCH] lib: Add shared copy of __lshrti3 from libgcc To: Matthias Kaehlcke , Andy Lutomirski , Thomas Gleixner , Ingo Molnar , Borislav Petkov CC: x86@kernel.org, linux-kernel@vger.kernel.org, Nick Desaulniers , Manoj Gupta , Tiancong Wang , Stephen Hines , clang-built-linux@googlegroups.com From: hpa@zytor.com Message-ID: <25133BBA-9121-4B3A-865B-085BFC5F154C@zytor.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On March 18, 2019 2:31:13 PM PDT, Matthias Kaehlcke wrote: >On Fri, Mar 15, 2019 at 01:54:50PM -0700, Matthias Kaehlcke wrote: >> The compiler may emit calls to __lshrti3 from the compiler runtime >> library, which results in undefined references: >> >> arch/x86/kvm/x86.o: In function `mul_u64_u64_shr': >> include/linux/math64.h:186: undefined reference to `__lshrti3' >> >> Add a copy of the __lshrti3 libgcc routine (from gcc v4.9.2). >> >> Include the function for x86 builds with clang, which is the >> environment where the above error was observed. >> >> Signed-off-by: Matthias Kaehlcke > >With "Revert "kbuild: use -Oz instead of -Os when using clang" >(https://lore.kernel.org/patchwork/patch/1051932/) the above >error is fixed, a few comments inline for if the patch is >resurrected in the future because __lshrti3 is emitted in a >different context. > >> diff --git a/include/linux/libgcc.h b/include/linux/libgcc.h >> index 32e1e0f4b2d0..a71036471838 100644 >> --- a/include/linux/libgcc.h >> +++ b/include/linux/libgcc.h >> @@ -22,15 +22,26 @@ >> #include >> >> typedef int word_type __attribute__ ((mode (__word__))); >> +typedef int TItype __attribute__ ((mode (TI))); > >Consider using __int128 instead. Definition and use need a >'defined(__SIZEOF_INT128__)' guard (similar for mode (TI)), since >these 128 bit types aren't supported on all platforms. > >> #ifdef __BIG_ENDIAN >> struct DWstruct { >> int high, low; >> }; >> + >> +struct DWstruct128 { >> + long long high, low; >> +}; > >This struct isn't needed, struct DWstruct can be used. > >> diff --git a/lib/lshrti3.c b/lib/lshrti3.c >> new file mode 100644 >> index 000000000000..2d2123bb3030 >> --- /dev/null >> +++ b/lib/lshrti3.c >> @@ -0,0 +1,31 @@ >> +// SPDX-License-Identifier: GPL-2.0 >> + >> +#include >> +#include >> + >> +long long __lshrti3(long long u, word_type b) > >use TItype for input/output, which is what gcc does, though the above >matches the interface in the documentation. > >> +{ >> + DWunion128 uu, w; >> + word_type bm; >> + >> + if (b == 0) >> + return u; >> + >> + uu.ll = u; >> + bm = 64 - b; >> + >> + if (bm <= 0) { >> + w.s.high = 0; >> + w.s.low = (unsigned long long) uu.s.high >> -bm; > >include and use u64 instead of unsigned long long. Ok, now I'm really puzzled. How could we need a 128-bit shift when the prototype only has 64 bits of input?! -- Sent from my Android device with K-9 Mail. Please excuse my brevity.