public inbox for linux-s390@vger.kernel.org
 help / color / mirror / Atom feed
From: "Nico Boehr" <nrb@linux.ibm.com>
To: "Janosch Frank" <frankja@linux.ibm.com>,
	"Nico Boehr" <nrb@linux.ibm.com>, <kvm@vger.kernel.org>
Cc: <linux-s390@vger.kernel.org>, <imbrenda@linux.ibm.com>,
	<borntraeger@linux.ibm.com>
Subject: Re: [kvm-unit-tests 3/5] lib: s390x: sie: Free guest memory on destroy
Date: Thu, 16 Apr 2026 12:24:29 +0200	[thread overview]
Message-ID: <DHUI89JRQHI5.1VWXLD3VX2JUI@linux.ibm.com> (raw)
In-Reply-To: <624c8a3f-2a09-4257-9b0c-2b64e60e52a1@linux.ibm.com>

On Thu Apr 16, 2026 at 10:03 AM CEST, Janosch Frank wrote:
> On 4/15/26 16:21, Nico Boehr wrote:
>> On Wed Apr 15, 2026 at 10:45 AM CEST, Janosch Frank wrote:
>>> We never freed the memory that the sie library allocates as the guest
>>> ram on destruction of the VM. Most tests reuse the VM or just leak the
>>> memory since the standard allocation is one megabyte and tests only
>>> use single digit numbers of VMs.
>>>
>>> It's time to add automatic freeing to the sie library when a VM is
>>> destroyed.
>>>
>>> Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
>>> ---
>>>   lib/s390x/sie.c | 1 +
>>>   1 file changed, 1 insertion(+)
>>>
>>> diff --git a/lib/s390x/sie.c b/lib/s390x/sie.c
>>> index a49c45c7..758ead77 100644
>>> --- a/lib/s390x/sie.c
>>> +++ b/lib/s390x/sie.c
>>> @@ -192,4 +192,5 @@ void sie_guest_destroy(struct vm *vm)
>>>   	free_page(vm->sblk);
>>>   	if (vm->sblk->ecb2 & ECB2_ESCA)
>>>   		free_page(vm->sca);
>>> +	free_pages((void *)virt_to_pte_phys(get_page_root(), vm->guest_mem));
>>>   }
>> 
>> Is there a particular reason why we have a two-step process of calling
>> sie_guest_alloc() for memory allocation
>> and then
>> sie_guest_create() for initializing the sie_block etc
>> 
>> but
>> sie_guest_destroy()
>> cleans up both?
>> 
>
> Historical reasons I guess.
> There've been a lot of changes to the SIE lib over the years, snippet 
> support itself isn't that consistent but it's currently good enough.
> s390x/sie.c is the only direct user of the allocation and even that 
> usage looks like it could be converted.

Yeah, I am a bit concerned about the intermixed dependencies and concerns
between the two. Especially having free_pages() here even when the guest may
(theoretically) have been allocated with something other than sie_guest_alloc().
It would be an error that's kind of hard to spot in a review since it's not
obvious that sie_guest_destroy() pairs with sie_guest_alloc() AND
sie_guest_create().

Would this be an option:
- add small function sie_guest_free() which frees only guest memory to sie lib
  this would be the counterpart to sie_guest_alloc()
- add function snippet_destroy_guest()
  which calls sie_guest_destroy() and sie_guest_free()
  this would be the counterpart to snippet_setup_guest()

Then this pairs nicely as follows for the SIE lib:
sie_guest_alloc() - sie_guest_free()
sie_guest_create() - sie_guest_destroy()

And the higher level snippet operations:
snippet_setup_guest() - snippet_destroy_guest()

  reply	other threads:[~2026-04-16 10:24 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-15  8:45 [kvm-unit-tests 0/5] s390x: Cleanup virtualization library Janosch Frank
2026-04-15  8:45 ` [kvm-unit-tests 1/5] lib: s390x: Add function to get page root Janosch Frank
2026-04-15 11:53   ` Nico Boehr
2026-04-15 12:01     ` Janosch Frank
2026-04-15  8:45 ` [kvm-unit-tests 2/5] lib: s390x: sie: Allocate physical guest memory via memalign Janosch Frank
2026-04-15  8:45 ` [kvm-unit-tests 3/5] lib: s390x: sie: Free guest memory on destroy Janosch Frank
2026-04-15 14:21   ` Nico Boehr
2026-04-16  8:03     ` Janosch Frank
2026-04-16 10:24       ` Nico Boehr [this message]
2026-04-15  8:45 ` [kvm-unit-tests 4/5] lib: s390x: snippet: Add function to create a guest of specific length Janosch Frank
2026-04-16  7:50   ` Nico Boehr
2026-04-15  8:45 ` [kvm-unit-tests 5/5] lib: s390x: Remove kvm s390 prefix from sie control block Janosch Frank
2026-04-16  7:48   ` Nico Boehr
2026-04-16  8:00     ` Janosch Frank

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=DHUI89JRQHI5.1VWXLD3VX2JUI@linux.ibm.com \
    --to=nrb@linux.ibm.com \
    --cc=borntraeger@linux.ibm.com \
    --cc=frankja@linux.ibm.com \
    --cc=imbrenda@linux.ibm.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox