From patchwork Wed Jul 11 11:25:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tamar Christina X-Patchwork-Id: 942452 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-481350-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="Z5z6H3BJ"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=armh.onmicrosoft.com header.i=@armh.onmicrosoft.com header.b="DWa0p40J"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41QcFD5Gb8z9s01 for ; Wed, 11 Jul 2018 21:25:36 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:mime-version:content-type; q=dns; s=default; b=PFQnkKhx34ErE5YE7yvJrpSFFL3oT/ngvGr2QHOiVFNEiWri8/ RK1hK8j7fJvescN0qx/DAXQp8RL+qDwXG4Rv1gAYqjP1SCUNLR/vsSDco7J0fDQy FQeFNvKajo9W0NpzAhB9YPQkgZu+qoEy+2XxiDSMo7b2c56tEHK+gwy6w= 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:date :from:to:cc:subject:message-id:mime-version:content-type; s= default; bh=m9tfH0QUPbBE4JSYr7FC3Yh7VHA=; b=Z5z6H3BJDGgK04iulB3g jy/NkzFTlejAyjDCB5TXzfztBljDkx/A9eWBaiiaTJZbvDMV5nDdW0kjj0meVGaf KhKh7X26XVAUHjNSETpzjv6GKbzREoQ6svn83SWjpMyOjECGnNrf2G/jaffL5xY1 MpWbb/xP/64bq4a1eSKd1qU= Received: (qmail 129641 invoked by alias); 11 Jul 2018 11:25:19 -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 129475 invoked by uid 89); 11 Jul 2018 11:25:18 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: EUR01-VE1-obe.outbound.protection.outlook.com Received: from mail-ve1eur01on0073.outbound.protection.outlook.com (HELO EUR01-VE1-obe.outbound.protection.outlook.com) (104.47.1.73) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 11 Jul 2018 11:25:15 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector1-arm-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=OengkW3+oB/WPlK9ymdwTe0N03YFMA3VFCOPaa6VdkA=; b=DWa0p40J3dtEll0SAxKSWUBORfpOxbxCZaVGoRoDpYruc1OUnWwMjuYnZBsw2/69WLsr+NLa0fTCARjf6rnifEjN11M456MqNrKqXkFQ8slioGSIcvBsXnPmTPTiEVy9E1UrOJPIwLAqVaZ5unG/ZwwzeGwL/5zyQF4vjQNA3TI= Received: from arm.com (217.140.96.140) by VI1PR08MB0750.eurprd08.prod.outlook.com (2a01:111:e400:5a04::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.952.17; Wed, 11 Jul 2018 11:25:12 +0000 Date: Wed, 11 Jul 2018 12:25:08 +0100 From: Tamar Christina To: gcc-patches@gcc.gnu.org Cc: nd@arm.com, james.greenhalgh@arm.com, Richard.Earnshaw@arm.com, Marcus.Shawcroft@arm.com Subject: [PATCH][GCC][AArch64] Validate and set default parameters for stack-clash. [Patch (3/3)] Message-ID: <20180711112506.GA16112@arm.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Tamar.Christina@arm.com; Received-SPF: None (protection.outlook.com: arm.com does not designate permitted sender hosts) X-IsSubscribed: yes Hi All, This patch defines the default parameters and validation for the aarch64 stack clash probing interval and guard sizes. It cleans up the previous implementation and insures that at no point the invalidate arguments are present in the pipeline for AArch64. Currently they are only corrected once cc1 initalizes the back-end. The default for AArch64 is 64 KB for both of these and we only support 4 KB and 64 KB probes. We also enforce that any value you set here for the parameters must be in sync. If an invalid value is specified an error will be generated and compilation aborted. Bootstrapped Regtested on aarch64-none-linux-gnu and no issues. Target was tested with stack clash on and off by default. Ok for trunk? Thanks, Tamar gcc/ 2018-07-11 Tamar Christina * common/config/aarch64/aarch64-common.c (TARGET_OPTION_DEFAULT_PARAM, aarch64_option_default_param): New. (params.h): Include. (TARGET_OPTION_VALIDATE_PARAM, aarch64_option_validate_param): New. * config/aarch64/aarch64.c (aarch64_override_options_internal): Simplify stack-clash protection validation code. diff --git a/gcc/common/config/aarch64/aarch64-common.c b/gcc/common/config/aarch64/aarch64-common.c index 292fb818705d4650113da59a6d88cf2aa7c9e57d..73f2f95e8cb989f93e7a17bbf274f4364e660c0d 100644 --- a/gcc/common/config/aarch64/aarch64-common.c +++ b/gcc/common/config/aarch64/aarch64-common.c @@ -30,6 +30,7 @@ #include "opts.h" #include "flags.h" #include "diagnostic.h" +#include "params.h" #ifdef TARGET_BIG_ENDIAN_DEFAULT #undef TARGET_DEFAULT_TARGET_FLAGS @@ -41,6 +42,10 @@ #undef TARGET_OPTION_OPTIMIZATION_TABLE #define TARGET_OPTION_OPTIMIZATION_TABLE aarch_option_optimization_table +#undef TARGET_OPTION_DEFAULT_PARAMS +#define TARGET_OPTION_DEFAULT_PARAMS aarch64_option_default_params +#undef TARGET_OPTION_VALIDATE_PARAM +#define TARGET_OPTION_VALIDATE_PARAM aarch64_option_validate_param /* Set default optimization options. */ static const struct default_options aarch_option_optimization_table[] = @@ -60,6 +65,52 @@ static const struct default_options aarch_option_optimization_table[] = { OPT_LEVELS_NONE, 0, NULL, 0 } }; +/* Implement target validation TARGET_OPTION_DEFAULT_PARAM. */ + +static bool +aarch64_option_validate_param (const int value, const int param) +{ + /* Check that both parameters are the same. */ + if (param == (int) PARAM_STACK_CLASH_PROTECTION_GUARD_SIZE) + { + if (value != 12 && value != 16) + { + error ("only values 12 (4 KB) and 16 (64 KB) are supported for guard " + "size. Given value %d (%llu KB) is out of range.\n", + value, (1ULL << value) / 1024ULL); + return false; + } + + /* Enforce that they are the same. */ + set_default_param_value (PARAM_STACK_CLASH_PROTECTION_PROBE_INTERVAL, + value); + } + + return true; +} + +/* Implement TARGET_OPTION_DEFAULT_PARAMS. */ + +static void +aarch64_option_default_params (void) +{ + /* We assume the guard page is 64k. */ + int index = (int) PARAM_STACK_CLASH_PROTECTION_GUARD_SIZE; + if (!compiler_params[index].configure_value) + set_default_param_value (PARAM_STACK_CLASH_PROTECTION_GUARD_SIZE, 16); + + int guard_size + = default_param_value (PARAM_STACK_CLASH_PROTECTION_GUARD_SIZE); + + /* Set the interval parameter to be the same as the guard size. This way the + mid-end code does the right thing for us. */ + set_default_param_value (PARAM_STACK_CLASH_PROTECTION_PROBE_INTERVAL, + guard_size); + + /* Validate the options. */ + aarch64_option_validate_param (guard_size, index); +} + /* Implement TARGET_HANDLE_OPTION. This function handles the target specific options for CPU/target selection. diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c index e62d8a92ff53128e5e10ffd3b52eb8898869b756..dfc0da6a27d6007c669db32abe5c7b0248ea28a5 100644 --- a/gcc/config/aarch64/aarch64.c +++ b/gcc/config/aarch64/aarch64.c @@ -10900,41 +10900,21 @@ aarch64_override_options_internal (struct gcc_options *opts) opts->x_param_values, global_options_set.x_param_values); - /* Use the alternative scheduling-pressure algorithm by default. */ - maybe_set_param_value (PARAM_SCHED_PRESSURE_ALGORITHM, SCHED_PRESSURE_MODEL, - opts->x_param_values, - global_options_set.x_param_values); - - /* If the user hasn't change it via configure then set the default to 64 KB - for the backend. */ - if (DEFAULT_STK_CLASH_GUARD_SIZE == 0) - maybe_set_param_value (PARAM_STACK_CLASH_PROTECTION_GUARD_SIZE, 16, - opts->x_param_values, - global_options_set.x_param_values); - - /* Validate the guard size. */ - int guard_size = PARAM_VALUE (PARAM_STACK_CLASH_PROTECTION_GUARD_SIZE); - if (guard_size != 12 && guard_size != 16) - error ("only values 12 (4 KB) and 16 (64 KB) are supported for guard " - "size. Given value %d (%llu KB) is out of range.\n", - guard_size, (1ULL << guard_size) / 1024ULL); - - /* Enforce that interval is the same size as size so the mid-end does the - right thing. */ - maybe_set_param_value (PARAM_STACK_CLASH_PROTECTION_PROBE_INTERVAL, - guard_size, - opts->x_param_values, - global_options_set.x_param_values); - /* The maybe_set calls won't update the value if the user has explicitly set one. Which means we need to validate that probing interval and guard size are equal. */ int probe_interval = PARAM_VALUE (PARAM_STACK_CLASH_PROTECTION_PROBE_INTERVAL); + int guard_size = PARAM_VALUE (PARAM_STACK_CLASH_PROTECTION_GUARD_SIZE); if (guard_size != probe_interval) error ("stack clash guard size '%d' must be equal to probing interval " "'%d'\n", guard_size, probe_interval); + /* Use the alternative scheduling-pressure algorithm by default. */ + maybe_set_param_value (PARAM_SCHED_PRESSURE_ALGORITHM, SCHED_PRESSURE_MODEL, + opts->x_param_values, + global_options_set.x_param_values); + /* Enable sw prefetching at specified optimization level for CPUS that have prefetch. Lower optimization level threshold by 1 when profiling is enabled. */