Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp1383798imm; Fri, 29 Jun 2018 17:35:58 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKz+juvMES4U6kC+49u9ZusdmNhyexQv9A00PnkmzHNOaPV4vxo4IsNjZbSC532ZiaP1uvp X-Received: by 2002:a63:8442:: with SMTP id k63-v6mr14467746pgd.309.1530318958153; Fri, 29 Jun 2018 17:35:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530318958; cv=none; d=google.com; s=arc-20160816; b=EuPyJG0b5gVGFTUiEX7bA1bJHw6OwXGKawUf6O42bQCkAxYhf+pBgKNo1dKitVDk7r 9i1EXd/Fz/8qDcKHawgMYb3VZievSCLxmvaMzzh7pbz2XRT8F9vDlIrcgcQSm/faTBh/ I7kHEYi4zip32l7Zx8caNJ5QutgyNy3TrnkzkG7xALScjN+CMetekPjBfsKYrD/WesJ7 oSsUdtMkne7rDuf7r75azvvb+IcSu1ssGayFXnn2WPsiX29zeuFwsSn8Q9eL8f5cddlV UF48sriseJ2kS6cDZCzx1tiSGh292wqVt6tCr+WcTa7oFFPaa9UM0QM/o4K+c2SOXKja Wylg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date :arc-authentication-results; bh=W5gV7oyRPYFirZpUadXlN9FcOSupdeuszLk5dRTvhmk=; b=yF3scF3GebucZPKAmXUZBX+gv/9c7mhgz1ZVBLDmJosKX3iPa8S3bBNHH2+25WNHhi 90TuB3qM1GFBmA/3BuhshQFxZ1tCB6VPb0yur7W7U+wyvA707z83A+v7Xa1iw+PELa6C vkFHG4wVJpYDJUbDSksWk8XeFvHm+yEBeTYiBis+s9pPQvx8MeeJXQ2nzwOg1kM3rsUv a3Vjs92mV34bM9hJgtmsNqEEXwfXiYd+jxKzeaUA2fl/BWqY86m381al5Vx1y5PtmtQA +ZIe93KI/f7mmPbkRPwZg5U7twxOrZpiJre1dr2/Ql7+OKKIIgSIwcnwryvwEzk2yB7v lchw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q129-v6si5542582pga.217.2018.06.29.17.35.43; Fri, 29 Jun 2018 17:35:58 -0700 (PDT) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935829AbeF2VpM (ORCPT + 99 others); Fri, 29 Jun 2018 17:45:12 -0400 Received: from Galois.linutronix.de ([146.0.238.70]:32809 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935556AbeF2VpL (ORCPT ); Fri, 29 Jun 2018 17:45:11 -0400 Received: from p4fea482e.dip0.t-ipconnect.de ([79.234.72.46] helo=nanos) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1fZ1C9-0008IA-1z; Fri, 29 Jun 2018 23:44:45 +0200 Date: Fri, 29 Jun 2018 23:44:44 +0200 (CEST) From: Thomas Gleixner To: Dave Hansen cc: Fenghua Yu , Ingo Molnar , H Peter Anvin , Ashok Raj , Alan Cox , Peter Zijlstra , Rafael Wysocki , Tony Luck , Ravi V Shankar , linux-kernel , x86 Subject: Re: [PATCH v2 2/4] x86/split_lock: Align x86_capability to unsigned long to avoid split locked access In-Reply-To: <8fdfb671-f223-163b-12cd-3c97d94f91b4@intel.com> Message-ID: References: <1530282807-66555-1-git-send-email-fenghua.yu@intel.com> <1530282807-66555-3-git-send-email-fenghua.yu@intel.com> <20180629190346.GO18979@romley-ivt3.sc.intel.com> <20180629203844.GA68178@romley-ivt3.sc.intel.com> <8fdfb671-f223-163b-12cd-3c97d94f91b4@intel.com> User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 29 Jun 2018, Dave Hansen wrote: > On 06/29/2018 01:38 PM, Fenghua Yu wrote: > > How to handle data that is used in generic code which can be used on > > non-Intel platform? For exmple, if I do this change for struct efi in > > include/linux/efi.h because set_bit() sets bits in efi.flags: > > - unsigned long flags; > > + unsigned long flags __aligned(unsigned long); > > } efi; > > > > People may argue that the alignment unnecessarily increases size of 'efi' > > on non-Intel platform which doesn't have split lock issue. Do we care this > > argument? > > Unaligned memory accesses are bad, pretty much universally. This is a > general good practice that we should have been doing anyway. Let folks > complain. Don't let it stop you. > > Also, look at the size of that structure. Look at how many pointers it > has. Do you think *anyone* is going to complain about an extra 4 bytes > in a 400-byte structure? But in the above case the compiler does already the right thing. Why? Because struct members are aligned to their natural alignment unless the struct is explicitely marked 'packed'. In that case the programmer has to take care of the alignment. Just look at it with pahole: struct efi_memory_map memmap; /* 280 56 */ /* XXX last struct has 7 bytes of padding */ /* --- cacheline 5 boundary (320 bytes) was 16 bytes ago --- */ long unsigned int flags; /* 336 8 */ The issue with the capability arrays is that the data type is u32 which has the natural alignment of 4 byte, while unsigned long has 8 byte on 64bit. So just slapping blindly aligned(unsigned long) to anything which is accessed by locked instructions is pointless. Thanks, tglx