Doubt regarding memory allocation in KVM

2021-04-19 Thread Shivank Garg
. How/where can I access the GPFNs in the host? Is "gfn_t gfn = gpa >> PAGE_SHIFT" and "gpa_t cr2_or_gpa" in the KVM page fault handler, x86 is the same as GPFN. (that is can I use pfn_to_page in guest VM to access the struct page in Guest) Thank You. Best Regards, Shivank Garg M.Tech Student, IIT Kanpur

[PATCH RFC v7 3/8] security: Export security_inode_init_security_anon for KVM guest_memfd

2025-04-08 Thread Shivank Garg
use outside the core kernel. In the future, guest_memfd might be moved to core-mm, at which point the symbols no longer would have to be exported. When/if that happens is still unclear. Signed-off-by: Shivank Garg --- security/security.c | 1 + 1 file changed, 1 insertion(+) diff --git a/security

[PATCH RFC v7 1/8] mm/filemap: Add mempolicy support to the filemap layer

2025-04-08 Thread Shivank Garg
the default allocation behavior. Signed-off-by: Shivansh Dhiman Signed-off-by: Shivank Garg --- include/linux/pagemap.h | 41 + mm/filemap.c| 27 +++ 2 files changed, 64 insertions(+), 4 deletions(-) diff --git a/include

[PATCH RFC v7 8/8] KVM: guest_memfd: selftests: Add tests for mmap and NUMA policy support

2025-04-08 Thread Shivank Garg
before and after memory allocation These tests help ensure NUMA support for guest_memfd works correctly. Signed-off-by: Shivank Garg --- .../testing/selftests/kvm/guest_memfd_test.c | 86 ++- 1 file changed, 82 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests

[PATCH RFC v7 0/8] Add NUMA mempolicy support for KVM guest-memfd

2025-04-08 Thread Shivank Garg
mem inodes instead of anonymous inodes Shivank Garg (6): mm/mempolicy: Export memory policy symbols security: Export security_inode_init_security_anon for KVM guest_memfd KVM: Add kvm_gmem_exit() cleanup function KVM: guest_memfd: Add slab-allocated inode cache KVM: guest_memfd: Enforc

[PATCH RFC v7 5/8] KVM: guest_memfd: Make guest mem use guest mem inodes instead of anonymous inodes

2025-04-08 Thread Shivank Garg
ith a struct kvm, and metadata about backing memory is not unique to a specific binding and struct kvm. Signed-off-by: Ackerley Tng Signed-off-by: Fuad Tabba Signed-off-by: Shivank Garg --- include/uapi/linux/magic.h | 1 + virt/kvm/guest_memfd.c | 133 +++

[PATCH RFC v7 7/8] KVM: guest_memfd: Enforce NUMA mempolicy using shared policy

2025-04-08 Thread Shivank Garg
ested-by: David Hildenbrand Signed-off-by: Shivank Garg --- virt/kvm/guest_memfd.c | 75 -- 1 file changed, 73 insertions(+), 2 deletions(-) diff --git a/virt/kvm/guest_memfd.c b/virt/kvm/guest_memfd.c index 0ccbb152483a..233d3fd5781c 100644 --- a/virt/kvm/gues

[PATCH RFC v7 6/8] KVM: guest_memfd: Add slab-allocated inode cache

2025-04-08 Thread Shivank Garg
Add dedicated inode structure (kvm_gmem_inode_info) and slab-allocated inode cache for guest memory backing, similar to how shmem handles inodes. This adds the necessary allocation/destruction functions and prepares for upcoming guest_memfd NUMA policy support changes. Signed-off-by: Shivank

[PATCH RFC v7 2/8] mm/mempolicy: Export memory policy symbols

2025-04-08 Thread Shivank Garg
symbols no longer would have to be exported. When/if that happens is still unclear. Acked-by: David Hildenbrand Acked-by: Vlastimil Babka Signed-off-by: Shivank Garg --- mm/mempolicy.c | 6 ++ 1 file changed, 6 insertions(+) diff --git a/mm/mempolicy.c b/mm/mempolicy.c index b28a1e6ae096

