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 X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FSL_HELO_FAKE, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0ED02C07E95 for ; Mon, 19 Jul 2021 19:14:56 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 987D960C40 for ; Mon, 19 Jul 2021 19:14:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 987D960C40 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 435DC6B018D; Mon, 19 Jul 2021 15:14:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3E5B68D00F5; Mon, 19 Jul 2021 15:14:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 260078D00F4; Mon, 19 Jul 2021 15:14:55 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0240.hostedemail.com [216.40.44.240]) by kanga.kvack.org (Postfix) with ESMTP id F275E6B018D for ; Mon, 19 Jul 2021 15:14:54 -0400 (EDT) Received: from smtpin06.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 940E38248D7C for ; Mon, 19 Jul 2021 19:14:53 +0000 (UTC) X-FDA: 78380289666.06.28698EA Received: from mail-pg1-f179.google.com (mail-pg1-f179.google.com [209.85.215.179]) by imf20.hostedemail.com (Postfix) with ESMTP id 5C6C8D0000A7 for ; Mon, 19 Jul 2021 19:14:53 +0000 (UTC) Received: by mail-pg1-f179.google.com with SMTP id 37so20069648pgq.0 for ; Mon, 19 Jul 2021 12:14:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=tQHel7KfmZotRt+JL+tikCTH8i4jvKerKwX4Ykhe458=; b=XzM+UTgoPg+XkDOQ81Qyu9Aj1IHESyBIMhh/NFuqluTQUx/dfqwUh9CfJ7hyZrzFOq 98OBWEJ8SBib/jcg/gWXAgVqsGzmGzVmU1OUdWlfXwZp6TOhQz8JOPY/LhU0HLup5t60 MG09uBh/EZAN80GUdXbWAIzfSVF8OpL6KrxKsnW7KZT5qxtMjdXlgfFYJCVMyibNrxap bI8rESzefHOSN3QAHId4wLC6/nFzqtJ5ez4iL6x1w8/BsoenbhCPqleRFd2divXFsxNi r/lz770w0+7cZ8LA1ahJas+30qW/2CSV1uocE/OAPLcIqktisM8VvyTh0xw7f/nc4gbi Wsfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=tQHel7KfmZotRt+JL+tikCTH8i4jvKerKwX4Ykhe458=; b=kp3jJqIab4Jp8xa6j69MP3yagmVhriArnu6uZrfcDgZBRus50NL5GJWYALG8JXetBZ I+GV5d8drFhG9VGN2AWKQrTgVzZiUqdR+9riTMWlW6FE54oU++4zrbZc2KZL3ru3npLL 4XOKCMNeFtzkhzKUlKfGMwqsFXl4L1fn9bLKzNWPQMJ0Pseasdv/59/y3M9O7mAHQoVc jc1f5S+xkNxPILYpo6I5r2IFzgiqADrK3Ks8qrRI/AyrTvbMdw/JNxR7yBy+6ueJNFxY uFuEiyDfHtGa78m9OjVKxaG1TNhlk+FoIcAUeZNvOsXk7+bHqklRpEC+JYKrA9g4Xuto 5eTA== X-Gm-Message-State: AOAM530IirW+KV+Wk77FPE/ZAD2YM8E0/oTMeijKcEuisp1c9KY5eznU JE2FtcnrDBPctRZnZSiq6eQucg== X-Google-Smtp-Source: ABdhPJwrFVVD96rnIFIK2jlY/ieHH+6lfcSv1ywrpxxBKG4B8nAAH7dSYEIACsmYQwT8smdf5ajGig== X-Received: by 2002:a65:5bc6:: with SMTP id o6mr3241244pgr.43.1626722092334; Mon, 19 Jul 2021 12:14:52 -0700 (PDT) Received: from google.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id x10sm22140073pgj.73.2021.07.19.12.14.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Jul 2021 12:14:51 -0700 (PDT) Date: Mon, 19 Jul 2021 19:14:48 +0000 From: Sean Christopherson To: Brijesh Singh Cc: x86@kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-efi@vger.kernel.org, platform-driver-x86@vger.kernel.org, linux-coco@lists.linux.dev, linux-mm@kvack.org, linux-crypto@vger.kernel.org, Thomas Gleixner , Ingo Molnar , Joerg Roedel , Tom Lendacky , "H. Peter Anvin" , Ard Biesheuvel , Paolo Bonzini , 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 , tony.luck@intel.com, npmccallum@redhat.com, brijesh.ksingh@gmail.com Subject: Re: [PATCH Part2 RFC v4 26/40] KVM: SVM: Add KVM_SEV_SNP_LAUNCH_FINISH command Message-ID: References: <20210707183616.5620-1-brijesh.singh@amd.com> <20210707183616.5620-27-brijesh.singh@amd.com> <9ee5a991-3e43-3489-5ee1-ff8c66cfabc1@amd.com> <379fd4da-3ca9-3205-535b-8d1891b3a75a@amd.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <379fd4da-3ca9-3205-535b-8d1891b3a75a@amd.com> X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 5C6C8D0000A7 X-Stat-Signature: s3pnfrai6qhbadwak6779tqe9za175qd Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=google.com header.s=20161025 header.b=XzM+UTgo; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf20.hostedemail.com: domain of seanjc@google.com designates 209.85.215.179 as permitted sender) smtp.mailfrom=seanjc@google.com X-HE-Tag: 1626722093-710842 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Mon, Jul 19, 2021, Brijesh Singh wrote: > > > On 7/19/21 11:54 AM, Sean Christopherson wrote: > > > As I said in previous comments that by default all the memory is in the > > > hypervisor state. if the rmpupdate() failed that means nothing is changed in > > > the RMP and there is no need to reclaim. The reclaim is required only if the > > > pages are assigned in the RMP table. > > > > I wasn't referring to RMPUPDATE failing here (or anywhere). This is the vCPU free > > path, which I think means the svm->vmsa page was successfully updated in the RMP > > during LAUNCH_UPDATE. snp_launch_update_vmsa() goes through snp_page_reclaim() > > on LAUNCH_UPDATE failure, whereas this happy path does not. Is there some other > > transition during teardown that obviastes the need for reclaim? If so, a comment > > to explain that would be very helpful. > > > > In this patch, the sev_free_vcpu() hunk takes care of reclaiming the vmsa > pages before releasing it. I think it will make it more obvious after I add > a helper so that we don't depend on user reading the comment block to see > what its doing. Where? I feel like I'm missing something. The only change to sev_free_vcpu() I see is that addition of the rmpupdate(), I don't see any reclaim path. @@ -2346,8 +2454,25 @@ void sev_free_vcpu(struct kvm_vcpu *vcpu) 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)) { + struct rmpupdate e = {}; + int rc; + + rc = rmpupdate(virt_to_page(svm->vmsa), &e); + if (rc) { + pr_err("Failed to release SNP guest VMSA page (rc %d), leaking it\n", rc); + goto skip_vmsa_free; + } + } + __free_page(virt_to_page(svm->vmsa)); +skip_vmsa_free: if (svm->ghcb_sa_free) kfree(svm->ghcb_sa); }