Received: by 10.213.65.68 with SMTP id h4csp153506imn; Wed, 21 Mar 2018 14:58:11 -0700 (PDT) X-Google-Smtp-Source: AG47ELugjfY+NSKlMehgBPnRfusL7rp6oudvfEuuwSedw/s+TcC88eukGBT4JFTwujhRyCkgaapk X-Received: by 2002:a17:902:7787:: with SMTP id o7-v6mr22475921pll.75.1521669490967; Wed, 21 Mar 2018 14:58:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521669490; cv=none; d=google.com; s=arc-20160816; b=FGBBUbxnm0QRmd68aKPh4OUj33CLInU3vSJ7+xdv4CD89hJnf6HnUvjJqqPQ3w5Dy5 PgRKRFwL0ELw8p4aXJsDQJZC9ISzuKW7CC2dI0tBTVfbQ1Ed6hJpjxW31pomfOwxiJQ6 37T8pBNHvAQZG1d1ruIKumAxkA9d3CiPm2swV5qRUiGcCmKHWZHjjwxh9cRQ6XJqZ1ws XX2/DyO4/zgCsrpQ1mA9awC5/7Uf7Ei7gkqs6UtiaOaf3RAbRQB08Bl0KNRWw5w2fcHk wp0zMODEaQ+FiTLRtAk+ycHDQeuHxInrADmXY+ukytHxjEhDV23hZ0GsTLp6YhIqea0O E+jQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:arc-authentication-results; bh=/qozT+xOln2dEMLHO1+aQTtScQRGz86v5ePgYCSb9Q0=; b=whsckpcrqKUL/CKSNgwV+MQ5LydIX9Kv/wujhAUpjcuZ9Yo80LUO+IKdYSDwHhyQUV +JHsnGGMar0ekb7lrXsc1dNDEK3OLt/bBtaBQhxctb60ATKg1pyIlRWHhoGDAWTnkSpn 7ogckVqbTyEsah6fm88eUQIR0Iy49Z/tDCp2Xf0MTlU1vqaUQ6daPP73NU0ud4o58i55 8SbnBskH4nst51O8Od43NENzXp6nVdOXBjO3z+D+5LjiTOw7psTjPZzXGT1XWQlJsmhJ snRMdsMiG+pnODifIzx5W1sVGxC2wSIPZiEQWCYlCK74DT9DlnjKcCqfj9Dsoyydd2xl SXVA== 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 e5-v6si5306334plk.730.2018.03.21.14.57.55; Wed, 21 Mar 2018 14:58:10 -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 S1753891AbeCUV4z (ORCPT + 99 others); Wed, 21 Mar 2018 17:56:55 -0400 Received: from terminus.zytor.com ([198.137.202.136]:39523 "EHLO mail.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753772AbeCUV4y (ORCPT ); Wed, 21 Mar 2018 17:56:54 -0400 Received: from hanvin-mobl2.amr.corp.intel.com ([192.55.54.42]) (authenticated bits=0) by mail.zytor.com (8.15.2/8.15.2) with ESMTPSA id w2LLuS5t019545 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NO); Wed, 21 Mar 2018 14:56:28 -0700 Subject: Re: [PATCH 13/15] x86/fsgsbase/64: With FSGSBASE, compare GS bases on paranoid_entry To: Andy Lutomirski Cc: David Laight , "Chang S. Bae" , "x86@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 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: "H. Peter Anvin" Message-ID: <9aa3ef0a-84b5-9806-4213-1b63023e6c5a@zytor.com> Date: Wed, 21 Mar 2018 14:56:23 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 03/20/18 17:36, Andy Lutomirski wrote: >> >> 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. > I don't really understand why you want to do it this way. 1. It means that the location of the user space gs_base is ill-defined, whereas with the SWAPGS it is *always* in the same place. 2. It is most likely slower, although I obviously haven't benchmarked it. -hpa