Received: by 2002:ac2:464d:0:0:0:0:0 with SMTP id s13csp3261405lfo; Mon, 23 May 2022 00:14:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxkeAO6OA8VHdl9t1oHm/diGnqEjfPd/Fv0w0L1vOPhrgivCT6pdXnX9jNUOe/ZpJ1RRznf X-Received: by 2002:a17:902:d64d:b0:162:3595:220c with SMTP id y13-20020a170902d64d00b001623595220cmr66937plh.10.1653290066867; Mon, 23 May 2022 00:14:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653290066; cv=none; d=google.com; s=arc-20160816; b=mmQhB079kDkOvjdYiEvzFJGqZ4C/ien+boS+wKlJVgMG9AkCkRbSmWhGerWIfzMMCh c7AiCYCXrEIQrYSa2RbnI5CoFvetdzGXkMDcjZPkvhctHosNOdtafRRx7GuDpksgbU5J +iMFQwFHsE950+vkMlThK4Y/DCLmJ+4viJlOJu+aJ2B6oFAS4LPiHTPT1U+MsTwnYtx1 Q8Doq//QJpd2MMnhIzFamK/abP07vCDrdd5AvYdczudwaJ1vgcL9V590bgnZ/jDBO4XH nXbo8gnnlqFf3JVkbkNS2N+6oUSzsf/or1K6yxvj4Gg6skpXaVgbk8mgU51u1Tv+FFzg y/zw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:subject:cc:to:from:message-id :date:dkim-signature; bh=fqDXjJb0+Kh9F21dXRLtUEm/05v8CnZ63msCnuXqJ5Q=; b=L/7hHD5iqe8ELHMpJBmLSnC86LF2rHdvbzKgN3VCZym0TNIHqR2wii0v7H+TVeXPJi 5ZGIboIQyxL1aSVeOn6cT2g2C0cVAQEs2ySUxOyzQJXV7gY1x63qjJu0a7+p/hUPhOoJ QOq806/pmxeuF4FnCMSEj/HSxPhugTr9hSfjN/7XcvJfzfqGtIXAGlqMU4zVZe+kX0gr bEsVi7rkttIkzpstRQA/vevC8InTcUL3x4PF16MqdfUBHs+7mKpmZNbtiXXwo4IPnRVa 625Fz9tuhQYY8krcuc+X3qp6SnQ5OBaD8Fea4kMsJ+Uu9q2kDQMlWLACmJ7xLxSpcEmO w/RQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=pdjkKNJp; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id a16-20020a63cd50000000b003c5ea42d972si10066427pgj.168.2022.05.23.00.14.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 May 2022 00:14:26 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=pdjkKNJp; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 55C0C7C171; Sun, 22 May 2022 23:32:48 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348094AbiEVPfu (ORCPT + 99 others); Sun, 22 May 2022 11:35:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33146 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241366AbiEVPfs (ORCPT ); Sun, 22 May 2022 11:35:48 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 773F639164 for ; Sun, 22 May 2022 08:35:46 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 14CB460FEB for ; Sun, 22 May 2022 15:35:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 712FDC385AA; Sun, 22 May 2022 15:35:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1653233745; bh=Ni6fjoGMdQzbQmZpLoAHQFcIXLw4p5hqcCJJSrIedEw=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=pdjkKNJpUux7FDHj3pAlVI8Su/CRzMtqOihjp6TXsFhRzMS1+TsROlMXw5Ibh/w2J fg4V2aoORBmfWJumujotUYxbAovyL9q/+r3vHk0oEXoLbD0rX866pSTc59ufmIegkO gZiIFLgvD/Jm/FzEToUSe1Z5guBbx4S0upkXpOAL7DsLHM///1vCwxUMyIDidlityq s0DBG4rXrXcvCayRLwNlCB5M9d0rf7Xzdu33YBi8Y8o7tUG9WUrZAVwmbClQsoDGos 9I0ANxrZHrkSf6yhTOxXVzfmFh+NC5qblIIdTaRVAxFnrs8wnYxa4y9JvdR/u82R7Q diJEurUswCyRQ== Received: from ppp-94-66-34-157.home.otenet.gr ([94.66.34.157] helo=wait-a-minute.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1nsncM-00D06N-UA; Sun, 22 May 2022 16:35:43 +0100 Date: Sun, 22 May 2022 16:35:40 +0100 Message-ID: <87ilpxmvg3.wl-maz@kernel.org> From: Marc Zyngier To: Kyle Huey Cc: open list , "moderated list:ARM PORT" , "maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)" , yyc1992@gmail.com, Keno Fischer , "Robert O'Callahan" , Thomas Gleixner , Borislav Petkov , Suzuki K Poulose , Will Deacon Subject: Re: arm64 equivalents of PR_SET_TSC/ARCH_SET_CPUID In-Reply-To: References: User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/27.1 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable X-SA-Exim-Connect-IP: 94.66.34.157 X-SA-Exim-Rcpt-To: me@kylehuey.com, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, x86@kernel.org, yyc1992@gmail.com, keno@juliacomputing.com, robert@ocallahan.org, tglx@linutronix.de, bp@alien8.de, suzuki.poulose@arm.com, will.deacon@arm.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, 21 May 2022 21:07:14 +0100, Kyle Huey wrote: >=20 > There is ongoing work by Yichao Yu to make rr, a userspace record and > replay debugger[0], production quality on arm64[1]. One of the bigger > remaining issues is the kernel's emulation of accesses to certain > system registers[2] that reflect timing and CPU capabilities and are > either non-deterministic or can vary from processor to processor. Just to make things clear: the kernel usually doesn't provide any emulation for registers such as CNTVCT_EL0. On sane HW, userspace is free to access it directly without any mediation (we only use the trap for the sake of dealing with HW bugs). > We > would like to add the ability to tell the kernel to decline to emulate > these instructions for a given task and pass that responsibility onto > the supervising rr ptracer. There are analogous processor features and > disabling mechanisms on x86. The RDTSC instruction is controlled by > prctl(PR_SET_TSC) and the CPUID instruction is controlled (when the > hardware allows) by arch_prctl(ARCH_SET_CPUID). >=20 > The questions I'd like to raise are: >=20 > 1. Is it appropriate to reuse PR_SET_TSC for roughly equivalent > functionality on AArch64? (even if the AArch64 feature is not actually > named Time Stamp Counter). My gut feeling is that you really don't want to hijack an existing API, because this is fundamentally different. The Linux arm64 ABI mandates that the counter (and the frequency register associated with it) are accessible, and you can't make them disappear. =46rom what I understand, you are relying on the TSC being disabled in the tracee and intercepting the signal that gets delivered when it accesses the counter. Is that correct? Assuming I'm right, I think it'd make a lot more sense if there was a first class ptrace option, if only because this would mandate the kernel to start trapping things that are not trapped today. It also begs the question of the fate of CNTFRQ_EL0, since you want to be able to replay traces from one system to another (and the counter is meaningless without the frequency). Finally, what of the VDSO, which is by far the most common user of the counter? I can totally imagine the VDSO getting stuck if emulation is used and the sequence counter moves synchronously with the traps (which is why we disable the VDSO when trapping CNTVCT_EL0). > 2. Likewise for ARCH_SET_CPUID We don't just emulate a single register, but a whole class of them. If you are to present a different view for any of those, you'll need to handle the lot (I really can't see why one would be more important than the others). So SET_CPUID really is the wrong tool. I'd rather there was (again) an API that described exactly that. > 3. Since arch_prctl is x86-only, does it make more sense to add > arch_prctl to arm64 or to duplicate ARCH_SET_CPUID into the prctl > world? (e.g. a PR_SET_CPUID that works on both x86/arm64) I don't think any applies here. Different architectures have different ABI requirements, and you can't really merge the two. Because the next thing you know, you'll ask for the same thing for PMU registers, and try to map them onto something else. Overall, this would be better served by a framework for userspace delegation of sysreg access by a ptrace'd process. Let's try to look at it in those terms rather than casting arm64 into a seemingly unrelated API. Thanks, M. >=20 > - Kyle >=20 > [0] https://rr-project.org/ > [1] https://github.com/rr-debugger/rr/issues/3234 > [2] e.g. CNTVCT_EL0 and MIDR_EL1, among others >=20 --=20 Without deviation from the norm, progress is not possible.