From nobody Wed Dec 17 21:46:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1655309665; cv=none; d=zohomail.com; s=zohoarc; b=AglLDxlz3UBl/rDMziAFwmYjlR27SsynsXID0hW2/C8WJPAHrdGVFgGGdpD8AgQSo8rS1l+QbHoSgvnHmhCOkD6mbPTOiePNCNl3na0qrMBf18la1zODNfimPvvZveInbD/t3YIP2gCGEuLtJfdZGDaNp8SkdFvyxtLUrcbqmrg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1655309665; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=aZL/JlJ/vqeiyMYiiFVFD0RUBsrLB52ersglBUsQrag=; b=QGSCGuFCqGwN/7mP0XlQauKes0r33yUUZCUPC5G6k4GeMu2yHHjwotN5Sk0o5RJVvhGdpAyBJk7O7Qm/rQJl9eLA6GfGErOOHlL35luk+3RJFw9GozoHq9CMM642R+/mn7EQINlYCEdQBgQWeTgEUx9f+GM+atJ45pyVfiEaK4U= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1655309665354146.49395438890338; Wed, 15 Jun 2022 09:14:25 -0700 (PDT) Received: from localhost ([::1]:42912 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o1Vex-0001j3-Oi for importer@patchew.org; Wed, 15 Jun 2022 12:14:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43298) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o1VLr-0004Ag-2K for qemu-devel@nongnu.org; Wed, 15 Jun 2022 11:54:39 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:51022) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o1VLp-0007Lx-4x for qemu-devel@nongnu.org; Wed, 15 Jun 2022 11:54:38 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-631-bQZ6q3lPNBqCvE_z6Sq56A-1; Wed, 15 Jun 2022 11:54:32 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B514580418F; Wed, 15 Jun 2022 15:54:30 +0000 (UTC) Received: from localhost (unknown [10.39.192.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1996D2166B26; Wed, 15 Jun 2022 15:54:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655308474; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=aZL/JlJ/vqeiyMYiiFVFD0RUBsrLB52ersglBUsQrag=; b=CBoJ/vUD1ugjDutjJ4MesBgzxkSJS5ACmR87r52QkJX5AMD3AXWk357M5d4THKntUJLFmE cCZVb8+34TZZ5ocNjJDouhUBvbYUaNG7YRgIbJ+ks/17HRTqnWlbf3IwWQSwrX7eubU0wl XAcUqL4nK7eE1aQGtftwmnXF/9YcOYk= X-MC-Unique: bQZ6q3lPNBqCvE_z6Sq56A-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: Thomas Huth , Jagannathan Raman , Aarushi Mehta , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Elena Ufimtseva , Marcel Apfelbaum , Stefan Hajnoczi , Laurent Vivier , , "Dr. David Alan Gilbert" , Richard Henderson , virtio-fs@redhat.com, Hanna Reitz , David Hildenbrand , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Eric Blake , Kevin Wolf , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Beraldo Leal , Peter Xu , Eduardo Habkost , Qiuhao Li , Paolo Bonzini , Markus Armbruster , Bandan Das , "Michael S. Tsirkin" , Stefano Garzarella , Alexander Bulekov , Julia Suvorova , Darren Kenny , Wainer dos Santos Moschetta , John G Johnson Subject: [PULL 11/18] vfio-user: handle PCI config space accesses Date: Wed, 15 Jun 2022 16:51:22 +0100 Message-Id: <20220615155129.1025811-12-stefanha@redhat.com> In-Reply-To: <20220615155129.1025811-1-stefanha@redhat.com> References: <20220615155129.1025811-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1655309666013100001 Content-Type: text/plain; charset="utf-8" From: Jagannathan Raman Define and register handlers for PCI config space accesses Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman Reviewed-by: Stefan Hajnoczi Message-id: be9d2ccf9b1d24e50dcd9c23404dbf284142cec7.1655151679.git.jag.ram= an@oracle.com Signed-off-by: Stefan Hajnoczi --- hw/remote/vfio-user-obj.c | 51 +++++++++++++++++++++++++++++++++++++++ hw/remote/trace-events | 2 ++ 2 files changed, 53 insertions(+) diff --git a/hw/remote/vfio-user-obj.c b/hw/remote/vfio-user-obj.c index 178bd6f8ed..cef473cb98 100644 --- a/hw/remote/vfio-user-obj.c +++ b/hw/remote/vfio-user-obj.c @@ -46,6 +46,7 @@ #include "qapi/qapi-events-misc.h" #include "qemu/notify.h" #include "qemu/thread.h" +#include "qemu/main-loop.h" #include "sysemu/sysemu.h" #include "libvfio-user.h" #include "hw/qdev-core.h" @@ -244,6 +245,45 @@ retry_attach: qemu_set_fd_handler(o->vfu_poll_fd, vfu_object_ctx_run, NULL, o); } =20 +static ssize_t vfu_object_cfg_access(vfu_ctx_t *vfu_ctx, char * const buf, + size_t count, loff_t offset, + const bool is_write) +{ + VfuObject *o =3D vfu_get_private(vfu_ctx); + uint32_t pci_access_width =3D sizeof(uint32_t); + size_t bytes =3D count; + uint32_t val =3D 0; + char *ptr =3D buf; + int len; + + /* + * Writes to the BAR registers would trigger an update to the + * global Memory and IO AddressSpaces. But the remote device + * never uses the global AddressSpaces, therefore overlapping + * memory regions are not a problem + */ + while (bytes > 0) { + len =3D (bytes > pci_access_width) ? pci_access_width : bytes; + if (is_write) { + memcpy(&val, ptr, len); + pci_host_config_write_common(o->pci_dev, offset, + pci_config_size(o->pci_dev), + val, len); + trace_vfu_cfg_write(offset, val); + } else { + val =3D pci_host_config_read_common(o->pci_dev, offset, + pci_config_size(o->pci_dev),= len); + memcpy(ptr, &val, len); + trace_vfu_cfg_read(offset, val); + } + offset +=3D len; + ptr +=3D len; + bytes -=3D len; + } + + return count; +} + /* * TYPE_VFU_OBJECT depends on the availability of the 'socket' and 'device' * properties. It also depends on devices instantiated in QEMU. These @@ -336,6 +376,17 @@ static void vfu_object_init_ctx(VfuObject *o, Error **= errp) TYPE_VFU_OBJECT, o->device); qdev_add_unplug_blocker(DEVICE(o->pci_dev), o->unplug_blocker); =20 + ret =3D vfu_setup_region(o->vfu_ctx, VFU_PCI_DEV_CFG_REGION_IDX, + pci_config_size(o->pci_dev), &vfu_object_cfg_ac= cess, + VFU_REGION_FLAG_RW | VFU_REGION_FLAG_ALWAYS_CB, + NULL, 0, -1, 0); + if (ret < 0) { + error_setg(errp, + "vfu: Failed to setup config space handlers for %s- %s", + o->device, strerror(errno)); + goto fail; + } + ret =3D vfu_realize_ctx(o->vfu_ctx); if (ret < 0) { error_setg(errp, "vfu: Failed to realize device %s- %s", diff --git a/hw/remote/trace-events b/hw/remote/trace-events index 7da12f0d96..2ef7884346 100644 --- a/hw/remote/trace-events +++ b/hw/remote/trace-events @@ -5,3 +5,5 @@ mpqemu_recv_io_error(int cmd, int size, int nfds) "failed t= o receive %d size %d, =20 # vfio-user-obj.c vfu_prop(const char *prop, const char *val) "vfu: setting %s as %s" +vfu_cfg_read(uint32_t offset, uint32_t val) "vfu: cfg: 0x%u -> 0x%x" +vfu_cfg_write(uint32_t offset, uint32_t val) "vfu: cfg: 0x%u <- 0x%x" --=20 2.36.1