From nobody Sat Apr 27 11:23:23 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.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=1557053822; cv=none; d=zoho.com; s=zohoarc; b=G+J7pYjY1Z/RQ2Q/UhnU0L00DcH0nBiV3BDGBPwziWGntM+zDSRW8dkXwR9r8rvdjN/GZH53nLsCV6pLijFAZIhxUSOZbrhb6JEKNlP7lGZelhf7ccydwsZoRMW6G17X8ZhofSMIhZSSJjAc66X8vst38SZ71VFduVvY64v8Wyw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557053822; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To:ARC-Authentication-Results; bh=gV1kW32mit71+wxEeBlfTg2NOTCOXntVwlzg++tFl70=; b=hj2dxQL3ZiRDNXdlwrgUH778GQHCr6UWJaHogrAI42JZEH71BUe5saLVil2N6/APYc/MRgJWkGDgvrW7p4UHWzRDLu+m3aQD9zkYjXBwt5UXTRCJPYNZ7EahdSPkoWsgTBzBcc4i2xiCOmedcdIIgpNn3fDFp8lUPUqOdXuRymg= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.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 1557053822175994.0327624223172; Sun, 5 May 2019 03:57:02 -0700 (PDT) Received: from localhost ([127.0.0.1]:39429 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNEpD-0005af-5C for importer@patchew.org; Sun, 05 May 2019 06:56:55 -0400 Received: from eggs.gnu.org ([209.51.188.92]:53206) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNEoL-0005Hr-Px for qemu-devel@nongnu.org; Sun, 05 May 2019 06:56:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hNEoJ-00026A-Rs for qemu-devel@nongnu.org; Sun, 05 May 2019 06:56:01 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:48278) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hNEoI-00025A-8r for qemu-devel@nongnu.org; Sun, 05 May 2019 06:55:59 -0400 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x45AsYRo148776; Sun, 5 May 2019 10:55:56 GMT Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2120.oracle.com with ESMTP id 2s94b0any9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 05 May 2019 10:55:56 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x45AtW9u185190; Sun, 5 May 2019 10:55:56 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserp3020.oracle.com with ESMTP id 2s9aydy62x-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 05 May 2019 10:55:55 +0000 Received: from abhmp0006.oracle.com (abhmp0006.oracle.com [141.146.116.12]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x45Atsdx004720; Sun, 5 May 2019 10:55:54 GMT Received: from host4.lan (/77.138.183.59) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Sun, 05 May 2019 10:55:54 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding; s=corp-2018-07-02; bh=gV1kW32mit71+wxEeBlfTg2NOTCOXntVwlzg++tFl70=; b=fEz/EF15f91Moh9o/UwNaQLL+nzlSIqA6Sq1E4Z7NFZ2C9pzvfl7beGqoe+MwELRGtGG 4gaB4Jn2lpbGT77zow9KqAuHV5RlW9g5nxEKvzt+OspfJB4GcjnPhXjNptX8jxEVRAD+ tmgvoSwE+31UeVRUauildAgzsKCGTjFZdeCyaKB7dYRk5chB6Odl+9o5mgU0X7H+ANib 06bbS8wg4x6shtW2EkQLhLZwTiI2e6fEXydoSgvFRjo2D348Stz5IleJt9qaiFB8PLhj K21TW4NR94NDcikktbHfIrsYp6a9lrOARZwyV1ngSp60FeGcKxPYT9SRvmvcLVX5vEg0 /w== From: Yuval Shaia To: marcel.apfelbaum@gmail.com, qemu-devel@nongnu.org Date: Sun, 5 May 2019 13:55:18 +0300 Message-Id: <20190505105518.22793-1-yuval.shaia@oracle.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9247 signatures=668686 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1905050099 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9247 signatures=668686 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1905050099 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 156.151.31.85 Subject: [Qemu-devel] [PATCH] hw/rdma: Add support for GID state changes for non-qmp frameworks 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: Yuval Shaia Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Any GID change in guest must be propogate to host. This is already done by firing QMP event to managment system such as libvirt which in turn will update the host with the relevant change. When qemu is executed on non-qmp framework (ex from command-line) we need to update the host instead. Fix it by adding support to update the RoCE device's Ethernet function IP list from qemu via netlink. Signed-off-by: Yuval Shaia --- configure | 6 ++++ hw/rdma/rdma_backend.c | 74 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 79 insertions(+), 1 deletion(-) diff --git a/configure b/configure index 5b183c2e39..1f707b1a62 100755 --- a/configure +++ b/configure @@ -3132,6 +3132,8 @@ fi =20 cat > $TMPC < +#include +#include =20 int main(void) @@ -3144,10 +3146,13 @@ main(void) } EOF =20 +pvrdma_libs=3D"-lmnl" + if test "$rdma" =3D "yes" ; then case "$pvrdma" in "") if compile_prog "" ""; then + libs_softmmu=3D"$libs_softmmu $pvrdma_libs" pvrdma=3D"yes" else pvrdma=3D"no" @@ -3156,6 +3161,7 @@ if test "$rdma" =3D "yes" ; then "yes") if ! compile_prog "" ""; then error_exit "PVRDMA is not supported since mremap is not implem= ented" + " or libmnl-devel is not installed" fi pvrdma=3D"yes" ;; diff --git a/hw/rdma/rdma_backend.c b/hw/rdma/rdma_backend.c index 05f6b03221..bc57b1a624 100644 --- a/hw/rdma/rdma_backend.c +++ b/hw/rdma/rdma_backend.c @@ -16,6 +16,11 @@ #include "qemu/osdep.h" #include "qapi/qapi-events-rdma.h" =20 +#include "linux/if_addr.h" +#include "libmnl/libmnl.h" +#include "linux/rtnetlink.h" +#include "net/if.h" + #include =20 #include "contrib/rdmacm-mux/rdmacm-mux.h" @@ -47,6 +52,61 @@ static void dummy_comp_handler(void *ctx, struct ibv_wc = *wc) rdma_error_report("No completion handler is registered"); } =20 +static int netlink_route_update(const char *ifname, union ibv_gid *gid, + __u16 type) +{ + char buf[MNL_SOCKET_BUFFER_SIZE]; + struct nlmsghdr *nlh; + struct ifaddrmsg *ifm; + struct mnl_socket *nl; + int ret; + uint32_t ipv4; + + nl =3D mnl_socket_open(NETLINK_ROUTE); + if (!nl) { + rdma_error_report("Fail to connect to netlink\n"); + return -EIO; + } + + ret =3D mnl_socket_bind(nl, 0, MNL_SOCKET_AUTOPID); + if (ret < 0) { + rdma_error_report("Fail to bind to netlink\n"); + goto out; + } + + nlh =3D mnl_nlmsg_put_header(buf); + nlh->nlmsg_type =3D type; + nlh->nlmsg_flags =3D NLM_F_REQUEST | NLM_F_CREATE | NLM_F_EXCL; + nlh->nlmsg_seq =3D 1; + + ifm =3D mnl_nlmsg_put_extra_header(nlh, sizeof(*ifm)); + ifm->ifa_index =3D if_nametoindex(ifname); + if (gid->global.subnet_prefix) { + ifm->ifa_family =3D AF_INET6; + ifm->ifa_prefixlen =3D 64; + ifm->ifa_flags =3D IFA_F_PERMANENT; + ifm->ifa_scope =3D RT_SCOPE_UNIVERSE; + mnl_attr_put(nlh, IFA_ADDRESS, sizeof(*gid), gid); + } else { + ifm->ifa_family =3D AF_INET; + ifm->ifa_prefixlen =3D 24; + memcpy(&ipv4, (char *)&gid->global.interface_id + 4, sizeof(ipv4)); + mnl_attr_put(nlh, IFA_LOCAL, 4, &ipv4); + } + + ret =3D mnl_socket_sendto(nl, nlh, nlh->nlmsg_len); + if (ret < 0) { + rdma_error_report("Fail to send msg to to netlink\n"); + goto out; + } + + ret =3D 0; + +out: + mnl_socket_close(nl); + return ret; +} + static inline void complete_work(enum ibv_wc_status status, uint32_t vendo= r_err, void *ctx) { @@ -1123,7 +1183,13 @@ int rdma_backend_add_gid(RdmaBackendDev *backend_dev= , const char *ifname, gid->global.subnet_prefix, gid->global.interface_id); =20 - return ret; + /* + * We ignore return value since operation might completed sucessfully + * by the QMP consumer + */ + netlink_route_update(ifname, gid, RTM_NEWADDR); + + return 0; } =20 int rdma_backend_del_gid(RdmaBackendDev *backend_dev, const char *ifname, @@ -1149,6 +1215,12 @@ int rdma_backend_del_gid(RdmaBackendDev *backend_dev= , const char *ifname, gid->global.subnet_prefix, gid->global.interface_id); =20 + /* + * We ignore return value since operation might completed sucessfully + * by the QMP consumer + */ + netlink_route_update(ifname, gid, RTM_DELADDR); + return 0; } =20 --=20 2.20.1