From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (prime256v1) server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8DFCA606A327 for ; Mon, 30 Nov 2026 16:46:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=ZmIh777w Received: from list by lists.xenproject.org with outflank-mailman.1508042.1701066 (Exim 4.92) (envelope-from ) id 1xY4Vn-0000ZP-Q3; Mon, 30 Nov 2026 16:45:55 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 1508042.1701066; Mon, 30 Nov 2026 16:45:55 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1xY4Vn-0000ZH-Me; Mon, 30 Nov 2026 16:45:55 +0000 Received: by outflank-mailman (input) for mailman id 1508042; Mon, 30 Nov 2026 16:45:55 +0000 Received: from mx.expurgate.net ([195.190.135.20]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1xY4Vn-0000S7-4I for xen-devel@lists.xenproject.org; Mon, 30 Nov 2026 16:45:55 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1xY4Vm-009kJh-Gz for xen-devel@lists.xenproject.org; Mon, 30 Nov 2026 17:45:54 +0100 Received: from [10.42.69.1] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6b0da838-2eae-0a2a0a5409dd-0a2a4501a1b6-20 for ; Mon, 30 Nov 2026 17:45:54 +0100 Received: from [209.85.221.47] (helo=mail-wr1-f47.google.com) by tlsNG-d62444.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from ) id 6b0da842-5bcc-0a2a45010019-d155dd2fa8aa-3 for ; Mon, 30 Nov 2026 17:45:54 +0100 Received: by mail-wr1-f47.google.com with SMTP id ffacd0b85a97d-4a5024b3c28so6624735f8f.0 for ; Mon, 30 Nov 2026 08:45:54 -0800 (PST) Received: from ws-fedora.tail006fee.ts.net (cm-93-156-219-234.telecable.es. [93.156.219.234]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4ab6a67fe75sm75312283f8f.24.2026.11.30.08.45.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 08:45:53 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Post: List-Help: List-Subscribe: , Precedence: list Sender: "Xen-devel" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=20260707 header.d=gmail.com header.i="@gmail.com" header.h="Content-Transfer-Encoding:Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796057154; x=1796661954; darn=lists.xenproject.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to:content-type; bh=aOeq6BK9hkk+O5vadqhGysxA+pfeZgwnF6lf5WGcGSs=; b=ZmIh777wt8hx2z45TQ3+4O6thvE1EiMJzIQj/DEuyCYW9E3X2cOxSCe737UPzfjPov 1B+mgh34iPLVV7ivEmZ+uvjbXRlo7j/Z2TnJmr0qtxbvbpDVO89EXRITCCw8uzj4tGOy q6H+BGKP/WSNReVxoRVJcxvNvVPYpRP6IwSbZOo3UZWdsoCzTWW35TyCBIeDLsW/JIt1 SNy8fYmmSwkKGOXNRsoRKvgvUDL4z/wKwBivkLSiPSe6nbrZiAHC7/QrW678iz6n9PrU 2Pi9VhBT7ooepGFxjlgsGNQi+w6BvB242GM760TwZvioNIhPYl/XFX3ms/vv4iERC7gL 7M2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796057154; x=1796661954; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=aOeq6BK9hkk+O5vadqhGysxA+pfeZgwnF6lf5WGcGSs=; b=otnDLUQnV1+Y0k0vUX+TcXEhnRDcjG1Gpa0dibu9mC01g1rDjTcAsgQDSXjXmlScad Xr9KhO+sqynG4rkoP8kWaZJ2aFvKi8mF/FEr+e1/dwtqT+Flsqo54u5wRUf8TRNQDpyi Lbd0kMrJw7XQPZLJa0o5hD0bp9/RFH41n6LYpXfJNlMDMjhFkjEXQidvcaItstIx+7BX PDeN4IOzTFKznDgC7pnZtMF47Rc/WVcmAHxdlsFGAw4Bdw9US86K36c/iTQyONXamjcn psA1T8NZdOB3t1zxArgnjLO4m5xQFmY7DOQhTNDFFr4LgTh9oqqRIGz8kx/kyUsO67H8 0T8w== X-Gm-Message-State: APuU4Z8tIAdJyc3HIMSsWvGbo+8UtxcMT/ZD1IlgFBKQcwAunxqD6aK7 t6w2hOy7eGZ2DmecvCiDoj5tJhguuOUz870G4tU80q7jzn4SoAGko5LbefyQphFl X-Gm-Gg: AZFdTZc24o9Lm21NpA8AyCbNyr0uuvbpMvawW5jJ95G34gE27Pqis+Bhuf46cCcCvO0 pXJ9tCsR7V/NYmuUNx61iVP2R6zZyvauOe/8/NKHDvHlci/O7GGTRONeP8+HFj5m8ypv/0Wdkkz +WUFb+pRKIGgZz+nDymOlARrN68E46EkNwb17eB73tL4y9kDNQ5mCznx0xNrUhwR/lvcbEb6y3+ sVzz3+iAchYZmS3qllM1nrbt5DiuuOtL3WipXT9pjGNjg7K8M7Zuf6kK7lh9qw2ZLoBOOK3T68u gGOHRP4TybzJjZ8+X8Y28GWYtTzfpmI0bS6xz8H+w113x/d/CiYGClo+sfYf6nvLuAUlM9QefZG g/UmrNs+R6FPV+7MPpU0Aob/49HNx+gQdhilriqdPRMRd3lEnnjOAKq9Pn1BEknSdqfWdjtfuFZ OpfdovB+wziCK4pa6jvoy/gTVyxU0/nHBjRUXZx6JjqzEBp0kLEOTFAKZm5sAY7/5XCebP0X6ID ZDmqfAac52bvnbdH02KziDfAmufrzABP6DSunm4cfEbyumy95Wh64VtrqEW0AM5m3FNOxYKdhSc w0EZNGTFC8ZXAVCQw/i/GCBZJha/FAFPI+AWvuyUwfLPEn5gQEVNog9LF0y9jyPHE9fPX/SEt+9 xJhNmyakxMg== X-Received: by 2002:a05:6000:1acc:b0:4c8:135e:b43c with SMTP id ffacd0b85a97d-4c8135eb4bdmr4325430f8f.6.1796057153883; Mon, 30 Nov 2026 08:45:53 -0800 (PST) From: =?UTF-8?q?Gabriel=20Quint=C3=A1ns=20Souto?= To: xen-devel@lists.xenproject.org Cc: Luca Fancellu , =?UTF-8?q?Gabriel=20Quint=C3=A1ns=20Souto?= , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk Subject: [PATCH 2/3] xen/arm: p2m: split level 1 foreign superpages for preemption Date: Mon, 30 Nov 2026 17:43:23 +0100 Message-ID: <20261130164324.47726-3-gabi.qs.mail@gmail.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261130164324.47726-1-gabi.qs.mail@gmail.com> References: <20261130164324.47726-1-gabi.qs.mail@gmail.com> X-Archived-By: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-purgate-ID: tlsNG-d62444/1796057154-4C9575FD-93110103/0/0 X-purgate-type: clean X-purgate-size: 2765 X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_PASS,SPF_PASS,UNPARSEABLE_RELAY, USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 Static shared memory can create 1GB foreign mappings, as p2m_set_entry() picks the mapping size based only on alignment. p2m_put_page() doesn't have a put for level 1, so the references of such a mapping are never dropped, the pages are never freed and destroying the owner never completes. Putting the references of a 1GB block at once would take too long without being able to preempt, since relinquish_p2m_mapping() can only be preempted between entries. By changing the order to 2MB, __p2m_set_entry() can split the superpage and therefore put 2MB blocks, allowing the preemption check in relinquish_p2m_mapping() to work properly. For that, the check also needs ">=" instead of ">". Signed-off-by: Gabriel Quintáns Souto --- xen/arch/arm/mmu/p2m.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/xen/arch/arm/mmu/p2m.c b/xen/arch/arm/mmu/p2m.c index bc6d196..e7a27db 100644 --- a/xen/arch/arm/mmu/p2m.c +++ b/xen/arch/arm/mmu/p2m.c @@ -1595,6 +1595,13 @@ int relinquish_p2m_mapping(struct domain *d) start = gfn_next_boundary(start, order) ) { mfn_t mfn = p2m_get_entry(p2m, start, &t, NULL, &order, NULL); + bool split = false; + + if ( p2m_is_foreign(t) && order == XEN_PT_LEVEL_ORDER(1) ) + { + order = XEN_PT_LEVEL_ORDER(2); + split = true; + } count++; /* @@ -1602,7 +1609,7 @@ int relinquish_p2m_mapping(struct domain *d) * foreign mapping. */ if ( (!(count % 512) || - (p2m_is_foreign(t) && (order > XEN_PT_LEVEL_ORDER(2)))) && + (p2m_is_foreign(t) && (order >= XEN_PT_LEVEL_ORDER(2)))) && hypercall_preempt_check() ) { rc = -ERESTART; @@ -1621,6 +1628,16 @@ int relinquish_p2m_mapping(struct domain *d) */ rc = __p2m_set_entry(p2m, start, order, INVALID_MFN, p2m_invalid, p2m_access_rwx); + if ( unlikely(rc == -ENOMEM && split) ) + { + /* + * Shattering the foreign superpage needs a page from the P2M + * pool. If none is left, remove the whole superpage at once. + */ + order = XEN_PT_LEVEL_ORDER(1); + rc = __p2m_set_entry(p2m, start, order, INVALID_MFN, + p2m_invalid, p2m_access_rwx); + } if ( unlikely(rc) ) { printk(XENLOG_G_ERR "Unable to remove mapping gfn=%#"PRI_gfn" order=%u from the p2m of domain %d\n", gfn_x(start), order, d->domain_id); -- 2.56.0