From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754277AbcDYKOQ (ORCPT ); Mon, 25 Apr 2016 06:14:16 -0400 Received: from eu-smtp-delivery-143.mimecast.com ([207.82.80.143]:24709 "EHLO eu-smtp-delivery-143.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754128AbcDYKOO convert rfc822-to-8bit (ORCPT ); Mon, 25 Apr 2016 06:14:14 -0400 Date: Mon, 25 Apr 2016 11:14:07 +0100 From: Dave P Martin To: Alexandre Belloni CC: Russell King - ARM Linux , , , "Ard Biesheuvel" , Olof Johansson , Doug Anderson , Heiko Stuebner , Russ Dill , Nicolas Ferre Subject: Re: [PATCH 1/2] ARM: PIE infrastructure Message-ID: <20160425101406.GR24713@e103592.cambridge.arm.com> References: <1459668234-16033-1-git-send-email-alexandre.belloni@free-electrons.com> <1459668234-16033-2-git-send-email-alexandre.belloni@free-electrons.com> <20160404100052.GS19428@n2100.arm.linux.org.uk> <20160422231503.GE17051@piout.net> MIME-Version: 1.0 In-Reply-To: <20160422231503.GE17051@piout.net> User-Agent: Mutt/1.5.23 (2014-03-12) X-EOPAttributedMessage: 0 X-Forefront-Antispam-Report: CIP:217.140.96.140;IPV:CAL;SCL:-1;CTRY:GB;EFV:NLI;SFV:NSPM;SFS:(10009020)(6009001)(2980300002)(438002)(24454002)(40434004)(199003)(189002)(4326007)(1220700001)(1076002)(83506001)(5003600100002)(1096002)(106466001)(50466002)(5890100001)(87936001)(33656002)(5008740100001)(11100500001)(104016004)(6806005)(189998001)(77096005)(47776003)(586003)(4001350100001)(97756001)(2950100001)(92566002)(93886004)(86362001)(46406003)(2906002)(50986999)(76176999)(54356999)(110136002)(23726003);DIR:OUT;SFP:1101;SCL:1;SRVR:DB3PR08MB0137;H:nebula.arm.com;FPR:;SPF:Pass;MLV:sfv;A:1;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: 1;AM1F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s5Yo32muaURDiQeZSfOJkyB+WTP9ZoPPgucBPOyuB0aqXNMotLzKQJAjYtIgx+b9LXwNa+eQUFeJaLgXqbu3q9Adh4MqQMTj7DuVa4UB0WQwj92vDkbF52IT6hjEtFj+FLCI7DRtH0srmgnD8RVsbllRHW0ETWXWm8y8BmmRB/DAPs4S9cs7C7fCAfHiWBIoB+yAwhITmj+Y= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(9101521026)(601004)(2401047)(5005006)(8121501046)(13023025)(13024025)(13013025)(13020025)(10201501046)(3002001)(6055026);SRVR:DB3PR08MB0137;BCL:0;PCL:0;RULEID:;SRVR:DB3PR08MB0137; X-Forefront-PRVS: 0923977CCA X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;DB3PR08MB0137;23:zvJ+yBPlqybqkSumNKNnfLennIvR0DJ2gvMD/siDq?= =?us-ascii?Q?OPCuNixi3dQ6t+2wh1T9NMZRm0TM95KHGz3vKSurc7F8/f3/1ohMIMdkSriH?= =?us-ascii?Q?0yKSz4D/CA3WFRaiVXxKIDAichkduDlVyTk5szTpFGoK3Nhctq7YJUkCq3iF?= =?us-ascii?Q?/fLNsJmDIVYKuS1pOMO1Qt9Fghi7mhgl/RbekDFmly8oX40gvSx+eeWMxS8K?= =?us-ascii?Q?7YxDS3Nxr77s3d4743lL3TkNX6xvkz47AkNe/kNDOW2g05YAcENnR2H3++DH?= =?us-ascii?Q?tQJJfPfldoq3mwc2TEdc4bltCnb2K8Kdg3oyRBmp5kbpu2pVMugQgrAMQXKF?= =?us-ascii?Q?2fCtWnEli+GVemRVVWvioPlUgkHyfOYx58cBe15N0b7y4ZvfOLFd9WVd/U7Q?= =?us-ascii?Q?Ovy2Qop5OmbGsvUQp3PQ76dvup6jyA6BLEFUgJ6H/v9klv0yQTfpfCFM8/UJ?= =?us-ascii?Q?FDpVfn8xIG5MTXAWCOVvRW3+ma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R5A1HaW/LGQ1q7OcnZHYrEA/2C/rmDXR/rSG6BczzYcvY6HqosAgpVPI4hcjk9QYRF4OQxUJSTgtAErsCiHnIRMos9nFKFYFM5onFKpRxaVGkW0dySTeWu+atHHEmuE4hRfjEpRb0ewkTtBCamQ59AX3cPlIhm7arLoSYfDKAZH4nMu+snqndSqhVv9rVEDLWcm++KI=;20:60BOV4p4MVM/R82rFu28WS4zGlneQvcMKAXz1GRx23Z+9Ta5QJJah8K5CayL4GywdIUq2+ad7csOkmjtrkALL6poe9dX3QhaJaIO2Zg9XryXPROztqUBkihvM0C8hQ4yy0YaP3BnP+mvAM8r26wKObTy85saFGzHVLhxfg1VrtA= SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Apr 2016 10:14:08.6785 (UTC) X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d;Ip=[217.140.96.140];Helo=[nebula.arm.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB3PR08MB0137 X-MC-Unique: 6wOBhtsZRYSI6J-AlbkXxg-1 Content-Type: text/plain; charset=WINDOWS-1252 Content-Transfer-Encoding: 8BIT Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Apr 23, 2016 at 01:15:03AM +0200, Alexandre Belloni wrote: > On 04/04/2016 at 11:00:52 +0100, Russell King - ARM Linux wrote : > > > + /* Copy chunk specific code/data */ > > > + fncpy((char *)chunk->addr, code_start, code_sz); > > > > Sorry, NAK. This abuses fncpy(). There is extensive documentation on > > the proper use of this in asm/fncpy.h, and anything that does not > > conform, or which uses memcpy() to copy functions, gets an immediate > > NAK from me. fncpy() exists to avoid people doing broken things, and > > it's written in such a way to help people get it right. > > Well, do you want me to iterate and use fncpy on all the functions from > the generated binary? > > I'm not sure this is necessary as the generated binary is self contained > and doing so will force me to also ensure the offsets are kept the same. > Doing only one copy is much more convenient. However, I still need to > ensure the destination address is properly 8-byte aligned and the > flush_icache_range(). > I understand this is abusing fncpy() but it does want I need (still, I'm > planning to avoid the BUG() by always passing a properly aligned > destination address). fncpy was only intented for a single, self-contained function. It bakes in assumptions that are not going to apply to PIEs in general. The main purpose of this was to avoid (possibly buggy) reinvention of this bit of code in every driver or board file that needed to copy a function to SRAM. The PIE mechanism supersedes this approach, in that it should completely hide the mechanics of copying to SRAM from the users of PIEs -- so its worth the PIE infrastructure having it's own code to do this. Since PIEs will have their own requirements that go beyond what fncpy does, using fncpy to implement the PIE infrastructure is a misfactorage. In particular, what is the alignment requirement for a PIE? It can be anything that ELF allows, not simply "8". The "thumb bit" is obviously also meaningless for section base addresses. Cheers ---Dave IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.