Re: [PATCH RFC v7 7/8] KVM: guest_memfd: Enforce NUMA mempolicy using shared policy

2025-04-10 Thread Shivank Garg
On 4/10/2025 7:10 PM, Ackerley Tng wrote: > Shivank Garg writes: > >> Previously, guest-memfd allocations followed local NUMA node id in absence >> of process mempolicy, resulting in arbitrary memory allocation. >> Moreover, mbind() couldn't be used since memo

Re: [PATCH RFC v7 3/8] security: Export security_inode_init_security_anon for KVM guest_memfd

2025-04-10 Thread Shivank Garg
On 4/10/2025 2:11 PM, Christoph Hellwig wrote: > On Tue, Apr 08, 2025 at 11:23:57AM +0000, Shivank Garg wrote: >> KVM guest_memfd is implementing its own inodes to store metadata for >> backing memory using a custom filesystem. This requires the ability to >> initialize

Re: [PATCH RFC v7 3/8] security: Export security_inode_init_security_anon for KVM guest_memfd

2025-04-10 Thread Shivank Garg
Hi Paul, On 4/10/2025 1:49 AM, Paul Moore wrote: > On Tue, Apr 8, 2025 at 7:25 AM Shivank Garg wrote: >> >> KVM guest_memfd is implementing its own inodes to store metadata for >> backing memory using a custom filesystem. This requires the ability to >> initi

[PATCH RFC v7 4/8] KVM: Add kvm_gmem_exit() cleanup function

2025-04-10 Thread Shivank Garg
Add empty kvm_gmem_exit() function for proper cleanup of guest memory resources. Call it from both kvm_init() error path and kvm_exit(). This is preparatory change for upcoming work that involves KVM guest_memfd using inodes to store metadata for backing memory. Signed-off-by: Shivank Garg

Re: [PATCH RFC v7 3/8] security: Export security_inode_init_security_anon for KVM guest_memfd

2025-05-08 Thread Shivank Garg
On 4/22/2025 10:55 PM, David Hildenbrand wrote: > On 10.04.25 10:41, Christoph Hellwig wrote: >> On Tue, Apr 08, 2025 at 11:23:57AM +, Shivank Garg wrote: >>> KVM guest_memfd is implementing its own inodes to store metadata for >>> backing memory using a custom fi

Re: [RFC PATCH v8 3/7] mm/filemap: Add mempolicy support to the filemap layer

2025-06-19 Thread Shivank Garg
On 6/19/2025 9:33 PM, Matthew Wilcox wrote: > On Wed, Jun 18, 2025 at 11:29:31AM +0000, Shivank Garg wrote: >> From: Shivansh Dhiman >> >> Add NUMA mempolicy support to the filemap allocation path by introducing >> new APIs that take a mempolicy argument: &

[RFC PATCH v8 3/7] mm/filemap: Add mempolicy support to the filemap layer

2025-06-18 Thread Shivank Garg
the default allocation behavior. Signed-off-by: Shivansh Dhiman Co-developed-by: Shivank Garg Signed-off-by: Shivank Garg --- include/linux/pagemap.h | 41 + mm/filemap.c| 27 +++ 2 files changed, 64 insertions(+), 4

[RFC PATCH v8 6/7] KVM: guest_memfd: Enforce NUMA mempolicy using shared policy

2025-06-18 Thread Shivank Garg
it is unmovable. Suggested-by: David Hildenbrand Signed-off-by: Shivank Garg --- virt/kvm/guest_memfd.c | 69 -- 1 file changed, 67 insertions(+), 2 deletions(-) diff --git a/virt/kvm/guest_memfd.c b/virt/kvm/guest_memfd.c index 5a1ce6f5e287..2bd5ff3abd

[RFC PATCH v8 4/7] mm/mempolicy: Export memory policy symbols

