From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-oi1-f177.google.com (mail-oi1-f177.google.com [209.85.167.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 163491FDD for ; Wed, 18 May 2022 20:21:30 +0000 (UTC) Received: by mail-oi1-f177.google.com with SMTP id m25so4092417oih.2 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=sCAPL0os3nBeFNBPcQEZzllDGYgnFZDARRbyc3+TzeEPBKr86PO4zDxomfTDCfKtqH buDVUeFozoOikW+PZ8TgMGCAZOaazRNdx1Tr2xSDfjRx7qtG3X9/SsAFdD/bRqXRc2tp qS0XsFxZOOE3xggxOsPKArllTlnQDc8D7IUEg0PRF5TPF3xusJt8VJDssQlWlY2Ni+SF x8C/7+f4tq9LVObWB2ywuevgjWgq6VbcNkz56WrRuMMJFiX2P7AIVLWWSqxZMLBuHUOK WKQRpqM8tBvt52TmSAMfZLH1fn3FJK9qfmilx3/0VVy9zkLXhZfSIIYep/7fCNMAftfS 3h5w== X-Gm-Message-State: AOAM5316Z1+0JW8RIM8PWeiMXFWU6McOpynweH1AdpvTS25Yvjye46R8 A2O6xrqFLKNDmzTytvU/ffm4uwKpDr+SZ/RjK/oJjQ== X-Google-Smtp-Source: ABdhPJyrABDg8UmKaFO4g1zPr7ZghjFTnzNY7hYFLo47MNaYS70K3fAAfHBMwODnv6JC7BiV3xuQQnWrp6uzkVZkDcY= 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) Precedence: bulk X-Mailing-List: linux-coco@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: 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" > @@ -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