Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755907AbdCUH01 (ORCPT ); Tue, 21 Mar 2017 03:26:27 -0400 Received: from mail-wr0-f196.google.com ([209.85.128.196]:35760 "EHLO mail-wr0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751176AbdCUHYz (ORCPT ); Tue, 21 Mar 2017 03:24:55 -0400 Date: Tue, 21 Mar 2017 08:24:50 +0100 From: Ingo Molnar To: Andy Lutomirski Cc: Andy Lutomirski , X86 ML , "linux-kernel@vger.kernel.org" , Borislav Petkov , Linus Torvalds , Thomas Garnier Subject: Re: [PATCH tip:x86/mm] x86/tls: Forcibly set the accessed bit in TLS segments Message-ID: <20170321072450.GA18180@gmail.com> References: <62b7748542df0164af7e0a5231283b9b13858c45.1489900519.git.luto@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1884 Lines: 42 * Andy Lutomirski wrote: > On Sat, Mar 18, 2017 at 10:17 PM, Andy Lutomirski wrote: > > For mysterious historical reasons, struct user_desc doesn't indicate > > whether segments are accessed. set_thread_area() has always > > programmed segments as non-accessed, so the first write will set the > > accessed bit. This will fault if the GDT is read-only. > > > > Fix it by making TLS segments start out accessed. > > > > If this ends up breaking something, we could, in principle, leave > > TLS segments non-accessed and fix them up when we get the page > > fault. I'd be surprised, though -- AFAIK all the nasty legacy > > segmented programs (DOSEMU, Wine, things that run on DOSEMU and > > Wine, etc.) do their nasty segmented things using the LDT and not > > the GDT. I assume this is mainly because old OSes (Linux and > > otherwise) didn't historically provide APIs to do nasty things in > > the GDT. > > > > Fixes: 45fc8757d1d2 ("x86: Make the GDT remapping read-only on 64-bit") > > Signed-off-by: Andy Lutomirski > > FWIW, I'm now extra convinced that this won't break anything: the > accessed bit didn't work properly before this patch. When we > scheduled a task in, we'd copy the TLS segment descriptors to the GDT, > but we never copied them back out when we scheduled out, so the > accessed bit would randomly clear itself. Whoops :) > > So arguably this patch would be a bugfix even without Thomas' changes. It's probably even a small speedup per scheduling atom, as we'd avoid dirtying the GDT again and again, right? On very high context switching rates it might even be measurable in principle, as this ought to be the only thing that dirtied the (per CPU) GDT cacheline, so if the workload is write bandwidth or store queue depth bound this change will slightly improve things. Thanks, Ingo