2025-06-18 Thread Shivank Garg
symbols no longer would have to be exported. When/if that happens is still unclear. Acked-by: David Hildenbrand Acked-by: Vlastimil Babka Signed-off-by: Shivank Garg --- mm/mempolicy.c | 6 ++ 1 file changed, 6 insertions(+) diff --git a/mm/mempolicy.c b/mm/mempolicy.c index 3b1dfd08338b

[RFC PATCH v8 5/7] KVM: guest_memfd: Add slab-allocated inode cache

2025-06-18 Thread Shivank Garg
Add dedicated inode structure (kvm_gmem_inode_info) and slab-allocated inode cache for guest memory backing, similar to how shmem handles inodes. This adds the necessary allocation/destruction functions and prepares for upcoming guest_memfd NUMA policy support changes. Signed-off-by: Shivank

[RFC PATCH v8 7/7] KVM: guest_memfd: selftests: Add tests for mmap and NUMA policy support

2025-06-18 Thread Shivank Garg
allocation These tests help ensure NUMA support for guest_memfd works correctly. Signed-off-by: Shivank Garg --- tools/testing/selftests/kvm/Makefile.kvm | 1 + .../testing/selftests/kvm/guest_memfd_test.c | 123 +- 2 files changed, 122 insertions(+), 2 deletions(-) diff

[RFC PATCH v8 0/7] Add NUMA mempolicy support for KVM guest-memfd

2025-06-18 Thread Shivank Garg
e.kernel.org/all/6fbef654-36e2-4be5-906e-2a648a845...@redhat.com [7] https://lore.kernel.org/all/2b77e055-98ac-43a1-a7ad-9f9065d7f...@amd.com [8] https://lore.kernel.org/all/diqzbjumm167@ackerleytng-ctop.c.googlers.com Ackerley Tng (1): KVM: guest_memfd: Use guest mem inodes instead of anon

[RFC PATCH v8 2/7] KVM: guest_memfd: Use guest mem inodes instead of anonymous inodes

2025-06-18 Thread Shivank Garg
f-by: Fuad Tabba Signed-off-by: Shivank Garg --- include/uapi/linux/magic.h | 1 + virt/kvm/guest_memfd.c | 134 +++-- virt/kvm/kvm_main.c| 7 +- virt/kvm/kvm_mm.h | 10 ++- 4 files changed, 127 insertions(+), 25 deletions(-) diff --git a/in

[RFC PATCH v8 1/7] security: Export anon_inode_make_secure_inode for KVM guest_memfd

2025-06-18 Thread Shivank Garg
this symbol for use outside the core kernel. In the future, guest_memfd might be moved to core-mm, at which point the symbols no longer would have to be exported. When/if that happens is still unclear. Signed-off-by: Shivank Garg --- The handling of the S_PRIVATE flag for these inodes was

Re: [RFC PATCH v8 4/7] mm/mempolicy: Export memory policy symbols

2025-06-19 Thread Shivank Garg
On 6/18/2025 8:42 PM, Gregory Price wrote: > On Wed, Jun 18, 2025 at 11:29:32AM +0000, Shivank Garg wrote: >> KVM guest_memfd wants to implement support for NUMA policies just like >> shmem already does using the shared policy infrastructure. As >> guest_memfd currently

Re: [RFC PATCH v8 3/7] mm/filemap: Add mempolicy support to the filemap layer

2025-06-20 Thread Shivank Garg
On 6/20/2025 8:04 PM, Matthew Wilcox wrote: > On Fri, Jun 20, 2025 at 11:29:20AM +0530, Shivank Garg wrote: >> filemap_grab_folio_mpol() is used in [Patch 6/7] in kvm_gmem_prepare_folio(). >> >> filemap_alloc_folio_mpol() and __filemap_get_folio_mpol()) are internally >

Re: [PATCH 2/2] filemap: Add __filemap_get_folio_mpol()

