Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1684161pxb; Wed, 20 Oct 2021 09:45:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwbE2Dvak4nSLaXLcjQ7ACj9YFPVe5i8NVo+ebOLkhDMFJ99UyA7M9kS900Em1w2wtwFH5E X-Received: by 2002:a17:902:6808:b0:13e:a85b:52bd with SMTP id h8-20020a170902680800b0013ea85b52bdmr99642plk.76.1634748302465; Wed, 20 Oct 2021 09:45:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634748302; cv=none; d=google.com; s=arc-20160816; b=fXAsQbGXDz347nN87ZG8PZhuiffRbLiRHdGlQm+qcRMRE4xo78mdVnxCJUYewxV5ep GBTKdRmifrFS+eTKhogEmzAs9chfpmH9Jrh4ylrhnicPwEzw6XjJADchL0d0i/wqToEE v6T76s4r99OI1w/6F3HkeyIUzQ6NSbzBDZE3RKCXwvgqgHl8xvIPCmKel6BhCQSMxIZa EQMY4E/OOV5bBwmoBnOn3taDe1dEiJlVLN27ImEHg/ENYz4EewpDesOkAxN6afzk6kkj D3HCnsVPBwwUldH4HyYK5jmsa3yDS36zBkyqHCwG6yGbxtHpBgU006FdJI/6gsh5bA4Y QL8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=9V+8rul2u7rTv7duCIPwiAQnngf6T0tukRAReXsW6vM=; b=KSbZoHcPB+WVPlqKesYSKlYEg/DvGCOvBi6SzCM5Ho2gKxHgp4EtpM/KXSsKvJH6yl RAoW1da8nf1aYrHgpv7xsXG1W6Srd224aTWA6Wpj7+oP0tdDKYFK5H5lH5geXi855cwL q/WHxq6OtwYbaKjZ4j8Z7npo7vKqGX9f2bA8Ne/cfijYRLa8CLAl2o/axyKylT9uDb2f DoiQC2QUx+Uu+cClVoyQaoSu5N0SKrSpm483LA1Vy9mC5XDPG43CHrYWuUeW96KI3CXS 0Oos+ObUCPLcGZc2z4BTj+qbxIHAqAgGPFfllZJwGGZBFDKomDGeVrZ5X2dHNK5NVe4C oipQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w1si3200881plz.130.2021.10.20.09.44.49; Wed, 20 Oct 2021 09:45:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230020AbhJTQqA (ORCPT + 99 others); Wed, 20 Oct 2021 12:46:00 -0400 Received: from mga14.intel.com ([192.55.52.115]:16711 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230049AbhJTQp7 (ORCPT ); Wed, 20 Oct 2021 12:45:59 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10143"; a="229099652" X-IronPort-AV: E=Sophos;i="5.87,167,1631602800"; d="scan'208";a="229099652" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Oct 2021 09:43:45 -0700 X-IronPort-AV: E=Sophos;i="5.87,167,1631602800"; d="scan'208";a="720485176" Received: from yakasaka-mobl1.gar.corp.intel.com (HELO skuppusw-desk1.amr.corp.intel.com) ([10.254.9.165]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Oct 2021 09:43:43 -0700 Subject: Re: [PATCH v5 01/16] x86/mm: Move force_dma_unencrypted() to common code To: Tom Lendacky , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Peter Zijlstra , Andy Lutomirski , Bjorn Helgaas , Richard Henderson , Thomas Bogendoerfer , James E J Bottomley , Helge Deller , "David S . Miller" , Arnd Bergmann , Jonathan Corbet , "Michael S . Tsirkin" , Paolo Bonzini , David Hildenbrand , Andrea Arcangeli , Josh Poimboeuf Cc: Peter H Anvin , Dave Hansen , Tony Luck , Dan Williams , Andi Kleen , Kirill Shutemov , Sean Christopherson , Kuppuswamy Sathyanarayanan , x86@kernel.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, linux-alpha@vger.kernel.org, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, sparclinux@vger.kernel.org, linux-arch@vger.kernel.org, linux-doc@vger.kernel.org, virtualization@lists.linux-foundation.org References: <20211009003711.1390019-1-sathyanarayanan.kuppuswamy@linux.intel.com> <20211009003711.1390019-2-sathyanarayanan.kuppuswamy@linux.intel.com> <72b8be39-b4e2-5d77-524c-a2ea0c750ab1@amd.com> From: Sathyanarayanan Kuppuswamy Message-ID: Date: Wed, 20 Oct 2021 09:43:43 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Firefox/78.0 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: <72b8be39-b4e2-5d77-524c-a2ea0c750ab1@amd.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 10/20/21 9:11 AM, Tom Lendacky wrote: >> Intel TDX doesn't allow VMM to access guest private memory. Any memory >> that is required for communication with VMM must be shared explicitly >> by setting the bit in page table entry. After setting the shared bit, >> the conversion must be completed with MapGPA hypercall. Details about >> MapGPA hypercall can be found in [1], sec 3.2. >> >> The call informs VMM about the conversion between private/shared >> mappings. The shared memory is similar to unencrypted memory in AMD >> SME/SEV terminology but the underlying process of sharing/un-sharing >> the memory is different for Intel TDX guest platform. >> >> SEV assumes that I/O devices can only do DMA to "decrypted" physical >> addresses without the C-bit set. In order for the CPU to interact with >> this memory, the CPU needs a decrypted mapping. To add this support, >> AMD SME code forces force_dma_unencrypted() to return true for >> platforms that support AMD SEV feature. It will be used for DMA memory >> allocation API to trigger set_memory_decrypted() for platforms that >> support AMD SEV feature. >> >> TDX is similar. So, to communicate with I/O devices, related pages need >> to be marked as shared. As mentioned above, shared memory in TDX >> architecture is similar to decrypted memory in AMD SME/SEV. So similar >> to AMD SEV, force_dma_unencrypted() has to forced to return true. This >> support is added in other patches in this series. >> >> So move force_dma_unencrypted() out of AMD specific code and call AMD >> specific (amd_force_dma_unencrypted()) initialization function from it. >> force_dma_unencrypted() will be modified by later patches to include >> Intel TDX guest platform specific initialization. >> >> Also, introduce new config option X86_MEM_ENCRYPT_COMMON that has to be >> selected by all x86 memory encryption features. This will be selected >> by both AMD SEV and Intel TDX guest config options. >> >> This is preparation for TDX changes in DMA code and it has no >> functional change. > > Can force_dma_unencrypted() be moved to arch/x86/kernel/cc_platform.c, > instead of creating a new file? It might fit better with patch #6. Please check the final version of mem_encrypt_common.c https://github.com/intel/tdx/blob/guest/arch/x86/mm/mem_encrypt_common.c I am not sure whether it is alright to move mem_encrypt_init() and arch_has_restricted_virtio_memory_access() to cc_platform.c If this is fine, I can get rid of mem_encrypt_common.c -- Sathyanarayanan Kuppuswamy Linux Kernel Developer