From patchwork Wed Jan 17 14:55:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Richard Earnshaw \(lists\)" X-Patchwork-Id: 124807 Delivered-To: patch@linaro.org Received: by 10.46.62.1 with SMTP id l1csp70752lja; Wed, 17 Jan 2018 06:56:22 -0800 (PST) X-Google-Smtp-Source: ACJfBou75aFQULKNc+KXeIvJW4FKU3CZoEuVELrbeH8Cavp7Ye7uDW469m/xQ/0hEHdezsMcrzO1 X-Received: by 10.98.147.7 with SMTP id b7mr38160428pfe.236.1516200982677; Wed, 17 Jan 2018 06:56:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516200982; cv=none; d=google.com; s=arc-20160816; b=H9oqE9QuxIA77T6SDKYM4mVccAcNLuzk6VNkBLrA+Yi4xmitkxQqzyHhIfEgFq3m3d o0fPrWn2z+ZBwj4yaHftJkFt7luO0q1gQQiZexG9RTmDzRZZ0s4q/pD7hH8Hjz29aLlO lL3a4raijV/hyMKjjRwizvZJJyEWw6ojHiHxM2jsh1XzYB21bNIhD6HEf9P0PWERqCh3 1YN06ADiq+WbScop1DiPB4Vxsk1ZQQvKYG7itCkDk5Y21Orfu/m0BiJwUXJ6is8zdHBg 5ikepph6P/uWdPeATvhod3N7xMchfCs6c3QP4X35S92rBbkrEDm7W/WBQCeQThtJivNc 2Vsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:in-reply-to:message-id:date:subject:cc:to:from :delivered-to:sender:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:mailing-list:dkim-signature :domainkey-signature:arc-authentication-results; bh=wUW7r7SPm4b/+Z/GNyrB2XoK+MP3E3QJI2frxnjPMa4=; b=hq1R7X89IL8ictntzNZcZvvgwo/HR99C5WxI9NvVnTEx7E5WNYzpVnAz33tMlQBkzE gzhZ7x3K0NEKa/CkfkBDqrPwXytyL0HpHc8JsJozyX28lygNN17VY755jI/O1hrCUBYd tZagg9dn9UoInMdqTxPhJOQqRYUR4ZbxOwqBLrvGk5sZk1nkqREfZPREGeFqjRuUHH+J mIVuuKcN1uLpJ8aQ/a2XnuNpPrrpfPiqvb0BYFn3fuTIvr1E2AAGf+ebfGewjM7i43+L lToEuo6rgGGHmxFRjes0RoSTX/wjhnPnXJqHoS3BoSsWFb2XQ1L1anlp4RiccQOKw222 Vgwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=jIii1eOe; spf=pass (google.com: domain of gcc-patches-return-471476-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-471476-patch=linaro.org@gcc.gnu.org Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id m2si4017391pgd.498.2018.01.17.06.56.22 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 Jan 2018 06:56:22 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-return-471476-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=jIii1eOe; spf=pass (google.com: domain of gcc-patches-return-471476-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-471476-patch=linaro.org@gcc.gnu.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:mime-version :content-type; q=dns; s=default; b=PLpU5eQaEwtec6MJ6NCZjpHzpn9ff sGDvtEPO7mLfbN24PsMQK1nWfuoZTX+FqiRVgoflTreRXH2H/PeJVMp2K97WzQTt TuDbtexdCqokRGm/8lH5k9Ur/46A/C7nYSm8Ss6i3JTYRzwj530oTDw36z0kk6mp sqMftU2+PoLFhI= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:mime-version :content-type; s=default; bh=ertddsZXtrcknueHlnNi/DDBW5c=; b=jIi i1eOeNBEHciCEHwURYxvMzMVAMc+igNPd2LBIA1Xc+6AWbC8hfYo6XCxeVPjtKG5 tl5AXbBlgjIJIEPYT21HoST9T5qFcmzXqP/q5Fz68nO5Lat6RG+J5U7U7eLemk+K vasx8BYyZI32RMRfBJtpcFWr7vGq+CGl5F473CGE= Received: (qmail 84476 invoked by alias); 17 Jan 2018 14:56:10 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 84463 invoked by uid 89); 17 Jan 2018 14:56:10 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.9 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=one-off, oneoff, Hx-languages-length:3111, protect X-HELO: foss.arm.com Received: from usa-sjc-mx-foss1.foss.arm.com (HELO foss.arm.com) (217.140.101.70) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 17 Jan 2018 14:56:08 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 7D1DD1435; Wed, 17 Jan 2018 06:56:06 -0800 (PST) Received: from e105689-lin.cambridge.arm.com (e105689-lin.cambridge.arm.com [10.2.207.32]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id B3FD73F557; Wed, 17 Jan 2018 06:56:05 -0800 (PST) From: Richard Earnshaw To: gcc-patches@gcc.gnu.org Cc: Richard Earnshaw Subject: [PATCH 0/3] [v2] Implement __builtin_speculation_safe_load Date: Wed, 17 Jan 2018 14:55:33 +0000 Message-Id: In-Reply-To: MIME-Version: 1.0 This patch series is version 2 for a patch to protect against speculative use of a load instruction. It's based on a roll-up of the feedback from the first version. What's changed since v1? First, and foremost, the API has changed to make it possible to reduce the amount of code that needs to be generated on architectures that provide an unconditional speculation barrier. Although the builtin still requires the additional operands (and does some checking to ensure that they aren't completely unreasonable), back-end expansion can ignore them and simply emit a load instruction along with the barrier operation.. Secondly, I've dropped the failval parameter. With the new API, with undefined behaviour for an out-of-bounds access, this paramter no-longer makes sense. Thirdly, based on off-list comments, I've dropped the ability to make upper_bound NULL. As a bounds value it was not particularly logical and coding it requierd special handling in the back-end (wrong code would be generated otherwise). By removing it the bounds are now all natural. (NULL is still supported as a lower bound, nothing can be less than address 0 --- at least on unsigned addressing-mode machines, which appear to be all that GCC supports --- so it is a simple back-end optimization to drop the check in this case.) Finally, I've changed the name of the builtin. This was mostly for Arm's benefit since we already have some folk building code with the old API and I need to be able to transition them cleanly to the new one. This is a one-off change, I'm not intending to support such renames if we have to iterate again on this builtin before the initial commit (ie I won't do it again, promise). I've updated the documentation for the changes, please read that for additional details (in patch 1). Richi commented that he thought some examples would help: I agree, but feel that putting them in extend.texi with the builtin itself doesn't really fit with the rest of that section - I think a web, or wiki page on the subject would be a better bet. That can be kept up-to-date more easily than the documentation that comes with the compiler. R. Richard Earnshaw (3): [builtins] Generic support for __builtin_speculation_safe_load() [aarch64] Implement support for __builtin_speculation_safe_load [arm] Implement support for the de-speculation intrinsic gcc/builtin-types.def | 16 +++++ gcc/builtins.c | 81 ++++++++++++++++++++++ gcc/builtins.def | 17 +++++ gcc/c-family/c-common.c | 152 ++++++++++++++++++++++++++++++++++++++++++ gcc/c-family/c-cppbuiltin.c | 5 +- gcc/config/aarch64/aarch64.c | 81 ++++++++++++++++++++++ gcc/config/aarch64/aarch64.md | 28 ++++++++ gcc/config/arm/arm.c | 100 +++++++++++++++++++++++++++ gcc/config/arm/arm.md | 40 ++++++++++- gcc/config/arm/unspecs.md | 1 + gcc/doc/cpp.texi | 4 ++ gcc/doc/extend.texi | 68 +++++++++++++++++++ gcc/doc/tm.texi | 9 +++ gcc/doc/tm.texi.in | 2 + gcc/target.def | 34 ++++++++++ gcc/targhooks.c | 59 ++++++++++++++++ gcc/targhooks.h | 3 + 17 files changed, 698 insertions(+), 2 deletions(-)