2025-06-23 Thread Shivank Garg
On 6/23/2025 3:46 AM, Andrew Morton wrote: > On Mon, 23 Jun 2025 00:32:05 +0530 Shivank Garg wrote: > >>> -EXPORT_SYMBOL(__filemap_get_folio); >>> +EXPORT_SYMBOL(__filemap_get_folio_mpol); >>> >>> static inline struct folio *find_get_en

Re: [PATCH 2/2] filemap: Add __filemap_get_folio_mpol()

2025-06-22 Thread Shivank Garg
On 6/23/2025 3:46 AM, Andrew Morton wrote: > On Mon, 23 Jun 2025 00:32:05 +0530 Shivank Garg wrote: > >>> -EXPORT_SYMBOL(__filemap_get_folio); >>> +EXPORT_SYMBOL(__filemap_get_folio_mpol); >>> >>> static inline struct folio *find_get_en

Re: [PATCH 2/2] filemap: Add __filemap_get_folio_mpol()

2025-06-23 Thread Shivank Garg
On 6/23/2025 12:46 PM, Vlastimil Babka wrote: > On 6/22/25 21:02, Shivank Garg wrote: >> >> Hi Andrew, >> >> Thank you for addressing this. >> >> If you don’t mind me asking, >> I was curious why we used EXPORT_SYMBOL instead of EXPORT_SYMBOL_GP

Re: [PATCH] selftests/mm: Increase timeout from 180 to 900 seconds

2025-06-09 Thread Shivank Garg
On 6/10/2025 4:37 AM, Andrew Morton wrote: > On Mon, 9 Jun 2025 12:06:07 +0000 Shivank Garg wrote: > >> The mm selftests are timing out with the current 180-second limit. >> Testing shows that run_vmtests.sh takes approximately 11 minutes >> (664 seconds) to comp

[PATCH] selftests/mm: Increase timeout from 180 to 900 seconds

2025-06-09 Thread Shivank Garg
: Shivank Garg --- tools/testing/selftests/mm/settings | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/selftests/mm/settings b/tools/testing/selftests/mm/settings index a953c96aa16e..e2206265f67c 100644 --- a/tools/testing/selftests/mm/settings +++ b/tools/testing

Re: [PATCH 2/2] filemap: Add __filemap_get_folio_mpol()

