From patchwork Fri Apr 2 15:26:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kirill A. Shutemov" X-Patchwork-Id: 12181183 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.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,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 07A81C43462 for ; Fri, 2 Apr 2021 15:27:03 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A1BD061179 for ; Fri, 2 Apr 2021 15:27:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A1BD061179 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=shutemov.name Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 41D176B0074; Fri, 2 Apr 2021 11:27:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 381028D0002; Fri, 2 Apr 2021 11:27:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 09BC06B0080; Fri, 2 Apr 2021 11:27:01 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0130.hostedemail.com [216.40.44.130]) by kanga.kvack.org (Postfix) with ESMTP id D39076B007D for ; Fri, 2 Apr 2021 11:27:00 -0400 (EDT) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 8846910F3D for ; Fri, 2 Apr 2021 15:27:00 +0000 (UTC) X-FDA: 77987805000.07.2747856 Received: from mail-lf1-f43.google.com (mail-lf1-f43.google.com [209.85.167.43]) by imf10.hostedemail.com (Postfix) with ESMTP id 990E440002CF for ; Fri, 2 Apr 2021 15:26:58 +0000 (UTC) Received: by mail-lf1-f43.google.com with SMTP id d13so8055535lfg.7 for ; Fri, 02 Apr 2021 08:26:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shutemov-name.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=ZjsS1bI2uKq/2mrnLoFtUTJW7+/w5vjC+pfAdCGzd/4=; b=sLsxFjLldrKmyHyURfqQVaKuUqWfHVD0j45vA/YcBUS7CK7j45ipCGAFB8I3JUaul7 EeEMeHuOsEsTv/LrV3rlZXAaQxWH6eHqX/HhMPc2amFnqgahdYRDYS01rQ3A3gNG09Q6 /wpQeMSCIKilbzP9PBU+7XDjS3/CKdHWx5T4wwUIHeCsLzuHQfv2lJ0sHOn2ypoBLhsr ffP0o/FDsjV36uhUX+CKEbJ28/nBdgfXMNS+cPDy0ExO4c6D5sPQoPmVHZnpD4tMFq0A jDdGh3Vgx9XQFa3JfbWE5j+nPUsokwi2vRJ+mCVB5TiW94Z81EUfv0ybUkXSh2ftQIiD tN/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=ZjsS1bI2uKq/2mrnLoFtUTJW7+/w5vjC+pfAdCGzd/4=; b=DYq9PxQh+cwyao+BGD60I9ZKNzE71Bx848cAypjOAuwgVh2E9Z1GJSaaoCIsrJ35CW YpdJHysGGydYAUepGTOvJBLvK50UVJHe6NEritoJO9Yc2GqiGQMLwXI0dMLEn7kBGr8Z 00DyzSBlSstsr7CespvCof343USrzwgVPKvThIQrbVxt13y3Pn5+xO3mmyHE6y6Ah04s DlICgh3Z4woSyWhiQ094cBY1/vtWfZUvur06legtnbHZzxVzm9SBZdaUFL6pOjAQKUaQ 3WhFo+yTSbz6cU52ks+9xBX6dCgSVFRqgHIQx7BvYQfRR/7x+TB8vzGll5S4H5GcorSn slCA== X-Gm-Message-State: AOAM532FjiDM9eL71tdUU3XtPJSYgRWFGmRbQFyRfWmlDuYwa3vJfird Zprq6sPLWTvIPCvV6UYOkjBwmQ== X-Google-Smtp-Source: ABdhPJz8iSga8n37GQkADy+ssjbmrF28xrjeJGW7r3kmWl1I/wA1rNnTc3V3f/miI9fjdcL6UCQoyw== X-Received: by 2002:a05:6512:21a:: with SMTP id a26mr9409958lfo.507.1617377218429; Fri, 02 Apr 2021 08:26:58 -0700 (PDT) Received: from box.localdomain ([86.57.175.117]) by smtp.gmail.com with ESMTPSA id o11sm950978ljg.42.2021.04.02.08.26.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Apr 2021 08:26:57 -0700 (PDT) From: "Kirill A. Shutemov" X-Google-Original-From: "Kirill A. Shutemov" Received: by box.localdomain (Postfix, from userid 1000) id 1E1E310257C; Fri, 2 Apr 2021 18:26:59 +0300 (+03) To: Dave Hansen , Andy Lutomirski , Peter Zijlstra , Sean Christopherson , Jim Mattson Cc: David Rientjes , "Edgecombe, Rick P" , "Kleen, Andi" , "Yamahata, Isaku" , x86@kernel.org, kvm@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Kirill A. Shutemov" Subject: [RFCv1 0/7] TDX and guest memory unmapping Date: Fri, 2 Apr 2021 18:26:38 +0300 Message-Id: <20210402152645.26680-1-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.26.3 MIME-Version: 1.0 X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 990E440002CF X-Stat-Signature: uho7zjfrtygohe4e6xa17hqugxpu1ubx Received-SPF: none (shutemov.name>: No applicable sender policy available) receiver=imf10; identity=mailfrom; envelope-from=""; helo=mail-lf1-f43.google.com; client-ip=209.85.167.43 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1617377218-875429 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. 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 (7): 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 KVM: unmap guest memory using poisoned pages 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 | 20 ++++ 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 | 15 ++- 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 | 12 ++ include/linux/swapops.h | 20 ++++ include/uapi/linux/kvm_para.h | 5 +- mm/gup.c | 31 +++-- mm/memory.c | 45 +++++++- mm/page_vma_mapped.c | 8 +- mm/rmap.c | 2 +- mm/shmem.c | 7 ++ virt/kvm/Kconfig | 3 + virt/kvm/kvm_main.c | 164 ++++++++++++++++++++++++--- 29 files changed, 442 insertions(+), 124 deletions(-) create mode 100644 arch/x86/mm/mem_encrypt_common.c