From nobody Thu Oct 30 22:56:26 2025 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=1755187482; cv=none; d=zohomail.com; s=zohoarc; b=TZ3+JOfBpQCR6W7VeKidbBoVNO540zN7EDHHnCtOdm9ZgknM0Y3fPHBKXoJlCe/5Gstb2Hgw0wDWra1/ifCxU+TpU4NxLMGa4pLU4s8PCxrCUaSPG302fz7RZULzUWTajkjJL+Zp52HnBHoyfuIvghm1KiTcvNVSXsdjB2Xem70= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1755187482; 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=q/aE4/XzPV59CJPrm3Gg+uv4SbRmBDmotMngXyRqJUQ=; b=cCxzCV3YCRSt858Pzk7uPsU/IvMd1MpTtbN+rGU3N8J4QL4tYdgvjm2C2rxHnCRIyYOytg0CpBmU5EyZK7lbbkhLYibDUOLFLhwnlifK4RY1esj+FUC67JoUQpZ0+KEqwbMn39WWIzg5cFK4OOrvWd8eyo6F4tH3sKmv7hnMBpQ= 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 1755187482032456.58123346293326; Thu, 14 Aug 2025 09:04:42 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1081984.1441987 (Exim 4.92) (envelope-from ) id 1umaRD-0002Dm-3m; Thu, 14 Aug 2025 16:04:23 +0000 Received: by outflank-mailman (output) from mailman id 1081984.1441987; Thu, 14 Aug 2025 16:04:23 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1umaRC-0002DZ-Uy; Thu, 14 Aug 2025 16:04:22 +0000 Received: by outflank-mailman (input) for mailman id 1081984; Thu, 14 Aug 2025 16:04:22 +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 1umaRC-0000md-BL for xen-devel@lists.xenproject.org; Thu, 14 Aug 2025 16:04:22 +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 5741821a-7928-11f0-a328-13f23c93f187; Thu, 14 Aug 2025 18:04:22 +0200 (CEST) Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-45a1b0990b2so7380825e9.2 for ; Thu, 14 Aug 2025 09:04:22 -0700 (PDT) Received: from localhost (112.pool92-178-7.dynamic.orange.es. [92.178.7.112]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-45a1c6bc93fsm26178975e9.2.2025.08.14.09.04.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Aug 2025 09:04:05 -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: 5741821a-7928-11f0-a328-13f23c93f187 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1755187461; x=1755792261; 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=q/aE4/XzPV59CJPrm3Gg+uv4SbRmBDmotMngXyRqJUQ=; b=E7+134YxY9FOURXY/MR9yTGDiYdJrEEt/Nqnx04HlTmbE6U+8uXXBS52kvgXWuJbGx Hx+55Y7FYtUFq9j4Sf4xoM8XM8HbrwmhJOkxjtcncVY5HU96W603zaBQW93nhWuR4+ny pBwNVKdlGIWuqLEs5nYGR6YOk7dCpTQZSFfZE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755187461; x=1755792261; 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=q/aE4/XzPV59CJPrm3Gg+uv4SbRmBDmotMngXyRqJUQ=; b=CG5FNWvYBpgicw6htT2c1PeFBTlBUF2KS8ch9UzppJq/s7fJ63dfflfebEeIk7aATh Bipq+LTFhYEaOmz7GDXWol/gTqC//ccfo019rRTzsoao8B120VZMWhMX/rHF1cHG3HPH 3hBTpqPjgwGGe5aTeSUtDjLqcNvyeFXv3hkSD7dS+YLRgUa3dtFhejnT/AIaDRL/nWFA chANtyPSTVO6hY24zrBVk2rjieEJVCJc2Es02xSF3fZjJxfyRHaAggMIyhn3KXkB1o9b 6Ev9jCI8Cj5qazuZi6qG3LI6xRVp47vED/6HobED1OpzyBpKFaPgrDijgnjaAILoIhQn tb0w== X-Gm-Message-State: AOJu0YzgMxfOAY06hvWnFvR48skBKCKEpnp9KISkdEOX+mKPzHILsB2x 7702WbJpkgWWd87UMlPfD8L+mMRdflmgioLHsQYAGwUM/l+2HUiYakdpFeZ4jNym8cWdiU6oDWl OEsrU X-Gm-Gg: ASbGncsu9e/WRixiw3b0gwqMOwLDE/Jt24HYrtyvcpJdCqPLVv9ebOPaY15OYXb/rSf Bc+lpQGgZ20ovmBA8J6Im5wQ8BwS0j+G9eEGlIG+iNl0j7JjFJ4fUz72EeWCAyVCrSYzVTR4lhA j7V/IFXTvHE+QLvNhe67YXWw5ys5lRpJ06APtnKpIfvI4GQb3ZG5LF0O+TIuOsM9qMpUoZ5snAY 83qCh4SlypR/pRwyeJW/5+Xno0F5pJ9HaEg4CkhJcDj1ka3RkbwDr0BjkOi5N6ZE/gN1+q8s3VM cyJC+2yazDKQ2lHbZhd4S1CkTUnwS8CtC5p6v3BflNggPyEAWxAksAmB80tjd8ZclC/y1QSVR8d PtDIClP4FDfQGTNAfDPKMyxwOYLBXx+aRUOFbRjASmuXKtKes2wdV2JdAJcOwZTEKWw== X-Google-Smtp-Source: AGHT+IHmbaGVo5yru/zbIYz4g1CR9qPgenXRGr/YGkkrLd01NhwlOqiZstHfexkqrTx+XqeNe3W9Pg== X-Received: by 2002:a05:600c:b90:b0:458:bda4:43df with SMTP id 5b1f17b1804b1-45a1b646db2mr37167305e9.17.1755187445701; Thu, 14 Aug 2025 09:04:05 -0700 (PDT) From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: stewart.hildebrand@amd.com, Jiqian.Chen@amd.com, jbeulich@suse.com, Roger Pau Monne Subject: [PATCH 1/5] xen/vpci: purge BAR rangeset contents before use Date: Thu, 14 Aug 2025 18:03:54 +0200 Message-ID: <20250814160358.95543-2-roger.pau@citrix.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250814160358.95543-1-roger.pau@citrix.com> References: <20250814160358.95543-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: 1755187482964124100 It's possible for the BAR rangeset to contain stale data when used in modify_bars() if previous calls to modify_bars() resulted in errors. Fix by always purging the rangeset before usage, thus getting rid of any previous stale data. Remove the ASSERT that checked whether the rangeset was empty, it was incorrect. Fixes: 52ebde3cfae2 ('vpci/header: program p2m with guest BAR view') Signed-off-by: Roger Pau Monn=C3=A9 Reviewed-by: Stewart Hildebrand --- xen/drivers/vpci/header.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/xen/drivers/vpci/header.c b/xen/drivers/vpci/header.c index 469f4977441a..b9756b364300 100644 --- a/xen/drivers/vpci/header.c +++ b/xen/drivers/vpci/header.c @@ -338,6 +338,12 @@ static int modify_bars(const struct pci_dev *pdev, uin= t16_t cmd, bool rom_only) if ( !bar->mem ) continue; =20 + /* + * Empty before use, previous failures might have left stale data = in + * the rangeset. + */ + rangeset_purge(bar->mem); + if ( !MAPPABLE_BAR(bar) || (rom_only ? bar->type !=3D VPCI_BAR_ROM : (bar->type =3D=3D VPCI_BAR_ROM && !header->rom_en= abled)) || @@ -353,8 +359,6 @@ static int modify_bars(const struct pci_dev *pdev, uint= 16_t cmd, bool rom_only) continue; } =20 - ASSERT(rangeset_is_empty(bar->mem)); - /* * Make sure that the guest set address has the same page offset * as the physical address on the host or otherwise things won't w= ork as --=20 2.49.0 From nobody Thu Oct 30 22:56:26 2025 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=1755187468; cv=none; d=zohomail.com; s=zohoarc; b=VlmBbgdERHin6MK7JPlhPgzWARQxrKkGIJcR6nY7fONM2aqIhhy5vwRtyZf9k6T2LcfYd7tHJ5GxeUIkS6mMAJwPCPTyLdqZkQ6bpVBuAwuY1vlCE/MePV14bZ45uXlsiZaTyRdeWsup3p5pr49jsloTZ01foXukYzI9qWTUNNc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1755187468; 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=L6B37Ba3gyt57gIs6nirOWojNHZXWUq/F0/HSDXW+MY=; b=LXDkoUbZ/i05sjHa/Uz9jM0L/xISJnRcOw7pBJFtQkW+shVmbyPR0JRzW0aLPYvp197mfDcPwiaRqtm/mFYid0hg29otXOb7nZOixDi/ykcQIplBPiqebIx3OQslvMbneHXMCP2pZIwM6MeP71TiPYbaRGCReahJ6IjeJc1CimY= 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 1755187468049979.4527843322209; Thu, 14 Aug 2025 09:04:28 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1081977.1441947 (Exim 4.92) (envelope-from ) id 1umaR0-000117-Sh; Thu, 14 Aug 2025 16:04:10 +0000 Received: by outflank-mailman (output) from mailman id 1081977.1441947; Thu, 14 Aug 2025 16:04:10 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1umaR0-000110-Om; Thu, 14 Aug 2025 16:04:10 +0000 Received: by outflank-mailman (input) for mailman id 1081977; Thu, 14 Aug 2025 16:04:09 +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 1umaQz-0000md-FD for xen-devel@lists.xenproject.org; Thu, 14 Aug 2025 16:04:09 +0000 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [2a00:1450:4864:20::32a]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 4f937e03-7928-11f0-a328-13f23c93f187; Thu, 14 Aug 2025 18:04:09 +0200 (CEST) Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-45a1b0c52f3so5799915e9.3 for ; Thu, 14 Aug 2025 09:04:09 -0700 (PDT) Received: from localhost (112.pool92-178-7.dynamic.orange.es. [92.178.7.112]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-45a1c749143sm28269975e9.16.2025.08.14.09.04.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Aug 2025 09:04:07 -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: 4f937e03-7928-11f0-a328-13f23c93f187 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1755187448; x=1755792248; 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=L6B37Ba3gyt57gIs6nirOWojNHZXWUq/F0/HSDXW+MY=; b=gGQr3+xD/BTbo1c6cIZ8tBypqbIr4swDpXQTM0uT8zFx4YUer290zi5exTUHCmc8j8 Poxm9A5lDiVe9/POBY3rbfcOdyjKK01bygZtHVVYWlZanWmOmvT13kYYgoHlFsWeLVNV T8rh9opjXdfdvqkC2iJrAXSLS5D1sWK76WNgE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755187448; x=1755792248; 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=L6B37Ba3gyt57gIs6nirOWojNHZXWUq/F0/HSDXW+MY=; b=M3Uu3NOG24NsmBsLNnlpX9m35OBhk44Qnq4AHdUiKmIIt7JmyhxqFe12RkziP2Khif QI4PRjWh0eRtJcqBHzsZPvDi1GbMpM407kp3pT+WO5OFP3T4Ga0UcApKDpO9o7hC8Xcz GamgIDgEeWgBXqUbSvgFsPBXjVXWZ4bgUgLGAJcpDhrap++whJNT3IRtdH82qVkKWyp3 7rxc8w6LHKJ/CX9RT3bf0Rz9h4SpJh0vUhYoaI6PbYgUFNioPyGPVcwoKDF4N2IxUqWk nGrDSMcqaI8EAMJU5HPDJKcMaPuZzWLOaoNKa6ogkdONeycpekWky8UrltVhJnV9BkHO YMfA== X-Gm-Message-State: AOJu0YyN8Dz/BIiuvHsbEBMpZgSGLVXt6DBYzBVPoVDlMb3Uz6Y8RXfy jtR8JR0vU3xtlPJ/I4yO+opMkGS0+hkZqJEgIlOKiNDi2egunPAyvAWp3E5IwuDlxWq1GNX1auR 8aLJf X-Gm-Gg: ASbGnctpvRASPjfFbyijsY2tmUZ/ZhmDis1av/ZP7j/eCfTorLaE/G2hEcbnXtqrFdb eVcrLm+gDIQIZPSsZrLApV/MY6gi1ZC7hdzj6xbvRbnKlb98xr+PrPjdAs1ylak4n7KRSbbgWKl 6mm/jzJsdbt1m4Ltcn8EnYzvSMsc5qfL5pWD2o1wz+oms9Ej849LOetQO4R73Ra2014zLk7WrFz igMylqxeVQEwDF84q/sjcbo1pjUbf7arFqqOH5McM1gMONJdY/HgH8NpcOssRHDVdMlB0t2SpOz Hz9F40FPDLbL6mRghyqSBSbtgnRNfRmke1w80SF+bmaZcXN78JgQsQrTS2xWv4hSOLmJxOAnPP2 dU22rhzFKkHw/bWwApiKeGtJzG07leFKHsyX80vr17H3bhoFagO3kh7ye/NcXTic79w== X-Google-Smtp-Source: AGHT+IHz1EWE4bvPiHqh//WTyRN3eUMg7wkQwNpRCuR6tA5I9ANzFfbUOhz3S4ExD0/q0mmBuNpGvQ== X-Received: by 2002:a05:600c:3b87:b0:459:d709:e5cf with SMTP id 5b1f17b1804b1-45a1b602b85mr34984975e9.3.1755187448072; Thu, 14 Aug 2025 09:04:08 -0700 (PDT) From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: stewart.hildebrand@amd.com, Jiqian.Chen@amd.com, jbeulich@suse.com, Roger Pau Monne Subject: [PATCH 2/5] xen/vpci: make BAR mapping more resilient for the hardware domain Date: Thu, 14 Aug 2025 18:03:55 +0200 Message-ID: <20250814160358.95543-3-roger.pau@citrix.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250814160358.95543-1-roger.pau@citrix.com> References: <20250814160358.95543-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: 1755187470858124100 The logic in map_range() will bubble up failures to the upper layer, which will result in any remaining regions being skip, and for the non-hardware domain case the owner domain of the device would be destroyed. However for the hardware domain the intent is to continue execution, hopping the failure to modify the p2m could be worked around by the hardware domain. To accomplish that in a better way, ignore failures and skip the range in that case, possibly continuing to map further ranges. Since the error path in vpci_process_pending() should only be used by domUs now, and it will unconditionally end up calling domain_crash(), simplify it: there's no need to cleanup if the domain will be destroyed. No functional change for domUs intended. Signed-off-by: Roger Pau Monn=C3=A9 --- xen/drivers/vpci/header.c | 51 +++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/xen/drivers/vpci/header.c b/xen/drivers/vpci/header.c index b9756b364300..1035dcca242d 100644 --- a/xen/drivers/vpci/header.c +++ b/xen/drivers/vpci/header.c @@ -64,7 +64,8 @@ static int cf_check map_range( printk(XENLOG_G_WARNING "%pd denied access to MMIO range [%#lx, %#lx]\n", map->d, map_mfn, m_end); - return -EPERM; + rc =3D -EPERM; + goto done; } =20 rc =3D xsm_iomem_mapping(XSM_HOOK, map->d, map_mfn, m_end, map->ma= p); @@ -73,7 +74,7 @@ static int cf_check map_range( printk(XENLOG_G_WARNING "%pd XSM denied access to MMIO range [%#lx, %#lx]: %d\n= ", map->d, map_mfn, m_end, rc); - return rc; + goto done; } =20 /* @@ -87,17 +88,27 @@ static int cf_check map_range( =20 rc =3D map->map ? map_mmio_regions(map->d, _gfn(s), size, _mfn(map= _mfn)) : unmap_mmio_regions(map->d, _gfn(s), size, _mfn(map= _mfn)); - if ( rc =3D=3D 0 ) - { - *c +=3D size; - break; - } if ( rc < 0 ) { printk(XENLOG_G_WARNING "Failed to %smap [%lx %lx] -> [%lx %lx] for %pd: %d\n", map->map ? "" : "un", s, e, map_mfn, map_mfn + size, map->d, rc); + goto done; + } + if ( rc =3D=3D 0 ) + { + done: + if ( is_hardware_domain(map->d) ) + { + /* + * Ignore failures for the hardware domain and skip the ra= nge. + * Do it as a best effort workaround to attempt to get the + * hardware domain to boot. + */ + rc =3D 0; + *c +=3D size; + } break; } ASSERT(rc < size); @@ -213,28 +224,22 @@ bool vpci_process_pending(struct vcpu *v) return true; } =20 - if ( rc ) + if ( rc && !is_hardware_domain(v->domain) ) { - spin_lock(&pdev->vpci->lock); - /* Disable memory decoding unconditionally on failure. */ - modify_decoding(pdev, v->vpci.cmd & ~PCI_COMMAND_MEMORY, - false); - spin_unlock(&pdev->vpci->lock); - - /* Clean all the rangesets */ - for ( i =3D 0; i < ARRAY_SIZE(header->bars); i++ ) - if ( !rangeset_is_empty(header->bars[i].mem) ) - rangeset_purge(header->bars[i].mem); - - v->vpci.pdev =3D NULL; - read_unlock(&v->domain->pci_lock); =20 - if ( !is_hardware_domain(v->domain) ) - domain_crash(v->domain); + domain_crash(v->domain); =20 return false; } + ASSERT(!rc); + /* + * Purge rangeset to deal with the hardware domain having triggere= d an + * error. It shouldn't be possible, as map_range() will always sh= allow + * errors for hardware domain owned devices, and + * rangeset_consume_ranges() itself doesn't generate any errors. + */ + rangeset_purge(bar->mem); } v->vpci.pdev =3D NULL; =20 --=20 2.49.0 From nobody Thu Oct 30 22:56:26 2025 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=1755187468; cv=none; d=zohomail.com; s=zohoarc; b=Uqwo8CZgQnXC5I7BkPXZ02mqdKT0WWRY0qnRX42RQ64hZeBHfbZAXUFTZa+joaoAF2YhC6Tra5p26zsu/pt2I1sp3wnzZofwoSrU1GM3vxvEqTf9B2gj2vl2m0ZSkmXqro5O1HdIn0QxzCwqZbFNdh4d2AsgsBpUSeF8JBAxRTU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1755187468; 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=VIvTZ7pv/C0sfHkl6ro//lBTy9KaJCip4Yzq1BFnW40=; b=RV2TqHrlf9F1nC3/oKRYNTETsSCJIEaDMWWXQdSAnJIFkK12moQvVnBYC86VPibP3Yxf3XYHsWVladUUU6nvXvM2/DP30ZIoI3F5A1tpULJ6M2jS+sqiySnoMUgPEegW/ynI6GjwAnNZHXayaLX+q33uJ5d6sKgJKzROGrI3WM8= 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 1755187468682256.66406410723255; Thu, 14 Aug 2025 09:04:28 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1081978.1441956 (Exim 4.92) (envelope-from ) id 1umaR4-0001H3-1x; Thu, 14 Aug 2025 16:04:14 +0000 Received: by outflank-mailman (output) from mailman id 1081978.1441956; Thu, 14 Aug 2025 16:04:14 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1umaR3-0001Gw-V4; Thu, 14 Aug 2025 16:04:13 +0000 Received: by outflank-mailman (input) for mailman id 1081978; Thu, 14 Aug 2025 16:04:12 +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 1umaR2-0001FY-Io for xen-devel@lists.xenproject.org; Thu, 14 Aug 2025 16:04:12 +0000 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [2a00:1450:4864:20::430]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 505238ff-7928-11f0-b898-0df219b8e170; Thu, 14 Aug 2025 18:04:10 +0200 (CEST) Received: by mail-wr1-x430.google.com with SMTP id ffacd0b85a97d-3b9e418ba08so556601f8f.3 for ; Thu, 14 Aug 2025 09:04:10 -0700 (PDT) Received: from localhost (112.pool92-178-7.dynamic.orange.es. [92.178.7.112]) by smtp.gmail.com with UTF8SMTPSA id ffacd0b85a97d-3b79c3ac036sm51020430f8f.15.2025.08.14.09.04.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Aug 2025 09:04:08 -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: 505238ff-7928-11f0-b898-0df219b8e170 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1755187449; x=1755792249; 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=VIvTZ7pv/C0sfHkl6ro//lBTy9KaJCip4Yzq1BFnW40=; b=QYkOREoGD2BIXPWwmg3BqMgw9Orc+khwwDCiIa4d2fJwD5HOCaurqcABl42+FNYGb+ MlmAeBt8uQcJGwxD8B2eDr9WIO26kHn8gd7uOqKG1KNrEHO/eXDDHpq+W2YOdTK8TPjZ Wn5on3PcJ0s8H+wmiR2+K9Rmg8cEvfmbM5ALY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755187449; x=1755792249; 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=VIvTZ7pv/C0sfHkl6ro//lBTy9KaJCip4Yzq1BFnW40=; b=he8OwmHGWWiAgrxjvJnUDdB7+NSmoCNZCqSf9Et6vHOaY8tq+Boo7lL8DpZtV7Qg3G qUosDNSNwP+Ms2ymtpBfetbORcLrdkbe3xw1kqLTHAcSQ4VoUYPePCkXwi1IRBTKViS8 XrB95r04pqpfqHUfZjDZ0hAZukos/KkBimRvw5YzeLzmCyFN+6meDug+8iH/Uhyw/kQ8 BL1OfuVkLk4SWaggHIYsEYdCDKflc/ejLKM9CxxT8yJIFTseVOwWhj4kH9IPDgj3JrQ6 /+lx0VlWgMfmnI33QXbqSxS3UNDCe/PkTxDF58xw1CinDatRL6ZlfWQwdd7hsn/e+xgF FIPg== X-Gm-Message-State: AOJu0Yy5Rm+3Xk8b71SljdaKAJHauUWgkI9riyyGTxATpn4RJGEAzZGq 2PN7ZX9SK5mPM7CB2owBrebuKa2v0BA/c6MQD5PY10yEpaUrbVKNQ6/9GNDRsMkhcSV0s0Zxauw zNTH0 X-Gm-Gg: ASbGncu86q6NfoiCyZAz3jwx4VFygHxbry9VD/nyaN15AjDbu5viSIgvlKbkHL/qbQa 15a5wkAu/JyRN7mwPn5ca/r9jRgskkCXnzEAUfZC9ZuJWq+AZk5Xjz1M7R3jSU4waFqvXEpuTy2 WgpBUx4xOamwBMwD7+zRetx9VcDzo0g2+6ScwlxCcJREJdImRwnabj4jWlrz2TUmJ3c6NM6k8ax 7Q4UVAXsMr2kDYvgRF8DbO2d8WCWAmlaZpFkwTCg0r5dAmna0TfIU1mRSoOkFHD0ZNoHSXrAh1+ I5jHxLzE/Nnpx14oNAx/BWiieJeepbs1QF2flScMy3PgAH+d9QQThKgeBzNIdavGzbEoFZHSFam kv4LKVMXXCyYS8+cbS63uzFyP6Xl55ODNdLaxIkHtqFG1039fGdkxwZSknhuqeOauYg== X-Google-Smtp-Source: AGHT+IFMWd1gDHrhhDVDn1MANjFzIFBwYOifVOB7VqWG1FjR3VFzCt61QxOnUOTU4XGSLCkGCzdCYg== X-Received: by 2002:a05:6000:40ce:b0:3b8:f318:dc61 with SMTP id ffacd0b85a97d-3b9edfbc760mr3354469f8f.40.1755187449317; Thu, 14 Aug 2025 09:04:09 -0700 (PDT) From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: stewart.hildebrand@amd.com, Jiqian.Chen@amd.com, jbeulich@suse.com, Roger Pau Monne Subject: [PATCH 3/5] xen/vpci: simplify handling of memory decoding and ROM enable writes Date: Thu, 14 Aug 2025 18:03:56 +0200 Message-ID: <20250814160358.95543-4-roger.pau@citrix.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250814160358.95543-1-roger.pau@citrix.com> References: <20250814160358.95543-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: 1755187470926124100 Deferring the actual write of the PCI register bit, either the memory decoding or the ROM enable is not helpful, and adds an unnecessary amount of complexity to the preemptible handling of BAR related p2m modifications. In the hardware domain case, whether the PCI register write is done ahead or after the p2m changes doesn't matter, a hardware domain has plenty of ways to mess with the PCI register state if it wants to. Any poking at the BAR p2m regions ahead of the guest write having completed will be undefined. On the other hand, for domUs the memory decoding bit shouldn't really change as a result of guest actions, and should always be enabled. Guest toggling the memory decoding command register should only result in p2m modifications, but no propagation to the device PCI registers. Having memory decoding unconditionally enabled ensures the domU attempting to perform p2m accesses while the p2m changes are taking place will always access the BAR contents. This is not the current behavior for domUs, so add a note that it would preferably done that way. Signed-off-by: Roger Pau Monn=C3=A9 --- xen/drivers/vpci/header.c | 42 +++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/xen/drivers/vpci/header.c b/xen/drivers/vpci/header.c index 1035dcca242d..1a501a0ba47e 100644 --- a/xen/drivers/vpci/header.c +++ b/xen/drivers/vpci/header.c @@ -163,8 +163,6 @@ static void modify_decoding(const struct pci_dev *pdev,= uint16_t cmd, if ( pci_check_bar(pdev, _mfn(PFN_DOWN(bar->addr)), _mfn(PFN_DOWN(bar->addr + bar->size - 1))) ) bar->enabled =3D map; - header->rom_enabled =3D map; - pci_conf_write32(pdev->sbdf, rom_pos, val); return; } =20 @@ -174,14 +172,6 @@ static void modify_decoding(const struct pci_dev *pdev= , uint16_t cmd, _mfn(PFN_DOWN(bar->addr + bar->size - 1))) ) bar->enabled =3D map; } - - if ( !rom_only ) - { - pci_conf_write16(pdev->sbdf, PCI_COMMAND, cmd); - header->bars_mapped =3D map; - } - else - ASSERT_UNREACHABLE(); } =20 bool vpci_process_pending(struct vcpu *v) @@ -547,16 +537,23 @@ static void cf_check cmd_write( * decoding one. Bits that are not allowed for DomU are already * handled above and by the rsvdp_mask. */ - if ( header->bars_mapped !=3D !!(cmd & PCI_COMMAND_MEMORY) ) + if ( header->bars_mapped !=3D !!(cmd & PCI_COMMAND_MEMORY) && + modify_bars(pdev, cmd, false) ) /* * Ignore the error. No memory has been added or removed from the = p2m * (because the actual p2m changes are deferred in defer_map) and = the * memory decoding bit has not been changed, so leave everything a= s-is, * hoping the guest will realize and try again. */ - modify_bars(pdev, cmd, false); - else - pci_conf_write16(pdev->sbdf, reg, cmd); + return; + + /* + * FIXME: for domUs we don't want the guest toggling the memory decodi= ng + * bit. It should be set in vpci_init_header() and guest attempts to + * modify it should only lead to guest p2m changes. + */ + header->bars_mapped =3D cmd & PCI_COMMAND_MEMORY; + pci_conf_write16(pdev->sbdf, reg, cmd); } =20 static uint32_t cf_check guest_cmd_read( @@ -712,17 +709,11 @@ static void cf_check rom_write( rom->guest_addr =3D rom->addr; } =20 - if ( !header->bars_mapped || rom->enabled =3D=3D new_enabled ) - { - /* Just update the ROM BAR field. */ - header->rom_enabled =3D new_enabled; - pci_conf_write32(pdev->sbdf, reg, val); - } /* * Pass PCI_COMMAND_MEMORY or 0 to signal a map/unmap request, note th= at * this fabricated command is never going to be written to the registe= r. */ - else if ( modify_bars(pdev, new_enabled ? PCI_COMMAND_MEMORY : 0, true= ) ) + if ( modify_bars(pdev, new_enabled ? PCI_COMMAND_MEMORY : 0, true) ) /* * No memory has been added or removed from the p2m (because the a= ctual * p2m changes are deferred in defer_map) and the ROM enable bit h= as @@ -733,6 +724,8 @@ static void cf_check rom_write( */ return; =20 + header->rom_enabled =3D new_enabled; + pci_conf_write32(pdev->sbdf, reg, val); if ( !new_enabled ) { rom->addr =3D val & PCI_ROM_ADDRESS_MASK; @@ -1057,6 +1050,13 @@ int vpci_init_header(struct pci_dev *pdev) goto fail; } =20 + if ( cmd & PCI_COMMAND_MEMORY ) + { + /* Restore command register value. */ + header->bars_mapped =3D true; + pci_conf_write16(pdev->sbdf, PCI_COMMAND, cmd); + } + return (cmd & PCI_COMMAND_MEMORY) ? modify_bars(pdev, cmd, false) : 0; =20 fail: --=20 2.49.0 From nobody Thu Oct 30 22:56:26 2025 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=1755187470; cv=none; d=zohomail.com; s=zohoarc; b=iGzeLbupp7WIOKd7aCzti5y8pgJROC+nggi8mnfZ5y54+PEg1YYu7wFr4mwBOYEh1/ff6M/ZSFdcp/32FuWqF8HJNyhlcfvGJc6OLmDzmRUhwt51NRAXnEWTKKDHdoIrVBM+Zd+IG3YFEL+t6781oQYyyCHKZ10zW8yhzNbprkY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1755187470; 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=xBj5NRvP8XG/dMSSpUAh9hQU/qoLTjxS6PC2X80rtxs=; b=SrPUZhne41Yzzq5fRyK/Brk1+9uU5yk/jEk194LUZzOAsBwLcMjL4wdV4dWsxx/DXiWt/1jAgv24ZTBxpO2R3sR53M6H2SMTq9KK+E56eL2AMquIQ8EPNluxPUWynNHxrnXRP5tE/4txeS5XG6cLZoHC4GzS2iqXlGMYJ/k4vIc= 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 175518747018168.3824368421956; Thu, 14 Aug 2025 09:04:30 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1081980.1441972 (Exim 4.92) (envelope-from ) id 1umaR5-0001ZR-LL; Thu, 14 Aug 2025 16:04:15 +0000 Received: by outflank-mailman (output) from mailman id 1081980.1441972; Thu, 14 Aug 2025 16:04:15 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1umaR5-0001Y1-ET; Thu, 14 Aug 2025 16:04:15 +0000 Received: by outflank-mailman (input) for mailman id 1081980; Thu, 14 Aug 2025 16:04:13 +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 1umaR3-0001FY-LH for xen-devel@lists.xenproject.org; Thu, 14 Aug 2025 16:04:13 +0000 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [2a00:1450:4864:20::329]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 515d4357-7928-11f0-b898-0df219b8e170; Thu, 14 Aug 2025 18:04:12 +0200 (CEST) Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-45a1b001f55so5404695e9.0 for ; Thu, 14 Aug 2025 09:04:12 -0700 (PDT) Received: from localhost (112.pool92-178-7.dynamic.orange.es. [92.178.7.112]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-45a1c6fa00bsm26313545e9.19.2025.08.14.09.04.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Aug 2025 09:04:10 -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: 515d4357-7928-11f0-b898-0df219b8e170 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1755187451; x=1755792251; 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=xBj5NRvP8XG/dMSSpUAh9hQU/qoLTjxS6PC2X80rtxs=; b=bmBSX/sE+9SEZvaH7CmeS9iuJvunCvQd0SPNUpgQ1Qx6n14vWpeJK2B0PAip3tARfQ 8DharXDrpBbQ2wtQzFORnQ2l4Uhd0qKpkIcpcbzFX0K3nJrnaQYhy8yY/tBdVsFmABcK 9Tay1OKiSVdPOsSlnklfA7cVMB8yLb8iDQzEM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755187451; x=1755792251; 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=xBj5NRvP8XG/dMSSpUAh9hQU/qoLTjxS6PC2X80rtxs=; b=WT3pwIHfXKvWgBOSvZit9CVu6NsmFcJew+k06/PFfnM1tDkZ/nnIEy1ZlrQQer8YRF RME/k79zNbQKdf2yJtBJYMj0vpvTIyj5N7jcWfXnLDbyptD/zU4Fc4PcAugD5JSCkOSn 13gCdiX6UouIyntwmBZ2Sj/H7CBspxeedVRsDq9SHHdYerTFUixx62+c3OHWXERbg0Bz Q5mbmNLVKQPgQe2HM13pVIIq7NG72XJB5vepLrNgTBTw9KuYwUpDOq4yDr0+qfjdRDyL +TQbT7KwwbnlHAJavASlV3V24rCceEzvgSlh3dGAThtETeOm4sl0bupnvtKGTgfo2mBE CDIw== X-Gm-Message-State: AOJu0YwY74H7VPAYpL5RCF0ajc0tnR0nGmnRoZSV04aNwEEiqP3ih0R4 WcIiDf06eeEeess0KBMtMoJGxXW3uUQjbhHRYXUmftjLdoeZQQqBOae/c0+f/D3cfR30rtROg02 nLtOc X-Gm-Gg: ASbGncvaxzrRDuhnwli3JR9uWQTMxmzVIuavdP6RlPFLkAkXE13d35yL6n0s31ExTGS Ul+CjKSMXPu+8ORUMeBgX4lx+ydAlFE2OgcafVlFnf8zJ45M0mLVtAvmHhXuzPtD+MBzpuVn47Q o1pA3+Lr5tSvLikMC8LC3+T1gy1WQz1+rU9o9sK0MIa72Af7FNDmIPOHtYtO9Z/Nyr8gANN466n 76d2PVKoL/5hgx8d8sEMTPVofXQwR8RJ2FJln4uDHmoty6XfLWhU8J2a1xSasDNOh51Ms1CYGcq bS+AFyNt7OSxktgUPDqz8a2uzWBArGGtOplxGlSgj/rRTsAqFqubAOzyA4wYovscLfpLNs9Swrw Oh9AxazHWkqCNagnffrK84pKOSQkNxNwMcWy6mcnj0P3fYNotfRe3IruLnLbuebzlTA== X-Google-Smtp-Source: AGHT+IH2hvKY7uV7i/yxnMKmS32Xi9zhMKkCRqCwn5ROjY05Dm67HZQHtqs4EAJOZ4JIHnvBuiwEgA== X-Received: by 2002:a05:600c:3b1a:b0:458:c059:7db1 with SMTP id 5b1f17b1804b1-45a1b668ac4mr39262205e9.30.1755187450635; Thu, 14 Aug 2025 09:04:10 -0700 (PDT) From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: stewart.hildebrand@amd.com, Jiqian.Chen@amd.com, jbeulich@suse.com, Roger Pau Monne Subject: [PATCH 4/5] vpci/msix: move MSI-X hole punching as a result of memory decoding enable Date: Thu, 14 Aug 2025 18:03:57 +0200 Message-ID: <20250814160358.95543-5-roger.pau@citrix.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250814160358.95543-1-roger.pau@citrix.com> References: <20250814160358.95543-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: 1755187470863124101 Deferring the p2m unpopulate of the MSI-X table region to after the BAR are mapped in the p2m is not needed. The aim of vpci_make_msix_hole() is to cope with the BAR containing the MSI-X table being positioned over a reserved e820 region, by making sure the MSI-X table region is unpopulated on the p2m. Note that reserved e820 regions are identity mapped in the hardware domain p2m by default. Doing it before or after the BAR p2m changes are done is irrelevant, hence do it ahead of the p2m changes, as that's simpler. Signed-off-by: Roger Pau Monn=C3=A9 Reviewed-by: Jan Beulich --- xen/drivers/vpci/header.c | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/xen/drivers/vpci/header.c b/xen/drivers/vpci/header.c index 1a501a0ba47e..255c6d54b406 100644 --- a/xen/drivers/vpci/header.c +++ b/xen/drivers/vpci/header.c @@ -133,19 +133,6 @@ static void modify_decoding(const struct pci_dev *pdev= , uint16_t cmd, bool map =3D cmd & PCI_COMMAND_MEMORY; unsigned int i; =20 - /* - * Make sure there are no mappings in the MSIX MMIO areas, so that acc= esses - * can be trapped (and emulated) by Xen when the memory decoding bit is - * enabled. - * - * FIXME: punching holes after the p2m has been set up might be racy f= or - * DomU usage, needs to be revisited. - */ -#ifdef CONFIG_HAS_PCI_MSI - if ( map && !rom_only && vpci_make_msix_hole(pdev) ) - return; -#endif - for ( i =3D 0; i < ARRAY_SIZE(header->bars); i++ ) { struct vpci_bar *bar =3D &header->bars[i]; @@ -547,6 +534,11 @@ static void cf_check cmd_write( */ return; =20 +#ifdef CONFIG_HAS_PCI_MSI + /* Unpopulate MSI-X table region, so accesses trap into Xen. */ + if ( (cmd & PCI_COMMAND_MEMORY) && vpci_make_msix_hole(pdev) ) + return; +#endif /* * FIXME: for domUs we don't want the guest toggling the memory decodi= ng * bit. It should be set in vpci_init_header() and guest attempts to --=20 2.49.0 From nobody Thu Oct 30 22:56:26 2025 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=1755187476; cv=none; d=zohomail.com; s=zohoarc; b=L/He0dMliHwhF1hflmlWFmNtdB3oNBx5nWo0g1LXYJSMdhjcBa+XWcdkdB4cSHLpvz1ejaPaC76Rj96u1dvN5Uk43wYJeawBq8xGzUhO5TSvbJyvjnkKKGs99c6tKxT+9h7SkrneWLWTQkk6Qq5FO/tNC/rZZl5X9ezsnL4px5M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1755187476; 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=psLG+a7CXrYEhoUcdPoZMaJ5jEU0fJdv182ycPW3oJY=; b=JKQzCqqGCPsm6gnyUyT1wrBpJRqP5B97ngigT7c7rO5cgAWjVA9OM8dq5CcznZ1JFUGZnQXmd3Pog3CtpT/BTMH4Dokm8Gs0nkJTbHqS889GtVc7XZmVuxQDYcLzvZuKhxd5Wjwx5gqqSH2GtbWFypkWkHaLWljcQzcgTy35TuI= 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 1755187476124749.019150094886; Thu, 14 Aug 2025 09:04:36 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1081979.1441967 (Exim 4.92) (envelope-from ) id 1umaR5-0001WM-9L; Thu, 14 Aug 2025 16:04:15 +0000 Received: by outflank-mailman (output) from mailman id 1081979.1441967; Thu, 14 Aug 2025 16:04:15 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1umaR5-0001WB-5y; Thu, 14 Aug 2025 16:04:15 +0000 Received: by outflank-mailman (input) for mailman id 1081979; Thu, 14 Aug 2025 16:04:13 +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 1umaR3-0000md-Fi for xen-devel@lists.xenproject.org; Thu, 14 Aug 2025 16:04:13 +0000 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [2a00:1450:4864:20::435]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 51fd66da-7928-11f0-a328-13f23c93f187; Thu, 14 Aug 2025 18:04:13 +0200 (CEST) Received: by mail-wr1-x435.google.com with SMTP id ffacd0b85a97d-3b9d41bfa35so907963f8f.0 for ; Thu, 14 Aug 2025 09:04:13 -0700 (PDT) Received: from localhost (112.pool92-178-7.dynamic.orange.es. [92.178.7.112]) by smtp.gmail.com with UTF8SMTPSA id ffacd0b85a97d-3b916394937sm7421304f8f.6.2025.08.14.09.04.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Aug 2025 09:04:11 -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: 51fd66da-7928-11f0-a328-13f23c93f187 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1755187452; x=1755792252; 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=psLG+a7CXrYEhoUcdPoZMaJ5jEU0fJdv182ycPW3oJY=; b=mtyHyx0pGttgZb8AMfiPdem3cuDCzz6+nZcR7NTF2vx5nDvZPVEburYcal6DWmbfKp kVsV6y0kcwGBK/O7i/FxhkYU3MYm7/YVm+7bNtLPzPN5mLCplG4sWGiRChbTkIdoogGQ s+aCA16jJmJamLSuAFU7h47/eGv3GZhQJCJ4A= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755187452; x=1755792252; 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=psLG+a7CXrYEhoUcdPoZMaJ5jEU0fJdv182ycPW3oJY=; b=nD0uwKJklUmFW8v6lShlcy8SROyXYySeQzj3aVE3jX1J5CsmCnTPY4Q+nNcXi1Gyad z9dE2d76Y+MUzF2wr91+9N0x+y9DjmLcQnvZs/KVg5kvn1ReyGMTxjIO/k37hibhmsS2 iA+t7p/+dFMglxYWVreMTZUf0VX0qz9mE7B9uzI1qRq9ArNS1ZUl7iz+8kH6EdaaWOx4 D78Wi9ugwnYXLEfl+u7lxydX9LI4dDwPy8yfMn94ndiW8yaJE/aOGXC7z2eopxEnYqew zcVOvWWiYcI2SI3JoJbygX3CT+Yu9ik7VRwR7josHbMlA2+4V/g9HGaLZybFAzjz4LU7 g4fg== X-Gm-Message-State: AOJu0YxMdlx7SM7mfnX2768r7nR8NmJCnHtreZz39V4Zd7t3g0GqyT+N b2ij7FW+aBUlhpyIKmf2RTbNFvyQz7kIyCE4AUoFB/Pc50BjoFOOJ2H9CaIFhiGHs7QCmXsnual 3rDqX X-Gm-Gg: ASbGncs8kTjDL+bC/FJjsTLbaLjgZq/5X6J7a8LzmmsQqORTslAQQN2DtL1e+YP4GoN PTh5o5fqlzx0z5Od0Ee7CMDupdQto3RIT95ThPwSC0rLkX8XIU9EDxx88ez+ruwcq+Fdrcmb4bB 2srTzGwfbqU/57SuzWxoay6lVlvnc+ITeBBc6fk9QCRZmGYaCS12a8vWsRqdwCQVSltPbBwFSkk c+iQIubSFkjC4ti3xh9oyGgyZEd7M/ApoBzYzOJLCsnSEows2ycIDnzenHZXvbB8bunr9aEEUbO hkBV11QuqGC8nuHucE3swfccYmcQsUcK4tpmyFtds2w15SGimFUlBCv3Q8JVQYlhSiBKyjTHiyO qD5F229q8DrHk7VnSsqXoWtnIAaUt5S1J6YZ7RgxOBrCoM/6Q9lOd5OxqT4IfiFWv2Q== X-Google-Smtp-Source: AGHT+IFVNy9qIZPfceRvaHctViLQahdoKWIo5FMIKzNqIfiwufvCPdS8zCJ/TffyRWtxQ+EoGQvZdQ== X-Received: by 2002:a5d:5f4a:0:b0:3b8:d493:31ed with SMTP id ffacd0b85a97d-3b9edf4454emr3440941f8f.47.1755187452069; Thu, 14 Aug 2025 09:04:12 -0700 (PDT) From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: stewart.hildebrand@amd.com, Jiqian.Chen@amd.com, jbeulich@suse.com, Roger Pau Monne , Andrew Cooper Subject: [PATCH 5/5] xen/vpci: only check BAR validity once Date: Thu, 14 Aug 2025 18:03:58 +0200 Message-ID: <20250814160358.95543-6-roger.pau@citrix.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250814160358.95543-1-roger.pau@citrix.com> References: <20250814160358.95543-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: 1755187477888116600 Avoid multiple calls to pci_check_bar() for the same memory decoding related operation, as each call can possibly print a warning message avoid a BAR being in an invalid position. Store whether the BAR is validly positioned in modify_bars(), and used that cached value for the whole operation. This allows to get rid of modify_decoding(), as the setting of whether the BAR is enabled or not can be easily done in vpci_process_pending() itself, without the need for an external helper. Reported-by: Andrew Cooper Fixes: 4acab25a9300 ('x86/vpci: fix handling of BAR overlaps with non-hole = regions') Signed-off-by: Roger Pau Monn=C3=A9 --- xen/drivers/vpci/header.c | 69 ++++++++++----------------------------- xen/include/xen/vpci.h | 5 +++ 2 files changed, 23 insertions(+), 51 deletions(-) diff --git a/xen/drivers/vpci/header.c b/xen/drivers/vpci/header.c index 255c6d54b406..2071bed81676 100644 --- a/xen/drivers/vpci/header.c +++ b/xen/drivers/vpci/header.c @@ -121,46 +121,6 @@ static int cf_check map_range( return rc; } =20 -/* - * The rom_only parameter is used to signal the map/unmap helpers that the= ROM - * BAR's enable bit has changed with the memory decoding bit already enabl= ed. - * If rom_only is not set then it's the memory decoding bit that changed. - */ -static void modify_decoding(const struct pci_dev *pdev, uint16_t cmd, - bool rom_only) -{ - struct vpci_header *header =3D &pdev->vpci->header; - bool map =3D cmd & PCI_COMMAND_MEMORY; - unsigned int i; - - for ( i =3D 0; i < ARRAY_SIZE(header->bars); i++ ) - { - struct vpci_bar *bar =3D &header->bars[i]; - - if ( !MAPPABLE_BAR(bar) ) - continue; - - if ( rom_only && bar->type =3D=3D VPCI_BAR_ROM ) - { - unsigned int rom_pos =3D (i =3D=3D PCI_HEADER_NORMAL_NR_BARS) - ? PCI_ROM_ADDRESS : PCI_ROM_ADDRESS1; - uint32_t val =3D bar->addr | - (map ? PCI_ROM_ADDRESS_ENABLE : 0); - - if ( pci_check_bar(pdev, _mfn(PFN_DOWN(bar->addr)), - _mfn(PFN_DOWN(bar->addr + bar->size - 1))) ) - bar->enabled =3D map; - return; - } - - if ( !rom_only && - (bar->type !=3D VPCI_BAR_ROM || header->rom_enabled) && - pci_check_bar(pdev, _mfn(PFN_DOWN(bar->addr)), - _mfn(PFN_DOWN(bar->addr + bar->size - 1))) ) - bar->enabled =3D map; - } -} - bool vpci_process_pending(struct vcpu *v) { const struct pci_dev *pdev =3D v->vpci.pdev; @@ -190,8 +150,10 @@ bool vpci_process_pending(struct vcpu *v) }; int rc; =20 + ASSERT(bar->valid || rangeset_is_empty(bar->mem)); + if ( rangeset_is_empty(bar->mem) ) - continue; + goto next; =20 rc =3D rangeset_consume_ranges(bar->mem, map_range, &data); =20 @@ -217,13 +179,13 @@ bool vpci_process_pending(struct vcpu *v) * rangeset_consume_ranges() itself doesn't generate any errors. */ rangeset_purge(bar->mem); + + next: + if ( bar->valid ) + bar->enabled =3D v->vpci.cmd & PCI_COMMAND_MEMORY; } v->vpci.pdev =3D NULL; =20 - spin_lock(&pdev->vpci->lock); - modify_decoding(pdev, v->vpci.cmd, v->vpci.rom_only); - spin_unlock(&pdev->vpci->lock); - read_unlock(&v->domain->pci_lock); =20 return false; @@ -243,10 +205,8 @@ static int __init apply_map(struct domain *d, const st= ruct pci_dev *pdev, struct vpci_bar *bar =3D &header->bars[i]; struct map_data data =3D { .d =3D d, .map =3D true, .bar =3D bar }; =20 - if ( rangeset_is_empty(bar->mem) ) - continue; - - while ( (rc =3D rangeset_consume_ranges(bar->mem, map_range, + while ( bar->mem && + (rc =3D rangeset_consume_ranges(bar->mem, map_range, &data)) =3D=3D -ERESTART ) { /* @@ -258,9 +218,10 @@ static int __init apply_map(struct domain *d, const st= ruct pci_dev *pdev, process_pending_softirqs(); write_lock(&d->pci_lock); } + + if ( bar->valid ) + bar->enabled =3D true; } - if ( !rc ) - modify_decoding(pdev, cmd, false); =20 return rc; } @@ -326,6 +287,9 @@ static int modify_bars(const struct pci_dev *pdev, uint= 16_t cmd, bool rom_only) */ rangeset_purge(bar->mem); =20 + /* Reset whether the BAR is valid, will be checked below. */ + bar->valid =3D false; + if ( !MAPPABLE_BAR(bar) || (rom_only ? bar->type !=3D VPCI_BAR_ROM : (bar->type =3D=3D VPCI_BAR_ROM && !header->rom_en= abled)) || @@ -341,6 +305,8 @@ static int modify_bars(const struct pci_dev *pdev, uint= 16_t cmd, bool rom_only) continue; } =20 + bar->valid =3D true; + /* * Make sure that the guest set address has the same page offset * as the physical address on the host or otherwise things won't w= ork as @@ -539,6 +505,7 @@ static void cf_check cmd_write( if ( (cmd & PCI_COMMAND_MEMORY) && vpci_make_msix_hole(pdev) ) return; #endif + /* * FIXME: for domUs we don't want the guest toggling the memory decodi= ng * bit. It should be set in vpci_init_header() and guest attempts to diff --git a/xen/include/xen/vpci.h b/xen/include/xen/vpci.h index 17cfecb0aabf..6bdbbb842f58 100644 --- a/xen/include/xen/vpci.h +++ b/xen/include/xen/vpci.h @@ -128,6 +128,11 @@ struct vpci { bool prefetchable : 1; /* Store whether the BAR is mapped into guest p2m. */ bool enabled : 1; + /* + * Is the BAR position valid? Used to store intermediate state + * before BAR modifications are applied to the p2m. + */ + bool valid : 1; } bars[PCI_HEADER_NORMAL_NR_BARS + 1]; /* At most 6 BARS + 1 expansion ROM BAR. */ =20 --=20 2.49.0