Received: by 10.213.65.68 with SMTP id h4csp853698imn; Tue, 20 Mar 2018 17:49:16 -0700 (PDT) X-Google-Smtp-Source: AG47ELstizbVg2Yy7vIkI3yWnTC/GOPMpPCAqp2ibbjNoMx9ZbxOC9T1RCVAijVJfsui1m3lQASw X-Received: by 2002:a17:902:43e4:: with SMTP id j91-v6mr814977pld.118.1521593356066; Tue, 20 Mar 2018 17:49:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521593356; cv=none; d=google.com; s=arc-20160816; b=t6Xi3V9L1XuTcv5MSTl3/Qn2YLR3WUUAOFUgasSuZRx8c9wPElabSpiIjHlUOiKGf1 qDSpbrgzCiZN57G8nsXVpPEaar6jfBQ9kyBVEj3cgguMSa0vdzCKegtTEV17sy+QXUbr CVmjwIs0lU5ZNw10RjkTPoqxLZKRe9mpc0eUiZKz4uVGrmgbB491XPtV0DUhyyLBoHEI PCp8awZOTGqiio20QOlo1ShkQdw3lq4s5Dx2cg+HZffYPAf74hXpN8cjlROOUe/sMIBW Yk70DAFra9ggv1e/q7zt51NR3N0vERIxS2KKo0b5ch8SxbDlUvQfGJBEnZ8GBL71Xx0U 6dyw== 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=hE0diV/QtNPQzjAe1abdMHZiyKajuaR6I5N3PKMuoCo=; b=GTnNHgCo6bG8jzqOOkIUw8nkx1a3BofwFjF/hNDzgbKRolGJtml63RoOq2WoMNN+b5 iYV6O9cFky93D5uAArduJgVhbM0DdrtSDaax1w2SadEyVluZueCPJjiDbV5eK9MGaA/i 85EpoMI1ZKOrZl7M2yMOLbO2pb9np60C8/t9YUojQiYEFbw3mQ5BezyLOBg9Ye2lMFMw qw087Db5LNqrzZCIpNvEXTK0FVpcW1+epm4EDcZ0qKRFanHANlWp7syJ1vm2FqjnWS8D BbbuKw7m2HyH7Nw35ft8vs9seSLy9tKS93pnphionPzNhmubQAQ4UVur+RRz0H+SG9+W jQzw== 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 d31-v6si2706977pld.495.2018.03.20.17.49.02; Tue, 20 Mar 2018 17:49:16 -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 S1751646AbeCUArq (ORCPT + 99 others); Tue, 20 Mar 2018 20:47:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:34286 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751448AbeCUArm (ORCPT ); Tue, 20 Mar 2018 20:47:42 -0400 Received: from mail-it0-f52.google.com (mail-it0-f52.google.com [209.85.214.52]) (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 1F85F2177B for ; Wed, 21 Mar 2018 00:47:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1F85F2177B 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-it0-f52.google.com with SMTP id j137-v6so4793747ita.1 for ; Tue, 20 Mar 2018 17:47:42 -0700 (PDT) X-Gm-Message-State: AElRT7F/0Ury7pn4RnF5VVKqXVXFF6BS9U6x3PUMnc8ly92QZa7n9ac8 cMpCheBNLR8Vkt+N3RgLEwHecYbk1xySpyatNq7AQQ== X-Received: by 2002:a24:4e0e:: with SMTP id r14-v6mr2033359ita.146.1521593261478; Tue, 20 Mar 2018 17:47:41 -0700 (PDT) MIME-Version: 1.0 Received: by 10.2.137.70 with HTTP; Tue, 20 Mar 2018 17:47:21 -0700 (PDT) In-Reply-To: References: <1521481767-22113-1-git-send-email-chang.seok.bae@intel.com> <1521481767-22113-15-git-send-email-chang.seok.bae@intel.com> From: Andy Lutomirski Date: Wed, 21 Mar 2018 00:47:21 +0000 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 14/15] x86/fsgsbase/64: Support legacy behavior when FS/GS updated by ptracer To: "Bae, Chang Seok" Cc: Andy Lutomirski , X86 ML , Andi Kleen , "H. Peter Anvin" , "Metzger, Markus T" , "Luck, Tony" , "Shankar, Ravi V" , 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 Tue, Mar 20, 2018 at 4:33 PM, Bae, Chang Seok wrote: > On 3/20/18, 08:05, "Andy Lutomirski" wrote: >> I've also suggested something like this myself, but this approach is >> far more complicated than the older approach. Was there something >> that the old approach would break? If so, what? > Sorry, I don't know your suggestion. Can you elaborate your suggestion? What the old code did. If I've understood all your emails right, when you looked at existing ptrace users, you found that all of them that write to gs and/or gs_base do it as part of a putregs call that writes them at the same time. If so, then your patch does exactly the same thing that my old patches did, but your patch is much more complicated. So why did you add all that complexity? > >>> + /* >>> + * %fs setting goes to reload its base, when tracee >>> + * resumes without FSGSBASE (legacy). Here with FSGSBASE >>> + * FS base is (manually) fetched from GDT/LDT when needed. >>> + */ >>> + else if (static_cpu_has(X86_FEATURE_FSGSBASE) && >>> + (value != 0) && (task->thread.fsindex != value)) >>> + task->thread.fsbase = task_seg_base(task, value); > >> The comment above should explain why you're checking this particular >> condition. I find the fsindex != value check to be *very* surprising. >> On a real CPU, writing some nonzero value to %fs does the same thing >> regardless of what the old value of %fs was. > > With FSGSBASE, when both index and base are not changed, base will > be (always) fetched from GDT/LDT. This is not thought as legacy behavior > we need to support, AFAIK. > >> This is_fully_covered thing is IMO overcomplicated. Why not just make >> a separate helper set_fsgs_index_and_base() and have putregs() call it >> when both are set at once? > > Using helper function here is exactly what I did at first. I thought this > tag is simple enough and straightforward at the end. But I'm open to > factor it out. > > I retract this particular comment. But I still think that all this complexity needs to be more clearly justified. My objection to the old approach wasn't that I thought it was obviously wrong -- I thought that someone needed to survey existing ptrace() users and see if anyone needed the fancier code that you're adding. Did you find something that needs this fancy code?