From nobody Sat Feb 7 08:28:14 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=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1632988664; cv=none; d=zohomail.com; s=zohoarc; b=ic0IPQkEmD112+bdLhPVFt6U9Cz4q1uGJl0AHEWEA5HIZAc4J1TVFM60PiRNWfRxzwEUdD36dB/lSgTHOz5ALzj5lhqkjt12fqOhQs7BKViuPP5b8HpqiA2B+d5Ou+Pj/JtwscgOHw9R51h3PVIecrAFAXn7lkn7tZcupHeO8Aw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1632988664; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=kFKr9R5/eoTpWJugUvdw0hZSjF5zvjYKXnAMVRzF8Pk=; b=K10W1yino1UOK51OzOMXtUvE8amCbpwjIytduXmyCSGBWKzbD4brjJfnSt/CU+B700sTZsVM2ES+kN/uHEjvcdPC0m1WP6JVuZeMcMt7dPpRUMGBSP78N8OW49VuhHLd43xvwSMhEglZ1HFwLpy9eiksI5/j/fHlgF8WY+ifPmw= 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 1632988664250178.95849570135317; Thu, 30 Sep 2021 00:57:44 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.199561.353724 (Exim 4.92) (envelope-from ) id 1mVqwe-0008ML-Ij; Thu, 30 Sep 2021 07:57:32 +0000 Received: by outflank-mailman (output) from mailman id 199561.353724; Thu, 30 Sep 2021 07:57:32 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mVqwe-0008ME-Ee; Thu, 30 Sep 2021 07:57:32 +0000 Received: by outflank-mailman (input) for mailman id 199561; Thu, 30 Sep 2021 07:57:31 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mVqsX-00017f-6I for xen-devel@lists.xenproject.org; Thu, 30 Sep 2021 07:53:17 +0000 Received: from mail-lf1-x12a.google.com (unknown [2a00:1450:4864:20::12a]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 9ac7d20e-d2a5-489d-acb4-b13358f83a1a; Thu, 30 Sep 2021 07:52:35 +0000 (UTC) Received: by mail-lf1-x12a.google.com with SMTP id j5so16804175lfg.8 for ; Thu, 30 Sep 2021 00:52:35 -0700 (PDT) Received: from localhost.localdomain (host-176-36-245-220.b024.la.net.ua. [176.36.245.220]) by smtp.gmail.com with ESMTPSA id 13sm251099ljf.51.2021.09.30.00.52.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Sep 2021 00:52:33 -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: 9ac7d20e-d2a5-489d-acb4-b13358f83a1a DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kFKr9R5/eoTpWJugUvdw0hZSjF5zvjYKXnAMVRzF8Pk=; b=cWJGSCPP+epJ29KCHDh+8crG7u2S+kudHu40Amr21tBEaYnCRj4sLpj6yJlBz5lWjY bkH0E367iOZOHaRQVdwMKNzJb+JV4+Hdpvm9oZKzkFxD726NCHoDuDDfPzLQSBUpRL3L 9gFvonYsfiA/cdTdKzmi+5Ei+EzFxrwYmM4UMvr7JF5bpk214Gygsk6sXxyi9OaJBOnD gUV2hlylrGcyAW4tN/mZrbZ2AeINau62FVNJQ+e/v/u+p9CChqku8UpSjyViK6YE5vD2 xj/9U0yHM5Xhn43L9AK2JPGa9oCy5CEHeEiudzW4kf5ZRLmKNidiK4/f1BUA6xzxzKsv 39FA== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=kFKr9R5/eoTpWJugUvdw0hZSjF5zvjYKXnAMVRzF8Pk=; b=r4AWQ2Ooqfpm6p4JXzLGJkWw8tW67sIWlk0D+cPk2Wicb9rDHl8iWspPvc/WqNQnWI wgNI+WNDlNEEZzyGb5lL0uQx7jdewvKVc9tss0ImmQrqXqkP9hMjnvljrkolfzJgnYtw KFQtA6AJft7Axeq7Bo5selkocKYUuzAcIKFbDjKguIsV3regHtfp8a51xGpq23vp3g0Y U36o/fmNAVJjKZIC0iR3ZIhN4nmTieiLA0zTwVNJJk8AslesdPrA2BKi9VAstXhuXCG2 ZV5c46+rcQD1rzDTFniUEmXi5TwVTUzWyDat9zCVZPuPr9ZX16AnxeVEwU+sw5pZ3VqC wOVQ== X-Gm-Message-State: AOAM53095PPna5TjcukGTE0ypoywHseoZHeELUgGc6rfgQEN6MlDOPHf Zi781nuFbzJS0VPDs0+zDdDou3gG62w= X-Google-Smtp-Source: ABdhPJzNrHs+SZ/Q+mD+Sr3QROyeTeMKrWMeDO5LFmSFYlTZ1RNOC9HAByTat96meLn6Ha/BcigpWQ== X-Received: by 2002:ac2:4f02:: with SMTP id k2mr4255807lfr.378.1632988354376; Thu, 30 Sep 2021 00:52:34 -0700 (PDT) From: Oleksandr Andrushchenko To: xen-devel@lists.xenproject.org Cc: julien@xen.org, sstabellini@kernel.org, oleksandr_tyshchenko@epam.com, volodymyr_babchuk@epam.com, Artem_Mygaiev@epam.com, roger.pau@citrix.com, jbeulich@suse.com, bertrand.marquis@arm.com, rahul.singh@arm.com, Oleksandr Andrushchenko , Michal Orzel Subject: [PATCH v3 09/11] vpci/header: Reset the command register when adding devices Date: Thu, 30 Sep 2021 10:52:21 +0300 Message-Id: <20210930075223.860329-10-andr2000@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210930075223.860329-1-andr2000@gmail.com> References: <20210930075223.860329-1-andr2000@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1632988665393100001 Content-Type: text/plain; charset="utf-8" From: Oleksandr Andrushchenko Reset the command register when passing through a PCI device: it is possible that when passing through a PCI device its memory decoding bits in the command register are already set. Thus, a guest OS may not write to the command register to update memory decoding, so guest mappings (guest's view of the BARs) are left not updated. Signed-off-by: Oleksandr Andrushchenko Reviewed-by: Michal Orzel --- Since v1: - do not write 0 to the command register, but respect host settings. --- xen/drivers/vpci/header.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/xen/drivers/vpci/header.c b/xen/drivers/vpci/header.c index 754aeb5a584f..70d911b147e1 100644 --- a/xen/drivers/vpci/header.c +++ b/xen/drivers/vpci/header.c @@ -451,8 +451,7 @@ static void cmd_write(const struct pci_dev *pdev, unsig= ned int reg, pci_conf_write16(pdev->sbdf, reg, cmd); } =20 -static void guest_cmd_write(const struct pci_dev *pdev, unsigned int reg, - uint32_t cmd, void *data) +static uint32_t emulate_cmd_reg(const struct pci_dev *pdev, uint32_t cmd) { /* TODO: Add proper emulation for all bits of the command register. */ =20 @@ -467,14 +466,20 @@ static void guest_cmd_write(const struct pci_dev *pde= v, unsigned int reg, cmd |=3D PCI_COMMAND_INTX_DISABLE; else { - uint16_t current_cmd =3D pci_conf_read16(pdev->sbdf, reg); + uint16_t current_cmd =3D pci_conf_read16(pdev->sbdf, PCI_COMMA= ND); =20 if ( current_cmd & PCI_COMMAND_INTX_DISABLE ) cmd |=3D PCI_COMMAND_INTX_DISABLE; } } =20 - cmd_write(pdev, reg, cmd, data); + return cmd; +} + +static void guest_cmd_write(const struct pci_dev *pdev, unsigned int reg, + uint32_t cmd, void *data) +{ + cmd_write(pdev, reg, emulate_cmd_reg(pdev, cmd), data); } =20 static void bar_write(const struct pci_dev *pdev, unsigned int reg, @@ -793,6 +798,10 @@ int vpci_bar_add_handlers(const struct domain *d, cons= t struct pci_dev *pdev) gdprintk(XENLOG_ERR, "%pp: failed to add BAR handlers for dom%pd: %d\n", &pdev->sbdf, d, rc); + + /* Reset the command register with respect to host settings. */ + pci_conf_write16(pdev->sbdf, PCI_COMMAND, emulate_cmd_reg(pdev, 0)); + return rc; } =20 --=20 2.25.1