From nobody Mon Feb 9 16:56:05 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; dkim=pass; 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=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1746520521; cv=none; d=zohomail.com; s=zohoarc; b=FceAzI/LC6FHgQjbf1re8LmKj3JvZWQ8xR5QAgcIx0AmhoVtb45cGlZv0sdphEFzM3hbuht4ZjIhPAyKxXmY1sqS+ADPLjmdtaj5W/505NqVejDFiHA8chwSMCwy1TbMTG44VQp0UUykgxa8KKqOJNFwNpq+SYSsB8VtVpulNo8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1746520521; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=fgghoeas14+y+/fNB0eokRVfIB1w/ZzOUGRan/5YZkA=; b=c7diXp+eJm/ryz+02pHykBiodOJqzvqiS5yCqCwH7x/CaRnq7g5FCuIwh5ogiWLWKiD4aHbD1+s6NQGzqbO4fFMXf31dHjZjljOE6M/ItxIZ1NUqftv33hwuGcm4qNObCoYPfTcq6mN+Z/xYi1yotzgYhTl5XDpeqPtZbBBBDew= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1746520521204213.1225651715663; Tue, 6 May 2025 01:35:21 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.976751.1363933 (Exim 4.92) (envelope-from ) id 1uCDlO-0005E5-8C; Tue, 06 May 2025 08:34:54 +0000 Received: by outflank-mailman (output) from mailman id 976751.1363933; Tue, 06 May 2025 08:34:54 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1uCDlO-0005DP-3i; Tue, 06 May 2025 08:34:54 +0000 Received: by outflank-mailman (input) for mailman id 976751; Tue, 06 May 2025 08:34:52 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1uCDlM-00048v-7Q for xen-devel@lists.xenproject.org; Tue, 06 May 2025 08:34:52 +0000 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [2a00:1450:4864:20::32f]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id fa5497cd-2a54-11f0-9eb4-5ba50f476ded; Tue, 06 May 2025 10:34:51 +0200 (CEST) Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-43d2d952eb1so29529405e9.1 for ; Tue, 06 May 2025 01:34:51 -0700 (PDT) Received: from localhost ([84.78.159.3]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-441b2b20b36sm207541225e9.25.2025.05.06.01.34.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 May 2025 01:34:50 -0700 (PDT) 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: fa5497cd-2a54-11f0-9eb4-5ba50f476ded DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1746520491; x=1747125291; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=fgghoeas14+y+/fNB0eokRVfIB1w/ZzOUGRan/5YZkA=; b=PlC5a2Y5PlpVAQwWiv0r0U/TDy/bZtUJRfwTKGNhnvC1jRMnOoaWZcVGhBVPYmo8sl OuMAsNpnjJg7YHKu08OhT5UaSW1+kycz3gr7H0vPkK2kvHaGC0YLZbsmdJq5Su4RXDQI a8ChVLK63iTullXW5ZwVSv67pLBPyerbGgoKM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1746520491; x=1747125291; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fgghoeas14+y+/fNB0eokRVfIB1w/ZzOUGRan/5YZkA=; b=iP6iRIF5xDMFp0exGxq8CyH/ov7Mm9yweGKtb5lNQzQL0m+tJPK6S9VKq+d0RJlgLo Yfj6PwcqHtt7gSqOGeFhCoOtjzLMWdfnC/fYQhpxR9ANHY/c/KnleJRT6TVNfphe6lw9 fJici6B4vvJABnZaMS1MFyGaGg4BlhJcT34l2rrxcGCDihA3M2/IelAdMjGMoNGILjXF 48l2rxBCcjs3k9WH01PfL76fjHGVUOc9s53AfoxFFLM9OII0ta8lJe500zZHK+hROk1v C8n0iIMq5zQuNUK8u14CCw1aC+x2V2P297FN5acK00pjETmiZkvpDl82BI/pwsC+lzfT tefg== X-Gm-Message-State: AOJu0Yzzb1AkR0U4HyfAFebJfmNWOvU6eSVg1f1+ucMNJc8DpSKRPCqE Fetk3PDU8cFlis9sKAsGYD7LLrLgacuZoL9Sk2c1ACAjFS9kyOXp4mljKQaVzcThlAofH3WbpYk L X-Gm-Gg: ASbGncsjUBEcCgHWNykAr46pkVYihymmuZbn0RTRQ183BDwQAW9BTxDHK1q2q3kuey8 5kJPOu87wJgF6zcaZNyC3LMq947nElLVhJaX8roULJ3YftgjnQgMLzyIIm9wVXwnW9RsiAZ3mOh zs4+9EmnlzhWFSVcO5ITEmeSHNMPs8u5y6jV3rBZllqkcw3vSVbzsMpccyvv7uYFNJcNX2OM5KS xzk7PZcafzdtvQvl8GgjSysMOIPMBbdFuKepbaqemTXqjtWDdjzjjdrZZwAgUxrILLIarNSFocX nEakoQLtNwTWpRiK/XhXcc5VUQMfUJVshCVEKFQ5/al+xg== X-Google-Smtp-Source: AGHT+IFy3ozUxsGi2jitSr9ubKsaPbVL8wW6yqXgzNmoNPsoSYOYTdbpTX/VTHQ8XuEd/keRVE0rUQ== X-Received: by 2002:a05:600c:5010:b0:43d:526:e0ce with SMTP id 5b1f17b1804b1-441d100b3c5mr16425255e9.21.1746520490691; Tue, 06 May 2025 01:34:50 -0700 (PDT) From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Jan Beulich , Andrew Cooper Subject: [PATCH 6/9] x86/p2m: limit cache flush in memory_type_changed() Date: Tue, 6 May 2025 10:31:45 +0200 Message-ID: <20250506083148.34963-7-roger.pau@citrix.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250506083148.34963-1-roger.pau@citrix.com> References: <20250506083148.34963-1-roger.pau@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1746520523100116600 Only do the cache flush when there's a p2m type change to propagate, otherwise there's no change in the p2m effective caching attributes. If the p2m memory_type_changed hook is not set p2m_memory_type_changed() is a no-op, no recalculation of caching attributes is needed, nor flushing of the previous cache contents. Signed-off-by: Roger Pau Monn=C3=A9 Reviewed-by: Jan Beulich --- xen/arch/x86/hvm/mtrr.c | 3 +-- xen/arch/x86/include/asm/p2m.h | 2 +- xen/arch/x86/mm/p2m.c | 13 ++++++++++++- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/xen/arch/x86/hvm/mtrr.c b/xen/arch/x86/hvm/mtrr.c index b88e81eb44b1..e7acfb6e8dc4 100644 --- a/xen/arch/x86/hvm/mtrr.c +++ b/xen/arch/x86/hvm/mtrr.c @@ -767,9 +767,8 @@ HVM_REGISTER_SAVE_RESTORE(MTRR, hvm_save_mtrr_msr, NULL= , hvm_load_mtrr_msr, 1, void memory_type_changed(struct domain *d) { if ( (is_iommu_enabled(d) || cache_flush_permitted(d)) && - d->vcpu && d->vcpu[0] ) + d->vcpu && d->vcpu[0] && p2m_memory_type_changed(d) ) { - p2m_memory_type_changed(d); flush_all(FLUSH_CACHE); } } diff --git a/xen/arch/x86/include/asm/p2m.h b/xen/arch/x86/include/asm/p2m.h index b9ce7d8705ba..4358cc15a2a1 100644 --- a/xen/arch/x86/include/asm/p2m.h +++ b/xen/arch/x86/include/asm/p2m.h @@ -700,7 +700,7 @@ void p2m_pod_dump_data(struct domain *d); #ifdef CONFIG_HVM =20 /* Report a change affecting memory types. */ -void p2m_memory_type_changed(struct domain *d); +bool p2m_memory_type_changed(struct domain *d); =20 /* Called by p2m code when demand-populating a PoD page */ bool diff --git a/xen/arch/x86/mm/p2m.c b/xen/arch/x86/mm/p2m.c index 3a39b5d1246b..b9a7c2dc5302 100644 --- a/xen/arch/x86/mm/p2m.c +++ b/xen/arch/x86/mm/p2m.c @@ -126,12 +126,21 @@ static void _memory_type_changed(struct p2m_domain *p= 2m) { if ( p2m->memory_type_changed ) p2m->memory_type_changed(p2m); + else + ASSERT_UNREACHABLE(); } =20 -void p2m_memory_type_changed(struct domain *d) +bool p2m_memory_type_changed(struct domain *d) { struct p2m_domain *hostp2m =3D p2m_get_hostp2m(d); =20 + /* + * The p2m memory_type_changed hook will be the same for the host p2m = or + * the altp2ms, do the check early and return if not set. + */ + if ( !hostp2m->memory_type_changed ) + return false; + p2m_lock(hostp2m); =20 _memory_type_changed(hostp2m); @@ -154,6 +163,8 @@ void p2m_memory_type_changed(struct domain *d) } =20 p2m_unlock(hostp2m); + + return true; } =20 int p2m_set_ioreq_server(struct domain *d, --=20 2.48.1