git: 6448a0a51a81 - stable/13 - bhyve: keep physical and virtual COMMAND reg in sync

From: Emmanuel Vadot <manu_at_FreeBSD.org>
Date: Fri, 14 Jan 2022 14:20:42 UTC
The branch stable/13 has been updated by manu:

URL: https://cgit.FreeBSD.org/src/commit/?id=6448a0a51a81846764f56afb5d83a2245f139d37

commit 6448a0a51a81846764f56afb5d83a2245f139d37
Author:     Corvin Köhne <CorvinK@beckhoff.com>
AuthorDate: 2021-11-22 15:26:03 +0000
Commit:     Emmanuel Vadot <manu@FreeBSD.org>
CommitDate: 2022-01-14 14:18:08 +0000

    bhyve: keep physical and virtual COMMAND reg in sync
    
    On startup all virtual BARs are registered.
    Additionally, the encoding bit in the virtual cmd register is set.
    After that, the passthru emulation overwrites the virtual cmd register with
    the physical one.
    This could lead to a mismatch between registered BARs and the encoding
    bits in the cmd register.
    Instead of writing the physical to the virtual cmd register,
    write the virtual to the physical cmd register to solve this issue.
    
    Reviewed by:      markj
    Differential Revision:  https://reviews.freebsd.org/D32687
    Sponsored by:   Beckhoff Automation GmbH & Co. KG
    
    (cherry picked from commit 2eb2079554f4d54c4283410b4ee1aca549b29616)
---
 usr.sbin/bhyve/pci_passthru.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/usr.sbin/bhyve/pci_passthru.c b/usr.sbin/bhyve/pci_passthru.c
index eeb01e61b658..8c48f522562d 100644
--- a/usr.sbin/bhyve/pci_passthru.c
+++ b/usr.sbin/bhyve/pci_passthru.c
@@ -594,8 +594,8 @@ cfginit(struct vmctx *ctx, struct pci_devinst *pi, int bus, int slot, int func)
 		goto done;
 	}
 
-	pci_set_cfgdata16(pi, PCIR_COMMAND, read_config(&sc->psc_sel,
-	    PCIR_COMMAND, 2));
+	write_config(&sc->psc_sel, PCIR_COMMAND, 2,
+	    pci_get_cfgdata16(pi, PCIR_COMMAND));
 
 	/*
 	 * We need to do this after PCIR_COMMAND got possibly updated, e.g.,