Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp4616390ybb; Tue, 7 Apr 2020 10:57:14 -0700 (PDT) X-Google-Smtp-Source: APiQypIm8r6P+3za7fvNn16xhExr9mpuP5SlfirqgEoT7uMinRWpwDfHUgU7ZVnURufEnTLzTmAx X-Received: by 2002:aca:5014:: with SMTP id e20mr65832oib.34.1586282234753; Tue, 07 Apr 2020 10:57:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586282234; cv=none; d=google.com; s=arc-20160816; b=d7VOX8LNa01nAvQNLvb8fIortmGHFc4WSi8/KsdODl09WgTrsgHpAN4IUpfPwaYnwa 1SggTbP/guDadhA7oz4JxuOYiRnU3oHtiLhZKf6G4S0MVOWbOc98QaKWdMsDosLextLu iQTlknxf/6H5TRiFr1GHVWXqEN/15vATXnymLlCZp8KvDBeyDo6YWBhzo2etU/mBLq3X oD1vyvIzPMijLOD6Bh8432TrWL+oRyNnLqqYsWI+6GgFOudtDgDC8Rk/SJsmRtd6wM7t aWvYhVcU0JKOO72Fm29uvZDHJ4K3QoNEaLsYVqtgGVjZDg+jFIOELa1069RLrfcmN+R1 TFzg== 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; bh=hvJ5mj6gXn9DT9sfAhJ2ChcXw2JKTkzR1Wi3heZ02Ig=; b=IsupKZ5LsB3mDYR/GWulhCXwNNpGnScUPOX6B2mj3Nxr4YGd+iQr3yj4ke2RBEM1SP dGrjVJJebQPSnMT072AmDJK2PDnLv+2m7Xjz7NOEjeOPf4PiHHV/6DBBiHMih9uj+6sr QIztoQioTni716fIj9EzlLP04fFovBzJ9LaK2Ef9vwNv/rV+pzXVAxk5mDlCfPvrIMQ4 SHIhDq/yOfH/ZmomyaDYVGLapEknd7qcDwpYhxNEu/nB+9k8o9zWdMTk7ykleb75qVOQ efAHN9jW0Hmn4wZD5Oc/VpEKJPovWaQfYYuhK1XXicYENn/mw9f/gbaA5n+vj+BaBKy7 l/+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@juliacomputing-com.20150623.gappssmtp.com header.s=20150623 header.b=qTZRxyhU; 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 z23si939154oih.275.2020.04.07.10.56.59; Tue, 07 Apr 2020 10:57:14 -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=@juliacomputing-com.20150623.gappssmtp.com header.s=20150623 header.b=qTZRxyhU; 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 S1726421AbgDGR4S (ORCPT + 99 others); Tue, 7 Apr 2020 13:56:18 -0400 Received: from mail-il1-f195.google.com ([209.85.166.195]:40435 "EHLO mail-il1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726277AbgDGR4S (ORCPT ); Tue, 7 Apr 2020 13:56:18 -0400 Received: by mail-il1-f195.google.com with SMTP id j9so4114237ilr.7 for ; Tue, 07 Apr 2020 10:56:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=juliacomputing-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=hvJ5mj6gXn9DT9sfAhJ2ChcXw2JKTkzR1Wi3heZ02Ig=; b=qTZRxyhUBvB8r8DzHaWWJ9MSkCYfWnA/YinvGgDEnyptSg0zjB0/eCP2yHOV2WjPXa 3zcyfee9oNK+lHnTa6A3PHTDDz622tb9gN7uO/wJX3PdQ1wvuhq194yRokWbyMys6zAK 30jTu88B+/XQA7bnfLiRVfk2XJkQqKk+3eRkfQ5U/EyXBJSQ6JMlVIrCvR84HRzfIWF5 /zxuXnctRaRDBUaAcJKvzCmKtb91dDR2wuGS6k9Y6Ege0ucIHqUmqDskDjVLmsA7NoHu Zh4c+JRkLlSCrKkbHG6wGo7tmH27RgIzta7u2Jl33xGUzLHsUewKCZbRrYWQavGaSoKG 5p5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=hvJ5mj6gXn9DT9sfAhJ2ChcXw2JKTkzR1Wi3heZ02Ig=; b=FRVfsRJnetgClBkIgfaGJa36XEwvwYdhhzTStvG5WxizrAjqgmKkvd8kXmt7+6w9JU H0sRyjBpcDatjHu+IlsWBuvOJfBR0LQqx94FSGdL+Saqng7/nfx6ZFlA2EKDLqBfraJv Ev4A+glHczqwNexWsLsK6OlsUO04mQwTG60ZuX0VwZV6ZdaBJlrteajNz11DcmeVSrh4 2/OIzuE60Ojo493hteZoTqJoqzNHBXyE0ieBsst7ja7EZDA3ilHQr/YXeBkIY0voO2yI Q12mZxdUmkq0mbxcYvJ03jleWyzOvl1jqMitENPKmKVcAIvmTqwe/ZcWhIC9Hrqm0XPb usqA== X-Gm-Message-State: AGi0PuYzPrzU8PwYWsRT6uycvTwZUfMARyCy0Zk5EKDtNCS1T7EnJV3K ARNsv8oCOtKLa+29PJwsZwTm50jdvLps9uMoVu8pNg== X-Received: by 2002:a92:d11:: with SMTP id 17mr3753627iln.145.1586282177536; Tue, 07 Apr 2020 10:56:17 -0700 (PDT) MIME-Version: 1.0 References: <20200407011259.GA72735@juliacomputing.com> <8f95e8b4-415f-1652-bb02-0a7c631c72ac@intel.com> <5208ad1e-cd9b-d57e-15b0-0ca935fccacd@intel.com> In-Reply-To: <5208ad1e-cd9b-d57e-15b0-0ca935fccacd@intel.com> From: Keno Fischer Date: Tue, 7 Apr 2020 13:55:40 -0400 Message-ID: Subject: Re: [RFC PATCH v2] x86/arch_prctl: Add ARCH_SET_XCR0 to set XCR0 per-thread To: Dave Hansen Cc: Linux Kernel Mailing List , Thomas Gleixner , Ingo Molnar , "maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)" , "H. Peter Anvin" , Borislav Petkov , Dave Hansen , Andi Kleen , Kyle Huey , "Robert O'Callahan" 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, Apr 7, 2020 at 12:27 PM Dave Hansen wrote: > > >> How does this work with things like xstateregs_[gs]et() where the format > >> of the kernel buffer and thus the kernel XCR0 is exposed as part of our > >> ABI? With this patch, wouldn't a debugger app see a state buffer that > >> looks invalid? > > > > Since those operate on the in-kernel buffer of these, which > > in this patch always uses the unmodified XCR0, ptracers > > should not observe a difference. > > Those operate on *BOTH* kernel and userspace buffers. They copy between > them. That's kinda the point. :) Right, what I meant was that in this patch the kernel level xsaves that populates the struct fpu always runs with an unmodified XCR0, so the contents of the xsave area in struct fpu does not change layout (this is the major change in this patch over v1). Are you referring to a ptracer which runs with a modified XCR0, and assumes that the value it gets back from ptrace will have an XSTATE_BV equal to its own observed XCR0 and thus get confused about the layout of the buffer (or potentially have not copied all of the relevant xstate because it calculated a wrong buffer size)? If so, I think that's just a buggy ptracer. The kernel's xfeature mask is available via ptrace and a well-behaved ptracer should use that (e.g. gdb does, though it looks like it then also assumes that the xstate has no holes, so it potentially gets the layout wrong anyway). In general, I don't really want the modified XCR0 to affect anything other than the particular instructions that depend on it and maybe the signal frame (though as I said before, I'm open to either here). If I misunderstood what you were trying to say, I apologize. > I suspect the patch thus far is only the tip of the iceberg. I'd really > suggest doing some more thorough audits of all of the locations in the > kernel that touch the fpu buffer *or* that call XSAVE/XRSTOR. I'm > pretty sure that audit hasn't been done or the ptrace example would have > been found already. Yes, good idea. I will do this again. That said, I'm hoping that the general principle to use the kernel layout, except perhaps in the signal frame will hold and thus not require modification. > But, it's also not my daily go-to for debugging. Luckily rr is fast enough (after much work) that there's almost never a reason not to use it. Our developers essentially use it exclusively (rather than raw gdb), and our users send us rr traces as bug reports. It's basically become our one-stop-shop for all things debugging on Linux.