Re: [PATCH v10 16/50] x86/sev: Introduce snp leaked pages list

From: Borislav Petkov
Date: Wed Dec 06 2023 - 15:43:55 EST


On Mon, Oct 16, 2023 at 08:27:45AM -0500, Michael Roth wrote:
> + spin_lock(&snp_leaked_pages_list_lock);
> + while (npages--) {
> + /*
> + * Reuse the page's buddy list for chaining into the leaked
> + * pages list. This page should not be on a free list currently
> + * and is also unsafe to be added to a free list.
> + */
> + list_add_tail(&page->buddy_list, &snp_leaked_pages_list);
> + sev_dump_rmpentry(pfn);
> + pfn++;
> + }
> + spin_unlock(&snp_leaked_pages_list_lock);
> + atomic_long_inc(&snp_nr_leaked_pages);

How is this supposed to count?

You're leaking @npages as the function's parameter but are incrementing
snp_nr_leaked_pages only once?

Just make it a bog-normal unsigned long and increment it inside the
locked section.

Or do at the beginning of the function:

atomic_long_add(npages, &snp_nr_leaked_pages);

--
Regards/Gruss,
Boris.

https://people.kernel.org/tglx/notes-about-netiquette