From nobody Wed May 8 19:06:02 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1675696139; cv=none; d=zohomail.com; s=zohoarc; b=XVwAat/iBBUZrDRfyrjbwFBO99CWGE6POgZiyURxxRTipyklSwb8KwvaRK+LcYAyt5BeK0UoHrkadldrM4d4gTNNS94+8hRjVrcuJTOw7VHpQqEm6v2Widjn+YBSkqGs2nB1iFew/b6NX+WAHaN4Dcgm3tJ+ccJ8AGQSCakwgmc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675696139; h=Content-Type:Content-Transfer-Encoding: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=r6lRXzzomNpHB6eVTMq6TMdbZC+rcsp51zsjPhQfCIw=; b=ZCvebuIz4E+RLt7AqtYa4t1GZL2sz29CUFlz25z9M2FLJT1u10kx+OnqmOBgL2QCRxPNT33YWIbUXA8uE1MBkvYldHf4A5AYfTL9hIA+LSxRshZSTh9F2Vyv6E/a7MRD6beEo348V6NyTIaVXy7G0PWgS5LoASfJoA9QPF4moj4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 16756961399611021.2032913222412; Mon, 6 Feb 2023 07:08:59 -0800 (PST) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-609-1sN7WcslMtWGyUkZhJ8XRQ-1; Mon, 06 Feb 2023 10:08:56 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 161C129ABA01; Mon, 6 Feb 2023 15:08:48 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 039B5440DC; Mon, 6 Feb 2023 15:08:48 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 2C3A1194658D; Mon, 6 Feb 2023 15:08:37 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 5433C1946589 for ; Mon, 6 Feb 2023 15:08:30 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 292922026D38; Mon, 6 Feb 2023 15:08:30 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id C460C2026D37 for ; Mon, 6 Feb 2023 15:08:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675696139; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=r6lRXzzomNpHB6eVTMq6TMdbZC+rcsp51zsjPhQfCIw=; b=YVkJOV+osOZ19bshh+7DwkKSR4FL9SuoPeCs8Ugt+2xEUweKLoHy/pR2dzJMHW+sjj+SuR nmVAj2xerka5tbuzT9auYN4hx+IYh7yQ4KU7uVNp+sSA4WEVTmNsEmkhnMB7Zncy7Nm1pm Sl0ZfkeKCGQZQnJrcexYgcyiRvQA9Yc= X-MC-Unique: 1sN7WcslMtWGyUkZhJ8XRQ-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 1/2] virhostdevtest: Initialize hostdev @subsys Date: Mon, 6 Feb 2023 16:08:27 +0100 Message-Id: <6b4d959c24d5ca589169f7ac7725e084ca032c8d.1675696024.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1675696141640100001 Content-Type: text/plain; charset="utf-8"; x-default="true" With recent work on storing original PCI stats in _virDomainHostdevSubsysPCI struct, the virhostdevtest can across a latent bug we had. Only some parts of the virDomainHostdevSubsys structure are initialized. Incidentally, subsys->u.pci.origstates is not one of them. This lead to unexpected crashes at runtime. Signed-off-by: Michal Privoznik Reviewed-by: Martin Kletzander --- tests/virhostdevtest.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/virhostdevtest.c b/tests/virhostdevtest.c index b9e16dd4e8..92bafcbb49 100644 --- a/tests/virhostdevtest.c +++ b/tests/virhostdevtest.c @@ -123,7 +123,7 @@ myInit(void) size_t i; =20 for (i =3D 0; i < nhostdevs; i++) { - virDomainHostdevSubsys subsys; + virDomainHostdevSubsys subsys =3D {0}; hostdevs[i] =3D virDomainHostdevDefNew(); if (!hostdevs[i]) goto cleanup; --=20 2.39.1 From nobody Wed May 8 19:06:02 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1675696135; cv=none; d=zohomail.com; s=zohoarc; b=kXRJTS/UalgaZEDPty8tDHhCZXFsefafukxEx8UN/Nr4bKtjrN8m+O1S7k8UwM923bJk2x8Gm5qZNcSXgdNVZBj9zauPMo5KAEVyGc7Sb+mhdosJSZ4jk5e8qROxtuXoJlyJQ3pRuHcR0xKEdtgZkYdmMHQ02m5T8RKl+IjyJtI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675696135; h=Content-Type:Content-Transfer-Encoding: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=vUjFMdmFFrm85/UE7Nl1gtakySM5KT+nVn6i6RhkC38=; b=SyjW+TLTRvY+tphW7+sv/kAOA7CRMMI3ZBFdCmkpJU4Ae7nqaVct8AZfkCgJClImoU6vD81It16aKNiN6KgAdl3hDCWON+/IpplAO7d9byrFy+eu4ed7XSgpCpGVpPLMoAjy7ZrqaoojLTGdgUdMOPsJX5AuPUv7bpZW59ObWp4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1675696135957212.94142552523886; Mon, 6 Feb 2023 07:08:55 -0800 (PST) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-63-PU9l2-HMPtqNJLsohfAf6Q-1; Mon, 06 Feb 2023 10:08:50 -0500 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E79611C29D40; Mon, 6 Feb 2023 15:08:46 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id D3085492C3C; Mon, 6 Feb 2023 15:08:46 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id C620C19465B3; Mon, 6 Feb 2023 15:08:31 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id C2DD219465B3 for ; Mon, 6 Feb 2023 15:08:30 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id B79472026D38; Mon, 6 Feb 2023 15:08:30 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5F9812026D37 for ; Mon, 6 Feb 2023 15:08:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675696135; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=vUjFMdmFFrm85/UE7Nl1gtakySM5KT+nVn6i6RhkC38=; b=VVrmI2K2WsWosI9rTfEeRGwsl9D2RVibC9z5ziRmcrCfq9PQqjBpj2A7nRcKJAvox11LlE nMsR04EjgNCn3kro3oklisOnb/Hba2zaQpWX01XfIDApIg8gh0b/BUvqPLv1HAjdygYIbt i+iGYyGdej8zPl5gqeBg4wE1JoAhOYQ= X-MC-Unique: PU9l2-HMPtqNJLsohfAf6Q-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 2/2] virhostdevtest: Decrease possibility of uninitialized @subsys Date: Mon, 6 Feb 2023 16:08:28 +0100 Message-Id: <68f440c03bb50c9eb77b2d9ac9029277b6022451.1675696024.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1675696137844100001 Content-Type: text/plain; charset="utf-8"; x-default="true" With the current way the myInit() is written, it's fairly easy to miss initialization of @subsys variable as the variable is allocated firstly on the stack and then it's assigned to hostdev[i] which was allocated using g_new0() (this it is containing nothing but all zeroes). Make the subsys point to the corresponding member in hostdev[i] from the start. This way only the important bits are overwritten and the rest stays initialized to zero. Signed-off-by: Michal Privoznik Reviewed-by: Martin Kletzander --- tests/virhostdevtest.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/virhostdevtest.c b/tests/virhostdevtest.c index 92bafcbb49..1aed0d2b6d 100644 --- a/tests/virhostdevtest.c +++ b/tests/virhostdevtest.c @@ -123,23 +123,23 @@ myInit(void) size_t i; =20 for (i =3D 0; i < nhostdevs; i++) { - virDomainHostdevSubsys subsys =3D {0}; + virDomainHostdevSubsys *subsys; hostdevs[i] =3D virDomainHostdevDefNew(); if (!hostdevs[i]) goto cleanup; hostdevs[i]->mode =3D VIR_DOMAIN_HOSTDEV_MODE_SUBSYS; - subsys.type =3D VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI; - subsys.u.pci.addr.domain =3D 0; - subsys.u.pci.addr.bus =3D 0; - subsys.u.pci.addr.slot =3D i + 1; - subsys.u.pci.addr.function =3D 0; - subsys.u.pci.backend =3D VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO; - hostdevs[i]->source.subsys =3D subsys; + subsys =3D &hostdevs[i]->source.subsys; + subsys->type =3D VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI; + subsys->u.pci.addr.domain =3D 0; + subsys->u.pci.addr.bus =3D 0; + subsys->u.pci.addr.slot =3D i + 1; + subsys->u.pci.addr.function =3D 0; + subsys->u.pci.backend =3D VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO; } =20 for (i =3D 0; i < nhostdevs; i++) { - virDomainHostdevSubsys subsys =3D hostdevs[i]->source.subsys; - if (!(dev[i] =3D virPCIDeviceNew(&subsys.u.pci.addr))) + virDomainHostdevSubsys *subsys =3D &hostdevs[i]->source.subsys; + if (!(dev[i] =3D virPCIDeviceNew(&subsys->u.pci.addr))) goto cleanup; =20 virPCIDeviceSetStubDriver(dev[i], VIR_PCI_STUB_DRIVER_VFIO); --=20 2.39.1