Received: from mail-wm1-f74.google.com (mail-wm1-f74.google.com [209.85.128.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1272B2BE7AA for ; Wed, 11 Jun 2025 13:34:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.74 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749648848; cv=none; b=IAo9z6WcJ/DkO7VBhWA1D4GMZnMikHyRWClf6PNgv/TXWMuKo1qcDeVs2VfHi9jiV4vE+HDokSpWYt8TUAy0wl7yZQ/ZKbou3yrIeq4AxGssyLgFZNtJdpmdUuhGYnx4DTgp2Dcw17JJ99x6IELhzIr6ZR7vc3y/fq449Bx7XH4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749648848; c=relaxed/simple; bh=85h3na1gsYFMlWN8UpZMM/0gWDZKX7wBW0lX7RlGk8Y=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=YkjfKsEwaeqefAGEi97lfJjDcpI/rk5JxdGflrB/jfNgtf0cRdZgehyG5rC9ilKNSWcBkW6OkyJwOmO53Ss6r7pkKntZbnrzyOd5x+Fa+bRWcfqbhaRs5HJfnVEp1yUptpOzeJPMToOwNjl/eVCRd9/j/5bJ93CNc4TdoC7Pfmc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--tabba.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=3a9NKNo4; arc=none smtp.client-ip=209.85.128.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--tabba.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="3a9NKNo4" Received: by mail-wm1-f74.google.com with SMTP id 5b1f17b1804b1-450eaae2934so59538605e9.2 for ; Wed, 11 Jun 2025 06:34:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1749648845; x=1750253645; darn=lists.linux.dev; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=1XR59PTGuiW1gb55TNwkuIBSMjZG1XsBaxGQqCed/os=; b=3a9NKNo4i1vhdiZjYV4QObOU167Uoi+Z0x/ZpV6KQ6JCJeTPqST30eilZMVD9oqT6S 9FckyzkCeB5cWifNO1nY3dVoj8d8MsdPRwxKNbTDhDMnL2zTEJ23XO8GkXVz9Q1RA/Q+ 6NizAR/qkSidpDh8832ca3Hd3soPevVct3R0UnDAyMJnTvgfrxMI+AR/hut3iBllx/r9 lynjbRVdIHh81NCsKtpxWVWlVC80xD5pQ29uFqvFQy32BPjBTX07hFaheTPZ8QxXRw3N C754HG3x4i4MjQfsO/qluA6xj8FKtfPN++6QIHceeE46mCas79Q+Bo0J2bK4zaJvqwfB 1qRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749648845; x=1750253645; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=1XR59PTGuiW1gb55TNwkuIBSMjZG1XsBaxGQqCed/os=; b=Qc/ugtPl7YY9Nu10Y7XjOOJ3IsTE/ik2jbHZdaPVmIajBY6Liij7ohygHVN0EhMhjm igAI+pbHgnawDjVnXPqK1ADYIzUk5Me8f49jDnpR3eH0rwNhWC15m7RwHkBFiruNATCe lghVB9xDu4ih9i4Zu0GbSP5XsVevC4877HnjNrni28b+m1RX08Q61BP7tWJ3FC0eUcXg 9vqP+bIQljzzfRYeusOcnNpCx2C8SYZMYkzUnI1T9jqkf0kW0mPbOL8EQHXRj0PtMol1 EiV4dOAmlCQ0Hb6PJQmKbonEe1HzIGTKl7f+9prsAdcoM3V9e6RMjovqEcLUlnz2S/Hn hywQ== X-Forwarded-Encrypted: i=1; AJvYcCWR6h2aJBUnjoxM8qqn2UX57KSvVsga93Phxx5dfbnbOYLRz/L26/VHcoM72ou8YZi+DFN0KNQ=@lists.linux.dev X-Gm-Message-State: AOJu0YzAKrnB8DD2oF4YUYT6/uamAfRSUqbLP8Q2Y4Y8+L64EKh30nWz pKF8neu516zQrQU3SzqFqzBeXlRiUArE+L6MpdD2egq6M7HW3zgb2m/sX/DXX+0Dqso0wAFlwhx YVg== X-Google-Smtp-Source: AGHT+IEfAr/l95Kf+rwSAj9mppIOYExWAEsd3FitYHNfOu71BGp8Mi+xQZ98YDO3SYy4dT9bCQ1C1E+czA== X-Received: from wmbep25.prod.google.com ([2002:a05:600c:8419:b0:442:ea0c:c453]) (user=tabba job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:6986:b0:439:9424:1b70 with SMTP id 5b1f17b1804b1-45324f6a144mr26676635e9.30.1749648845441; Wed, 11 Jun 2025 06:34:05 -0700 (PDT) Date: Wed, 11 Jun 2025 14:33:28 +0100 In-Reply-To: <20250611133330.1514028-1-tabba@google.com> Precedence: bulk X-Mailing-List: kvmarm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250611133330.1514028-1-tabba@google.com> X-Mailer: git-send-email 2.50.0.rc0.642.g800a2b2222-goog Message-ID: <20250611133330.1514028-17-tabba@google.com> Subject: [PATCH v12 16/18] KVM: Introduce the KVM capability KVM_CAP_GMEM_SHARED_MEM From: Fuad Tabba To: kvm@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-mm@kvack.org, kvmarm@lists.linux.dev 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, 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, peterx@redhat.com, pankaj.gupta@amd.com, ira.weiny@intel.com, tabba@google.com Content-Type: text/plain; charset="UTF-8" This patch introduces the KVM capability KVM_CAP_GMEM_SHARED_MEM, which indicates that guest_memfd supports shared memory (when enabled by the flag). This support is limited to certain VM types, determined per architecture. This patch also updates the KVM documentation with details on the new capability, flag, and other information about support for shared memory in guest_memfd. Reviewed-by: David Hildenbrand Reviewed-by: Gavin Shan Signed-off-by: Fuad Tabba --- Documentation/virt/kvm/api.rst | 9 +++++++++ include/uapi/linux/kvm.h | 1 + virt/kvm/kvm_main.c | 4 ++++ 3 files changed, 14 insertions(+) diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst index 1bd2d42e6424..4ef3d8482000 100644 --- a/Documentation/virt/kvm/api.rst +++ b/Documentation/virt/kvm/api.rst @@ -6407,6 +6407,15 @@ most one mapping per page, i.e. binding multiple memory regions to a single guest_memfd range is not allowed (any number of memory regions can be bound to a single guest_memfd file, but the bound ranges must not overlap). +When the capability KVM_CAP_GMEM_SHARED_MEM is supported, the 'flags' field +supports GUEST_MEMFD_FLAG_SUPPORT_SHARED. Setting this flag on guest_memfd +creation enables mmap() and faulting of guest_memfd memory to host userspace. + +When the KVM MMU performs a PFN lookup to service a guest fault and the backing +guest_memfd has the GUEST_MEMFD_FLAG_SUPPORT_SHARED set, then the fault will +always be consumed from guest_memfd, regardless of whether it is a shared or a +private fault. + See KVM_SET_USER_MEMORY_REGION2 for additional details. 4.143 KVM_PRE_FAULT_MEMORY diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h index cb19150fd595..c74cf8f73337 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -934,6 +934,7 @@ struct kvm_enable_cap { #define KVM_CAP_ARM_EL2 240 #define KVM_CAP_ARM_EL2_E2H0 241 #define KVM_CAP_RISCV_MP_STATE_RESET 242 +#define KVM_CAP_GMEM_SHARED_MEM 243 struct kvm_irq_routing_irqchip { __u32 irqchip; diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index d41bcc6a78b0..441c9b53b876 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -4913,6 +4913,10 @@ static int kvm_vm_ioctl_check_extension_generic(struct kvm *kvm, long arg) #ifdef CONFIG_KVM_GMEM case KVM_CAP_GUEST_MEMFD: return !kvm || kvm_arch_supports_gmem(kvm); +#endif +#ifdef CONFIG_KVM_GMEM_SHARED_MEM + case KVM_CAP_GMEM_SHARED_MEM: + return !kvm || kvm_arch_supports_gmem_shared_mem(kvm); #endif default: break; -- 2.50.0.rc0.642.g800a2b2222-goog