From patchwork Wed Jan 22 15:27:29 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fuad Tabba X-Patchwork-Id: 13947428 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 215B5C02181 for ; Wed, 22 Jan 2025 15:27:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 86B916B0085; Wed, 22 Jan 2025 10:27:44 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 81BB06B0088; Wed, 22 Jan 2025 10:27:44 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6BCEE6B0089; Wed, 22 Jan 2025 10:27:44 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 4D2AD6B0085 for ; Wed, 22 Jan 2025 10:27:44 -0500 (EST) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id C02D91603EB for ; Wed, 22 Jan 2025 15:27:43 +0000 (UTC) X-FDA: 83035467606.24.34E1439 Received: from mail-wm1-f74.google.com (mail-wm1-f74.google.com [209.85.128.74]) by imf04.hostedemail.com (Postfix) with ESMTP id 0448C40002 for ; Wed, 22 Jan 2025 15:27:41 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=SlWiRlu1; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf04.hostedemail.com: domain of 3bA6RZwUKCBEArssrx55x2v.t532z4BE-331Crt1.58x@flex--tabba.bounces.google.com designates 209.85.128.74 as permitted sender) smtp.mailfrom=3bA6RZwUKCBEArssrx55x2v.t532z4BE-331Crt1.58x@flex--tabba.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1737559662; a=rsa-sha256; cv=none; b=JCADNQ0XUEPR9HH+wMfcDsPp6gCDecLbPHX7oCRiySy8X/qess7qi7ETOnAJADdMaVJdTh bayOH+z24Yf0mCCZ6GbG7wEp/1woiIMYxZ7tGCBOVqkedigNz1qcI4Ew2+C5bZ/i1o+mXB GLZUJ/U1nrA9qepkPXiQn7zd/haRX60= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=SlWiRlu1; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf04.hostedemail.com: domain of 3bA6RZwUKCBEArssrx55x2v.t532z4BE-331Crt1.58x@flex--tabba.bounces.google.com designates 209.85.128.74 as permitted sender) smtp.mailfrom=3bA6RZwUKCBEArssrx55x2v.t532z4BE-331Crt1.58x@flex--tabba.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1737559662; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=hUlZwtZNQ+0WbUZT+N6HTTUa81FjTajN+tozduRl9ck=; b=Hc2ytoskZ3aLqK9p0IcCy8LpkQq3Qx9f+bdEMndt3Uod6ndT4/SIwVwOPuU/AQOiAY6S8b t+AhY/U/hNRaQ5kSXLRq7V0Eje7TKPBaeMZXIkD+V8IczaxnWZP/v+X4cXtgcFeykab7cC KeqSxAw9F/ZWLruSVhzpY2FeXVLLx8Y= Received: by mail-wm1-f74.google.com with SMTP id 5b1f17b1804b1-4362552ce62so36459885e9.0 for ; Wed, 22 Jan 2025 07:27:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1737559660; x=1738164460; darn=kvack.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=hUlZwtZNQ+0WbUZT+N6HTTUa81FjTajN+tozduRl9ck=; b=SlWiRlu1F8hN7IV8MRsy7XIW5ViPWow4IyeIPIkoR0RC1ker3JekKsh4k7XdINjeZr m78hPE/xqtxeMjq2UOqAogcVZoDMpIXBt1SHk2O9cuZTyND7uLuJvivRlWuRIecM5rZ1 9AiQmSO4gB3icLhoLfQ0ufFWbbSGisn+TnNdwW0JhdyG9I9DrBNFSvieFjel1hX3Usp8 vEdlAKsiWjhckG+BErgNSMmePkz6ClbRrclV4U5xqFR8u3YCtZxrNqKD0WHxa9EXiAL4 iz9eJe7jLwRaWn1spAx/JQJ6RrEBkfC23w/2N4L7aDhFmiPJy9W24F7hic3eYMr7NJXK b6XQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737559660; x=1738164460; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=hUlZwtZNQ+0WbUZT+N6HTTUa81FjTajN+tozduRl9ck=; b=NJwJWTVxCXThhWW7j+gEMgV1oS3mcZnhpeA6K3k6TC9uLVkRl6O0bFYPvsaScbjkNg 0VEvI/iqTgn24wb6y3eOzonILQgZlGtvCaCtd1FK0UKyVjMSVBhuDRNQAfT7wA14FI4n RG5hpAXrNlrLUL5q9P1yKcBtmmpeIFvCNh179xaFdCqTs/taeRoKmiGgZt4VWU8qHK0b ILaDvPVnml0G75+iTwAjTqFRxguMsJX831oDblALkowNUDR5IH3kgv5cQqJMOoAEQ1+3 qPLZbORgKgAbLZH6bLsmc5q3UaX3PU15BPUenIVY6FyTTfXY7j3B/UJqfI27FEEvgOqN D0dw== X-Forwarded-Encrypted: i=1; AJvYcCV4rLhwGMCr24akJJi15sMAe+ZJ2EYdYrKNfI+7jD2qLpKpqdRvhk4DI3HAae3hn8+984og6783sQ==@kvack.org X-Gm-Message-State: AOJu0YxyPTfi8878TWlIQB6upfzQNFegMefT+awKGL/QgbJex04MDWhl 75EqzQrZBtqAxnkyDrQGGm32Ku+kt5re9g0olwD3H3FWgXUJ/cwwppYOUHt3bBZE4x7qcduRaA= = X-Google-Smtp-Source: AGHT+IGlxCTs9CCgxMjMw6rARxYZ9Zc0l91dOQzdNksXlO8dehmJjHKu3LgJYvypsZ2Om7YcLwpnK3FMEA== X-Received: from wmqp4.prod.google.com ([2002:a05:600c:3584:b0:436:d819:e4eb]) (user=tabba job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:1da8:b0:434:a711:ace4 with SMTP id 5b1f17b1804b1-4389eca3ca1mr207276765e9.17.1737559660568; Wed, 22 Jan 2025 07:27:40 -0800 (PST) Date: Wed, 22 Jan 2025 15:27:29 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.48.0.rc2.279.g1de40edade-goog Message-ID: <20250122152738.1173160-1-tabba@google.com> Subject: [RFC PATCH v1 0/9] KVM: Mapping of guest_memfd at the host and a software protected VM type From: Fuad Tabba To: kvm@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-mm@kvack.org Cc: pbonzini@redhat.com, chenhuacai@kernel.org, mpe@ellerman.id.au, anup@brainfault.org, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, seanjc@google.com, viro@zeniv.linux.org.uk, brauner@kernel.org, willy@infradead.org, akpm@linux-foundation.org, xiaoyao.li@intel.com, yilun.xu@intel.com, chao.p.peng@linux.intel.com, jarkko@kernel.org, amoorthy@google.com, dmatlack@google.com, yu.c.zhang@linux.intel.com, isaku.yamahata@intel.com, mic@digikod.net, vbabka@suse.cz, vannapurve@google.com, ackerleytng@google.com, mail@maciej.szmigiero.name, david@redhat.com, michael.roth@amd.com, wei.w.wang@intel.com, liam.merwick@oracle.com, isaku.yamahata@gmail.com, kirill.shutemov@linux.intel.com, suzuki.poulose@arm.com, steven.price@arm.com, quic_eberman@quicinc.com, quic_mnalajal@quicinc.com, quic_tsoni@quicinc.com, quic_svaddagi@quicinc.com, quic_cvanscha@quicinc.com, quic_pderrin@quicinc.com, quic_pheragu@quicinc.com, catalin.marinas@arm.com, james.morse@arm.com, yuzenghui@huawei.com, oliver.upton@linux.dev, maz@kernel.org, will@kernel.org, qperret@google.com, keirf@google.com, roypat@amazon.co.uk, shuah@kernel.org, hch@infradead.org, jgg@nvidia.com, rientjes@google.com, jhubbard@nvidia.com, fvdl@google.com, hughd@google.com, jthoughton@google.com, tabba@google.com X-Rspam-User: X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 0448C40002 X-Stat-Signature: xmwcj915iyk4q7ijqpn1idjud6kpf598 X-HE-Tag: 1737559661-937945 X-HE-Meta: U2FsdGVkX19rR8mbxcxRSbTS3K+33Z5fTTRSxQN8ypTDxZpqc0eq6GkAGOHb8TFbebeAarb0hSsTKIJuPSyo9sEzXeGkPBYBFbAVvSOVXq/mhhFkP4jWQj+2PT/robcZDcmLs/3ket/yfEmhTGjwca5WfDVct+hoODPyQSwiO3eQQmiTbKhxftM2aF1F7hFzDAUnkw/jZHGrLVxjN/unlcWFb2ZbZ3x/Q5vVH93WrPGeeqLwjSOxIMeDLG633pGwxY47cxrt6e84wZ0Tyt+9HAaaTC3PejvWW8f8Al7KtRyTM7jU6pAG1dOIOshw1iu8yKaKmfNAMwc9MU4oDc04Al4agHbrqj1S7i0auoCpMWNu0JP37XArx6k8weomvecSgnBW1/tBh9NJhjXEp9CLHr/J3sNyPpaFwkLujYlr/86BxmIZy0X0cw944vpwwpVvRUMNVa8APxUS7M4rDrR+0YolJH63RQHwqMsLtmNjJ+NOUQI/jjZoatLxsF5kUAbacRXHYhAyJDnsJ6lwpu32yt57xCRopzHkTprNlM7xYAP6tUgD0JMUE+KShU3NmfRqPKwq5KuxUbVukvUVooOnJjCuWS2JXcha07qa+jJL2niUv2kYgJ1pA6jPi2Z3HDzDc4OVzByMvlzpSaXGk5DyzQViDh4W+LGRFoLK8Lv4kX+8GkY2zimrc5nRrvag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1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: The purpose of this series is to serve as a potential base for restricted mmap() support for guest_memfd [1]. It would allow experimentation with what that support would be like, in the safe environment of a new VM type used for testing. This series adds a new VM type for arm64, KVM_VM_TYPE_ARM_SW_PROTECTED, analogous to the x86 KVM_X86_SW_PROTECTED_VM. This type is to serve as a development and testing vehicle for Confidential (CoCo) VMs. Similar to the x86 type, this is currently only for development and testing. It's not meant to be used for "real" VMs, and especially not in production. The behavior and effective ABI for software-protected VMs is unstable. This series enables mmap() support for guest_memfd specifically for the new software-protected VM type, only when explicitly enabled in the config. The series is based on Linux 6.13-rc7 and much of the code within is a subset of the latest series I sent [1], with the addition of the new software protected vm type. To test this series, there's a kvmtool branch with support for guest_memfd for arm64 and the new runtime options of --guest_memfd and --sw_protected, which marks the VM as software protected [2]. I plan on upstreaming this kvmtool branch after more testing and tidying up. Please let me know if this series is useful as a stand-alone series, or if I should merge it with the other guest_memfd for future respins [1]. Cheers, /fuad [1] https://lore.kernel.org/all/20250117163001.2326672-1-tabba@google.com/ [2] https://android-kvm.googlesource.com/kvmtool/+/refs/heads/tabba/guestmem-6.13 Fuad Tabba (9): KVM: guest_memfd: Allow host to mmap guest_memfd() pages KVM: guest_memfd: Add guest_memfd support to kvm_(read|/write)_guest_page() KVM: guest_memfd: Add KVM capability to check if guest_memfd is host mappable KVM: arm64: Skip VMA checks for slots without userspace address KVM: arm64: Refactor user_mem_abort() calculation of force_pte KVM: arm64: Handle guest_memfd()-backed guest page faults KVM: arm64: Introduce KVM_VM_TYPE_ARM_SW_PROTECTED machine type KVM: guest_memfd: selftests: guest_memfd mmap() test when mapping is allowed KVM: arm64: Enable mapping guest_memfd in arm64 Documentation/virt/kvm/api.rst | 5 + arch/arm64/include/asm/kvm_host.h | 10 ++ arch/arm64/kvm/Kconfig | 1 + arch/arm64/kvm/arm.c | 5 + arch/arm64/kvm/mmu.c | 101 ++++++++++---- arch/x86/include/asm/kvm_host.h | 2 + include/linux/kvm_host.h | 16 +++ include/uapi/linux/kvm.h | 7 + tools/testing/selftests/kvm/Makefile | 1 + .../testing/selftests/kvm/guest_memfd_test.c | 60 ++++++++- tools/testing/selftests/kvm/lib/kvm_util.c | 3 +- virt/kvm/Kconfig | 4 + virt/kvm/guest_memfd.c | 71 ++++++++++ virt/kvm/kvm_main.c | 127 ++++++++++++++---- 14 files changed, 353 insertions(+), 60 deletions(-) base-commit: 5bc55a333a2f7316b58edc7573e8e893f7acb532