Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp804240iob; Wed, 18 May 2022 13:25:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwD9aomThl8A3wWQ4Bo5ASpnne8zCJdPM4CURD6uzPLkxt/64z+Zc2gYhmLlGw7W3UIG4Fv X-Received: by 2002:a63:d90c:0:b0:3c6:4ab4:fbfe with SMTP id r12-20020a63d90c000000b003c64ab4fbfemr970481pgg.499.1652905521268; Wed, 18 May 2022 13:25:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652905521; cv=none; d=google.com; s=arc-20160816; b=zHNyLgpTbPjWcn8Lapb0Obr+IVTk+4V3YK3YH4AD4jKNbYx5ffJTVR7iM6+qRuZPIb wEOx82OpvZbkUEqnp3951y8hU4TR5HNwNfDiPrXTp7dTT0fn+dN1q9jysYR0j6cs/n8f qGj9MTHNXTgiSsL9hqCrqXd0atmVGlWes2IMjK0cTU/MN/TIbrzLTQJq6uLt4ZNPWcS5 DpRMn8MNRDx+LyhDZTG3A3iNrMWKKBz1IbT78AQNnFa3dmOuEMrNP/mbNWv2V1CPfjuD We7lUPuOvo4gJkfXwnuVPmVgX82QLoTURRRvMSshAuM9fU/SUPXtzC6YoOcbe9KJ1Qem w+6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=r6lnRyXRdpclSkDpWdKxmmOT7zesUDWOskA8B4RYY/c=; b=ZrG2ATD5MNyvfGyHLawrbKlW31JyGTdebkAzpX0Msqe9I4/lSE3SJVZPASLzaFdQ8i 4B9SjAuwgSB2O+kUqsZIzfpTvadK67ngYrtMJB55gX6yJt9RDuVucaEwvR4pNLuCcqiZ qfPmTKdFigjYfijUR0HwY6SxT83te07sulrTxaxVORBo8biWhYa9oHz+7vtHsy49Ym3U JWYQMnKgFJeNdGeFQFxGrFckj0FLx5ETv6zIY0Q9qtStdWVJtSdySYTVC61hkY7TTqnX cL3pjHkGHhePWrmNwA0rqcIOga2E27u1LcqQTwvGAHaqZ7weMzh2jgR1mTA4htvh6lFy N3Mg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=TWLXdHK3; spf=softfail (google.com: domain of transitioning linux-crypto-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id b19-20020a17090ae39300b001cd57ed2fa8si3403938pjz.39.2022.05.18.13.25.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 May 2022 13:25:21 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-crypto-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=@google.com header.s=20210112 header.b=TWLXdHK3; spf=softfail (google.com: domain of transitioning linux-crypto-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 6400C9729F; Wed, 18 May 2022 13:21:47 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242484AbiERUVe (ORCPT + 99 others); Wed, 18 May 2022 16:21:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33700 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242477AbiERUVc (ORCPT ); Wed, 18 May 2022 16:21:32 -0400 Received: from mail-oi1-x230.google.com (mail-oi1-x230.google.com [IPv6:2607:f8b0:4864:20::230]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D1FC08BD29 for ; Wed, 18 May 2022 13:21:30 -0700 (PDT) Received: by mail-oi1-x230.google.com with SMTP id w127so647366oie.1 for ; Wed, 18 May 2022 13:21:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=r6lnRyXRdpclSkDpWdKxmmOT7zesUDWOskA8B4RYY/c=; b=TWLXdHK3wqNn3HdV/aaUGPAQQ67/UmzCtZoSH5kRM5ZacS3noO6/4Sxti0A+n+d8eK 1cia2priGINJE3sdKfl5lyXttfyP8mpKT5PN4Abc/50p7LOTBEhCyvWaoJxCt8LngOD5 8wxJ79V5d786nAjFdxCpX4rks6paFflfetG9XBR2bSaIls0VWyrw1KPOv/6GpGy8UKkk dfaZiFUkrhQcb7qj0r3ab3HlNgedt7IH+FJloM9LcbqCLSLNuJMvRAKoAl4RyJUYCvQ3 7Peqa0F359j7JUpE6eKM3OwajlJelq+aFw0oyz0E5QyvEFmqZD8TK4K9TzliWrfFF+J4 DUDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=r6lnRyXRdpclSkDpWdKxmmOT7zesUDWOskA8B4RYY/c=; b=aTIneenFntsfSlLSIiyEGczTojZgG/pWUZdR7+YRKkI7raTK8tp+VRdGxVZTxjp7Cx nOVxNvX1MsAwQ7geRwoBdGODkTP0A17GB/sQfL4QUifzDOSVKJl116qUNpaLc5oV4z// zZ1CvLQ1FNq07tHUk2Crr7poSW35Z9kgh1sY6LUvZXLc/nk/nCYqnCURAnviClvKcOBU SxG1ry0zVGYrZyzWEgCB3Y3+2384M2dMDq2AmHtNcbLPHhVwX0bfMsgiT743BKgebBh5 U79zEj/fJilIkmMDXQueq5ttqSgcrB5DllPE4N1kPCHYSxRMdo+E55cVhf1MvI4yKSjW ivAA== X-Gm-Message-State: AOAM531RvM9JwvLr1gz5SsVq7LzHnEY0HP6q0bThP50JElp+xhHiK1rk IVv6Mpx51z2aiIbrAAnH4f7zzzmLu24AtggrRnvdRg== X-Received: by 2002:a05:6808:1599:b0:326:dae2:e49d with SMTP id t25-20020a056808159900b00326dae2e49dmr1027193oiw.110.1652905289966; Wed, 18 May 2022 13:21:29 -0700 (PDT) MIME-Version: 1.0 References: <20210820155918.7518-1-brijesh.singh@amd.com> <20210820155918.7518-28-brijesh.singh@amd.com> In-Reply-To: <20210820155918.7518-28-brijesh.singh@amd.com> From: Marc Orr Date: Wed, 18 May 2022 13:21:18 -0700 Message-ID: Subject: Re: [PATCH Part2 v5 27/45] KVM: SVM: Add KVM_SEV_SNP_LAUNCH_FINISH command To: "Kalra, Ashish" Cc: x86 , LKML , kvm list , linux-coco@lists.linux.dev, linux-mm@kvack.org, Linux Crypto Mailing List , Thomas Gleixner , Ingo Molnar , Joerg Roedel , Tom Lendacky , "H. Peter Anvin" , Ard Biesheuvel , Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Andy Lutomirski , Dave Hansen , Sergio Lopez , Peter Gonda , Peter Zijlstra , Srinivas Pandruvada , David Rientjes , Dov Murik , Tobin Feldman-Fitzthum , Borislav Petkov , Michael Roth , Vlastimil Babka , "Kirill A . Shutemov" , Andi Kleen , Tony Luck , Sathyanarayanan Kuppuswamy , Alper Gun Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=no 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-crypto@vger.kernel.org > @@ -2364,16 +2467,29 @@ static void sev_flush_guest_memory(struct vcpu_svm *svm, void *va, > void sev_free_vcpu(struct kvm_vcpu *vcpu) > { > struct vcpu_svm *svm; > + u64 pfn; > > if (!sev_es_guest(vcpu->kvm)) > return; > > svm = to_svm(vcpu); > + pfn = __pa(svm->vmsa) >> PAGE_SHIFT; > > if (vcpu->arch.guest_state_protected) > sev_flush_guest_memory(svm, svm->vmsa, PAGE_SIZE); > + > + /* > + * If its an SNP guest, then VMSA was added in the RMP entry as > + * a guest owned page. Transition the page to hyperivosr state > + * before releasing it back to the system. > + */ > + if (sev_snp_guest(vcpu->kvm) && > + host_rmp_make_shared(pfn, PG_LEVEL_4K, false)) > + goto skip_vmsa_free; > + > __free_page(virt_to_page(svm->vmsa)); > > +skip_vmsa_free: > if (svm->ghcb_sa_free) > kfree(svm->ghcb_sa); > } Hi Ashish. We're still working with this patch set internally. We found a bug that I wanted to report in this patch. Above, we need to flush the VMSA page, `svm->vmsa`, _after_ we call `host_rmp_make_shared()` to mark the page is shared. Otherwise, the host gets an RMP violation when it tries to flush the guest-owned VMSA page. The bug was silent, at least on our Milan platforms, bef reo d45829b351ee6 ("KVM: SVM: Flush when freeing encrypted pages even on SME_COHERENT CPUs"), because the `sev_flush_guest_memory()` helper was a noop on platforms with the SME_COHERENT feature. However, after d45829b351ee6, we unconditionally do the flush to keep the IO address space coherent. And then we hit this bug. Thanks, Marc