Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp222052ybz; Wed, 15 Apr 2020 07:34:20 -0700 (PDT) X-Google-Smtp-Source: APiQypI97+Fi6+RWPsnPGZ6z1bCAaEI6GphresRCWghIGcMEUQ4TgPDP+cQnDH1DrkWF3J8JzA7J X-Received: by 2002:a17:906:7486:: with SMTP id e6mr5477210ejl.181.1586961260086; Wed, 15 Apr 2020 07:34:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586961260; cv=none; d=google.com; s=arc-20160816; b=E8ub9SWPLKVTO6GhmNdgv+kjsTGdDUikSX8SCPaFa1d6lAPzn83OanoipHn2eawl6D 4HfjCN/R52znMeHf5KnAi7KvAetVgQJ+sPQB5Ur47zG/jLzasW3InCLT2HYsQ8ewe8zc G/Zk2zVhcdlN5k4yMlzpv2rVveLOKY9RMi18bouQ6fkbubCLOkJkAFE1wQ18o2JnNhIE MZbJkj0UyVv1pbdLEMBg+m79dle6vJ2IIfAgrul9NNOt/i+p8IuH8UfglixTq6QyqMaa 4FEMJ2LA8gItR6NJ/KJ+0SpX8c/GJSWb+uxwJv9AClZNoc8Ua7U5sk88QSj8URdE+VKp Nwwg== 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:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=gJS2Wn4UZRNCVZz9CDUXltZvgsCGxfVi/3j2NMti6jM=; b=Ukmj3BrkYYMaVXXMBNwe0cJCHtlJouHKT1qacAPYGP4cJ515wzsZAtPQrTJuvZBYY2 T74PUL1cuUoHLWcFw94ARJ1o6qVLVMUtAehs6auW6OpcCPVdkiWrNvSNvWQhOlq3n5oE qJZZ51HUsYlT5oz11vQVBq3K27mDrWJzPeSuW03E2XXCrL/z3DdR6dzmSu+LhXoWhfLB hk9Dvxmc3gQT6GbexBP3Y9ZTN0VkOTQgKUGAsyznShJkQXS2WMj72qBxxju1xCMZNNO1 IdnFGkp6QQKblc3FHhurOkfdawe+wBT8fNl89PdCe9+PSh6Rxl5jqUjlAHzzwtNhkaCm xYKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=GLsNtWv6; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id o4si11606020edz.151.2020.04.15.07.33.38; Wed, 15 Apr 2020 07:34:20 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=GLsNtWv6; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S2392113AbgDNXUq (ORCPT + 99 others); Tue, 14 Apr 2020 19:20:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:58458 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731159AbgDNXU1 (ORCPT ); Tue, 14 Apr 2020 19:20:27 -0400 Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.53]) (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 3EC142084D for ; Tue, 14 Apr 2020 23:20:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1586906427; bh=ZOpLQhnRd08sOnvMFaa91+VED600Lo361J+I/x4HT/U=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=GLsNtWv62Q2xFLHzli9xxQrcjowu/vSVQ47ptlXB7uRq2TkuSj8zc+g3vDTitOlCr Rl1DcfgjJN7XfdwTiXf+v9/l+HiBK62qm0MrTquyEuoTahuaEE2QjflboRa6E2ypb4 WfJJnA6yBzhCuMOcyop8FjQoAtNKwqL16/YNGxc4= Received: by mail-wr1-f53.google.com with SMTP id u13so16136047wrp.3 for ; Tue, 14 Apr 2020 16:20:27 -0700 (PDT) X-Gm-Message-State: AGi0PuaiWzunaK7muriCAFyHPqWT0eIjYGC4/ZL8f/vLpQGj3+XZKdr/ L6rqKxXgRX0k/UeK06noMvlvafCZG9g6BHpCtLbQaw== X-Received: by 2002:adf:bc05:: with SMTP id s5mr25696906wrg.70.1586906425665; Tue, 14 Apr 2020 16:20:25 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Andy Lutomirski Date: Tue, 14 Apr 2020 16:20:14 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [RFC PATCH v2] x86/arch_prctl: Add ARCH_SET_XCR0 to set XCR0 per-thread To: Keno Fischer Cc: Dave Hansen , Peter Zijlstra , 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" Content-Transfer-Encoding: quoted-printable 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 11:30 AM Keno Fischer wrot= e: > > > TSX! > > Yes, it's problematic, but luckily turns out to > be ok in practice if masked off in cpuid. > > > I think rr should give the raw KVM API at least a try. It should be po= ssible to fire up a vCPU in CPL3 in the correct state. No guest kernel req= uired. I don=E2=80=99t know if there will be issues with the perf API, tho= ugh. > > Yes, I've looked into it, but stopped short of doing a > complete implementation. Using KVM to solve it > for replay would probably be feasible with a moderate > amount of engineering work, since rr does very few > syscalls during replay. I'm a bit afraid of the > performance implications, but I don't have numbers on this. > > Record and diversions are a lot harder though, because > in this mode the tracee is a live process and able to do > syscalls (and needs to receive signals and all that good > stuff associated with being a real process). For diversions, > performance isn't super important, so we could probably > emulate this, but for record, performance is quite critical. > I assume it would be possible to add a feature to KVM > where it forwards syscalls made in guest CPL3 to the real > kernel without round-trip through userspace, but I'm just > seeing myself back here asking > for a weird KVM feature that nobody but me wants ;) > (well almost nobody, as I mentioned, there's an > academic project that tried this with a custom kernel > plugin - http://dune.scs.stanford.edu/). > > Admittedly, the use case for this feature during record is > less pressing, since in our (operational) case > the replay machines tend to be much newer than > the record machines, but I wouldn't be surprised if I got > bit by this as soon as the next user xstate component gets > added and users start sending me those kinds of traces, > even if we mask off the feature in CPUID (which rr already > supports for record for similar reasons). I'm imagining that rr would do record the usual way with normal XCR0 (why would you want to record with an unusual XCR0?) and replay would use KVM. I'm not sure about diversions. This way KVM wouldn't need to deal with syscalls. Would this work?