Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp3214489pxb; Mon, 18 Oct 2021 10:24:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw8wf8hNaX/Wvd29IfIf8UHUjbFvie8rF8LkYFNTk/IElXKv4jY0241eWqN4x0qUSiAf820 X-Received: by 2002:a17:902:8f90:b0:13e:a44e:2d3c with SMTP id z16-20020a1709028f9000b0013ea44e2d3cmr28576747plo.85.1634577869756; Mon, 18 Oct 2021 10:24:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634577869; cv=none; d=google.com; s=arc-20160816; b=z2tBcMTrlUXEK8EdYgXX/jRz7GKlfeA6r9XRc2+Fl4xPQulWMAMuX21ak8lVJuU3v3 w4yqjl26Tpva7/cPI5hF6xXW5Ns3xH1s0p+LYfikqkvAB6/rA8YxfrTt1hUnXHpcf7aD QxF8twwvs5xTmFxrgQBTKdbvHaB2KQn4UmAX8g9m+TjwaqscdEtY6fXACg0wL4mZc7wW Mj1Lk/sGUin42/8Fof2C/PUvMe4wfZZEA+/oGm3xq6KUQs9+R06wLbXoW+cvmEfPPMIP tyb5ex5/bLR3EbT979DZlf6rSrD2p7LkOpaomKtIrg6vHp1TvE6hb0kGMZcNzkQ3c6wR D6/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:message-id:user-agent :references:in-reply-to:subject:cc:to:from:date:mime-version; bh=oawcCEQCJbb7N6KdQxD94XP8bbtos5lw+zLVw2l9sFE=; b=I+PUiOyI975mljeivYSN5F13NTkHw1slzzoPKjMLU328QnshnXRPOI2Hs95iQ6gctm G/DVdty3yX4mUJgPM6hAmSfkkLgKOxRsfgt6T+B1XBCWuRza9nc6YE/SXZrNpMuK8d4J Dges8LXt7NXRaL7kyLajiFGn373HG5k4aV7W0q8GrHhi/dzL47/lkpMCwgYAfgfcDFv2 RvowWC/1woQty8EJl2LlkQk4ZX0mDobUOjsbZgSLJJ0Qnap+nKSK4FG7D/90Xy9Cm28K GGPLpjnVs4QZ26g5aLOksm2YtSy1+GMKstj3DvFFfTd2Qa5ejZTlR8o/RWJg7iHnmcu0 6itQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: 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 21si20324690pgb.269.2021.10.18.10.24.16; Mon, 18 Oct 2021 10:24:29 -0700 (PDT) Received-SPF: pass (google.com: 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; spf=pass (google.com: 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 S234020AbhJRRYT (ORCPT + 99 others); Mon, 18 Oct 2021 13:24:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:58978 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233600AbhJRRYP (ORCPT ); Mon, 18 Oct 2021 13:24:15 -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 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 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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...