From nobody Mon Feb 9 23:19:12 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=arm.com Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1770140865576476.5131000062888; Tue, 3 Feb 2026 09:47:45 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.1219612.1528492 (Exim 4.92) (envelope-from ) id 1vnKUn-0006JD-Gp; Tue, 03 Feb 2026 17:47:25 +0000 Received: by outflank-mailman (output) from mailman id 1219612.1528492; Tue, 03 Feb 2026 17:47:25 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1vnKUn-0006J6-Cj; Tue, 03 Feb 2026 17:47:25 +0000 Received: by outflank-mailman (input) for mailman id 1219612; Tue, 03 Feb 2026 17:47:23 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1vnKMe-0000Zt-R6 for xen-devel@lists.xenproject.org; Tue, 03 Feb 2026 17:39:00 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-flk1.inumbo.com (Halon) with ESMTP id 36fa34b3-0127-11f1-9ccf-f158ae23cfc8; Tue, 03 Feb 2026 18:38:56 +0100 (CET) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 84871497; Tue, 3 Feb 2026 09:38:49 -0800 (PST) Received: from C3HXLD123V.arm.com (unknown [10.57.54.220]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id E1D003F632; Tue, 3 Feb 2026 09:38:54 -0800 (PST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 36fa34b3-0127-11f1-9ccf-f158ae23cfc8 From: Bertrand Marquis To: xen-devel@lists.xenproject.org Cc: Volodymyr Babchuk , Jens Wiklander , Stefano Stabellini , Julien Grall , Michal Orzel Subject: [PATCH 11/12] xen/arm: ffa: Add MEM_SHARE page diagnostics Date: Tue, 3 Feb 2026 18:38:06 +0100 Message-ID: <94e10f14d499d7e584fb0fbdd28d0288bb5831bd.1770115302.git.bertrand.marquis@arm.com> X-Mailer: git-send-email 2.51.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1770140867576158500 Content-Type: text/plain; charset="utf-8" MEM_SHARE failures in get_shm_pages() are silent, which makes malformed ranges and page mapping failures hard to diagnose. Add debug logging for page validation failures: - descriptor validation failures (unaligned, range short/overflow) - per-page mapping failures (unmapped GFN, wrong p2m type) - address overflow detection in range walks Ratelimit temporary reclaim failures and log permanent reclaim failures as errors. No functional changes. Signed-off-by: Bertrand Marquis --- xen/arch/arm/tee/ffa_shm.c | 73 ++++++++++++++++++++++++++++++++------ 1 file changed, 63 insertions(+), 10 deletions(-) diff --git a/xen/arch/arm/tee/ffa_shm.c b/xen/arch/arm/tee/ffa_shm.c index 905a64e3db01..89161753e922 100644 --- a/xen/arch/arm/tee/ffa_shm.c +++ b/xen/arch/arm/tee/ffa_shm.c @@ -169,6 +169,12 @@ static int32_t get_shm_pages(struct domain *d, struct = ffa_shm_mem *shm, uint64_t addr; uint64_t page_count; uint64_t gaddr; + int32_t ret =3D FFA_RET_OK; + const char *reason =3D NULL; + unsigned int bad_rg =3D 0; + unsigned int bad_pg =3D 0; + unsigned long bad_addr =3D 0; + p2m_type_t bad_t =3D p2m_invalid; =20 for ( n =3D 0; n < range_count; n++ ) { @@ -176,34 +182,78 @@ static int32_t get_shm_pages(struct domain *d, struct= ffa_shm_mem *shm, addr =3D ACCESS_ONCE(range[n].address); =20 if ( !IS_ALIGNED(addr, FFA_PAGE_SIZE) ) - return FFA_RET_INVALID_PARAMETERS; + { + ret =3D FFA_RET_INVALID_PARAMETERS; + reason =3D "unaligned"; + bad_rg =3D n; + bad_addr =3D (unsigned long)addr; + goto out; + } =20 for ( m =3D 0; m < page_count; m++ ) { if ( pg_idx >=3D shm->page_count ) - return FFA_RET_INVALID_PARAMETERS; + { + ret =3D FFA_RET_INVALID_PARAMETERS; + reason =3D "range overflow"; + bad_rg =3D n; + bad_pg =3D m; + goto out; + } =20 if ( !ffa_safe_addr_add(addr, m) ) - return FFA_RET_INVALID_PARAMETERS; + { + ret =3D FFA_RET_INVALID_PARAMETERS; + reason =3D "addr overflow"; + bad_rg =3D n; + bad_pg =3D m; + bad_addr =3D (unsigned long)addr; + goto out; + } =20 gaddr =3D addr + m * FFA_PAGE_SIZE; gfn =3D gaddr_to_gfn(gaddr); shm->pages[pg_idx] =3D get_page_from_gfn(d, gfn_x(gfn), &t, P2M_ALLOC); if ( !shm->pages[pg_idx] ) - return FFA_RET_DENIED; + { + ret =3D FFA_RET_DENIED; + reason =3D "gfn unmapped"; + bad_rg =3D n; + bad_pg =3D m; + bad_addr =3D (unsigned long)gaddr; + goto out; + } /* Only normal RW RAM for now */ if ( t !=3D p2m_ram_rw ) - return FFA_RET_DENIED; + { + ret =3D FFA_RET_DENIED; + reason =3D "p2m type"; + bad_rg =3D n; + bad_pg =3D m; + bad_addr =3D (unsigned long)gaddr; + bad_t =3D t; + goto out; + } pg_idx++; } } =20 /* The ranges must add up */ if ( pg_idx < shm->page_count ) - return FFA_RET_INVALID_PARAMETERS; + { + ret =3D FFA_RET_INVALID_PARAMETERS; + reason =3D "range short"; + bad_pg =3D pg_idx; + goto out; + } =20 - return FFA_RET_OK; +out: + if ( ret ) + gdprintk(XENLOG_DEBUG, + "ffa: mem share pages invalid: %s rg %u pg %u addr %#lx p= 2m %u\n", + reason ? reason : "unknown", bad_rg, bad_pg, bad_addr, ba= d_t); + return ret; } =20 static void put_shm_pages(struct ffa_shm_mem *shm) @@ -759,8 +809,10 @@ bool ffa_shm_domain_destroy(struct domain *d) * A temporary error that may get resolved a bit later, it's * worth retrying. */ - printk(XENLOG_G_INFO "%pd: ffa: Failed to reclaim handle %#lx = : %d\n", - d, shm->handle, res); + if ( printk_ratelimit() ) + printk(XENLOG_G_WARNING + "%pd: ffa: Failed to reclaim handle %#lx : %d\n", + d, shm->handle, res); break; /* We will retry later */ default: /* @@ -772,7 +824,8 @@ bool ffa_shm_domain_destroy(struct domain *d) * FFA_RET_NO_MEMORY might be a temporary error as it it could * succeed if retried later, but treat it as permanent for now. */ - printk(XENLOG_G_INFO "%pd: ffa: Permanent failure to reclaim h= andle %#lx : %d\n", + printk(XENLOG_G_ERR + "%pd: ffa: Permanent failure to reclaim handle %#lx : %= d\n", d, shm->handle, res); =20 /* --=20 2.50.1 (Apple Git-155)