Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752514AbdHEOlC (ORCPT ); Sat, 5 Aug 2017 10:41:02 -0400 Received: from mail-cys01nam02on0071.outbound.protection.outlook.com ([104.47.37.71]:37616 "EHLO NAM02-CY1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752280AbdHEOk6 (ORCPT ); Sat, 5 Aug 2017 10:40:58 -0400 From: Yury Norov To: Catalin Marinas , Pratyush Anand , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Yury Norov Subject: [PATCH 2/2] arm64: cleanup {COMPAT_,}SET_PERSONALITY() macro Date: Sat, 5 Aug 2017 17:40:22 +0300 Message-Id: <20170805144022.17260-3-ynorov@caviumnetworks.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170805144022.17260-1-ynorov@caviumnetworks.com> References: <20170805144022.17260-1-ynorov@caviumnetworks.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [196.71.79.105] X-ClientProxiedBy: DB6PR02CA0016.eurprd02.prod.outlook.com (10.170.218.157) To SN1PR07MB2127.namprd07.prod.outlook.com (10.164.46.157) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: beb24a4d-e19b-43fe-7f1f-08d4dc0ffaa1 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(300000500095)(300135000095)(300000501095)(300135300095)(22001)(300000502095)(300135100095)(2017030254152)(300000503095)(300135400095)(201703131423075)(201703031133081)(201702281549075)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095);SRVR:SN1PR07MB2127; X-Microsoft-Exchange-Diagnostics: 1;SN1PR07MB2127;3:p5A7OLimTw1nPrW/rTFVrjLnfSsUrGLD4WXXkIOMDHBroh+BcP4h2GiNm99pvnuEaBBibRh2gcrpxnRy6qUtWSu2KG2PMWPZzci/qUVSL193ilZB13dR8g3/BDxB7LY+la1jvo7ToU4gJRg4o9/Km24/RdQPPYiabR/6QTJf2PfmaqQ0w8MYw4oXZM5Xz/K4hO3AUbSHhBWz/rBUeMRiJwYY13ECJvxuy8yumuvgqg4jY17fE70HALPnHdxBPskA;25:dCvZBHfpRViBanHCV58eg0wyy84v3tHQn/rDWjyQHOZjC5mHlt2BilRUdbLGKv/asZhnN2shth72Zd7VIL8zN4rncSL0mtDMQUEaLT51cCcNjmOsk96tPkZks6QdnsWgIvMiywYwMy3IM3cUWY9JZwLuFer2zGEAqHwXA9DDFZyy6FhK01wVbdb/ubaVLA8vKw4GNxAb2eLi+3xLU6u+0UH5yiwyNmP2XMwPLEvMrJN3PSODZnoH1lGcTBTYkfEBRAp/P60au6CkG6MB3LyNjnGxBBMsMuYOzA3mGTHqzRN5VS6/zFT2yPuziW/BkN3hSv1mcx4xHMqpzn3l+aCWSg==;31:1/D6im72L8bZ0vy511jjiGgCBt9sVJciU3UlIZNxDq96r+sO68d0DOLBS17am4QJCheugx4L8EYHpctAddaYcuRzko7RdhC2CVdsfMjTZuK96JeDmQ0ZSSuAtRZveJ5rk8pqDYeV4p3qhfZNoEQyEU12dslZ6uFLykmzPkexnVsB0sF5muKNJZjmwDwrwaZcxfLeUVZkK7HaRTUJYpUexDfe2ggqTvQ9cgMl55r+cLE= X-MS-TrafficTypeDiagnostic: SN1PR07MB2127: Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Yuri.Norov@cavium.com; X-Microsoft-Exchange-Diagnostics: 1;SN1PR07MB2127;20:CGYEQHEJc2Nfue3K4mHcCYGL76wXzFY389WssrmOTCiCS1mA4HErrXJMfwFYeaxc6hCyh3I8B1ppGDa9KoKbWTRhe2gn5EDLNL5lhympVSXmQ/dgeGTssiInzK6BmkXBDBfAFxdXWkkluFj34cMu75DdRwURgDJvZsVCHrIZ/ghXl8EtBMOs/SVWVWw715XERtxx9TQ1EvOqlpKIYhMl6UoxLSTwVfqYJmB7fSwZmFPz5ARsl1JME8IzrkVqezC/gwztlnW/jmSvEZZ9EWWbmrwyOOom6P8EuSyp42Rh3mAJqqrLVrSqptzo/l4pJK2l0xNzNfZAwZ68dd5wH7NB9VyFrIAxp99CFBYuZ9SI/tkopi3VsXLdHYeshwIztD+YQchIjqFTXlAVe/yRV2xXkOo30ElS3NZlkhF+rrd4SZLmlHyJCKiLxF093JODB2fShhr26bGMdCqMCHV1OKenfuMJX5FVuFEbbHvvND3OP3ygDx+riH8tu/NkkBhChAJmb0uxoUhu/LGTxXUNSmpR3F+gN9W5mXHIr2p9ix/GaOaNAU3M60pLmOSF/wiFwqTmVKfUBncTpu5NhV52YjqRyC+RvWivC84T6sKSFyryt0E=;4:gThX8IKKdE136+OPNfVvmOxufgdP/SzOH29vXqTGmRnvbVYvt2AID15r0nF4cO2tq3RXtuvOq8j5GJY4k5V15JrcIDT7ulJnDcllMLWF7v+InG5cU/jte8Z2lOjrTTR1o9znYFdFSGvoZqIFV9f4LnBgeGH0Kk7FrDt2XqT7v88jsaQdHLE6jnzX+Bs7o38CmWL9b5JGRfjaUMkYUeCrs/fbhFDvnajlVmFn52jsmv68AWnwtjlesbkJgwl9E7DqNgWLnWvmz8ZxIHvh4k/hxj8gu+DmyhlON8pN+j2JW/I= X-Exchange-Antispam-Report-Test: UriScan:(180628864354917); X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(601004)(2401047)(8121501046)(5005006)(100000703101)(100105400095)(10201501046)(93006095)(3002001)(6041248)(20161123562025)(20161123564025)(20161123560025)(20161123555025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123558100)(6072148)(100000704101)(100105200095)(100000705101)(100105500095);SRVR:SN1PR07MB2127;BCL:0;PCL:0;RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095);SRVR:SN1PR07MB2127; X-Forefront-PRVS: 0390DB4BDA X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(4630300001)(7370300001)(6009001)(6069001)(39450400003)(39410400002)(39850400002)(39400400002)(39840400002)(189002)(199003)(8676002)(6116002)(106356001)(105586002)(3846002)(33646002)(101416001)(10806002)(76176999)(68736007)(50986999)(76506005)(966005)(48376002)(50466002)(1076002)(42186005)(305945005)(7736002)(5003940100001)(4326008)(6486002)(7350300001)(53936002)(6496005)(6306002)(38730400002)(107886003)(478600001)(72206003)(5001810100001)(97736004)(25786009)(47776003)(2906002)(66066001)(36756003)(81166006)(81156014)(10916006)(50226002)(5660300001)(6666003)(2950100002)(42882006)(189998001);DIR:OUT;SFP:1101;SCL:1;SRVR:SN1PR07MB2127;H:localhost;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;SN1PR07MB2127;23:rXu0h9OlXafzTZcN62lfnyclaY5PLO9JT/Vtx0mbJ?= =?us-ascii?Q?bdVGrU69zBcan/FQUwaSMo31p/6RIWZp89rA6Jn+RIZUcqK8rEtamdurkAnw?= =?us-ascii?Q?kX3uSRUn6y/qi/scfTfZIGO1zeWKshkE6lg1z1S2bLLg3KjLSZudP5+gi5OH?= =?us-ascii?Q?03zoWBOkUPlXcq4skfMk7JtSO9sb+uFkE5hjQwH+u3taFuA3D5ywcwZ+2geS?= =?us-ascii?Q?GCzaVrxO3xEvY5uSqhhKOnG3SiHDBQu/n6X8qcYURFtteAa1QAP94HXWBQ4j?= =?us-ascii?Q?8pWHt9wewRTVZQdPKefUdzRP0qNKFDtQzj7fHEZt27jxvlHDdpdwoMmcIhjs?= =?us-ascii?Q?w4id4zTB90hcLGP5crwUFSBuIT/f39nYEAvNS2kC/FWQKL6CzrlzdPre0xna?= =?us-ascii?Q?cHDV52NAKnuoYGTaiqrZP3PeYkzU0cGi13/Zuo+NBAH4L9KO9/agGc1uO2jr?= =?us-ascii?Q?sfrDQQ4JhcjC4S7Q+9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= =?us-ascii?Q?Lw8IvLnnCRLQEBz6+P/Mb/sxpqBXaWvD0R8ybPSNvvZ0VDa?= X-Microsoft-Exchange-Diagnostics: 1;SN1PR07MB2127;6:z7rDmoQYXYQJ1Nz/n88a0hm3F54jL236deJ9C7XCntS7VrICt0pyWsoL7SH45iPKqJLDFty10UrZqS9XpF6MF3NUJoaqdtmUDKy2MdP6+gAWe7d5/CTtHSvu1kKJYaXCXvRPJbU99cIINIXeaJjX+mYk//uW/mcUx8E8rgMiHcY0Liwn+jwECi3OYtkJlobCt1YpfHa6sD2Z7C7fHuVvhdsx9CQUmCEiZi/ndDWZeeOhDDsO0qsMBwJ8m6O36ePO8XReJ7wLT4IWb8EBQh1oILhxLA+ZJUaUT1kVE1OPikrpT5yQBYRTTRxhXv9hlb/ZriG3p3/c2Rh+G0TLWy4Opw==;5:ayo//m9k7B/2m4iCbY3HUzRrjoc1dqX88KDsRr2ivWi/PWxXYi4HwYw8nkj2HMH41yDPFs6rzJpr09Vgn6PJiKhlv94fEFMarBMSszrhkY4mEJvvK1d0WU/SiEHdMVRbfUY/sZiApHLM9rY0TJQZ3Q==;24:hGvKtIQlcouujZ5+sA9Qfd0aQ8UgXv9R85oGUveTDalkLArLr0ILrIB80vkCqcc73dk2PxmW1gOl+E3et9JoiqIKoEaBDEPuZoE7pLW1BkY=;7:l0xeQb+XJiiC3ndHDRuvn0bRw1KFhSxMvCBOmybf3DWEKwl/FgHHWCmxIFipIc5w3zs7sh038Hly+9Uw3ZWInPe8ANpAff6XGeQ5fwuKZYN6LokBsnhfYV3+STz9TIQtsIHaqCJTL7jtfOsFhkcaNbtskoBPmCDJMnxu+IEsqoLh+GWZvbSpUGY7XTXatoOligHvSGg/Tc2jVST208SoJIaoHdmo5kvVt35bmbkUVqg= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Aug 2017 14:40:54.7965 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR07MB2127 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3547 Lines: 101 Originally {COMPAT_,}SET_PERSONALITY() only sets the 32-bit flag in thread_info structure. But there is some work that should be done after setting the personality. Currently it's done in the macro, which is not the best idea. In this patch new arch_setup_new_exec() routine is introduced, and all setup code is moved there, as suggested by Catalin: https://lkml.org/lkml/2017/8/4/494 Note: mm->context.flags doesn't require the atomic strong ordered acceess to the field, so use __set_bit() there; Signed-off-by: Yury Norov CC: Pratyush Anand CC: Catalin Marinas --- arch/arm64/include/asm/elf.h | 15 +++++++++------ arch/arm64/include/asm/thread_info.h | 3 +++ arch/arm64/kernel/process.c | 17 +++++++++++++++++ 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/arch/arm64/include/asm/elf.h b/arch/arm64/include/asm/elf.h index de11ed1484e3..615953243961 100644 --- a/arch/arm64/include/asm/elf.h +++ b/arch/arm64/include/asm/elf.h @@ -137,11 +137,14 @@ typedef struct user_fpsimd_state elf_fpregset_t; */ #define ELF_PLAT_INIT(_r, load_addr) (_r)->regs[0] = 0 +/* + * Don't modify this macro unless you add new personality. + * All personality-related setup should be done at proper place. + * If not sure, consider the arch_setup_new_exec() function. + */ #define SET_PERSONALITY(ex) \ ({ \ - clear_bit(MMCF_AARCH32, ¤t->mm->context.flags); \ clear_thread_flag(TIF_32BIT); \ - current->personality &= ~READ_IMPLIES_EXEC; \ }) /* update AT_VECTOR_SIZE_ARCH if the number of NEW_AUX_ENT entries changes */ @@ -188,14 +191,14 @@ typedef compat_elf_greg_t compat_elf_gregset_t[COMPAT_ELF_NGREG]; ((x)->e_flags & EF_ARM_EABI_MASK)) #define compat_start_thread compat_start_thread + /* - * Unlike the native SET_PERSONALITY macro, the compat version inherits - * READ_IMPLIES_EXEC across a fork() since this is the behaviour on - * arch/arm/. + * Don't modify this macro unless you add new personality. + * All personality-related setup should be done at proper place. + * If not sure, consider the arch_setup_new_exec() function. */ #define COMPAT_SET_PERSONALITY(ex) \ ({ \ - set_bit(MMCF_AARCH32, ¤t->mm->context.flags); \ set_thread_flag(TIF_32BIT); \ }) #define COMPAT_ARCH_DLINFO diff --git a/arch/arm64/include/asm/thread_info.h b/arch/arm64/include/asm/thread_info.h index 46c3b93cf865..c823d2f12b4c 100644 --- a/arch/arm64/include/asm/thread_info.h +++ b/arch/arm64/include/asm/thread_info.h @@ -68,6 +68,9 @@ struct thread_info { #define thread_saved_fp(tsk) \ ((unsigned long)(tsk->thread.cpu_context.fp)) +void arch_setup_new_exec(void); +#define arch_setup_new_exec arch_setup_new_exec + #endif /* diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c index 659ae8094ed5..ebca9e4f62c7 100644 --- a/arch/arm64/kernel/process.c +++ b/arch/arm64/kernel/process.c @@ -417,3 +417,20 @@ unsigned long arch_randomize_brk(struct mm_struct *mm) else return randomize_page(mm->brk, SZ_1G); } + +/* + * Called immediately after a successful exec. + */ +void arch_setup_new_exec(void) +{ + current->mm->context.flags = 0; + + /* + * Unlike the native one, the compat version of exec() inherits + * READ_IMPLIES_EXEC since this is the behaviour on arch/arm/. + */ + if (is_compat_task()) + __set_bit(MMCF_AARCH32, ¤t->mm->context.flags); + else + current->personality &= ~READ_IMPLIES_EXEC; +} -- 2.11.0