Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2887423pxj; Mon, 10 May 2021 13:03:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxbWCioJIs2uiEfG/elx0hvzbmtCLQ93sgHZ+VH4/0wSPUCghxsVJBUiKaYCMILXLHn1N16 X-Received: by 2002:a17:906:1984:: with SMTP id g4mr26894849ejd.525.1620677002786; Mon, 10 May 2021 13:03:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620677002; cv=none; d=google.com; s=arc-20160816; b=HJuUWLHPndY/ZP6sPzo2TXB4xABNAIWVs1zlhrxv3dG4bN154yJJ7InF4fqxOgcxjB eXc0GU1e6Hxcbgz1QiF71/V3FUeHvU3fwvN8NOLmB+bOI11jwuh/KJep0z4vfkJ0fEkr 4IfjCfFBCDY9mZQBFtYjI+zZWj//J8xByCtaeDjQ/vSLSO30lSJvgDyoNIhV7XmyvSRq o1B/v2xgLoFGiN3Ovy5U5VNfXyyNu4HV2hoUb+4Vn1r/wb67Cel3AGWZBXPVZs24xFhQ h6VhiSiyXVhIzECFhLErRqsv+rdNARDYVmmkwkcO12qcB8czEUTbWlMq3gZSAZe/w4vt re6g== 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=Z3iJh2XmGP7LkEWrFxeTJh6BbwLsdzrCzxXMlURocYQ=; b=j76jfnNveT+G7afqjg5YyMjTKJqTyNdPngu56g3La04bU83GsrnREkh+GbMQya5bcQ SMaXP2IRpK5gdSfsJCXeBNvS2UNnR75nmnNRfoSi4jHjF2gR8tNQV5UQXG1nifBHmKRH VFD0v2Zev+PijNOH4tumdZlDez3D34HGpGiPZy93GYX4F2hpK9i8QayRiu/cFxrAyEyS WmwLRK5R8EISV08IrzYLf4IYBDZncarTsZ9rPkDdxCBxNXKBet5PQc1B6h2VJw0h+k6R ARyRGeRLhr0jJUaiKGLBr0psaztfAFmNTpNCXpFQlhsXbI0zghkU/fN1q5mRY1A8uWto +WzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=lv1c8f50; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w10si14568976edd.545.2021.05.10.13.02.57; Mon, 10 May 2021 13:03:22 -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; dkim=pass header.i=@google.com header.s=20161025 header.b=lv1c8f50; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231518AbhEJUA2 (ORCPT + 99 others); Mon, 10 May 2021 16:00:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53598 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229877AbhEJUA1 (ORCPT ); Mon, 10 May 2021 16:00:27 -0400 Received: from mail-lj1-x22b.google.com (mail-lj1-x22b.google.com [IPv6:2a00:1450:4864:20::22b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2647CC061574 for ; Mon, 10 May 2021 12:59:22 -0700 (PDT) Received: by mail-lj1-x22b.google.com with SMTP id b21so22276285ljf.11 for ; Mon, 10 May 2021 12:59:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Z3iJh2XmGP7LkEWrFxeTJh6BbwLsdzrCzxXMlURocYQ=; b=lv1c8f50xF9jqpc8vxaf3InOEokK44UCAOqI3N5+cVGgZytZk0XgUubCIIMD1VAhiu 0NQFNlJoovN6HsnwBHK5iaB/N66Dh28LK7kNc1AGDy2qHG22honcnvRGYqze45gmjiyc iST+zZNWjk4GFR7f+PpOiaGksl+C278jMmelZ/VnvXyhoyx6OfMR7emluvTVOtpiFIi9 Dy10/N4CMV/K+8Mrz+bBXyGBOHvd91cfpXDUFb6cAsrmiQYxZ66vUIfKZWKVA5vGHKlM vOZLqKbzIO2bo35VQpgQcIsfXFAVa/OKJ6kQvR1NOnPtio//+e1fGN610TwJR8EQXclQ Ch+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Z3iJh2XmGP7LkEWrFxeTJh6BbwLsdzrCzxXMlURocYQ=; b=MYZ9eLgDFGLFezHkHNV8M/6XcaR1DOSmKlX8wIfpfId0IcWDixtoVuVqUk/VX2IOK0 JJ1b3c65ZkNRMtiH4j4EFjUaUu12WG3gZuYrXXfgD7ujgG0c+U1nApPBPpM+dTapLgCx CB+3oZ1XvF33uINY8G0OFiASre9rvCBtaPHaUzOQCSzWZtqWGvspZ7BTNglcHQL5yltm fG6B1vhKG6v8Se8mGqycU+XBPWZlXxaggzcOI+ZYotstx6o5skg5HFJZgE3R1bAydcxh DS73tjxturRUtekkv0+174KoJCZ2I6gwDFw81lLxeGTsP4bnrME6dKSDoK/E6OM76/8U XzyA== X-Gm-Message-State: AOAM533oIUepeXrhNvfwmIfoBd1kg5RxqxcVHOitNOfrs2Q+ZWlLw4IZ wGcBjE03TUQEaUC4syIYKOWK6BqalZ770x0O2vaHJ5wR3Co8+ifJ X-Received: by 2002:a2e:8e62:: with SMTP id t2mr21396917ljk.20.1620676760311; Mon, 10 May 2021 12:59:20 -0700 (PDT) MIME-Version: 1.0 References: <20210430123822.13825-1-brijesh.singh@amd.com> <20210430123822.13825-33-brijesh.singh@amd.com> <84f52e0e-b034-ebcf-e787-7ef9e3baae2f@amd.com> In-Reply-To: <84f52e0e-b034-ebcf-e787-7ef9e3baae2f@amd.com> From: Peter Gonda Date: Mon, 10 May 2021 13:59:08 -0600 Message-ID: Subject: Re: [PATCH Part2 RFC v2 32/37] KVM: SVM: Add support to handle MSR based Page State Change VMGEXIT To: Brijesh Singh Cc: x86@kernel.org, linux-kernel@vger.kernel.org, kvm list , Thomas Gleixner , Borislav Petkov , jroedel@suse.de, "Lendacky, Thomas" , Paolo Bonzini , Ingo Molnar , Dave Hansen , David Rientjes , Sean Christopherson , peterz@infradead.org, "H. Peter Anvin" , tony.luck@intel.com Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, May 10, 2021 at 11:51 AM Brijesh Singh wrote: > > Hi Peter, > > On 5/10/21 12:30 PM, Peter Gonda wrote: > >> +static int snp_make_page_shared(struct kvm_vcpu *vcpu, gpa_t gpa, kvm_pfn_t pfn, int level) > >> +{ > >> + struct rmpupdate val; > >> + int rc, rmp_level; > >> + struct rmpentry *e; > >> + > >> + e = snp_lookup_page_in_rmptable(pfn_to_page(pfn), &rmp_level); > >> + if (!e) > >> + return -EINVAL; > >> + > >> + if (!rmpentry_assigned(e)) > >> + return 0; > >> + > >> + /* Log if the entry is validated */ > >> + if (rmpentry_validated(e)) > >> + pr_debug_ratelimited("Remove RMP entry for a validated gpa 0x%llx\n", gpa); > >> + > >> + /* > >> + * Is the page part of an existing 2M RMP entry ? Split the 2MB into multiple > >> + * of 4K-page before making the memory shared. > >> + */ > >> + if ((level == PG_LEVEL_4K) && (rmp_level == PG_LEVEL_2M)) { > >> + rc = snp_rmptable_psmash(vcpu, pfn); > >> + if (rc) > >> + return rc; > >> + } > >> + > >> + memset(&val, 0, sizeof(val)); > >> + val.pagesize = X86_TO_RMP_PG_LEVEL(level); > > This is slightly different from Rev 2.00 of the GHCB spec. This > > defaults to 2MB page sizes, when the spec says the only valid settings > > for level are 0 -> 4k pages or 1 -> 2MB pages. Should this enforce the > > same strictness as the spec? > > > The caller of the snp_make_page_shared() must pass the x86 page level. > We should reach here after all the guest provide value have passed > through checks. > > The call sequence in this case should be: > > snp_handle_vmgexit_msr_protocol() > > __snp_handle_page_state_change(vcpu, gfn_to_gpa(gfn), PG_LEVEL_4K) > > snp_make_page_shared(..., level) > > Am I missing something ? Thanks Brijesh. I think my comment was misplaced. Looking at 33/37 +static unsigned long snp_handle_page_state_change(struct vcpu_svm *svm, struct ghcb *ghcb) +{ ... + while (info->header.cur_entry <= info->header.end_entry) { + entry = &info->entry[info->header.cur_entry]; + gpa = gfn_to_gpa(entry->gfn); + level = RMP_TO_X86_PG_LEVEL(entry->pagesize); + op = entry->operation; This call to RMP_TO_X86_PG_LEVEL is not as strict as the spec. Is that OK? > > >> + return rmpupdate(pfn_to_page(pfn), &val); > >> +} > >> + > >> +static int snp_make_page_private(struct kvm_vcpu *vcpu, gpa_t gpa, kvm_pfn_t pfn, int level) > >> +{ > >> + struct kvm_sev_info *sev = &to_kvm_svm(vcpu->kvm)->sev_info; > >> + struct rmpupdate val; > >> + struct rmpentry *e; > >> + int rmp_level; > >> + > >> + e = snp_lookup_page_in_rmptable(pfn_to_page(pfn), &rmp_level); > >> + if (!e) > >> + return -EINVAL; > >> + > >> + /* Log if the entry is validated */ > >> + if (rmpentry_validated(e)) > >> + pr_err_ratelimited("Asked to make a pre-validated gpa %llx private\n", gpa); > >> + > >> + memset(&val, 0, sizeof(val)); > >> + val.gpa = gpa; > >> + val.asid = sev->asid; > >> + val.pagesize = X86_TO_RMP_PG_LEVEL(level); > > Same comment as above. > > See my above response. > > > > > >> + val.assigned = true; > >> + > >> + return rmpupdate(pfn_to_page(pfn), &val); > >> +}