Received: by 10.213.65.68 with SMTP id h4csp848501imn; Tue, 20 Mar 2018 17:37:51 -0700 (PDT) X-Google-Smtp-Source: AG47ELs2woEZMTORGjFrY/Eqp4FgFl3mu1a+yL/2NO031PzCqcD9gCbK00rds44zjgGoC4LDDx9n X-Received: by 10.98.181.18 with SMTP id y18mr15300403pfe.115.1521592671919; Tue, 20 Mar 2018 17:37:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521592671; cv=none; d=google.com; s=arc-20160816; b=ekKSCvfQRpkdAG/x8/iGrWFg8QLLeidDXZjmJi+iTs2d44q/YkQLVOQJFD63cVuevO hCkeXTFHUfs8YjJDU0GST8saKDOr0ljFGFtiGqCBRB+EILBSnY3FVZ2g/Kxd6HawIMrM 3K/MJX1aAbHsA2MNOxK5SL9/5uenilDleV44PBic9xAiGwA9HQucpfYGtwApUh2Jt37J y7mP4K+tdvHy2RdYveSJMrcvJRD4DwlSm8tc4qkYLU+jNQooGrER8XEZ+tLFJI0OywYG 7TdlxcE9nUxF9t8ozpfV4+mmLYIXeA3vDTq8PIf2oyq2HVah/2Let02cnGqbp1ZvKhCN MIVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dmarc-filter :arc-authentication-results; bh=2fV7CtMsdzNZZ1aERkzncgSWjKXTqkwW+ISipK1E4D0=; b=T3T14PKmqFRX+2hakCM99K7d5FSpElixuR72yT8d2kSEfK94LuFGCNNOZi2X6b+D/x K1X0Xu78tAb1paE4/tFx6QlYoyyanRgWG0APzmZcUFHIVQSXBsBkNwiK8qoqifW40oyP t2Q0Smkf/o2wfw8QdeV4As0BxDlRwVqILSwlQ5ueZr40t10zEdTLxfFIecbHKMDQCXew im+r6KO6DRulwrLojGJXDpm6ZpWb9Z8nsRMYpVFkfvw+C+878VQVoxqYkqfJ7D2+HpZt lp+XKtciNe2gbNY7kbf3YTqFcg8Cw/C+PaCY9S+UVTjli6TryazE9/ySaIG72SNi7UxZ WStg== 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 v15si1955216pgt.635.2018.03.20.17.37.37; Tue, 20 Mar 2018 17:37:51 -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 S1751542AbeCUAge (ORCPT + 99 others); Tue, 20 Mar 2018 20:36:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:54716 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751018AbeCUAgb (ORCPT ); Tue, 20 Mar 2018 20:36:31 -0400 Received: from mail-io0-f177.google.com (mail-io0-f177.google.com [209.85.223.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 404B621834 for ; Wed, 21 Mar 2018 00:36:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 404B621834 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 Received: by mail-io0-f177.google.com with SMTP id g14so4575001iob.13 for ; Tue, 20 Mar 2018 17:36:31 -0700 (PDT) X-Gm-Message-State: AElRT7G3oV03oT3MUoW/3iYdI1L/RVukeRJ2N+5R8jxni10RAlRpUdRb CIfDyWD8fx5oqniUjfVKaBGu2UqetsTo7rrlXmWAqA== X-Received: by 10.107.40.73 with SMTP id o70mr18229657ioo.6.1521592590560; Tue, 20 Mar 2018 17:36:30 -0700 (PDT) MIME-Version: 1.0 Received: by 10.2.137.70 with HTTP; Tue, 20 Mar 2018 17:36:10 -0700 (PDT) In-Reply-To: <191d8212-6740-3131-1653-d057f522843c@zytor.com> References: <1521481767-22113-1-git-send-email-chang.seok.bae@intel.com> <1521481767-22113-14-git-send-email-chang.seok.bae@intel.com> <191d8212-6740-3131-1653-d057f522843c@zytor.com> From: Andy Lutomirski Date: Wed, 21 Mar 2018 00:36:10 +0000 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 13/15] x86/fsgsbase/64: With FSGSBASE, compare GS bases on paranoid_entry To: "H. Peter Anvin" Cc: David Laight , "Chang S. Bae" , "x86@kernel.org" , "luto@kernel.org" , "ak@linux.intel.com" , "markus.t.metzger@intel.com" , "tony.luck@intel.com" , "ravi.v.shankar@intel.com" , "linux-kernel@vger.kernel.org" , Dave Hansen Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Mar 20, 2018 at 8:07 PM, H. Peter Anvin wrote: > On 03/20/18 03:16, David Laight wrote: >> From: Chang S. Bae >>> Sent: 19 March 2018 17:49 >> ... >>> When FSGSBASE is enabled, SWAPGS needs if and only if (current) >>> GS base is not the kernel's. >>> >>> FSGSBASE instructions allow user to write any value on GS base; >>> even negative. Sign check on the current GS base is not >>> sufficient. Fortunately, reading GS base is fast. Kernel GS >>> base is also known from the offset table with the CPU number. >> ... >> >> Use code might want to put a negative value into GSBASE. >> While it is normal to put a valid address into GSBASE there >> is no reason why the code can't put an offset into GSBASE, >> in which case it might be negative. >> >> Yes, I know you can't put arbitrary 64bit values into GSBASE. >> But the difference between 2 user pointers will always be valid. >> > > You don't have a choice: you can't control what userspace puts in there. > Anything that depends on a specific value is inherently unsafe. > > But we also don't need swapgs when we have rdgsbase/wrgsbase available. > We can indeed just unconditionally save it (via rdgsbase) into the stack > frame and wrgsbase the correct percpu value. In that case it might be > necessary in order to avoid insane complexity to also save/restore the > gs selector. This is exactly what the old code did. I liked the old code better. > > Is it going to be faster? *Probably* not as swapgs is designed to be > fast; it does, however, eliminate the need to RDMSR/WRMSR inside the > kernel task switch as the user space gsbase will simply live on the > stack. (This is assuming we do this unconditionally on every method of > kernel entry, including non-paranoid. I'm not sure if we ever care > about the userspace GS/GSBASE inside a paranoid handler, but if we do it > would be rather messy to find if we do this conditionally. > > Now... > > + ALTERNATIVE "jmp .Lparanoid_entry_no_fsgsbase", \ > + "RDGSBASE %rdx", X86_FEATURE_FSGSBASE > + READ_KERNEL_GSBASE %rax > > READ_KERNEL_GSBASE here seems like a Really Bad Name[TM] for this macro, > since it seems to imply reading MSR_KERNEL_GS_BASE, rather than finding > the current percpu offset. I would prefer calling it something like > FIND_PERCPU_BASE or something like that. I think we should revert to what the old patches did here.