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 B2F10C433F5 for ; Mon, 18 Oct 2021 17:14:58 +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 8001C61212 for ; Mon, 18 Oct 2021 17:14:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 8001C61212 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-Type: Content-Transfer-Encoding:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:Message-ID:References:In-Reply-To:Subject:Cc:To:From :Date:MIME-Version:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=wuomElujcOeMPmTmp9A5zkE/qd+HMHNqI3YzzcRHWj8=; b=J2gn0veom0n3yGPhrSnLHMIOSR RCKhZ5ugHWlsBuldQv6lIyM4IDlIl+Sc6PJCvGApmX7KpkwhsGbsMa/7OfOwgf4/YB1m6r9dOazE9 w+kNX6jqHjPsPOcqYtWZ4o2/jPLr9oP3IWmHOBOoVPjjj6Vn8GHvFIgHZzfbQeh1DacOogi8T5tnQ e5e5h7HBzwuUcp3UgeFc32HmymJCc69AlUjdnHaebMyBlY20MRyjFr+cmeD8Qph8hI7SHa8txx2pH WO3+nJZw8bdVfiD8yCFUVZOUpZX4W/P1EUx3ax0Wy+tb2KJBk+OOdpgNHYbdMPj/Fs2AOYaGQQnDR B2aToUTw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mcWCL-00GbCg-D8; Mon, 18 Oct 2021 17:13:17 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mcWCJ-00GbCY-DP for linux-arm-kernel@bombadil.infradead.org; Mon, 18 Oct 2021 17:13:15 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:Content-Type :Message-ID:References:In-Reply-To:Subject:Cc:To:From:Date:MIME-Version: Sender:Reply-To:Content-ID:Content-Description; bh=oawcCEQCJbb7N6KdQxD94XP8bbtos5lw+zLVw2l9sFE=; b=WW/R2uXe1VhjPjbP7Z5r/H7Wj3 to5PMvFWHFlcuVDxhuG1EUMm1O+XDHohsunl3rnLGC0bwDvMzDS8SRqj5nf296ymTAdlkVKyJ5pVu fyyJiJ1LAHX0sSxAubLYVHW3nUZ+ra8B74dPwttK3U0sOo3MrrF5ShweG5VMP4av6KY6b9xuWnV5P oD0l8Xad9ajJ3yXEuh5eSKsWvj/+edam0QTvq7LGLSEpfmrP+IRocPVdBLD8s3WaKyXaGhWgz8uJq pl4CGeb/ozl3nZm9CjLi8M7Jkq2Zvp5JNslAyPPXELhBCfvE4PUnWjv74H9mg2rdKPzFX24AKZYQ8 naJWpc8g==; Received: from mail.kernel.org ([198.145.29.99]) by desiato.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mcWCF-00AaHy-Bj for linux-arm-kernel@lists.infradead.org; Mon, 18 Oct 2021 17:13:14 +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 2DC2060F9D; Mon, 18 Oct 2021 17:12:24 +0000 (UTC) Received: from disco-boy.misterjones.org ([51.254.78.96] helo=www.loen.fr) 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 1mcWBS-0001xi-5Z; Mon, 18 Oct 2021 18:12:22 +0100 MIME-Version: 1.0 Date: Mon, 18 Oct 2021 18:12:22 +0100 From: Marc Zyngier To: Quentin Perret Cc: James Morse , Alexandru Elisei , Suzuki K Poulose , Catalin Marinas , Will Deacon , Fuad Tabba , David Brazdil , linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, kernel-team@android.com Subject: Re: [PATCH 16/16] KVM: arm64: pkvm: Unshare guest structs during teardown In-Reply-To: References: <20211013155831.943476-1-qperret@google.com> <20211013155831.943476-17-qperret@google.com> <87h7dhupfa.wl-maz@kernel.org> User-Agent: Roundcube Webmail/1.4.11 Message-ID: <3ec8ab06f9950a13818109051835fdb9@kernel.org> X-Sender: maz@kernel.org X-SA-Exim-Connect-IP: 51.254.78.96 X-SA-Exim-Rcpt-To: qperret@google.com, james.morse@arm.com, alexandru.elisei@arm.com, suzuki.poulose@arm.com, catalin.marinas@arm.com, will@kernel.org, tabba@google.com, dbrazdil@google.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.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-20211018_181312_150927_6E3D93E0 X-CRM114-Status: GOOD ( 16.98 ) 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-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 2021-10-18 15:03, Quentin Perret wrote: > On Monday 18 Oct 2021 at 11:32:13 (+0100), Quentin Perret wrote: >> Another option is to take a refcount on 'current' from >> kvm_arch_vcpu_run_map_fp() before sharing thread-specific structs with >> the hyp and release the refcount of the previous task after unsharing. >> But that means we'll have to also drop the refcount when the vcpu >> gets destroyed, as well as explicitly unshare at that point. Shouldn't >> be too bad I think. Thoughts? > > Something like the below seems to work OK on my setup, including > SIGKILL'ing the guest and such. How much do you hate it? It is annoyingly elegant! Small nitpick below. > > diff --git a/arch/arm64/include/asm/kvm_host.h > b/arch/arm64/include/asm/kvm_host.h > index f8be56d5342b..50598d704c71 100644 > --- a/arch/arm64/include/asm/kvm_host.h > +++ b/arch/arm64/include/asm/kvm_host.h > @@ -322,6 +322,7 @@ struct kvm_vcpu_arch { > > struct thread_info *host_thread_info; /* hyp VA */ > struct user_fpsimd_state *host_fpsimd_state; /* hyp VA */ > + struct task_struct *parent_task; > > struct { > /* {Break,watch}point registers */ > @@ -738,6 +739,7 @@ int kvm_arch_vcpu_run_map_fp(struct kvm_vcpu > *vcpu); > void kvm_arch_vcpu_load_fp(struct kvm_vcpu *vcpu); > void kvm_arch_vcpu_ctxsync_fp(struct kvm_vcpu *vcpu); > void kvm_arch_vcpu_put_fp(struct kvm_vcpu *vcpu); > +void kvm_vcpu_unshare_task_fp(struct kvm_vcpu *vcpu); > > static inline bool kvm_pmu_counter_deferred(struct perf_event_attr > *attr) > { > diff --git a/arch/arm64/kvm/fpsimd.c b/arch/arm64/kvm/fpsimd.c > index 2fe1128d9f3d..27afeebbe1cb 100644 > --- a/arch/arm64/kvm/fpsimd.c > +++ b/arch/arm64/kvm/fpsimd.c > @@ -15,6 +15,22 @@ > #include > #include > > +void kvm_vcpu_unshare_task_fp(struct kvm_vcpu *vcpu) > +{ > + struct task_struct *p = vcpu->arch.parent_task; > + struct user_fpsimd_state *fpsimd; > + struct thread_info *ti; > + > + if (!static_branch_likely(&kvm_protected_mode_initialized) || !p) Shouldn't this be a check on is_protected_kvm_enabled() instead? The two should be equivalent outside of the initialisation code... Otherwise, ship it. M. -- Jazz is not dead. It just smells funny... _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel