From nobody Sun Apr 28 21:30:47 2024 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=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1635852065; cv=none; d=zohomail.com; s=zohoarc; b=HVVb7hOy2lMol82pJsi+RIbI0HYZRpqZQNhqfhYRDMSFT/QG4Ob6uiVtvMNKVgy+2tCT7d0b7NNIIeSsg+xWHDV6hzMEny4cf0I0YDVQnc6ILYd10/xOjK+MS8ln3WJmP4RqLT5u+pnTl09tkhImDR0EgLTHmKfgyc5GsyqaKtU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1635852065; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=/Bk39DMTk2FXQwoiWFM450b+7g+0Wcb+kzWeUVJoYG8=; b=M5kPXzhc9NR9cEXs4kiZqDcXrcZQlb8zBILcK/pZi6rbTHRjRkv3twhqJkqjvwWHN2LSIqN7AztfFlLL9j8WrvN6g7FKEGXd/HyOHGZKgwIuqgQftHYDRuuMCsPtrAg8BbvMRY552vyNO1R8xNPGCpcJwENSmlwHA0jDhVB9Ozc= 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=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1635852065209433.97989022515117; Tue, 2 Nov 2021 04:21:05 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.220086.381203 (Exim 4.92) (envelope-from ) id 1mhrqV-0007gd-2V; Tue, 02 Nov 2021 11:20:51 +0000 Received: by outflank-mailman (output) from mailman id 220086.381203; Tue, 02 Nov 2021 11:20:51 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mhrqU-0007gW-Vd; Tue, 02 Nov 2021 11:20:50 +0000 Received: by outflank-mailman (input) for mailman id 220086; Tue, 02 Nov 2021 11:20:49 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mhrqT-0007Zk-DH for xen-devel@lists.xenproject.org; Tue, 02 Nov 2021 11:20:49 +0000 Received: from mail-ed1-x531.google.com (unknown [2a00:1450:4864:20::531]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id cd5d33b0-347c-461d-959a-97eb106900d3; Tue, 02 Nov 2021 11:20:44 +0000 (UTC) Received: by mail-ed1-x531.google.com with SMTP id w1so20794365edd.10 for ; Tue, 02 Nov 2021 04:20:44 -0700 (PDT) Received: from localhost.localdomain ([185.199.97.5]) by smtp.gmail.com with ESMTPSA id b2sm8107480ejj.124.2021.11.02.04.20.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Nov 2021 04:20:42 -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: cd5d33b0-347c-461d-959a-97eb106900d3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=/Bk39DMTk2FXQwoiWFM450b+7g+0Wcb+kzWeUVJoYG8=; b=b9BUwypTBpyF+2iQdP7QO5dyAZ74fMgsHw+8AZG6B/NheRXBe1F2OlSWufar2omS0T 2ofoXudprP+HphAONPoW0ERb4B0NH9lrzDqBAf1InwjwocgbbqahogO7MlQPBre/v/VV fhRuWbK3gPrjl/CLZE4NSgA0efXx9rpGqngaJvhkvLxKFD+xewG4F4hRq18byx2tPyS3 zomnvWGQL09zlvW0Jlp7upwed3sScItYYBCS6HIx8ewCgnweiLY7UjNxuiLDbqoegWaT QitpV+GjagCbtaQLUpdLysPDXKjRuZ4/f73O0RJ5mKLyT1p30G3rmg8l2sA4Ncv+XQ6n DITA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=/Bk39DMTk2FXQwoiWFM450b+7g+0Wcb+kzWeUVJoYG8=; b=HZYZ57imQaKHXfiLekWy2lZArluIjaLOf8fLb8JDX4ZAtBFTIJDbL005WqVzKNrNmC ddc3ggpnIPYKHSYTWHP+axJ2NjIi0nSCCdO1RhDhGX+h/AZ5sbIwyzvZEAZajECy9XOY YtamsJUbnatgYOhPvcWIsAx61GO21ulAL11BkDOO/iDTvmHEaEIDj5cv0HpCqx5C6non Q2LV19wngIQO1CRm4+ZsaKEduWD9tB7vS46En5HMH64v97uNvKRToSgdme5aIRZ2mFK9 HBDrSnFyGDP/otcskIOQJfaPwmMIOwVsx5bfIivSmbsYUuvqqWccbkfpOaZ8QZn/VXur WTpA== X-Gm-Message-State: AOAM530glejA9oNFc2qAyLDukft4V96kCol5sa6CcOhw9g5yzZ6DOhWA 9H1O1cs1lrOJjRJ2ncuii5HWIf20wLGL2w== X-Google-Smtp-Source: ABdhPJy97tx0v6AhTvxHzvJg9/7CyJTxjGGYYCc46mNOyY+e2lrhhmnyy48CV+pCaJ+0q3H4ROLivw== X-Received: by 2002:a05:6402:47:: with SMTP id f7mr50453296edu.52.1635852043453; Tue, 02 Nov 2021 04:20:43 -0700 (PDT) From: Oleksandr Andrushchenko To: xen-devel@lists.xenproject.org Cc: julien@xen.org, sstabellini@kernel.org, iwj@xenproject.org, bertrand.marquis@arm.com, rahul.singh@arm.com, Oleksandr Andrushchenko Subject: [PATCH-4.16 v2] xen/arm: fix SBDF calculation for vPCI MMIO handlers Date: Tue, 2 Nov 2021 13:20:41 +0200 Message-Id: <20211102112041.551369-1-andr2000@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1635852066315100001 Content-Type: text/plain; charset="utf-8" From: Oleksandr Andrushchenko While in vPCI MMIO trap handlers for the guest PCI host bridge it is not enough for SBDF translation to simply call VPCI_ECAM_BDF(info->gpa) as the base address may not be aligned in the way that the translation always work. If not adjusted with respect to the base address it may not be able to properly convert SBDF. Fix this by adjusting the gpa with respect to the host bridge base address in a way as it is done for x86. Please note, that this change is not strictly required given the current value of GUEST_VPCI_ECAM_BASE which has bits 0 to 27 clear, but could cause issues if such value is changed, or when handlers for dom0 ECAM regions are added as those will be mapped over existing hardware regions that could use non-aligned base addresses. Fixes: d59168dc05a5 ("xen/arm: Enable the existing x86 virtual PCI support = for ARM") Signed-off-by: Oleksandr Andrushchenko Acked-by: Stefano Stabellini --- Since v1: - updated commit message (Roger) This patch aims for 4.16 release. Benefits: Fix potential bug and clear the way for further PCI passthrough development. Risks: None as the change doesn't change the behaviour of the current code, but brings clarity into SBDF calculation. --- xen/arch/arm/vpci.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xen/arch/arm/vpci.c b/xen/arch/arm/vpci.c index 8f40a0dec6d2..23f45386f4b3 100644 --- a/xen/arch/arm/vpci.c +++ b/xen/arch/arm/vpci.c @@ -24,7 +24,7 @@ static int vpci_mmio_read(struct vcpu *v, mmio_info_t *in= fo, unsigned long data; =20 /* We ignore segment part and always handle segment 0 */ - sbdf.sbdf =3D VPCI_ECAM_BDF(info->gpa); + sbdf.sbdf =3D VPCI_ECAM_BDF(info->gpa - GUEST_VPCI_ECAM_BASE); =20 if ( vpci_ecam_read(sbdf, ECAM_REG_OFFSET(info->gpa), 1U << info->dabt.size, &data) ) @@ -44,7 +44,7 @@ static int vpci_mmio_write(struct vcpu *v, mmio_info_t *i= nfo, pci_sbdf_t sbdf; =20 /* We ignore segment part and always handle segment 0 */ - sbdf.sbdf =3D VPCI_ECAM_BDF(info->gpa); + sbdf.sbdf =3D VPCI_ECAM_BDF(info->gpa - GUEST_VPCI_ECAM_BASE); =20 return vpci_ecam_write(sbdf, ECAM_REG_OFFSET(info->gpa), 1U << info->dabt.size, r); --=20 2.25.1