[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v5 06/14] vpci/header: implement guest BAR register handlers
- To: Oleksandr Andrushchenko <Oleksandr_Andrushchenko@xxxxxxxx>
- From: Roger Pau Monné <roger.pau@xxxxxxxxxx>
- Date: Thu, 3 Feb 2022 15:05:46 +0100
- Arc-authentication-results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; 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=CS7V07AIdkGI252hKVMxsoOyL2HAZKXrXAMBhnxgCB4=; b=nm89MeaHr9hjoAgasb157cUVbcoTZUj5J+nmQfwCLIvX9fDA/H1/oVVyNPr7EyPgb83dFplLKpjBvaTCoJcmfFkDYJwVLu7knVS0B11AIxl1luDU3zBEJT4e1IHQJmxCjVAB0sWf4EhWlhwicX1Jd5iv+gO3Y68MNkNrFTmw7Ov2w40lwYKXPt221FbQUuj3/Qsz5aQdVaAxAMAsFe17B/dSh4NAJrLC7hY7vBw35cbiSu11YergVLmuN5dbMixK0bNuW+XkZ40F7BcdDoHH/hn+TU/XEhu8GnftJbPvfIk9RcYOC6nvGHf3f5ZhTDRrLVz/IXTwfs3G1Tc5ebWTNQ==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RHsezH2bVg1r4v/udyqxnT5fA09WOKApK89RNo/kzfD1ay2/Hz3DOzHCHkNCeZHhkxdDHfsyEyvWfjN/u54F1n67sAdsQ+inmywBAGy33fZ4D4xG5dUGWdUQFpIIiiMAbKqhjAX7omFxjZWdiRlH0fwTvOdnjj9K0EF9S/P79U4SD6MMCQA426nhzxCbgKpRfr0dpwkJdaVrUVlRuMy59hoDjXsZNTjEmVnDmV57CKsrDvtO+MnMn35mZLfDDllo7Xjqhbm4WWhRzJNPl+B04XnUK1V+1j0ACBmlw5/Uy+54PpKk5UvJUoxVSYA+xPTOYfwrf2pxGR7oSCq/xVJHiw==
- Authentication-results: esa6.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com
- Cc: Jan Beulich <jbeulich@xxxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, "julien@xxxxxxx" <julien@xxxxxxx>, "sstabellini@xxxxxxxxxx" <sstabellini@xxxxxxxxxx>, Oleksandr Tyshchenko <Oleksandr_Tyshchenko@xxxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>, Artem Mygaiev <Artem_Mygaiev@xxxxxxxx>, "andrew.cooper3@xxxxxxxxxx" <andrew.cooper3@xxxxxxxxxx>, "george.dunlap@xxxxxxxxxx" <george.dunlap@xxxxxxxxxx>, "paul@xxxxxxx" <paul@xxxxxxx>, Bertrand Marquis <bertrand.marquis@xxxxxxx>, Rahul Singh <rahul.singh@xxxxxxx>
- Delivery-date: Thu, 03 Feb 2022 14:06:07 +0000
- Ironport-data: A9a23:+VEB06PizotvbZrvrR3NkMFynXyQoLVcMsEvi/4bfWQNrUog1DBTn GFKXm3Sa62MYWqme9ona4+w/UhXvpSDmoJmTwto+SlhQUwRpJueD7x1DKtR0wB+jCHnZBg6h ynLQoCYdKjYdpJYz/uUGuCJQUNUjMlkfZKhTr6UUsxNbVU8En1500o4w7RRbrNA2rBVPSvc4 bsenOWHULOV82Yc3rU8sv/rRLtH5ZweiRtA1rAMTakjUGz2zhH5OKk3N6CpR0YUd6EPdgKMq 0Qv+5nilo/R109F5tpICd8XeGVSKlLZFVDmZna7x8FOK/WNz8A/+v9TCRYSVatYozbV3Ox90 YRPj7OtGQM4EYHvyfU8fDANRkmSPYUekFPGCX22sMjVxEzaaXr8hf5pCSnaP6VBpLwxWzsXs 6VFdnZ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FcJHXdLJyesId70hD6qkvc3Nom52j+/ xGws536faVslcssHFJo6HmBEClewKnyXcT2/htAV7CZnichILMFu9fBOTZsl/d8kHFh4tgPO JbAtRD4b7LfClHZKTBkXCF+r8bqbHtmsDY5ts2jU0dNT2CA5sQkTuRYTzrdHGeKjM2YabQQ/ Gnl7V6TnebCD8qR/X+IkNAc/nIptXNmp6jSRkaByQ/4A3LqT+z8rb1HzWRwx9bClp0sPof2F mAtza8yrSosvm9xBOZ/2jP765OkN+k7tdYHsSDhuUcNz2poAe1Y4ZKXaGEoVkO0auSwWdvtO OJjwYrPsx15X+UVmapoSH10w2l6zoq42+K8y7vvVLT5ejCAB4qActIgoxUNjHD7VA7gd162K VXm0qEqpt+F3r77WrAzumNcysvulu/oHIkn+JWpWdYS5EiZLhYqpFa1F9JEa0HADnx5OkcYa ZT5fnnlbZrmG6hHjPkVjEF+q3vYp1zJGbLfqE6gL3V79AM90oJinfxx6Qk7wA9HdwGOt15Dt //Q9dVfYd1P7srhJJGdZc8qPSMex7wqDL3QSuvyAfcZek600ykke+D3Fxy3pDsRKA1
- Ironport-sdr: rjcPPiKvhURkGwfAVZNZ2O4IOWplLIOeKyil5DOMI9wdCGiN7HAn6xLVnXUm6LSEE8sr/4LWV2 tXV0vaF7ecfu1FefQAGu9DR84YUmh5Qj0uvSgtgt01WZrOnLF98H3AZtB5GQYxwmZ7jYkr7W0/ 1rO09V3WKjgG7n33HCXfCZZeFwLmjNJdrW0SZHJZ1yKoohAiWPG+wpxDTER4t6m6LYbrADKXzf skjV0+EFasFoq4TCsuTFBl4Y9ZMvHUO7f/5lX5tiaq0CnR6Xs5jSABgkqk0oK3KA6Tz1vKy+L0 fxk=
- List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
On Thu, Feb 03, 2022 at 01:30:26PM +0000, Oleksandr Andrushchenko wrote:
>
>
> On 03.02.22 14:54, Jan Beulich wrote:
> > On 03.02.2022 13:45, Oleksandr Andrushchenko wrote:
> >>>> Also memory decoding needs to be initially disabled when used by
> >>>> guests, in order to prevent the BAR being placed on top of a RAM
> >>>> region. The guest physmap will be different from the host one, so it's
> >>>> possible for BARs to end up placed on top of RAM regions initially
> >>>> until the firmware or OS places them at a suitable address.
> >>> Agree, memory decoding must be disabled
> >> Isn't it already achieved by the toolstack resetting the PCI device
> >> while assigning it to a guest?
> > Iirc the tool stack would reset a device only after getting it back from
> > a DomU. When coming straight from Dom0 or DomIO, no reset would be
> > performed. Furthermore, (again iirc) there are cases where there's no
> > known (standard) way to reset a device. Assigning such to a guest when
> > it previously was owned by another one is risky (and hence needs an
> > admin knowing what they're doing), but may be acceptable in particular
> > when e.g. simply rebooting a guest.
> >
> > IOW - I don't think you can rely on the bit being in a particular state.
> So, you mean something like:
>
> diff --git a/xen/drivers/vpci/header.c b/xen/drivers/vpci/header.c
> index 7695158e6445..9ebd57472da8 100644
> --- a/xen/drivers/vpci/header.c
> +++ b/xen/drivers/vpci/header.c
> @@ -808,6 +808,14 @@ static int init_bars(struct pci_dev *pdev)
> return rc;
> }
>
> + /*
> + * Memory decoding needs to be initially disabled when used by
> + * guests, in order to prevent the BAR being placed on top of a RAM
> + * region.
> + */
> + if ( !is_hwdom )
> + pci_conf_write16(pdev->sbdf, PCI_COMMAND, cmd & ~PCI_COMMAND_MEMORY);
Memory decoding is already disabled here, so you just need to avoid
enabling it, for example:
/*
* Memory decoding needs to be initially disabled when used by
* guests, in order to prevent the BARs being mapped at gfn 0 by
* default.
*/
if ( !is_hwdom )
cmd &= ~PCI_COMMAND_MEMORY;
> return (cmd & PCI_COMMAND_MEMORY) ? modify_bars(pdev, cmd, false) : 0;
This is important here because guest_reg won't be set (ie: will be set
to 0) so if for some reason memory decoding was enabled you would end
up with BARs mappings overlapping at gfn 0.
Thanks, Roger.
|