From patchwork Fri Oct 21 18:41:42 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ido Yariv X-Patchwork-Id: 9389871 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id EB6AB60780 for ; Fri, 21 Oct 2016 18:42:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E1BCD2A218 for ; Fri, 21 Oct 2016 18:42:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D4BDD2A27B; Fri, 21 Oct 2016 18:42:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 60EE62A218 for ; Fri, 21 Oct 2016 18:42:25 +0000 (UTC) Received: from localhost ([::1]:33787 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bxels-0001PP-M3 for patchwork-qemu-devel@patchwork.kernel.org; Fri, 21 Oct 2016 14:42:24 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40761) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bxelV-0001O4-3p for qemu-devel@nongnu.org; Fri, 21 Oct 2016 14:42:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bxelQ-0008OB-Fm for qemu-devel@nongnu.org; Fri, 21 Oct 2016 14:42:01 -0400 Received: from mail-pf0-x244.google.com ([2607:f8b0:400e:c00::244]:34973) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1bxelQ-0008Nc-A1 for qemu-devel@nongnu.org; Fri, 21 Oct 2016 14:41:56 -0400 Received: by mail-pf0-x244.google.com with SMTP id s8so9296965pfj.2 for ; Fri, 21 Oct 2016 11:41:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wizery-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=2km4yat9Q75RejZhgo4woM5dskaH1Ihje5LiAxooF+M=; b=Ide9xx7aIYF9vFsIreQqTTlCmCY7mZxEAvmnnDBKsSiXEiqbhlcGOqJI2a/OsGADjT GjL8fbr4h84WlvBqQ55Gs2jsf+E7DVtFKWlOIAwlBaqAohMBaIUZBR5pQ65tQA3KdLe6 DRDPt+8EcYjU5W8FMrSzh7a7ofy7VFplsZw5xoxcp9W85doCSEpGXImTIafvzj9WBYi5 4UhQmAp/8PzgSEmYwgeD1ln0MpuoBFTPN4YITU/Gj/4d9MtI8HvHmb5gcqC/tHcpVCtF odQEiZdgXaxny7vu+Umx0UEHD7Ldp25e4zkpvtjEQWhwnv95aVIjQN1wKQmwjrJ7nwEX HAhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=2km4yat9Q75RejZhgo4woM5dskaH1Ihje5LiAxooF+M=; b=XOu994qOSLKwzafgctYHp48mgxrEa2/kDzUjsSRy6s4RuV/Y/T5/VEuQqJ85hSZi1Q GmyXkT9BXI2OPdFN+Xc1xjdcXYptpQBS7Jo1osPgMFBILQ63ORTkbvwYZ0274R3d5gna YO6uEdhLYdZr8E+hXwQIcg7tLtcsLbU+GdmL7cPdgCJk8ZcxcZCdJ+qAT5/zbjvvnca3 0FSSyXayJCdJPWn21as3ycxHnNp81lun1c3wAOnNToi5l+C/ZUw78/mOwe0vtKH9M9Pf ECTaYcKAeCLHLQaQqJ07b0UHVUsNvjiX4AHJutWF46w/eXYQYYt/cw0wQFz7oLqMTJml iRiQ== X-Gm-Message-State: ABUngvek7ChiLrRPVculfix7Mo1CTNGCnoNc4u1VwZGOkYBKC/tOUTBPnylhqBAWBAslog== X-Received: by 10.99.121.133 with SMTP id u127mr3459513pgc.4.1477075315225; Fri, 21 Oct 2016 11:41:55 -0700 (PDT) Received: from WorkStation.amr.corp.intel.com (fmdmzpr01-ext.fm.intel.com. [192.55.54.36]) by smtp.gmail.com with ESMTPSA id y2sm6859648pfk.54.2016.10.21.11.41.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Oct 2016 11:41:54 -0700 (PDT) From: Ido Yariv To: Alex Williamson Date: Fri, 21 Oct 2016 14:41:42 -0400 Message-Id: <1477075302-21120-1-git-send-email-ido@wizery.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <20161021120321.46bf6f44@t450s.home> References: <20161021120321.46bf6f44@t450s.home> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400e:c00::244 Subject: [Qemu-devel] [PATCH v2] vfio/pci: fix out-of-sync BAR information on reset X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-devel@nongnu.org, Ido Yariv Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP When a PCI device is reset, pci_do_device_reset resets all BAR addresses in the relevant PCIDevice's config buffer. The VFIO configuration space stays untouched, so the guest OS may choose to skip restoring the BAR addresses as they would seem intact. The PCI device may be left non-operational. One example of such a scenario is when the guest exits S3. Fix this by resetting the BAR addresses in the VFIO configuration space as well. Signed-off-by: Ido Yariv --- hw/vfio/pci.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 65d30fd..b399742 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -1922,11 +1922,23 @@ static void vfio_pci_pre_reset(VFIOPCIDevice *vdev) static void vfio_pci_post_reset(VFIOPCIDevice *vdev) { Error *err = NULL; + int nr; vfio_intx_enable(vdev, &err); if (err) { error_reportf_err(err, ERR_PREFIX, vdev->vbasedev.name); } + + for (nr = 0; nr < PCI_NUM_REGIONS - 1; ++nr) { + off_t addr = vdev->config_offset + PCI_BASE_ADDRESS_0 + (4 * nr); + uint32_t val = 0; + uint32_t len = sizeof(val); + + if (pwrite(vdev->vbasedev.fd, &val, len, addr) != len) { + error_report("%s(%s) reset bar %d failed: %m", __func__, + vdev->vbasedev.name, nr); + } + } } static bool vfio_pci_host_match(PCIHostDeviceAddress *addr, const char *name)