Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4002019pxj; Tue, 8 Jun 2021 04:14:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzjtp1WaMZjtlgRAGaU+GJYZCdN36pv5zGH/eGyH2seg+VF5nivzLsMe08wSdBykkyLb2X4 X-Received: by 2002:a17:906:2bcc:: with SMTP id n12mr7317241ejg.430.1623150853309; Tue, 08 Jun 2021 04:14:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623150853; cv=none; d=google.com; s=arc-20160816; b=kMtyMcpw0F4eEPv9Gju8Tfgz0LNrRbqWb215emdmCWSpd2uk/FzOAU4/DBslgXQsv8 IWgZIlyt+U2Cm0qbHzPojDsDQax9C7sac6+DRwCuKdcF3jHGfvZdUNl0/Ka13nicoLR3 qzr2gIRwjETBttb64G1NzoUNqP76CtO0hdZKqj70mj4MYVySI4tTbvA8OSDujDyAG2p4 Swwzb/OLRIke60aUYqg1DTulrrKPvTFYfbHSc5S8crvcQznv59hNvvdLDZ1p5n8FPsP/ dZ89A78TPwyIQN3ImJKesqyGrqUIrfkJhX3y/K3eOZ7FAAcIJJtLDr/r72YHP7Hr0GaY dUdg== 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-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=3sPDCvRlwwIpxA2b3PcLxBUFevSmv4P/XZ/ZVXKpHEY=; b=EWI2W/IwSrC8XbGj5S5klNekJP8SxpfYALCq8UA4f3uex1OUVylpayXngvNzZXm2w7 R+K3m3+sMqB84uRrUGegmvdtVIK4sV20O3kzHkKrmA7ylQXgh39p+D4/bpM1h/RzR1ZH OLJTpky98QON9k6D0LblsUm2eI3MLPNaXV9f/lDd3OVvZqdqYpMBR8wqztBOR3azVx4B qeTnNJ7eH6nVwxrAoZtqD9PDnEk/Rg3GoQsiOLfC1Gq5D3/H7pGWnvi5Ay1OADKSOpn5 UEjArpV57Rl7U+iOE76k8zkllfK8x4KtZu9DFOK9a21933gY6xek3m5AisEYoe761NCu GeZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=pm3yWyMy; 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=NONE sp=NONE dis=NONE) header.from=alien8.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l5si15248699ejg.306.2021.06.08.04.13.42; Tue, 08 Jun 2021 04:14:13 -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=@alien8.de header.s=dkim header.b=pm3yWyMy; 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=NONE sp=NONE dis=NONE) header.from=alien8.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231680AbhFHLOb (ORCPT + 99 others); Tue, 8 Jun 2021 07:14:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44114 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230190AbhFHLOa (ORCPT ); Tue, 8 Jun 2021 07:14:30 -0400 Received: from mail.skyhub.de (mail.skyhub.de [IPv6:2a01:4f8:190:11c2::b:1457]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 23111C061574; Tue, 8 Jun 2021 04:12:37 -0700 (PDT) Received: from zn.tnic (p200300ec2f0bc9005757c3be7e9afbb5.dip0.t-ipconnect.de [IPv6:2003:ec:2f0b:c900:5757:c3be:7e9a:fbb5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id 6E0BA1EC036C; Tue, 8 Jun 2021 13:12:35 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1623150755; 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: content-transfer-encoding:in-reply-to:in-reply-to: references:references; bh=3sPDCvRlwwIpxA2b3PcLxBUFevSmv4P/XZ/ZVXKpHEY=; b=pm3yWyMyq0vfbN/1lB1/7YSiZn9GqmppzRw5hFrYhvwk6G8zDGbVnobmgbVtvU5ugIyGc2 AvNowWwi3/OJYL2ri6TSgeqQ6tZbxnkJW1XzcRYwrpPRsJY9eY4tLQhjhK0PfmioT/M5D8 XquQKU68mAu73X2MJSJsE7Wl84JJeyg= Date: Tue, 8 Jun 2021 13:12:35 +0200 From: Borislav Petkov 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 , 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 Subject: Re: [PATCH Part1 RFC v3 08/22] x86/compressed: Add helper for validating pages in the decompression stage Message-ID: References: <20210602140416.23573-1-brijesh.singh@amd.com> <20210602140416.23573-9-brijesh.singh@amd.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20210602140416.23573-9-brijesh.singh@amd.com> Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org On Wed, Jun 02, 2021 at 09:04:02AM -0500, Brijesh Singh wrote: > +static void __page_state_change(unsigned long paddr, int op) > +{ > + u64 val; > + > + if (!sev_snp_enabled()) > + return; > + > + /* > + * If private -> shared then invalidate the page before requesting the > + * state change in the RMP table. > + */ > + if ((op == SNP_PAGE_STATE_SHARED) && pvalidate(paddr, RMP_PG_SIZE_4K, 0)) > + goto e_pvalidate; > + > + /* Issue VMGEXIT to change the page state in RMP table. */ > + sev_es_wr_ghcb_msr(GHCB_MSR_PSC_REQ_GFN(paddr >> PAGE_SHIFT, op)); > + VMGEXIT(); > + > + /* Read the response of the VMGEXIT. */ > + val = sev_es_rd_ghcb_msr(); > + if ((GHCB_RESP_CODE(val) != GHCB_MSR_PSC_RESP) || GHCB_MSR_PSC_RESP_VAL(val)) > + sev_es_terminate(1, GHCB_TERM_PSC); > + > + /* > + * Now that page is added in the RMP table, validate it so that it is > + * consistent with the RMP entry. > + */ > + if ((op == SNP_PAGE_STATE_PRIVATE) && pvalidate(paddr, RMP_PG_SIZE_4K, 1)) > + goto e_pvalidate; > + > + return; > + > +e_pvalidate: > + sev_es_terminate(1, GHCB_TERM_PVALIDATE); > +} You don't even need that label, diff ontop: diff --git a/arch/x86/boot/compressed/sev.c b/arch/x86/boot/compressed/sev.c index 808fe1f6b170..dd0f22386fd2 100644 --- a/arch/x86/boot/compressed/sev.c +++ b/arch/x86/boot/compressed/sev.c @@ -146,7 +146,7 @@ static void __page_state_change(unsigned long paddr, int op) * state change in the RMP table. */ if ((op == SNP_PAGE_STATE_SHARED) && pvalidate(paddr, RMP_PG_SIZE_4K, 0)) - goto e_pvalidate; + sev_es_terminate(1, GHCB_TERM_PVALIDATE); /* Issue VMGEXIT to change the page state in RMP table. */ sev_es_wr_ghcb_msr(GHCB_MSR_PSC_REQ_GFN(paddr >> PAGE_SHIFT, op)); @@ -162,12 +162,7 @@ static void __page_state_change(unsigned long paddr, int op) * consistent with the RMP entry. */ if ((op == SNP_PAGE_STATE_PRIVATE) && pvalidate(paddr, RMP_PG_SIZE_4K, 1)) - goto e_pvalidate; - - return; - -e_pvalidate: - sev_es_terminate(1, GHCB_TERM_PVALIDATE); + sev_es_terminate(1, GHCB_TERM_PVALIDATE); } void snp_set_page_private(unsigned long paddr) -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette