Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1605362

Re: [PATCH tip:x86/mm] x86/tls: Forcibly set the accessed bit in TLS segments

Path csiph.com!news.mixmin.net!aioe.org!bofh.it!news.nic.it!robomod
From Ingo Molnar <mingo@kernel.org>
Newsgroups linux.kernel
Subject Re: [PATCH tip:x86/mm] x86/tls: Forcibly set the accessed bit in TLS segments
Date Tue, 21 Mar 2017 08:30:02 +0100
Message-ID <tnmoW-5p-1@gated-at.bofh.it> (permalink)
References <tmBzI-XZ-13@gated-at.bofh.it> <tnkn7-7aS-1@gated-at.bofh.it>
Dkim-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=UsCyQFjWwz6xpidkEvucVHpnlVaJRleAw4FexAPG6p8=; b=VTPJP89ZJ8HAgHvjpYdemoXHay2y+g9r3jlwowaWwoTwS9+R77xBWz8Re1Y5FgUZDF rseqq4qFFBRhAEGvb8Rw6WIZoij4cLXclSWJp5lxVReESCBl3x1lY/2wc3QAF5+zw/AH x5ZbeHLKEzph845z2Zas+0gDoR1VveZW288EhBfmj+NB4vTrmig0DNCx722hqzmZPUhh C2sEungpu1pP6kXdEi5OIksfftLXObWt0QphVd4dzbIyCaxUW/irVRL9bkWgbgF7O52a DiegOGDNtSBIbb0wEqSGcayvmiml8va0pYOJEww6cT106KcGs7+UYYET8k9cUr4JaP8V XLkg==
X-Google-Dkim-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to:user-agent; bh=UsCyQFjWwz6xpidkEvucVHpnlVaJRleAw4FexAPG6p8=; b=pKOM0iTnbZla7se7dWCbuSJ2jIUG8I3F5sSMH2UYl/jqd44Oxg9wq1g2ILjk6Zxgav BDtHJW57fKsBAMFna0xDVbmciV4NcrP7JgB2bLDV8qG+1bnU7uIGwy/ydBUaPf7h/jKi SGgcHHSCB/ePk0Ce7uVo/k/eWJ9mybeyYdqHubYviWDd7AekimIVRMu+Pdpyn5cAez0I NAFKJ9otEYRUv6BNArfARzCNF0vzsa3egPHyMyQKGnT+spcLS0+brpCYHBMRgeyTe23I nsYbn1XURHU/wvxlYdgcoODohI3RzmFkCLDq56o0vM57eXbi2CfSzJV2Gp3X8kpsLKco KmUg==
X-Gm-Message-State AFeK/H30IDzweGynBJ+neAbuNz86NGzLNExN/Amygs824ZMJP0XodAxnOz33pDsF1CKo2A==
X-Received by 10.223.164.83 with SMTP id e19mr28598789wra.201.1490081093214; Tue, 21 Mar 2017 00:24:53 -0700 (PDT)
MIME-Version 1.0
Content-Type text/plain; charset=us-ascii
Content-Disposition inline
User-Agent Mutt/1.5.24 (2015-08-30)
Sender robomod@news.nic.it
List-ID <linux-kernel.vger.kernel.org>
X-Mailing-List linux-kernel@vger.kernel.org
Approved robomod@news.nic.it
Lines 42
Organization linux.* mail to news gateway
X-Original-Cc Andy Lutomirski <luto@kernel.org>, X86 ML <x86@kernel.org>, "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>, Borislav Petkov <bp@alien8.de>, Linus Torvalds <torvalds@linux-foundation.org>, Thomas Garnier <thgarnie@google.com>
X-Original-Date Tue, 21 Mar 2017 08:24:50 +0100
X-Original-Message-ID <20170321072450.GA18180@gmail.com>
X-Original-References <62b7748542df0164af7e0a5231283b9b13858c45.1489900519.git.luto@kernel.org> <CALCETrVHm1ovumDyK6oGs=hQ74+GtkZ4z7ndsSENjEAtrUFGUg@mail.gmail.com>
X-Original-Sender linux-kernel-owner@vger.kernel.org
Xref csiph.com linux.kernel:1605362

Show key headers only | View raw


* Andy Lutomirski <luto@amacapital.net> wrote:

> On Sat, Mar 18, 2017 at 10:17 PM, Andy Lutomirski <luto@kernel.org> 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 <luto@kernel.org>
> 
> 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

Back to linux.kernel | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

[PATCH tip:x86/mm] x86/tls: Forcibly set the accessed bit in TLS segments Andy Lutomirski <luto@kernel.org> - 2017-03-19 06:30 +0100
  [tip:x86/mm] x86/tls: Forcibly set the accessed bit in TLS segments tip-bot for Andy Lutomirski <tipbot@zytor.com> - 2017-03-19 12:30 +0100
  Re: [PATCH tip:x86/mm] x86/tls: Forcibly set the accessed bit in TLS segments Andy Lutomirski <luto@amacapital.net> - 2017-03-21 06:20 +0100
    Re: [PATCH tip:x86/mm] x86/tls: Forcibly set the accessed bit in TLS  segments Ingo Molnar <mingo@kernel.org> - 2017-03-21 08:30 +0100

csiph-web