From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 83894C433F5 for ; Wed, 27 Oct 2021 11:26:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 568F4610A4 for ; Wed, 27 Oct 2021 11:26:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232566AbhJ0L3B (ORCPT ); Wed, 27 Oct 2021 07:29:01 -0400 Received: from mail.kernel.org ([198.145.29.99]:49394 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229869AbhJ0L3B (ORCPT ); Wed, 27 Oct 2021 07:29:01 -0400 Received: from disco-boy.misterjones.org (disco-boy.misterjones.org [51.254.78.96]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 00B8D60E73; Wed, 27 Oct 2021 11:26:36 +0000 (UTC) Received: from sofa.misterjones.org ([185.219.108.64] helo=why.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 1mfh4j-001tTL-SX; Wed, 27 Oct 2021 12:26:34 +0100 Date: Wed, 27 Oct 2021 12:26:33 +0100 Message-ID: <8735ombtee.wl-maz@kernel.org> From: Marc Zyngier To: Mark Brown Cc: kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, James Morse , Suzuki K Poulose , Alexandru Elisei , Quentin Perret , Will Deacon , kernel-team@android.com Subject: Re: [PATCH 4/4] arm64/fpsimd: Document the use of TIF_FOREIGN_FPSTATE by KVM In-Reply-To: References: <20211021151124.3098113-1-maz@kernel.org> <20211021151124.3098113-5-maz@kernel.org> 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 X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: broonie@kernel.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, james.morse@arm.com, suzuki.poulose@arm.com, alexandru.elisei@arm.com, qperret@google.com, will@kernel.org, kernel-team@android.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org On Thu, 21 Oct 2021 16:57:15 +0100, Mark Brown wrote: > > [1 ] > On Thu, Oct 21, 2021 at 04:11:24PM +0100, Marc Zyngier wrote: > > The bit of documentation that talks about TIF_FOREIGN_FPSTATE > > does not mention the ungodly tricks that KVM plays with this flag. > > > > Try and document this for the posterity. > > Yes, more documentation here would definitely be helpful - it's pretty > hard to follow what KVM is doing here. > > > * CPU currently contain the most recent userland FPSIMD state of the current > > - * task. > > + * task *or* the state of the corresponding KVM vcpu if userspace is behaving > > + * as a VMM and that the vcpu has used FP during its last run. In the latter > > + * case, KVM will set TIF_FOREIGN_FPSTATE on kvm_vcpu_put(). For all intents > > + * and purposes, the vcpu FP state is treated identically to userspace's. > > I'm not able to find a kvm_vcpu_put() function in upstream, just > kvm_cpu_put_sysregs_vhe(). There's kvm_arch_vcpu_put() which is called > from the vcpu_put() function in generic KVM code but they don't show up > until you start mangling the name in that comment. You, vcpu_put() is the one I had in mind. > It'd be good to > mention what vcpu_put() is actually doing and a bit more about the > general model, KVM is behaving differently here AFAICT in that it flags > the current state as invalid when it saves the context to memory rather > than when an event happens that requires that the context be reloaded. > There's no problem there but it's a bit surprising due the difference > and worth highlighting. There is a bit more to it: KVM flags the userspace state as invalid, but also ties the guest state to the current task via fpsimd_bind_state_to_cpu() so that the state can be saved on vcpu_put() via fpsimd_save_and_flush_cpu_state(), or if we end-up running kernel_neon_begin() because of some softirq handling. > I think I'd also be inclined to restructure this to foreground the fact > that it's the state of the current task but that task may be a VMM. So > something more like > > ...contain the most recent FPSIMD state of the current userspace > task. If the task is behaving as a VMM then this will be > managed by KVM which will... > > making it a bit easier to follow (assuming my understanding of what's > going on is correct, if not then I guess something else needs > clarifying!). I'll have a go at rewriting this. M. -- Without deviation from the norm, progress is not possible. From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 424B0C433F5 for ; Wed, 27 Oct 2021 11:26:44 +0000 (UTC) Received: from mm01.cs.columbia.edu (mm01.cs.columbia.edu [128.59.11.253]) by mail.kernel.org (Postfix) with ESMTP id B19E66109E for ; Wed, 27 Oct 2021 11:26:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org B19E66109E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.cs.columbia.edu Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 39B524B105; Wed, 27 Oct 2021 07:26:43 -0400 (EDT) X-Virus-Scanned: at lists.cs.columbia.edu Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 1BRaj3eHUPOW; Wed, 27 Oct 2021 07:26:40 -0400 (EDT) Received: from mm01.cs.columbia.edu (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 878FF4B153; Wed, 27 Oct 2021 07:26:40 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 45A864A5A0 for ; Wed, 27 Oct 2021 07:26:39 -0400 (EDT) X-Virus-Scanned: at lists.cs.columbia.edu Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id z3heBoWfsri1 for ; Wed, 27 Oct 2021 07:26:38 -0400 (EDT) Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by mm01.cs.columbia.edu (Postfix) with ESMTPS id CD4A74A534 for ; Wed, 27 Oct 2021 07:26:37 -0400 (EDT) Received: from disco-boy.misterjones.org (disco-boy.misterjones.org [51.254.78.96]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 00B8D60E73; Wed, 27 Oct 2021 11:26:36 +0000 (UTC) Received: from sofa.misterjones.org ([185.219.108.64] helo=why.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 1mfh4j-001tTL-SX; Wed, 27 Oct 2021 12:26:34 +0100 Date: Wed, 27 Oct 2021 12:26:33 +0100 Message-ID: <8735ombtee.wl-maz@kernel.org> From: Marc Zyngier To: Mark Brown Subject: Re: [PATCH 4/4] arm64/fpsimd: Document the use of TIF_FOREIGN_FPSTATE by KVM In-Reply-To: References: <20211021151124.3098113-1-maz@kernel.org> <20211021151124.3098113-5-maz@kernel.org> 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") X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: broonie@kernel.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, james.morse@arm.com, suzuki.poulose@arm.com, alexandru.elisei@arm.com, qperret@google.com, will@kernel.org, kernel-team@android.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Cc: kernel-team@android.com, kvm@vger.kernel.org, Will Deacon , kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org X-BeenThere: kvmarm@lists.cs.columbia.edu X-Mailman-Version: 2.1.14 Precedence: list List-Id: Where KVM/ARM decisions are made List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: kvmarm-bounces@lists.cs.columbia.edu Sender: kvmarm-bounces@lists.cs.columbia.edu On Thu, 21 Oct 2021 16:57:15 +0100, Mark Brown wrote: > > [1 ] > On Thu, Oct 21, 2021 at 04:11:24PM +0100, Marc Zyngier wrote: > > The bit of documentation that talks about TIF_FOREIGN_FPSTATE > > does not mention the ungodly tricks that KVM plays with this flag. > > > > Try and document this for the posterity. > > Yes, more documentation here would definitely be helpful - it's pretty > hard to follow what KVM is doing here. > > > * CPU currently contain the most recent userland FPSIMD state of the current > > - * task. > > + * task *or* the state of the corresponding KVM vcpu if userspace is behaving > > + * as a VMM and that the vcpu has used FP during its last run. In the latter > > + * case, KVM will set TIF_FOREIGN_FPSTATE on kvm_vcpu_put(). For all intents > > + * and purposes, the vcpu FP state is treated identically to userspace's. > > I'm not able to find a kvm_vcpu_put() function in upstream, just > kvm_cpu_put_sysregs_vhe(). There's kvm_arch_vcpu_put() which is called > from the vcpu_put() function in generic KVM code but they don't show up > until you start mangling the name in that comment. You, vcpu_put() is the one I had in mind. > It'd be good to > mention what vcpu_put() is actually doing and a bit more about the > general model, KVM is behaving differently here AFAICT in that it flags > the current state as invalid when it saves the context to memory rather > than when an event happens that requires that the context be reloaded. > There's no problem there but it's a bit surprising due the difference > and worth highlighting. There is a bit more to it: KVM flags the userspace state as invalid, but also ties the guest state to the current task via fpsimd_bind_state_to_cpu() so that the state can be saved on vcpu_put() via fpsimd_save_and_flush_cpu_state(), or if we end-up running kernel_neon_begin() because of some softirq handling. > I think I'd also be inclined to restructure this to foreground the fact > that it's the state of the current task but that task may be a VMM. So > something more like > > ...contain the most recent FPSIMD state of the current userspace > task. If the task is behaving as a VMM then this will be > managed by KVM which will... > > making it a bit easier to follow (assuming my understanding of what's > going on is correct, if not then I guess something else needs > clarifying!). I'll have a go at rewriting this. M. -- Without deviation from the norm, progress is not possible. _______________________________________________ kvmarm mailing list kvmarm@lists.cs.columbia.edu https://lists.cs.columbia.edu/mailman/listinfo/kvmarm From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F2DEBC433F5 for ; Wed, 27 Oct 2021 11:28:01 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id BF55860E76 for ; Wed, 27 Oct 2021 11:28:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org BF55860E76 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Subject:Cc:To:From:Message-ID:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=uHebG2HQ1XSRPWqqTOfL3V8CCFKP+mqjFGJsSze5AT4=; b=11shBpXZBekCtY mFT83HhcVcH5GDso+kbx9YM8cm8IfUgJjqco8lRCFro6qWp/UK2pQiTHVoh8lJSoIPzsO9KGUahhH Jk3tJ2+6e6u1AbIDU4cQ9sb7DZTeQCznr1YSCVjsJDmgmJadMYWD1CfFU0jAbNgZ3UNfnEB7HR81z krG90gkfrAkturew1nRP3aZfJRAlJetkZvis737W6sYlZN0Ecwdm8Q0D95LHCZSgB2V7lE7YzpbXa 9RB27WdKwsmPby4T57btE65shXC1iI9sAuk07u1JNDbZvttTnPxnuT38RSCzhMoYsrwz9g2eck6jo bztwfFCKtky3THYjHMEQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mfh4q-004hom-9K; Wed, 27 Oct 2021 11:26:40 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mfh4m-004hoH-ET for linux-arm-kernel@lists.infradead.org; Wed, 27 Oct 2021 11:26:37 +0000 Received: from disco-boy.misterjones.org (disco-boy.misterjones.org [51.254.78.96]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 00B8D60E73; Wed, 27 Oct 2021 11:26:36 +0000 (UTC) Received: from sofa.misterjones.org ([185.219.108.64] helo=why.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 1mfh4j-001tTL-SX; Wed, 27 Oct 2021 12:26:34 +0100 Date: Wed, 27 Oct 2021 12:26:33 +0100 Message-ID: <8735ombtee.wl-maz@kernel.org> From: Marc Zyngier To: Mark Brown Cc: kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, James Morse , Suzuki K Poulose , Alexandru Elisei , Quentin Perret , Will Deacon , kernel-team@android.com Subject: Re: [PATCH 4/4] arm64/fpsimd: Document the use of TIF_FOREIGN_FPSTATE by KVM In-Reply-To: References: <20211021151124.3098113-1-maz@kernel.org> <20211021151124.3098113-5-maz@kernel.org> 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") X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: broonie@kernel.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, james.morse@arm.com, suzuki.poulose@arm.com, alexandru.elisei@arm.com, qperret@google.com, will@kernel.org, kernel-team@android.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211027_042636_553555_71FBE5AE X-CRM114-Status: GOOD ( 35.81 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Thu, 21 Oct 2021 16:57:15 +0100, Mark Brown wrote: > > [1 ] > On Thu, Oct 21, 2021 at 04:11:24PM +0100, Marc Zyngier wrote: > > The bit of documentation that talks about TIF_FOREIGN_FPSTATE > > does not mention the ungodly tricks that KVM plays with this flag. > > > > Try and document this for the posterity. > > Yes, more documentation here would definitely be helpful - it's pretty > hard to follow what KVM is doing here. > > > * CPU currently contain the most recent userland FPSIMD state of the current > > - * task. > > + * task *or* the state of the corresponding KVM vcpu if userspace is behaving > > + * as a VMM and that the vcpu has used FP during its last run. In the latter > > + * case, KVM will set TIF_FOREIGN_FPSTATE on kvm_vcpu_put(). For all intents > > + * and purposes, the vcpu FP state is treated identically to userspace's. > > I'm not able to find a kvm_vcpu_put() function in upstream, just > kvm_cpu_put_sysregs_vhe(). There's kvm_arch_vcpu_put() which is called > from the vcpu_put() function in generic KVM code but they don't show up > until you start mangling the name in that comment. You, vcpu_put() is the one I had in mind. > It'd be good to > mention what vcpu_put() is actually doing and a bit more about the > general model, KVM is behaving differently here AFAICT in that it flags > the current state as invalid when it saves the context to memory rather > than when an event happens that requires that the context be reloaded. > There's no problem there but it's a bit surprising due the difference > and worth highlighting. There is a bit more to it: KVM flags the userspace state as invalid, but also ties the guest state to the current task via fpsimd_bind_state_to_cpu() so that the state can be saved on vcpu_put() via fpsimd_save_and_flush_cpu_state(), or if we end-up running kernel_neon_begin() because of some softirq handling. > I think I'd also be inclined to restructure this to foreground the fact > that it's the state of the current task but that task may be a VMM. So > something more like > > ...contain the most recent FPSIMD state of the current userspace > task. If the task is behaving as a VMM then this will be > managed by KVM which will... > > making it a bit easier to follow (assuming my understanding of what's > going on is correct, if not then I guess something else needs > clarifying!). I'll have a go at rewriting this. M. -- Without deviation from the norm, progress is not possible. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel