Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp680686ioo; Thu, 26 May 2022 12:05:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxTe5cLJLxTGlOfAgi5Sk1zJ39VnNbC+ZNzKeH6KxODnTCAOqzZA0rHiY3NJ4jhSDqJaTad X-Received: by 2002:a17:906:a219:b0:6e4:86a3:44ea with SMTP id r25-20020a170906a21900b006e486a344eamr35822242ejy.385.1653591911805; Thu, 26 May 2022 12:05:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653591911; cv=none; d=google.com; s=arc-20160816; b=VZahJfl6nzQ8DxUd3QqIJFwIDnfRaDoPgefyFLJaWrKt+6rkaF/xaCusRAPOmlL6f+ UEf6IISI4dfvxVY0Hai6raJgJGN5aZsa341kDA7ubza8Ef5d6DTv0gzk5CVMYtwlccqi H1LoTlxcqNr9rKVvHzsOFg/aHlFMCqXL0vDwGDiDj3EGMVYOBl77EjsNTKPaQw6JquB6 k9lLLUv/jPh3JJnNhp3UFoK7iv8p+AJ3qrCyK85AMx2ZMbu9IDoQLUNkcXHhUOZ7bq1r 8OafZylga1EFdpQ+AhsP0Cz3/XjuAxWZMG1qLz12hMlq1uIjHNhPS4KL2qoJe4z3V8EW QeCw== 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=ml+pRF/A/MpBrIvAqGV2py687V13DhTfdNhix+Imz6s=; b=pDRezrMTti2yRciC9KJpjXuBZ65aZQk3uLAy5B/Cqg8I1iaxfUp73OweiRe8EdtrK8 tdES4a6tKba8tSrlI9CJFED1Ob7DZiPAeXMwEKEbuQWMXN9xzICpAs3gd0Wc0LbiyW3T KbSUTKc5PJiLz+S5Qp398aB5FZ3sWKlsqd4eXiDwqATfVfGKS4F3ZnEoJ39/BdRFdXep 7LdioX4k4ds2WGZmNw0JaZMo+J6Pb9aZJRca1Cyyxo658JeiI+DvsRIsALxF9CwiScBn 5wLEwDr5bGcKDA8Z+EsZiB+sJE+USYK3j5yx8A9K2HLIgRyTSi1kw02srcFXgI1Eoupo x2XQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="GNTT/nCC"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id di5-20020a170906730500b006feb145361esi878204ejc.746.2022.05.26.12.04.32; Thu, 26 May 2022 12:05:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="GNTT/nCC"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234915AbiEZOjf (ORCPT + 99 others); Thu, 26 May 2022 10:39:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37206 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347685AbiEZOjK (ORCPT ); Thu, 26 May 2022 10:39:10 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C127ECEBB9 for ; Thu, 26 May 2022 07:39:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1653575948; 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=ml+pRF/A/MpBrIvAqGV2py687V13DhTfdNhix+Imz6s=; b=GNTT/nCCWgCuPVNf1iLs0n/xhs2UvWRXAP3u7EzuHHmGIt2D/ede6VvTbWMb3GTvU0EVkL u+bSWIvwy52IWO9ICs0Ra4pMH/87B+C7xukiSCydnTRcx8guMfnxfEB24UqkhEuYSJZqcu vRh/90iWyhWRSF9+HhYcfModfr1N2I4= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-193-TK7Fj8qpMgi-tpJwKQW5FA-1; Thu, 26 May 2022 10:39:04 -0400 X-MC-Unique: TK7Fj8qpMgi-tpJwKQW5FA-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A13EE966222; Thu, 26 May 2022 14:39:03 +0000 (UTC) Received: from fedora (unknown [10.22.16.201]) by smtp.corp.redhat.com (Postfix) with SMTP id 70B7B1410DD5; Thu, 26 May 2022 14:39:00 +0000 (UTC) Date: Thu, 26 May 2022 11:38:59 -0300 From: Wander Lairson Costa To: Kuppuswamy Sathyanarayanan Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H . Peter Anvin" , "Kirill A . Shutemov" , Tony Luck , Andi Kleen , Kai Huang , Isaku Yamahata , marcelo.cerri@canonical.com, tim.gardner@canonical.com, khalid.elmously@canonical.com, philip.cox@canonical.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH v7 4/5] x86/mm: Add noalias variants of set_memory_*crypted() functions Message-ID: References: <20220524040517.703581-1-sathyanarayanan.kuppuswamy@linux.intel.com> <20220524040517.703581-5-sathyanarayanan.kuppuswamy@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220524040517.703581-5-sathyanarayanan.kuppuswamy@linux.intel.com> X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 X-Spam-Status: No, score=-3.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 > --- > 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