From patchwork Wed Mar 22 14:51:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Martin X-Patchwork-Id: 9639193 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A1475602CB for ; Wed, 22 Mar 2017 15:08:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 92E522845C for ; Wed, 22 Mar 2017 15:08:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 874582846F; Wed, 22 Mar 2017 15:08:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1883E2845C for ; Wed, 22 Mar 2017 15:08:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=U8h1VFRwxdnzj6NkS4gHv87GqB0BqSaqYF5PJMsKubw=; b=jq2Q1UQjSQOBJN2VSPLbACWx7d PaSymgzvQKgUIUd41h+DUGpblIOKXumtLyFA9dTsQIH2JZQMGO73vrfDwd/Z6sWxeRzQyMbHEq4nU c/J6sEp4m/eQlYRJtJpq63mSQOUiGqJYKPzmZiZe1jYDyrDAQUozFnvoYgRT9ams8d5LBgidPHjEZ gnsPkfZ+SykdM99c/3gT2OZUBV/JEoqLx2+FI88QnScHMpkrsOERXEEF/dftMzj6MQjB1xM4JTUJU tp2TVfoPT9m+5DRHtoOh4DYjXi22kAapqRQjGpB38QEwuDSi7IQRs+/LfJ/l5R26pZOQwMdR8Hjxq J0Ti7ywA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cqhsX-0005ci-IO; Wed, 22 Mar 2017 15:08:49 +0000 Received: from casper.infradead.org ([2001:770:15f::2]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cqhrj-0004Jl-60 for linux-arm-kernel@bombadil.infradead.org; Wed, 22 Mar 2017 15:07:59 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=YYRC8b6jQ8MzKFp0Spu4m+gyDz9hWyxliTKHATpebCI=; b=EdIgVeGfiroWf7lF5eyQ+jxQ8 GCVsbItwWwdXKJh1hu9RCneaNR56o/6eQ5Q3usQj18e7ZQv3SPZNRRFRO66IhLgq48BB+cX7KfKiD 6GxK5gtUdoNOHSYanIar4tdWXzY8SWnlDGhrf0lOJMeVInoHHRgfrnhQc9AGFQT7uggG6AawzUQs2 z2FDGcM1n+yxP9YcdGylOoWydxT3Tc1ZEQQ0ScecyZhmKVwZdDGBG1ilDl/T2sUXC9wOUsPD3dQKo 0k4GT4eX7ipLiVIrwQ1dLxAFEW8dC2LKHKBUXeWdk6b7ykbwhPlEz9T0R+DfhmnpqyGrMr9W9XbCe WFIG1EE9w==; Received: from foss.arm.com ([217.140.101.70]) by casper.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cqheJ-00021G-4f for linux-arm-kernel@lists.infradead.org; Wed, 22 Mar 2017 14:54: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 DF19015AB; Wed, 22 Mar 2017 07:54:06 -0700 (PDT) Received: from e103592.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 8F0E23F575; Wed, 22 Mar 2017 07:54:05 -0700 (PDT) From: Dave Martin To: linux-arm-kernel@lists.infradead.org Subject: [RFC PATCH v2 34/41] arm64/sve: Disallow VL setting for individual threads by default Date: Wed, 22 Mar 2017 14:51:04 +0000 Message-Id: <1490194274-30569-35-git-send-email-Dave.Martin@arm.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1490194274-30569-1-git-send-email-Dave.Martin@arm.com> References: <1490194274-30569-1-git-send-email-Dave.Martin@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170322_145407_316746_7AB10DDD X-CRM114-Status: GOOD ( 14.95 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Florian Weimer , Ard Biesheuvel , Marc Zyngier , Catalin Marinas , Will Deacon , Szabolcs Nagy , Joseph Myers MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP General-purpose code in userspace is not expected to work correctly if multiple threads are allowed to run concurrently with different vector lengths in a single process. This patch adds an explicit flag PR_SVE_SET_VL_THREAD to request this behaviour. Without the flag, vector length setting is permitted only for a single-threaded process (which matches the expected usage model of setting the vector length at process startup). Signed-off-by: Dave Martin --- arch/arm64/kernel/fpsimd.c | 12 +++++++++++- include/uapi/linux/prctl.h | 1 + 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kernel/fpsimd.c b/arch/arm64/kernel/fpsimd.c index c9934bb..ab00e9f 100644 --- a/arch/arm64/kernel/fpsimd.c +++ b/arch/arm64/kernel/fpsimd.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -226,8 +227,17 @@ int sve_set_vector_length(struct task_struct *task, { BUG_ON(task == current && preemptible()); + /* + * To avoid accidents, forbid setting for individual threads of a + * multithreaded process. User code that knows what it's doing can + * pass PR_SVE_SET_VL_THREAD to override this restriction: + */ + if (!(flags & PR_SVE_SET_VL_THREAD) && get_nr_threads(task) != 1) + return -EINVAL; + + flags &= ~(unsigned long)PR_SVE_SET_VL_THREAD; if (flags) - return -EINVAL; /* No flags defined yet */ + return -EINVAL; /* No other flags defined yet */ if (!sve_vl_valid(vl)) return -EINVAL; diff --git a/include/uapi/linux/prctl.h b/include/uapi/linux/prctl.h index e32e2da..c55530b 100644 --- a/include/uapi/linux/prctl.h +++ b/include/uapi/linux/prctl.h @@ -199,6 +199,7 @@ struct prctl_mm_map { /* arm64 Scalable Vector Extension controls */ #define PR_SVE_SET_VL 48 /* set task vector length */ +# define PR_SVE_SET_VL_THREAD (1 << 1) /* set just this thread */ #define PR_SVE_GET_VL 49 /* get task vector length */ #endif /* _LINUX_PRCTL_H */