Received: by 2002:a05:6a10:8a4d:0:0:0:0 with SMTP id dn13csp706268pxb; Fri, 13 Aug 2021 04:41:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyJNzwjWe7h96TaC4HRqlxxumRINi0UoxscskJiRQOTdtQ/dvnxi+JY+R9a1oCuG4i5HL3D X-Received: by 2002:a05:6402:518c:: with SMTP id q12mr2476081edd.205.1628854909849; Fri, 13 Aug 2021 04:41:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628854909; cv=none; d=google.com; s=arc-20160816; b=WETAL4XI8iUs/zWnYJ3whBKPQjQDNecMM8iiZ0ICgS0CUkovnFxdtM+S8wk28sxEBa ozW1D0ADxUkwU1upjkX1eMghr42HSe+zHRJTHrqIcd0M4yll1a9VYkBs4xeCpValIV+S ZorcEe7Pow7GYlk/k7s2IxIuFnHCsL6Hlu2aOgq457G8i0+bCENgi1sqjhZK2Ol2qPtg aUo0u7LT3Rpz/R6ZfGPEUDxR16ojM5ISmdEtHas1RsciemBxms02xU/2W+TyIOaCV44R f09zI2oQhTo1tI1yhXe6CnxusgWxx05JlqWm2HZHSdiN63gPTQbeukRur3XnCXoN96zX jyaQ== 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=BrEpox4JFTOv//FkK1+++liPSNoSwrYzYIAmzeG1Vvg=; b=h5jcC1MK9MDWLKxSRSN/pSfASOPfLi9jaoRvE8VCqXT46X5oOOSztMXr2CSJoEgRIu vfm13FX1NfzvDlHHF+yqF/vNhM6ek4cdY8hRLl2NL+LGsftqqS8ok1b2Z2YO3FHk9Tu9 40eN+kN4lGl6ZoofZU/4Y8PzI9VBOltoqYypfchS7sPK0J1ngYJybYGzvAVjm9BeQBLy x6m7z3kYvY35b98qa0gj/ye8Gs3oWCDma8cU9Dsq7+lFfgz/Nd6UmCUD0Zb65DObRnPh IZoYsnlfy1iOh5psl1fGy6CIUEWy2JCIi3Pe4J7wxQ+YftERAjpHMHHx+O+t03t+fmUD oigA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b="rrhY/wFP"; 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 ho38si1385901ejc.727.2021.08.13.04.41.15; Fri, 13 Aug 2021 04:41:49 -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="rrhY/wFP"; 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 S240024AbhHMKWx (ORCPT + 99 others); Fri, 13 Aug 2021 06:22:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36890 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239357AbhHMKWx (ORCPT ); Fri, 13 Aug 2021 06:22:53 -0400 Received: from mail.skyhub.de (mail.skyhub.de [IPv6:2a01:4f8:190:11c2::b:1457]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD161C0617AD; Fri, 13 Aug 2021 03:22:26 -0700 (PDT) Received: from zn.tnic (p200300ec2f0a0d0079874d21390dee82.dip0.t-ipconnect.de [IPv6:2003:ec:2f0a:d00:7987:4d21:390d:ee82]) (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 179861EC0390; Fri, 13 Aug 2021 12:22:21 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1628850141; 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=BrEpox4JFTOv//FkK1+++liPSNoSwrYzYIAmzeG1Vvg=; b=rrhY/wFPs01PzwPngi2OvYsBOn3Oj+mOPU4ppqg2QD3QMMpo5HPrRQksILGK2tbPzMNL/P /Z+q2NCpFwOZGLfgdVjlJd5AbybcSaH0RK4p4eLjvedsqwEIBCnfou68aXrXhezqElb99A CyzdpLOPT9knQnU7SkvRJRi/bsKl6e0= Date: Fri, 13 Aug 2021 12:22:59 +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 , Dov Murik , Tobin Feldman-Fitzthum , Michael Roth , Vlastimil Babka , tony.luck@intel.com, npmccallum@redhat.com, brijesh.ksingh@gmail.com Subject: Re: [PATCH Part1 RFC v4 09/36] x86/compressed: Add helper for validating pages in the decompression stage Message-ID: References: <20210707181506.30489-1-brijesh.singh@amd.com> <20210707181506.30489-10-brijesh.singh@amd.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20210707181506.30489-10-brijesh.singh@amd.com> Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org On Wed, Jul 07, 2021 at 01:14:39PM -0500, Brijesh Singh wrote: > @@ -274,16 +274,31 @@ static int set_clr_page_flags(struct x86_mapping_info *info, > /* > * Changing encryption attributes of a page requires to flush it from > * the caches. > + * > + * If the encryption attribute is being cleared, then change the page > + * state to shared in the RMP table. That comment... > */ > - if ((set | clr) & _PAGE_ENC) > + if ((set | clr) & _PAGE_ENC) { > clflush_page(address); > ... goes here: <--- > + if (clr) > + snp_set_page_shared(pte_pfn(*ptep) << PAGE_SHIFT); > + } > + ... > diff --git a/arch/x86/boot/compressed/sev.c b/arch/x86/boot/compressed/sev.c > index 2f3081e9c78c..f386d45a57b6 100644 > --- a/arch/x86/boot/compressed/sev.c > +++ b/arch/x86/boot/compressed/sev.c > @@ -164,6 +164,47 @@ static bool is_vmpl0(void) > return true; > } > > +static void __page_state_change(unsigned long paddr, int op) That op should be: enum psc_op { SNP_PAGE_STATE_SHARED, SNP_PAGE_STATE_PRIVATE, }; and have static void __page_state_change(unsigned long paddr, enum psc_op op) so that the compiler can check you're at least passing from the correct set of defines. > diff --git a/arch/x86/include/asm/sev-common.h b/arch/x86/include/asm/sev-common.h > index ea508835ab33..aee07d1bb138 100644 > --- a/arch/x86/include/asm/sev-common.h > +++ b/arch/x86/include/asm/sev-common.h > @@ -45,6 +45,23 @@ > (((unsigned long)reg & GHCB_MSR_CPUID_REG_MASK) << GHCB_MSR_CPUID_REG_POS) | \ > (((unsigned long)fn) << GHCB_MSR_CPUID_FUNC_POS)) > > +/* SNP Page State Change */ > +#define GHCB_MSR_PSC_REQ 0x014 > +#define SNP_PAGE_STATE_PRIVATE 1 > +#define SNP_PAGE_STATE_SHARED 2 > +#define GHCB_MSR_PSC_GFN_POS 12 > +#define GHCB_MSR_PSC_GFN_MASK GENMASK_ULL(39, 0) > +#define GHCB_MSR_PSC_OP_POS 52 > +#define GHCB_MSR_PSC_OP_MASK 0xf > +#define GHCB_MSR_PSC_REQ_GFN(gfn, op) \ > + (((unsigned long)((op) & GHCB_MSR_PSC_OP_MASK) << GHCB_MSR_PSC_OP_POS) | \ > + ((unsigned long)((gfn) & GHCB_MSR_PSC_GFN_MASK) << GHCB_MSR_PSC_GFN_POS) | \ > + GHCB_MSR_PSC_REQ) > + > +#define GHCB_MSR_PSC_RESP 0x015 > +#define GHCB_MSR_PSC_ERROR_POS 32 > +#define GHCB_MSR_PSC_RESP_VAL(val) ((val) >> GHCB_MSR_PSC_ERROR_POS) > + Also get rid of eccessive defines... -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette