Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp4940927pxv; Tue, 20 Jul 2021 15:07:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw0su2c/d9pporIrCiZqZks56fvs8oS3Mos1kcodiJaRKgfmyqlBarvSGsSk6LR0tkbZ3GL X-Received: by 2002:a17:906:b6c5:: with SMTP id ec5mr34515764ejb.290.1626818852287; Tue, 20 Jul 2021 15:07:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626818852; cv=none; d=google.com; s=arc-20160816; b=JTs1KXQ8Zf7sEWp42KnEQSyIrq+VDoSgoLFh+Iu/7kPa4YSwsDBoqXMXJQ8Qtuad7i hgbL9iGZQ33ozVSzv8D7w5K8J3Ahwxjy7ry4kKo4iImjo2J1Fievz+P/qvKoGLqUudpd lGACmPAiTUGJxV/O8PHUrhbcmwSvpsPxsm/6r+r/D+HdAgvMuvFtPimeS98gFShzFfaQ PAHAlfCD9w/T98j87ZgC5LlGKZpJrSJ+SWnLHlnhKYHjIv7C3/VtpaFZgjQkHoRYjvXu p4iaSBcpNcGJI8AZV7qox1pq2Yap+mku0xLZpf/9IK+hWEqdW9NGvJVgSxorqdGvVy/g YASw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=BB0NGsGv3epWhxiQYCc03cLFHcDOFlK36/5xOhr9iGo=; b=zxLmvghTrF3/PM8ICHXXErbNH2N1mbkXA8OYCNAMlh9bTFIkoqc+dq5CUkr10oN8wl lRmELXlLgpuNBveM+Yoq5k00L9EFrDiqhQCIF43BICBgXpKsVN1B/gybfAZeof2SJ7kV ytQ4gsZ8BsqY7GDfbiL+L/hGmPHTwLuxiuFg85BwNzbyONPKAUe+07CHSWXGdiXoJCNQ vyg6zK/I4MCDvqleDzI0hCHE/pM8A6rKTLT5PcavoxFbFXEAZlATqA5JN4wQdoKg6ozT N6xI3modfIDu4UJOSPPfuZZLqeRT391aH1cewTFpMw+Im1SimwrUTFNYccYn9KyXGpeq oOpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=G60QHWuy; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 8si27652436ejx.637.2021.07.20.15.06.57; Tue, 20 Jul 2021 15:07:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-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=G60QHWuy; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-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 S229866AbhGTVZz (ORCPT + 99 others); Tue, 20 Jul 2021 17:25:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32976 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229818AbhGTVZy (ORCPT ); Tue, 20 Jul 2021 17:25:54 -0400 Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 64591C061762 for ; Tue, 20 Jul 2021 15:06:29 -0700 (PDT) Received: by mail-pj1-x102a.google.com with SMTP id g6-20020a17090adac6b029015d1a9a6f1aso2566735pjx.1 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=QUkEXVLlkPFXzBe70+W4dMjgKzVyAVCWEpLqhigB9zDxn6+ptcYCIn3iNBPR0oZ23c gpMa3zUNpFdIA2kJ1EKKrQcin3gyKEeEIBjeLwO0qMx7puQY9bAgBJQcH5TQPMmEu/UD 0N8F7fLPYQixZysbLQAkHGHOyodOPInY2WJLXr8H04oTCIGWBdk5TGcui1OnGD+aGMjV TexBQ5JGe6T3vOPJ6anuTC/Ng4lH9lqglPunDjmD0wpJ44aAChF/A9gbCGibxoGrqWU7 fXjuKdN98+Yz+UChXvTaPzybI9kVgKjMhQb4viWDF0lzHZkAVrv8/8NJpyEDI+2rW09L VG1Q== X-Gm-Message-State: AOAM533FPZggFzy/Cb/VlLG/HyLOdmUdYUWopg36bNKy3VQ8IqYRkrUR G8W4B9vVLsM9Bq8hAe3rl6hRHQ== 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 Content-Transfer-Encoding: 8bit In-Reply-To: <39be0f79-e8e4-fd4a-5c4a-47731c61740d@amd.com> Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org On Fri, Jul 16, 2021, Brijesh Singh wrote: > > On 7/15/21 2:28 PM, Brijesh Singh wrote: > >> Looking at the future patches, dump_rmpentry() is the only power user, > >> e.g. everything else mostly looks at "assigned" and "level" (and one > >> ratelimited warn on "validated" in snp_make_page_shared(), but I suspect > >> 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. If > 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 the 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. > > struct rmpentry *snp_lookup_rmpentry(unsigned long paddr, int *level); > > The 'struct rmpentry' uses the format defined in APM Table 15-36. > > struct _rmpentry *_snp_lookup_rmpentry(unsigned long paddr, int *level); > > The 'struct _rmpentry' will use include the PPR definition (basically > what we have today in this patch). > > 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. > >> /* > >> ? * 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. > >> ? */ > >> int snp_lookup_rmpentry(struct page *page, int *level) > >> { > >> ????unsigned long phys = page_to_pfn(page) << PAGE_SHIFT; > >> ????struct rmpentry *entry, *large_entry; > >> ????unsigned long vaddr; > >> > >> ????if (!cpu_feature_enabled(X86_FEATURE_SEV_SNP)) > >> ??????? return -ENXIO; > >> > >> ????vaddr = rmptable_start + rmptable_page_offset(phys); > >> ????if (unlikely(vaddr > rmptable_end)) > >> ??????? return -EXNIO; > >> > >> ????entry = (struct rmpentry *)vaddr; > >> > >> ????/* Read a large RMP entry to get the correct page level used in > >> RMP entry. */ > >> ????vaddr = rmptable_start + rmptable_page_offset(phys & PMD_MASK); > >> ????large_entry = (struct rmpentry *)vaddr; > >> ????*level = RMP_TO_X86_PG_LEVEL(rmpentry_pagesize(large_entry)); > >> > >> ????return !!entry->assigned; > >> } > >> > >> > >> And then move dump_rmpentry() (or add a helper) in sev.c so that "struct > >> rmpentry" can be declared in sev.c.