[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v9 11/16] vpci/header: reset the command register when adding devices
- To: Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>
- From: Roger Pau Monné <roger.pau@xxxxxxxxxx>
- Date: Thu, 21 Sep 2023 15:30:31 +0200
- Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
- Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=yMpSe2qRFfSi4/R7e1GMan/Lz3FzGZSzjpoVHIDIN60=; b=TPtyrQaklVWBXM/ZjyZIhg/na31FTVUpD1GgpQDfwn9eCDdZvAkAVNYa+15s/DaUkyoob2VAqie4EfZk485sByNLBWXpS/JcCmc8F7cWoI1CasLTu5pmpI5kSLgqQf33TFpAfiTaKx2nCnr1hAUmaxiB6LRQ4Utt7UoagQe7qiiZhFyokKpJY345L1+vGHmV4HHZnHSyYYC6zASopjJZLnn0mOoKaf8JMpqb32hHoLOx3ERYgDaYxxeMMHGszq3CC1TTTCzUs42whknXtJD9QpZhHJ+qen85XGT2Sipeo09R8IkEbSRUYiA1x1XGK00f6GfpvlXPb+kAXPe91cQg5w==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aLe8yZfRoljAaF2b/9v+jgETrrp4tQinNvPUbWjHhkiaOygqkSF7U5Uy0Zs3DvapyKes/AGFvEFook49qXeiKLwlI6UqLiJCzeWG6l2fVBf6lMXCSKdPIwZA9q63rCL12wnvUBdA3ILS4sUD8EqVSpHIm9nit0CXVuiimaR0BJyLJ+QhqXEoq7t4vP4VXkdqcaUMj/wnlBZxbtNLfvYpB1ae3Yv7Ep4mPWsK74qgfu+PPEXVG4HTDEpdYnAK62l9rrnvixuDVClvkwDTus1Qs+WNVHoOR4PDIKWGnW75JylTocK/OkGo+oZ78VhB2rxmck0MGX746Oc5iUBaA4rR8g==
- Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
- Cc: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Stewart Hildebrand <stewart.hildebrand@xxxxxxx>, Oleksandr Andrushchenko <Oleksandr_Andrushchenko@xxxxxxxx>
- Delivery-date: Thu, 21 Sep 2023 13:30:59 +0000
- Ironport-data: A9a23:FC9aaatTAwaOBP+QHgHXgZzwy+fnVI1fMUV32f8akzHdYApBsoF/q tZmKWqDbP2IYzbwKNwkadnk9U4B6pLQy9BnSwo6+X80FHlG+JbJXdiXEBz9bniYRiHhoOCLz O1FM4Wdc5pkJpP4jk3wWlQ0hSAkjclkfpKlVaicfHg3HFc4IMsYoUoLs/YjhYJ1isSODQqIu Nfjy+XSI1bg0DNvWo4uw/vrRChH4rKq41v0gnRkPaoQ5A6EziFPZH4iDfrZw0XQE9E88tGSH 44v/JnhlkvF8hEkDM+Sk7qTWiXmlZaLYGBiIlIPM0STqkAqSh4ai87XB9JFAatjsB2bnsgZ9 Tl4ncfYpTHFnEH7sL91vxFwS0mSNEDdkVPNCSDXXce7lyUqf5ZwqhnH4Y5f0YAwo45K7W9yG fMwCm4jRzqTteOMwpWnWORnq9t6MfbwM9ZK0p1g5Wmx4fcOZ7nmGv2PwOACmTA6i4ZJAOrUY NcfZXx3dhPcbhZTO1ARTpUjgOOvgXq5eDpdwL6XjfNvvy6Pk0osjf60aIq9lt+iHK25mm6Co W3L5SLhCwwyP92D0zuVtHmrg4cjmAuiAtxLTuLoqqUCbFu77HRDECVGUQOCmeC5u2+6UIhUE m8J5X97xUQ13AnxJjXnZDWGp3qDsg8ZSsBnOeQw4wGQyYLZ+w+cQGMDS1ZpeNEg8cM7WzEu/ luIhM/yQyxitqWPTnCQ/avSqim9UQAOMWIdbDUYCwsE59Xuqps6iB7nR9NvVqWyi7XdPjX9w CuDqiQksJwVgdQWzKWw/V3BgDWEq4DAS0g+4QC/Y46+xgZwZYrgYpPy71HetK5ENNzAFgnHu 2UYkc+D6uxIFYuKiCGGXOQKGveu+uqBNzrfx1VoGvHN6giQxpJqRqgIiBkWGaujGp9slePBC KMLhT5s2Q==
- Ironport-hdrordr: A9a23:IY3gT67bnPBKKeipVAPXwDjXdLJyesId70hD6qkQc3Fom62j5q STdZEgvyMc5wx/ZJhNo7690cq7MBbhHPxOkOos1N6ZNWGLhILPFuBfBOPZqAEIcBeOlNK1u5 0BT0EEMqyWMbB75/yKnDVREbwbsaa6GHbDv5ah859vJzsaGp2J921Ce2Cm+tUdfng9OXI+fq Dsn/Zvln6bVlk8SN+0PXUBV/irnay3qHq3CSR2fyLO8WO1/EiV1II=
- List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
On Tue, Aug 29, 2023 at 11:19:45PM +0000, Volodymyr Babchuk wrote:
> From: Oleksandr Andrushchenko <oleksandr_andrushchenko@xxxxxxxx>
>
> Reset the command register when assigning a PCI device to a guest:
> according to the PCI spec the PCI_COMMAND register is typically all 0's
> after reset, but this might not be true for the guest as it needs
> to respect host's settings.
> For that reason, do not write 0 to the PCI_COMMAND register directly,
> but go through the corresponding emulation layer (cmd_write), which
> will take care about the actual bits written. Also, honor value of
> PCI_COMMAND_VGA_PALETTE value, which is set by firmware.
I think this is likely dangerous, it would be better IMO to simply
make sure the value presented to the guest is all zeros, and that the
vPCI cached state is consistent with that.
> Signed-off-by: Oleksandr Andrushchenko <oleksandr_andrushchenko@xxxxxxxx>
> Signed-off-by: Volodymyr Babchuk <volodymyr_babchuk@xxxxxxxx>
> ---
> Since v9:
> - Honor PCI_COMMAND_VGA_PALETTE bit
> Since v6:
> - use cmd_write directly without introducing emulate_cmd_reg
> - update commit message with more description on all 0's in PCI_COMMAND
> Since v5:
> - updated commit message
> Since v1:
> - do not write 0 to the command register, but respect host settings.
> ---
> xen/drivers/vpci/header.c | 7 ++++++-
> 1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/xen/drivers/vpci/header.c b/xen/drivers/vpci/header.c
> index e351db4620..1d243eeaf9 100644
> --- a/xen/drivers/vpci/header.c
> +++ b/xen/drivers/vpci/header.c
> @@ -762,6 +762,12 @@ static int cf_check init_bars(struct pci_dev *pdev)
> return -EOPNOTSUPP;
> }
>
> + /* Reset the command register for guests. We want to preserve only
> + * PCI_COMMAND_VGA_PALETTE as it is configured by firmware */
Wrong comment style, and PCI_COMMAND_VGA_PALETTE is likely to be gone
anyway after we perform a FLR of the device anyway?
> + cmd = pci_conf_read16(pdev->sbdf, PCI_COMMAND);
> + if ( !is_hwdom )
> + cmd_write(pdev, PCI_COMMAND, cmd & PCI_COMMAND_VGA_PALETTE, header);
Such cmd_write() call might trigger an attempt to change the guest
physmap if you are toggling the Memory Enabled bit from 1 -> 0, and
that would fail because the guest doesn't have BAR p2m mappings setup
yet, those are done at the end of the function by the call to
modify_bars().
Thanks, Roger.
|