Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp123373imu; Thu, 3 Jan 2019 15:31:14 -0800 (PST) X-Google-Smtp-Source: ALg8bN5cYUbxFLL15OGuu2yTntPUqVcJ4RtrJXVD+a42QYv6H2g0G6CtVg5kZcHOxA5UH0Fj3SS3 X-Received: by 2002:a65:448a:: with SMTP id l10mr18803564pgq.387.1546558274446; Thu, 03 Jan 2019 15:31:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546558274; cv=none; d=google.com; s=arc-20160816; b=ABDwME/UoJQued+eMVan/LCzv6Y5lk3YuDQ5gooXa9vODH5f1C8voa6/tXMceyQL3J yRZRp0MjNLcmTuWw6J6PxniDd5ItF9/hq1KR3jP3c68mvj8ktTUT+lasijzRdTLg3+Hr Y+xpoFzo0MgqknGgsxmnCa8yqMuoS7vZaUtnN2WawtqtVqRTtADWINOeMVdC/H+N3w2q DLrzn9k78D0iQvWONEZDL0BjsDzwc3OpzXoC0LmSvO9xFpW+sXYalVn9+cHeZGEMJIbc T9g/oYDQEFYRWHcNiV/Suvlw8DOJxry4gZxXWvJceE6IcLeRKrkR/BDO5QJlUK5BIexX AKCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=D5E0DiulLRHuulBUvsASph64KLrsKEiRJCnpkFvNE10=; b=OjEMHgq7IYF/RkOyNMBLhLGhe7pO6Vz4vHe0FeNkfn268ZbhfA7mZqW/3cGHW8H3ZZ EKhl2fYjOag20KTcMDxyhS/ee5hUgX2sZhoMBK/htgiJ3HRgdoEvgmLVje8o1JOvrL4i nSYAFhO5byMXQsJSXDFVIilneUQN3Dyoq0MZPZZil/RknwQG6ctwNWg/1KYUYvHBpeHt NPoO+BX7Tl82QfC3F16Aq4u8vd/rBkFVV6n57adaarfOjB/4+qyuLc+liU5e7AZmYaFH zZMSd3bw7tP92/rn4WqjYj7v5dF6DNj0TliP1A3pQJP0SryTjw87JnqHmrhIxHqoXLtS ZL+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=IYVvmgop; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o124si55659039pfb.256.2019.01.03.15.30.59; Thu, 03 Jan 2019 15:31:14 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=IYVvmgop; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732530AbfACRRD (ORCPT + 99 others); Thu, 3 Jan 2019 12:17:03 -0500 Received: from mail.kernel.org ([198.145.29.99]:51882 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730554AbfACRRD (ORCPT ); Thu, 3 Jan 2019 12:17:03 -0500 Received: from gmail.com (unknown [104.132.1.77]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 4E7892073D; Thu, 3 Jan 2019 17:17:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1546535822; bh=W7Wiltv5gCLIUwsnevB3rRn0lr2jwTqaPd8I/6WmpVk=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=IYVvmgopgiHQa6Y48PXGBAZOhaXzhx9G9qY9BlpzkQAmvFjTO0uBcTsvrVglf9hN+ cAbkBO9Ajn1vcYtWU0AcV10yE2MbYGUPgbSUEc1cu9Mu5tFl+/MVt0uyN+KFr3lX5n M4l04VhcRHxYgrVFrN9KEjIDFmSyckVtPiwi9kdM= Date: Thu, 3 Jan 2019 09:17:00 -0800 From: Eric Biggers To: Aaro Koskinen , David Howells Cc: "Theodore Y. Ts'o" , Jaegeuk Kim , linux-fscrypt@vger.kernel.org, linux-kernel@vger.kernel.org, keyrings@vger.kernel.org Subject: Re: Bug report: unaligned access with ext4 encryption Message-ID: <20190103171659.GA208343@gmail.com> References: <20181230162906.GI27785@darkstar.musicnaut.iki.fi> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181230162906.GI27785@darkstar.musicnaut.iki.fi> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Dec 30, 2018 at 06:29:06PM +0200, Aaro Koskinen wrote: > Hi, > > When using ext4 encryption on SPARC, there's plenty of dmesg noise about > unaligned access: > > [ 167.269526] Kernel unaligned access at TPC[5497a0] find_and_lock_process_key+0x80/0x120 > [ 167.270152] Kernel unaligned access at TPC[5497a0] find_and_lock_process_key+0x80/0x120 > [ 181.087451] log_unaligned: 5 callbacks suppressed > [ 181.087511] Kernel unaligned access at TPC[5497a0] find_and_lock_process_key+0x80/0x120 > [ 181.092435] Kernel unaligned access at TPC[5497a0] find_and_lock_process_key+0x80/0x120 > [ 181.095816] Kernel unaligned access at TPC[5497a0] find_and_lock_process_key+0x80/0x120 > > And also seen on an ARM machine: > > $ cat /proc/cpu/alignment > User: 0 > System: 1028193 (find_and_lock_process_key+0x84/0x10c) > Skipped: 0 > Half: 0 > Word: 1028193 > DWord: 0 > Multi: 0 > User faults: 0 (ignored) > > Looks like user_key_payload layout is not optimal when data address > is used for fscrypt_key... I tried the below change and got rid of the > messages. Not sure what the proper fix should be? > > A. > > diff --git a/include/keys/user-type.h b/include/keys/user-type.h > index e098cbe27db5..6495ffcfe510 100644 > --- a/include/keys/user-type.h > +++ b/include/keys/user-type.h > @@ -31,7 +31,7 @@ > struct user_key_payload { > struct rcu_head rcu; /* RCU destructor */ > unsigned short datalen; /* length of this data */ > - char data[0]; /* actual data */ > + char data[0] __aligned(4); /* actual data */ > }; > > extern struct key_type key_type_user; > Hi Aaro, thanks for the bug report! I think you're on the right track; it makes much more sense to have the keyrings subsystem store the payload with better alignment, than to work around the 2-byte alignment in fscrypt. But how about '__aligned(__alignof__(u64))' instead? 4 bytes may not be enough. David, what do you think? - Eric