lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Thu, 26 May 2022 11:38:59 -0300
From:   Wander Lairson Costa <wander@...hat.com>
To:     Kuppuswamy Sathyanarayanan 
        <sathyanarayanan.kuppuswamy@...ux.intel.com>
Cc:     Thomas Gleixner <tglx@...utronix.de>,
        Ingo Molnar <mingo@...hat.com>, Borislav Petkov <bp@...en8.de>,
        Dave Hansen <dave.hansen@...ux.intel.com>, x86@...nel.org,
        "H . Peter Anvin" <hpa@...or.com>,
        "Kirill A . Shutemov" <kirill.shutemov@...ux.intel.com>,
        Tony Luck <tony.luck@...el.com>,
        Andi Kleen <ak@...ux.intel.com>,
        Kai Huang <kai.huang@...el.com>,
        Isaku Yamahata <isaku.yamahata@...il.com>,
        marcelo.cerri@...onical.com, tim.gardner@...onical.com,
        khalid.elmously@...onical.com, philip.cox@...onical.com,
        linux-kernel@...r.kernel.org
Subject: Re: [PATCH v7 4/5] x86/mm: Add noalias variants of
 set_memory_*crypted() functions

On Mon, May 23, 2022 at 09:05:16PM -0700, Kuppuswamy Sathyanarayanan wrote:
> set_memory_*crypted() functions are used to modify the "shared" page
> attribute of the given memory. Using these APIs will modify the page
> attributes of the aliased mappings (which also includes the direct
> mapping).
> 
> But such aliased mappings modification is not desirable in use cases
> like TDX guest, where the requirement is to create the shared mapping
> without touching the direct map. It is used when allocating VMM shared
> buffers using alloc_pages()/vmap()/set_memory_*crypted() API
> combinations.
> 
> So to support such use cases, add support for noalias variants of
> set_memory_*crypted() functions.
> 
> Signed-off-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@...ux.intel.com>
> ---
>  arch/x86/include/asm/set_memory.h |  2 ++
>  arch/x86/mm/pat/set_memory.c      | 26 ++++++++++++++++++++------
>  2 files changed, 22 insertions(+), 6 deletions(-)
> 
> diff --git a/arch/x86/include/asm/set_memory.h b/arch/x86/include/asm/set_memory.h
> index 78ca53512486..0e5fc2b818be 100644
> --- a/arch/x86/include/asm/set_memory.h
> +++ b/arch/x86/include/asm/set_memory.h
> @@ -46,7 +46,9 @@ int set_memory_wb(unsigned long addr, int numpages);
>  int set_memory_np(unsigned long addr, int numpages);
>  int set_memory_4k(unsigned long addr, int numpages);
>  int set_memory_encrypted(unsigned long addr, int numpages);
> +int set_memory_encrypted_noalias(unsigned long addr, int numpages);
>  int set_memory_decrypted(unsigned long addr, int numpages);
> +int set_memory_decrypted_noalias(unsigned long addr, int numpages);
>  int set_memory_np_noalias(unsigned long addr, int numpages);
>  int set_memory_nonglobal(unsigned long addr, int numpages);
>  int set_memory_global(unsigned long addr, int numpages);
> diff --git a/arch/x86/mm/pat/set_memory.c b/arch/x86/mm/pat/set_memory.c
> index 0656db33574d..4475f6e3bebb 100644
> --- a/arch/x86/mm/pat/set_memory.c
> +++ b/arch/x86/mm/pat/set_memory.c
> @@ -1976,7 +1976,8 @@ int set_memory_global(unsigned long addr, int numpages)
>   * __set_memory_enc_pgtable() is used for the hypervisors that get
>   * informed about "encryption" status via page tables.
>   */
> -static int __set_memory_enc_pgtable(unsigned long addr, int numpages, bool enc)
> +static int __set_memory_enc_pgtable(unsigned long addr, int numpages,
> +		bool enc, int checkalias)
>  {
>  	pgprot_t empty = __pgprot(0);
>  	struct cpa_data cpa;
> @@ -2004,7 +2005,7 @@ static int __set_memory_enc_pgtable(unsigned long addr, int numpages, bool enc)
>  	/* Notify hypervisor that we are about to set/clr encryption attribute. */
>  	x86_platform.guest.enc_status_change_prepare(addr, numpages, enc);
>  
> -	ret = __change_page_attr_set_clr(&cpa, 1);
> +	ret = __change_page_attr_set_clr(&cpa, checkalias);
>  
>  	/*
>  	 * After changing the encryption attribute, we need to flush TLBs again
> @@ -2024,29 +2025,42 @@ static int __set_memory_enc_pgtable(unsigned long addr, int numpages, bool enc)
>  	return ret;
>  }
>  
> -static int __set_memory_enc_dec(unsigned long addr, int numpages, bool enc)
> +static int __set_memory_enc_dec(unsigned long addr, int numpages, bool enc,
> +		int checkalias)
>  {
>  	if (hv_is_isolation_supported())
>  		return hv_set_mem_host_visibility(addr, numpages, !enc);
>  
>  	if (cc_platform_has(CC_ATTR_MEM_ENCRYPT))
> -		return __set_memory_enc_pgtable(addr, numpages, enc);
> +		return __set_memory_enc_pgtable(addr, numpages, enc, checkalias);
>  
>  	return 0;
>  }
>  
>  int set_memory_encrypted(unsigned long addr, int numpages)
>  {
> -	return __set_memory_enc_dec(addr, numpages, true);
> +	return __set_memory_enc_dec(addr, numpages, true, 1);
>  }
>  EXPORT_SYMBOL_GPL(set_memory_encrypted);
>  
>  int set_memory_decrypted(unsigned long addr, int numpages)
>  {
> -	return __set_memory_enc_dec(addr, numpages, false);
> +	return __set_memory_enc_dec(addr, numpages, false, 1);
>  }
>  EXPORT_SYMBOL_GPL(set_memory_decrypted);
>  
> +int set_memory_encrypted_noalias(unsigned long addr, int numpages)
> +{
> +	return __set_memory_enc_dec(addr, numpages, true, 0);
> +}
> +EXPORT_SYMBOL_GPL(set_memory_encrypted_noalias);
> +
> +int set_memory_decrypted_noalias(unsigned long addr, int numpages)
> +{
> +	return __set_memory_enc_dec(addr, numpages, false, 0);
> +}
> +EXPORT_SYMBOL_GPL(set_memory_decrypted_noalias);
> +
>  int set_pages_uc(struct page *page, int numpages)
>  {
>  	unsigned long addr = (unsigned long)page_address(page);
> -- 
> 2.25.1
> 
> 

Acked-by: Wander Lairson Costa <wander@...hat.com>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