Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp4334766ybb; Tue, 7 Apr 2020 05:35:06 -0700 (PDT) X-Google-Smtp-Source: APiQypKbbh7nT+XRNRaMkTTVc+n3H6qq+dxIZrVnqyotzQrgR9z4rsyI+rioJQy1YX3i4Agfrhwd X-Received: by 2002:aca:4e47:: with SMTP id c68mr1528970oib.16.1586262905976; Tue, 07 Apr 2020 05:35:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586262905; cv=none; d=google.com; s=arc-20160816; b=H4h+PNl8GPKfhefX4xpmXgYm/Kr1b1KpuNPIkbUAvIzchchPZAg7IDcexh3nEqhwAD afrT6Dg+UHWoGDzUxhc8DHXtkTrDyWY3MFCEhwox7lH6YplNckvMkSGvxMEKgPfTWP0K yJSNj1sqYTynBGtdtvQ2JTJ6qFm/zrSRg4w6aMmJtrDWJaeH+QaGjCo4S8Kd9SGIlORJ 07j8CqQ6oeJ8PLB2GAuQ8nGEhjgK3bjlKdEqu5neaFyXi1kzq1bd0tOvFativUN50VSj fUmYu9qldfUdA2gkvhPDvoMJg+/jtQ1GQwpHT4caE1F0R5aknl2J+8P8kYPDduD0ZfBE +lig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=riSm6OQQkxYGmZsCsCgLPBnh+Vw6HfHvJMjb39H1oCI=; b=qlc1PNLjANYoUy/wXts8rhSlc0myU0QOuvrhmpKXV1Nffj+iYRdK00vsBbCQA1NUJV /1L5sAGTufKfxXYsiSfvMlEsQuTMvtOpXijtMl6+WLVBwlk+4HrSsP6WFb1afmt23pgV gKDt348kolkU2rG4zgvHzRt7fiU+6LLwQZ2751ZvLugzXVB3SC9ov8o08+/cML8gShw4 /BQfkADjtsuLrGa4nUfKBj69800WTX0ZPPeLLk8JsUvoorlkbCtE5JsAIXguKLw17ykx lsBFZlGXNycUpuPf5KasIFKBIt0mZ/3HJrpc0oBQcwZECya6qV8c4+cp6EyvxL5uNsUE U+0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=eEx66aTR; 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 j1si579327oiw.205.2020.04.07.05.34.54; Tue, 07 Apr 2020 05:35: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=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=eEx66aTR; 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 S1728696AbgDGMeA (ORCPT + 99 others); Tue, 7 Apr 2020 08:34:00 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:59962 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728152AbgDGMeA (ORCPT ); Tue, 7 Apr 2020 08:34:00 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Transfer-Encoding :Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: Sender:Reply-To:Content-ID:Content-Description; bh=riSm6OQQkxYGmZsCsCgLPBnh+Vw6HfHvJMjb39H1oCI=; b=eEx66aTRxbCtW82gVL8Fg6OgoT zuCCgwzeKDkpJD4uQkBXnWb41/+7CkwmIdmJNbVaEWHfqU7Ebpl8vr21hM3oMZatFeUwMgntd8Cmf /k3nRtlLkr3jWVG+XMo2/5GjS50F7ooMGUSf3W/pl5bjirWSK/M1BMBG7uypXgV0On6x068Kza0k2 /z3hgtBLS40Pdyf3oq3lMApJlxM/vltY/P0mUyu9WKPFt8Z/S1jpzeT4+ghBIs27Foqjrthh+qItB DvsduGzFNNBKUOZmOEa4N/1B9cWEatzIgap9ZjEMN695xceJbm1N450abi43436fWV3u34BBT/4hP jVe0jBmw==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jLnQN-0004HC-0T; Tue, 07 Apr 2020 12:33:51 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 9FD11304D58; Tue, 7 Apr 2020 14:33:48 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 86B4D2B907A8B; Tue, 7 Apr 2020 14:33:48 +0200 (CEST) Date: Tue, 7 Apr 2020 14:33:48 +0200 From: Peter Zijlstra To: Kyle Huey Cc: Keno Fischer , Andy Lutomirski , 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 Subject: Re: [RFC PATCH v2] x86/arch_prctl: Add ARCH_SET_XCR0 to set XCR0 per-thread Message-ID: <20200407123348.GV20730@hirez.programming.kicks-ass.net> References: <20200407011259.GA72735@juliacomputing.com> <2A931F48-D28F-46F3-827F-FF7F4D5D3E66@amacapital.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Apr 06, 2020 at 09:53:40PM -0700, Kyle Huey wrote: > On Mon, Apr 6, 2020 at 9:45 PM Keno Fischer wrote: > > > > On Mon, Apr 6, 2020 at 11:58 PM Andy Lutomirski wrote: > > > > > > > > > > On Apr 6, 2020, at 6:13 PM, Keno Fischer wrote: > > > > > > > > This is a follow-up to my from two-years ago [1]. > > > > > > Your changelog is missing an explanation of why this is useful. Why would a user program want to change XCR0? > > > > Ah, sorry - I wasn't sure what the convention was around repeating the > > applicable parts from the v1 changelog in this email. > > Here's the description from the v1 patch: > > > > > The rr (http://rr-project.org/) debugger provides user space > > > record-and-replay functionality by carefully controlling the process > > > environment in order to ensure completely deterministic execution > > > of recorded traces. The recently added ARCH_SET_CPUID arch_prctl > > > allows rr to move traces across (Intel) machines, by allowing cpuid > > > invocations to be reliably recorded and replayed. This works very > > > well, with one catch: It is currently not possible to replay a > > > recording from a machine supporting a smaller set of XCR0 state > > > components on one supporting a larger set. This is because the > > > value of XCR0 is observable in userspace (either by explicit > > > xgetbv or by looking at the result of xsave) and since glibc > > > does observe this value, replay divergence is almost immediate. > > > I also suspect that people interested in process (or container) > > > live-migration may eventually care about this if a migration happens > > > in between a userspace xsave and a corresponding xrstor. > > > > > > We encounter this problem quite frequently since most of our users > > > are using pre-Skylake systems (and thus don't support the AVX512 > > > state components), while we recently upgraded our main development > > > machines to Skylake. > > > > Basically, for rr to work, we need to tightly control any user-visible > > CPU behavior, > > either by putting in the CPU in the right state or by trapping and emulating > > (as we do for rdtsc, cpuid, etc). XCR0 controls a bunch of > > user-visible CPU behavior, > > namely: > > 1) The size of the xsave region if xsave is passed an all-ones mask > > (which is fairly common) > > 2) The return value of xgetbv > > It's mentioned elsewhere, but I want to emphasize that the return > value of xgetbv is the big one because the dynamic linker uses this. > rr trace portability is essentially limited to machines with identical > xcr0 values because of it. I'm thinking just exposing that value is doable in a much less objectionable fashion, no?