From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756989AbcIUK27 (ORCPT ); Wed, 21 Sep 2016 06:28:59 -0400 Received: from foss.arm.com ([217.140.101.70]:44870 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756963AbcIUK2y (ORCPT ); Wed, 21 Sep 2016 06:28:54 -0400 Date: Wed, 21 Sep 2016 11:28:27 +0100 From: Mark Rutland To: Andy Lutomirski Cc: "linux-arm-kernel@lists.infradead.org" , Andrew Morton , Ard Biesheuvel , Catalin Marinas , james.morse@arm.com, Kees Cook , "linux-kernel@vger.kernel.org" , lorenzo.pieralisi@arm.com, Andrew Lutomirski , suzuki.poulose@arm.com, Takahiro Akashi , Will Deacon , "kernel-hardening@lists.openwall.com" Subject: Re: [RFC PATCH 2/8] thread_info: allow custom in-task thread_info Message-ID: <20160921102827.GC18176@leverpostej> References: <1473947349-14521-1-git-send-email-mark.rutland@arm.com> <1473947349-14521-3-git-send-email-mark.rutland@arm.com> <20160916103101.GA21702@leverpostej> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Andy, On Fri, Sep 16, 2016 at 08:11:14AM -0700, Andy Lutomirski wrote: > > On Thu, Sep 15, 2016 at 11:37:47AM -0700, Andy Lutomirski wrote: > > Just to check, what do you mean to happen with the flags field? Should > > that always be in the generic thread_info? e.g. > > > > struct thread_info { > > u32 flags; > > #ifdef arch_thread_info > > struct arch_thread_info arch_ti; > > #endif > > }; > > Exactly. Possibly with a comment that using thread_struct should be > preferred and that arch_thread_info should be used only if some header > file requires access via current_thread_info() or task_thread_info(). While fixing up these patches, I realised that I'm somewhat concerned by flags becoming a u32 (where it was previously an unsigned long for arm64). The generic {test,set,*}_ti_thread_flag() helpers use the usual bitops, which perform accesses of sizeof(unsigned long) at a time, and for arm64 these need to be naturally-aligned. We happen to get that alignment from subsequent fields in task_struct and/or thread_info, and for arm64 we don't seem to have a problem with tearing, but it feels somewhat fragile, and leaves me uneasy. Looking at the git log, it seems that x86 also use unsigned long until commit affa219b60a11b32 ("x86: change thread_info's flag field back to 32 bits"), where if I'm reading correctly, this was done to get rid of unnecessary padding. With THREAD_INFO_IN_STACK, thread_info::flags is immediately followed by a long on x86, so we save no padding. Given all that, can we make the generic thread_info::flags an unsigned long, matching what the thread flag helpers implicitly assume? Thanks, Mark.