2025-06-23 Thread Shivank Garg
On 6/23/2025 12:13 AM, Andrew Morton wrote: > On Fri, 20 Jun 2025 17:53:15 +0100 Matthew Wilcox wrote: > >> On Fri, Jun 20, 2025 at 03:34:47PM +0100, Matthew Wilcox (Oracle) wrote: >>> +struct folio *__filemap_get_folio_mpol(struct address_space *mapping, >>> + pgoff_t index, fgf_t f

Re: [RFC PATCH v8 5/7] KVM: guest_memfd: Add slab-allocated inode cache

2025-06-29 Thread Shivank Garg
On 6/24/2025 9:46 AM, Huang, Ying wrote: > Shivank Garg writes: > >> +static void kvm_gmem_init_inodecache(void) >> +{ >> +kvm_gmem_inode_cachep = kmem_cache_create("kvm_gmem_inode_cache", >> +

[PATCH V9 0/7] Add NUMA mempolicy support for KVM guest-memfd

2025-07-13 Thread Shivank Garg
y support to filemap_alloc_folio() mm/filemap: Extend __filemap_get_folio() to support NUMA memory policies Shivank Garg (4): mm/mempolicy: Export memory policy symbols KVM: guest_memfd: Add slab-allocated inode cache KVM: guest_memfd: Enforce NUMA mempolicy using shared policy KVM: guest_memfd: se

[PATCH V9 1/7] KVM: guest_memfd: Use guest mem inodes instead of anonymous inodes

2025-07-13 Thread Shivank Garg
by: Ackerley Tng Signed-off-by: Shivank Garg --- include/uapi/linux/magic.h | 1 + virt/kvm/guest_memfd.c | 134 +++-- virt/kvm/kvm_main.c| 7 +- virt/kvm/kvm_mm.h | 10 ++- 4 files changed, 127 insertions(+), 25 deletions(-) diff --

[PATCH V9 4/7] mm/mempolicy: Export memory policy symbols

2025-07-13 Thread Shivank Garg
symbols no longer would have to be exported. When/if that happens is still unclear. Acked-by: David Hildenbrand Acked-by: Vlastimil Babka Signed-off-by: Shivank Garg --- mm/mempolicy.c | 6 ++ 1 file changed, 6 insertions(+) diff --git a/mm/mempolicy.c b/mm/mempolicy.c index 3b1dfd08338b

[PATCH V9 2/7] mm/filemap: Add NUMA mempolicy support to filemap_alloc_folio()

2025-07-13 Thread Shivank Garg
ting users pass NULL maintaining current behavior. Reviewed-by: Pankaj Gupta Reviewed-by: Vlastimil Babka Signed-off-by: Matthew Wilcox (Oracle) Signed-off-by: Shivank Garg --- fs/bcachefs/fs-io-buffered.c | 2 +- fs/btrfs/compression.c | 4 ++-- fs/btrfs/verity.c| 2 +-

[PATCH V9 3/7] mm/filemap: Extend __filemap_get_folio() to support NUMA memory policies

2025-07-13 Thread Shivank Garg
icy. This infrastructure will enable future support for NUMA-aware page cache allocations in guest_memfd memory backend KVM guests. Reviewed-by: Pankaj Gupta Reviewed-by: Vlastimil Babka Signed-off-by: Matthew Wilcox (Oracle) Signed-off-by: Shivank Garg --- include/linux/pagemap.h | 10 -- mm

[PATCH V9 7/7] KVM: guest_memfd: selftests: Add tests for mmap and NUMA policy support

2025-07-13 Thread Shivank Garg
allocation These tests help ensure NUMA support for guest_memfd works correctly. Signed-off-by: Shivank Garg --- tools/testing/selftests/kvm/Makefile.kvm | 1 + .../testing/selftests/kvm/guest_memfd_test.c | 122 +- 2 files changed, 122 insertions(+), 1 deletion(-) diff

[PATCH V9 6/7] KVM: guest_memfd: Enforce NUMA mempolicy using shared policy

2025-07-13 Thread Shivank Garg
it is unmovable. Suggested-by: David Hildenbrand Signed-off-by: Shivank Garg --- virt/kvm/guest_memfd.c | 67 -- 1 file changed, 65 insertions(+), 2 deletions(-) diff --git a/virt/kvm/guest_memfd.c b/virt/kvm/guest_memfd.c index 989e2b26b344..5c9a5eb5c1

[PATCH V9 5/7] KVM: guest_memfd: Add slab-allocated inode cache

2025-07-13 Thread Shivank Garg
Add dedicated inode structure (kvm_gmem_inode_info) and slab-allocated inode cache for guest memory backing, similar to how shmem handles inodes. This adds the necessary allocation/destruction functions and prepares for upcoming guest_memfd NUMA policy support changes. Signed-off-by: Shivank

Re: [PATCH V9 5/7] KVM: guest_memfd: Add slab-allocated inode cache

2025-07-21 Thread Shivank Garg
On 7/21/2025 5:14 PM, Vlastimil Babka wrote: >> +kvm_gmem_inode_cachep = kmem_cache_create("kvm_gmem_inode_cache", >> + sizeof(struct >> kvm_gmem_inode_info), >> + 0, SLAB_ACCOUNT, >> +

Re: [PATCH V9 0/7] Add NUMA mempolicy support for KVM guest-memfd

2025-07-22 Thread Shivank Garg
On 7/22/2025 8:10 PM, David Hildenbrand wrote: > On 13.07.25 19:43, Shivank Garg wrote: >> This series introduces NUMA-aware memory placement support for KVM guests >> with guest_memfd memory backends. It builds upon Fuad Tabba's work that >> enabled host-mapping