[{"id":3678840,"web_url":"http://patchwork.ozlabs.org/comment/3678840/","msgid":"<894A0EA3-66BF-4B53-B44C-EECA28D3595C@netways.de>","list_archive_url":null,"date":"2026-04-17T06:59:13","subject":"Re: [PATCH] module: fix early stop for module loading function","submitter":{"id":93178,"url":"http://patchwork.ozlabs.org/api/people/93178/","name":"Gabriel Hartmann","email":"gabriel.hartmann@netways.de"},"content":"On Wed, Apr 16, 2026 at 01:48:42PM +0000, Hector Cao wrote:\n> The commit c551fb0b53d introduces a regression on the behavior\n> of the module load logic. Historically, if QEMU cannot load a\n> particular module in a folder, it keeps going and look for the\n> module in the remaining folders. The mentioned commit make QEMU\n> stop if the module exists but cannot be loaded (build mismatch\n> reason for example).\n\nThanks for the patch, Hector. I'm the original reporter of this issue\nand have been debugging it on our OpenStack/Ceph production environment.\nThe analysis and both fixes look correct to me. One comment:\n\n> +    rv = 0; /* module not found */\n> +    for (i = 0; (i < n_dirs) && (rv != 1); i++) {\n>          char *fname = g_strdup_printf(\"%s/%s%s\",\n>                                        dirs[i], module_name,\n>  CONFIG_HOST_DSOSUF);\n>          int ret = access(fname, F_OK);\n> -        if (ret != 0 && (errno == ENOENT || errno == ENOTDIR)) {\n> -            /*\n> -             * if we don't find the module in this dir, try the next one.\n> -             * If we don't find it in any dir, that can be fine too: user\n> -             * did not install the module. We will return 0 in this case\n> -             * with no error set.\n> -             */\n> -            g_free(fname);\n> -            continue;\n> -        } else if (ret != 0) {\n> +        if ((ret == 0) && module_load_dso(fname, export_symbols, errp)) {\n> +            rv = 1; /* module successfully loaded */\n> +        }\n> +\n> +        /* The file exists but cannot be accessed -> report an error and\n> continue */\n> +        if ((ret != 0) && (errno != ENOENT) && (errno != ENOTDIR)) {\n>              /* most common is EACCES here */\n>              error_setg_errno(errp, errno, \"error trying to access %s\", fname);\n> -        } else if (module_load_dso(fname, export_symbols, errp)) {\n> -            rv = 1; /* module successfully loaded */\n>          }\n\nThe loop can trigger assert(*errp == NULL) inside error_setv() when\nerrors occur in multiple iterations.\n\nConsider: directory 1 contains the module but with a build mismatch.\nmodule_load_dso() returns false and sets *errp. The loop continues to\ndirectory 2, which either also has a mismatched module (calling\nmodule_load_dso() -> error_setg() again) or has an access error\n(calling error_setg_errno()). In both cases, *errp is already set,\nand error_setv() will hit its assert(*errp == NULL).\n\nThe error needs to be freed between iterations, for example:\n\n    rv = 0;\n    for (i = 0; (i < n_dirs) && (rv != 1); i++) {\n        char *fname = g_strdup_printf(\"%s/%s%s\",\n                                      dirs[i], module_name, CONFIG_HOST_DSOSUF);\n        int ret = access(fname, F_OK);\n        if ((ret == 0) && module_load_dso(fname, export_symbols, errp)) {\n            rv = 1;\n        }\n\n        if ((ret != 0) && (errno != ENOENT) && (errno != ENOTDIR)) {\n            error_setg_errno(errp, errno, \"error trying to access %s\", fname);\n        }\n\n        /* Clear error from this iteration before trying next directory */\n        if ((rv != 1) && *errp) {\n            error_free(*errp);\n            *errp = NULL;\n        }\n\n        g_free(fname);\n    }\n\n    /* If we exhausted all dirs without success, set a meaningful error */\n    if (rv != 1 && !*errp) {\n        error_setg(errp, \"could not load module '%s'\", module_name);\n    }\n\nAlternatively, using a local Error *local_err = NULL and only\npropagating the last error at the end would follow the common QEMU\npattern more closely.\n\n-- \nGabriel Hartmann\nSenior Systems Engineer\n\nNETWAYS Managed Services GmbH | Deutschherrnstr. 15-19 | D-90429 Nuernberg\nTel: +49 911 92885-0 | Fax: +49 911 92885-77\nCEO: Julian Hein, Bernd Erk, Sebastian Saemann | AG Nuernberg HRB25207\nhttps://www.netways.de | gabriel.hartmann@netways.de\n\n** stackconf 2026 - April | Munich - https://stackconf.eu **\n** Open Source Monitoring Conference 2026 - November | Nuremberg - https://osmc.de **\n** NETWAYS Web Services - https://nws.netways.de **\n** NETWAYS Trainings - https://netways.de/trainings **","headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=netways.de header.i=@netways.de header.a=rsa-sha256\n header.s=20241115 header.b=n+kPw+NZ;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org\n (client-ip=209.51.188.17; helo=lists1p.gnu.org;\n envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n receiver=patchwork.ozlabs.org)"],"Received":["from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17])\n\t(using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fy1Md1D8yz1yCv\n\tfor <incoming@patchwork.ozlabs.org>; Sat, 18 Apr 2026 02:59:55 +1000 (AEST)","from localhost ([::1] helo=lists1p.gnu.org)\n\tby lists1p.gnu.org with esmtp (Exim 4.90_1)\n\t(envelope-from <qemu-devel-bounces@nongnu.org>)\n\tid 1wDmXA-00011f-OL; Fri, 17 Apr 2026 12:59:12 -0400","from eggs.gnu.org ([2001:470:142:3::10])\n by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)\n (Exim 4.90_1) (envelope-from <gabriel.hartmann@netways.de>)\n id 1wDdAk-0003JM-Ow\n for qemu-devel@nongnu.org; Fri, 17 Apr 2026 02:59:27 -0400","from mail1.netways.de ([2a01:4a0:4:1002::146])\n by eggs.gnu.org with esmtps (TLS1.2:DHE_RSA_AES_128_GCM_SHA256:128)\n (Exim 4.90_1) (envelope-from <gabriel.hartmann@netways.de>)\n id 1wDdAg-00044H-NB\n for qemu-devel@nongnu.org; Fri, 17 Apr 2026 02:59:25 -0400","from exchange.int.netways.de (nethqex2.int.netways.de\n [IPv6:2a01:4a0:4:2102::112])\n (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))\n (No client certificate requested)\n by mail1.netways.de (Postfix) with ESMTPS id 4fxm2V6js4z3sSs;\n Fri, 17 Apr 2026 08:59:14 +0200 (CEST)","from nethqex1.int.netways.de (2a01:4a0:4:2102::111) by\n nethqex2.int.netways.de (2a01:4a0:4:2102::112) with Microsoft SMTP Server\n (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id\n 15.2.2562.37; Fri, 17 Apr 2026 08:59:13 +0200","from nethqex1.int.netways.de ([fe80::250:56ff:fe84:9c82]) by\n nethqex1.int.netways.de ([fe80::250:56ff:fe84:9c82%8]) with mapi id\n 15.02.2562.037; Fri, 17 Apr 2026 08:59:13 +0200"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=netways.de;\n s=20241115;\n t=1776409155;\n h=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n to:to:cc:cc:mime-version:mime-version:content-type:content-type:\n content-transfer-encoding:content-transfer-encoding:\n in-reply-to:in-reply-to:references:references;\n bh=8GMnt7XduqIPXyfLTInkhYMgqft64clwpRgfQtFO7ck=;\n b=n+kPw+NZrtUUVKrntRYG5bT07GoeDuavFvRfAHWi+NoRbrgQsY+wPiCpGmYVgEXNPZ18DD\n ud4PnEGR0IWPG70CqmRnIslOn51ckARcWkLNx7Jonao69x/z0x2lyAJJyWEjnF1H9HSRtp\n vPbnr5MaQYqeKv1d513FNH3b6bXJuIh9h70DM3+WM7cf8lslrx9uHtXmn56X95BU+wdpZg\n i/S2rpJYMDmWkL/7h8sCwC+yf+BxkLgZZoZGN49FHtyCjX0evwaxCnJ5SgEFRa5/94GkNP\n hHetG1qI8Msnkpr3BFtsTMxRpsuh+p6aDnaOUz+yXDAgvpblq9xe99bTVAbQNg==","From":"Gabriel Hartmann <gabriel.hartmann@netways.de>","To":"\"qemu-devel@nongnu.org\" <qemu-devel@nongnu.org>","CC":"\"hector.cao@canonical.com\" <hector.cao@canonical.com>","Subject":"Re: [PATCH] module: fix early stop for module loading function","Thread-Topic":"[PATCH] module: fix early stop for module loading function","Thread-Index":"AQHczjezEpcEbRRJDk6bvN4S4MrIdg==","Date":"Fri, 17 Apr 2026 06:59:13 +0000","Message-ID":"<894A0EA3-66BF-4B53-B44C-EECA28D3595C@netways.de>","References":"<20260416134842.1726474-1-hector.cao@canonical.com>","In-Reply-To":"<20260416134842.1726474-1-hector.cao@canonical.com>","Accept-Language":"en-DE, de-DE, en-US","Content-Language":"en-US","X-MS-Has-Attach":"","X-MS-TNEF-Correlator":"","x-originating-ip":"[2a02:ed80:2:0:f816:3eff:feb9:43e0]","Content-Type":"text/plain; charset=\"utf-8\"","Content-ID":"<70B009573A729340A31252D7D6DDFAA0@netways.de>","Content-Transfer-Encoding":"base64","MIME-Version":"1.0","Received-SPF":"pass client-ip=2a01:4a0:4:1002::146;\n envelope-from=gabriel.hartmann@netways.de; helo=mail1.netways.de","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,\n DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001,\n SPF_PASS=-0.001 autolearn=ham autolearn_force=no","X-Spam_action":"no action","X-Mailman-Approved-At":"Fri, 17 Apr 2026 12:59:11 -0400","X-BeenThere":"qemu-devel@nongnu.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"qemu development <qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<https://lists.nongnu.org/archive/html/qemu-devel>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n <mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org"}}]