From patchwork Thu Oct 19 14:47:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 735589 Delivered-To: patch@linaro.org Received: by 2002:adf:f0cd:0:b0:32d:baff:b0ca with SMTP id x13csp1557507wro; Thu, 19 Oct 2023 07:49:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHmIsMWM12Hpl+kdTAroOYHtn2XeYrJE6A3sKK3Y+XD1pvD+UblLhHAcpzCoXkrz3mqm448 X-Received: by 2002:a05:6830:3154:b0:6b9:3f64:4e8c with SMTP id c20-20020a056830315400b006b93f644e8cmr2873981ots.9.1697726949587; Thu, 19 Oct 2023 07:49:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697726949; cv=none; d=google.com; s=arc-20160816; b=D251VpNfLVrAdcl/ixjA7dl/bMjxZRSvjWWFApKBGDBrQeW9UPm4ZcLfoEYodb93wg BGm2wqjzu+f5JBfi2Wu3UVpxUp2x8iv0/xQeGayvDO6qdvIqReP5wVCDbK8MJSHGM8Hr ExYhEayDYwCctDIc+1zI38JcDLqexJm8VQe/TsRDkBhBeVPVX3FeLSRUoQCqY6p+/7G0 mDKxMdq90zAZQGQa/+Siat6LnVg1Vp9ilT+JdXATKxWXXSzjtulQAHnSt5H7NLuhsv6F F8l+sPGMAYMoLy6ITbKLKedx0Q4eV5kecSmgcnSk4xmdXMERCNi4ID169oWyTCP67nVx SkGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature; bh=nneD4HdeurggZQELllDiQ+M3+QZ2zLmj+zTEoZbm1vE=; fh=j8Eny3pWjxAkMr10+k0VrE5A9KnCJFgtOVJMNQFSSCY=; b=Mad1GmarE42Ue4n/tjnZ6gEbcVb/5DzmbPsY/7OnEthalzBAI6p9rBfmBVROWof1n7 RcKyPeflftkEd3Vj/wB6H/7JFqKO2LHdnMzUbMcR5gOEdlyBhs8TPbeYUpyn8YYao3XA OoD04vpx1xq0jdGHn+z9UXyY7pGiDpQewVz84wWrSyHT8R+QRaJySP/hs1ZMPr6ol8UB OJthdA+jGT6bHgxqLPcdAr7roUgzPBlcNLB9cZkrB7hu3jbwNsQoaxsE3U0AxitExXXr 4CcmEDrAtqDpPamMk+tsuRBiv6Y4mVr72AbUSjlH2m3zTOdRGP7bubmOXxfK7CYX/+N8 RJ8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WLVAEPfE; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id mf12-20020a0562145d8c00b0063d0e8eb3b1si1709695qvb.572.2023.10.19.07.49.09 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 19 Oct 2023 07:49:09 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WLVAEPfE; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qtUJX-0005Ps-8k; Thu, 19 Oct 2023 10:47:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qtUJV-0005KE-9v for qemu-devel@nongnu.org; Thu, 19 Oct 2023 10:47:53 -0400 Received: from mail-wm1-x333.google.com ([2a00:1450:4864:20::333]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qtUJS-0003bw-5v for qemu-devel@nongnu.org; Thu, 19 Oct 2023 10:47:53 -0400 Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-4081ccf69dcso5410055e9.0 for ; Thu, 19 Oct 2023 07:47:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1697726868; x=1698331668; darn=nongnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=nneD4HdeurggZQELllDiQ+M3+QZ2zLmj+zTEoZbm1vE=; b=WLVAEPfEd7r4FRm7SfFBzyB5chwyigvHp9FKzdZrs/5cR+JVhDPMyBrEZSrL7BE7nV w8ciGFSln7Ew4xBfUn0lsLLjngRwA/8X4G4WVzBwAI7GR2IldHCF2P23Tatgn2Z7k1O/ 7k4CCFR4f0CtLaGbhVMFWND7LSG7hQRbIMCeKeE84DUNRK2OwT0BlxvTAxvoyA9gfrB/ 3/7aO7mBDfY/Ts5NSJbrgd/Z6l9wRRuPrPd11awnTQzv61wiU6kFE5uYWMvZLj+6zhqa 524izPws8Iron9AVpmkgWNzlb8xKwY+ZYz+MLYXqkbJJDsXuc7LXkI0Hv90AfVrfJZBB GvgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697726868; x=1698331668; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=nneD4HdeurggZQELllDiQ+M3+QZ2zLmj+zTEoZbm1vE=; b=kFMxLiI08vszgVETOcZy8qg0Oay44ql3SXJllAAlJAwq/2dwtkM3pUihIAhhzMOjxm Rs7dPvsHuOiz5A69ysCEKZ7dogFjxB3yML8PpPUwEafuf4PFFASS16V/nyd4g/nIjM0l XVqoFGZG/UOsTVcMwu0euoB2pF7uS1uGTRqnEh+01T48tz6Qp/fp5XAVRyigS4RIrXTT KRxFgyX2pESsm9XBfzPVvArAqR1cElLpmSuGKbN19Je0dsdVk54NpZYeBDwd6UUmu3BR BHR0Sb2B6CBKnkP2IqF+fEfFpR4UfDS8Z4m5/u35BXnsTQYGLNdN+dPaYpmk3AuRhFd0 2iMw== X-Gm-Message-State: AOJu0YzIIZ/tQChwWewHWVj3NBA+raK7m9DuX5tGPLmn6gLVaAhqVlw9 l6U/IFtjWZWDo5La0U9TFLxDzABKQhxiO1O1LN0= X-Received: by 2002:a05:6000:102:b0:31f:a717:f1b6 with SMTP id o2-20020a056000010200b0031fa717f1b6mr2161986wrx.11.1697726868463; Thu, 19 Oct 2023 07:47:48 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id g15-20020adfe40f000000b0032d88e370basm4666883wrm.34.2023.10.19.07.47.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 07:47:48 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Cc: qemu-trivial@nongnu.org, qemu-stable@nongnu.org, Yuval Shaia , Marcel Apfelbaum , Thomas Huth , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH v2] hw/rdma/vmw/pvrdma_cmd: Use correct struct in query_port() Date: Thu, 19 Oct 2023 15:47:47 +0100 Message-Id: <20231019144747.2199130-1-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::333; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x333.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, 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 autolearn=unavailable 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org In query_port() we pass the address of a local pvrdma_port_attr struct to the rdma_query_backend_port() function. Unfortunately, rdma_backend_query_port() wants a pointer to a struct ibv_port_attr, and the two are not the same length. Coverity spotted this (CID 1507146): pvrdma_port_attr is 48 bytes long, and ibv_port_attr is 52 bytes, because it has a few extra fields at the end. Fortunately, all we do with the attrs struct after the call is to read a few specific fields out of it which are all at the same offsets in both structs, so we can simply make the local variable the correct type. This also lets us drop the cast (which should have been a bit of a warning flag that we were doing something wrong here). We do however need to add extra casts for the fields of the struct that are enums: clang will complain about the implicit cast to a different enum type otherwise. Cc: qemu-stable@nongnu.org Signed-off-by: Peter Maydell --- v2: Add explicit casts on the enum fields, and a comment about why they're OK. --- hw/rdma/vmw/pvrdma_cmd.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/hw/rdma/vmw/pvrdma_cmd.c b/hw/rdma/vmw/pvrdma_cmd.c index c6ed0259821..d385d18d9c0 100644 --- a/hw/rdma/vmw/pvrdma_cmd.c +++ b/hw/rdma/vmw/pvrdma_cmd.c @@ -129,23 +129,27 @@ static int query_port(PVRDMADev *dev, union pvrdma_cmd_req *req, { struct pvrdma_cmd_query_port *cmd = &req->query_port; struct pvrdma_cmd_query_port_resp *resp = &rsp->query_port_resp; - struct pvrdma_port_attr attrs = {}; + struct ibv_port_attr attrs = {}; if (cmd->port_num > MAX_PORTS) { return -EINVAL; } - if (rdma_backend_query_port(&dev->backend_dev, - (struct ibv_port_attr *)&attrs)) { + if (rdma_backend_query_port(&dev->backend_dev, &attrs)) { return -ENOMEM; } memset(resp, 0, sizeof(*resp)); - resp->attrs.state = dev->func0->device_active ? attrs.state : - PVRDMA_PORT_DOWN; - resp->attrs.max_mtu = attrs.max_mtu; - resp->attrs.active_mtu = attrs.active_mtu; + /* + * The state, max_mtu and active_mtu fields are enums; the values + * for pvrdma_port_state and pvrdma_mtu match those for + * ibv_port_state and ibv_mtu, so we can cast them safely. + */ + resp->attrs.state = dev->func0->device_active ? + (enum pvrdma_port_state)attrs.state : PVRDMA_PORT_DOWN; + resp->attrs.max_mtu = (enum pvrdma_mtu)attrs.max_mtu; + resp->attrs.active_mtu = (enum pvrdma_mtu)attrs.active_mtu; resp->attrs.phys_state = attrs.phys_state; resp->attrs.gid_tbl_len = MIN(MAX_PORT_GIDS, attrs.gid_tbl_len); resp->attrs.max_msg_sz = 1024;