Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp1018729imm; Thu, 31 May 2018 13:40:05 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLYHmORYZKHFz7ZGDPfkOZ4aYz4WR0suJYqaNxQEEQDtmiXiYFl9asl1dfrLaH5lHH7gcpV X-Received: by 2002:a62:dc1c:: with SMTP id t28-v6mr3806081pfg.137.1527799205549; Thu, 31 May 2018 13:40:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527799205; cv=none; d=google.com; s=arc-20160816; b=YMxamzerCoo4jfqafwE5sVgVSX5SZ4vkyAMf2HxPLcjBSVQAONVwclVPvBsIcIoVjY 3ybVZ+JyvBieOCg0EWtGMNJrQTRFmOCltD4pivt0vxAbzf/WD4/N+iHSkaniZ9OQG7fK 5fLX8j1qDsnytRQS74+Y428ZG+imOGSI967M/D5u1USbQ2dXTVWjhJIvUNSWAnAECCin pF1ShLIXD4xnAVg7+1IReyZRwwB1YSFWsoFkWoNymCjZucl0nIvxPuzFqypF4CVDoN/t oz+XBwIcxYrHR7NiqY6C9MREmh3+MTtimhGJabUIlN09eZjS2o1HCEaqq1gveT5SbLA0 3gFg== 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 :in-reply-to:references:mime-version:dkim-signature :arc-authentication-results; bh=wcCbuELCvzlpkEJCgLcibxC+kRE/GVXKuyj0UgkEUH8=; b=IQhs/m0QLs60hMYgSVK4aya1yRsT/nVwqwzO081FyvfCg2mWTteNOzhaABZQNQQGk+ 77e1I7vlfFuJXNlNFWowKr/eZnbcsRF97P+zaHamM1sZeyFVFJqfEMXalwg1fJ7yiHYc WWmGJJ2sDRjBjb9T9XkDiIuAx07/VWAHe+MhSRWamPmQhxOX7bpqk/2vxRcJAdNedvgI ZyhN994gTfMHsD5v5cYuWqRuB6NX8zyYfdHCpvr5v2eEbNmdt+RGwe3yX0gDrw6OisR4 NUByBL5OksxMcxiEuADSKGRjzi99Q6ravvQWlXJ0h85dzWjhbpGDAu9UGvRuU/qletlY 6sMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=rmB+2upv; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d123-v6si30099129pgc.445.2018.05.31.13.39.50; Thu, 31 May 2018 13:40:05 -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; dkim=pass header.i=@kernel.org header.s=default header.b=rmB+2upv; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754461AbeEaUiN (ORCPT + 99 others); Thu, 31 May 2018 16:38:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:51930 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754160AbeEaUiM (ORCPT ); Thu, 31 May 2018 16:38:12 -0400 Received: from mail-wr0-f178.google.com (mail-wr0-f178.google.com [209.85.128.178]) (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 959BD208B6 for ; Thu, 31 May 2018 20:38:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527799091; bh=ZrIhwbieZ35K+bA030E5FjKvbNViPtwDkc0neSmzQPo=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=rmB+2upvmIFnSYnsQZ2QvzB6oTkUY3oU0L5IDrLDrHsXxZKzmJAEOVHiu8RUqYg8R ZeUZahR3gbKPMoFqXgZT2lUDMoPflpEoY5CCsvKZABxvEfO22mmrjpvr6M52tIR/8z G7jyCoRU2Fm+BdEqMT8SLYtNlSRCSiYifeHiiUbE= Received: by mail-wr0-f178.google.com with SMTP id i14-v6so34217181wre.2 for ; Thu, 31 May 2018 13:38:11 -0700 (PDT) X-Gm-Message-State: ALKqPwcrYRHGGn8oCWyXrLU0Tf3xO8+4fd25KygRoGhZ+Yhr2ELgFdtf 9FAA1YLySdd9RDSra7t+ErbnIW9dD60mFDPOEyaFRg== X-Received: by 2002:adf:9c01:: with SMTP id f1-v6mr6287553wrc.171.1527799090044; Thu, 31 May 2018 13:38:10 -0700 (PDT) MIME-Version: 1.0 References: <1527789525-8857-1-git-send-email-chang.seok.bae@intel.com> In-Reply-To: <1527789525-8857-1-git-send-email-chang.seok.bae@intel.com> From: Andy Lutomirski Date: Thu, 31 May 2018 13:37:58 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH V2 00/15] x86: Enable FSGSBASE instructions To: "Bae, Chang Seok" Cc: Andrew Lutomirski , "H. Peter Anvin" , Thomas Gleixner , Ingo Molnar , Andi Kleen , Dave Hansen , "Metzger, Markus T" , "Ravi V. Shankar" , LKML 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 Thu, May 31, 2018 at 10:58 AM Chang S. Bae wrote: > > FSGSBASE is 64-bit instruction set to allow read/write > FS/GS base from any privilege. As introduced from > Ivybridge, enabling effort has been revolving quite long > [2,3,4] for various reasons. After extended discussions [1], > this patchset is proposed to introduce new ABIs of > customizing FS/GS base (separate from its selector). Thanks! I have two general comments: 1. Can you try and generate a new version of patches 1-5 quickly? I think it would be nice to get them merged this cycle. 2. I spoke to hpa, and he said that, after further investigation of how gdb works, a command like 'p $gs = 0x7' results in PTRACE_POKEUSER. He further suggested that it would therefore be reasonable to have POKEUSER on gs refresh gsindex (assuming the poked value is nonzero, sigh) and to make PTRACE_SETREGS iterate over the registers in reverse order so that it behaves sanely. Is this indeed the case? 3. The ptrace behavior is sufficiently subtle that I think it needs a test case. Can you add a new selftest (or extend the existing fsgsbase selftest) to do something like this: - Create an LDT entry in slot zero with base == 1. - Read out the hwcap bit indicating whether we have the new instructions on. - MOV 0x7 to %gs and use ptrace to read gsbase. Confirm that the result is 1. - MOV 0x7 to %gs, do wrgsbase to change the base to 2 (if supported), and use ptrace to read gsbase. Confirm that the result is 2. - Same as previous test, but with 0x0 instead of 0x7. - Allocate a TLS segment with base == 3. Load it into %gs. Use ptrace to read gsbase. Confirm that the result is 3. - Use ptrace to toggle %gs (using POKEUSER) back and forth between 0x0, 0x7, and the TLS segment. In each case, immediately use ptrace to read the base and confirm that you get the expected result. Then resume the tracee and read the base directly, confirming that you get the expected result. - Use PTRACE_SETREGS to load gs = 0, gsbase = 4. Confirm that GETREGS returns those values back and confirm that they are in fact loaded into the tracee. - Use PTRACE_SETREGS to load gs = 0x7, gsbase = 4. Confirm that GETREGS returns those values back and confirm that they have the expected values (which will depend on the hwcap bit). Also confirm that the expected values are loaded into the tracee. Does this seem reasonable? The mov_ss_trap testcase has a nice bit of code you can borrow to invoke ptrace operations on yourself.