From nobody Sat Sep 26 01:39:01 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 05D9C42123A; Sun, 6 Sep 2026 08:27:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788683248; cv=none; b=gacqKEQox47PR4AZLjEkQaY83NeamVvknW5dCGrWcfI7hCcSeerTjMrK9njYmLUeXGGQuvp+SulBmFv9qNi1yy0BPuylz/f4HpQRGoKkOFeObwK+Sv3jVtdlfrBNTQZ7tC0mCkNQUQ99B8X5KBO0MRXycXxXsFPdFNk8x28JjOk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788683248; c=relaxed/simple; bh=sU/e0fY+v3yOZepe/bQAZAzN6JHKQnyoIpSt9leu59g=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ddrE/hRKodSm2vekhpyCcMM3Nf3OX1D9bQGEX8fNCDXTuLuL4LsfRTIsRMEhMWMYbka/BK+99zK2pxXaSt5hKl0o5dDI+n1lYYXikVodvIfJHvOQ9NbWJ3NctOEFeuRAIEIjDav41zb+cFPgYpA5EJplWNNo16Rg/eWrpuaU8JU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=B9xOmBhf; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="B9xOmBhf" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A1B3C1F00A3E; Sun, 6 Sep 2026 08:27:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1788683246; bh=+/DLks/ODhSSfW/GITBux87qvqpTH/gxUu8xFDYHwLA=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=B9xOmBhf5s1dNs5ihOaIRxoyVrbv3vnNPdqW1m1NfKoTMp2VCm129J6VEykH+qPZy TYo/4xEBX69W2vMkcM/8fu+tw+R4A9OS3OLvpBmVySnAEgusWdb85ZFx7idRl6qYmv 8iElq7IoQW46OE+TTLDuiloZmzhPMfm8DuRYIOkdyCVw0R9QiAaKQUVYyOOe2fdaKv lcJpzhvsJdNb52UKsz6NgKjJsBFqv5aA3FMT+9lqSulnkIrpwNf9N7FzssS3icUuFR vh5/spbemJxViWOplTH8NDh4Mc/rX3ETRLyXT1/ulYvl/lKJ4LgwU9W42ROUFOxjn3 Sdp2QgxR9wNnA== From: "Mike Rapoport (Microsoft)" Date: Sun, 06 Sep 2026 11:27:09 +0300 Subject: [PATCH v2 1/4] KVM: s390: Replace get_zeroed_page() with kzalloc() for the STHYI buffer Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260906-s390-kvm-v2-1-2cf6434e6646@kernel.org> References: <20260906-s390-kvm-v2-0-2cf6434e6646@kernel.org> In-Reply-To: <20260906-s390-kvm-v2-0-2cf6434e6646@kernel.org> To: Christian Borntraeger , Claudio Imbrenda , Janosch Frank Cc: Alexander Gordeev , David Hildenbrand , Heiko Carstens , Mike Rapoport , Sven Schnelle , Vasily Gorbik , Vlastimil Babka , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-s390@vger.kernel.org X-Mailer: b4 0.17-dev handle_sthyi() allocates the buffer that receives the STHYI response block before it is copied to the guest. This buffer can be allocated with kmalloc() as there's nothing special about it to go directly to the page allocator. kmalloc() provides a better API that does not require ugly casts and kfree() does not need to know the size of the freed object. Performance difference between kmalloc() and __get_free_pages() is not measurable as both allocators take an object/page from a per-CPU list for fast path allocations. For the slow path the performance is anyway determined by the amount of reclaim involved rather than by what allocator is used. The only goto in that function does not unwind anything, it merely skips to the exit when the function code is invalid. Turn it into an early return so that the buffer can be freed with __free(kfree). Replace use of get_zeroed_page() with kzalloc() and free_page() with kfree(). Assisted-by: copilot:claude-opus Signed-off-by: Mike Rapoport (Microsoft) Reviewed-by: Claudio Imbrenda Reviewed-by: Janosch Frank --- arch/s390/kvm/s390/intercept.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/arch/s390/kvm/s390/intercept.c b/arch/s390/kvm/s390/intercept.c index ca1205dfac8b0..f7ad111f259c9 100644 --- a/arch/s390/kvm/s390/intercept.c +++ b/arch/s390/kvm/s390/intercept.c @@ -11,6 +11,8 @@ #include #include #include +#include +#include =20 #include #include @@ -411,9 +413,9 @@ static int handle_partial_execution(struct kvm_vcpu *vc= pu) */ int handle_sthyi(struct kvm_vcpu *vcpu) { + struct sthyi_sctns *sctns __free(kfree) =3D NULL; int reg1, reg2, cc =3D 0, r =3D 0; u64 code, addr, rc =3D 0; - struct sthyi_sctns *sctns =3D NULL; =20 if (!test_kvm_facility(vcpu->kvm, 74)) return kvm_s390_inject_program_int(vcpu, PGM_OPERATION); @@ -430,37 +432,32 @@ int handle_sthyi(struct kvm_vcpu *vcpu) return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); =20 if (code & 0xffff) { - cc =3D 3; - rc =3D 4; - goto out; + vcpu->run->s.regs.gprs[reg2 + 1] =3D 4; + kvm_s390_set_psw_cc(vcpu, 3); + return 0; } =20 if (!kvm_s390_pv_cpu_is_protected(vcpu) && (addr & ~PAGE_MASK)) return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); =20 - sctns =3D (void *)get_zeroed_page(GFP_KERNEL_ACCOUNT); + sctns =3D kzalloc(PAGE_SIZE, GFP_KERNEL_ACCOUNT); if (!sctns) return -ENOMEM; =20 cc =3D sthyi_fill(sctns, &rc); - if (cc < 0) { - free_page((unsigned long)sctns); + if (cc < 0) return cc; - } -out: + if (!cc) { if (kvm_s390_pv_cpu_is_protected(vcpu)) { memcpy(sida_addr(vcpu->arch.sie_block), sctns, PAGE_SIZE); } else { r =3D write_guest(vcpu, addr, reg2, sctns, PAGE_SIZE); - if (r) { - free_page((unsigned long)sctns); + if (r) return kvm_s390_inject_prog_cond(vcpu, r); - } } } =20 - free_page((unsigned long)sctns); vcpu->run->s.regs.gprs[reg2 + 1] =3D rc; kvm_s390_set_psw_cc(vcpu, cc); return r; --=20 2.53.0 From nobody Sat Sep 26 01:39:01 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 98BE93C73C1; Sun, 6 Sep 2026 08:27:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788683251; cv=none; b=K6cArgpYLan3NJyoeq4PgS+E9H0MJg7W/zzWBfG1UqC+7TJrKrH2Tkd2gYal1DHlYJfme6t+7NyzhsXSVL8wVKuz1KsH8zla5onoSquWtDVUpwcguVMWkRjCHO99JUEDfqawsXrvNGiQA04Q8dUOKivYYd/7tmmL06T8TUR1tjA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788683251; c=relaxed/simple; bh=KjSvS6cVarz2EGcjO+qgUC/Z3Ug9TAUlDU9fkjFomJM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=okUgZDcatrCMLR6+qB+4aztj4roGFIcNhS6asVRHauW1Qse1/sPXCBzI/0gAxdoHfetq9EDkD47sQ1UOApksPtGsu5xERD3YyM/SCQQK0u6bKVczWCTiEAUYKD+bikdt+IJ7Xeq15W+PXCyJ6L47sKoq/gGbENfTFZpuXSLllKI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=AcR5c2yr; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="AcR5c2yr" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 361E51F00A3A; Sun, 6 Sep 2026 08:27:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1788683250; bh=YsA6hNpdDuoXhmxFeC3uv8uIXxR1ksQ/iBUtdB1feUs=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=AcR5c2yr8yOxaqMU6PZEBu6m02H8NVpIdqeHBB2EFX2dbaMH3nSarLvRXgeWGBiM7 MIeq9DCB9ddMgZ9WeZwLv9n9Y20tR0MzTXQj27Hwib1mXac85h8xBvnuyCvHWezux2 JIfpisVjB0kWI3S0X3DZ9SuUMtd+02l8kekxpIcWiS19ONEN8aUAy+NihFDQo50gZq 53+02iM0MXsyxPvBUALso3DG9nZBiUHyTVdEGOXM0u10Vm8Kaf7ONJfjE+tVA10+dk 78/QrcPBTu8wyNMeh/0ockC9hYKzU2A2vYBSNZhg9kITxws6XQw3NY2P6WmueaV82Z hfqq6KEYyZXHA== From: "Mike Rapoport (Microsoft)" Date: Sun, 06 Sep 2026 11:27:10 +0300 Subject: [PATCH v2 2/4] KVM: s390: Replace get_zeroed_page() with kzalloc() for the STSI buffer Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260906-s390-kvm-v2-2-2cf6434e6646@kernel.org> References: <20260906-s390-kvm-v2-0-2cf6434e6646@kernel.org> In-Reply-To: <20260906-s390-kvm-v2-0-2cf6434e6646@kernel.org> To: Christian Borntraeger , Claudio Imbrenda , Janosch Frank Cc: Alexander Gordeev , David Hildenbrand , Heiko Carstens , Mike Rapoport , Sven Schnelle , Vasily Gorbik , Vlastimil Babka , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-s390@vger.kernel.org X-Mailer: b4 0.17-dev handle_stsi() allocates the buffer that receives the STSI response block before it is copied to the guest. This buffer can be allocated with kmalloc() as there's nothing special about it to go directly to the page allocator. kmalloc() provides a better API that does not require ugly casts and kfree() does not need to know the size of the freed object. Performance difference between kmalloc() and __get_free_pages() is not measurable as both allocators take an object/page from a per-CPU list for fast path allocations. For the slow path the performance is anyway determined by the amount of reclaim involved rather than by what allocator is used. While on it, make the buffer a void pointer to get rid of the casts. Replace use of get_zeroed_page() with kzalloc() and free_page() with kfree(). Link: https://lore.kernel.org/all/635405e4-9423-4a25-a6e7-e03c8ea0bcbe@redh= at.com Assisted-by: copilot:claude-opus Signed-off-by: Mike Rapoport (Microsoft) Reviewed-by: Claudio Imbrenda Reviewed-by: Janosch Frank --- arch/s390/kvm/s390/priv.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/arch/s390/kvm/s390/priv.c b/arch/s390/kvm/s390/priv.c index b3cb2c2c3aa71..856939acf012f 100644 --- a/arch/s390/kvm/s390/priv.c +++ b/arch/s390/kvm/s390/priv.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -869,7 +870,7 @@ static int handle_stsi(struct kvm_vcpu *vcpu) int fc =3D (vcpu->run->s.regs.gprs[0] & 0xf0000000) >> 28; int sel1 =3D vcpu->run->s.regs.gprs[0] & 0xff; int sel2 =3D vcpu->run->s.regs.gprs[1] & 0xffff; - unsigned long mem =3D 0; + void *mem =3D NULL; u64 operand2; int rc =3D 0; u8 ar; @@ -911,19 +912,19 @@ static int handle_stsi(struct kvm_vcpu *vcpu) switch (fc) { case 1: /* same handling for 1 and 2 */ case 2: - mem =3D get_zeroed_page(GFP_KERNEL_ACCOUNT); + mem =3D kzalloc(PAGE_SIZE, GFP_KERNEL_ACCOUNT); if (!mem) goto out_no_data; - if (stsi((void *) mem, fc, sel1, sel2)) + if (stsi(mem, fc, sel1, sel2)) goto out_no_data; break; case 3: if (sel1 !=3D 2 || sel2 !=3D 2) goto out_no_data; - mem =3D get_zeroed_page(GFP_KERNEL_ACCOUNT); + mem =3D kzalloc(PAGE_SIZE, GFP_KERNEL_ACCOUNT); if (!mem) goto out_no_data; - handle_stsi_3_2_2(vcpu, (void *) mem); + handle_stsi_3_2_2(vcpu, mem); break; case 15: /* fc 15 is fully handled in userspace */ insert_stsi_usr_data(vcpu, operand2, ar, fc, sel1, sel2); @@ -931,10 +932,10 @@ static int handle_stsi(struct kvm_vcpu *vcpu) return -EREMOTE; } if (kvm_s390_pv_cpu_is_protected(vcpu)) { - memcpy(sida_addr(vcpu->arch.sie_block), (void *)mem, PAGE_SIZE); + memcpy(sida_addr(vcpu->arch.sie_block), mem, PAGE_SIZE); rc =3D 0; } else { - rc =3D write_guest(vcpu, operand2, ar, (void *)mem, PAGE_SIZE); + rc =3D write_guest(vcpu, operand2, ar, mem, PAGE_SIZE); } if (rc) { rc =3D kvm_s390_inject_prog_cond(vcpu, rc); @@ -945,14 +946,14 @@ static int handle_stsi(struct kvm_vcpu *vcpu) rc =3D -EREMOTE; } trace_kvm_s390_handle_stsi(vcpu, fc, sel1, sel2, operand2); - free_page(mem); + kfree(mem); kvm_s390_set_psw_cc(vcpu, 0); vcpu->run->s.regs.gprs[0] =3D 0; return rc; out_no_data: kvm_s390_set_psw_cc(vcpu, 3); out: - free_page(mem); + kfree(mem); return rc; } =20 --=20 2.53.0 From nobody Sat Sep 26 01:39:01 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2783A39EF20; Sun, 6 Sep 2026 08:27:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788683257; cv=none; b=CI2QZiAFhqyiSm7ysE7yyNAXfsO4i5ukHCyuuN/wnBadU2B5AAIhuJ/utrp/11Kv9RH+onoTNr/HNCEojyqsxpws4+IvfwMdcXP+c8WQygCI2O7kZYaX+gTLeGdgJSkU+Tjig1MA1OPOIaS3VMmdE9bAsOKirQAMEEPLVPzUg4c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788683257; c=relaxed/simple; bh=3Kxvl3vX0xOruGJqXO47tS1ILmPa2NLsdEexPXqkiRw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=drqnJYe+woEh5ZHsXsY1sSS1MFkllUt2gvFgGPTCRGz7euzmAK6CN0xlPSj7B+p9AMEx//tjmz9csadNUENxo0LYA7qfCJ5B7wQ6CB6KS2AtgaeRvLGBEfSIUrPZ5S/QONlR+imu87VBRDX9XBU4QmB+5eBR9aq7dIRhQMLA7mA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=PYMp5XZs; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="PYMp5XZs" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BE4A11F00A3D; Sun, 6 Sep 2026 08:27:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1788683253; bh=JMHG+THezrVqv+LxM1LlqqUzwwh90wkGAEXs+OQ+QKU=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=PYMp5XZs0RSikeOmuwhKduqniWT3hGFAXvR0qtGbALX9yosr5KePfNaVKRg2SYiMw McPUiTok5nieRhEXBdSvYsbnohtBT6eIH7uo8rKYD0KjrtCe939rzxcAOi7eKhdzlK /J5jg6Cs50eL9nyAeDEwkb+kVAhGHqCa9HptydJc36ezW2aYQTWAVT2zJ3s2BvoZJ9 ZU0XIXucyOWL9vLlOdtrggfum95IivONi/zf+Z5UuI5qMUYm2kprd8LNgSvJL3nSRh l7+Y6tYXYBM614JIt91OPc+lOS0AklR7KTb2Ql8XHR7x5kg4z9UfusC95OUyZpMewN kXn39hX7a6AbA== From: "Mike Rapoport (Microsoft)" Date: Sun, 06 Sep 2026 11:27:11 +0300 Subject: [PATCH v2 3/4] KVM: s390: Replace get_zeroed_page() with kzalloc() for the GIB Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260906-s390-kvm-v2-3-2cf6434e6646@kernel.org> References: <20260906-s390-kvm-v2-0-2cf6434e6646@kernel.org> In-Reply-To: <20260906-s390-kvm-v2-0-2cf6434e6646@kernel.org> To: Christian Borntraeger , Claudio Imbrenda , Janosch Frank Cc: Alexander Gordeev , David Hildenbrand , Heiko Carstens , Mike Rapoport , Sven Schnelle , Vasily Gorbik , Vlastimil Babka , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-s390@vger.kernel.org X-Mailer: b4 0.17-dev kvm_s390_gib_init() allocates the guest information block (GIB). The GIB is passed to the hardware as a physical address and must be page aligned. kmalloc() guarantees that a power of two sized allocation is aligned to its size, so a PAGE_SIZE allocation is page aligned as well. This buffer can be allocated with kmalloc() as there's nothing special about it to go directly to the page allocator. kmalloc() provides a better API that does not require ugly casts and kfree() does not need to know the size of the freed object. Performance difference between kmalloc() and __get_free_pages() is not measurable as both allocators take an object/page from a per-CPU list for fast path allocations. For the slow path the performance is anyway determined by the amount of reclaim involved rather than by what allocator is used. Replace use of get_zeroed_page() with kzalloc() and free_page() with kfree(). Link: https://lore.kernel.org/all/635405e4-9423-4a25-a6e7-e03c8ea0bcbe@redh= at.com Assisted-by: copilot:claude-opus Signed-off-by: Mike Rapoport (Microsoft) Reviewed-by: Claudio Imbrenda Reviewed-by: Janosch Frank --- arch/s390/kvm/s390/interrupt.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/arch/s390/kvm/s390/interrupt.c b/arch/s390/kvm/s390/interrupt.c index 0381ae9817035..02065fb8d053e 100644 --- a/arch/s390/kvm/s390/interrupt.c +++ b/arch/s390/kvm/s390/interrupt.c @@ -3689,7 +3689,7 @@ void kvm_s390_gib_destroy(void) } chsc_sgib(0); unregister_adapter_interrupt(&gib_alert_irq); - free_page((unsigned long)gib); + kfree(gib); gib =3D NULL; } =20 @@ -3703,7 +3703,7 @@ int __init kvm_s390_gib_init(u8 nisc) goto out; } =20 - gib =3D (struct kvm_s390_gib *)get_zeroed_page(GFP_KERNEL_ACCOUNT | GFP_D= MA); + gib =3D kzalloc(PAGE_SIZE, GFP_KERNEL_ACCOUNT | GFP_DMA); if (!gib) { rc =3D -ENOMEM; goto out; @@ -3722,7 +3722,7 @@ int __init kvm_s390_gib_init(u8 nisc) gib_origin =3D virt_to_phys(gib); if (chsc_sgib(gib_origin)) { pr_err("Associating the GIB with the AIV facility failed\n"); - free_page((unsigned long)gib); + kfree(gib); gib =3D NULL; rc =3D -EIO; goto out_unreg_gal; @@ -3742,7 +3742,7 @@ int __init kvm_s390_gib_init(u8 nisc) out_unreg_gal: unregister_adapter_interrupt(&gib_alert_irq); out_free_gib: - free_page((unsigned long)gib); + kfree(gib); gib =3D NULL; out: return rc; --=20 2.53.0 From nobody Sat Sep 26 01:39:01 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B73C441F345; Sun, 6 Sep 2026 08:27:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788683259; cv=none; b=eiqMAoS5SPhnlK7peeOfrOGBq3QwldJdDysa3RVTuHSV/NJ/sVA5kPeVxlMcemUdRR0D0ty4CIWc7eCaETJnvKkofIgdfCv4/MRzULv73gHragx7XKia0+RuVXbt3Aa6lo3S3lYX14O+I5mFBMWBJkf/7IcxKXWqtRGsh4Z8AEo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788683259; c=relaxed/simple; bh=ufJh+vhtA2xE8IFkFr5agtYfSUKrc8pWqo1ChrJW9AM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=LnB/uwIaHS8K0RWDCrGgwFBRWWaclhZ5P7V1ETtXb/AqfrjoCdcdm1v4ZSwk+j277PLvZjEGnuJn/DcNVLnOD2/yHJZZgkB1D6OQc87Cx/YQs3kEVLGs8IUXreCE1ywMDnxs526YvLvwa8KnuO2GKsJj1HR0hJgSjY7NL4nqVQ4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=LEaSjZJz; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="LEaSjZJz" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5210C1F00A3A; Sun, 6 Sep 2026 08:27:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1788683257; bh=s9ZM75Oj1X5kSc3IVFNLWbiJNUqBfJ8HFbN3imH3XNM=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=LEaSjZJzcZh5DGcvXdyiiI5ZPI69KmLsiONdb27CcK2pOBlqgkoLV9ANAKT6N6QJt QVJooOn5NfL8Z8krU/IidkYMfWo7mwRRGt6q1jyMMgc8fnFqs+8HJS4beV3f7vui0t zDGgt1ejbZhXGLMlb0Xf0C6KPo2gj5gyKUid8F/0n33qu4cSi3mgKV2QPsM8C2k6ds L7cqss+5Ej9CDdnO6SxSHcK04CLzQ/KrPrOgvhy9KZlrt4uiAbSiYACkYWXMp5RaSu aly5fL+egIsPNx0EQ/fkGBZRXeUExX3kZyAOkBo7MmbvJIgHZWLCQmcz3dXghQD7VZ +IB2+fC92Tr5Q== From: "Mike Rapoport (Microsoft)" Date: Sun, 06 Sep 2026 11:27:12 +0300 Subject: [PATCH v2 4/4] KVM: s390: Replace get_zeroed_page() with kzalloc() for sie_page2 and CMMA Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260906-s390-kvm-v2-4-2cf6434e6646@kernel.org> References: <20260906-s390-kvm-v2-0-2cf6434e6646@kernel.org> In-Reply-To: <20260906-s390-kvm-v2-0-2cf6434e6646@kernel.org> To: Christian Borntraeger , Claudio Imbrenda , Janosch Frank Cc: Alexander Gordeev , David Hildenbrand , Heiko Carstens , Mike Rapoport , Sven Schnelle , Vasily Gorbik , Vlastimil Babka , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-s390@vger.kernel.org X-Mailer: b4 0.17-dev kvm_arch_init_vm() allocates struct sie_page2 that holds the facility list and the crypto control block of a VM and kvm_s390_vcpu_setup_cmma() allocates the CMMA collaborative memory management block referenced by the SIE control block. Both are passed to the hardware as physical addresses and must be page aligned. kmalloc() guarantees that a power of two sized allocation is aligned to its size, so a PAGE_SIZE allocation is page aligned as well. These buffers can be allocated with kmalloc() as there's nothing special about them to go directly to the page allocator. kmalloc() provides a better API that does not require ugly casts and kfree() does not need to know the size of the freed object. Performance difference between kmalloc() and __get_free_pages() is not measurable as both allocators take an object/page from a per-CPU list for fast path allocations. For the slow path the performance is anyway determined by the amount of reclaim involved rather than by what allocator is used. The sie_page allocated in kvm_arch_vcpu_create() is left alone because it is mapped to userspace with virt_to_page() in kvm_arch_vcpu_fault() and therefore really needs a struct page. The SIE hardware stores the offset of the next CBR entry in the low bits of cbrlo, so mask them out before converting cbrlo back to a virtual address. free_page() did not care, kfree() needs the address kzalloc() returned. Replace use of get_zeroed_page() with kzalloc() and free_page() with kfree(). Link: https://lore.kernel.org/all/635405e4-9423-4a25-a6e7-e03c8ea0bcbe@redh= at.com Assisted-by: copilot:claude-opus Signed-off-by: Mike Rapoport (Microsoft) Reviewed-by: Claudio Imbrenda Reviewed-by: Janosch Frank --- arch/s390/kvm/s390/s390.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/arch/s390/kvm/s390/s390.c b/arch/s390/kvm/s390/s390.c index b0839e887221e..1d9eea64f3dbd 100644 --- a/arch/s390/kvm/s390/s390.c +++ b/arch/s390/kvm/s390/s390.c @@ -3273,8 +3273,8 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long t= ype) goto out_err; =20 BUILD_BUG_ON(sizeof(struct sie_page2) !=3D 4096); - kvm->arch.sie_page2 =3D - (struct sie_page2 *) get_zeroed_page(GFP_KERNEL_ACCOUNT | GFP_DMA); + kvm->arch.sie_page2 =3D kzalloc_obj(*kvm->arch.sie_page2, + GFP_KERNEL_ACCOUNT | GFP_DMA); if (!kvm->arch.sie_page2) goto out_err; =20 @@ -3369,7 +3369,7 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long t= ype) =20 return 0; out_err: - free_page((unsigned long)kvm->arch.sie_page2); + kfree(kvm->arch.sie_page2); debug_unregister(kvm->arch.dbf); sca_dispose(kvm); KVM_EVENT(3, "creation of vm failed: %d", rc); @@ -3427,7 +3427,7 @@ void kvm_arch_destroy_vm(struct kvm *kvm) mmu_notifier_unregister(&kvm->arch.pv.mmu_notifier, kvm->mm); =20 debug_unregister(kvm->arch.dbf); - free_page((unsigned long)kvm->arch.sie_page2); + kfree(kvm->arch.sie_page2); kvm_s390_destroy_adapters(kvm); kvm_s390_clear_float_irqs(kvm); kvm_s390_vsie_destroy(kvm); @@ -3657,13 +3657,13 @@ static void kvm_s390_vcpu_crypto_setup(struct kvm_v= cpu *vcpu) void kvm_s390_vcpu_unsetup_cmma(struct kvm_vcpu *vcpu) { if (vcpu->arch.sie_block->cbrlo) - free_page((unsigned long)phys_to_virt(vcpu->arch.sie_block->cbrlo)); + kfree(phys_to_virt(vcpu->arch.sie_block->cbrlo & PAGE_MASK)); vcpu->arch.sie_block->cbrlo =3D 0; } =20 int kvm_s390_vcpu_setup_cmma(struct kvm_vcpu *vcpu) { - void *cbrlo_page =3D (void *)get_zeroed_page(GFP_KERNEL_ACCOUNT); + void *cbrlo_page =3D kzalloc(PAGE_SIZE, GFP_KERNEL_ACCOUNT); =20 if (!cbrlo_page) return -ENOMEM; --=20 2.53.0