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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id D02B8C2D0CD for ; Wed, 21 May 2025 13:33:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6E5D56B009B; Wed, 21 May 2025 09:33:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 695E86B009C; Wed, 21 May 2025 09:33:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 584C66B009D; Wed, 21 May 2025 09:33:24 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 3B3886B009B for ; Wed, 21 May 2025 09:33:24 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id D3ADD1CE0E0 for ; Wed, 21 May 2025 13:33:23 +0000 (UTC) X-FDA: 83467006686.05.A783499 Received: from mail-qt1-f173.google.com (mail-qt1-f173.google.com [209.85.160.173]) by imf30.hostedemail.com (Postfix) with ESMTP id 15C1980010 for ; Wed, 21 May 2025 13:33:21 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=JBSgpKIw; spf=pass (imf30.hostedemail.com: domain of tabba@google.com designates 209.85.160.173 as permitted sender) smtp.mailfrom=tabba@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1747834402; 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:in-reply-to:references:references:dkim-signature; bh=7IElG8t6UQOCXlMao4ZOb1RJT5HCrLgm0tglQ9eav/M=; b=oqhiDvGMm6zF4OggpXzd0h9vnZAHYNnSEDUz0o0RLZkYWBJoorbrFW3i2ISTbhwGsaIN1T /9+C9BQ0Mlku1VFFaro3zhJTCIQ6q/qmoMaPDEt40RZiNSGqiDEQ6BtK99h2YDtT9ilj5O hHEbX9ChxnRTs+F9ZfKF2B0jyO/6lY0= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=JBSgpKIw; spf=pass (imf30.hostedemail.com: domain of tabba@google.com designates 209.85.160.173 as permitted sender) smtp.mailfrom=tabba@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1747834402; a=rsa-sha256; cv=none; b=2v1gv3fGK6Sx6ZyP7To+b4KCcGFx6qpYMCTVisc6hm+lOdTdApUoIketVsxFXJC7DZoxLc bQXKv4rSxBwTBXMMfN22yl0LfqTBJG4GIRtU/cgb+bQFvFPIByMklBq3tIZAlJYsRo8IW4 ndMCQcSnDXWVpLkRSNiVstvTsZCeEvk= Received: by mail-qt1-f173.google.com with SMTP id d75a77b69052e-48b7747f881so1440331cf.1 for ; Wed, 21 May 2025 06:33:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1747834401; x=1748439201; darn=kvack.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=7IElG8t6UQOCXlMao4ZOb1RJT5HCrLgm0tglQ9eav/M=; b=JBSgpKIwDAkFLFGP5WSIEQTitn+qftMQLr7+ggPCSFxybzqzQsTmd5+O+MvEbpCdnx 5VcSBoy0FjCWl2EmgCLZEnd7HTRxKngPnxTlUSF7YL83Td/uw0Oulohr2Wgq0nkzDbRB hspE9lPHAvOGY0RwvYcuhOI5SIoQ7diDUKDJp2bhsPECbfMALaeUsHGE2XlPilf9fuMg 0Ka7Rt6VSQFG14pVMFSlvmNkjpsYFW2QClqMkLzbelKBfKR5i43PwL1vQ0+LBF9OnjD5 y1efj2Qwt1jVpwJ9X4dqUAeiVWAysoj+mp/QHY0B6ftVyqWTfp/6AJr7UQjCoPa3Fk4m dTgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747834401; x=1748439201; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=7IElG8t6UQOCXlMao4ZOb1RJT5HCrLgm0tglQ9eav/M=; b=SVUJ4bGgOfWamFi5LLsibcAh/bmHBiHAiUeHdq+y5K5hgjCiIw2SoihfNY7PT/Ljrf Z3nSkHJtxv0EBypapxCCskSJ44sgbLkPmzpaqXoKuEiR45UWtv0UjLF7+sNIEJkL7lQG R5lYFlvMLJNUzQqW3pKo9ntdyO06ygjx8a8K/ukbUAl6wy4191qeegNkxZe5nRVMkaKH 7MCso+MOYVuaNEPWFoDUcJBtSk9atdZXYZgxEkkF/ehLw2wkOlR1hb6hGSdRsZB7BN16 vBgu8TbMySchqaYJeUjJZYCzFVNXjvgl1ebgrPTyaiDlGtd2kH1y1074jsv7WTLYz8l5 tXBg== X-Forwarded-Encrypted: i=1; AJvYcCXp+w7ru+n/KUMiNGDKZIxW8kxxMqzjBSLcl9I9jQJuiHAR7QYgmWChnRiLehPTo7AVGrK0oCVy4A==@kvack.org X-Gm-Message-State: AOJu0Yx2IGY6LSP8eWEcSNqzvjJWNmvAiz2qpYTpSuzBEsMdjrbJNcQW OIDwb2KiLENH7870pdmPc7bBgzeYSDw+DHB2L+Vt9p5GMshKcmXthTuOQBBFA/cYYzkSvjgu9RJ dUfFlvJikMyAN80+aFAwWUg/aELGHunmBY8oguuh+ X-Gm-Gg: ASbGncsqzNPhku13OrtGXv31EBXCZQFLVAt3t5YB1tUmBQjyvmrWh7jXpsXl5ziSzCQ j8poQO9SxVDeRyD8YUfHGQYnwyU6izwjZka0EOFltwzaGt/qfGxbPim0fascUS0Cger+gZP1zoW DGYGwQJ0WFTrFkfQcsEY2Kb4GhfiV8huUFLX5UIt/se9XbVOFHjLFnPyEkxSzkPa4X9nk/9k6u X-Google-Smtp-Source: AGHT+IGHrTdfeMb7jlXQw3K737a7s2UVgkzPNNbLnqAt7pGQ9skk0T2PnsNL8ybReruUQvJls1mTzXEvnmXLudYE3yo= X-Received: by 2002:a05:622a:14c:b0:466:8c23:823a with SMTP id d75a77b69052e-49600c876ddmr15160551cf.17.1747834400540; Wed, 21 May 2025 06:33:20 -0700 (PDT) MIME-Version: 1.0 References: <20250513163438.3942405-1-tabba@google.com> <20250513163438.3942405-15-tabba@google.com> <2084504e-2a11-404a-bbe8-930384106f53@redhat.com> <5da72da7-b82c-4d70-ac86-3710a046b836@redhat.com> In-Reply-To: <5da72da7-b82c-4d70-ac86-3710a046b836@redhat.com> From: Fuad Tabba Date: Wed, 21 May 2025 14:32:43 +0100 X-Gm-Features: AX0GCFusE07bvRo-Pqsi4ydaoFt5tlnl13zLKduQ18To8DRrmGMT_dqdB-JwRxU Message-ID: Subject: Re: [PATCH v9 14/17] KVM: arm64: Enable mapping guest_memfd in arm64 To: David Hildenbrand Cc: kvm@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-mm@kvack.org, 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, 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 Content-Type: text/plain; charset="UTF-8" X-Rspamd-Queue-Id: 15C1980010 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: ds357451nswm6s9bg3r7mqaapdo4sqtd X-HE-Tag: 1747834401-245643 X-HE-Meta: U2FsdGVkX1+URwBPnwG/BnMi93vrSDBszIfhOmwJ1AYjdqqpHVeTIlms4RTz8YerWA1+eEV0BYMHY0Xx/AhXmCru8as7zc+0ypf1sLUPsvpJ4BT7dyDu1/4wOo75XTdMinSNz/5QXVre02XY85ufYqtmZW/E6olM2Wsp0U5sHqb2uPYl0lpcovLWDipYE8iZ1Ny/ltPovZA5ou0+Q7kkD0RyBWvBPa17STde0sC/0PQLbYRFNvryNWGv8ixe6BSPnIV3vB9piPOh85Fx8asxbSe+3jWHfnwI7BwijgraTTsGkvVxtlTTSoLg82dsdY8HA77AqzJBodEMK8uwx/j/S69OCBKJ73kq0C4gAS173tc0h5mhVa1TD0r50byEmgRyhXq12jBi+kKBraTI73KG95CIH5KKWwJa7kNZWexgWuvCmwuG5dFu9LDd1SJS13G8kRMoUijq9p9+59rD8vVUYf8sZXoYaPIPqsa7guvxq9TErYZ9lzFDuQkbmQgcvKESUpkF7SL8ygTjgKryrP261451oAkPpWyUjt9CUX9wG484vpJWp53VJdMWk19vvoTb0nEzVxJlpaXq5RS45XnOvg5G9KRRybieMMvCLMPptHf+zk3uq6/2gGPikfoyJ9FBW7+9LXGfs2ZH98v7sVtcxTU+riyCaoaPMpS0lftXXnd+quabS+HGzekRo0LUAt9RagMsySXujMkAtmqepj53Mi4BIolXw9N5XpodIYjWVsmDOEXEkcQJEnLaALKqG3kQHS2ILp7gegIVkYm851NzuiBFMgbyEIXXgNY0pDM3nMBIBdV+Im860N/OzMiR3S0eu05vzmofTT2Ej7pfdJE+vkGGveYSRQyU0aKqTR2g+5gcwYRtixkMJGD4FwEnhsCgYckvOUJDzyELKMap/gtJQjn7hyruHhZj1URAT8+2+aL+lDdumJOnbdX+A8xNNOZStrJQfNMHXb+8gEjp+n0 INQczauf UqqAp7W+M3eA61K4mk42NrmG9H1upi+aTC3EfRDXYvJYv3Tssok62ytziOFl7gwiXJ8oVO6Jh6uONvpp8hAMfCEYOOJYcDBxQfOsBmnsfNOPzzaHSSJD96erhI2UNmONDCSBhq0fj3fyLfFC+hEtNGpdRfuseViilg9M4vOR4KZ5bw0M23NmcSsLepkXo2AVedPNpF/EUVqfQu3kB/1ADHTqTFmGvgRLtRXoXcYveKBiYk+ldiJ7x+/pyTokYTzDniMFGMsP0jhMWvc6L7lbio0o18dOdosTS5KOPJ4tE5p6GXSRr0SRfANMGF8HNd6s7lLrAnciNhZdilgTAvrhaXpLGfmIcy56D+0xGUaMWWtQmYNw= 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: List-Subscribe: List-Unsubscribe: Hi David, On Wed, 21 May 2025 at 14:22, David Hildenbrand wrote: > > On 21.05.25 15:15, Fuad Tabba wrote: > > Hi David, > > > > On Wed, 21 May 2025 at 13:44, David Hildenbrand wrote: > >> > >> On 21.05.25 12:29, Fuad Tabba wrote: > >>> On Wed, 21 May 2025 at 11:26, David Hildenbrand wrote: > >>>> > >>>> On 21.05.25 12:12, Fuad Tabba wrote: > >>>>> Hi David, > >>>>> > >>>>> On Wed, 21 May 2025 at 09:05, David Hildenbrand wrote: > >>>>>> > >>>>>> On 13.05.25 18:34, Fuad Tabba wrote: > >>>>>>> Enable mapping guest_memfd in arm64. For now, it applies to all > >>>>>>> VMs in arm64 that use guest_memfd. In the future, new VM types > >>>>>>> can restrict this via kvm_arch_gmem_supports_shared_mem(). > >>>>>>> > >>>>>>> Signed-off-by: Fuad Tabba > >>>>>>> --- > >>>>>>> arch/arm64/include/asm/kvm_host.h | 10 ++++++++++ > >>>>>>> arch/arm64/kvm/Kconfig | 1 + > >>>>>>> 2 files changed, 11 insertions(+) > >>>>>>> > >>>>>>> diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h > >>>>>>> index 08ba91e6fb03..2514779f5131 100644 > >>>>>>> --- a/arch/arm64/include/asm/kvm_host.h > >>>>>>> +++ b/arch/arm64/include/asm/kvm_host.h > >>>>>>> @@ -1593,4 +1593,14 @@ static inline bool kvm_arch_has_irq_bypass(void) > >>>>>>> return true; > >>>>>>> } > >>>>>>> > >>>>>>> +static inline bool kvm_arch_supports_gmem(struct kvm *kvm) > >>>>>>> +{ > >>>>>>> + return IS_ENABLED(CONFIG_KVM_GMEM); > >>>>>>> +} > >>>>>>> + > >>>>>>> +static inline bool kvm_arch_vm_supports_gmem_shared_mem(struct kvm *kvm) > >>>>>>> +{ > >>>>>>> + return IS_ENABLED(CONFIG_KVM_GMEM_SHARED_MEM); > >>>>>>> +} > >>>>>>> + > >>>>>>> #endif /* __ARM64_KVM_HOST_H__ */ > >>>>>>> diff --git a/arch/arm64/kvm/Kconfig b/arch/arm64/kvm/Kconfig > >>>>>>> index 096e45acadb2..8c1e1964b46a 100644 > >>>>>>> --- a/arch/arm64/kvm/Kconfig > >>>>>>> +++ b/arch/arm64/kvm/Kconfig > >>>>>>> @@ -38,6 +38,7 @@ menuconfig KVM > >>>>>>> select HAVE_KVM_VCPU_RUN_PID_CHANGE > >>>>>>> select SCHED_INFO > >>>>>>> select GUEST_PERF_EVENTS if PERF_EVENTS > >>>>>>> + select KVM_GMEM_SHARED_MEM > >>>>>>> help > >>>>>>> Support hosting virtualized guest machines. > >>>>>>> > >>>>>> > >>>>>> Do we have to reject somewhere if we are given a guest_memfd that was > >>>>>> *not* created using the SHARED flag? Or will existing checks already > >>>>>> reject that? > >>>>> > >>>>> We don't reject, but I don't think we need to. A user can create a > >>>>> guest_memfd that's private in arm64, it would just be useless. > >>>> > >>>> But the arm64 fault routine would not be able to handle that properly, no? > >>> > >>> Actually it would. The function user_mem_abort() doesn't care whether > >>> it's private or shared. It would fault it into the guest correctly > >>> regardless. > >> > >> > >> I think what I meant is that: if it's !shared (private only), shared > >> accesses (IOW all access without CoCo) should be taken from the user > >> space mapping. > >> > >> But user_mem_abort() would blindly go to kvm_gmem_get_pfn() because > >> "is_gmem = kvm_slot_has_gmem(memslot) = true". > > > > Yes, since it is a gmem-backed slot. > > > >> In other words, arm64 would have to *ignore* guest_memfd that does not > >> support shared? > >> > >> That's why I was wondering whether we should just immediately refuse > >> such guest_memfds. > > > > My thinking is that if a user deliberately creates a > > guest_memfd-backed slot without designating it as being sharable, then > > either they would find out when they try to map that memory to the > > host userspace (mapping it would fail), or it could be that they > > deliberately want to set up a VM with memslots that not mappable at > > all by the host. > > Hm. But that would meant that we interpret "private" memory as a concept > that is not understood by the VM. Because the VM does not know what > "private" memory is ... > > > Perhaps to add some layer of security (although a > > very flimsy one, since it's not a confidential guest). > > Exactly my point. If you don't want to mmap it then ... don't mmap it :) > > > > > I'm happy to a check to prevent this. The question is, how to do it > > exactly (I assume it would be in kvm_gmem_create())? Would it be > > arch-specific, i.e., prevent arm64 from creating non-shared > > guest_memfd backed memslots? Or do it by VM type? Even if we do it by > > VM-type it would need to be arch-specific, since we allow private > > guest_memfd slots for the default VM in x86, but we wouldn't for > > arm64. > > > > We could add another function, along the lines of > > kvm_arch_supports_gmem_only_shared_mem(), but considering that it > > actually works, and (arguably) would behave as intended, I'm not sure > > if it's worth the complexity. > > > > What do you think? > > My thinking was to either block this at slot creation time or at > guest_memfd creation time. And we should probably block that for other > VM types as well that do not support private memory? > > I mean, creating guest_memfd for private memory when there is no concept > of private memory for the VM is ... weird, no? :) Actually, I could add this as an arch-specific check in arch/arm64/kvm/mmu.c:kvm_arch_prepare_memory_region(). That way, core KVM/guest_memfd code doesn't need to handle this arm64-specific behavior. Does that sound good? Thanks, /fuad > -- > Cheers, > > David / dhildenb >