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=-17.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=unavailable 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 48BB7C48BE5 for ; Thu, 10 Jun 2021 13:04:26 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E92FC613F1 for ; Thu, 10 Jun 2021 13:04:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E92FC613F1 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 68EEE6B0036; Thu, 10 Jun 2021 09:04:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 63E416B006E; Thu, 10 Jun 2021 09:04:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 490C36B0070; Thu, 10 Jun 2021 09:04:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0175.hostedemail.com [216.40.44.175]) by kanga.kvack.org (Postfix) with ESMTP id 0B3A96B0036 for ; Thu, 10 Jun 2021 09:04:24 -0400 (EDT) Received: from smtpin09.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 14EB3878D for ; Thu, 10 Jun 2021 13:04:23 +0000 (UTC) X-FDA: 78237832806.09.8C1D098 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by imf01.hostedemail.com (Postfix) with ESMTP id 1442D5001722 for ; Thu, 10 Jun 2021 13:03:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1623330237; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=w1yRG9vI4ont0xlQTDfWQBvjqAZg/7xjdkXXrg1Zl+M=; b=HrhLhhShp9oM6sI34Qt5gGy749B+oZGsufj2gKbxRxVLfO1eqwxk7deaZkuwDbSnn7uyG/ +R54VIIjnpJzC7HFx6YxmhQflU/5aiUxTEu/cezu6BqrL95oQ5lDqax8s851gTuP710ozE xLaCt/4YXWdVIiVkrdur8j1JiW0pMeI= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-211-2Zzpl9QmNe-i8YEvI8cx5A-1; Thu, 10 Jun 2021 09:03:51 -0400 X-MC-Unique: 2Zzpl9QmNe-i8YEvI8cx5A-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 95914100C624; Thu, 10 Jun 2021 13:03:47 +0000 (UTC) Received: from work-vm (ovpn-114-240.ams2.redhat.com [10.36.114.240]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 552845C1D1; Thu, 10 Jun 2021 13:03:30 +0000 (UTC) Date: Thu, 10 Jun 2021 14:03:27 +0100 From: "Dr. David Alan Gilbert" To: Brijesh Singh Cc: x86@kernel.org, linux-kernel@vger.kernel.org, kvm@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 , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Andy Lutomirski , Dave Hansen , Sergio Lopez , Peter Gonda , Peter Zijlstra , Srinivas Pandruvada , David Rientjes , tony.luck@intel.com, npmccallum@redhat.com, Borislav Petkov Subject: Re: [PATCH Part2 RFC v3 06/37] x86/sev: Add helper functions for RMPUPDATE and PSMASH instruction Message-ID: References: <20210602141057.27107-1-brijesh.singh@amd.com> <20210602141057.27107-7-brijesh.singh@amd.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210602141057.27107-7-brijesh.singh@amd.com> User-Agent: Mutt/2.0.7 (2021-05-04) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=HrhLhhSh; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf01.hostedemail.com: domain of dgilbert@redhat.com has no SPF policy when checking 216.205.24.124) smtp.mailfrom=dgilbert@redhat.com X-Rspamd-Server: rspam02 X-Stat-Signature: enk6ew9mdt679gu4akysijqcma8f8fhu X-Rspamd-Queue-Id: 1442D5001722 X-HE-Tag: 1623330232-17012 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: * Brijesh Singh (brijesh.singh@amd.com) wrote: > The RMPUPDATE instruction writes a new RMP entry in the RMP Table. The > hypervisor will use the instruction to add pages to the RMP table. See > APM3 for details on the instruction operations. > > The PSMASH instruction expands a 2MB RMP entry into a corresponding set of > contiguous 4KB-Page RMP entries. The hypervisor will use this instruction > to adjust the RMP entry without invalidating the previous RMP entry. > > Signed-off-by: Brijesh Singh > --- > arch/x86/kernel/sev.c | 42 ++++++++++++++++++++++++++++++++++++++++++ > include/linux/sev.h | 20 ++++++++++++++++++++ > 2 files changed, 62 insertions(+) > > diff --git a/arch/x86/kernel/sev.c b/arch/x86/kernel/sev.c > index 51676ab1a321..9727df945fb1 100644 > --- a/arch/x86/kernel/sev.c > +++ b/arch/x86/kernel/sev.c > @@ -2226,3 +2226,45 @@ struct rmpentry *snp_lookup_page_in_rmptable(struct page *page, int *level) > return entry; > } > EXPORT_SYMBOL_GPL(snp_lookup_page_in_rmptable); > + > +int psmash(struct page *page) > +{ > + unsigned long spa = page_to_pfn(page) << PAGE_SHIFT; > + int ret; > + > + if (!cpu_feature_enabled(X86_FEATURE_SEV_SNP)) > + return -ENXIO; > + > + /* Retry if another processor is modifying the RMP entry. */ > + do { > + /* Binutils version 2.36 supports the PSMASH mnemonic. */ > + asm volatile(".byte 0xF3, 0x0F, 0x01, 0xFF" > + : "=a"(ret) > + : "a"(spa) > + : "memory", "cc"); > + } while (ret == FAIL_INUSE); > + > + return ret; > +} > +EXPORT_SYMBOL_GPL(psmash); > + > +int rmpupdate(struct page *page, struct rmpupdate *val) > +{ > + unsigned long spa = page_to_pfn(page) << PAGE_SHIFT; > + int ret; > + > + if (!cpu_feature_enabled(X86_FEATURE_SEV_SNP)) > + return -ENXIO; > + > + /* Retry if another processor is modifying the RMP entry. */ > + do { > + /* Binutils version 2.36 supports the RMPUPDATE mnemonic. */ > + asm volatile(".byte 0xF2, 0x0F, 0x01, 0xFE" > + : "=a"(ret) > + : "a"(spa), "c"((unsigned long)val) > + : "memory", "cc"); > + } while (ret == FAIL_INUSE); > + > + return ret; > +} > +EXPORT_SYMBOL_GPL(rmpupdate); > diff --git a/include/linux/sev.h b/include/linux/sev.h > index 83c89e999999..bcd4d75d87c8 100644 > --- a/include/linux/sev.h > +++ b/include/linux/sev.h > @@ -39,13 +39,33 @@ struct __packed rmpentry { > > #define RMP_TO_X86_PG_LEVEL(level) (((level) == RMP_PG_SIZE_4K) ? PG_LEVEL_4K : PG_LEVEL_2M) > > +struct rmpupdate { > + u64 gpa; > + u8 assigned; > + u8 pagesize; > + u8 immutable; > + u8 rsvd; > + u32 asid; > +} __packed; > + > + > +/* > + * The psmash() and rmpupdate() returns FAIL_INUSE when another processor is > + * modifying the RMP entry. > + */ > +#define FAIL_INUSE 3 Perhaps SEV_FAIL_INUSE ? (Given that there are a whole buunch of FAIL_* macros already in general) Dave > #ifdef CONFIG_AMD_MEM_ENCRYPT > struct rmpentry *snp_lookup_page_in_rmptable(struct page *page, int *level); > +int psmash(struct page *page); > +int rmpupdate(struct page *page, struct rmpupdate *e); > #else > static inline struct rmpentry *snp_lookup_page_in_rmptable(struct page *page, int *level) > { > return NULL; > } > +static inline int psmash(struct page *page) { return -ENXIO; } > +static inline int rmpupdate(struct page *page, struct rmpupdate *e) { return -ENXIO; } > > #endif /* CONFIG_AMD_MEM_ENCRYPT */ > #endif /* __LINUX_SEV_H */ > -- > 2.17.1 > > -- Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK