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 89F54C433F5 for ; Tue, 19 Oct 2021 09:40:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6DDF86139D for ; Tue, 19 Oct 2021 09:40:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235088AbhJSJmn (ORCPT ); Tue, 19 Oct 2021 05:42:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54538 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234680AbhJSJml (ORCPT ); Tue, 19 Oct 2021 05:42:41 -0400 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 017C6C06161C for ; Tue, 19 Oct 2021 02:40:29 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id k7so46397732wrd.13 for ; Tue, 19 Oct 2021 02:40:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=+v4Hfkg/w1/B4R5A/ecV7kDZ1+BpxRgtZ9ZYRUTGvYQ=; b=SKdRW7siAk731anszKLFJ7LCVf1ZukxuHCQa9UfvTaS+LMfaeSqnc+PdFEyz2b9Vql R9n2h4pfsBE+hTtl9Ghcf73/JuT7EvSbvrayRN4ynnOPhQo2YSbaa2uPZt5r4puv5gfK GaTMyTPjRRQgvhLvowqAFIDI+9cKrp/IeO9ZAC8t6pdqf4w8t/Q1YC4NIoHvacb0FPms Cgm3gUBIOrm4FhPkuzjC6bGgzVMTNnDNWmpEOZz92J1kYF54KTktv+6+qRpIPIOleMfH 7rW14/k/BiowMiLxGBg2YIKmhi2tV85quWfj9WotO4rPM5TGN+7tWvTBQUosIYMhYK9X v8wA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=+v4Hfkg/w1/B4R5A/ecV7kDZ1+BpxRgtZ9ZYRUTGvYQ=; b=Oq5ehedJSFXgqqV71DBzuQ/rkmsayz3pPTtlqlrOkZjJPzpRRqSwC/+XzCDBYlORxw 4HGzVvpiGCGVg4No8QYVoYoSY/4raMpNyLk5h0gZrh7qocWunhqpr9815bvqX7z5LU+p U8A1X04X+Oxybkq3kkgh4xNeqbbIuFT9+viCMkWQRuk1uam4w/QQaT6wYg24Xgu9m6m2 P9BwEodJE1Cw8z7FF8zdluTPbWyujRYDoTrjK2mcPBlFurVAyvBXz0DIpeOTsjyhS2tL ckD6YuYhAqgFY5Rk4r+qWMuucBXOZjM9cO8ZYMhSEC87j4FRVkXFjQBdnuvtp9FYElLc dfHQ== X-Gm-Message-State: AOAM531EzRiGDTJt52QQgQ/e+9bFN9rkPCINNbUvw+cU3sDm8sn9fSe2 XxZNA0I5z+oRZyt2MsVzw5HsbQ== X-Google-Smtp-Source: ABdhPJy9ly25Wdf1sCClM7a9Zz77DNMQFpedsH5Fh26mLWFifdz5sv78JyKVIUA8hXD5r5R+3vWcpA== X-Received: by 2002:adf:ec46:: with SMTP id w6mr29994052wrn.240.1634636427307; Tue, 19 Oct 2021 02:40:27 -0700 (PDT) Received: from google.com ([2a00:79e0:d:210:59ca:401f:83a8:de6d]) by smtp.gmail.com with ESMTPSA id g33sm1594777wmp.45.2021.10.19.02.40.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Oct 2021 02:40:26 -0700 (PDT) Date: Tue, 19 Oct 2021 10:40:24 +0100 From: Quentin Perret To: Marc Zyngier 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 Message-ID: References: <20211013155831.943476-1-qperret@google.com> <20211013155831.943476-17-qperret@google.com> <87h7dhupfa.wl-maz@kernel.org> <3ec8ab06f9950a13818109051835fdb9@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3ec8ab06f9950a13818109051835fdb9@kernel.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Monday 18 Oct 2021 at 18:12:22 (+0100), Marc Zyngier wrote: > 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... Yup, it'd be nice to do checks on kvm_protected_mode_initialized only when they're strictly necessary, and that's not the case here. I'll fold that change in v2. Cheers Quentin 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 E52ABC433EF for ; Tue, 19 Oct 2021 09:40:32 +0000 (UTC) Received: from mm01.cs.columbia.edu (mm01.cs.columbia.edu [128.59.11.253]) by mail.kernel.org (Postfix) with ESMTP id 68D376138F for ; Tue, 19 Oct 2021 09:40:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 68D376138F Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com 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 D3AFD4079A; Tue, 19 Oct 2021 05:40:31 -0400 (EDT) X-Virus-Scanned: at lists.cs.columbia.edu Authentication-Results: mm01.cs.columbia.edu (amavisd-new); dkim=softfail (fail, message has been altered) header.i=@google.com 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 GMR0xGU4xABM; Tue, 19 Oct 2021 05:40:30 -0400 (EDT) Received: from mm01.cs.columbia.edu (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id BDBD94A193; Tue, 19 Oct 2021 05:40:30 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id E823D4086C for ; Tue, 19 Oct 2021 05:40:29 -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 s1RI++zbs13G for ; Tue, 19 Oct 2021 05:40:28 -0400 (EDT) Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.45]) by mm01.cs.columbia.edu (Postfix) with ESMTPS id BFEB14079A for ; Tue, 19 Oct 2021 05:40:28 -0400 (EDT) Received: by mail-wr1-f45.google.com with SMTP id r18so46590685wrg.6 for ; Tue, 19 Oct 2021 02:40:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=+v4Hfkg/w1/B4R5A/ecV7kDZ1+BpxRgtZ9ZYRUTGvYQ=; b=SKdRW7siAk731anszKLFJ7LCVf1ZukxuHCQa9UfvTaS+LMfaeSqnc+PdFEyz2b9Vql R9n2h4pfsBE+hTtl9Ghcf73/JuT7EvSbvrayRN4ynnOPhQo2YSbaa2uPZt5r4puv5gfK GaTMyTPjRRQgvhLvowqAFIDI+9cKrp/IeO9ZAC8t6pdqf4w8t/Q1YC4NIoHvacb0FPms Cgm3gUBIOrm4FhPkuzjC6bGgzVMTNnDNWmpEOZz92J1kYF54KTktv+6+qRpIPIOleMfH 7rW14/k/BiowMiLxGBg2YIKmhi2tV85quWfj9WotO4rPM5TGN+7tWvTBQUosIYMhYK9X v8wA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=+v4Hfkg/w1/B4R5A/ecV7kDZ1+BpxRgtZ9ZYRUTGvYQ=; b=mtTEFcvHU28zb4o9XUmj8YaUf51a3NWN5lP0RJX4mEYsWmNWNreWSFQlce3z3T8dmI iZy9+Gn3I1PG14w5whFCR8rQFP2KNrtsXa+Bg4fL9Ps0eJCLXp7SquyC7Fg21oMsZEwo LqcbSpgYGW9Nwz1PwOPXPVD1za5+UjAalp6cdC7rxKylp1nC/cVxFyE2MdQBF9c9LFJX Xpwf24jsEybdrEFuJv73VHzJiCefOmT4DtJST2vkTHiqu2X2cW8aKWXzpQCQA0tR+cLa aE0SUQGku4ahZBpQXJnwxC8hcXfSAqT8w46HUu2YRYMDzideRctIn9Q5HfE5zyig8OuT OEbQ== X-Gm-Message-State: AOAM532htn5wB/7OUDJBwAZSVTrr5zcPUl2en5criN9cOfR0XUdeewmk WE8lyatfqAC9R/BJXVLStvBvMA== X-Google-Smtp-Source: ABdhPJy9ly25Wdf1sCClM7a9Zz77DNMQFpedsH5Fh26mLWFifdz5sv78JyKVIUA8hXD5r5R+3vWcpA== X-Received: by 2002:adf:ec46:: with SMTP id w6mr29994052wrn.240.1634636427307; Tue, 19 Oct 2021 02:40:27 -0700 (PDT) Received: from google.com ([2a00:79e0:d:210:59ca:401f:83a8:de6d]) by smtp.gmail.com with ESMTPSA id g33sm1594777wmp.45.2021.10.19.02.40.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Oct 2021 02:40:26 -0700 (PDT) Date: Tue, 19 Oct 2021 10:40:24 +0100 From: Quentin Perret To: Marc Zyngier Subject: Re: [PATCH 16/16] KVM: arm64: pkvm: Unshare guest structs during teardown Message-ID: References: <20211013155831.943476-1-qperret@google.com> <20211013155831.943476-17-qperret@google.com> <87h7dhupfa.wl-maz@kernel.org> <3ec8ab06f9950a13818109051835fdb9@kernel.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <3ec8ab06f9950a13818109051835fdb9@kernel.org> Cc: kernel-team@android.com, Will Deacon , Catalin Marinas , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu 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 Monday 18 Oct 2021 at 18:12:22 (+0100), Marc Zyngier wrote: > 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... Yup, it'd be nice to do checks on kvm_protected_mode_initialized only when they're strictly necessary, and that's not the case here. I'll fold that change in v2. Cheers Quentin _______________________________________________ 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 8AB77C433F5 for ; Tue, 19 Oct 2021 09:42:16 +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 5C6CB60EE3 for ; Tue, 19 Oct 2021 09:42:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 5C6CB60EE3 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com 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:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=9p43XTqrlWvFm6JCvPulBOmvjdBLWGQiKoHB3CYGLjI=; b=TMdPOnpKV3EWL5 nWzHiOa+ggzZDcdMYTkZ0/L2X2CeHcUvdnDjFG4GX4pKk3SQfB34Z1IV7McZfA5a78XXaRAXY48Yg a+Ma6RfirOsHtgFqp4d7svZUI51ZzKjFADImEtAzaKa4TlL64VYSKSpiFAArlfqAlHGEWVC1f4o7V Z/D7p5ht3xO1mukL2h9lMT4poheLbUs1sRd4bNnzDQ1GAucndh1fxVs7zhXjsZec4Q/MDCzzHIbb+ vNTsSIFS7zewhePczh9hnGVpghSdaL6Fqn8FAznVD7S1yTd0TULRIR+H127TeKX8HTxDCLfalQrnJ iKSKlOTgUzHxafS1jemA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mclbk-000i42-Qd; Tue, 19 Oct 2021 09:40:33 +0000 Received: from mail-wr1-x434.google.com ([2a00:1450:4864:20::434]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mclbh-000i2i-3b for linux-arm-kernel@lists.infradead.org; Tue, 19 Oct 2021 09:40:30 +0000 Received: by mail-wr1-x434.google.com with SMTP id y3so46765325wrl.1 for ; Tue, 19 Oct 2021 02:40:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=+v4Hfkg/w1/B4R5A/ecV7kDZ1+BpxRgtZ9ZYRUTGvYQ=; b=SKdRW7siAk731anszKLFJ7LCVf1ZukxuHCQa9UfvTaS+LMfaeSqnc+PdFEyz2b9Vql R9n2h4pfsBE+hTtl9Ghcf73/JuT7EvSbvrayRN4ynnOPhQo2YSbaa2uPZt5r4puv5gfK GaTMyTPjRRQgvhLvowqAFIDI+9cKrp/IeO9ZAC8t6pdqf4w8t/Q1YC4NIoHvacb0FPms Cgm3gUBIOrm4FhPkuzjC6bGgzVMTNnDNWmpEOZz92J1kYF54KTktv+6+qRpIPIOleMfH 7rW14/k/BiowMiLxGBg2YIKmhi2tV85quWfj9WotO4rPM5TGN+7tWvTBQUosIYMhYK9X v8wA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=+v4Hfkg/w1/B4R5A/ecV7kDZ1+BpxRgtZ9ZYRUTGvYQ=; b=pSzQU4zzzGkrxngvfMBY1oXh11qMgn2E8lmckGs0A5QFTPjGPlQPMSrVEaaLoUiOIf ihcNI8NzRROwU35aWNgXreLi44baDUoqcdiDOOxicJ/4RhOVAouVHDdzowF9YvVBVEiT fbBcsxBronE8/jEiLEDlxhf3siYf+482osjuayUVYscUeszIhqXhtWHxOCZDsnpw3X0S 5CKA5rh5cbWcEVtM8zhqvF1tbUs0DiNNtOjpQ69/HqN7zWilXMWzA1SNlp4Yb4ZvMeaO s8YbP9mSo09pzf+dq+cf09vA0amQ5ylNCLqth9Q5tFU9Xn/5ATWsSjc+qGYNhQKJV4Fx MkgQ== X-Gm-Message-State: AOAM533TAivYdRj2K638y/AoK1hbVE0+w0xMFAD21rXUNX8jt12bYA9e cS4N209PItXJ/G6YfQLuMrTc2w== X-Google-Smtp-Source: ABdhPJy9ly25Wdf1sCClM7a9Zz77DNMQFpedsH5Fh26mLWFifdz5sv78JyKVIUA8hXD5r5R+3vWcpA== X-Received: by 2002:adf:ec46:: with SMTP id w6mr29994052wrn.240.1634636427307; Tue, 19 Oct 2021 02:40:27 -0700 (PDT) Received: from google.com ([2a00:79e0:d:210:59ca:401f:83a8:de6d]) by smtp.gmail.com with ESMTPSA id g33sm1594777wmp.45.2021.10.19.02.40.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Oct 2021 02:40:26 -0700 (PDT) Date: Tue, 19 Oct 2021 10:40:24 +0100 From: Quentin Perret To: Marc Zyngier 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 Message-ID: References: <20211013155831.943476-1-qperret@google.com> <20211013155831.943476-17-qperret@google.com> <87h7dhupfa.wl-maz@kernel.org> <3ec8ab06f9950a13818109051835fdb9@kernel.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <3ec8ab06f9950a13818109051835fdb9@kernel.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211019_024029_174428_DE30CE3C X-CRM114-Status: GOOD ( 23.57 ) 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 Monday 18 Oct 2021 at 18:12:22 (+0100), Marc Zyngier wrote: > 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... Yup, it'd be nice to do checks on kvm_protected_mode_initialized only when they're strictly necessary, and that's not the case here. I'll fold that change in v2. Cheers Quentin _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel