From nobody Sat Nov 15 17:47:13 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1747909901; cv=none; d=zohomail.com; s=zohoarc; b=BmsNqFVGikgDeYbFh37LqVVUl6O+J/muVMratGI2coAwx6g9UkCKXWP0e/8RPCkQomIi0604a5hjYQaQxf4mNZfd9/a0OsF2l5z536WVyVBcS07gSe7e6zakyA9+AL9R1USpzHHV29OPhvrtbFaBIbsj+F3dBeMjFb3OWUNB130= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1747909901; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=8jfTVts1uQnnQOq04ScY/y3ND2kZkyWDQrlQ9FP3OdE=; b=L7eLV8jvMNIm8HpGizMJzr1j+HpqfmsUDJJI/XqBa+z0qFTdYVgcTRlOQl8WzPaGr5oRfjOaWNIY+qqHJEJablArzzoZJRI0IAuZsbMzN6cKAhIZ1RgIJFy2gL6pXKjYXvkslKfxmE5duAJ1MAJQgTd4hfC3Ail2150F/0CvAHk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1747909901959919.465469477944; Thu, 22 May 2025 03:31:41 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uI3BG-0002z6-KG; Thu, 22 May 2025 06:29:42 -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 1uI3BD-0002yY-KK for qemu-devel@nongnu.org; Thu, 22 May 2025 06:29:39 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uI3BB-0006MT-OZ for qemu-devel@nongnu.org; Thu, 22 May 2025 06:29:39 -0400 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-486-T5fhH__9P_2qdCk-8Tgg3Q-1; Thu, 22 May 2025 06:29:33 -0400 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 2F7411956080; Thu, 22 May 2025 10:29:32 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.179]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 32A7C1958014; Thu, 22 May 2025 10:29:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1747909776; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8jfTVts1uQnnQOq04ScY/y3ND2kZkyWDQrlQ9FP3OdE=; b=J7iGG1qem7Y76g5VWiLyp909usdKG3PvuDKgQTq8ZPs8NFm/u4A5zJY7giL59Bow3zZSpA 7WWQwA2rcq0p0BFdlnG+ozuiD+KcP3eaBaDtwHS1W/F6vBN0/fow4QZjx2BVpgs8vnK1Zo VA39Rlfyrcs7eccqWIm+DF29+0JQJus= X-MC-Unique: T5fhH__9P_2qdCk-8Tgg3Q-1 X-Mimecast-MFC-AGG-ID: T5fhH__9P_2qdCk-8Tgg3Q_1747909772 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Markus Armbruster , Paolo Bonzini , Eric Blake , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , BALATON Zoltan Subject: [PULL 01/23] ui/vnc.c: replace big endian flag with byte order value Date: Thu, 22 May 2025 11:29:01 +0100 Message-ID: <20250522102923.309452-2-berrange@redhat.com> In-Reply-To: <20250522102923.309452-1-berrange@redhat.com> References: <20250522102923.309452-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 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=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.184, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1747909902539116600 It will make it easier to do certain comparisons in future if we store G_BIG_ENDIAN/G_LITTLE_ENDIAN directly, instead of a boolean flag, as we can then compare directly to the G_BYTE_ORDER constant. Reviewed-by: BALATON Zoltan Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Daniel P. Berrang=C3=A9 --- ui/vnc-enc-tight.c | 2 +- ui/vnc-enc-zrle.c | 2 +- ui/vnc-jobs.c | 2 +- ui/vnc.c | 6 +++--- ui/vnc.h | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/ui/vnc-enc-tight.c b/ui/vnc-enc-tight.c index 41f559eb83..f8aaa8f346 100644 --- a/ui/vnc-enc-tight.c +++ b/ui/vnc-enc-tight.c @@ -150,7 +150,7 @@ tight_detect_smooth_image24(VncState *vs, int w, int h) * If client is big-endian, color samples begin from the second * byte (offset 1) of a 32-bit pixel value. */ - off =3D vs->client_be; + off =3D vs->client_endian =3D=3D G_BIG_ENDIAN ? 1 : 0; =20 memset(stats, 0, sizeof (stats)); =20 diff --git a/ui/vnc-enc-zrle.c b/ui/vnc-enc-zrle.c index bd33b89063..97ec6c7119 100644 --- a/ui/vnc-enc-zrle.c +++ b/ui/vnc-enc-zrle.c @@ -255,7 +255,7 @@ static void zrle_write_u8(VncState *vs, uint8_t value) static int zrle_send_framebuffer_update(VncState *vs, int x, int y, int w, int h) { - bool be =3D vs->client_be; + bool be =3D vs->client_endian =3D=3D G_BIG_ENDIAN; size_t bytes; int zywrle_level; =20 diff --git a/ui/vnc-jobs.c b/ui/vnc-jobs.c index fcca7ec632..d3486af9e2 100644 --- a/ui/vnc-jobs.c +++ b/ui/vnc-jobs.c @@ -188,7 +188,7 @@ static void vnc_async_encoding_start(VncState *orig, Vn= cState *local) local->lossy_rect =3D orig->lossy_rect; local->write_pixels =3D orig->write_pixels; local->client_pf =3D orig->client_pf; - local->client_be =3D orig->client_be; + local->client_endian =3D orig->client_endian; local->tight =3D orig->tight; local->zlib =3D orig->zlib; local->hextile =3D orig->hextile; diff --git a/ui/vnc.c b/ui/vnc.c index 9e097dc4b4..ab18172c4d 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -891,7 +891,7 @@ void vnc_convert_pixel(VncState *vs, uint8_t *buf, uint= 32_t v) buf[0] =3D v; break; case 2: - if (vs->client_be) { + if (vs->client_endian =3D=3D G_BIG_ENDIAN) { buf[0] =3D v >> 8; buf[1] =3D v; } else { @@ -901,7 +901,7 @@ void vnc_convert_pixel(VncState *vs, uint8_t *buf, uint= 32_t v) break; default: case 4: - if (vs->client_be) { + if (vs->client_endian =3D=3D G_BIG_ENDIAN) { buf[0] =3D v >> 24; buf[1] =3D v >> 16; buf[2] =3D v >> 8; @@ -2312,7 +2312,7 @@ static void set_pixel_format(VncState *vs, int bits_p= er_pixel, vs->client_pf.bits_per_pixel =3D bits_per_pixel; vs->client_pf.bytes_per_pixel =3D bits_per_pixel / 8; vs->client_pf.depth =3D bits_per_pixel =3D=3D 32 ? 24 : bits_per_pixel; - vs->client_be =3D big_endian_flag; + vs->client_endian =3D big_endian_flag ? G_BIG_ENDIAN : G_LITTLE_ENDIAN; =20 if (!true_color_flag) { send_color_map(vs); diff --git a/ui/vnc.h b/ui/vnc.h index acc53a2cc1..02613aa63a 100644 --- a/ui/vnc.h +++ b/ui/vnc.h @@ -323,7 +323,7 @@ struct VncState VncWritePixels *write_pixels; PixelFormat client_pf; pixman_format_code_t client_format; - bool client_be; + int client_endian; /* G_LITTLE_ENDIAN or G_BIG_ENDIAN */ =20 CaptureVoiceOut *audio_cap; struct audsettings as; --=20 2.49.0 From nobody Sat Nov 15 17:47:13 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1747910004; cv=none; d=zohomail.com; s=zohoarc; b=c3eLA1DAOejX1q3pmGXTFBttczj4nDDHYFLYaNRjvo0o8rW4e4vTnSjSFiV7Wi4ndu9G0psWO3oRaz3V6VDeRkiBlv6olIqLcetLRCzotMnhDvcAkWkisdGpsbggEUzsrIJP5On6Xy3/OIlT7zboBMRsWwsdGW8qM42clnhBZYo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1747910004; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Ap10gC6UPF4kfaH1XFvlSl7+azVePcG6UA51Fn1/tbg=; b=kkx7CB3XuN/Y+B/SklexkIF0eCrEKVRRfmZRtwetOvpZ8AMB/U+Tgb1Hqtk9vS2729jEli0TUmoFpuvsak/QkEzLcHP/uRSTadA+4sZSmRqihl4ij97V+fE3AfYmCdNWeO42zm0+MJtQHuIFCpUDLnRpIrCy6i24HHKYup66FTw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1747910004481515.711808383003; Thu, 22 May 2025 03:33:24 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uI3BI-0002zR-Bv; Thu, 22 May 2025 06:29:44 -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 1uI3BE-0002yu-Qu for qemu-devel@nongnu.org; Thu, 22 May 2025 06:29:41 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uI3BC-0006Mb-Mz for qemu-devel@nongnu.org; Thu, 22 May 2025 06:29:40 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-534-Eg7Jj7uYPjGIuNF-WhBtFg-1; Thu, 22 May 2025 06:29:36 -0400 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 862CC1800373; Thu, 22 May 2025 10:29:35 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.179]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id BD6531958014; Thu, 22 May 2025 10:29:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1747909777; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Ap10gC6UPF4kfaH1XFvlSl7+azVePcG6UA51Fn1/tbg=; b=fTTjfVRa45wFeooSMeeNpko75EhVHE4oCaHlTdcsD25qnbOSMs/f9Be4tklLi1fIXmNrun 8Iad8hb1z3xuM10MTxk5TuaZkfi/mwyDKwE90mvzNGdd5F017wOTu5gDGvClWyw/eAzK/D 7Q2ooh6NwtM3leh/FfpXYMfNaiFTkXc= X-MC-Unique: Eg7Jj7uYPjGIuNF-WhBtFg-1 X-Mimecast-MFC-AGG-ID: Eg7Jj7uYPjGIuNF-WhBtFg_1747909775 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Markus Armbruster , Paolo Bonzini , Eric Blake , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Subject: [PULL 02/23] ui/vnc: take account of client byte order in pixman format Date: Thu, 22 May 2025 11:29:02 +0100 Message-ID: <20250522102923.309452-3-berrange@redhat.com> In-Reply-To: <20250522102923.309452-1-berrange@redhat.com> References: <20250522102923.309452-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 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=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.184, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1747910005854116600 The set_pixel_conversion() method is responsible for determining whether the VNC client pixel format matches the server format, and thus whether we can use the fast path "copy" impl for sending pixels, or must use the generic impl with bit swizzling. The VNC server format is set at build time to VNC_SERVER_FB_FORMAT, which corresponds to PIXMAN_x8r8g8b8. The qemu_pixman_get_format() method is then responsible for converting the VNC pixel format into a pixman format. The VNC client pixel shifts are relative to the associated endianness. The pixman formats are always relative to the host native endianness. The qemu_pixman_get_format() method does not take into account the VNC client endianness, and is thus returning a pixman format that is only valid with the host endianness matches that of the VNC client. This has been broken since pixman was introduced to the VNC server: commit 9f64916da20eea67121d544698676295bbb105a7 Author: Gerd Hoffmann Date: Wed Oct 10 13:29:43 2012 +0200 pixman/vnc: use pixman images in vnc. The flaw can be demonstrated using the Tigervnc client by using vncviewer -AutoSelect=3D0 -PreferredEncoding=3Draw server:display connecting from a LE client to a QEMU on a BE server, or the reverse. The bug was masked, however, because almost all VNC clients will advertize support for the "tight" encoding and the QEMU VNC server will prefer "tight" if advertized. The tight_pack24 method is responsible for taking a set of pixels which have already been converted into client endianness and then repacking them into the TPIXEL format which the RFB spec defines as "TPIXEL is only 3 bytes long, where the first byte is the red component, the second byte is the green component, and the third byte is the blue component of the pixel color value" IOW, the TPIXEL format is fixed on the wire, regardless of what the VNC client declare as its endianness. Since the VNC pixel encoding code was failing to honour the endian flag of the client, the tight_pack24 method was always operating on data in native endianness. Its impl cancelled out the VNC pixel encoding bug. With the VNC pixel encoding code now fixed, the tight_pack24 method needs to take into account that it is operating on data in client endianness, not native endianness. It thus may need to invert the pixel shifts. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Daniel P. Berrang=C3=A9 --- include/ui/qemu-pixman.h | 4 ++-- ui/qemu-pixman.c | 15 ++++++++------- ui/vnc-enc-tight.c | 2 +- ui/vnc.c | 3 ++- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/include/ui/qemu-pixman.h b/include/ui/qemu-pixman.h index 193bc046d1..2ca0ed7029 100644 --- a/include/ui/qemu-pixman.h +++ b/include/ui/qemu-pixman.h @@ -75,12 +75,12 @@ PixelFormat qemu_pixelformat_from_pixman(pixman_format_= code_t format); pixman_format_code_t qemu_default_pixman_format(int bpp, bool native_endia= n); pixman_format_code_t qemu_drm_format_to_pixman(uint32_t drm_format); uint32_t qemu_pixman_to_drm_format(pixman_format_code_t pixman); -int qemu_pixman_get_type(int rshift, int gshift, int bshift); +int qemu_pixman_get_type(int rshift, int gshift, int bshift, int endian); bool qemu_pixman_check_format(DisplayChangeListener *dcl, pixman_format_code_t format); =20 #ifdef CONFIG_PIXMAN -pixman_format_code_t qemu_pixman_get_format(PixelFormat *pf); +pixman_format_code_t qemu_pixman_get_format(PixelFormat *pf, int endian); pixman_image_t *qemu_pixman_linebuf_create(pixman_format_code_t format, int width); void qemu_pixman_linebuf_fill(pixman_image_t *linebuf, pixman_image_t *fb, diff --git a/ui/qemu-pixman.c b/ui/qemu-pixman.c index 6ef4376f4e..ef4e71da11 100644 --- a/ui/qemu-pixman.c +++ b/ui/qemu-pixman.c @@ -126,33 +126,34 @@ uint32_t qemu_pixman_to_drm_format(pixman_format_code= _t pixman_format) return 0; } =20 -int qemu_pixman_get_type(int rshift, int gshift, int bshift) +int qemu_pixman_get_type(int rshift, int gshift, int bshift, int endian) { int type =3D PIXMAN_TYPE_OTHER; + bool native_endian =3D (endian =3D=3D G_BYTE_ORDER); =20 if (rshift > gshift && gshift > bshift) { if (bshift =3D=3D 0) { - type =3D PIXMAN_TYPE_ARGB; + type =3D native_endian ? PIXMAN_TYPE_ARGB : PIXMAN_TYPE_BGRA; } else { - type =3D PIXMAN_TYPE_RGBA; + type =3D native_endian ? PIXMAN_TYPE_RGBA : PIXMAN_TYPE_ABGR; } } else if (rshift < gshift && gshift < bshift) { if (rshift =3D=3D 0) { - type =3D PIXMAN_TYPE_ABGR; + type =3D native_endian ? PIXMAN_TYPE_ABGR : PIXMAN_TYPE_RGBA; } else { - type =3D PIXMAN_TYPE_BGRA; + type =3D native_endian ? PIXMAN_TYPE_BGRA : PIXMAN_TYPE_ARGB; } } return type; } =20 #ifdef CONFIG_PIXMAN -pixman_format_code_t qemu_pixman_get_format(PixelFormat *pf) +pixman_format_code_t qemu_pixman_get_format(PixelFormat *pf, int endian) { pixman_format_code_t format; int type; =20 - type =3D qemu_pixman_get_type(pf->rshift, pf->gshift, pf->bshift); + type =3D qemu_pixman_get_type(pf->rshift, pf->gshift, pf->bshift, endi= an); format =3D PIXMAN_FORMAT(pf->bits_per_pixel, type, pf->abits, pf->rbits, pf->gbits, pf->bbits); if (!pixman_format_supported_source(format)) { diff --git a/ui/vnc-enc-tight.c b/ui/vnc-enc-tight.c index f8aaa8f346..a5bdc19ebb 100644 --- a/ui/vnc-enc-tight.c +++ b/ui/vnc-enc-tight.c @@ -891,7 +891,7 @@ static void tight_pack24(VncState *vs, uint8_t *buf, si= ze_t count, size_t *ret) =20 buf8 =3D buf; =20 - if (1 /* FIXME */) { + if (vs->client_endian =3D=3D G_BYTE_ORDER) { rshift =3D vs->client_pf.rshift; gshift =3D vs->client_pf.gshift; bshift =3D vs->client_pf.bshift; diff --git a/ui/vnc.c b/ui/vnc.c index ab18172c4d..d095cd7da3 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -2240,7 +2240,8 @@ static void set_encodings(VncState *vs, int32_t *enco= dings, size_t n_encodings) =20 static void set_pixel_conversion(VncState *vs) { - pixman_format_code_t fmt =3D qemu_pixman_get_format(&vs->client_pf); + pixman_format_code_t fmt =3D qemu_pixman_get_format(&vs->client_pf, + vs->client_endian); =20 if (fmt =3D=3D VNC_SERVER_FB_FORMAT) { vs->write_pixels =3D vnc_write_pixels_copy; --=20 2.49.0 From nobody Sat Nov 15 17:47:13 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1747909931; cv=none; d=zohomail.com; s=zohoarc; b=NE54kdJNBfzzM0igXikv3DNEJDQguTsR0qnJRy/E9SM4f8jUcrW8pgfzvCrqcLjKWgUdLCA8qzPQsLorz7e4GSU/fz38o8Mkwty4NxocdHhPYHqXq5kbIEFh6qywpJ8YujwTm1OL6MIqWbxZ7vd+2ceWteyLOuZB7Uw+YD9GbN0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1747909931; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=biXxzScDBWVmE+hD/uFL07beKKlaR++rnGpBnyLbCto=; b=DVKXqqHCXKHZjLSPHRcG5k+zpLmuAJ9PYlq+2lpIouGBZztXP4CisvVY3yi/I44NTaA93vAG0rsIIyf/oNAAWWblbszQWLUlEu+Hr2xCQOaVX33A0u0mlezi2nG0mROWB8gOGCkNEdwueC+40GKmd6NPpDpJJVWFdtIKCu6d7hc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17479099311274.730536545837708; Thu, 22 May 2025 03:32:11 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uI3BK-0002zx-8p; Thu, 22 May 2025 06:29:46 -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 1uI3BI-0002zS-I3 for qemu-devel@nongnu.org; Thu, 22 May 2025 06:29:44 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uI3BG-0006N6-Q2 for qemu-devel@nongnu.org; Thu, 22 May 2025 06:29:44 -0400 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-167-MVlD0FQwNc6uMRLyrL4GWA-1; Thu, 22 May 2025 06:29:39 -0400 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id AB34E19560B5; Thu, 22 May 2025 10:29:38 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.179]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D03311958014; Thu, 22 May 2025 10:29:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1747909781; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=biXxzScDBWVmE+hD/uFL07beKKlaR++rnGpBnyLbCto=; b=BBOydzOo254S59zhMPyV5xgWJj8r5dc+XdO+9/LfST+lZGxkAr27bWcC2ayDYZxP5aHDwD +CORa9UviLwkcgN0TGzDiHGI/38ESeOikE5MBQs2nqAjqB19K5uT6IPXUZbXO+hkVhpx0M 9a/TE1BORjYX3VGEXEbaB3eNOaGAfLE= X-MC-Unique: MVlD0FQwNc6uMRLyrL4GWA-1 X-Mimecast-MFC-AGG-ID: MVlD0FQwNc6uMRLyrL4GWA_1747909778 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Markus Armbruster , Paolo Bonzini , Eric Blake , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Subject: [PULL 03/23] ui/vnc: fix tight palette pixel encoding for 8/16-bpp formats Date: Thu, 22 May 2025 11:29:03 +0100 Message-ID: <20250522102923.309452-4-berrange@redhat.com> In-Reply-To: <20250522102923.309452-1-berrange@redhat.com> References: <20250522102923.309452-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 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=170.10.129.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.184, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1747909932810116600 When sending a tight rectangle with the palette filter, if the client format was 8/16bpp, the colours on big endian hosts are not set as we're sending the wrong bytes. We must first cast the 32-bit colour to a 16/8-bit value, and then send the result. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Daniel P. Berrang=C3=A9 --- ui/vnc-enc-tight.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/ui/vnc-enc-tight.c b/ui/vnc-enc-tight.c index a5bdc19ebb..25c7b2c788 100644 --- a/ui/vnc-enc-tight.c +++ b/ui/vnc-enc-tight.c @@ -1001,16 +1001,24 @@ static int send_mono_rect(VncState *vs, int x, int = y, break; } case 2: - vnc_write(vs, &bg, 2); - vnc_write(vs, &fg, 2); + { + uint16_t bg16 =3D bg; + uint16_t fg16 =3D fg; + vnc_write(vs, &bg16, 2); + vnc_write(vs, &fg16, 2); tight_encode_mono_rect16(vs->tight->tight.buffer, w, h, bg, fg); break; + } default: - vnc_write_u8(vs, bg); - vnc_write_u8(vs, fg); + { + uint8_t bg8 =3D bg; + uint8_t fg8 =3D fg; + vnc_write_u8(vs, bg8); + vnc_write_u8(vs, fg8); tight_encode_mono_rect8(vs->tight->tight.buffer, w, h, bg, fg); break; } + } vs->tight->tight.offset =3D bytes; =20 bytes =3D tight_compress_data(vs, stream, bytes, level, Z_DEFAULT_STRA= TEGY); --=20 2.49.0 From nobody Sat Nov 15 17:47:13 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1747909878; cv=none; d=zohomail.com; s=zohoarc; b=e+QNkdXXr7Ru4sjlSYpi3DmHrG13xZ+h5f2/Vv2wPLp6LvEyloMFpfy8utLiupGcWzf2vAf/i5seWmR7swDGZu9BkZH63wGGFuiOWlX1C0qMRSIp7mgaRk0a46yGD3flISfNp3PtndD1tBR+Xfq5ciyow38/5E50jdLdJtDWcMs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1747909878; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=H1ru16hW7DCDOwAs0v+4rHKqGbQmXQDtD3+sjoRZxn4=; b=XpT6zxloczNVN/JM6qcXhEryUpV1qGd1ZUa3Ybb23gewi6ngsHa+2VDp9F0MeBnU8fwGq65owSC2BKhIF1DgQ6d49l6rkTcdXy2OW3l0q2TRFObT1gC+B3N9CUm0b6kXm3lCd4JJ8yQ/580S2xXsR8DByKHdhTFrtuPBKQeJsE4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1747909878121317.88380099669087; Thu, 22 May 2025 03:31:18 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uI3BS-000316-1t; Thu, 22 May 2025 06:29:54 -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 1uI3BP-00030P-B1 for qemu-devel@nongnu.org; Thu, 22 May 2025 06:29:51 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uI3BN-0006NX-KR for qemu-devel@nongnu.org; Thu, 22 May 2025 06:29:51 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-664-pWa7CPkuOmelubZhzTze_w-1; Thu, 22 May 2025 06:29:42 -0400 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id E0F831800570; Thu, 22 May 2025 10:29:41 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.179]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 3F4661958014; Thu, 22 May 2025 10:29:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1747909788; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=H1ru16hW7DCDOwAs0v+4rHKqGbQmXQDtD3+sjoRZxn4=; b=jS9QQ5d4J6PtOKlQfZgYrIss6IojsJNxGzgTOHFo7ZdTHpvk9l4aEsmuADksrLOjAFIib6 g97RRjKV1reTOw7Qr4ihP4dJjRF6b/kH5JrXXAFILCv6PiWC0ghWJGt7rEDlbfxuwhkybx L/Py7Rtnr9kQPpGNy1euY4tBRFgamfY= X-MC-Unique: pWa7CPkuOmelubZhzTze_w-1 X-Mimecast-MFC-AGG-ID: pWa7CPkuOmelubZhzTze_w_1747909782 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Markus Armbruster , Paolo Bonzini , Eric Blake , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Richard Henderson Subject: [PULL 04/23] tests: skip encrypted secret tests if AES is not available Date: Thu, 22 May 2025 11:29:04 +0100 Message-ID: <20250522102923.309452-5-berrange@redhat.com> In-Reply-To: <20250522102923.309452-1-berrange@redhat.com> References: <20250522102923.309452-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 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=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.184, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1747909880231116600 This avoids test breakage when we drop support for using the built-in AES impl as a fallback for missing crypto libraries. Reviewed-by: Richard Henderson Signed-off-by: Daniel P. Berrang=C3=A9 --- tests/unit/test-crypto-secret.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/tests/unit/test-crypto-secret.c b/tests/unit/test-crypto-secre= t.c index ffd13ff70e..fc32a01747 100644 --- a/tests/unit/test-crypto-secret.c +++ b/tests/unit/test-crypto-secret.c @@ -22,6 +22,7 @@ =20 #include "crypto/init.h" #include "crypto/secret.h" +#include "crypto/cipher.h" #include "qapi/error.h" #include "qemu/module.h" #if defined(CONFIG_KEYUTILS) && defined(CONFIG_SECRET_KEYRING) @@ -597,18 +598,21 @@ int main(int argc, char **argv) g_test_add_func("/crypto/secret/conv/utf8/base64", test_secret_conv_utf8_base64); =20 - g_test_add_func("/crypto/secret/crypt/raw", - test_secret_crypt_raw); - g_test_add_func("/crypto/secret/crypt/base64", - test_secret_crypt_base64); - g_test_add_func("/crypto/secret/crypt/shortkey", - test_secret_crypt_short_key); - g_test_add_func("/crypto/secret/crypt/shortiv", - test_secret_crypt_short_iv); - g_test_add_func("/crypto/secret/crypt/missingiv", - test_secret_crypt_missing_iv); - g_test_add_func("/crypto/secret/crypt/badiv", - test_secret_crypt_bad_iv); + if (qcrypto_cipher_supports(QCRYPTO_CIPHER_ALGO_AES_128, + QCRYPTO_CIPHER_MODE_CBC)) { + g_test_add_func("/crypto/secret/crypt/raw", + test_secret_crypt_raw); + g_test_add_func("/crypto/secret/crypt/base64", + test_secret_crypt_base64); + g_test_add_func("/crypto/secret/crypt/shortkey", + test_secret_crypt_short_key); + g_test_add_func("/crypto/secret/crypt/shortiv", + test_secret_crypt_short_iv); + g_test_add_func("/crypto/secret/crypt/missingiv", + test_secret_crypt_missing_iv); + g_test_add_func("/crypto/secret/crypt/badiv", + test_secret_crypt_bad_iv); + } =20 return g_test_run(); } --=20 2.49.0 From nobody Sat Nov 15 17:47:13 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1747909872; cv=none; d=zohomail.com; s=zohoarc; b=TXN61zW6ZryyquOEFHOL/ERfvGM3fPUPgInOwZ3coSpUuy/gKzYktw4EKRX/VBs8m5v/hAg9OPdBU5p2tLwlNOuCjUCHBvf/PgeNZI+ysvhHZg4mo3j+WabbWPb9kWgWxAl+1sZ+q0FgZwx2nohi5xymI4nYN/07QyVvcl7/OEQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1747909872; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=ZxpEFbLS34uMmcFhE5xzGXyMY8b1zltlu/qrjpYdh8I=; b=UNKEoJbK5dQWW3dqeSrG3bTvHlAizD/Cbb7JXBeKfbDCsCnRygXcY8twUTBtqw5Y7uVKfcjRxJi/zhKXqWYcLU2wAwFBsrSkY+s0lTbaAnTf6/8mffwPeVSOfmUGHdHaaBJAj29Ze1mXNK6Od0n0ahG51PlHRmyo9nycj/yBOhk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1747909872823274.80420924491705; Thu, 22 May 2025 03:31:12 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uI3BQ-00030l-LA; Thu, 22 May 2025 06:29:52 -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 1uI3BP-00030O-7r for qemu-devel@nongnu.org; Thu, 22 May 2025 06:29:51 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uI3BN-0006NV-KQ for qemu-devel@nongnu.org; Thu, 22 May 2025 06:29:51 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-518-dzxVuL-FMyC7ojCtk3EsgQ-1; Thu, 22 May 2025 06:29:46 -0400 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 7AF5A18004A7; Thu, 22 May 2025 10:29:45 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.179]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 7C3B01958014; Thu, 22 May 2025 10:29:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1747909787; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZxpEFbLS34uMmcFhE5xzGXyMY8b1zltlu/qrjpYdh8I=; b=L+AD+sZ0HPq9CXlqKO+rPxR4UUqUiKQDGw1vH3mLJijDw0vaO1NTAH40S67svyhFlGTDVZ j8ZQX2gU+6c2kJmR3OELbJC9kEaPOzt9TFYkukTpsWpWp03Hx1IeyBWO3vGqmFbh0lDTvZ LlSn5PC2+ygmBojC+TmJ6/Dq2/E1yAI= X-MC-Unique: dzxVuL-FMyC7ojCtk3EsgQ-1 X-Mimecast-MFC-AGG-ID: dzxVuL-FMyC7ojCtk3EsgQ_1747909785 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Markus Armbruster , Paolo Bonzini , Eric Blake , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Richard Henderson Subject: [PULL 05/23] tests: skip legacy qcow2 encryption test if AES is not available Date: Thu, 22 May 2025 11:29:05 +0100 Message-ID: <20250522102923.309452-6-berrange@redhat.com> In-Reply-To: <20250522102923.309452-1-berrange@redhat.com> References: <20250522102923.309452-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 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=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.184, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1747909874271116600 This avoids test breakage when we drop support for using the built-in AES impl as a fallback for missing crypto libraries. Reviewed-by: Richard Henderson Signed-off-by: Daniel P. Berrang=C3=A9 --- tests/unit/test-crypto-block.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/unit/test-crypto-block.c b/tests/unit/test-crypto-block.c index 9217b9a2ef..3ac7f17b2a 100644 --- a/tests/unit/test-crypto-block.c +++ b/tests/unit/test-crypto-block.c @@ -574,6 +574,13 @@ int main(int argc, char **argv) for (i =3D 0; i < G_N_ELEMENTS(test_data); i++) { if (test_data[i].open_opts->format =3D=3D QCRYPTO_BLOCK_FORMAT_LUK= S && !qcrypto_hash_supports(test_data[i].hash_alg)) { + g_printerr("# skip unsupported %s\n", + QCryptoHashAlgo_str(test_data[i].hash_alg)); + continue; + } + if (!qcrypto_cipher_supports(QCRYPTO_CIPHER_ALGO_AES_128, + QCRYPTO_CIPHER_MODE_CBC)) { + g_printerr("# skip unsupported aes-128:cbc\n"); continue; } if (!test_data[i].slow || --=20 2.49.0 From nobody Sat Nov 15 17:47:13 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1747909898; cv=none; d=zohomail.com; s=zohoarc; b=nX+sPyPhSQQKDUsW5+W/61+hy8I/M3H3u7/kfvFW8n2aeksGF9aDhnTYegs/UH7FjXq/C9eS1MLvO16hdLg6ovk/hyZ5w2UF8gPVqOYfL6UVdPLTzLrMIujdsMo9jaHgoM3eXxtvaaWaSpEOkc7f8eUYBhg1XmZiSCPlh+O0YW4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1747909898; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=XyUnMj9/H/0h1Xv5aB6MTdGPBSZaLnJUbbb38XM38Uw=; b=TW3AwTi6DGOQmyA7Nua8U9mSwuGj8VqINPxoJilbggyJaVQs/GnLY3YQzPhwEXlzJa4/sjSzkJ6gtmh/JEfXyxrU7Xo0yuQC/ta7GkBXvBXPdjMhW4c1GuAVMGoBRDzeFJ0KhmTJOpDFppY+VpytuPcmtR5f98u+gmxj6ZNR09E= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1747909898482526.2042027919335; Thu, 22 May 2025 03:31:38 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uI3BT-00031Q-77; Thu, 22 May 2025 06:29: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 1uI3BR-000311-Nr for qemu-devel@nongnu.org; Thu, 22 May 2025 06:29:53 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uI3BP-0006Ns-Us for qemu-devel@nongnu.org; Thu, 22 May 2025 06:29:53 -0400 Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-576-mlDKAfqPPOGC5jIfGfC7pg-1; Thu, 22 May 2025 06:29:49 -0400 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id D835A195608B; Thu, 22 May 2025 10:29:48 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.179]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 170801958014; Thu, 22 May 2025 10:29:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1747909791; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XyUnMj9/H/0h1Xv5aB6MTdGPBSZaLnJUbbb38XM38Uw=; b=E7CmLgZdxWTX9sKXRclO4wz2gYuH+W9KXwNH/Y6Hc7v4VPGUfyhjVpf0uiv7cnNPFtJAQ2 hDZ6REXlrFbJCRJDLzMJF/HFR96ztHZkaSQZl9UismBr+rxkiVdepN8jWv3FfLfJCOLoFc dlMC3S4q7WkvqH2Ac5UCnbPoCkTO22s= X-MC-Unique: mlDKAfqPPOGC5jIfGfC7pg-1 X-Mimecast-MFC-AGG-ID: mlDKAfqPPOGC5jIfGfC7pg_1747909789 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Markus Armbruster , Paolo Bonzini , Eric Blake , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Richard Henderson Subject: [PULL 06/23] tests: fix skipping cipher tests when AES is not available Date: Thu, 22 May 2025 11:29:06 +0100 Message-ID: <20250522102923.309452-7-berrange@redhat.com> In-Reply-To: <20250522102923.309452-1-berrange@redhat.com> References: <20250522102923.309452-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 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=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.184, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1747909900417116600 This avoid tests breakage when we drop support for using the built-in AES impl as a fallback for missing crypto libraries. Reviewed-by: Richard Henderson Signed-off-by: Daniel P. Berrang=C3=A9 --- tests/unit/test-crypto-cipher.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/tests/unit/test-crypto-cipher.c b/tests/unit/test-crypto-ciphe= r.c index b328b482e1..1331d558cf 100644 --- a/tests/unit/test-crypto-cipher.c +++ b/tests/unit/test-crypto-cipher.c @@ -828,11 +828,16 @@ int main(int argc, char **argv) } } =20 - g_test_add_func("/crypto/cipher/null-iv", - test_cipher_null_iv); + if (qcrypto_cipher_supports(QCRYPTO_CIPHER_ALGO_AES_256, + QCRYPTO_CIPHER_MODE_CBC)) { + g_test_add_func("/crypto/cipher/null-iv", + test_cipher_null_iv); =20 - g_test_add_func("/crypto/cipher/short-plaintext", - test_cipher_short_plaintext); + g_test_add_func("/crypto/cipher/short-plaintext", + test_cipher_short_plaintext); + } else { + g_printerr("# skip unsupported aes-256:cbc\n"); + } =20 return g_test_run(); } --=20 2.49.0 From nobody Sat Nov 15 17:47:13 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1747909872; cv=none; d=zohomail.com; s=zohoarc; b=MSH3GD9WHsYWicqAeUj/mh5W4OhNM35UZsDVMepCOisE+eoH7PdAAaqDxBIsCRDGPlRVZpmS2O1oJn2utMt+/FaWBACkgaAZmGwCBMcCjWwan5YX2qYLaNW2SZ9uRlLBLI6MGK3umtQyiCgDZ/OJ4VB9Rr63tXwzlhWGaQ/Uj0M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1747909872; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=e9p8hpxbfxOPrOCxKvtdg/NVtJ4xa6dRRIaWVk1vJjc=; b=V0h4AUrDd8xGGPkEDU6MrfuhuNhaBJ89nWRf9l3VoyBDa2SK/lzFtTuqx8mNrZSUieDCZl+jA4L3BJFkOcHl2/ubi2b4+MLNsMxOnStTj7hghWynMCJcxMN3jarS3P2I04nbh9jrvuJYafXtE78w89PavXEM1RgGUhso1YlMWvk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 174790987247013.689341562155619; Thu, 22 May 2025 03:31:12 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uI3Bc-00032o-4a; Thu, 22 May 2025 06:30:04 -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 1uI3BZ-00031o-4S for qemu-devel@nongnu.org; Thu, 22 May 2025 06:30:01 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uI3BW-0006PA-I2 for qemu-devel@nongnu.org; Thu, 22 May 2025 06:30:00 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-683-PnxuwjxsPymcF2vTBWarow-1; Thu, 22 May 2025 06:29:54 -0400 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 31F01180045C; Thu, 22 May 2025 10:29:53 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.179]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 5A4221958014; Thu, 22 May 2025 10:29:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1747909797; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=e9p8hpxbfxOPrOCxKvtdg/NVtJ4xa6dRRIaWVk1vJjc=; b=Zw+aN1MIRLO7SJmy5QiaPkdLn2vdtDX02Ihp7Ryoh5YZezTpmf+8nd5v5VflpPzdC545z4 wID8kgU8rZGsx3AIv5stPvZjHl3o5TqS0YYRignRzRqqZ/o96VlWXX0awax80J+vr6WD5r 7KClPSXhpqXdB+Oz3P9JAc6CIW6iWkA= X-MC-Unique: PnxuwjxsPymcF2vTBWarow-1 X-Mimecast-MFC-AGG-ID: PnxuwjxsPymcF2vTBWarow_1747909793 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Markus Armbruster , Paolo Bonzini , Eric Blake , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Richard Henderson , =?UTF-8?q?Alex=20Benn=C3=A9e?= Subject: [PULL 07/23] crypto: fully drop built-in cipher provider Date: Thu, 22 May 2025 11:29:07 +0100 Message-ID: <20250522102923.309452-8-berrange@redhat.com> In-Reply-To: <20250522102923.309452-1-berrange@redhat.com> References: <20250522102923.309452-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 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=170.10.129.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.184, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1747909874506116600 When originally creating the internal crypto cipher APIs, they were wired up to use the built-in D3DES and AES implementations, as a way to gracefully transition to the new APIs without introducing an immediate hard dep on any external crypto libraries for the VNC password auth (D3DES) or the qcow2 encryption (AES). In the 6.1.0 release we dropped the built-in D3DES impl, and also the XTS mode for the AES impl, leaving only AES with ECB/CBC modes. The rational was that with the system emulators, it is expected that 3rd party crypto libraries will be available. The qcow2 LUKS impl is preferred to the legacy raw AES impl, and by default that requires AES in XTS mode, limiting the usefulness of the built-in cipher provider. The built-in AES impl has known timing attacks and is only suitable for use cases where a security boundary is already not expected to be provided (TCG). Providing a built-in cipher impl thus potentially misleads users, should they configure a QEMU without any crypto library, and try to use it with the LUKS backend, even if that requires a non-default configuration choice. Complete what we started in 6.1.0 and purge the remaining AES support. Use of either gnutls, nettle, or libcrypt is now mandatory for any cipher support, except for TCG impls. Reviewed-by: Richard Henderson Reviewed-by: Alex Benn=C3=A9e Signed-off-by: Daniel P. Berrang=C3=A9 --- crypto/cipher-builtin.c.inc | 303 ------------------------------------ crypto/cipher-stub.c.inc | 30 ++++ crypto/cipher.c | 2 +- 3 files changed, 31 insertions(+), 304 deletions(-) delete mode 100644 crypto/cipher-builtin.c.inc create mode 100644 crypto/cipher-stub.c.inc diff --git a/crypto/cipher-builtin.c.inc b/crypto/cipher-builtin.c.inc deleted file mode 100644 index da5fcbd9a3..0000000000 --- a/crypto/cipher-builtin.c.inc +++ /dev/null @@ -1,303 +0,0 @@ -/* - * QEMU Crypto cipher built-in algorithms - * - * Copyright (c) 2015 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, see . - * - */ - -#include "crypto/aes.h" - -typedef struct QCryptoCipherBuiltinAESContext QCryptoCipherBuiltinAESConte= xt; -struct QCryptoCipherBuiltinAESContext { - AES_KEY enc; - AES_KEY dec; -}; - -typedef struct QCryptoCipherBuiltinAES QCryptoCipherBuiltinAES; -struct QCryptoCipherBuiltinAES { - QCryptoCipher base; - QCryptoCipherBuiltinAESContext key; - uint8_t iv[AES_BLOCK_SIZE]; -}; - - -static inline bool qcrypto_length_check(size_t len, size_t blocksize, - Error **errp) -{ - if (unlikely(len & (blocksize - 1))) { - error_setg(errp, "Length %zu must be a multiple of block size %zu", - len, blocksize); - return false; - } - return true; -} - -static void qcrypto_cipher_ctx_free(QCryptoCipher *cipher) -{ - g_free(cipher); -} - -static int qcrypto_cipher_no_setiv(QCryptoCipher *cipher, - const uint8_t *iv, size_t niv, - Error **errp) -{ - error_setg(errp, "Setting IV is not supported"); - return -1; -} - -static void do_aes_encrypt_ecb(const void *vctx, - size_t len, - uint8_t *out, - const uint8_t *in) -{ - const QCryptoCipherBuiltinAESContext *ctx =3D vctx; - - /* We have already verified that len % AES_BLOCK_SIZE =3D=3D 0. */ - while (len) { - AES_encrypt(in, out, &ctx->enc); - in +=3D AES_BLOCK_SIZE; - out +=3D AES_BLOCK_SIZE; - len -=3D AES_BLOCK_SIZE; - } -} - -static void do_aes_decrypt_ecb(const void *vctx, - size_t len, - uint8_t *out, - const uint8_t *in) -{ - const QCryptoCipherBuiltinAESContext *ctx =3D vctx; - - /* We have already verified that len % AES_BLOCK_SIZE =3D=3D 0. */ - while (len) { - AES_decrypt(in, out, &ctx->dec); - in +=3D AES_BLOCK_SIZE; - out +=3D AES_BLOCK_SIZE; - len -=3D AES_BLOCK_SIZE; - } -} - -static void do_aes_encrypt_cbc(const AES_KEY *key, - size_t len, - uint8_t *out, - const uint8_t *in, - uint8_t *ivec) -{ - uint8_t tmp[AES_BLOCK_SIZE]; - size_t n; - - /* We have already verified that len % AES_BLOCK_SIZE =3D=3D 0. */ - while (len) { - for (n =3D 0; n < AES_BLOCK_SIZE; ++n) { - tmp[n] =3D in[n] ^ ivec[n]; - } - AES_encrypt(tmp, out, key); - memcpy(ivec, out, AES_BLOCK_SIZE); - len -=3D AES_BLOCK_SIZE; - in +=3D AES_BLOCK_SIZE; - out +=3D AES_BLOCK_SIZE; - } -} - -static void do_aes_decrypt_cbc(const AES_KEY *key, - size_t len, - uint8_t *out, - const uint8_t *in, - uint8_t *ivec) -{ - uint8_t tmp[AES_BLOCK_SIZE]; - size_t n; - - /* We have already verified that len % AES_BLOCK_SIZE =3D=3D 0. */ - while (len) { - memcpy(tmp, in, AES_BLOCK_SIZE); - AES_decrypt(in, out, key); - for (n =3D 0; n < AES_BLOCK_SIZE; ++n) { - out[n] ^=3D ivec[n]; - } - memcpy(ivec, tmp, AES_BLOCK_SIZE); - len -=3D AES_BLOCK_SIZE; - in +=3D AES_BLOCK_SIZE; - out +=3D AES_BLOCK_SIZE; - } -} - -static int qcrypto_cipher_aes_encrypt_ecb(QCryptoCipher *cipher, - const void *in, void *out, - size_t len, Error **errp) -{ - QCryptoCipherBuiltinAES *ctx - =3D container_of(cipher, QCryptoCipherBuiltinAES, base); - - if (!qcrypto_length_check(len, AES_BLOCK_SIZE, errp)) { - return -1; - } - do_aes_encrypt_ecb(&ctx->key, len, out, in); - return 0; -} - -static int qcrypto_cipher_aes_decrypt_ecb(QCryptoCipher *cipher, - const void *in, void *out, - size_t len, Error **errp) -{ - QCryptoCipherBuiltinAES *ctx - =3D container_of(cipher, QCryptoCipherBuiltinAES, base); - - if (!qcrypto_length_check(len, AES_BLOCK_SIZE, errp)) { - return -1; - } - do_aes_decrypt_ecb(&ctx->key, len, out, in); - return 0; -} - -static int qcrypto_cipher_aes_encrypt_cbc(QCryptoCipher *cipher, - const void *in, void *out, - size_t len, Error **errp) -{ - QCryptoCipherBuiltinAES *ctx - =3D container_of(cipher, QCryptoCipherBuiltinAES, base); - - if (!qcrypto_length_check(len, AES_BLOCK_SIZE, errp)) { - return -1; - } - do_aes_encrypt_cbc(&ctx->key.enc, len, out, in, ctx->iv); - return 0; -} - -static int qcrypto_cipher_aes_decrypt_cbc(QCryptoCipher *cipher, - const void *in, void *out, - size_t len, Error **errp) -{ - QCryptoCipherBuiltinAES *ctx - =3D container_of(cipher, QCryptoCipherBuiltinAES, base); - - if (!qcrypto_length_check(len, AES_BLOCK_SIZE, errp)) { - return -1; - } - do_aes_decrypt_cbc(&ctx->key.dec, len, out, in, ctx->iv); - return 0; -} - -static int qcrypto_cipher_aes_setiv(QCryptoCipher *cipher, const uint8_t *= iv, - size_t niv, Error **errp) -{ - QCryptoCipherBuiltinAES *ctx - =3D container_of(cipher, QCryptoCipherBuiltinAES, base); - - if (niv !=3D AES_BLOCK_SIZE) { - error_setg(errp, "IV must be %d bytes not %zu", - AES_BLOCK_SIZE, niv); - return -1; - } - - memcpy(ctx->iv, iv, AES_BLOCK_SIZE); - return 0; -} - -static const struct QCryptoCipherDriver qcrypto_cipher_aes_driver_ecb =3D { - .cipher_encrypt =3D qcrypto_cipher_aes_encrypt_ecb, - .cipher_decrypt =3D qcrypto_cipher_aes_decrypt_ecb, - .cipher_setiv =3D qcrypto_cipher_no_setiv, - .cipher_free =3D qcrypto_cipher_ctx_free, -}; - -static const struct QCryptoCipherDriver qcrypto_cipher_aes_driver_cbc =3D { - .cipher_encrypt =3D qcrypto_cipher_aes_encrypt_cbc, - .cipher_decrypt =3D qcrypto_cipher_aes_decrypt_cbc, - .cipher_setiv =3D qcrypto_cipher_aes_setiv, - .cipher_free =3D qcrypto_cipher_ctx_free, -}; - -bool qcrypto_cipher_supports(QCryptoCipherAlgo alg, - QCryptoCipherMode mode) -{ - switch (alg) { - case QCRYPTO_CIPHER_ALGO_AES_128: - case QCRYPTO_CIPHER_ALGO_AES_192: - case QCRYPTO_CIPHER_ALGO_AES_256: - switch (mode) { - case QCRYPTO_CIPHER_MODE_ECB: - case QCRYPTO_CIPHER_MODE_CBC: - return true; - default: - return false; - } - break; - default: - return false; - } -} - -static QCryptoCipher *qcrypto_cipher_ctx_new(QCryptoCipherAlgo alg, - QCryptoCipherMode mode, - const uint8_t *key, - size_t nkey, - Error **errp) -{ - if (!qcrypto_cipher_validate_key_length(alg, mode, nkey, errp)) { - return NULL; - } - - switch (alg) { - case QCRYPTO_CIPHER_ALGO_AES_128: - case QCRYPTO_CIPHER_ALGO_AES_192: - case QCRYPTO_CIPHER_ALGO_AES_256: - { - QCryptoCipherBuiltinAES *ctx; - const QCryptoCipherDriver *drv; - - switch (mode) { - case QCRYPTO_CIPHER_MODE_ECB: - drv =3D &qcrypto_cipher_aes_driver_ecb; - break; - case QCRYPTO_CIPHER_MODE_CBC: - drv =3D &qcrypto_cipher_aes_driver_cbc; - break; - default: - goto bad_mode; - } - - ctx =3D g_new0(QCryptoCipherBuiltinAES, 1); - ctx->base.driver =3D drv; - - if (AES_set_encrypt_key(key, nkey * 8, &ctx->key.enc)) { - error_setg(errp, "Failed to set encryption key"); - goto error; - } - if (AES_set_decrypt_key(key, nkey * 8, &ctx->key.dec)) { - error_setg(errp, "Failed to set decryption key"); - goto error; - } - - return &ctx->base; - - error: - g_free(ctx); - return NULL; - } - - default: - error_setg(errp, - "Unsupported cipher algorithm %s", - QCryptoCipherAlgo_str(alg)); - return NULL; - } - - bad_mode: - error_setg(errp, "Unsupported cipher mode %s", - QCryptoCipherMode_str(mode)); - return NULL; -} diff --git a/crypto/cipher-stub.c.inc b/crypto/cipher-stub.c.inc new file mode 100644 index 0000000000..1b7ea81eac --- /dev/null +++ b/crypto/cipher-stub.c.inc @@ -0,0 +1,30 @@ +/* + * SPDX-License-Identifier: GPL-2.0-or-later + * + * QEMU Crypto cipher impl stub + * + * Copyright (c) 2025 Red Hat, Inc. + * + */ + +bool qcrypto_cipher_supports(QCryptoCipherAlgo alg, + QCryptoCipherMode mode) +{ + return false; +} + +static QCryptoCipher *qcrypto_cipher_ctx_new(QCryptoCipherAlgo alg, + QCryptoCipherMode mode, + const uint8_t *key, + size_t nkey, + Error **errp) +{ + if (!qcrypto_cipher_validate_key_length(alg, mode, nkey, errp)) { + return NULL; + } + + error_setg(errp, + "Unsupported cipher algorithm %s, no crypto library enabled= in build", + QCryptoCipherAlgo_str(alg)); + return NULL; +} diff --git a/crypto/cipher.c b/crypto/cipher.c index c14a8b8a11..229710f76b 100644 --- a/crypto/cipher.c +++ b/crypto/cipher.c @@ -145,7 +145,7 @@ qcrypto_cipher_validate_key_length(QCryptoCipherAlgo al= g, #elif defined CONFIG_GNUTLS_CRYPTO #include "cipher-gnutls.c.inc" #else -#include "cipher-builtin.c.inc" +#include "cipher-stub.c.inc" #endif =20 QCryptoCipher *qcrypto_cipher_new(QCryptoCipherAlgo alg, --=20 2.49.0 From nobody Sat Nov 15 17:47:13 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1747909885; cv=none; d=zohomail.com; s=zohoarc; b=N63i9uwLKIG7dvtrVKElmxdGvyesZHnddK/WJlQ3qyr34fKiRcun6xqjbTpkf//cUxi/u5kRyAB3URAhNSACWJ2S3kI5V0kk9ASoyiqk4E2gxyGij0AhLoT5076QTIuwGrl0TNLj4K//S2oz+NKuP9mNZdSEScZuOLLxyuZtzCU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1747909885; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=QlUv3WXzN1tjBcwFhwjIM/PQQRTgeOpjkK85tto1bTY=; b=dg2CWTB9raDFemq8jr2IqllPpfzygJ/E3xhAu1YOUdGbe3RgNoiqxeG+D6FfcWb9eE6S5OnsM9/ZyqbpOB3SxHmeQAZX7YDe9ILmdci1jXimywrVs5jbCptI/e5741FItCu3uvzziCr2523m5enQSHHnIPkr5mZ/QeH6DOsyIOM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1747909885461841.5701385968733; Thu, 22 May 2025 03:31:25 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uI3Bf-00033E-L0; Thu, 22 May 2025 06:30:07 -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 1uI3Bc-00032r-WF for qemu-devel@nongnu.org; Thu, 22 May 2025 06:30:05 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uI3Ba-0006PQ-Bd for qemu-devel@nongnu.org; Thu, 22 May 2025 06:30:04 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-124-PAOKFCZYPfyTwSVNlPRuWA-1; Thu, 22 May 2025 06:29:57 -0400 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A1F8D18004AD; Thu, 22 May 2025 10:29:56 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.179]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 74AB81958014; Thu, 22 May 2025 10:29:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1747909800; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QlUv3WXzN1tjBcwFhwjIM/PQQRTgeOpjkK85tto1bTY=; b=Kh8qhjr7emiqK8WPy0kDsQ0ILkMe8krrdCErNCTpszlrHdSZMQuRQJklaz6miHirwCd1i7 Y90ParLl4ohzswxfzCGGnOTiHpZRnQ1SQtEy58KpcJpqKQdB1IGkUy2nWwerw59XFyAGrq GAXfrlHUQCmI2vczmouzNY+8Cg52N6Q= X-MC-Unique: PAOKFCZYPfyTwSVNlPRuWA-1 X-Mimecast-MFC-AGG-ID: PAOKFCZYPfyTwSVNlPRuWA_1747909796 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Markus Armbruster , Paolo Bonzini , Eric Blake , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Peter Maydell , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 08/23] Revert "scripts: mandate that new files have SPDX-License-Identifier" Date: Thu, 22 May 2025 11:29:08 +0100 Message-ID: <20250522102923.309452-9-berrange@redhat.com> In-Reply-To: <20250522102923.309452-1-berrange@redhat.com> References: <20250522102923.309452-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 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=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.184, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1747909886504116600 This reverts commit fa4d79c64dae03ffa269e42e21822453856618b7. The logic in this commit was flawed in two critical ways * It always failed to report SPDX validation on the last newly added file. IOW, it only worked if at least 2 new files were added in a commit * If an existing file change, followed a new file change, in the commit and the existing file context/changed lines included SPDX-License-Identifier, it would incorrectly associate this with the previous newly added file. Simply reverting this commit will make it significantly easier to understand the improved logic in the following commit. Reported-by: Peter Maydell Reviewed-by: C=C3=A9dric Le Goater Reviewed-by: Peter Maydell Signed-off-by: Daniel P. Berrang=C3=A9 --- scripts/checkpatch.pl | 30 ------------------------------ 1 file changed, 30 deletions(-) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 365892de04..d355c0dad5 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -1442,8 +1442,6 @@ sub process { my $in_imported_file =3D 0; my $in_no_imported_file =3D 0; my $non_utf8_charset =3D 0; - my $expect_spdx =3D 0; - my $expect_spdx_file; =20 our @report =3D (); our $cnt_lines =3D 0; @@ -1681,34 +1679,6 @@ sub process { WARN("added, moved or deleted file(s), does MAINTAINERS need updating?\= n" . $herecurr); } =20 -# All new files should have a SPDX-License-Identifier tag - if ($line =3D~ /^new file mode\s*\d+\s*$/) { - if ($expect_spdx) { - if ($expect_spdx_file =3D~ - /\.(c|h|py|pl|sh|json|inc|Makefile)$/) { - # source code files MUST have SPDX license declared - ERROR("New file '$expect_spdx_file' requires " . - "'SPDX-License-Identifier'"); - } else { - # Other files MAY have SPDX license if appropriate - WARN("Does new file '$expect_spdx_file' need " . - "'SPDX-License-Identifier'?"); - } - } - $expect_spdx =3D 1; - $expect_spdx_file =3D undef; - } elsif ($expect_spdx) { - $expect_spdx_file =3D $realfile unless - defined $expect_spdx_file; - - # SPDX tags may occurr in comments which were - # stripped from '$line', so use '$rawline' - if ($rawline =3D~ /SPDX-License-Identifier/) { - $expect_spdx =3D 0; - $expect_spdx_file =3D undef; - } - } - # Check SPDX-License-Identifier references a permitted license if ($rawline =3D~ m,SPDX-License-Identifier: (.*?)(\*/)?\s*$,) { &checkspdx($realfile, $1); --=20 2.49.0 From nobody Sat Nov 15 17:47:13 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1747910017; cv=none; d=zohomail.com; s=zohoarc; b=hgvw+NV01N5/yI7Q93OtGqFTRTLNA/BTxCavTND+z92cHvACMcGWjN499liDkPHar4+IfyTp6ha1OTBoVXq+mS1R+Y6vXnKRV1XSTO3RGhXjysOP9qd3El8kQWitGgYqTBhXcQ6u2XAbu4lVFoaueXIowjtbLRAl7cB8znH0vfE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1747910017; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=NSadqX7JF7v4vi+CLTCLnCLIIM+Idk1jD2gv7AoF4PA=; b=SZQ88G6t7ot79UB4Lkv9dcE3Boz+LA5ZhqqAobdC3DXfu7G1k02gHTydLU0XLihg3q67Hc/q65W0mmNdNVHEHIk/1J8P4DFzjxWYOu/wbulAirigiZRLTOXi097R0APufhghskeLKBWbRjExE+nR54fbJEHJP3ZfXT2i0hHBOqk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1747910017380738.8598753206385; Thu, 22 May 2025 03:33:37 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uI3Bj-00034M-FB; Thu, 22 May 2025 06:30:11 -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 1uI3Bh-00033X-L4 for qemu-devel@nongnu.org; Thu, 22 May 2025 06:30:09 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uI3Be-0006bf-FH for qemu-devel@nongnu.org; Thu, 22 May 2025 06:30:08 -0400 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-280-L5mxZXFNO7iboIdCK3atpg-1; Thu, 22 May 2025 06:30:02 -0400 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 424FE1800256; Thu, 22 May 2025 10:30:00 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.179]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 3DB79195801F; Thu, 22 May 2025 10:29:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1747909805; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NSadqX7JF7v4vi+CLTCLnCLIIM+Idk1jD2gv7AoF4PA=; b=SBARdGUZLE3RqxFzJcL/a3yEySD1I9rQD60OqFRv65Nm34viUPXtT7moyB0QwIGPwf6zCj 6K2e1SM+2LwYQjYkQUU8iyklAcyr44NaU1Yvu4zE+xy8ElQEXwvVSI3U5Xn5jNhfGxG356 mHNjLErSM8NkzEBkAs0/10hRebTKitc= X-MC-Unique: L5mxZXFNO7iboIdCK3atpg-1 X-Mimecast-MFC-AGG-ID: L5mxZXFNO7iboIdCK3atpg_1747909800 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Markus Armbruster , Paolo Bonzini , Eric Blake , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Peter Maydell Subject: [PULL 09/23] scripts/checkpatch.pl: fix various indentation mistakes Date: Thu, 22 May 2025 11:29:09 +0100 Message-ID: <20250522102923.309452-10-berrange@redhat.com> In-Reply-To: <20250522102923.309452-1-berrange@redhat.com> References: <20250522102923.309452-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 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=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.184, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1747910018212116600 Various checks in the code were under-indented relative to other surrounding code. Some places used 4-space indents instead of single tab, while other places simply used too few tabs. Reviewed-by: C=C3=A9dric Le Goater Reviewed-by: Peter Maydell Signed-off-by: Daniel P. Berrang=C3=A9 --- scripts/checkpatch.pl | 101 ++++++++++++++++++++++-------------------- 1 file changed, 52 insertions(+), 49 deletions(-) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index d355c0dad5..2c19f6f0f2 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -1681,19 +1681,20 @@ sub process { =20 # Check SPDX-License-Identifier references a permitted license if ($rawline =3D~ m,SPDX-License-Identifier: (.*?)(\*/)?\s*$,) { - &checkspdx($realfile, $1); + &checkspdx($realfile, $1); } =20 if ($rawline =3D~ m,(SPDX-[a-zA-Z0-9-_]+):,) { - my $tag =3D $1; - my @permitted =3D qw( - SPDX-License-Identifier - ); - - unless (grep { /^$tag$/ } @permitted) { - ERROR("Tag $tag not permitted in QEMU code, valid " . - "choices are: " . join(", ", @permitted)); - } + my $tag =3D $1; + my @permitted =3D qw( + SPDX-License-Identifier + ); + + unless (grep { /^$tag$/ } @permitted) { + ERROR("Tag $tag not permitted in QEMU code, " . + "valid choices are: " . + join(", ", @permitted)); + } } =20 # Check for wrappage within a valid hunk of the file @@ -2274,7 +2275,7 @@ sub process { =20 # missing space after union, struct or enum definition if ($line =3D~ /^.\s*(?:typedef\s+)?(enum|union|struct)(?:\s+$Ident)?(?:= \s+$Ident)?[=3D\{]/) { - ERROR("missing space after $1 definition\n" . $herecurr); + ERROR("missing space after $1 definition\n" . $herecurr); } =20 # check for spacing round square brackets; allowed: @@ -2569,7 +2570,7 @@ sub process { =20 if ($line =3D~ /^.\s*(Q(?:S?LIST|SIMPLEQ|TAILQ)_HEAD)\s*\(\s*[^,]/ && $line !~ /^.typedef/) { - ERROR("named $1 should be typedefed separately\n" . $herecurr); + ERROR("named $1 should be typedefed separately\n" . $herecurr); } =20 # Need a space before open parenthesis after if, while etc @@ -3118,48 +3119,50 @@ sub process { =20 # Qemu error function tests =20 - # Find newlines in error messages - my $qemu_error_funcs =3D qr{error_setg| - error_setg_errno| - error_setg_win32| - error_setg_file_open| - error_set| - error_prepend| - warn_reportf_err| - error_reportf_err| - error_vreport| - warn_vreport| - info_vreport| - error_report| - warn_report| - info_report| - g_test_message}x; - - if ($rawline =3D~ /\b(?:$qemu_error_funcs)\s*\(.*\".*\\n/) { - ERROR("Error messages should not contain newlines\n" . $herecurr); - } + # Find newlines in error messages + my $qemu_error_funcs =3D qr{error_setg| + error_setg_errno| + error_setg_win32| + error_setg_file_open| + error_set| + error_prepend| + warn_reportf_err| + error_reportf_err| + error_vreport| + warn_vreport| + info_vreport| + error_report| + warn_report| + info_report| + g_test_message}x; + + if ($rawline =3D~ /\b(?:$qemu_error_funcs)\s*\(.*\".*\\n/) { + ERROR("Error messages should not contain newlines\n" . $herecurr); + } =20 - # Continue checking for error messages that contains newlines. This - # check handles cases where string literals are spread over multiple line= s. - # Example: - # error_report("Error msg line #1" - # "Error msg line #2\n"); - my $quoted_newline_regex =3D qr{\+\s*\".*\\n.*\"}; - my $continued_str_literal =3D qr{\+\s*\".*\"}; + # Continue checking for error messages that contains newlines. + # This check handles cases where string literals are spread + # over multiple lines. + # Example: + # error_report("Error msg line #1" + # "Error msg line #2\n"); + my $quoted_newline_regex =3D qr{\+\s*\".*\\n.*\"}; + my $continued_str_literal =3D qr{\+\s*\".*\"}; =20 - if ($rawline =3D~ /$quoted_newline_regex/) { - # Backtrack to first line that does not contain only a quoted literal - # and assume that it is the start of the statement. - my $i =3D $linenr - 2; + if ($rawline =3D~ /$quoted_newline_regex/) { + # Backtrack to first line that does not contain only + # a quoted literal and assume that it is the start + # of the statement. + my $i =3D $linenr - 2; =20 - while (($i >=3D 0) & $rawlines[$i] =3D~ /$continued_str_literal/) { - $i--; - } + while (($i >=3D 0) & $rawlines[$i] =3D~ /$continued_str_literal/) { + $i--; + } =20 - if ($rawlines[$i] =3D~ /\b(?:$qemu_error_funcs)\s*\(/) { - ERROR("Error messages should not contain newlines\n" . $herecurr); + if ($rawlines[$i] =3D~ /\b(?:$qemu_error_funcs)\s*\(/) { + ERROR("Error messages should not contain newlines\n" . $herecurr); + } } - } =20 # check for non-portable libc calls that have portable alternatives in QEMU if ($line =3D~ /\bffs\(/) { --=20 2.49.0 From nobody Sat Nov 15 17:47:13 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1747909915; cv=none; d=zohomail.com; s=zohoarc; b=WSXwlXCVLkXI12muERSAV8PUUFJ4qT69RI9+gQh2Ny8EQMd9L4Dyercgr0G/x6mDZ1Bt7/2y3jpNjHIqTTdrQIKqJhSb2LVwqHYs/CUjaWog3tOQhuvfaXlcSkzN0YwK+WwZq4kSSXXinK8TGOQPTc3aRbkF5ofmipx1Akoi8fs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1747909915; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=uTWc2uEJKIdMwUEEtwdUZJgeePM924WrG63gPuY07qk=; b=HQDirn31k95/hm3Ic+I1E2W5qCOJkWds6gniGpLPDBsdT/TZ5KR8RlrsmHGMthWAe1ikri0Oexjc240E/RvLW/qqEebpNzn9GJyQvfH+EYDA6VW+5RO9wjSlOZbozHqhli0pJOgGVfFCNmYRYzMxxNYorYcI391dkZSQhbrJeoQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1747909915407278.6868389908516; Thu, 22 May 2025 03:31:55 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uI3Bm-00036b-4K; Thu, 22 May 2025 06:30:14 -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 1uI3Bj-000357-R4 for qemu-devel@nongnu.org; Thu, 22 May 2025 06:30:11 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uI3Bh-0006bz-H7 for qemu-devel@nongnu.org; Thu, 22 May 2025 06:30:11 -0400 Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-97-E7YYqfvXO0el1s7NS6wXCQ-1; Thu, 22 May 2025 06:30:05 -0400 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 22609195608A; Thu, 22 May 2025 10:30:04 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.179]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id B55AD1958014; Thu, 22 May 2025 10:30:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1747909808; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uTWc2uEJKIdMwUEEtwdUZJgeePM924WrG63gPuY07qk=; b=HAcby9MfZzBz2V+MJjQ0qzmabTpP/LB3yQMOP73mqCQbKgaPpFRcuJddMbu4zt0rYd5c8d OL94sIJQcVRFO560jU7DxoIGunjvXJttFQYvHNoKCV0K7S7IG+FuzItEqKhQYmYsXMVIlE K2dyeW1BcxmBLv/uG40NhsPP2PZgaXA= X-MC-Unique: E7YYqfvXO0el1s7NS6wXCQ-1 X-Mimecast-MFC-AGG-ID: E7YYqfvXO0el1s7NS6wXCQ_1747909804 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Markus Armbruster , Paolo Bonzini , Eric Blake , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Peter Maydell Subject: [PULL 10/23] scripts/checkpatch: introduce tracking of file start/end Date: Thu, 22 May 2025 11:29:10 +0100 Message-ID: <20250522102923.309452-11-berrange@redhat.com> In-Reply-To: <20250522102923.309452-1-berrange@redhat.com> References: <20250522102923.309452-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 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=170.10.129.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.184, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1747909916857116600 Some checks want to be performed either at the start of a new file within a patch, or at the end. This is complicated by the fact that the information relevant to the check may be spread across multiple lines. It is further complicated by a need to support both git and non-git diffs, and special handling for renames where there might not be any patch hunks. To handle this more sanely, introduce explicit tracking of file start/end, taking account of git metadata, and calling a hook function at each transition. Reviewed-by: C=C3=A9dric Le Goater Reviewed-by: Peter Maydell Signed-off-by: Daniel P. Berrang=C3=A9 --- scripts/checkpatch.pl | 110 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 107 insertions(+), 3 deletions(-) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 2c19f6f0f2..bb3830d693 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -1417,6 +1417,39 @@ sub checkspdx { } } =20 +# All three of the methods below take a 'file info' record +# which is a hash ref containing +# +# 'isgit': 1 if an enhanced git diff or 0 for a plain diff +# 'githeader': 1 if still parsing git patch header, 0 otherwise +# 'linestart': line number of start of file diff +# 'lineend': line number of end of file diff +# 'filenew': the new filename +# 'fileold': the old filename (same as 'new filename' except +# for renames in git diffs) +# 'action': one of 'modified' (always) or 'new' or 'deleted' or +# 'renamed' (git diffs only) +# 'mode': file mode for new/deleted files (git diffs only) +# 'similarity': file similarity when renamed (git diffs only) +# 'facts': hash ref for storing any metadata related to checks +# + +# Called at the end of each patch, with the list of +# real filenames that were seen in the patch +sub process_file_list { + my @fileinfos =3D @_; +} + +# Called at the start of processing a diff hunk for a file +sub process_start_of_file { + my $fileinfo =3D shift; +} + +# Called at the end of processing a diff hunk for a file +sub process_end_of_file { + my $fileinfo =3D shift; +} + sub process { my $filename =3D shift; =20 @@ -1453,7 +1486,10 @@ sub process { my $realfile =3D ''; my $realline =3D 0; my $realcnt =3D 0; + my $fileinfo; + my @fileinfolist; my $here =3D ''; + my $oldhere =3D ''; my $in_comment =3D 0; my $comment_edge =3D 0; my $first_line =3D 0; @@ -1591,17 +1627,56 @@ sub process { $prefix =3D "$filename:$realline: " if ($emacs && $file); $prefix =3D "$filename:$linenr: " if ($emacs && !$file); =20 + $oldhere =3D $here; $here =3D "#$linenr: " if (!$file); $here =3D "#$realline: " if ($file); =20 # extract the filename as it passes - if ($line =3D~ /^diff --git.*?(\S+)$/) { - $realfile =3D $1; - $realfile =3D~ s@^([^/]*)/@@ if (!$file); + if ($line =3D~ /^diff --git\s+(\S+)\s+(\S+)$/) { + my $fileold =3D $1; + my $filenew =3D $2; + + if (defined $fileinfo) { + $fileinfo->{lineend} =3D $oldhere; + process_end_of_file($fileinfo) + } + $fileold =3D~ s@^([^/]*)/@@ if (!$file); + $filenew =3D~ s@^([^/]*)/@@ if (!$file); + $realfile =3D $filenew; checkfilename($realfile, \$acpi_testexpected, \$acpi_nont= estexpected); + + $fileinfo =3D { + "isgit" =3D> 1, + "githeader" =3D> 1, + "linestart" =3D> $here, + "lineend" =3D> 0, + "fileold" =3D> $fileold, + "filenew" =3D> $filenew, + "action" =3D> "modified", + "mode" =3D> 0, + "similarity" =3D> 0, + "facts" =3D> {}, + }; + push @fileinfolist, $fileinfo; + } elsif (defined $fileinfo && $fileinfo->{githeader} && + $line =3D~ /^(new|deleted) (?:file )?mode\s+([0-7]+)$/) { + $fileinfo->{action} =3D $1; + $fileinfo->{mode} =3D oct($2); + } elsif (defined $fileinfo && $fileinfo->{githeader} && + $line =3D~ /^similarity index (\d+)%/) { + $fileinfo->{similarity} =3D int($1); + } elsif (defined $fileinfo && $fileinfo->{githeader} && + $line =3D~ /^rename (from|to) [\w\/\.\-]+\s*$/) { + $fileinfo->{action} =3D "renamed"; + # For a no-change rename, we'll never have any "+++..." + # lines, so trigger actions now + if ($1 eq "to" && $fileinfo->{similarity} =3D=3D 100) { + process_start_of_file($fileinfo); + } } elsif ($line =3D~ /^\+\+\+\s+(\S+)/) { $realfile =3D $1; $realfile =3D~ s@^([^/]*)/@@ if (!$file); + checkfilename($realfile, \$acpi_testexpected, \$acpi_nont= estexpected); =20 $p1_prefix =3D $1; @@ -1610,6 +1685,30 @@ sub process { WARN("patch prefix '$p1_prefix' exists, appears to be a -p0 patch\n"); } =20 + if (defined $fileinfo && !$fileinfo->{isgit}) { + $fileinfo->{lineend} =3D $oldhere; + process_end_of_file($fileinfo); + } + + if (!defined $fileinfo || !$fileinfo->{isgit}) { + $fileinfo =3D { + "isgit" =3D> 0, + "githeader" =3D> 0, + "linestart" =3D> $here, + "lineend" =3D> 0, + "fileold" =3D> $realfile, + "filenew" =3D> $realfile, + "action" =3D> "modified", + "mode" =3D> 0, + "similarity" =3D> 0, + "facts" =3D> {}, + }; + push @fileinfolist, $fileinfo; + } else { + $fileinfo->{githeader} =3D 0; + } + process_start_of_file($fileinfo); + next; } =20 @@ -3216,6 +3315,11 @@ sub process { } } =20 + if (defined $fileinfo) { + process_end_of_file($fileinfo); + } + process_file_list(@fileinfolist); + if ($is_patch && $chk_signoff && $signoff =3D=3D 0) { ERROR("Missing Signed-off-by: line(s)\n"); } --=20 2.49.0 From nobody Sat Nov 15 17:47:13 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1747909900; cv=none; d=zohomail.com; s=zohoarc; b=VSnBoT91Rwqt0Qbuhcnqu2jLYRYI0TL+gGj+V+BTA5xtHZkcsnctNwdih4oyT/QcW47EQPAcZqsKbDLBbY0Tor75YEZpt6D0g68nTXtZwiV1gz7NV5LemaYnUZ4+arK1At9u/VL6t85Fl7QCCzhoOVBv+WZsuEiLP4VwOAsUq4c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1747909900; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=7RHGTHSIhQTbT0iiYyRt5/E9dPk7/JScP2mfBlnObQw=; b=aPCZYMYEyDFtpSYf77XNfn6GAPhvq1rbIl92rWPr+tAmMM9MwyLlxy1lcPwchI5diRNkKF3+nZCEm3111I4VEpjajSqU4QSXUU2zeSY7Js7FRUCNiSdOjFd5TJF4m0VxFu0/AsdRa2HaVQUQ6QtzRVjPfXNV8S2mUSWE412LL5U= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1747909900470196.27869489156058; Thu, 22 May 2025 03:31:40 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uI3Bq-000393-9N; Thu, 22 May 2025 06:30:18 -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 1uI3Bn-00038G-Us for qemu-devel@nongnu.org; Thu, 22 May 2025 06:30:16 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uI3Bl-0006cG-9u for qemu-devel@nongnu.org; Thu, 22 May 2025 06:30:15 -0400 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-255-jdixMz4fOJur6bPzkjHO0Q-1; Thu, 22 May 2025 06:30:08 -0400 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 8911319560B5; Thu, 22 May 2025 10:30:07 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.179]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 98D161958014; Thu, 22 May 2025 10:30:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1747909809; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7RHGTHSIhQTbT0iiYyRt5/E9dPk7/JScP2mfBlnObQw=; b=I5XzrY6qHs7jogIjISYBiYWM5X+lWzbV77+MtQZJv7RFJMm30FIHKVtLnPvB5DRUlaPbo7 6LzKGmNoJUp6pwka6qQul/0emly6xEvfYtY6uPXWn8D85WC1NhQsQ3BpJSxvjPvYLINWcB kNSCVZ6sBN8YWi3KvHE/ZtlRyOTX9+Q= X-MC-Unique: jdixMz4fOJur6bPzkjHO0Q-1 X-Mimecast-MFC-AGG-ID: jdixMz4fOJur6bPzkjHO0Q_1747909807 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Markus Armbruster , Paolo Bonzini , Eric Blake , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Peter Maydell Subject: [PULL 11/23] scripts/checkpatch: use new hook for ACPI test data check Date: Thu, 22 May 2025 11:29:11 +0100 Message-ID: <20250522102923.309452-12-berrange@redhat.com> In-Reply-To: <20250522102923.309452-1-berrange@redhat.com> References: <20250522102923.309452-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 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=170.10.129.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.184, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1747909902595116600 The ACPI test data check needs to analyse a list of all files in a commit, so can use the new hook for processing the file list. Reviewed-by: Peter Maydell Signed-off-by: Daniel P. Berrang=C3=A9 --- scripts/checkpatch.pl | 61 ++++++++++++++++++++----------------------- 1 file changed, 29 insertions(+), 32 deletions(-) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index bb3830d693..817df98231 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -1330,29 +1330,6 @@ sub WARN { } } =20 -# According to tests/qtest/bios-tables-test.c: do not -# change expected file in the same commit with adding test -sub checkfilename { - my ($name, $acpi_testexpected, $acpi_nontestexpected) =3D @_; - - # Note: shell script that rebuilds the expected files is in the sa= me - # directory as files themselves. - # Note: allowed diff list can be changed both when changing expect= ed - # files and when changing tests. - if ($name =3D~ m#^tests/data/acpi/# and not $name =3D~ m#^\.sh$#) { - $$acpi_testexpected =3D $name; - } elsif ($name !~ m#^tests/qtest/bios-tables-test-allowed-diff.h$#) { - $$acpi_nontestexpected =3D $name; - } - if (defined $$acpi_testexpected and defined $$acpi_nontestexpected) { - ERROR("Do not add expected files together with tests, " . - "follow instructions in " . - "tests/qtest/bios-tables-test.c: both " . - $$acpi_testexpected . " and " . - $$acpi_nontestexpected . " found\n"); - } -} - sub checkspdx { my ($file, $expr) =3D @_; =20 @@ -1438,6 +1415,34 @@ sub checkspdx { # real filenames that were seen in the patch sub process_file_list { my @fileinfos =3D @_; + + # According to tests/qtest/bios-tables-test.c: do not + # change expected file in the same commit with adding test + my @acpi_testexpected; + my @acpi_nontestexpected; + + foreach my $fileinfo (@fileinfos) { + # Note: shell script that rebuilds the expected files is in + # the same directory as files themselves. + # Note: allowed diff list can be changed both when changing + # expected files and when changing tests. + if ($fileinfo->{filenew} =3D~ m#^tests/data/acpi/# && + $fileinfo->{filenew} !~ m#^\.sh$#) { + push @acpi_testexpected, $fileinfo->{filenew}; + } elsif ($fileinfo->{filenew} !~ + m#^tests/qtest/bios-tables-test-allowed-diff.h$#) { + push @acpi_nontestexpected, $fileinfo->{filenew}; + } + } + if (int(@acpi_testexpected) > 0 and int(@acpi_nontestexpected) > 0) { + ERROR("Do not add expected files together with tests, " . + "follow instructions in " . + "tests/qtest/bios-tables-test.c. Files\n\n " . + join("\n ", @acpi_testexpected) . + "\n\nand\n\n " . + join("\n ", @acpi_nontestexpected) . + "\n\nfound in the same patch\n"); + } } =20 # Called at the start of processing a diff hunk for a file @@ -1502,9 +1507,6 @@ sub process { my %suppress_whiletrailers; my %suppress_export; =20 - my $acpi_testexpected; - my $acpi_nontestexpected; - # Pre-scan the patch sanitizing the lines. =20 sanitise_line_reset(); @@ -1643,7 +1645,6 @@ sub process { $fileold =3D~ s@^([^/]*)/@@ if (!$file); $filenew =3D~ s@^([^/]*)/@@ if (!$file); $realfile =3D $filenew; - checkfilename($realfile, \$acpi_testexpected, \$acpi_nont= estexpected); =20 $fileinfo =3D { "isgit" =3D> 1, @@ -1677,8 +1678,6 @@ sub process { $realfile =3D $1; $realfile =3D~ s@^([^/]*)/@@ if (!$file); =20 - checkfilename($realfile, \$acpi_testexpected, \$acpi_nont= estexpected); - $p1_prefix =3D $1; if (!$file && $tree && $p1_prefix ne '' && -e "$root/$p1_prefix") { @@ -1771,9 +1770,7 @@ sub process { $line =3D~ /^rename (?:from|to) [\w\/\.\-]+\s*$/ || ($line =3D~ /\{\s*([\w\/\.\-]*)\s*\=3D\>\s*([\w\/\.\-]*)\s*\}/ && (defined($1) || defined($2)))) && - !(($realfile ne '') && - defined($acpi_testexpected) && - ($realfile eq $acpi_testexpected))) { + $realfile !~ m#^tests/data/acpi/#) { $reported_maintainer_file =3D 1; WARN("added, moved or deleted file(s), does MAINTAINERS need updating?\= n" . $herecurr); } --=20 2.49.0 From nobody Sat Nov 15 17:47:13 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1747909977; cv=none; d=zohomail.com; s=zohoarc; b=fNEms8FVNzWfdmqIoGCnwy3nk3u+nePJJ5N530jBF/dnfyZF8RzRbmTdef3B7aDFn0s1DpM2ljTWJLg3o82slustmdxsW9WWuhGWH75udGDAbyxbhiBahYpFiH8LknW2BrxrNttuHz6tCMsZnRSqI5eo9gSHVNABAMGHfE0w7nU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1747909977; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=IbbIsrmYqzBf/pcS4JhraC6Fa/Yn5do/AQdr/9z95P8=; b=cuKv9ImqfnoHxbGT4pfsC6UU3wxKvPrr3D9+xm5oR6Cc7NY1l0LsibWiVT9NJZIZU5+pRF3wM06vwumb0XSobiRs10Fq7NHXqfjJsqSQw6IeGfLqur5Ez+fhn8JMld/vBXgavdP0a6vBHr2Y83nd45HsCEHtyxcjRyDXRik0RG0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17479099775611022.2942565019964; Thu, 22 May 2025 03:32:57 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uI3Bs-0003AU-Tw; Thu, 22 May 2025 06:30:21 -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 1uI3Br-000392-6H for qemu-devel@nongnu.org; Thu, 22 May 2025 06:30:19 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uI3Bo-0006cs-5t for qemu-devel@nongnu.org; Thu, 22 May 2025 06:30:17 -0400 Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-252-4ycuZalKPIyzlZofpUHnuQ-1; Thu, 22 May 2025 06:30:12 -0400 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 00DCC19560AE; Thu, 22 May 2025 10:30:11 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.179]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 01FE51958014; Thu, 22 May 2025 10:30:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1747909815; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IbbIsrmYqzBf/pcS4JhraC6Fa/Yn5do/AQdr/9z95P8=; b=DtfYkINpTXe6FNkAhpqCSBH3UCy10DZek0A0HhRfTvmones9E0I6ApllcHoEfim35WG4yq XDeu7P0yZBRDlQutCSk3og+FWLZ86d2LiYi1dcntqNMR8N1aRlPomcE4l1t3LtpD5gZU3G 8thccy/6DnwW2ZSlQZ7nH0pT27w3omY= X-MC-Unique: 4ycuZalKPIyzlZofpUHnuQ-1 X-Mimecast-MFC-AGG-ID: 4ycuZalKPIyzlZofpUHnuQ_1747909811 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Markus Armbruster , Paolo Bonzini , Eric Blake , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Peter Maydell Subject: [PULL 12/23] scripts/checkpatch: use new hook for file permissions check Date: Thu, 22 May 2025 11:29:12 +0100 Message-ID: <20250522102923.309452-13-berrange@redhat.com> In-Reply-To: <20250522102923.309452-1-berrange@redhat.com> References: <20250522102923.309452-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 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=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.184, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1747909979465116600 The file permissions check is the kind of check intended to be performed in the new start of file hook. Reviewed-by: C=C3=A9dric Le Goater Reviewed-by: Peter Maydell Signed-off-by: Daniel P. Berrang=C3=A9 --- scripts/checkpatch.pl | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 817df98231..881dcac29b 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -1448,6 +1448,17 @@ sub process_file_list { # Called at the start of processing a diff hunk for a file sub process_start_of_file { my $fileinfo =3D shift; + + # Check for incorrect file permissions + if ($fileinfo->{action} eq "new" && ($fileinfo->{mode} & 0111)) { + my $permhere =3D $fileinfo->{linestart} . "FILE: " . + $fileinfo->{filenew} . "\n"; + if ($fileinfo->{filenew} =3D~ + /(\bMakefile(?:\.objs)?|\.(c|cc|cpp|h|mak|s|S))$/) { + ERROR("do not set execute permissions for source " . + "files\n" . $permhere); + } + } } =20 # Called at the end of processing a diff hunk for a file @@ -1719,14 +1730,6 @@ sub process { =20 $cnt_lines++ if ($realcnt !=3D 0); =20 -# Check for incorrect file permissions - if ($line =3D~ /^new (file )?mode.*[7531]\d{0,2}$/) { - my $permhere =3D $here . "FILE: $realfile\n"; - if ($realfile =3D~ /(\bMakefile(?:\.objs)?|\.c|\.cc|\.cpp|\.h|\.mak|\.[= sS])$/) { - ERROR("do not set execute permissions for source files\n" . $permhere); - } - } - # Only allow Python 3 interpreter if ($realline =3D=3D 1 && $line =3D~ /^\+#!\ *\/usr\/bin\/(?:env )?python$/) { --=20 2.49.0 From nobody Sat Nov 15 17:47:13 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1747909928; cv=none; d=zohomail.com; s=zohoarc; b=RnPNxuUyOdYimmliebbNO/wxd3tXF9P2pxjuKokxy08Uo3knnLIUDCZGKsnj3GBvTdQDZLIqCfUo1QJuNfk5xcOKucasCSgvmTM1ogQasfXIuB4l6i1NBsj/d3NEQhBC5OTXQndsnqGeGGFaWT4mADqnmBUki04a+vCbj9pbG0I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1747909928; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=UubmKbpvSmyR3eE673UXh5T78kpLeKhgcFJtHfX49Mk=; b=VoZGXGpfM5aHICtXp8MN5K82wVhWoSTmPlVWnSk0s3bpSOCVoEu6je/oChd1n2sZD2qqaVFXkZOqoUL3ltPH1qHkoVsN25Vql7UvOIrWOTGej9oYYa/rjLLFDH5E0XrpKVjkbdQo8NgpmuKD4hY1QkG9OGo/aCRE7DyDjXXn2cg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1747909928230844.0457093470088; Thu, 22 May 2025 03:32:08 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uI3Bw-0003B5-Oz; Thu, 22 May 2025 06:30:24 -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 1uI3Bv-0003Ar-3p for qemu-devel@nongnu.org; Thu, 22 May 2025 06:30:23 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uI3Bt-0006dK-3y for qemu-devel@nongnu.org; Thu, 22 May 2025 06:30:22 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-519-WEuZzYxsM8-V9rL48SHskQ-1; Thu, 22 May 2025 06:30:16 -0400 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 4911F180036F; Thu, 22 May 2025 10:30:15 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.179]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id F42201958014; Thu, 22 May 2025 10:30:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1747909820; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UubmKbpvSmyR3eE673UXh5T78kpLeKhgcFJtHfX49Mk=; b=jKPXb470OHypoC+gveidOPEjOrvHC10juqnda9X5LCdrlQ+xDN6IhnG2k3Y5Ok8i1K+ZAV SFCPEXTE3f1SbRpSJuEoYvswoqHyj7qAH7Qz2Qtuu81NhZiss3Z5oVqIHuNfXt06BtcHXX XiYqxsrKWdhExBcn7McjH2TobO0ScX0= X-MC-Unique: WEuZzYxsM8-V9rL48SHskQ-1 X-Mimecast-MFC-AGG-ID: WEuZzYxsM8-V9rL48SHskQ_1747909815 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Markus Armbruster , Paolo Bonzini , Eric Blake , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Peter Maydell Subject: [PULL 13/23] scripts/checkpatch: expand pattern for matching makefiles Date: Thu, 22 May 2025 11:29:13 +0100 Message-ID: <20250522102923.309452-14-berrange@redhat.com> In-Reply-To: <20250522102923.309452-1-berrange@redhat.com> References: <20250522102923.309452-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 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=170.10.129.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.184, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1747909928862116600 The current regex matches Makefile & Makefile.objs, but the latter is no longer used, anjd we're missing coverage of Makefile.include and Makefile.target. Expand the pattern to match any suffix. Reviewed-by: C=C3=A9dric Le Goater Reviewed-by: Peter Maydell Signed-off-by: Daniel P. Berrang=C3=A9 --- scripts/checkpatch.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 881dcac29b..82ec71e05d 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -1454,7 +1454,7 @@ sub process_start_of_file { my $permhere =3D $fileinfo->{linestart} . "FILE: " . $fileinfo->{filenew} . "\n"; if ($fileinfo->{filenew} =3D~ - /(\bMakefile(?:\.objs)?|\.(c|cc|cpp|h|mak|s|S))$/) { + /(\bMakefile.*|\.(c|cc|cpp|h|mak|s|S))$/) { ERROR("do not set execute permissions for source " . "files\n" . $permhere); } --=20 2.49.0 From nobody Sat Nov 15 17:47:13 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1747909870; cv=none; d=zohomail.com; s=zohoarc; b=Lm1WMOMymxGeb/PciXO2Pi77LfV2p3K8Kt439a+aZuCNURXi6UH/+/aLKNR0jY/XkBQBpxoBsPmo1ipW5eHzJE35AYSffLUcEB3vrIDgLkcnC0VE3WbloiD+wafd79t+CyK6ITlG0/iSWiAsevGIZ3oZ5BGXRo1Ewthi4hVWkzo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1747909870; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=/KSIReOtCXI9OAmTNpxHjWOwdW11sGtW+E03elYeBeQ=; b=K4J/F4zhQ8rwaRZ1JTfyompbDbu1AjfjXSSg6YbYoyvym420Fjc6xM7oK+uwF46OlfNBImTC8mkWIGnq03JM9nAIvIcyU0RzvN4dkXt8MnxqAh0Cw+1jvTvzB8gfPymu8vpzjsRouEBRoCTQIov7mokJqt5PWT/XV4bscp4Gcx0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1747909870126117.80927652974856; Thu, 22 May 2025 03:31:10 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uI3C1-0003CJ-3y; Thu, 22 May 2025 06:30:29 -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 1uI3Bz-0003BW-Do for qemu-devel@nongnu.org; Thu, 22 May 2025 06:30:27 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uI3Bx-0006da-H6 for qemu-devel@nongnu.org; Thu, 22 May 2025 06:30:27 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-552-dAfYL1_4Nde_jfbvT_USPQ-1; Thu, 22 May 2025 06:30:20 -0400 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 489E3180087F; Thu, 22 May 2025 10:30:19 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.179]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D95621958014; Thu, 22 May 2025 10:30:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1747909823; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/KSIReOtCXI9OAmTNpxHjWOwdW11sGtW+E03elYeBeQ=; b=gja5f3UID3fgKdAwID3vfe4WbKk2b+tmVj/hopR3pIbcOxW71JY1o8wn5nVX1OYvy82Qrk OrMbRDH0UWDAuulSkyRdMDXy4NY7GSdq/7jgmpQG8Axo0WH7SvcLonrLkOjpVX5vLXl8hU XgxDl07+wMzzAsmctrR0w1xzv8F9M7c= X-MC-Unique: dAfYL1_4Nde_jfbvT_USPQ-1 X-Mimecast-MFC-AGG-ID: dAfYL1_4Nde_jfbvT_USPQ_1747909819 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Markus Armbruster , Paolo Bonzini , Eric Blake , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Peter Maydell Subject: [PULL 14/23] scripts/checkpatch: use new hook for MAINTAINERS update check Date: Thu, 22 May 2025 11:29:14 +0100 Message-ID: <20250522102923.309452-15-berrange@redhat.com> In-Reply-To: <20250522102923.309452-1-berrange@redhat.com> References: <20250522102923.309452-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 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=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.184, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1747909872159116600 When seeing a new/deleted/renamed file we check to see if MAINTAINERS is updated, but we don't give the user a list of files affected, as we don't want to repeat the same warning many times over. Using the new file list hook, we can give a single warning at the end with a list of filenames included. Reviewed-by: C=C3=A9dric Le Goater Reviewed-by: Peter Maydell Signed-off-by: Daniel P. Berrang=C3=A9 --- scripts/checkpatch.pl | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 82ec71e05d..c05559a108 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -1443,6 +1443,25 @@ sub process_file_list { join("\n ", @acpi_nontestexpected) . "\n\nfound in the same patch\n"); } + + my $sawmaintainers =3D 0; + my @maybemaintainers; + foreach my $fileinfo (@fileinfos) { + if ($fileinfo->{action} ne "modified" && + $fileinfo->{filenew} !~ m#^tests/data/acpi/#) { + push @maybemaintainers, $fileinfo->{filenew}; + } + if ($fileinfo->{filenew} eq "MAINTAINERS") { + $sawmaintainers =3D 1; + } + } + + # If we don't see a MAINTAINERS update, prod the user to check + if (int(@maybemaintainers) > 0 && !$sawmaintainers) { + WARN("added, moved or deleted file(s):\n\n " . + join("\n ", @maybemaintainers) . + "\n\nDoes MAINTAINERS need updating?\n"); + } } =20 # Called at the start of processing a diff hunk for a file @@ -1486,7 +1505,6 @@ sub process { =20 my $in_header_lines =3D $file ? 0 : 1; my $in_commit_log =3D 0; #Scanning lines before patch - my $reported_maintainer_file =3D 0; my $reported_mixing_imported_file =3D 0; my $in_imported_file =3D 0; my $in_no_imported_file =3D 0; @@ -1761,23 +1779,6 @@ sub process { } } =20 -# Check if MAINTAINERS is being updated. If so, there's probably no need = to -# emit the "does MAINTAINERS need updating?" message on file add/move/dele= te - if ($line =3D~ /^\s*MAINTAINERS\s*\|/) { - $reported_maintainer_file =3D 1; - } - -# Check for added, moved or deleted files - if (!$reported_maintainer_file && !$in_commit_log && - ($line =3D~ /^(?:new|deleted) file mode\s*\d+\s*$/ || - $line =3D~ /^rename (?:from|to) [\w\/\.\-]+\s*$/ || - ($line =3D~ /\{\s*([\w\/\.\-]*)\s*\=3D\>\s*([\w\/\.\-]*)\s*\}/ && - (defined($1) || defined($2)))) && - $realfile !~ m#^tests/data/acpi/#) { - $reported_maintainer_file =3D 1; - WARN("added, moved or deleted file(s), does MAINTAINERS need updating?\= n" . $herecurr); - } - # Check SPDX-License-Identifier references a permitted license if ($rawline =3D~ m,SPDX-License-Identifier: (.*?)(\*/)?\s*$,) { &checkspdx($realfile, $1); --=20 2.49.0 From nobody Sat Nov 15 17:47:13 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1747910018; cv=none; d=zohomail.com; s=zohoarc; b=CG/8L47BntaRBUCnrTL3DCPZYBrIIcQMYk6pq+qpSZMxvD4E7jn7Vn0z/ioGWNwev2cpF7kgZsyTWDhcMyNM7CC2CWTnvF3FeeTBXPafA9wIMRGewUw1c52NFMdTbc7nk9RRGKYLGgogkkS6WinNAoNE8hdWqyxj7FkZBvgSRZY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1747910018; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=UA4cTGi+Lc/4+DoQqkYqbsXU1LB2JteeJLHXJiUGT/U=; b=KgxsLAbFuNdqKa8AxRn4dJn/hz+YwfRDvpg5BYbka6CCcmDSuekyiwaMBIlhJqnvUuMRtqLTaD3N+NqKDTKgsjdlbnyxQAfyv9TWAdht0D1d7S118/CHl9I4vVz0SnDIvStUBpqbfSdmEF/WWK0ELywCihqC9W+vly8vfniVgLg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1747910018551584.7818774280104; Thu, 22 May 2025 03:33:38 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uI3C5-0003FB-Is; Thu, 22 May 2025 06:30:33 -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 1uI3C3-0003EM-G0 for qemu-devel@nongnu.org; Thu, 22 May 2025 06:30:31 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uI3C1-0006dy-Ic for qemu-devel@nongnu.org; Thu, 22 May 2025 06:30:31 -0400 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-660-Ak7YZXCvMx-xZMstpwX8gw-1; Thu, 22 May 2025 06:30:25 -0400 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 344B418007E1; Thu, 22 May 2025 10:30:24 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.179]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id BEE461958019; Thu, 22 May 2025 10:30:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1747909828; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UA4cTGi+Lc/4+DoQqkYqbsXU1LB2JteeJLHXJiUGT/U=; b=ReE1pElLY7UrHz2Fw6JmWx3HtUvvT6U8hPNgK356NxUy33AGxkqF+M4Y/zita7h0do0lCN LBUpeoImyNkvN6SfaSUKTfVAbVpzMA1dYgs3uNU1SrrO4eG84lllbQq6QOjLY91NibTi6S b0dSNekXNt5aDl0L5emFYU/6C/vG2ME= X-MC-Unique: Ak7YZXCvMx-xZMstpwX8gw-1 X-Mimecast-MFC-AGG-ID: Ak7YZXCvMx-xZMstpwX8gw_1747909824 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Markus Armbruster , Paolo Bonzini , Eric Blake , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Peter Maydell Subject: [PULL 15/23] scripts/checkpatch: reimplement mandate for SPDX-License-Identifier Date: Thu, 22 May 2025 11:29:15 +0100 Message-ID: <20250522102923.309452-16-berrange@redhat.com> In-Reply-To: <20250522102923.309452-1-berrange@redhat.com> References: <20250522102923.309452-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 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=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.184, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1747910019867116600 Going forward we want all newly created source files to have an SPDX-License-Identifier tag present. Initially mandate this for C, Python, Perl, Shell source files, as well as JSON (QAPI) and Makefiles, while encouraging users to consider it for other file types. The new attempt at detecting missing SPDX-License-Identifier relies on the hooks for relying triggering logic at the end of scanning a new file in the diff. Tested-by: C=C3=A9dric Le Goater Reviewed-by: C=C3=A9dric Le Goater Reviewed-by: Peter Maydell Signed-off-by: Daniel P. Berrang=C3=A9 --- scripts/checkpatch.pl | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index c05559a108..da13102eda 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -1483,6 +1483,20 @@ sub process_start_of_file { # Called at the end of processing a diff hunk for a file sub process_end_of_file { my $fileinfo =3D shift; + + if ($fileinfo->{action} eq "new" && + !exists $fileinfo->{facts}->{sawspdx}) { + if ($fileinfo->{filenew} =3D~ + /(\.(c|h|py|pl|sh|json|inc)|Makefile.*)$/) { + # source code files MUST have SPDX license declared + ERROR("New file '" . $fileinfo->{filenew} . + "' requires 'SPDX-License-Identifier'"); + } else { + # Other files MAY have SPDX license if appropriate + WARN("Does new file '" . $fileinfo->{filenew} . + "' need 'SPDX-License-Identifier'?"); + } + } } =20 sub process { @@ -1781,6 +1795,7 @@ sub process { =20 # Check SPDX-License-Identifier references a permitted license if ($rawline =3D~ m,SPDX-License-Identifier: (.*?)(\*/)?\s*$,) { + $fileinfo->{facts}->{sawspdx} =3D 1; &checkspdx($realfile, $1); } =20 --=20 2.49.0 From nobody Sat Nov 15 17:47:13 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1747909932; cv=none; d=zohomail.com; s=zohoarc; b=CSPq99LVBc8hAdP/E2UHy1YA9H5EV2RFf9lMWU30XjhYDbHxoJ5ohyqpI4drtpIXsP3lhmy8g9q3LeP2bT1e9Aus0Kg3i85dc7I3d3yO8gRuRyX+7mJOApgX5VNPW7rVX17NC5DLe9KW03W1SOc5usEMp+zwMtU5PtyaXxXR0xw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1747909932; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=YeVGPqqBG6X5kTXB75qnLsL0StBNE9cX70oHLqpo4kI=; b=PBoDg/OwBchdJmt4CtAK/naq5PZZ4MeU2JeHgmTnPoPhtgFcauioePjU+l5gpZaw7KTm4N0Z5eZQtXUceei883N9omhXbEVUaKkvS3yiCyzHTIs+WA0Pi1Myc15RwQ9N6PRMecuPn/xS2hel6l23YnxSdF2fMLJJr8GtVgMAGZo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1747909932212953.9628362637272; Thu, 22 May 2025 03:32:12 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uI3CD-0003Lt-V4; Thu, 22 May 2025 06:30:42 -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 1uI3C7-0003FY-P3 for qemu-devel@nongnu.org; Thu, 22 May 2025 06:30:36 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uI3C5-0006eD-CE for qemu-devel@nongnu.org; Thu, 22 May 2025 06:30:35 -0400 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-17-ZHxpZ2i8MzKZ9hOapG9i8Q-1; Thu, 22 May 2025 06:30:28 -0400 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C2A0018003FC; Thu, 22 May 2025 10:30:27 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.179]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id C2FF01958014; Thu, 22 May 2025 10:30:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1747909831; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YeVGPqqBG6X5kTXB75qnLsL0StBNE9cX70oHLqpo4kI=; b=PkhwbSJx8Icx2DCAyXodAYtsAnHVE5N6Qf0DgcQUvLE96p9kvQBT2HrPNSfnXca46h2TPx Ubz7qjPajNi/rmkb4pUnOoXndtYwVDzTzkn/7OZavrj8yeGed/lKAfVwmi9niS/W4y17tR MrcrVyVii7i9/UVWMkI9dI37p77gml8= X-MC-Unique: ZHxpZ2i8MzKZ9hOapG9i8Q-1 X-Mimecast-MFC-AGG-ID: ZHxpZ2i8MzKZ9hOapG9i8Q_1747909827 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Markus Armbruster , Paolo Bonzini , Eric Blake , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Peter Maydell , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 16/23] scripts/checkpatch: reject license boilerplate on new files Date: Thu, 22 May 2025 11:29:16 +0100 Message-ID: <20250522102923.309452-17-berrange@redhat.com> In-Reply-To: <20250522102923.309452-1-berrange@redhat.com> References: <20250522102923.309452-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 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=170.10.129.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.184, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1747909932855116600 The previous commit mandates use of SPDX-License-Identifier on common source files, and encourages it on all other files. Some contributors are none the less still also including the license boilerplate text. This is redundant and will potentially cause trouble if inconsistent with the SPDX declaration. Match common boilerplate text blurbs and report them as invalid, for newly added files. Reviewed-by: Peter Maydell Reviewed-by: C=C3=A9dric Le Goater Signed-off-by: Daniel P. Berrang=C3=A9 --- scripts/checkpatch.pl | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index da13102eda..9291bc9209 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -365,6 +365,18 @@ our @typeList =3D ( qr{guintptr}, ); =20 +# Match text found in common license boilerplate comments: +# for new files the SPDX-License-Identifier line is sufficient. +our @LICENSE_BOILERPLATE =3D ( + "licensed under the terms of the GNU GPL", + "under the terms of the GNU General Public License", + "under the terms of the GNU Lesser General Public", + "Permission is hereby granted, free of charge", + "GNU GPL, version 2 or later", + "See the COPYING file" +); +our $LICENSE_BOILERPLATE_RE =3D join("|", @LICENSE_BOILERPLATE); + # Load common spelling mistakes and build regular expression list. my $misspellings; my %spelling_fix; @@ -1497,6 +1509,13 @@ sub process_end_of_file { "' need 'SPDX-License-Identifier'?"); } } + if ($fileinfo->{action} eq "new" && + exists $fileinfo->{facts}->{sawboilerplate}) { + ERROR("New file '" . $fileinfo->{filenew} . "' must " . + "not have license boilerplate header text, only " . + "the SPDX-License-Identifier, unless this file was " . + "copied from existing code already having such text."); + } } =20 sub process { @@ -1799,6 +1818,10 @@ sub process { &checkspdx($realfile, $1); } =20 + if ($rawline =3D~ /$LICENSE_BOILERPLATE_RE/) { + $fileinfo->{facts}->{sawboilerplate} =3D 1; + } + if ($rawline =3D~ m,(SPDX-[a-zA-Z0-9-_]+):,) { my $tag =3D $1; my @permitted =3D qw( --=20 2.49.0 From nobody Sat Nov 15 17:47:13 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1747909980; cv=none; d=zohomail.com; s=zohoarc; b=Dn2IjiXY7dSfoyE7DyFa7SEHCn8lPcLNj3fnauUmuvgNQPVGPDQEp0w7NkAsv2t3ckoCBb72eMn8uXuDRu6Y2fGhiheTtjh5qLIvP5o1uVj2SQkP67nOMIywRw7kn2SW5KPuA3CMZNgyNL+S3c98Bi+arZz2rn0i3dIhcRzEs4s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1747909980; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=yQNziEu5Fj9POumjoD3nKCDjlCm27YhHDF1NDBvBs5M=; b=PB/55Npm/GglHeyb9suwm01l8NpSFVdQ6//2L3KfkajTpvX38P/GtTXPKmJnN2xuG8Hd+ocFmLrWZ20sKei4jjQjgbSuAKpUVU/r+ZPzQEofeIkGHH9BsgQW5GmyD0jhrEIm7Qz/NXrwmHx2JFm94FKHr5ud+ehYHmmrNHqbLOE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1747909980301817.319055879875; Thu, 22 May 2025 03:33:00 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uI3CT-0003jo-0q; Thu, 22 May 2025 06:30:57 -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 1uI3CB-0003Qu-Lp for qemu-devel@nongnu.org; Thu, 22 May 2025 06:30:41 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uI3C6-0006eM-VB for qemu-devel@nongnu.org; Thu, 22 May 2025 06:30:38 -0400 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-462-gOmYWhcqPc6UOApYrE21dQ-1; Thu, 22 May 2025 06:30:32 -0400 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 437D51800264; Thu, 22 May 2025 10:30:31 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.179]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 5D7131958014; Thu, 22 May 2025 10:30:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1747909833; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yQNziEu5Fj9POumjoD3nKCDjlCm27YhHDF1NDBvBs5M=; b=icfSfwEJW6K7XnVdJlw68knnE7f94+akyVmzTbao8bUAvgS/CnxJRqt4gds57HdotYB+rX osa3t3+tz5UDBJ/n0pEeZaa5Oznpgy6jH+OUIlK6cuZAQNwyqcMTuB+Dq/xyxqsAW5n5Z+ jqOxXRTVacAnLzK/sWXqG1fNd6eoLms= X-MC-Unique: gOmYWhcqPc6UOApYrE21dQ-1 X-Mimecast-MFC-AGG-ID: gOmYWhcqPc6UOApYrE21dQ_1747909831 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Markus Armbruster , Paolo Bonzini , Eric Blake , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Juraj Marcin Subject: [PULL 17/23] io: Fix partial struct copy in qio_dns_resolver_lookup_sync_inet() Date: Thu, 22 May 2025 11:29:17 +0100 Message-ID: <20250522102923.309452-18-berrange@redhat.com> In-Reply-To: <20250522102923.309452-1-berrange@redhat.com> References: <20250522102923.309452-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 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=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.184, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1747909981518116600 From: Juraj Marcin Commit aec21d3175 (qapi: Add InetSocketAddress member keep-alive) introduces the keep-alive flag, but this flag is not copied together with other options in qio_dns_resolver_lookup_sync_inet(). This patch fixes this issue and also prevents future ones by copying the entire structure first and only then overriding a few attributes that need to be different. Fixes: aec21d31756c (qapi: Add InetSocketAddress member keep-alive) Signed-off-by: Juraj Marcin Reviewed-by: Daniel P. Berrang=C3=A9 Signed-off-by: Daniel P. Berrang=C3=A9 --- io/dns-resolver.c | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/io/dns-resolver.c b/io/dns-resolver.c index 53b0e8407a..3712438f82 100644 --- a/io/dns-resolver.c +++ b/io/dns-resolver.c @@ -111,22 +111,11 @@ static int qio_dns_resolver_lookup_sync_inet(QIODNSRe= solver *resolver, uaddr, INET6_ADDRSTRLEN, uport, 32, NI_NUMERICHOST | NI_NUMERICSERV); =20 - newaddr->u.inet =3D (InetSocketAddress){ - .host =3D g_strdup(uaddr), - .port =3D g_strdup(uport), - .has_numeric =3D true, - .numeric =3D true, - .has_to =3D iaddr->has_to, - .to =3D iaddr->to, - .has_ipv4 =3D iaddr->has_ipv4, - .ipv4 =3D iaddr->ipv4, - .has_ipv6 =3D iaddr->has_ipv6, - .ipv6 =3D iaddr->ipv6, -#ifdef HAVE_IPPROTO_MPTCP - .has_mptcp =3D iaddr->has_mptcp, - .mptcp =3D iaddr->mptcp, -#endif - }; + newaddr->u.inet =3D *iaddr; + newaddr->u.inet.host =3D g_strdup(uaddr), + newaddr->u.inet.port =3D g_strdup(uport), + newaddr->u.inet.has_numeric =3D true, + newaddr->u.inet.numeric =3D true, =20 (*addrs)[i] =3D newaddr; } --=20 2.49.0 From nobody Sat Nov 15 17:47:13 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1747909978; cv=none; d=zohomail.com; s=zohoarc; b=A0yTJALCa9L3LU+Ss9rdDn+fxrY1j64YsVPkCbtXDiV7kjSy2KPWkUa5C+T34oFo7p8kFkQZbFTLdiRSR6xt7wDnkrb9NYrbeBjhP5vIHAZIkxPBmqxJgeELjse/dw0Mwb6ZwCdtUUI9UWC4UPMi05n4l201xl8gp8xAaV8OeJI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1747909978; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=LT8u+Odh24aw54w1xRgnLKb526I+ZLroJYzIr5dgjt0=; b=kE4AJUg5EET1hw2MosNOXtKA7Y2jamjDgTNw3T+GjE+lGQIOcwm36g/Ruzb1IYpzr76picBheTJOytvSDEfFt9WTfu7WxEe8aaJw4jntSHc4hl0OlQ2gAGv/ZkLoxwXpXLsu4a/ggNKrXzu3oz5fDnx/5FlKUtpi0F8A0GUsAIg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17479099789881012.1798777978325; Thu, 22 May 2025 03:32:58 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uI3Ca-0004Kg-0Q; Thu, 22 May 2025 06:31:04 -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 1uI3CI-0003i2-GU for qemu-devel@nongnu.org; Thu, 22 May 2025 06:30:49 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uI3CC-0006f6-SY for qemu-devel@nongnu.org; Thu, 22 May 2025 06:30:43 -0400 Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-160-pupDLAsnPiKQYTOEDWEBwA-1; Thu, 22 May 2025 06:30:35 -0400 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id EB71F195608B; Thu, 22 May 2025 10:30:34 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.179]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id AE70C1958014; Thu, 22 May 2025 10:30:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1747909839; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LT8u+Odh24aw54w1xRgnLKb526I+ZLroJYzIr5dgjt0=; b=gFYoIdCXpDuqzr+3jjT5kIzQrp8+JY3W4NlLB/whHNkiuSCzlYSpSuuqSe9EFYYLPrY9i8 Zxxq76aD4bOY4Shwc+Ug50xN84CH4L8OLTSRkkm1rv5tR1a+XqVa/Xl81EfJ4Q7OlurBRe r4xjFwxP3D/6mq68Uvan+GFBol9+nJA= X-MC-Unique: pupDLAsnPiKQYTOEDWEBwA-1 X-Mimecast-MFC-AGG-ID: pupDLAsnPiKQYTOEDWEBwA_1747909835 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Markus Armbruster , Paolo Bonzini , Eric Blake , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Juraj Marcin Subject: [PULL 18/23] util/qemu-sockets: Refactor setting client sockopts into a separate function Date: Thu, 22 May 2025 11:29:18 +0100 Message-ID: <20250522102923.309452-19-berrange@redhat.com> In-Reply-To: <20250522102923.309452-1-berrange@redhat.com> References: <20250522102923.309452-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 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=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.184, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1747909979377116600 From: Juraj Marcin This is done in preparation for enabling the SO_KEEPALIVE support for server sockets and adding settings for more TCP keep-alive socket options. Signed-off-by: Juraj Marcin Reviewed-by: Daniel P. Berrang=C3=A9 Signed-off-by: Daniel P. Berrang=C3=A9 --- util/qemu-sockets.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c index 77477c1cd5..4a878e0527 100644 --- a/util/qemu-sockets.c +++ b/util/qemu-sockets.c @@ -205,6 +205,22 @@ static int try_bind(int socket, InetSocketAddress *sad= dr, struct addrinfo *e) #endif } =20 +static int inet_set_sockopts(int sock, InetSocketAddress *saddr, Error **e= rrp) +{ + if (saddr->keep_alive) { + int keep_alive =3D 1; + int ret =3D setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, + &keep_alive, sizeof(keep_alive)); + + if (ret < 0) { + error_setg_errno(errp, errno, + "Unable to set keep-alive option on socket"); + return -1; + } + } + return 0; +} + static int inet_listen_saddr(InetSocketAddress *saddr, int port_offset, int num, @@ -475,16 +491,9 @@ int inet_connect_saddr(InetSocketAddress *saddr, Error= **errp) return sock; } =20 - if (saddr->keep_alive) { - int val =3D 1; - int ret =3D setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, - &val, sizeof(val)); - - if (ret < 0) { - error_setg_errno(errp, errno, "Unable to set KEEPALIVE"); - close(sock); - return -1; - } + if (inet_set_sockopts(sock, saddr, errp) < 0) { + close(sock); + return -1; } =20 return sock; --=20 2.49.0 From nobody Sat Nov 15 17:47:13 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1747910004; cv=none; d=zohomail.com; s=zohoarc; b=eienyHYP0IqhuZLbIot4FXy83Zev2tWR6d5RfvdOT19Nw3jrz/zLJ8OizQhK4EKuoc/qreQw5bvs/bJ5kq2RsbKxbSt0YuM/C/0MWkgFZQhABvbq7qOINTkXA2RA2iUs3Q0+YAGjoN1sD9+JAvcFm2fk7tmLTBIPW9vm9eHxaaA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1747910004; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=iIZzfgTdaV8CXAkQx0Ke4gbgAg+jKeWuEAcGyxYH8Lc=; b=kDX13L6PQkgTK6o7pOFPP92vd2+ehz7jdMX0nbO2nr3vIO8G1CHKddSzm/6iRZwBj39um/5Q2xnaB0AzSKjM3DOQHnXRbK1nZ6r043gW/c7mFUp3oJUS+aotG7K8+9oFa0hlY58aHBdlNqaURGob7jq9mDqzWMLOwA0NV26hsnI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1747910004690148.62833197331088; Thu, 22 May 2025 03:33:24 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uI3CX-00043u-3y; Thu, 22 May 2025 06:31:01 -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 1uI3CO-0003lf-Kb for qemu-devel@nongnu.org; Thu, 22 May 2025 06:30:56 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uI3CI-0006ft-8t for qemu-devel@nongnu.org; Thu, 22 May 2025 06:30:52 -0400 Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-448-TArIV9rBMFi9sp0jJp7jsw-1; Thu, 22 May 2025 06:30:39 -0400 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 84B7919560B0; Thu, 22 May 2025 10:30:38 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.179]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 866721958014; Thu, 22 May 2025 10:30:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1747909842; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=iIZzfgTdaV8CXAkQx0Ke4gbgAg+jKeWuEAcGyxYH8Lc=; b=TzmczH3QfVNtj5O2Udvz6+89bHDoSQgELffRPduv7McuW7aJHf0ba5Uon1mjYcrKSHrFAQ gKPrHPoVHDVnfeBwk1XfTpP05rlUKxXgs3sTjmx3hLCgJh57Fo/qBe7TRtYZal0pQ4H4oI aC/Obh98P99OHQmfcIHjTtlFbYi9azY= X-MC-Unique: TArIV9rBMFi9sp0jJp7jsw-1 X-Mimecast-MFC-AGG-ID: TArIV9rBMFi9sp0jJp7jsw_1747909838 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Markus Armbruster , Paolo Bonzini , Eric Blake , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Juraj Marcin Subject: [PULL 19/23] util/qemu-sockets: Refactor success and failure paths in inet_listen_saddr() Date: Thu, 22 May 2025 11:29:19 +0100 Message-ID: <20250522102923.309452-20-berrange@redhat.com> In-Reply-To: <20250522102923.309452-1-berrange@redhat.com> References: <20250522102923.309452-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 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=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.184, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1747910005762116600 From: Juraj Marcin To get a listening socket, we need to first create a socket, try binding it to a certain port, and lastly starting listening to it. Each of these operations can fail due to various reasons, one of them being that the requested address/port is already in use. In such case, the function tries the same process with a new port number. This patch refactors the port number loop, so the success path is no longer buried inside the 'if' statements in the middle of the loop. Now, the success path is not nested and ends at the end of the iteration after successful socket creation, binding, and listening. In case any of the operations fails, it either continues to the next iteration (and the next port) or jumps out of the loop to handle the error and exits the function. Signed-off-by: Juraj Marcin Reviewed-by: Daniel P. Berrang=C3=A9 Signed-off-by: Daniel P. Berrang=C3=A9 --- util/qemu-sockets.c | 51 ++++++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c index 4a878e0527..329fdbfd97 100644 --- a/util/qemu-sockets.c +++ b/util/qemu-sockets.c @@ -303,11 +303,20 @@ static int inet_listen_saddr(InetSocketAddress *saddr, port_min =3D inet_getport(e); port_max =3D saddr->has_to ? saddr->to + port_offset : port_min; for (p =3D port_min; p <=3D port_max; p++) { + if (slisten >=3D 0) { + /* + * We have a socket we tried with the previous port. It ca= nnot + * be rebound, we need to close it and create a new one. + */ + close(slisten); + slisten =3D -1; + } inet_setport(e, p); =20 slisten =3D create_fast_reuse_socket(e); if (slisten < 0) { - /* First time we expect we might fail to create the socket + /* + * First time we expect we might fail to create the socket * eg if 'e' has AF_INET6 but ipv6 kmod is not loaded. * Later iterations should always succeed if first iterati= on * worked though, so treat that as fatal. @@ -317,40 +326,38 @@ static int inet_listen_saddr(InetSocketAddress *saddr, } else { error_setg_errno(errp, errno, "Failed to recreate failed listening = socket"); - goto listen_failed; + goto fail; } } socket_created =3D true; =20 rc =3D try_bind(slisten, saddr, e); if (rc < 0) { - if (errno !=3D EADDRINUSE) { - error_setg_errno(errp, errno, "Failed to bind socket"); - goto listen_failed; - } - } else { - if (!listen(slisten, num)) { - goto listen_ok; + if (errno =3D=3D EADDRINUSE) { + /* This port is already used, try the next one */ + continue; } - if (errno !=3D EADDRINUSE) { - error_setg_errno(errp, errno, "Failed to listen on soc= ket"); - goto listen_failed; + error_setg_errno(errp, errno, "Failed to bind socket"); + goto fail; + } + if (listen(slisten, num)) { + if (errno =3D=3D EADDRINUSE) { + /* This port is already used, try the next one */ + continue; } + error_setg_errno(errp, errno, "Failed to listen on socket"= ); + goto fail; } - /* Someone else managed to bind to the same port and beat us - * to listen on it! Socket semantics does not allow us to - * recover from this situation, so we need to recreate the - * socket to allow bind attempts for subsequent ports: - */ - close(slisten); - slisten =3D -1; + /* We have a listening socket */ + freeaddrinfo(res); + return slisten; } } error_setg_errno(errp, errno, socket_created ? "Failed to find an available port" : "Failed to create a socket"); -listen_failed: +fail: saved_errno =3D errno; if (slisten >=3D 0) { close(slisten); @@ -358,10 +365,6 @@ listen_failed: freeaddrinfo(res); errno =3D saved_errno; return -1; - -listen_ok: - freeaddrinfo(res); - return slisten; } =20 #ifdef _WIN32 --=20 2.49.0 From nobody Sat Nov 15 17:47:13 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1747910037; cv=none; d=zohomail.com; s=zohoarc; b=MOdJV2Aqq231CcnM1k/uy3SKyQIfYi3f+N2dA0jeJ5c4fe1UlV2JWg+Uh51vauven0sFq8oC6rwhVPHx6DPjJgCeqfpPvs9+wkaJQ1Ds4Ma6XY82tLvlnjNR76JSBYKoKt+RRnYOlC2+0b0Wonxv4zrt1CZYbZws85hXykjcufs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1747910037; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=2Yow7LNmH5OMfkVvhtRhwk7HuQaFcN01RTER9XSpT+E=; b=mRC+KrmIjheaUUOnJ3ZG3WoUHLjvH/0v0rN/nNpiswqmFDAIrrzfleJPBkLxWF7mdryCPJ+AdHucmtj9tqBc08QwLFMmY6UugJ/Zify3iXIgcumYpUPoJNVcFV29doyNDulfaNuwZLphgCE1N3VCtU08g5sxh8mQKbVDBGSkhjM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1747910036668825.2300619308895; Thu, 22 May 2025 03:33:56 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uI3CW-00044R-JM; Thu, 22 May 2025 06:31:00 -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 1uI3CL-0003ki-IZ for qemu-devel@nongnu.org; Thu, 22 May 2025 06:30:56 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uI3CJ-0006gm-H3 for qemu-devel@nongnu.org; Thu, 22 May 2025 06:30:49 -0400 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-417-WfcHv6suOo-it3riuPTypA-1; Thu, 22 May 2025 06:30:43 -0400 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 397CC1800361; Thu, 22 May 2025 10:30:42 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.179]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 0AAF91958014; Thu, 22 May 2025 10:30:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1747909844; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2Yow7LNmH5OMfkVvhtRhwk7HuQaFcN01RTER9XSpT+E=; b=icEUEgxYfxfl1D89jIGhMIUJCt+d0ymsutVmejBEFK4MjyfluRHKb2qjtnTMsuTAGNvhMd Uq+A+3zzX9tcJ1XL1q1mS26uQqYl6TYee57t1fqC4rabE5Uwwp2ZPcAt/mTL3aniRfcMRD H5FGWEQC6b435dSC9xUioZkoqBgddUg= X-MC-Unique: WfcHv6suOo-it3riuPTypA-1 X-Mimecast-MFC-AGG-ID: WfcHv6suOo-it3riuPTypA_1747909842 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Markus Armbruster , Paolo Bonzini , Eric Blake , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Juraj Marcin Subject: [PULL 20/23] util/qemu-sockets: Add support for keep-alive flag to passive sockets Date: Thu, 22 May 2025 11:29:20 +0100 Message-ID: <20250522102923.309452-21-berrange@redhat.com> In-Reply-To: <20250522102923.309452-1-berrange@redhat.com> References: <20250522102923.309452-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 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=170.10.129.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.184, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1747910038167116600 From: Juraj Marcin Commit aec21d3175 (qapi: Add InetSocketAddress member keep-alive) introduces the keep-alive flag, which enables the SO_KEEPALIVE socket option, but only on client-side sockets. However, this option is also useful for server-side sockets, so they can check if a client is still reachable or drop the connection otherwise. This patch enables the SO_KEEPALIVE socket option on passive server-side sockets if the keep-alive flag is enabled. This socket option is then inherited by active server-side sockets communicating with connected clients. Signed-off-by: Juraj Marcin Reviewed-by: Daniel P. Berrang=C3=A9 Signed-off-by: Daniel P. Berrang=C3=A9 --- qapi/sockets.json | 4 ++-- util/qemu-sockets.c | 9 +++------ 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/qapi/sockets.json b/qapi/sockets.json index 6a95023315..62797cd027 100644 --- a/qapi/sockets.json +++ b/qapi/sockets.json @@ -56,8 +56,8 @@ # @ipv6: whether to accept IPv6 addresses, default try both IPv4 and # IPv6 # -# @keep-alive: enable keep-alive when connecting to this socket. Not -# supported for passive sockets. (Since 4.2) +# @keep-alive: enable keep-alive when connecting to/listening on this sock= et. +# (Since 4.2, not supported for listening sockets until 10.1) # # @mptcp: enable multi-path TCP. (Since 6.1) # diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c index 329fdbfd97..4fbf1ed5bf 100644 --- a/util/qemu-sockets.c +++ b/util/qemu-sockets.c @@ -236,12 +236,6 @@ static int inet_listen_saddr(InetSocketAddress *saddr, int saved_errno =3D 0; bool socket_created =3D false; =20 - if (saddr->keep_alive) { - error_setg(errp, "keep-alive option is not supported for passive " - "sockets"); - return -1; - } - memset(&ai,0, sizeof(ai)); ai.ai_flags =3D AI_PASSIVE; if (saddr->has_numeric && saddr->numeric) { @@ -349,6 +343,9 @@ static int inet_listen_saddr(InetSocketAddress *saddr, goto fail; } /* We have a listening socket */ + if (inet_set_sockopts(slisten, saddr, errp) < 0) { + goto fail; + } freeaddrinfo(res); return slisten; } --=20 2.49.0 From nobody Sat Nov 15 17:47:13 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1747909941; cv=none; d=zohomail.com; s=zohoarc; b=E1iom9Mx75HB9wVP7UQSKGTJW9Frnt2h6JiE9U6CE27p+ViC7JiAbJ8Nr1Qg7mz3s0f784tuqZM9u36hoIa1UIrxGuYXcVwOGAMoXllWT0o3dgXRXXlRI7ojaxxAsMG/KECM6k/gPL+57xaODaBP4IfvBAPn1Rv1ccDLGuM4fnU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1747909941; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=zyDczoF8Ea/zibDFBxcUI7jCKMlSBi/g/H/4wnvbA90=; b=gFJSfSH1ztqubm1GOlaxtsPjkWBGk44UzsRRdv8xZ1EdZWpz+eZx193pX9lH1TChW9l9Wb9BJfHxZ/pEY/7eVJfKINjkVlyEyKQ1G5viyzfXhZ5FdaMOYVLf5180VpmPoYwE728O3GaATqswLrSsIL4gEJjuW4onWPBkcx7MQNs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1747909941123692.354486020462; Thu, 22 May 2025 03:32:21 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uI3Ci-00058D-Mx; Thu, 22 May 2025 06:31:12 -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 1uI3Cg-0004wn-45 for qemu-devel@nongnu.org; Thu, 22 May 2025 06:31:10 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uI3CV-0006hz-IM for qemu-devel@nongnu.org; Thu, 22 May 2025 06:31:09 -0400 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-324-OaSZizkaP765Lb2o6h8yDw-1; Thu, 22 May 2025 06:30:46 -0400 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 6682718003FC; Thu, 22 May 2025 10:30:45 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.179]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id B24A71958019; Thu, 22 May 2025 10:30:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1747909857; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zyDczoF8Ea/zibDFBxcUI7jCKMlSBi/g/H/4wnvbA90=; b=W0zGlYX2U6z9smP12jHN2QwmKCS6tSb/neCpE+/TN2aD/nG4uPUUhLtkINi9oQz8MotmLZ zrQVFO+64UBoUivK0dI5PwbJM9zPRKjnouYYNj1KbgblQWOCqFhHtaBUYMiEnc6mzqTiBR tlmW2dU2+oVmQBnNbWwqk63XO8bX09g= X-MC-Unique: OaSZizkaP765Lb2o6h8yDw-1 X-Mimecast-MFC-AGG-ID: OaSZizkaP765Lb2o6h8yDw_1747909845 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Markus Armbruster , Paolo Bonzini , Eric Blake , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Juraj Marcin Subject: [PULL 21/23] util/qemu-sockets: Refactor inet_parse() to use QemuOpts Date: Thu, 22 May 2025 11:29:21 +0100 Message-ID: <20250522102923.309452-22-berrange@redhat.com> In-Reply-To: <20250522102923.309452-1-berrange@redhat.com> References: <20250522102923.309452-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 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=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1747909943174116600 From: Juraj Marcin Currently, the inet address parser cannot handle multiple options where one is prefixed with the name of the other. For example, with the 'keep-alive-idle' option added, the current parser cannot parse '127.0.0.1:5000,keep-alive-idle=3D60,keep-alive' correctly. Instead, it fails with "error parsing 'keep-alive' flag '-idle=3D60,keep-alive'". To resolve these issues, this patch rewrites the inet address parsing using the QemuOpts parser, which the inet_parse_flag() function tries to mimic. This new parser supports all previously supported options and on top of that the 'numeric' flag is now also supported. The only difference is, the new parser produces an error if an unknown option is passed, instead of silently ignoring it. Signed-off-by: Juraj Marcin Reviewed-by: Daniel P. Berrang=C3=A9 Signed-off-by: Daniel P. Berrang=C3=A9 --- tests/unit/test-util-sockets.c | 196 +++++++++++++++++++++++++++++++++ util/qemu-sockets.c | 158 +++++++++++++------------- 2 files changed, 270 insertions(+), 84 deletions(-) diff --git a/tests/unit/test-util-sockets.c b/tests/unit/test-util-sockets.c index 4c9dd0b271..9e39b92e7c 100644 --- a/tests/unit/test-util-sockets.c +++ b/tests/unit/test-util-sockets.c @@ -332,6 +332,177 @@ static void test_socket_unix_abstract(void) =20 #endif /* CONFIG_LINUX */ =20 +static void inet_parse_test_helper(const char *str, + InetSocketAddress *exp_addr, bool succe= ss) +{ + InetSocketAddress addr; + Error *error =3D NULL; + + int rc =3D inet_parse(&addr, str, &error); + + if (success) { + g_assert_cmpint(rc, =3D=3D, 0); + } else { + g_assert_cmpint(rc, <, 0); + } + if (exp_addr !=3D NULL) { + g_assert_cmpstr(addr.host, =3D=3D, exp_addr->host); + g_assert_cmpstr(addr.port, =3D=3D, exp_addr->port); + /* Own members: */ + g_assert_cmpint(addr.has_numeric, =3D=3D, exp_addr->has_numeric); + g_assert_cmpint(addr.numeric, =3D=3D, exp_addr->numeric); + g_assert_cmpint(addr.has_to, =3D=3D, exp_addr->has_to); + g_assert_cmpint(addr.to, =3D=3D, exp_addr->to); + g_assert_cmpint(addr.has_ipv4, =3D=3D, exp_addr->has_ipv4); + g_assert_cmpint(addr.ipv4, =3D=3D, exp_addr->ipv4); + g_assert_cmpint(addr.has_ipv6, =3D=3D, exp_addr->has_ipv6); + g_assert_cmpint(addr.ipv6, =3D=3D, exp_addr->ipv6); + g_assert_cmpint(addr.has_keep_alive, =3D=3D, exp_addr->has_keep_al= ive); + g_assert_cmpint(addr.keep_alive, =3D=3D, exp_addr->keep_alive); +#ifdef HAVE_IPPROTO_MPTCP + g_assert_cmpint(addr.has_mptcp, =3D=3D, exp_addr->has_mptcp); + g_assert_cmpint(addr.mptcp, =3D=3D, exp_addr->mptcp); +#endif + } + + g_free(addr.host); + g_free(addr.port); +} + +static void test_inet_parse_nohost_good(void) +{ + char host[] =3D ""; + char port[] =3D "5000"; + InetSocketAddress exp_addr =3D { + .host =3D host, + .port =3D port, + }; + inet_parse_test_helper(":5000", &exp_addr, true); +} + +static void test_inet_parse_empty_bad(void) +{ + inet_parse_test_helper("", NULL, false); +} + +static void test_inet_parse_only_colon_bad(void) +{ + inet_parse_test_helper(":", NULL, false); +} + +static void test_inet_parse_ipv4_good(void) +{ + char host[] =3D "127.0.0.1"; + char port[] =3D "5000"; + InetSocketAddress exp_addr =3D { + .host =3D host, + .port =3D port, + }; + inet_parse_test_helper("127.0.0.1:5000", &exp_addr, true); +} + +static void test_inet_parse_ipv4_noport_bad(void) +{ + inet_parse_test_helper("127.0.0.1", NULL, false); +} + +static void test_inet_parse_ipv6_good(void) +{ + char host[] =3D "::1"; + char port[] =3D "5000"; + InetSocketAddress exp_addr =3D { + .host =3D host, + .port =3D port, + }; + inet_parse_test_helper("[::1]:5000", &exp_addr, true); +} + +static void test_inet_parse_ipv6_noend_bad(void) +{ + inet_parse_test_helper("[::1", NULL, false); +} + +static void test_inet_parse_ipv6_noport_bad(void) +{ + inet_parse_test_helper("[::1]:", NULL, false); +} + +static void test_inet_parse_ipv6_empty_bad(void) +{ + inet_parse_test_helper("[]:5000", NULL, false); +} + +static void test_inet_parse_hostname_good(void) +{ + char host[] =3D "localhost"; + char port[] =3D "5000"; + InetSocketAddress exp_addr =3D { + .host =3D host, + .port =3D port, + }; + inet_parse_test_helper("localhost:5000", &exp_addr, true); +} + +static void test_inet_parse_all_options_good(void) +{ + char host[] =3D "::1"; + char port[] =3D "5000"; + InetSocketAddress exp_addr =3D { + .host =3D host, + .port =3D port, + .has_numeric =3D true, + .numeric =3D true, + .has_to =3D true, + .to =3D 5006, + .has_ipv4 =3D true, + .ipv4 =3D false, + .has_ipv6 =3D true, + .ipv6 =3D true, + .has_keep_alive =3D true, + .keep_alive =3D true, +#ifdef HAVE_IPPROTO_MPTCP + .has_mptcp =3D true, + .mptcp =3D false, +#endif + }; + inet_parse_test_helper( + "[::1]:5000,numeric=3Don,to=3D5006,ipv4=3Doff,ipv6=3Don,keep-alive= =3Don" +#ifdef HAVE_IPPROTO_MPTCP + ",mptcp=3Doff" +#endif + , &exp_addr, true); +} + +static void test_inet_parse_all_implicit_bool_good(void) +{ + char host[] =3D "::1"; + char port[] =3D "5000"; + InetSocketAddress exp_addr =3D { + .host =3D host, + .port =3D port, + .has_numeric =3D true, + .numeric =3D true, + .has_to =3D true, + .to =3D 5006, + .has_ipv4 =3D true, + .ipv4 =3D true, + .has_ipv6 =3D true, + .ipv6 =3D true, + .has_keep_alive =3D true, + .keep_alive =3D true, +#ifdef HAVE_IPPROTO_MPTCP + .has_mptcp =3D true, + .mptcp =3D true, +#endif + }; + inet_parse_test_helper( + "[::1]:5000,numeric,to=3D5006,ipv4,ipv6,keep-alive" +#ifdef HAVE_IPPROTO_MPTCP + ",mptcp" +#endif + , &exp_addr, true); +} + int main(int argc, char **argv) { bool has_ipv4, has_ipv6; @@ -377,6 +548,31 @@ int main(int argc, char **argv) test_socket_unix_abstract); #endif =20 + g_test_add_func("/util/socket/inet-parse/nohost-good", + test_inet_parse_nohost_good); + g_test_add_func("/util/socket/inet-parse/empty-bad", + test_inet_parse_empty_bad); + g_test_add_func("/util/socket/inet-parse/only-colon-bad", + test_inet_parse_only_colon_bad); + g_test_add_func("/util/socket/inet-parse/ipv4-good", + test_inet_parse_ipv4_good); + g_test_add_func("/util/socket/inet-parse/ipv4-noport-bad", + test_inet_parse_ipv4_noport_bad); + g_test_add_func("/util/socket/inet-parse/ipv6-good", + test_inet_parse_ipv6_good); + g_test_add_func("/util/socket/inet-parse/ipv6-noend-bad", + test_inet_parse_ipv6_noend_bad); + g_test_add_func("/util/socket/inet-parse/ipv6-noport-bad", + test_inet_parse_ipv6_noport_bad); + g_test_add_func("/util/socket/inet-parse/ipv6-empty-bad", + test_inet_parse_ipv6_empty_bad); + g_test_add_func("/util/socket/inet-parse/hostname-good", + test_inet_parse_hostname_good); + g_test_add_func("/util/socket/inet-parse/all-options-good", + test_inet_parse_all_options_good); + g_test_add_func("/util/socket/inet-parse/all-bare-bool-good", + test_inet_parse_all_implicit_bool_good); + end: return g_test_run(); } diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c index 4fbf1ed5bf..403dc26b36 100644 --- a/util/qemu-sockets.c +++ b/util/qemu-sockets.c @@ -30,6 +30,7 @@ #include "qapi/qobject-input-visitor.h" #include "qapi/qobject-output-visitor.h" #include "qemu/cutils.h" +#include "qemu/option.h" #include "trace.h" =20 #ifndef AI_ADDRCONFIG @@ -600,115 +601,104 @@ err: return -1; } =20 -/* compatibility wrapper */ -static int inet_parse_flag(const char *flagname, const char *optstr, bool = *val, - Error **errp) -{ - char *end; - size_t len; - - end =3D strstr(optstr, ","); - if (end) { - if (end[1] =3D=3D ',') { /* Reject 'ipv6=3Don,,foo' */ - error_setg(errp, "error parsing '%s' flag '%s'", flagname, opt= str); - return -1; - } - len =3D end - optstr; - } else { - len =3D strlen(optstr); - } - if (len =3D=3D 0 || (len =3D=3D 3 && strncmp(optstr, "=3Don", len) =3D= =3D 0)) { - *val =3D true; - } else if (len =3D=3D 4 && strncmp(optstr, "=3Doff", len) =3D=3D 0) { - *val =3D false; - } else { - error_setg(errp, "error parsing '%s' flag '%s'", flagname, optstr); - return -1; - } - return 0; -} +static QemuOptsList inet_opts =3D { + .name =3D "InetSocketAddress", + .head =3D QTAILQ_HEAD_INITIALIZER(inet_opts.head), + .implied_opt_name =3D "addr", + .desc =3D { + { + .name =3D "addr", + .type =3D QEMU_OPT_STRING, + }, + { + .name =3D "numeric", + .type =3D QEMU_OPT_BOOL, + }, + { + .name =3D "to", + .type =3D QEMU_OPT_NUMBER, + }, + { + .name =3D "ipv4", + .type =3D QEMU_OPT_BOOL, + }, + { + .name =3D "ipv6", + .type =3D QEMU_OPT_BOOL, + }, + { + .name =3D "keep-alive", + .type =3D QEMU_OPT_BOOL, + }, +#ifdef HAVE_IPPROTO_MPTCP + { + .name =3D "mptcp", + .type =3D QEMU_OPT_BOOL, + }, +#endif + { /* end of list */ } + }, +}; =20 int inet_parse(InetSocketAddress *addr, const char *str, Error **errp) { - const char *optstr, *h; - char host[65]; - char port[33]; - int to; - int pos; - char *begin; - + QemuOpts *opts =3D qemu_opts_parse(&inet_opts, str, true, errp); + if (!opts) { + return -1; + } memset(addr, 0, sizeof(*addr)); =20 /* parse address */ - if (str[0] =3D=3D ':') { - /* no host given */ - host[0] =3D '\0'; - if (sscanf(str, ":%32[^,]%n", port, &pos) !=3D 1) { - error_setg(errp, "error parsing port in address '%s'", str); - return -1; - } - } else if (str[0] =3D=3D '[') { + const char *addr_str =3D qemu_opt_get(opts, "addr"); + if (!addr_str) { + error_setg(errp, "error parsing address ''"); + return -1; + } + if (str[0] =3D=3D '[') { /* IPv6 addr */ - if (sscanf(str, "[%64[^]]]:%32[^,]%n", host, port, &pos) !=3D 2) { - error_setg(errp, "error parsing IPv6 address '%s'", str); + const char *ip_end =3D strstr(addr_str, "]:"); + if (!ip_end || ip_end - addr_str < 2 || strlen(ip_end) < 3) { + error_setg(errp, "error parsing IPv6 address '%s'", addr_str); return -1; } + addr->host =3D g_strndup(addr_str + 1, ip_end - addr_str - 1); + addr->port =3D g_strdup(ip_end + 2); } else { - /* hostname or IPv4 addr */ - if (sscanf(str, "%64[^:]:%32[^,]%n", host, port, &pos) !=3D 2) { - error_setg(errp, "error parsing address '%s'", str); + /* no host, hostname or IPv4 addr */ + const char *port =3D strchr(addr_str, ':'); + if (!port || strlen(port) < 2) { + error_setg(errp, "error parsing address '%s'", addr_str); return -1; } + addr->host =3D g_strndup(addr_str, port - addr_str); + addr->port =3D g_strdup(port + 1); } =20 - addr->host =3D g_strdup(host); - addr->port =3D g_strdup(port); - /* parse options */ - optstr =3D str + pos; - h =3D strstr(optstr, ",to=3D"); - if (h) { - h +=3D 4; - if (sscanf(h, "%d%n", &to, &pos) !=3D 1 || - (h[pos] !=3D '\0' && h[pos] !=3D ',')) { - error_setg(errp, "error parsing to=3D argument"); - return -1; - } + if (qemu_opt_find(opts, "numeric")) { + addr->has_numeric =3D true, + addr->numeric =3D qemu_opt_get_bool(opts, "numeric", false); + } + if (qemu_opt_find(opts, "to")) { addr->has_to =3D true; - addr->to =3D to; + addr->to =3D qemu_opt_get_number(opts, "to", 0); } - begin =3D strstr(optstr, ",ipv4"); - if (begin) { - if (inet_parse_flag("ipv4", begin + 5, &addr->ipv4, errp) < 0) { - return -1; - } + if (qemu_opt_find(opts, "ipv4")) { addr->has_ipv4 =3D true; + addr->ipv4 =3D qemu_opt_get_bool(opts, "ipv4", false); } - begin =3D strstr(optstr, ",ipv6"); - if (begin) { - if (inet_parse_flag("ipv6", begin + 5, &addr->ipv6, errp) < 0) { - return -1; - } + if (qemu_opt_find(opts, "ipv6")) { addr->has_ipv6 =3D true; + addr->ipv6 =3D qemu_opt_get_bool(opts, "ipv6", false); } - begin =3D strstr(optstr, ",keep-alive"); - if (begin) { - if (inet_parse_flag("keep-alive", begin + strlen(",keep-alive"), - &addr->keep_alive, errp) < 0) - { - return -1; - } + if (qemu_opt_find(opts, "keep-alive")) { addr->has_keep_alive =3D true; + addr->keep_alive =3D qemu_opt_get_bool(opts, "keep-alive", false); } #ifdef HAVE_IPPROTO_MPTCP - begin =3D strstr(optstr, ",mptcp"); - if (begin) { - if (inet_parse_flag("mptcp", begin + strlen(",mptcp"), - &addr->mptcp, errp) < 0) - { - return -1; - } + if (qemu_opt_find(opts, "mptcp")) { addr->has_mptcp =3D true; + addr->mptcp =3D qemu_opt_get_bool(opts, "mptcp", 0); } #endif return 0; --=20 2.49.0 From nobody Sat Nov 15 17:47:13 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1747909881; cv=none; d=zohomail.com; s=zohoarc; b=kpifsBvLrGMIG3+SR2WhW8Y+nYUj3tfJyHPq3VevJcnxputpsoNzAiCswqa2fYW/qSoiq95GvuTqsQBpHyPj9jiJowF6WVdyLFbs2QYiLOEUKbrnhgRxnohiX4brK4A5QIdBk5IHit9S+Qh9srakGuYrt8My+Fn4ABlxErQR1zg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1747909881; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=qFH+p8HR+JF9ppvRioJ+Oz56ZSrJiqELILA5yNuqU+Q=; b=M+AGhObrq/Lpxszq4Oo7m9hAMw2jhKIokou5FCkJk/732X3yXHBOLxDjeYByUdxv6ikVIG2qOslA2DZuVfq9GBQV7HB8eVzWQxUgeozW15mslt6zi2i0ODHTUn1Hs8+D1ac/UvZAGH4/+b8S0DXSrtdn3yRDRQjOiFAYOC27TZU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1747909881445548.944306861466; Thu, 22 May 2025 03:31:21 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uI3CV-0003vm-4a; Thu, 22 May 2025 06:30:59 -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 1uI3CR-0003lk-VX for qemu-devel@nongnu.org; Thu, 22 May 2025 06:30:56 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uI3CN-0006hG-WB for qemu-devel@nongnu.org; Thu, 22 May 2025 06:30:54 -0400 Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-298-NVXMuodON2qlNsTgNU2Yww-1; Thu, 22 May 2025 06:30:49 -0400 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id F2066195609E; Thu, 22 May 2025 10:30:48 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.179]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id F39851958014; Thu, 22 May 2025 10:30:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1747909851; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qFH+p8HR+JF9ppvRioJ+Oz56ZSrJiqELILA5yNuqU+Q=; b=XRYbElV+Uw2jhEuvV90Z6lTNIbefEsqCn2UKFPRAHJOWJX4rZ8EGomUFBJiEeHaG30oW6c Yy1lLMnKkrhe/w0AfzxmtKBTEUygGpNyicqjinCdCpIXn06Uc68EDKz15CcDDXzaCtbEWi sZ62CqXoNGIxY4gASN+FvLjYrW7j9t8= X-MC-Unique: NVXMuodON2qlNsTgNU2Yww-1 X-Mimecast-MFC-AGG-ID: NVXMuodON2qlNsTgNU2Yww_1747909849 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Markus Armbruster , Paolo Bonzini , Eric Blake , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Juraj Marcin Subject: [PULL 22/23] util/qemu-sockets: Introduce inet socket options controlling TCP keep-alive Date: Thu, 22 May 2025 11:29:22 +0100 Message-ID: <20250522102923.309452-23-berrange@redhat.com> In-Reply-To: <20250522102923.309452-1-berrange@redhat.com> References: <20250522102923.309452-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 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=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.184, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1747909882546116600 From: Juraj Marcin With the default TCP stack configuration, it could be even 2 hours before the connection times out due to the other side not being reachable. However, in some cases, the application needs to be aware of a connection issue much sooner. This is the case, for example, for postcopy live migration. If there is no traffic from the migration destination guest (server-side) to the migration source guest (client-side), the destination keeps waiting for pages indefinitely and does not switch to the postcopy-paused state. This can happen, for example, if the destination QEMU instance is started with the '-S' command line option and the machine is not started yet, or if the machine is idle and produces no new page faults for not-yet-migrated pages. This patch introduces new inet socket parameters that control count, idle period, and interval of TCP keep-alive packets before the connection is considered broken. These parameters are available on systems where the respective TCP socket options are defined, that includes Linux, Windows, macOS, but not OpenBSD. Additionally, macOS defines TCP_KEEPIDLE as TCP_KEEPALIVE instead, so the patch supplies its own definition. The default value for all is 0, which means the system configuration is used. Signed-off-by: Juraj Marcin Reviewed-by: Daniel P. Berrang=C3=A9 Signed-off-by: Daniel P. Berrang=C3=A9 --- meson.build | 30 +++++++++++++ qapi/sockets.json | 19 ++++++++ tests/unit/test-util-sockets.c | 39 +++++++++++++++++ util/qemu-sockets.c | 80 ++++++++++++++++++++++++++++++++++ 4 files changed, 168 insertions(+) diff --git a/meson.build b/meson.build index ad2053f968..fdad3fb528 100644 --- a/meson.build +++ b/meson.build @@ -2760,6 +2760,36 @@ if linux_io_uring.found() config_host_data.set('HAVE_IO_URING_PREP_WRITEV2', cc.has_header_symbol('liburing.h', 'io_uring_prep_w= ritev2')) endif +config_host_data.set('HAVE_TCP_KEEPCNT', + cc.has_header_symbol('netinet/tcp.h', 'TCP_KEEPCNT') = or + cc.compiles(''' + #include + #ifndef TCP_KEEPCNT + #error + #endif + int main(void) { return 0; }''', + name: 'Win32 TCP_KEEPCNT')) +# On Darwin TCP_KEEPIDLE is available under different name, TCP_KEEPALIVE. +# https://github.com/apple/darwin-xnu/blob/xnu-4570.1.46/bsd/man/man4/tcp.= 4#L172 +config_host_data.set('HAVE_TCP_KEEPIDLE', + cc.has_header_symbol('netinet/tcp.h', 'TCP_KEEPIDLE')= or + cc.has_header_symbol('netinet/tcp.h', 'TCP_KEEPALIVE'= ) or + cc.compiles(''' + #include + #ifndef TCP_KEEPIDLE + #error + #endif + int main(void) { return 0; }''', + name: 'Win32 TCP_KEEPIDLE')) +config_host_data.set('HAVE_TCP_KEEPINTVL', + cc.has_header_symbol('netinet/tcp.h', 'TCP_KEEPINTVL'= ) or + cc.compiles(''' + #include + #ifndef TCP_KEEPINTVL + #error + #endif + int main(void) { return 0; }''', + name: 'Win32 TCP_KEEPINTVL')) =20 # has_member config_host_data.set('HAVE_SIGEV_NOTIFY_THREAD_ID', diff --git a/qapi/sockets.json b/qapi/sockets.json index 62797cd027..f9f559daba 100644 --- a/qapi/sockets.json +++ b/qapi/sockets.json @@ -59,6 +59,22 @@ # @keep-alive: enable keep-alive when connecting to/listening on this sock= et. # (Since 4.2, not supported for listening sockets until 10.1) # +# @keep-alive-count: number of keep-alive packets sent before the connecti= on is +# closed. Only supported for TCP sockets on systems where TCP_KEEPCNT +# socket option is defined (this includes Linux, Windows, macOS, FreeB= SD, +# but not OpenBSD). When set to 0, system setting is used. (Since 10= .1) +# +# @keep-alive-idle: time in seconds the connection needs to be idle before +# sending a keepalive packet. Only supported for TCP sockets on syste= ms +# where TCP_KEEPIDLE socket option is defined (this includes Linux, +# Windows, macOS, FreeBSD, but not OpenBSD). When set to 0, system se= tting +# is used. (Since 10.1) +# +# @keep-alive-interval: time in seconds between keep-alive packets. Only +# supported for TCP sockets on systems where TCP_KEEPINTVL is defined = (this +# includes Linux, Windows, macOS, FreeBSD, but not OpenBSD). When set= to +# 0, system setting is used. (Since 10.1) +# # @mptcp: enable multi-path TCP. (Since 6.1) # # Since: 1.3 @@ -71,6 +87,9 @@ '*ipv4': 'bool', '*ipv6': 'bool', '*keep-alive': 'bool', + '*keep-alive-count': { 'type': 'uint32', 'if': 'HAVE_TCP_KEEPCNT' }, + '*keep-alive-idle': { 'type': 'uint32', 'if': 'HAVE_TCP_KEEPIDLE' }, + '*keep-alive-interval': { 'type': 'uint32', 'if': 'HAVE_TCP_KEEPINTVL'= }, '*mptcp': { 'type': 'bool', 'if': 'HAVE_IPPROTO_MPTCP' } } } =20 ## diff --git a/tests/unit/test-util-sockets.c b/tests/unit/test-util-sockets.c index 9e39b92e7c..8492f4d68f 100644 --- a/tests/unit/test-util-sockets.c +++ b/tests/unit/test-util-sockets.c @@ -359,6 +359,24 @@ static void inet_parse_test_helper(const char *str, g_assert_cmpint(addr.ipv6, =3D=3D, exp_addr->ipv6); g_assert_cmpint(addr.has_keep_alive, =3D=3D, exp_addr->has_keep_al= ive); g_assert_cmpint(addr.keep_alive, =3D=3D, exp_addr->keep_alive); +#ifdef HAVE_TCP_KEEPCNT + g_assert_cmpint(addr.has_keep_alive_count, =3D=3D, + exp_addr->has_keep_alive_count); + g_assert_cmpint(addr.keep_alive_count, =3D=3D, + exp_addr->keep_alive_count); +#endif +#ifdef HAVE_TCP_KEEPIDLE + g_assert_cmpint(addr.has_keep_alive_idle, =3D=3D, + exp_addr->has_keep_alive_idle); + g_assert_cmpint(addr.keep_alive_idle, =3D=3D, + exp_addr->keep_alive_idle); +#endif +#ifdef HAVE_TCP_KEEPINTVL + g_assert_cmpint(addr.has_keep_alive_interval, =3D=3D, + exp_addr->has_keep_alive_interval); + g_assert_cmpint(addr.keep_alive_interval, =3D=3D, + exp_addr->keep_alive_interval); +#endif #ifdef HAVE_IPPROTO_MPTCP g_assert_cmpint(addr.has_mptcp, =3D=3D, exp_addr->has_mptcp); g_assert_cmpint(addr.mptcp, =3D=3D, exp_addr->mptcp); @@ -460,6 +478,18 @@ static void test_inet_parse_all_options_good(void) .ipv6 =3D true, .has_keep_alive =3D true, .keep_alive =3D true, +#ifdef HAVE_TCP_KEEPCNT + .has_keep_alive_count =3D true, + .keep_alive_count =3D 10, +#endif +#ifdef HAVE_TCP_KEEPIDLE + .has_keep_alive_idle =3D true, + .keep_alive_idle =3D 60, +#endif +#ifdef HAVE_TCP_KEEPINTVL + .has_keep_alive_interval =3D true, + .keep_alive_interval =3D 30, +#endif #ifdef HAVE_IPPROTO_MPTCP .has_mptcp =3D true, .mptcp =3D false, @@ -467,6 +497,15 @@ static void test_inet_parse_all_options_good(void) }; inet_parse_test_helper( "[::1]:5000,numeric=3Don,to=3D5006,ipv4=3Doff,ipv6=3Don,keep-alive= =3Don" +#ifdef HAVE_TCP_KEEPCNT + ",keep-alive-count=3D10" +#endif +#ifdef HAVE_TCP_KEEPIDLE + ",keep-alive-idle=3D60" +#endif +#ifdef HAVE_TCP_KEEPINTVL + ",keep-alive-interval=3D30" +#endif #ifdef HAVE_IPPROTO_MPTCP ",mptcp=3Doff" #endif diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c index 403dc26b36..4773755fd5 100644 --- a/util/qemu-sockets.c +++ b/util/qemu-sockets.c @@ -45,6 +45,14 @@ # define AI_NUMERICSERV 0 #endif =20 +/* + * On macOS TCP_KEEPIDLE is available under a different name, TCP_KEEPALIV= E. + * https://github.com/apple/darwin-xnu/blob/xnu-4570.1.46/bsd/man/man4/tcp= .4#L172 + */ +#if defined(TCP_KEEPALIVE) && !defined(TCP_KEEPIDLE) +# define TCP_KEEPIDLE TCP_KEEPALIVE +#endif + =20 static int inet_getport(struct addrinfo *e) { @@ -218,6 +226,42 @@ static int inet_set_sockopts(int sock, InetSocketAddre= ss *saddr, Error **errp) "Unable to set keep-alive option on socket"); return -1; } +#ifdef HAVE_TCP_KEEPCNT + if (saddr->has_keep_alive_count && saddr->keep_alive_count) { + int keep_count =3D saddr->keep_alive_count; + ret =3D setsockopt(sock, IPPROTO_TCP, TCP_KEEPCNT, &keep_count, + sizeof(keep_count)); + if (ret < 0) { + error_setg_errno(errp, errno, + "Unable to set TCP keep-alive count optio= n on socket"); + return -1; + } + } +#endif +#ifdef HAVE_TCP_KEEPIDLE + if (saddr->has_keep_alive_idle && saddr->keep_alive_idle) { + int keep_idle =3D saddr->keep_alive_idle; + ret =3D setsockopt(sock, IPPROTO_TCP, TCP_KEEPIDLE, &keep_idle, + sizeof(keep_idle)); + if (ret < 0) { + error_setg_errno(errp, errno, + "Unable to set TCP keep-alive idle option= on socket"); + return -1; + } + } +#endif +#ifdef HAVE_TCP_KEEPINTVL + if (saddr->has_keep_alive_interval && saddr->keep_alive_interval) { + int keep_interval =3D saddr->keep_alive_interval; + ret =3D setsockopt(sock, IPPROTO_TCP, TCP_KEEPINTVL, &keep_int= erval, + sizeof(keep_interval)); + if (ret < 0) { + error_setg_errno(errp, errno, + "Unable to set TCP keep-alive interval op= tion on socket"); + return -1; + } + } +#endif } return 0; } @@ -630,6 +674,24 @@ static QemuOptsList inet_opts =3D { .name =3D "keep-alive", .type =3D QEMU_OPT_BOOL, }, +#ifdef HAVE_TCP_KEEPCNT + { + .name =3D "keep-alive-count", + .type =3D QEMU_OPT_NUMBER, + }, +#endif +#ifdef HAVE_TCP_KEEPIDLE + { + .name =3D "keep-alive-idle", + .type =3D QEMU_OPT_NUMBER, + }, +#endif +#ifdef HAVE_TCP_KEEPINTVL + { + .name =3D "keep-alive-interval", + .type =3D QEMU_OPT_NUMBER, + }, +#endif #ifdef HAVE_IPPROTO_MPTCP { .name =3D "mptcp", @@ -695,6 +757,24 @@ int inet_parse(InetSocketAddress *addr, const char *st= r, Error **errp) addr->has_keep_alive =3D true; addr->keep_alive =3D qemu_opt_get_bool(opts, "keep-alive", false); } +#ifdef HAVE_TCP_KEEPCNT + if (qemu_opt_find(opts, "keep-alive-count")) { + addr->has_keep_alive_count =3D true; + addr->keep_alive_count =3D qemu_opt_get_number(opts, "keep-alive-c= ount", 0); + } +#endif +#ifdef HAVE_TCP_KEEPIDLE + if (qemu_opt_find(opts, "keep-alive-idle")) { + addr->has_keep_alive_idle =3D true; + addr->keep_alive_idle =3D qemu_opt_get_number(opts, "keep-alive-id= le", 0); + } +#endif +#ifdef HAVE_TCP_KEEPINTVL + if (qemu_opt_find(opts, "keep-alive-interval")) { + addr->has_keep_alive_interval =3D true; + addr->keep_alive_interval =3D qemu_opt_get_number(opts, "keep-aliv= e-interval", 0); + } +#endif #ifdef HAVE_IPPROTO_MPTCP if (qemu_opt_find(opts, "mptcp")) { addr->has_mptcp =3D true; --=20 2.49.0 From nobody Sat Nov 15 17:47:13 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1747909934; cv=none; d=zohomail.com; s=zohoarc; b=Q3MAq8o9ZYXUVqEXVelacqd0ICUC6EGBS9KOf0ZQPRXU4N0gj71Cq7KzBZPRZuKG4swjoFEr8X5rvobngdF4R1IKkN5H6MotcxPcNyrfEzXYaZ6mZoPVL63hcD8DSGhXzpPgJPMYk/zk7UyYOhJyCTpcL0KAt8ps07ZS/8q0s3M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1747909934; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=p7vnhJt4PdqmsJ+0TYga4Jck+5A3tGiomg44j9XpGHk=; b=ihxMzZOrmJXc65K0WosON4gpnLic4QBjrJfYKTJWfilQE9eDw0FlTUfKHxfE501gKK+7+E69306/kYVp4my2fQIuJ+gSW7jVibVw9iSDET8G+HbOzxCy0glXn6VvzGBPKrCRI9G7EwFJO76bMwxYXz85OBxEoJM173RgMRar8Cw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1747909934813263.7278676288063; Thu, 22 May 2025 03:32:14 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uI3Ca-0004Mm-Bb; Thu, 22 May 2025 06:31:04 -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 1uI3CW-00048u-O6 for qemu-devel@nongnu.org; Thu, 22 May 2025 06:31:01 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uI3CU-0006hw-R5 for qemu-devel@nongnu.org; Thu, 22 May 2025 06:31:00 -0400 Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-673-FQCtsYnmM-GbvOFgBVprdA-1; Thu, 22 May 2025 06:30:53 -0400 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id DB4D919560A0; Thu, 22 May 2025 10:30:52 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.179]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 8E22D1958014; Thu, 22 May 2025 10:30:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1747909856; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=p7vnhJt4PdqmsJ+0TYga4Jck+5A3tGiomg44j9XpGHk=; b=UGdEpE2lMogRrWgE9Z6Epu0TbK4gXri2kkuqA9OBp/N/odwQHV5capG7ekV/FrVrDzYOy1 WB1jBo0IO8BwmDe6dahSuHK68lG2NObSijNRCr+2YtD5NuJRvF6WQS8JLwq8x/GRLKkVam a47rXWKD6qRhX/GAiWC1bf1GUvtRNY0= X-MC-Unique: FQCtsYnmM-GbvOFgBVprdA-1 X-Mimecast-MFC-AGG-ID: FQCtsYnmM-GbvOFgBVprdA_1747909853 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Markus Armbruster , Paolo Bonzini , Eric Blake , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Manos Pitsidianakis Subject: [PULL 23/23] scripts/checkpatch.pl: mandate SPDX tag for Rust src files Date: Thu, 22 May 2025 11:29:23 +0100 Message-ID: <20250522102923.309452-24-berrange@redhat.com> In-Reply-To: <20250522102923.309452-1-berrange@redhat.com> References: <20250522102923.309452-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 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=170.10.129.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.184, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1747909936882116600 Reviewed-by: Manos Pitsidianakis Signed-off-by: Daniel P. Berrang=C3=A9 --- scripts/checkpatch.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 9291bc9209..833f20f555 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -1499,7 +1499,7 @@ sub process_end_of_file { if ($fileinfo->{action} eq "new" && !exists $fileinfo->{facts}->{sawspdx}) { if ($fileinfo->{filenew} =3D~ - /(\.(c|h|py|pl|sh|json|inc)|Makefile.*)$/) { + /(\.(c|h|py|pl|sh|json|inc|rs)|Makefile.*)$/) { # source code files MUST have SPDX license declared ERROR("New file '" . $fileinfo->{filenew} . "' requires 'SPDX-License-Identifier'"); --=20 2.49.0