From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.201]) (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 5DDE3314D28 for ; Wed, 15 Oct 2025 22:48:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760568522; cv=none; b=HZ8rVa6rSxVmXAyTjv86ol4ZQEF8o+TxzMke2YcPyNUzK90W14MYPphnOCqzTKXi0LsM8swh0qFY0Jwzba5QPpvgusZ7i/ZWuqMFS6ah7uzB1iADnVqRqGagucJvPawPkHD+VVeUzDJeUM6pjaCAaQpNx+E44HBd145Kn9N1Zqc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760568522; c=relaxed/simple; bh=Zt/pWqHt/iqQ+2OV/rzrh0fmDpxk2J2y6d2dSCcAMnQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=D0cnFu7qLHz4RNKch/4HQ9bVy5TcBAV93pg/W9wXpT9mmg0LHhYyFjykf+RrmZ8FgZye3F+GBb2H/rxF4cIGfM9I4aaf1FNFtceyxjFr7TfrDwVi1x5ob5GCkq7M3b7WdfhBnkvhP6XvytcBQow28Zu5QXNvgybogoei1wckq/A= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=x513Y+Ee; arc=none smtp.client-ip=209.85.210.201 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--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="x513Y+Ee" Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-7a153ba0009so235316b3a.1 for ; Wed, 15 Oct 2025 15:48:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1760568519; x=1761173319; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=VfHhobHRKUrZuY035WUhQS9GUM0Uyoej5h99Za9ASAY=; b=x513Y+EerBtlIdJ6/SV7jfDEvrAFIG0YB9SEFmScIv+2dfmhpk+4CSM0dfz/CV2UmV a1lThTWGUVQLiZCR0ufD43JDhcu0SYfYQ46X+L0edksjTYFskTIJalsNnCddBduQwvXY XJy7SDAECZysPPgodrm6z5fF1qfd9nCE3RUSol9kEtPqoyTk6ThG/8QOTw5WsQIl9KSb u5I3dLFh6z/FnWm4h75nGWO7z5TrO9iCagvECfY4fB5+SBlZfSWmz9+X1QFH70IVAQvU gt9OoPXl4uJSY8IA2006XPHafC0P/mEs4ee9jqUfEF5DpPPqCNqJVxL4kia3w60iUm/U qAaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760568519; x=1761173319; 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=VfHhobHRKUrZuY035WUhQS9GUM0Uyoej5h99Za9ASAY=; b=lSwre+wg39lp1LHjIwFt+BSVoA7bEVHVdr/NBG+dERQPzPebnxjgsp6qLlf5SCheDd Kep4ouXtKLDoZBVhkAkkNbJ/+46guExJc/xQ1h8+ER8rF3wmdm+l3IMAxpvW1XzQjKvX gEkJ+p5bT9f57e4F++Z8oiduyKuY5RN4vi9WbtvcF6wR/GNSZEuuLTab+t4OgS/998hb SlZ8LKXpr9nQaL412q5JNNxc7anRt+mKmgq3z1C+p+YJG1CJN42QP1zkVh5SwyvOzFN7 h1d8dSYWARDSybHuyRm8fx5/USAemQSRUeqT9p95a+PJsmmrWvZz6A9NtdgE6HJy7UsM EwsA== X-Forwarded-Encrypted: i=1; AJvYcCWMeh8xji0u/1gdxGt2abUULpC7cmp7b2SJHGa451cQYWch3TyxaQ08AlQeE8NLGX4D+nc=@vger.kernel.org X-Gm-Message-State: AOJu0YxgaxjpmAjDfl4j98ABhkJZai0s1Ijbiozxh8icMLJrEzGerQT6 Gj0so3faywQ1l+8tLuTzWUQZHNPdzy43UW/kOTS7eLvePjOnqMPemcKVy8ZqO+r6nTqfehfUGtc dQO0cIA== X-Google-Smtp-Source: AGHT+IEyb34/gE6QWzF0uzhcKPL3N9PV8BEpaNWr9b3Rp3K51ypbe1jmOBzkgqmwgOny3WdOfUFKvL+VZBw= X-Received: from pjz11.prod.google.com ([2002:a17:90b:56cb:b0:33b:a35b:861]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:7351:b0:251:c33d:2783 with SMTP id adf61e73a8af0-32da813ce42mr40108259637.23.1760568519460; Wed, 15 Oct 2025 15:48:39 -0700 (PDT) Date: Wed, 15 Oct 2025 15:48:38 -0700 In-Reply-To: Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250827175247.83322-2-shivankg@amd.com> <20250827175247.83322-9-shivankg@amd.com> Message-ID: Subject: Re: [f2fs-dev] [PATCH kvm-next V11 6/7] KVM: guest_memfd: Enforce NUMA mempolicy using shared policy From: Sean Christopherson To: Gregory Price Cc: Shivank Garg , jgowans@amazon.com, mhocko@suse.com, jack@suse.cz, kvm@vger.kernel.org, david@redhat.com, linux-btrfs@vger.kernel.org, aik@amd.com, papaluri@amd.com, kalyazin@amazon.com, peterx@redhat.com, linux-mm@kvack.org, clm@fb.com, ddutile@redhat.com, linux-kselftest@vger.kernel.org, shdhiman@amd.com, gshan@redhat.com, ying.huang@linux.alibaba.com, shuah@kernel.org, roypat@amazon.co.uk, matthew.brost@intel.com, linux-coco@lists.linux.dev, zbestahu@gmail.com, lorenzo.stoakes@oracle.com, linux-bcachefs@vger.kernel.org, ira.weiny@intel.com, dhavale@google.com, jmorris@namei.org, willy@infradead.org, hch@infradead.org, chao.gao@intel.com, tabba@google.com, ziy@nvidia.com, rientjes@google.com, yuzhao@google.com, xiang@kernel.org, nikunj@amd.com, serge@hallyn.com, amit@infradead.org, thomas.lendacky@amd.com, ashish.kalra@amd.com, chao.p.peng@intel.com, yan.y.zhao@intel.com, byungchul@sk.com, michael.day@amd.com, Neeraj.Upadhyay@amd.com, michael.roth@amd.com, bfoster@redhat.com, bharata@amd.com, josef@toxicpanda.com, Liam.Howlett@oracle.com, ackerleytng@google.com, dsterba@suse.com, viro@zeniv.linux.org.uk, jefflexu@linux.alibaba.com, jaegeuk@kernel.org, dan.j.williams@intel.com, surenb@google.com, vbabka@suse.cz, paul@paul-moore.com, joshua.hahnjy@gmail.com, apopple@nvidia.com, brauner@kernel.org, quic_eberman@quicinc.com, rakie.kim@sk.com, cgzones@googlemail.com, pvorel@suse.cz, linux-erofs@lists.ozlabs.org, kent.overstreet@linux.dev, linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, pankaj.gupta@amd.com, linux-security-module@vger.kernel.org, lihongbo22@huawei.com, linux-fsdevel@vger.kernel.org, pbonzini@redhat.com, akpm@linux-foundation.org, vannapurve@google.com, suzuki.poulose@arm.com, rppt@kernel.org, jgg@nvidia.com Content-Type: text/plain; charset="us-ascii" On Wed, Oct 15, 2025, Gregory Price wrote: > On Fri, Sep 26, 2025 at 12:36:27PM -0700, Sean Christopherson via Linux-f2fs-devel wrote: > > > > > > static struct mempolicy *kvm_gmem_get_policy(struct vm_area_struct *vma, > > > unsigned long addr, pgoff_t *pgoff) > > > { > > > *pgoff = vma->vm_pgoff + ((addr - vma->vm_start) >> PAGE_SHIFT); > > > > > > return __kvm_gmem_get_policy(GMEM_I(file_inode(vma->vm_file)), *pgoff); > > > > Argh!!!!! This breaks the selftest because do_get_mempolicy() very specifically > > falls back to the default_policy, NOT to the current task's policy. That is > > *exactly* the type of subtle detail that needs to be commented, because there's > > no way some random KVM developer is going to know that returning NULL here is > > important with respect to get_mempolicy() ABI. > > > > Do_get_mempolicy was designed to be accessed by the syscall, not as an > in-kernel ABI. Ya, by "get_mempolicy() ABI" I meant the uABI for the get_mempolicy syscall. > get_task_policy also returns the default policy if there's nothing > there, because that's what applies. > > I have dangerous questions: Not dangerous at all, I find them very helpful! > why is __kvm_gmem_get_policy using > mpol_shared_policy_lookup() > instead of > get_vma_policy() With the disclaimer that I haven't followed the gory details of this series super closely, my understanding is... Because the VMA is a means to an end, and we want the policy to persist even if the VMA goes away. With guest_memfd, KVM effectively inverts the standard MMU model. Instead of mm/ being the primary MMU and KVM being a secondary MMU, guest_memfd is the primary MMU and any VMAs are secondary (mostly; it's probably more like 1a and 1b). This allows KVM to map guest_memfd memory into a guest without a VMA, or with more permissions than are granted to host userspace, e.g. guest_memfd memory could be writable by the guest, but read-only for userspace. But we still want to support things like mbind() so that userspace can ensure guest_memfd allocations align with the vNUMA topology presented to the guest, or are bound to the NUMA node where the VM will run. We considered adding equivalent file-based syscalls, e.g. fbind(), but IIRC the consensus was that doing so was unnecessary (and potentially messy?) since we were planning on eventually adding mmap() support to guest_memfd anyways. > get_vma_policy does this all for you I assume that doesn't work if the intent is for new VMAs to pick up the existing policy from guest_memfd? And more importantly, guest_memfd needs to hook ->set_policy so that changes through e.g. mbind() persist beyond the lifetime of the VMA. > struct mempolicy *get_vma_policy(struct vm_area_struct *vma, > unsigned long addr, int order, pgoff_t *ilx) > { > struct mempolicy *pol; > > pol = __get_vma_policy(vma, addr, ilx); > if (!pol) > pol = get_task_policy(current); > if (pol->mode == MPOL_INTERLEAVE || > pol->mode == MPOL_WEIGHTED_INTERLEAVE) { > *ilx += vma->vm_pgoff >> order; > *ilx += (addr - vma->vm_start) >> (PAGE_SHIFT + order); > } > return pol; > } > > Of course you still have the same issue: get_task_policy will return the > default, because that's what applies. > > do_get_mempolicy just seems like the completely incorrect interface to > be using here. 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 lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0498CCCD185 for ; Wed, 15 Oct 2025 22:48:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.sourceforge.net; s=beta; h=Content-Transfer-Encoding:Content-Type:Cc: Reply-To:From:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:Subject:To:Message-ID:References:Mime-Version: In-Reply-To:Date:Sender:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=m19Q3DM9NhM3T5Vubybsd6bCOfwKJ2fNllM2AE0bh60=; b=GfDuAKFjr0Zt3WUFmHSxDWHKNR yab/zASbquXi2NNT42lZuVVbLCtqcLDKn39i+XDv6IAFXfXcd0se8tFaUc4/Tq/vLpuiex5lRxtER N5eHz/GxoSJ5wNhktMeL9KTg3Tud79TWarhv+B2XCtzHMJL16duR85AN81TMbaN5vxB0=; Received: from [127.0.0.1] (helo=sfs-ml-3.v29.lw.sourceforge.com) by sfs-ml-3.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1v9AIe-00014j-PH; Wed, 15 Oct 2025 22:48:52 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-3.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from <3xyTwaAYKACAOA6JF8CKKCHA.8KI@flex--seanjc.bounces.google.com>) id 1v9AId-00014c-62 for linux-f2fs-devel@lists.sourceforge.net; Wed, 15 Oct 2025 22:48:51 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Type:Cc:To:From:Subject:Message-ID: References:Mime-Version:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=VfHhobHRKUrZuY035WUhQS9GUM0Uyoej5h99Za9ASAY=; b=ixAVdo+Edrn1CdCZ0+jAJDeXD9 rC8QHC5oQeOCkQTMQTTNsrxaFsTVKdZe3YyRCBxRtnvihRmFc/ryBuMSzPQgs8q5MmZ5XSE6aLi0M Mfz0Y3HRI8lkK9gx/bTGekYJgCg4yHV3cJ15faZqhDtuq1We+xteoOjI/az/0ehPCm9E=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Type:Cc:To:From:Subject:Message-ID:References:Mime-Version: In-Reply-To:Date:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=VfHhobHRKUrZuY035WUhQS9GUM0Uyoej5h99Za9ASAY=; b=l0MGD03P9U8sMQMD4f2SpqUqoH bj8XrvzeUbgFuglcKzJAvBNynMpcFO1efHmyze4tN53PMyWus7+bORbPVNCyIlZkDgJygspt53lvF sBJozX5ChX9fKOwhm29JTU6cy5Dl+K+AeS5wultSFn0KI8QUMHsenYg+Dk4Scn4MvzVc=; Received: from mail-pg1-f202.google.com ([209.85.215.202]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.95) id 1v9AIc-0007Gp-Mr for linux-f2fs-devel@lists.sourceforge.net; Wed, 15 Oct 2025 22:48:51 +0000 Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-b630753cc38so81641a12.1 for ; Wed, 15 Oct 2025 15:48:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1760568520; x=1761173320; darn=lists.sourceforge.net; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=VfHhobHRKUrZuY035WUhQS9GUM0Uyoej5h99Za9ASAY=; b=IfLqNrSAyf2jil955Xv/aUOQDOrWUCxB4H+vaJj7dAvDJb8IQXjY5qUebPWsYgE52k 11HhyTpywC+oZdXSSlunrUGgkXOenG8q+GOpO+FB/eANN+/5akhfftUz5PmgxxC7Ni/T nhnDZLFKR/2oiSfcbxMmLUqFTi9acz4kpbffAIMjZG4dJyJLQkvTAPAX1d2aLWCBr42m JhKKD0R6Kttp5QmjUZiOeRUsYwUHGm2IpDQk4/Knoog5ebC1YMCnSkHEAly0RGWVCw3d VYQVruB5rmRdGEykuX3MKP/7Fr0TEmk7JVBuAbexMRoJqW38ITpsgDqYCk3+FCJgLSIT GHZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760568520; x=1761173320; 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=VfHhobHRKUrZuY035WUhQS9GUM0Uyoej5h99Za9ASAY=; b=G89QYguPdy8bOIZE8S03Jbb01k6i/2RBm/6TWyS8mC99tMvcPaBQQ1RjBj4QzL+wxU nzLeSFjTi9mZLimbqxr+JvtVikvRvwCH8GTVtJNuJHiqnVSwL+VkTGkDAux1DYpsZ0Vf EF4pZ/GFfhj2j7cUhtW48Ef2WCq5N7eWwsN9VIHrfKdmkRb6FruHiMTU5FXQKB2cAgYb RhjoL5c1eXAYNckhQFCPzwhdTGapEQkC788UxAhaZQhM1tANNWxtITqSqf/PLZqNN2Sc ASiH1Y+/Po8aqtrQZqRLCwDUJ5vbxoewhIjaLWNngk+y3qoiswRLYude1r9RRbYnVlLp MaGA== X-Forwarded-Encrypted: i=1; AJvYcCXxGNFB+M3mWhdQ8dE98jdUG8qgWFc2OIprL7JCD4pe09zAN6Xiyr7+3o0DfOF2o6xt7+SUHugPw4fGqIa5/cbW@lists.sourceforge.net X-Gm-Message-State: AOJu0YzLC90KiGMHLgd1FhoCoxeAf2Y/FtZeuikWkETRrJ84t0uToHgV DbBoiSTBAODec2CTYAhm4y1I12YJJNZG+L+/DE+OUxoBfRP7zTYz+DRHP5aufBvcbHcpyjsFkjb ogvrt+w== X-Google-Smtp-Source: AGHT+IEyb34/gE6QWzF0uzhcKPL3N9PV8BEpaNWr9b3Rp3K51ypbe1jmOBzkgqmwgOny3WdOfUFKvL+VZBw= X-Received: from pjz11.prod.google.com ([2002:a17:90b:56cb:b0:33b:a35b:861]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:7351:b0:251:c33d:2783 with SMTP id adf61e73a8af0-32da813ce42mr40108259637.23.1760568519460; Wed, 15 Oct 2025 15:48:39 -0700 (PDT) Date: Wed, 15 Oct 2025 15:48:38 -0700 In-Reply-To: Mime-Version: 1.0 References: <20250827175247.83322-2-shivankg@amd.com> <20250827175247.83322-9-shivankg@amd.com> Message-ID: To: Gregory Price X-Headers-End: 1v9AIc-0007Gp-Mr Subject: Re: [f2fs-dev] [PATCH kvm-next V11 6/7] KVM: guest_memfd: Enforce NUMA mempolicy using shared policy X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Sean Christopherson via Linux-f2fs-devel Reply-To: Sean Christopherson Cc: jgowans@amazon.com, mhocko@suse.com, gshan@redhat.com, jgg@nvidia.com, kvm@vger.kernel.org, david@redhat.com, kalyazin@amazon.com, peterx@redhat.com, clm@fb.com, rppt@kernel.org, ddutile@redhat.com, linux-kselftest@vger.kernel.org, papaluri@amd.com, jack@suse.cz, ying.huang@linux.alibaba.com, shuah@kernel.org, dan.j.williams@intel.com, matthew.brost@intel.com, zbestahu@gmail.com, lorenzo.stoakes@oracle.com, pvorel@suse.cz, ira.weiny@intel.com, dhavale@google.com, jmorris@namei.org, willy@infradead.org, hch@infradead.org, linux-bcachefs@vger.kernel.org, vbabka@suse.cz, ziy@nvidia.com, rientjes@google.com, brauner@kernel.org, xiang@kernel.org, roypat@amazon.co.uk, chao.gao@intel.com, Shivank Garg , thomas.lendacky@amd.com, ashish.kalra@amd.com, chao.p.peng@intel.com, yan.y.zhao@intel.com, byungchul@sk.com, michael.day@amd.com, Neeraj.Upadhyay@amd.com, michael.roth@amd.com, bfoster@redhat.com, bharata@amd.com, josef@toxicpanda.com, Liam.Howlett@oracle.com, surenb@google.com, ackerleytng@google.com, suzuki.poulose@arm.com, linux-coco@lists.linux.dev, dsterba@suse.com, shdhiman@amd.com, jaegeuk@kernel.org, amit@infradead.org, tabba@google.com, yuzhao@google.com, joshua.hahnjy@gmail.com, apopple@nvidia.com, nikunj@amd.com, vannapurve@google.com, quic_eberman@quicinc.com, paul@paul-moore.com, cgzones@googlemail.com, linux-mm@kvack.org, kent.overstreet@linux.dev, rakie.kim@sk.com, linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, pankaj.gupta@amd.com, linux-security-module@vger.kernel.org, lihongbo22@huawei.com, jefflexu@linux.alibaba.com, aik@amd.com, linux-fsdevel@vger.kernel.org, pbonzini@redhat.com, akpm@linux-foundation.org, serge@hallyn.com, linux-erofs@lists.ozlabs.org, linux-btrfs@vger.kernel.org, viro@zeniv.linux.org.uk Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net On Wed, Oct 15, 2025, Gregory Price wrote: > On Fri, Sep 26, 2025 at 12:36:27PM -0700, Sean Christopherson via Linux-f2fs-devel wrote: > > > > > > static struct mempolicy *kvm_gmem_get_policy(struct vm_area_struct *vma, > > > unsigned long addr, pgoff_t *pgoff) > > > { > > > *pgoff = vma->vm_pgoff + ((addr - vma->vm_start) >> PAGE_SHIFT); > > > > > > return __kvm_gmem_get_policy(GMEM_I(file_inode(vma->vm_file)), *pgoff); > > > > Argh!!!!! This breaks the selftest because do_get_mempolicy() very specifically > > falls back to the default_policy, NOT to the current task's policy. That is > > *exactly* the type of subtle detail that needs to be commented, because there's > > no way some random KVM developer is going to know that returning NULL here is > > important with respect to get_mempolicy() ABI. > > > > Do_get_mempolicy was designed to be accessed by the syscall, not as an > in-kernel ABI. Ya, by "get_mempolicy() ABI" I meant the uABI for the get_mempolicy syscall. > get_task_policy also returns the default policy if there's nothing > there, because that's what applies. > > I have dangerous questions: Not dangerous at all, I find them very helpful! > why is __kvm_gmem_get_policy using > mpol_shared_policy_lookup() > instead of > get_vma_policy() With the disclaimer that I haven't followed the gory details of this series super closely, my understanding is... Because the VMA is a means to an end, and we want the policy to persist even if the VMA goes away. With guest_memfd, KVM effectively inverts the standard MMU model. Instead of mm/ being the primary MMU and KVM being a secondary MMU, guest_memfd is the primary MMU and any VMAs are secondary (mostly; it's probably more like 1a and 1b). This allows KVM to map guest_memfd memory into a guest without a VMA, or with more permissions than are granted to host userspace, e.g. guest_memfd memory could be writable by the guest, but read-only for userspace. But we still want to support things like mbind() so that userspace can ensure guest_memfd allocations align with the vNUMA topology presented to the guest, or are bound to the NUMA node where the VM will run. We considered adding equivalent file-based syscalls, e.g. fbind(), but IIRC the consensus was that doing so was unnecessary (and potentially messy?) since we were planning on eventually adding mmap() support to guest_memfd anyways. > get_vma_policy does this all for you I assume that doesn't work if the intent is for new VMAs to pick up the existing policy from guest_memfd? And more importantly, guest_memfd needs to hook ->set_policy so that changes through e.g. mbind() persist beyond the lifetime of the VMA. > struct mempolicy *get_vma_policy(struct vm_area_struct *vma, > unsigned long addr, int order, pgoff_t *ilx) > { > struct mempolicy *pol; > > pol = __get_vma_policy(vma, addr, ilx); > if (!pol) > pol = get_task_policy(current); > if (pol->mode == MPOL_INTERLEAVE || > pol->mode == MPOL_WEIGHTED_INTERLEAVE) { > *ilx += vma->vm_pgoff >> order; > *ilx += (addr - vma->vm_start) >> (PAGE_SHIFT + order); > } > return pol; > } > > Of course you still have the same issue: get_task_policy will return the > default, because that's what applies. > > do_get_mempolicy just seems like the completely incorrect interface to > be using here. _______________________________________________ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel