From nobody Mon Feb 9 00:30:18 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1606489441; cv=none; d=zohomail.com; s=zohoarc; b=mZY/rudbmNeYwKF0p5qI4cF15w2yc8d/FD1U/yaFwvZ6k4ggmZoDQ7wUmJ0J+/TVE7CIJKINXAcsDTW5zEYJMNhlB2UrHyxh9U9TdUzPmOjsV/AqrVwaxo+aoG4X6ymhECwmLkaUJCr6qm/pI1rLBBmE0AjNsCxb/d8WX38O+lc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1606489441; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=eORn8FrfPDBfqvgmr2EojIt4Lizapiy/tgFegk9s8DM=; b=EevSQ22XmemvLX7eE2I8tIiHh7RPLz6k7EXq88KLxv4kySuiSksR16eB4LfGvxRJygwmyXiROg/YZs5y7X0PylV2uAviK+INtjedCz63i13LEERVh9F68/eDUQrX0uqvlfOzOagx0ro6kDtg/x/yv65rVsmkfvzvbeUMYVHd490= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 16064894417111017.7261950091723; Fri, 27 Nov 2020 07:04:01 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-559-zHozvpZZMJOnORkbAJ0pgQ-1; Fri, 27 Nov 2020 10:03:56 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9A0268144EB; Fri, 27 Nov 2020 15:03:50 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 15ADE5C1C2; Fri, 27 Nov 2020 15:03:50 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id A37FF4A7C7; Fri, 27 Nov 2020 15:03:49 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0ARF3muE030629 for ; Fri, 27 Nov 2020 10:03:48 -0500 Received: by smtp.corp.redhat.com (Postfix) id 8CBA85D9E4; Fri, 27 Nov 2020 15:03:48 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.195.47]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8E9CC5D9CC; Fri, 27 Nov 2020 15:03:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1606489438; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=eORn8FrfPDBfqvgmr2EojIt4Lizapiy/tgFegk9s8DM=; b=fQdhn/arFZgT068EZgRG2TdcaavI/XoMd2yoXQLHHhraXbHQ2DiSx/BBAgFgRJ/7k8h3tK b1B5AzUe9CGZZXltFpdjymedeWWCqBC3fNxvYBUDHoU8jTgXdbOoRQiRWwErSTGI6l2j5E FdPYXABAnbXHYfXZsfuc57MHRR4K8cE= X-MC-Unique: zHozvpZZMJOnORkbAJ0pgQ-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v1 02/26] internal.h: Introduce VIR_IS_POW2() Date: Fri, 27 Nov 2020 16:02:48 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Cc: david@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" This macro checks whether given number is an integer power of two. Signed-off-by: Michal Privoznik --- src/internal.h | 10 +++++++++ src/qemu/qemu_validate.c | 46 +++++++++++++++++++++------------------- src/util/virrandom.c | 2 +- 3 files changed, 35 insertions(+), 23 deletions(-) diff --git a/src/internal.h b/src/internal.h index ff94e7e53e..0a03dfc46f 100644 --- a/src/internal.h +++ b/src/internal.h @@ -237,6 +237,16 @@ (a) =3D (a) ^ (b); \ } while (0) =20 + +/** + * VIR_IS_POW2: + * + * Returns true if given number is a power of two + */ +#define VIR_IS_POW2(x) \ + ((x) && !((x) & ((x) - 1))) + + /** * virCheckFlags: * @supported: an OR'ed set of supported flags diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c index e60d39a22f..6f4662b25a 100644 --- a/src/qemu/qemu_validate.c +++ b/src/qemu/qemu_validate.c @@ -1460,20 +1460,32 @@ qemuValidateDomainDeviceDefNetwork(const virDomainN= etDef *net, return -1; } =20 - if (net->driver.virtio.rx_queue_size && - !virQEMUCapsGet(qemuCaps, QEMU_CAPS_VIRTIO_NET_RX_QUEUE_SIZE))= { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("virtio rx_queue_size option is not supported= " - "with this QEMU binary")); - return -1; + if (net->driver.virtio.rx_queue_size) { + if (!VIR_IS_POW2(net->driver.virtio.rx_queue_size)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("rx_queue_size has to be a power of two")= ); + return -1; + } + if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_VIRTIO_NET_RX_QUEUE_SI= ZE)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("virtio rx_queue_size option is not suppo= rted " + "with this QEMU binary")); + return -1; + } } =20 - if (net->driver.virtio.tx_queue_size && - !virQEMUCapsGet(qemuCaps, QEMU_CAPS_VIRTIO_NET_TX_QUEUE_SIZE))= { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("virtio tx_queue_size option is not supported= " - "with this QEMU binary")); - return -1; + if (net->driver.virtio.tx_queue_size) { + if (!VIR_IS_POW2(net->driver.virtio.tx_queue_size)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("tx_queue_size has to be a power of two")= ); + return -1; + } + if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_VIRTIO_NET_TX_QUEUE_SI= ZE)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("virtio tx_queue_size option is not suppo= rted " + "with this QEMU binary")); + return -1; + } } =20 if (net->mtu && @@ -1484,16 +1496,6 @@ qemuValidateDomainDeviceDefNetwork(const virDomainNe= tDef *net, return -1; } =20 - if (net->driver.virtio.rx_queue_size & (net->driver.virtio.rx_queu= e_size - 1)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("rx_queue_size has to be a power of two")); - return -1; - } - if (net->driver.virtio.tx_queue_size & (net->driver.virtio.tx_queu= e_size - 1)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("tx_queue_size has to be a power of two")); - return -1; - } if (qemuValidateDomainVirtioOptions(net->virtio, qemuCaps) < 0) return -1; } diff --git a/src/util/virrandom.c b/src/util/virrandom.c index 6417232e3a..3ae1297e6b 100644 --- a/src/util/virrandom.c +++ b/src/util/virrandom.c @@ -89,7 +89,7 @@ double virRandom(void) */ uint32_t virRandomInt(uint32_t max) { - if ((max & (max - 1)) =3D=3D 0) + if (VIR_IS_POW2(max)) return virRandomBits(__builtin_ffs(max) - 1); =20 return virRandom() * max; --=20 2.26.2