From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751826AbdHGQPG (ORCPT ); Mon, 7 Aug 2017 12:15:06 -0400 Received: from mail.kernel.org ([198.145.29.99]:59816 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751426AbdHGQPF (ORCPT ); Mon, 7 Aug 2017 12:15:05 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B8BBB22CAA Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=luto@kernel.org MIME-Version: 1.0 In-Reply-To: References: From: Andy Lutomirski Date: Mon, 7 Aug 2017 09:14:43 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: FSGSBASE ABI considerations To: "Bae, Chang Seok" Cc: Andy Lutomirski , X86 ML , "linux-kernel@vger.kernel.org" , Linus Torvalds , Borislav Petkov , Brian Gerst , Stas Sergeev Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Jul 31, 2017, at 5:23 PM, Bae, Chang Seok wrote: >> On an FSGSBASE-enabled system, I think we need to provide deterministic, documented, tested behavior. I can think of three plausible choices: >> 1a. modify_ldt() immediately updates FSBASE and GSBASE all threads that reference the modified selector. >> 1b. modify_ldt() immediatley updates FSBASE and GSBASE on all threads that reference the LDT. >> 2. modify_ldt() leaves FSBASE and GSBASE alone on all threads. >> (2) is trivial to implement, whereas (1a) and (1b) are a bit nasty to implement when FSGSBASE is on. > >> The tricky bit is that 32-bit kernels can't do (2), so, if we want modify_ldt() to behave the same on 32-bit and 64-bit kernels, we're stuck with (1). > > While implementing (1) is still unclear for context switch, here is one idea for (1b): > - thread struct has new entry for ldt pointer that last seen > - modify_ldt happens > - ldtr upated for active threads via IPI > - for inactive threads being scheduled in, ldtr updated before __switch_to > - in __switch_to, read ldtr by sldt and compare the new ldt pointer > sldt is ucode that likely takes only a couple cycles > - mostly matched given modify_ldt is rare > - unmatched, don't write gsbase if gs indicating LDT That won't be reliable -- LDTR could change more than once and be reused between context switches. If we went this route, I think we'd put a u64 version in ldt_struct. We'd also need to audit and fix up every access to thread.fs/gsbase.