[{"id":1768576,"web_url":"http://patchwork.ozlabs.org/comment/1768576/","msgid":"<878thha0si.fsf@linaro.org>","list_archive_url":null,"date":"2017-09-14T13:05:01","subject":"Re: [PATCH v2 21/28] arm64/sve: Add sysctl to set the default\n\tvector length for new processes","submitter":{"id":39532,"url":"http://patchwork.ozlabs.org/api/people/39532/","name":"Alex Bennée","email":"alex.bennee@linaro.org"},"content":"Dave Martin <Dave.Martin@arm.com> writes:\n\n> Because of the effect of SVE on the size of the signal frame, the\n> default vector length used for new processes involves a tradeoff\n> between performance of SVE-enabled software on the one hand, and\n> reliability of non-SVE-aware software on the other hand.\n>\n> For this reason, the best choice depends on the repertoire of\n> userspace software in use and is thus best left up to distro\n> maintainers, sysadmins and developers.\n>\n> If CONFIG_SYSCTL is enabled, this patch exposes the default vector\n> length in /proc/sys/abi/sve_default_vector_length, where boot\n> scripts or the adventurous can poke it.\n>\n> In common with other arm64 ABI sysctls, this control is currently\n> global: setting it requires CAP_SYS_ADMIN in the root user\n> namespace, but the value set is effective for subsequent execs in\n> all namespaces.  The control only affects _new_ processes, however:\n> changing it does not affect the vector length of any existing\n> process.\n>\n> The intended usage model is that if userspace is known to be fully\n> SVE-tolerant (or a developer is curious to find out) then init\n> scripts can crank this up during startup.\n>\n> Signed-off-by: Dave Martin <Dave.Martin@arm.com>\n> Cc: Alex Bennée <alex.bennee@linaro.org>\n\nReviewed-by: Alex Bennée <alex.bennee@linaro.org>\n\n>\n> ---\n>\n> Changes since v1\n> ----------------\n>\n> Changes requested by Alex Bennée:\n>\n> * Thin out BUG_ON()s:\n> Redundant BUG_ON()s and ones that just check invariants are removed.\n> Important sanity-checks are migrated to WARN_ON()s, with some\n> minimal best-effort patch-up code.\n> ---\n>  arch/arm64/kernel/fpsimd.c | 62 +++++++++++++++++++++++++++++++++++++++++++++-\n>  1 file changed, 61 insertions(+), 1 deletion(-)\n>\n> diff --git a/arch/arm64/kernel/fpsimd.c b/arch/arm64/kernel/fpsimd.c\n> index 42e8331..b430ee0 100644\n> --- a/arch/arm64/kernel/fpsimd.c\n> +++ b/arch/arm64/kernel/fpsimd.c\n> @@ -34,6 +34,7 @@\n>  #include <linux/sched/signal.h>\n>  #include <linux/signal.h>\n>  #include <linux/slab.h>\n> +#include <linux/sysctl.h>\n>\n>  #include <asm/fpsimd.h>\n>  #include <asm/cputype.h>\n> @@ -244,6 +245,65 @@ static unsigned int find_supported_vector_length(unsigned int vl)\n>  \treturn sve_vl_from_vq(bit_to_vq(bit));\n>  }\n>\n> +#ifdef CONFIG_SYSCTL\n> +\n> +static int sve_proc_do_default_vl(struct ctl_table *table, int write,\n> +\t\t\t\t  void __user *buffer, size_t *lenp,\n> +\t\t\t\t  loff_t *ppos)\n> +{\n> +\tint ret;\n> +\tint vl = sve_default_vl;\n> +\tstruct ctl_table tmp_table = {\n> +\t\t.data = &vl,\n> +\t\t.maxlen = sizeof(vl),\n> +\t};\n> +\n> +\tret = proc_dointvec(&tmp_table, write, buffer, lenp, ppos);\n> +\tif (ret || !write)\n> +\t\treturn ret;\n> +\n> +\t/* Writing -1 has the special meaning \"set to max\": */\n> +\tif (vl == -1) {\n> +\t\t/* Fail safe if sve_max_vl wasn't initialised */\n> +\t\tif (WARN_ON(!sve_vl_valid(sve_max_vl)))\n> +\t\t\tvl = SVE_VL_MIN;\n> +\t\telse\n> +\t\t\tvl = sve_max_vl;\n> +\n> +\t\tgoto chosen;\n> +\t}\n> +\n> +\tif (!sve_vl_valid(vl))\n> +\t\treturn -EINVAL;\n> +\n> +\tvl = find_supported_vector_length(vl);\n> +chosen:\n> +\tsve_default_vl = vl;\n> +\treturn 0;\n> +}\n> +\n> +static struct ctl_table sve_default_vl_table[] = {\n> +\t{\n> +\t\t.procname\t= \"sve_default_vector_length\",\n> +\t\t.mode\t\t= 0644,\n> +\t\t.proc_handler\t= sve_proc_do_default_vl,\n> +\t},\n> +\t{ }\n> +};\n> +\n> +static int __init sve_sysctl_init(void)\n> +{\n> +\tif (system_supports_sve())\n> +\t\tif (!register_sysctl(\"abi\", sve_default_vl_table))\n> +\t\t\treturn -EINVAL;\n> +\n> +\treturn 0;\n> +}\n> +\n> +#else /* ! CONFIG_SYSCTL */\n> +static int __init sve_sysctl_init(void) { return 0; }\n> +#endif /* ! CONFIG_SYSCTL */\n> +\n>  #define ZREG(sve_state, vq, n) ((char *)(sve_state) +\t\t\\\n>  \t(SVE_SIG_ZREG_OFFSET(vq, n) - SVE_SIG_REGS_OFFSET))\n>\n> @@ -1030,6 +1090,6 @@ static int __init fpsimd_init(void)\n>  \tif (!(elf_hwcap & HWCAP_ASIMD))\n>  \t\tpr_notice(\"Advanced SIMD is not implemented\\n\");\n>\n> -\treturn 0;\n> +\treturn sve_sysctl_init();\n>  }\n>  late_initcall(fpsimd_init);\n\n\n--\nAlex Bennée","headers":{"Return-Path":"<libc-alpha-return-84613-incoming=patchwork.ozlabs.org@sourceware.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":["patchwork-incoming@bilbo.ozlabs.org","mailing list libc-alpha@sourceware.org"],"Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=sourceware.org\n\t(client-ip=209.132.180.131; helo=sourceware.org;\n\tenvelope-from=libc-alpha-return-84613-incoming=patchwork.ozlabs.org@sourceware.org;\n\treceiver=<UNKNOWN>)","ozlabs.org; dkim=pass (1024-bit key;\n\tsecure) header.d=sourceware.org header.i=@sourceware.org\n\theader.b=\"w9Ib+6gu\"; dkim-atps=neutral","sourceware.org; auth=none"],"Received":["from sourceware.org (server1.sourceware.org [209.132.180.131])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256\n\tbits)) (No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xtJfm3dwJz9sPs\n\tfor <incoming@patchwork.ozlabs.org>;\n\tThu, 14 Sep 2017 23:05:20 +1000 (AEST)","(qmail 83940 invoked by alias); 14 Sep 2017 13:05:12 -0000","(qmail 83930 invoked by uid 89); 14 Sep 2017 13:05:11 -0000"],"DomainKey-Signature":"a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id\n\t:list-unsubscribe:list-subscribe:list-archive:list-post\n\t:list-help:sender:references:from:to:cc:subject:in-reply-to:date\n\t:message-id:mime-version:content-type:content-transfer-encoding;\n\tq=dns; s=default; b=cv2yKtVNRBifEaAeNIU5hC3zvz0+jC8rcAGP7D9M2ZN\n\tJ7zGr5qft1NOvbBnUumh8H8m9XR+Uv5x9mV6zm16CXKWlmiUEEb6egHKcbdXb9ov\n\t04Y1l9r+DeJRRbvqi+lfNSG++dg3QVf7/DqCkRpX0nH72DeIkiZU/QFVedAvoiMo\n\t=","DKIM-Signature":"v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id\n\t:list-unsubscribe:list-subscribe:list-archive:list-post\n\t:list-help:sender:references:from:to:cc:subject:in-reply-to:date\n\t:message-id:mime-version:content-type:content-transfer-encoding;\n\ts=default; bh=LYD92bvkqHc4ETOgW7Xy0siBhWw=; b=w9Ib+6guEd94IoIt2\n\tImsK8kPg/NrLvQyT2F602n1Qd8yjml8qDnkhsRkNGIHp8OVz91AlWOTNXMnUP7/A\n\tLzWRhhSUWg2q8rKEhFJukGuT+9DJBjhdNLfbl7QOwn+Jpr3l4MfvkLcd2XE1P9FJ\n\tW0ea3H2ijVf+y3MKTYjwpcX0/4=","Mailing-List":"contact libc-alpha-help@sourceware.org; run by ezmlm","Precedence":"bulk","List-Id":"<libc-alpha.sourceware.org>","List-Unsubscribe":"<mailto:libc-alpha-unsubscribe-incoming=patchwork.ozlabs.org@sourceware.org>","List-Subscribe":"<mailto:libc-alpha-subscribe@sourceware.org>","List-Archive":"<http://sourceware.org/ml/libc-alpha/>","List-Post":"<mailto:libc-alpha@sourceware.org>","List-Help":"<mailto:libc-alpha-help@sourceware.org>,\n\t<http://sourceware.org/ml/#faqs>","Sender":"libc-alpha-owner@sourceware.org","X-Virus-Found":"No","X-Spam-SWARE-Status":"No, score=-26.5 required=5.0 tests=AWL, BAYES_00,\n\tGIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3,\n\tRCVD_IN_DNSWL_NONE,\n\tSPF_PASS autolearn=ham version=3.3.2 spammy=Fail","X-HELO":"mail-wm0-f51.google.com","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:references:user-agent:from:to:cc:subject\n\t:in-reply-to:date:message-id:mime-version:content-transfer-encoding; \n\tbh=bacw0c22Vu0cjARGYVMcWQtYen5N6H5yWHHwpDbe3Jk=;\n\tb=CUB0liNgUjB1UFVdU0JOjsObEkBkBtgWK0auf2+HcQ0g/PTCdodUTbO4E1OoA+w9hA\n\tWZrljNS9RlrmoWt/Ckr3VXUoIWCKvq9cyJVB3zW2e663qP4bog1d8v+W7A5yJdD975Ws\n\tXAcd9vpo5rkSc5Esj1alU8n+jI/kvlcY47FFXqV1M3gS9Actun0BvDb7yTNCWWc7IrGI\n\tF94HYrPrA3rSYitjQCXCoWDYZ3qfIzyb2MhA1ktvCMiL2donACuw3X/27F9FAKu39XM+\n\tdjdewrqZbAxjdTGJPTM8eLgzmj30Ot/mopR45y3dBIukuHxXODYUncNQlSZJtY823ta3\n\tPNbw==","X-Gm-Message-State":"AHPjjUji5MdE9Wb/8jt7v42lE7dIBITng8TlIOG0yRx+del/Jkvt6s2s\n\tPot8fAmq8vXXFJPh","X-Google-Smtp-Source":"AOwi7QBdl1D911rhZhx4BZ+rhKeRmlfPLjzYXkGnnzEhalHkYAi94OhRSpTH0GyftkDMTAlLE6oGCQ==","X-Received":"by 10.28.127.4 with SMTP id a4mr2023347wmd.12.1505394302896;\n\tThu, 14 Sep 2017 06:05:02 -0700 (PDT)","References":"<1504198860-12951-1-git-send-email-Dave.Martin@arm.com>\n\t<1504198860-12951-22-git-send-email-Dave.Martin@arm.com>","User-agent":"mu4e 0.9.19; emacs 25.2.50.3","From":"Alex =?utf-8?q?Benn=C3=A9e?= <alex.bennee@linaro.org>","To":"Dave Martin <Dave.Martin@arm.com>","Cc":"linux-arm-kernel@lists.infradead.org,\n\tCatalin Marinas <catalin.marinas@arm.com>,\n\tWill Deacon <will.deacon@arm.com>,\n\tArd Biesheuvel <ard.biesheuvel@linaro.org>,\n\tSzabolcs Nagy <szabolcs.nagy@arm.com>,\n\tRichard Sandiford <richard.sandiford@arm.com>,\n\tkvmarm@lists.cs.columbia.edu, libc-alpha@sourceware.org,\n\tlinux-arch@vger.kernel.org","Subject":"Re: [PATCH v2 21/28] arm64/sve: Add sysctl to set the default\n\tvector length for new processes","In-reply-to":"<1504198860-12951-22-git-send-email-Dave.Martin@arm.com>","Date":"Thu, 14 Sep 2017 14:05:01 +0100","Message-ID":"<878thha0si.fsf@linaro.org>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Transfer-Encoding":"8bit"}}]