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=-1.1 required=3.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FSL_HELO_FAKE,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no 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 1A4CEC07E95 for ; Tue, 20 Jul 2021 22:06:32 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 959BA61178 for ; Tue, 20 Jul 2021 22:06:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 959BA61178 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 145BF6B0011; Tue, 20 Jul 2021 18:06:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0D0816B0036; Tue, 20 Jul 2021 18:06:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E3B986B006C; Tue, 20 Jul 2021 18:06:31 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0024.hostedemail.com [216.40.44.24]) by kanga.kvack.org (Postfix) with ESMTP id BA2596B0011 for ; Tue, 20 Jul 2021 18:06:31 -0400 (EDT) Received: from smtpin33.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 47722824805A for ; Tue, 20 Jul 2021 22:06:30 +0000 (UTC) X-FDA: 78384350940.33.64902F5 Received: from mail-pj1-f50.google.com (mail-pj1-f50.google.com [209.85.216.50]) by imf10.hostedemail.com (Postfix) with ESMTP id 01AF660022D5 for ; Tue, 20 Jul 2021 22:06:29 +0000 (UTC) Received: by mail-pj1-f50.google.com with SMTP id x13-20020a17090a46cdb0290175cf22899cso468333pjg.2 for ; Tue, 20 Jul 2021 15:06:29 -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:content-transfer-encoding:in-reply-to; bh=BB0NGsGv3epWhxiQYCc03cLFHcDOFlK36/5xOhr9iGo=; b=G60QHWuyRH6eWtLou5HaWRxEN7Yq6nKV9T1iAIqyAq6fVrq1WWQgHIEV53g1ohgNc9 EQohQSGMoRnwcSERx2WtsFUY2oBHP2L7o6RLWdjM/8DnxS/jS2gR62e2ZdzQzsD/Cfqi t26NKDlXSIHcL8jfXQ4F7qrg5pPOvQuoI2mBqA5sqIxf4jaH3gQ080WBkK8r5zzKZj6Q G/9z8dSeMgvga8DzcwvEltKCTyVWefclmiDtlzTovNTWLqmL4Y7wltkF8n7JL2lbJV27 Rqq2Y/zqOcIZ3UnQEC1ynwVVGlNk1MtMr3wIXyYacV1olaGdhCMiOjk/TQIOvra62SgO XgXg== 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:content-transfer-encoding :in-reply-to; bh=BB0NGsGv3epWhxiQYCc03cLFHcDOFlK36/5xOhr9iGo=; b=pfk23U3aTrqyuJ5xQYYwR1rEHydKyAqrHdiQEjxbXlS0KkebzHAGaH3H//5pn8vEBE QOh0SLbKyBCR9uKIN47gjhqgOcs8Kchcct3EOeOtJjVglHrI2cHgC32d5E/wPgbMcmAx 2SMjCyZUCRN/byNVCmkt81dd5VQUV6FNelM6aKP7jFx2787eP0cjAAMSgxFsL23kf2IG Rcw57Dk87V0nXCijcwmVutUkq6kDSgb+onjzigOnzU0AZXkkvdYHN9tj8aAN5PYUJgew 4bKJ3YuotLQpdnpwyR0IRaHN4m4e45nF/kARbv+riDKfc24jFGgjde6XNDJLl3fhw3fA Ke8w== X-Gm-Message-State: AOAM5329TlV5zSDFIp9uq6C2Z0Kq89itJ3tIG/t7dkOHtsurdQP7u7WA cKFOHkY/X8myde0TW2a5T3a2aw== X-Google-Smtp-Source: ABdhPJwDD9+zuJ6DYICNGOinctEj1Edxq+hD2yj+AdZXjLWVr+ao/12i42Q3S8W5xw+1pKf5QwmK4Q== X-Received: by 2002:a17:90a:4295:: with SMTP id p21mr30863822pjg.149.1626818788641; Tue, 20 Jul 2021 15:06:28 -0700 (PDT) Received: from google.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id w184sm419793pfw.85.2021.07.20.15.06.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jul 2021 15:06:27 -0700 (PDT) Date: Tue, 20 Jul 2021 22:06:24 +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 05/40] x86/sev: Add RMP entry lookup helpers Message-ID: References: <20210707183616.5620-1-brijesh.singh@amd.com> <20210707183616.5620-6-brijesh.singh@amd.com> <437a5230-64fc-64ab-9378-612c34e1b641@amd.com> <39be0f79-e8e4-fd4a-5c4a-47731c61740d@amd.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <39be0f79-e8e4-fd4a-5c4a-47731c61740d@amd.com> Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=google.com header.s=20161025 header.b=G60QHWuy; spf=pass (imf10.hostedemail.com: domain of seanjc@google.com designates 209.85.216.50 as permitted sender) smtp.mailfrom=seanjc@google.com; dmarc=pass (policy=reject) header.from=google.com X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 01AF660022D5 X-Stat-Signature: hk5knwno35bi7imn95xb5ouq41cne6bd X-HE-Tag: 1626818789-99443 Content-Transfer-Encoding: quoted-printable 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 Fri, Jul 16, 2021, Brijesh Singh wrote: >=20 > On 7/15/21 2:28 PM, Brijesh Singh wrote: > >> Looking at the future patches, dump_rmpentry() is the only power use= r, > >> e.g. everything else mostly looks at "assigned" and "level" (and on= e > >> ratelimited warn on "validated" in snp_make_page_shared(), but I sus= pect > >> that particular check can and should be dropped). > > > > Yes, we need "assigned" and "level" and other entries are mainly for > > the debug purposes. > > > For the debug purposes, we would like to dump additional RMP entries. I= f > we go with your proposed function then how do we get those information > in the dump_rmpentry()? As suggested below, move dump_rmpentry() into sev.c so that it can use th= e microarchitectural version. For debug, I'm pretty that's what we'll want= anyways, e.g. dump the raw value along with the meaning of various bits. > How about if we provide two functions; the first > function provides architectural format and second provides the raw > values which can be used by the dump_rmpentry() helper. >=20 > struct rmpentry *snp_lookup_rmpentry(unsigned long paddr, int *level); >=20 > The 'struct rmpentry' uses the format defined in APM Table 15-36. >=20 > struct _rmpentry *_snp_lookup_rmpentry(unsigned long paddr, int *level)= ; >=20 > The 'struct _rmpentry' will use include the PPR definition (basically > what we have today in this patch). >=20 > Thoughts ? Why define an architectural "struct rmpentry"? IIUC, there isn't a true architectural RMP entry; the APM defines architectural fields but doesn't= define a layout. Functionally, making up our own struct isn't a problem, I just= don't see the point since all use cases only care about Assigned and Page-Size,= and we can do them a favor by translating Page-Size to X86_PG_LEVEL. > >> /* > >> =A0 * Returns 1 if the RMP entry is assigned, 0 if it exists but is = not > >> * assigned, and -errno if there is no corresponding RMP entry. > >> =A0 */ > >> int snp_lookup_rmpentry(struct page *page, int *level) > >> { > >> =A0=A0=A0=A0unsigned long phys =3D page_to_pfn(page) << PAGE_SHIFT; > >> =A0=A0=A0=A0struct rmpentry *entry, *large_entry; > >> =A0=A0=A0=A0unsigned long vaddr; > >> > >> =A0=A0=A0=A0if (!cpu_feature_enabled(X86_FEATURE_SEV_SNP)) > >> =A0=A0=A0=A0=A0=A0=A0 return -ENXIO; > >> > >> =A0=A0=A0=A0vaddr =3D rmptable_start + rmptable_page_offset(phys); > >> =A0=A0=A0=A0if (unlikely(vaddr > rmptable_end)) > >> =A0=A0=A0=A0=A0=A0=A0 return -EXNIO; > >> > >> =A0=A0=A0=A0entry =3D (struct rmpentry *)vaddr; > >> > >> =A0=A0=A0=A0/* Read a large RMP entry to get the correct page level = used in > >> RMP entry. */ > >> =A0=A0=A0=A0vaddr =3D rmptable_start + rmptable_page_offset(phys & P= MD_MASK); > >> =A0=A0=A0=A0large_entry =3D (struct rmpentry *)vaddr; > >> =A0=A0=A0=A0*level =3D RMP_TO_X86_PG_LEVEL(rmpentry_pagesize(large_e= ntry)); > >> > >> =A0=A0=A0=A0return !!entry->assigned; > >> } > >> > >> > >> And then move dump_rmpentry() (or add a helper) in sev.c so that "st= ruct > >> rmpentry" can be declared in sev.c.