# Re: \[PATCH v12 18/45\] KVM: guest\_memfd: Handle lru\_add fbatch refcounts during conversion safety check

- From: David Hildenbrand (Arm) \<david@kernel.org\>
- Date: 2026-09-09 15:52:30 
- List: linux-coco
- Page: https://ratatoskr.run/linux-coco/2026/09/17540693
- Thread: https://ratatoskr.run/kvm/2026/08/17480489/t/2.md

```text

> +
>  static bool kvm_gmem_has_outstanding_references(struct inode *inode,
>  						pgoff_t start, size_t nr_pages,
>  						pgoff_t *err_index)
>  {
> +	enum lru_cache_drained drained = LRU_CACHE_NOT_DRAINED;
>  	struct address_space *mapping = inode->i_mapping;
>  	pgoff_t last = start + nr_pages - 1;
>  	bool has_outstanding = false;
> @@ -570,17 +589,12 @@ static bool kvm_gmem_has_outstanding_references(struct inode *inode,
>  	folio_batch_init(&fbatch);
>  
>  	next = start;
> -	while (has_outstanding && filemap_get_folios(mapping, &next, last, &fbatch)) {
> +	while (!has_outstanding && filemap_get_folios(mapping, &next, last, &fbatch)) {
>  		for (i = 0; i < folio_batch_count(&fbatch); ++i) {
>  			struct folio *folio = fbatch.folios[i];
>  
> -			/*
> -			 * Outstanding references are anything other than those
> -			 * from the page cache, plus 1 temporary reference held
> -			 * by filemap_get_folios() in the folio batch.
> -			 */
> -			if (folio_ref_count(folio) != folio_nr_pages(folio) + 1) {
> -				has_outstanding = true;
> +			has_outstanding = __folio_has_outstanding_references(folio, &drained);
> +			if (has_outstanding) {
>  				*err_index = max(start, folio->index);
>  				break;
>  			}
> 

Having the folio.c bits go upstream early is certainly cleaner; without Hugh's
series an ack from MM maintainers would have been sufficient, though.

In any case, on the revised patch with only guest_memfd changes:

Reviewed-by: David Hildenbrand (Arm) <david@kernel.org>

-- 
Cheers,

David
```
