From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2853EC43460 for ; Fri, 16 Apr 2021 15:41:44 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9CA69613B4 for ; Fri, 16 Apr 2021 15:41:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9CA69613B4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 704818D0003; Fri, 16 Apr 2021 11:41:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 618E18D0002; Fri, 16 Apr 2021 11:41:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2E3186B0074; Fri, 16 Apr 2021 11:41:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0101.hostedemail.com [216.40.44.101]) by kanga.kvack.org (Postfix) with ESMTP id D22916B0036 for ; Fri, 16 Apr 2021 11:41:39 -0400 (EDT) Received: from smtpin16.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 45E69180CA82B for ; Fri, 16 Apr 2021 15:41:39 +0000 (UTC) X-FDA: 78038645118.16.3B26F04 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by imf17.hostedemail.com (Postfix) with ESMTP id CC25D40002E3 for ; Fri, 16 Apr 2021 15:41:35 +0000 (UTC) IronPort-SDR: myqb9sfdLtDMTz9uCsf4I+bIRKV+hTkWwCOI/4AqsvEyT6c61mytwwx4hhJPRQmLfUXqRV807U oxmIPU9ZoAxg== X-IronPort-AV: E=McAfee;i="6200,9189,9956"; a="175163909" X-IronPort-AV: E=Sophos;i="5.82,226,1613462400"; d="scan'208";a="175163909" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Apr 2021 08:41:36 -0700 IronPort-SDR: JHSnJpXle56RA6NOpktcidrINTGGvy+pVP+IY3njKrzX6L3ewV0BhUmmbMqeo9bSv6+cmm05xB WB9eJa8RjXkg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.82,226,1613462400"; d="scan'208";a="453378435" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga002.fm.intel.com with ESMTP; 16 Apr 2021 08:41:32 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id C158A12A; Fri, 16 Apr 2021 18:41:49 +0300 (EEST) From: "Kirill A. Shutemov" To: Dave Hansen , Andy Lutomirski , Peter Zijlstra , Sean Christopherson , Jim Mattson Cc: David Rientjes , "Edgecombe, Rick P" , "Kleen, Andi" , "Yamahata, Isaku" , Erdem Aktas , Steve Rutherford , Peter Gonda , David Hildenbrand , x86@kernel.org, kvm@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Kirill A. Shutemov" Subject: [RFCv2 00/13] TDX and guest memory unmapping Date: Fri, 16 Apr 2021 18:40:53 +0300 Message-Id: <20210416154106.23721-1-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: CC25D40002E3 X-Stat-Signature: rm6rydmbtmdzdtirtb917z5ddan5wnpo Received-SPF: none (linux.intel.com>: No applicable sender policy available) receiver=imf17; identity=mailfrom; envelope-from=""; helo=mga17.intel.com; client-ip=192.55.52.151 X-HE-DKIM-Result: none/none X-HE-Tag: 1618587695-415191 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: TDX integrity check failures may lead to system shutdown host kernel must not allow any writes to TD-private memory. This requirment clashes with KVM design: KVM expects the guest memory to be mapped into host userspace (e.g. QEMU). This patchset aims to start discussion on how we can approach the issue. The core of the change is in the last patch. Please see more detailed description of the issue and proposoal of the solution there. TODO: - THP support - Clarify semantics wrt. page cache v2: - Unpoison page on free - Authorize access to the page: only the KVM that poisoned the page allows to touch it - FOLL_ALLOW_POISONED is implemented The patchset can also be found here: git://git.kernel.org/pub/scm/linux/kernel/git/kas/linux.git kvm-unmapped-= poison Kirill A. Shutemov (13): x86/mm: Move force_dma_unencrypted() to common code x86/kvm: Introduce KVM memory protection feature x86/kvm: Make DMA pages shared x86/kvm: Use bounce buffers for KVM memory protection x86/kvmclock: Share hvclock memory with the host x86/realmode: Share trampoline area if KVM memory protection enabled mm: Add hwpoison_entry_to_pfn() and hwpoison_entry_to_page() mm/gup: Add FOLL_ALLOW_POISONED shmem: Fail shmem_getpage_gfp() on poisoned pages mm: Keep page reference for hwpoison entries mm: Replace hwpoison entry with present PTE if page got unpoisoned KVM: passdown struct kvm to hva_to_pfn_slow() KVM: unmap guest memory using poisoned pages arch/powerpc/kvm/book3s_64_mmu_hv.c | 2 +- arch/powerpc/kvm/book3s_64_mmu_radix.c | 2 +- arch/x86/Kconfig | 9 +- arch/x86/include/asm/cpufeatures.h | 1 + arch/x86/include/asm/io.h | 4 +- arch/x86/include/asm/kvm_para.h | 5 + arch/x86/include/asm/mem_encrypt.h | 7 +- arch/x86/include/uapi/asm/kvm_para.h | 3 +- arch/x86/kernel/kvm.c | 19 +++ arch/x86/kernel/kvmclock.c | 2 +- arch/x86/kernel/pci-swiotlb.c | 3 +- arch/x86/kvm/Kconfig | 1 + arch/x86/kvm/cpuid.c | 3 +- arch/x86/kvm/mmu/mmu.c | 20 ++- arch/x86/kvm/mmu/paging_tmpl.h | 10 +- arch/x86/kvm/x86.c | 6 + arch/x86/mm/Makefile | 2 + arch/x86/mm/mem_encrypt.c | 74 --------- arch/x86/mm/mem_encrypt_common.c | 87 ++++++++++ arch/x86/mm/pat/set_memory.c | 10 ++ arch/x86/realmode/init.c | 7 +- include/linux/kvm_host.h | 31 +++- include/linux/mm.h | 1 + include/linux/swapops.h | 20 +++ include/uapi/linux/kvm_para.h | 5 +- mm/gup.c | 29 ++-- mm/memory.c | 44 ++++- mm/page_alloc.c | 7 + mm/rmap.c | 2 +- mm/shmem.c | 7 + virt/Makefile | 2 +- virt/kvm/Kconfig | 4 + virt/kvm/Makefile | 1 + virt/kvm/kvm_main.c | 212 +++++++++++++++++++------ virt/kvm/mem_protected.c | 110 +++++++++++++ 35 files changed, 593 insertions(+), 159 deletions(-) create mode 100644 arch/x86/mm/mem_encrypt_common.c create mode 100644 virt/kvm/Makefile create mode 100644 virt/kvm/mem_protected.c --=20 2.26.3