From nobody Tue Dec 16 16:56:32 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1606854585; cv=none; d=zohomail.com; s=zohoarc; b=j8ipLTR7KvdswNAdUaq0oaJsMBbbINmALXEI+hhX6TmKVxlMn7uqt2fGSReMJ+ItK5pO3J8v+gwPdL/pEPhWQRXPaVOMpsTfsRsGP+8GRZTCDgIcv5If7g3EmvWso8Iak1dRcoduaJh9yewyZzlQ0bhMCuaUOCd2DOxVpnK/0p8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1606854585; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=dzVASaejOf++Ig6YE+dx7DDVuyb1MSb4KBmVodGL0lw=; b=PQkooYGxZtuCWUiEOADfznG2b3VUWR4bom4htMBd2F9gGKIRZlsyheuZvWqN/Xrq7W9vmf9HrxfdqbrG4rz1rqoB7656Nr5J6G1f6fOKDqHc5ipx1zcNprz5l4GIHjg9xmft9tPbtXOrJIw7t73WQWSMewVGxOPJfnhB0jgrNuU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1606854585346592.3143152402532; Tue, 1 Dec 2020 12:29:45 -0800 (PST) Received: from localhost ([::1]:37438 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kkCHQ-0005XK-6v for importer@patchew.org; Tue, 01 Dec 2020 15:29:44 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:59406) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kkCBY-0005pF-NW for qemu-devel@nongnu.org; Tue, 01 Dec 2020 15:23:40 -0500 Received: from aserp2130.oracle.com ([141.146.126.79]:34564) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kkCBW-0000Zp-JZ for qemu-devel@nongnu.org; Tue, 01 Dec 2020 15:23:40 -0500 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0B1KF9Sv164048; Tue, 1 Dec 2020 20:23:31 GMT Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by aserp2130.oracle.com with ESMTP id 353c2avstt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 01 Dec 2020 20:23:31 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0B1KFK9C006122; Tue, 1 Dec 2020 20:23:30 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userp3030.oracle.com with ESMTP id 3540fxgynd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 01 Dec 2020 20:23:30 +0000 Received: from abhmp0020.oracle.com (abhmp0020.oracle.com [141.146.116.26]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 0B1KNSgw014675; Tue, 1 Dec 2020 20:23:29 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 01 Dec 2020 20:23:28 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : in-reply-to : references; s=corp-2020-01-29; bh=dzVASaejOf++Ig6YE+dx7DDVuyb1MSb4KBmVodGL0lw=; b=U7f4KPvykbk1+3BsaGbGaZwqb2aZjuX0/OaqJ9XVExEqjFtErECXoU1AJTt/T0IaCYss DesJdJRh9jAD0vtdmBBjeZhceuo8cgTseyGfs79Co8NJa5woHRo4uZXjKY0KO670BMuT p2SDKhaKowrAgG1VOKU5rpXY+e8Nk7YFkZC/rq5jvKp8zKcWJkc2HDnBMKlSrRU2O8yK NTg3AIzY9qi1qcezsWSRV9KU3ozh7kq1TNOtSk997i9L/aojgDE5qHMcVrrmWbN8EQdN moRpgzxz1AHJkqbBaN95u4iWXJa4Wx1Dbr7VAEZfqEgR3NdLtQ9+CldTQxkhDbZJYpis Dw== From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v12 15/19] multi-process: PCI BAR read/write handling for proxy & remote endpoints Date: Tue, 1 Dec 2020 15:22:50 -0500 Message-Id: X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: In-Reply-To: References: X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9822 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 suspectscore=1 phishscore=0 mlxlogscore=999 adultscore=0 mlxscore=0 bulkscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2012010122 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9822 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 lowpriorityscore=0 clxscore=1015 bulkscore=0 mlxlogscore=999 phishscore=0 malwarescore=0 spamscore=0 adultscore=0 mlxscore=0 priorityscore=1501 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2012010122 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=141.146.126.79; envelope-from=jag.raman@oracle.com; helo=aserp2130.oracle.com X-Spam_score_int: -58 X-Spam_score: -5.9 X-Spam_bar: ----- X-Spam_report: (-5.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.497, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, fam@euphon.net, swapnil.ingle@nutanix.com, john.g.johnson@oracle.com, kraxel@redhat.com, jag.raman@oracle.com, quintela@redhat.com, mst@redhat.com, armbru@redhat.com, kanth.ghatraju@oracle.com, felipe@nutanix.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, alex.williamson@redhat.com, stefanha@redhat.com, thanos.makatos@nutanix.com, rth@twiddle.net, kwolf@redhat.com, berrange@redhat.com, mreitz@redhat.com, ross.lagerwall@citrix.com, marcandre.lureau@gmail.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Proxy device object implements handler for PCI BAR writes and reads. The handler uses BAR_WRITE/BAR_READ message to communicate to the remote process with the BAR address and value to be written/read. The remote process implements handler for BAR_WRITE/BAR_READ message. Signed-off-by: Jagannathan Raman Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Reviewed-by: Stefan Hajnoczi --- include/hw/remote/mpqemu-link.h | 10 +++++ include/hw/remote/proxy.h | 10 +++++ hw/remote/message.c | 87 +++++++++++++++++++++++++++++++++++++= ++++ hw/remote/mpqemu-link.c | 6 +++ hw/remote/proxy.c | 60 ++++++++++++++++++++++++++++ 5 files changed, 173 insertions(+) diff --git a/include/hw/remote/mpqemu-link.h b/include/hw/remote/mpqemu-lin= k.h index 057c98b..c752738 100644 --- a/include/hw/remote/mpqemu-link.h +++ b/include/hw/remote/mpqemu-link.h @@ -36,6 +36,8 @@ typedef enum { RET_MSG, PCI_CONFIG_WRITE, PCI_CONFIG_READ, + BAR_WRITE, + BAR_READ, MPQEMU_CMD_MAX, } MPQemuCmd; =20 @@ -51,6 +53,13 @@ typedef struct { int l; } PciConfDataMsg; =20 +typedef struct { + hwaddr addr; + uint64_t val; + unsigned size; + bool memory; +} BarAccessMsg; + /** * MPQemuMsg: * @cmd: The remote command @@ -70,6 +79,7 @@ typedef struct { uint64_t u64; PciConfDataMsg pci_conf_data; SyncSysmemMsg sync_sysmem; + BarAccessMsg bar_access; } data; =20 int fds[REMOTE_MAX_FDS]; diff --git a/include/hw/remote/proxy.h b/include/hw/remote/proxy.h index 923432a..e29c61b 100644 --- a/include/hw/remote/proxy.h +++ b/include/hw/remote/proxy.h @@ -16,8 +16,17 @@ =20 #define PCI_PROXY_DEV(obj) \ OBJECT_CHECK(PCIProxyDev, (obj), TYPE_PCI_PROXY_DEV) + typedef struct PCIProxyDev PCIProxyDev; =20 +typedef struct ProxyMemoryRegion { + PCIProxyDev *dev; + MemoryRegion mr; + bool memory; + bool present; + uint8_t type; +} ProxyMemoryRegion; + struct PCIProxyDev { PCIDevice parent_dev; char *fd; @@ -31,6 +40,7 @@ struct PCIProxyDev { QemuMutex io_mutex; QIOChannel *ioc; Error *migration_blocker; + ProxyMemoryRegion region[PCI_NUM_REGIONS]; }; =20 #endif /* PROXY_H */ diff --git a/hw/remote/message.c b/hw/remote/message.c index 52a6f6f..0f3e38a 100644 --- a/hw/remote/message.c +++ b/hw/remote/message.c @@ -16,11 +16,14 @@ #include "qapi/error.h" #include "sysemu/runstate.h" #include "hw/pci/pci.h" +#include "exec/memattrs.h" =20 static void process_config_write(QIOChannel *ioc, PCIDevice *dev, MPQemuMsg *msg); static void process_config_read(QIOChannel *ioc, PCIDevice *dev, MPQemuMsg *msg); +static void process_bar_write(QIOChannel *ioc, MPQemuMsg *msg, Error **err= p); +static void process_bar_read(QIOChannel *ioc, MPQemuMsg *msg, Error **errp= ); =20 void coroutine_fn mpqemu_remote_msg_loop_co(void *data) { @@ -55,6 +58,12 @@ void coroutine_fn mpqemu_remote_msg_loop_co(void *data) case PCI_CONFIG_READ: process_config_read(com->ioc, pci_dev, &msg); break; + case BAR_WRITE: + process_bar_write(com->ioc, &msg, &local_err); + break; + case BAR_READ: + process_bar_read(com->ioc, &msg, &local_err); + break; default: error_setg(&local_err, "Unknown command (%d) received for device %s (pid= =3D%d)", @@ -122,3 +131,81 @@ static void process_config_read(QIOChannel *ioc, PCIDe= vice *dev, getpid()); } } + +static void process_bar_write(QIOChannel *ioc, MPQemuMsg *msg, Error **err= p) +{ + BarAccessMsg *bar_access =3D &msg->data.bar_access; + AddressSpace *as =3D + bar_access->memory ? &address_space_memory : &address_space_io; + MPQemuMsg ret =3D { 0 }; + MemTxResult res; + uint64_t val; + Error *local_err =3D NULL; + + if (!is_power_of_2(bar_access->size) || + (bar_access->size > sizeof(uint64_t))) { + ret.data.u64 =3D UINT64_MAX; + goto fail; + } + + val =3D cpu_to_le64(bar_access->val); + + res =3D address_space_rw(as, bar_access->addr, MEMTXATTRS_UNSPECIFIED, + (void *)&val, bar_access->size, true); + + if (res !=3D MEMTX_OK) { + error_setg(errp, "Could not perform address space write operation," + " inaccessible address: %"PRIx64" in pid %d.", + bar_access->addr, getpid()); + ret.data.u64 =3D -1; + } + +fail: + ret.cmd =3D RET_MSG; + ret.size =3D sizeof(ret.data.u64); + + mpqemu_msg_send(&ret, ioc, &local_err); + if (local_err) { + error_setg(errp, "Error while sending message to proxy " + "in remote process pid=3D%d", getpid()); + } +} + +static void process_bar_read(QIOChannel *ioc, MPQemuMsg *msg, Error **errp) +{ + BarAccessMsg *bar_access =3D &msg->data.bar_access; + MPQemuMsg ret =3D { 0 }; + AddressSpace *as; + MemTxResult res; + uint64_t val =3D 0; + Error *local_err =3D NULL; + + as =3D bar_access->memory ? &address_space_memory : &address_space_io; + + if (!is_power_of_2(bar_access->size) || + (bar_access->size > sizeof(uint64_t))) { + val =3D UINT64_MAX; + goto fail; + } + + res =3D address_space_rw(as, bar_access->addr, MEMTXATTRS_UNSPECIFIED, + (void *)&val, bar_access->size, false); + + if (res !=3D MEMTX_OK) { + error_setg(errp, "Could not perform address space read operation," + " inaccessible address: %"PRIx64" in pid %d.", + bar_access->addr, getpid()); + val =3D UINT64_MAX; + } + +fail: + ret.cmd =3D RET_MSG; + ret.data.u64 =3D le64_to_cpu(val); + ret.size =3D sizeof(ret.data.u64); + + mpqemu_msg_send(&ret, ioc, &local_err); + if (local_err) { + error_setg(errp, "Error while sending message to proxy " + "in remote process pid=3D%d", getpid()); + } +} diff --git a/hw/remote/mpqemu-link.c b/hw/remote/mpqemu-link.c index 83dbd65..ac2cb2a 100644 --- a/hw/remote/mpqemu-link.c +++ b/hw/remote/mpqemu-link.c @@ -289,6 +289,12 @@ bool mpqemu_msg_valid(MPQemuMsg *msg) return false; } break; + case BAR_WRITE: + case BAR_READ: + if ((msg->size !=3D sizeof(BarAccessMsg)) || (msg->num_fds !=3D 0)= ) { + return false; + } + break; default: break; } diff --git a/hw/remote/proxy.c b/hw/remote/proxy.c index c193484..039347d 100644 --- a/hw/remote/proxy.c +++ b/hw/remote/proxy.c @@ -147,3 +147,63 @@ static void pci_proxy_dev_register_types(void) } =20 type_init(pci_proxy_dev_register_types) + +static void send_bar_access_msg(PCIProxyDev *pdev, MemoryRegion *mr, + bool write, hwaddr addr, uint64_t *val, + unsigned size, bool memory) +{ + MPQemuMsg msg =3D { 0 }; + long ret =3D -EINVAL; + Error *local_err =3D NULL; + + msg.size =3D sizeof(BarAccessMsg); + msg.data.bar_access.addr =3D mr->addr + addr; + msg.data.bar_access.size =3D size; + msg.data.bar_access.memory =3D memory; + + if (write) { + msg.cmd =3D BAR_WRITE; + msg.data.bar_access.val =3D *val; + } else { + msg.cmd =3D BAR_READ; + } + + ret =3D mpqemu_msg_send_and_await_reply(&msg, pdev, &local_err); + if (local_err) { + error_report_err(local_err); + } + + if (!write) { + *val =3D ret; + } +} + +static void proxy_bar_write(void *opaque, hwaddr addr, uint64_t val, + unsigned size) +{ + ProxyMemoryRegion *pmr =3D opaque; + + send_bar_access_msg(pmr->dev, &pmr->mr, true, addr, &val, size, + pmr->memory); +} + +static uint64_t proxy_bar_read(void *opaque, hwaddr addr, unsigned size) +{ + ProxyMemoryRegion *pmr =3D opaque; + uint64_t val; + + send_bar_access_msg(pmr->dev, &pmr->mr, false, addr, &val, size, + pmr->memory); + + return val; +} + +const MemoryRegionOps proxy_mr_ops =3D { + .read =3D proxy_bar_read, + .write =3D proxy_bar_write, + .endianness =3D DEVICE_NATIVE_ENDIAN, + .impl =3D { + .min_access_size =3D 1, + .max_access_size =3D 8, + }, +}; --=20 1.8.3.1