From nobody Mon May 6 08:14:37 2024 Delivered-To: importer@patchew.org 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; Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1585661008; cv=none; d=zohomail.com; s=zohoarc; b=JXgCtlp037mJ+epxn5WXYd5ooATjGKNA7Y+G1rn3ShMxmgeSteX64S6PuC3EcUkq4gNAfN7YaNmRCVFxYWSfrqt3VFeDbRB4R3zmsFgBvlWhsuuvvQgqGqfGU6yAq5XeqcgZvcRKkHZvdTAOtQYyF+gnsEok94FfvCQhbd3Xk9c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585661008; 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=ZBpdFRO5rJLxNzdJEGO4mRvZn0CjlnODLs22OFn9v5M=; b=OhN43r1BGdKu+1t0s6DWQnSnhRMzjG1ftkpkPlpMVJqhudkjnJzB7FudhnDiMZQkqeSKgI8Iw6OH0VXZtq6v9k/kVfJd2SksaQGcpZAInqUv6vIi661EEylakconaNoBSGU+fG+fN3yjxGWpcZJmS6OKFrQ6mjTfkIdiB8Lov5I= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1585661008931616.9734659268124; Tue, 31 Mar 2020 06:23:28 -0700 (PDT) Received: from localhost ([::1]:37946 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJGrX-0001Xh-Na for importer@patchew.org; Tue, 31 Mar 2020 09:23:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41894) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJGq6-0000Dn-9y for qemu-devel@nongnu.org; Tue, 31 Mar 2020 09:21:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jJGq4-0005f2-Ov for qemu-devel@nongnu.org; Tue, 31 Mar 2020 09:21:58 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:51286 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jJGq4-0005eT-L5 for qemu-devel@nongnu.org; Tue, 31 Mar 2020 09:21:56 -0400 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-17-zA7sR0JSPBy_C_IDipAI3g-1; Tue, 31 Mar 2020 09:21:53 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9531F18FE861; Tue, 31 Mar 2020 13:21:52 +0000 (UTC) Received: from jason-ThinkPad-T430s.redhat.com (ovpn-12-118.pek2.redhat.com [10.72.12.118]) by smtp.corp.redhat.com (Postfix) with ESMTP id DE37D10002BC; Tue, 31 Mar 2020 13:21:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1585660915; 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=ZBpdFRO5rJLxNzdJEGO4mRvZn0CjlnODLs22OFn9v5M=; b=euU3SIy9NL2CebxGz8cIibVkjNe3SjBS8xxYXBJIvcib+Rrr4u5xpSF37SVDGy61yGJzzk 1mRT12iP3CqP6UUz2cpBDf3uvEFuKWXCLBqfd2T+MrPKKTYFGulHwFfWLySp/TjhrGBN66 2fqJIpQ5+PEIrrhs2SluxrHkge8Uqw4= X-MC-Unique: zA7sR0JSPBy_C_IDipAI3g-1 From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Subject: [PULL V2 01/14] hw/net/i82596: Correct command bitmask (CID 1419392) Date: Tue, 31 Mar 2020 21:21:26 +0800 Message-Id: <1585660899-11228-2-git-send-email-jasowang@redhat.com> In-Reply-To: <1585660899-11228-1-git-send-email-jasowang@redhat.com> References: <1585660899-11228-1-git-send-email-jasowang@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.81 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jason Wang , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Philippe Mathieu-Daud=C3=A9 The command is 32-bit, but we are loading the 16 upper bits with the 'get_uint16(s->scb + 2)' call. Once shifted by 16, the command bits match the status bits: - Command Bit 31 ACK-CX Acknowledges that the CU completed an Action Command. Bit 30 ACK-FR Acknowledges that the RU received a frame. Bit 29 ACK-CNA Acknowledges that the Command Unit became not active. Bit 28 ACK-RNR Acknowledges that the Receive Unit became not ready. - Status Bit 15 CX The CU finished executing a command with its I(interrupt)= bit set. Bit 14 FR The RU finished receiving a frame. Bit 13 CNA The Command Unit left the Active state. Bit 12 RNR The Receive Unit left the Ready state. Add the SCB_COMMAND_ACK_MASK definition to simplify the code. This fixes Coverity 1419392 (CONSTANT_EXPRESSION_RESULT): /hw/net/i82596.c: 352 in examine_scb() 346 cuc =3D (command >> 8) & 0x7; 347 ruc =3D (command >> 4) & 0x7; 348 DBG(printf("MAIN COMMAND %04x cuc %02x ruc %02x\n", command,= cuc, ruc)); 349 /* and clear the scb command word */ 350 set_uint16(s->scb + 2, 0); 351 >>> CID 1419392: (CONSTANT_EXPRESSION_RESULT) >>> "command & (2147483648UL /* 1UL << 31 */)" is always 0 regardless= of the values of its operands. This occurs as the logical operand of "if". 352 if (command & BIT(31)) /* ACK-CX */ 353 s->scb_status &=3D ~SCB_STATUS_CX; >>> CID 1419392: (CONSTANT_EXPRESSION_RESULT) >>> "command & (1073741824UL /* 1UL << 30 */)" is always 0 regardless= of the values of its operands. This occurs as the logical operand of "if". 354 if (command & BIT(30)) /*ACK-FR */ 355 s->scb_status &=3D ~SCB_STATUS_FR; >>> CID 1419392: (CONSTANT_EXPRESSION_RESULT) >>> "command & (536870912UL /* 1UL << 29 */)" is always 0 regardless = of the values of its operands. This occurs as the logical operand of "if". 356 if (command & BIT(29)) /*ACK-CNA */ 357 s->scb_status &=3D ~SCB_STATUS_CNA; >>> CID 1419392: (CONSTANT_EXPRESSION_RESULT) >>> "command & (268435456UL /* 1UL << 28 */)" is always 0 regardless = of the values of its operands. This occurs as the logical operand of "if". 358 if (command & BIT(28)) /*ACK-RNR */ 359 s->scb_status &=3D ~SCB_STATUS_RNR; Fixes: Covertiy CID 1419392 (commit 376b851909) Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Peter Maydell Signed-off-by: Jason Wang --- hw/net/i82596.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/hw/net/i82596.c b/hw/net/i82596.c index fe9f239..ecdb9aa 100644 --- a/hw/net/i82596.c +++ b/hw/net/i82596.c @@ -43,6 +43,9 @@ #define SCB_STATUS_CNA 0x2000 /* CU left active state */ #define SCB_STATUS_RNR 0x1000 /* RU left active state */ =20 +#define SCB_COMMAND_ACK_MASK \ + (SCB_STATUS_CX | SCB_STATUS_FR | SCB_STATUS_CNA | SCB_STATUS_RNR) + #define CU_IDLE 0 #define CU_SUSPENDED 1 #define CU_ACTIVE 2 @@ -348,14 +351,7 @@ static void examine_scb(I82596State *s) /* and clear the scb command word */ set_uint16(s->scb + 2, 0); =20 - if (command & BIT(31)) /* ACK-CX */ - s->scb_status &=3D ~SCB_STATUS_CX; - if (command & BIT(30)) /*ACK-FR */ - s->scb_status &=3D ~SCB_STATUS_FR; - if (command & BIT(29)) /*ACK-CNA */ - s->scb_status &=3D ~SCB_STATUS_CNA; - if (command & BIT(28)) /*ACK-RNR */ - s->scb_status &=3D ~SCB_STATUS_RNR; + s->scb_status &=3D ~(command & SCB_COMMAND_ACK_MASK); =20 switch (cuc) { case 0: /* no change */ --=20 2.5.0 From nobody Mon May 6 08:14:37 2024 Delivered-To: importer@patchew.org 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; 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=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1585661203; cv=none; d=zohomail.com; s=zohoarc; b=SkjgpVOp4+pKRRo4duxtvfgc1c6WrKqJ+rsombJq2z0bCWST2j5L1G7st4On/DafONyL1QvTS/tAjvr/skvJvL3q7G0AglFLOMbfEYXLX4UM0eIpukOSpXjycyhJ1lwMDlMvEYKPMxuAw5VdhF1ufLbHbADIUJMg58ijtnKwCxA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585661203; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=tVkaJTRjt24I8sG8iS1Qlco78c4FvepcndOUPlDQIGU=; b=JHESGu+itBT+b+HisiuAIMZTfrZzbc8GSaH7Un9ZZvJNxKOJpZPEazRJ5jB9d19OWDtQ18x/COvhA5vlAOXZhKSuUMRjsnpvVGGLTfgdmx7yaMJh9dajK1Oc63qEp6hnL4w3T0CTCfcpb0DIxm68HwAhD2NaJI0rBS9qyAK8F5Q= 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=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1585661203338792.9042542895519; Tue, 31 Mar 2020 06:26:43 -0700 (PDT) Received: from localhost ([::1]:38014 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJGug-0007g4-5P for importer@patchew.org; Tue, 31 Mar 2020 09:26:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41909) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJGq7-0000EY-77 for qemu-devel@nongnu.org; Tue, 31 Mar 2020 09:22:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jJGq5-0005fg-Pa for qemu-devel@nongnu.org; Tue, 31 Mar 2020 09:21:59 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:42836 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jJGq5-0005fL-L9 for qemu-devel@nongnu.org; Tue, 31 Mar 2020 09:21:57 -0400 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-41-2rmRCDZePc--G56XQiIJ7Q-1; Tue, 31 Mar 2020 09:21:55 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7E6531412; Tue, 31 Mar 2020 13:21:54 +0000 (UTC) Received: from jason-ThinkPad-T430s.redhat.com (ovpn-12-118.pek2.redhat.com [10.72.12.118]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1DB9110002BC; Tue, 31 Mar 2020 13:21:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1585660917; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tVkaJTRjt24I8sG8iS1Qlco78c4FvepcndOUPlDQIGU=; b=VHS98x/eEUvqGwtegn7v53a5wdvCWPaAVX0029AjkijQZPrfUM9Mm4+ZG2g9x/r4wGuJc+ DUXthrMG5Z4im4H5xvN/NNG8DFTP8+0F3FuX+tQK18SaYPtXEZD0Vev/vUYoy0m7EW4zdt /UhguZMEy7GXa0xLFn5bBvqAdjkmTXQ= X-MC-Unique: 2rmRCDZePc--G56XQiIJ7Q-1 From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Subject: [PULL V2 02/14] hw/net/i82596.c: Avoid reading off end of buffer in i82596_receive() Date: Tue, 31 Mar 2020 21:21:27 +0800 Message-Id: <1585660899-11228-3-git-send-email-jasowang@redhat.com> In-Reply-To: <1585660899-11228-1-git-send-email-jasowang@redhat.com> References: <1585660899-11228-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.81 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jason Wang Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Peter Maydell The i82596_receive() function attempts to pass the guest a buffer which is effectively the concatenation of the data it is passed and a 4 byte CRC value. However, rather than implementing this as "write the data; then write the CRC" it instead bumps the length value of the data by 4, and writes 4 extra bytes from beyond the end of the buffer, which it then overwrites with the CRC. It also assumed that we could always fit all four bytes of the CRC into the final receive buffer, which might not be true if the CRC needs to be split over two receive buffers. Calculate separately how many bytes we need to transfer into the guest's receive buffer from the source buffer, and how many we need to transfer from the CRC work. We add a count 'bufsz' of the number of bytes left in the source buffer, which we use purely to assert() that we don't overrun. Spotted by Coverity (CID 1419396) for the specific case when we end up using a local array as the source buffer. Signed-off-by: Peter Maydell Signed-off-by: Jason Wang --- hw/net/i82596.c | 44 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/hw/net/i82596.c b/hw/net/i82596.c index ecdb9aa..3b0efd0 100644 --- a/hw/net/i82596.c +++ b/hw/net/i82596.c @@ -497,7 +497,8 @@ ssize_t i82596_receive(NetClientState *nc, const uint8_= t *buf, size_t sz) uint32_t rfd_p; uint32_t rbd; uint16_t is_broadcast =3D 0; - size_t len =3D sz; + size_t len =3D sz; /* length of data for guest (including CRC) */ + size_t bufsz =3D sz; /* length of data in buf */ uint32_t crc; uint8_t *crc_ptr; uint8_t buf1[MIN_BUF_SIZE + VLAN_HLEN]; @@ -591,6 +592,7 @@ ssize_t i82596_receive(NetClientState *nc, const uint8_= t *buf, size_t sz) if (len < MIN_BUF_SIZE) { len =3D MIN_BUF_SIZE; } + bufsz =3D len; } =20 /* Calculate the ethernet checksum (4 bytes) */ @@ -623,6 +625,7 @@ ssize_t i82596_receive(NetClientState *nc, const uint8_= t *buf, size_t sz) while (len) { uint16_t buffer_size, num; uint32_t rba; + size_t bufcount, crccount; =20 /* printf("Receive: rbd is %08x\n", rbd); */ buffer_size =3D get_uint16(rbd + 12); @@ -635,14 +638,37 @@ ssize_t i82596_receive(NetClientState *nc, const uint= 8_t *buf, size_t sz) } rba =3D get_uint32(rbd + 8); /* printf("rba is 0x%x\n", rba); */ - address_space_write(&address_space_memory, rba, - MEMTXATTRS_UNSPECIFIED, buf, num); - rba +=3D num; - buf +=3D num; - len -=3D num; - if (len =3D=3D 0) { /* copy crc */ - address_space_write(&address_space_memory, rba - 4, - MEMTXATTRS_UNSPECIFIED, crc_ptr, 4); + /* + * Calculate how many bytes we want from buf[] and how many + * from the CRC. + */ + if ((len - num) >=3D 4) { + /* The whole guest buffer, we haven't hit the CRC yet */ + bufcount =3D num; + } else { + /* All that's left of buf[] */ + bufcount =3D len - 4; + } + crccount =3D num - bufcount; + + if (bufcount > 0) { + /* Still some of the actual data buffer to transfer */ + assert(bufsz >=3D bufcount); + bufsz -=3D bufcount; + address_space_write(&address_space_memory, rba, + MEMTXATTRS_UNSPECIFIED, buf, bufcount); + rba +=3D bufcount; + buf +=3D bufcount; + len -=3D bufcount; + } + + /* Write as much of the CRC as fits */ + if (crccount > 0) { + address_space_write(&address_space_memory, rba, + MEMTXATTRS_UNSPECIFIED, crc_ptr, crcco= unt); + rba +=3D crccount; + crc_ptr +=3D crccount; + len -=3D crccount; } =20 num |=3D 0x4000; /* set F BIT */ --=20 2.5.0 From nobody Mon May 6 08:14:37 2024 Delivered-To: importer@patchew.org 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; 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=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1585661019; cv=none; d=zohomail.com; s=zohoarc; b=g9LQQmlJYoGP0+tq1YfBWGU1AdylmRSbQsyPvHKUi3n25wP4Z/XDXRoIBw1JLSn/sYNuv73gisxhrMZHavMoJDh+Cy2AENrMQOu2fjZggGTPg0TUr5pb3pamXCfLcZSpKxZI86szRlzL3RO9A8pIhTXXaG0OwdQV5aHO4Key6Y4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585661019; 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=paXF4BUdtUbKk4eCMDfsD2R4BGRN/BEYl8hEBt1HBS4=; b=b2xK98he6z+mjIQQHU6yRIYuObhhd3oxpMX+bhFtg6sk/FDaitNBaFL0mcWeloX2SCbvLJgFzRoqK8ci16m0vwtClJTqyHvFJ1OS+0D9y7eieZlsFRdnO6lv1BmGQMUb+rb+sy9iowz6fsR6y7wRfWuUSHYLbI/EF/4FYKmrzrg= 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=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1585661019959918.4345016182837; Tue, 31 Mar 2020 06:23:39 -0700 (PDT) Received: from localhost ([::1]:37948 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJGri-0001fa-Jt for importer@patchew.org; Tue, 31 Mar 2020 09:23:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41932) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJGq9-0000FS-MZ for qemu-devel@nongnu.org; Tue, 31 Mar 2020 09:22:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jJGq8-0005iQ-C0 for qemu-devel@nongnu.org; Tue, 31 Mar 2020 09:22:01 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:29773 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jJGq8-0005i6-7s for qemu-devel@nongnu.org; Tue, 31 Mar 2020 09:22:00 -0400 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-113-EFrCcvZlNki-QVctvAWQ9A-1; Tue, 31 Mar 2020 09:21:57 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B0DBA1137841; Tue, 31 Mar 2020 13:21:56 +0000 (UTC) Received: from jason-ThinkPad-T430s.redhat.com (ovpn-12-118.pek2.redhat.com [10.72.12.118]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0A2E61001B28; Tue, 31 Mar 2020 13:21:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1585660919; 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=paXF4BUdtUbKk4eCMDfsD2R4BGRN/BEYl8hEBt1HBS4=; b=fPxbyrut+b70IPKRrsK2cIInBucepcS1GPr7e+5b8cBxw2JEkcSRNjfoFsqpH+3M4BF+eU jKkvxBHruRP0tcGIxk0TkhH8HbgqxqADgUr6ix3UB1Tvz06eQkoi5JH75U1mE9KUdMlCRL QkKjFgCn4L2O50KpqmKbdlBV8tO4Gc0= X-MC-Unique: EFrCcvZlNki-QVctvAWQ9A-1 From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Subject: [PULL V2 03/14] Fixed integer overflow in e1000e Date: Tue, 31 Mar 2020 21:21:28 +0800 Message-Id: <1585660899-11228-4-git-send-email-jasowang@redhat.com> In-Reply-To: <1585660899-11228-1-git-send-email-jasowang@redhat.com> References: <1585660899-11228-1-git-send-email-jasowang@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Andrew Melnychenko , Jason Wang Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Andrew Melnychenko Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=3D1737400 Fixed setting max_queue_num if there are no peers in NICConf. qemu_new_nic() creates NICState with 1 NetClientState(index 0) without peers, set max_queue_num to 0 - It prevents undefined behavior and possible crashes, especially during pcie hotplug. Fixes: 6f3fbe4ed06 ("net: Introduce e1000e device emulation") Signed-off-by: Andrew Melnychenko Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Dmitry Fleytman Signed-off-by: Jason Wang --- hw/net/e1000e.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/net/e1000e.c b/hw/net/e1000e.c index a91dbdc..f2cc155 100644 --- a/hw/net/e1000e.c +++ b/hw/net/e1000e.c @@ -328,7 +328,7 @@ e1000e_init_net_peer(E1000EState *s, PCIDevice *pci_dev= , uint8_t *macaddr) s->nic =3D qemu_new_nic(&net_e1000e_info, &s->conf, object_get_typename(OBJECT(s)), dev->id, s); =20 - s->core.max_queue_num =3D s->conf.peers.queues - 1; + s->core.max_queue_num =3D s->conf.peers.queues ? s->conf.peers.queues = - 1 : 0; =20 trace_e1000e_mac_set_permanent(MAC_ARG(macaddr)); memcpy(s->core.permanent_mac, macaddr, sizeof(s->core.permanent_mac)); --=20 2.5.0 From nobody Mon May 6 08:14:37 2024 Delivered-To: importer@patchew.org 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; Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1585661152; cv=none; d=zohomail.com; s=zohoarc; b=UUIawvwP/eGGOrtIYxS2p/THmRR+10z8RyvKdIuSOFOxrILAj5l6TbZ2vqH82lZpjlRavj7RtqRl6guiOeijiEjC0TyDicW3fZAVH8Vw/ZPcBAO/q0WUBfrzAUsWTIqEP9o/H6DvhURdGMLiSEP+uwOioXNj7S4Q41lSskdVA+Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585661152; 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=UFzfJ32hrPYJEd61wip0J7pOl2Rd8tBOdRTwul4UXXQ=; b=myaBLXoIOzkCgE4yHH8XpRZWBU6KBeC6W9l0Ff8Qei4myxUUBhJEsiI7bIBNl4HiO1sgzAIAOdrKdoKnGkGaSa4t2QaYpTpbgoQVHj4MgtYJ6oJDsdfsjxpKuZVEb1Yy67ggvQfG3hFggHTgs8A6RYKziO+EadvSreSwdUuoL8A= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1585661152954677.2961469939684; Tue, 31 Mar 2020 06:25:52 -0700 (PDT) Received: from localhost ([::1]:37998 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJGtr-0006Jr-MC for importer@patchew.org; Tue, 31 Mar 2020 09:25:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41955) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJGqD-0000I1-7T for qemu-devel@nongnu.org; Tue, 31 Mar 2020 09:22:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jJGqA-0005jf-43 for qemu-devel@nongnu.org; Tue, 31 Mar 2020 09:22:04 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:51271 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jJGq9-0005jG-Ve for qemu-devel@nongnu.org; Tue, 31 Mar 2020 09:22:02 -0400 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-259--RUOYE2dN7SMVad5l9s_rg-1; Tue, 31 Mar 2020 09:21:59 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DA4E58017CC; Tue, 31 Mar 2020 13:21:58 +0000 (UTC) Received: from jason-ThinkPad-T430s.redhat.com (ovpn-12-118.pek2.redhat.com [10.72.12.118]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3B06C1036D00; Tue, 31 Mar 2020 13:21:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1585660921; 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=UFzfJ32hrPYJEd61wip0J7pOl2Rd8tBOdRTwul4UXXQ=; b=HwyjC+g1w49TsKVxUAHzr8Wf73zgWS1Ptf3QgQAgxwEGiOeGwFLpyYUJJtF+Zf7violnih ERvfGb5rr3ZERHYVDQH0OvbaU2aki8RJZsCTdGtntDUNlOV0IP8gXHpRuA0mw98BWu8CEF tG3FLaUiaiAfw247HFMxVSd+nrA32Ao= X-MC-Unique: -RUOYE2dN7SMVad5l9s_rg-1 From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Subject: [PULL V2 04/14] hw/net/e1000e_core: Let e1000e_can_receive() return a boolean Date: Tue, 31 Mar 2020 21:21:29 +0800 Message-Id: <1585660899-11228-5-git-send-email-jasowang@redhat.com> In-Reply-To: <1585660899-11228-1-git-send-email-jasowang@redhat.com> References: <1585660899-11228-1-git-send-email-jasowang@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.81 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jason Wang , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Philippe Mathieu-Daud=C3=A9 The e1000e_can_receive() function simply returns a boolean value. Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Alistair Francis Reviewed-by: Paolo Bonzini Signed-off-by: Jason Wang --- hw/net/e1000e_core.c | 2 +- hw/net/e1000e_core.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/net/e1000e_core.c b/hw/net/e1000e_core.c index df957e0..d567687 100644 --- a/hw/net/e1000e_core.c +++ b/hw/net/e1000e_core.c @@ -967,7 +967,7 @@ e1000e_start_recv(E1000ECore *core) } } =20 -int +bool e1000e_can_receive(E1000ECore *core) { int i; diff --git a/hw/net/e1000e_core.h b/hw/net/e1000e_core.h index 49abb13..aee32f7 100644 --- a/hw/net/e1000e_core.h +++ b/hw/net/e1000e_core.h @@ -143,7 +143,7 @@ e1000e_core_set_link_status(E1000ECore *core); void e1000e_core_pci_uninit(E1000ECore *core); =20 -int +bool e1000e_can_receive(E1000ECore *core); =20 ssize_t --=20 2.5.0 From nobody Mon May 6 08:14:37 2024 Delivered-To: importer@patchew.org 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; Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1585661245; cv=none; d=zohomail.com; s=zohoarc; b=PqCBQm7rhYCB9gBwLzvbcG4VP/aZOPV+nIfFfVbntqEFycnUbBagvwbxuJwyYlfMfF3TsbeDP6sjCwJ13iF4iWBW4zutXrCVPBwUv8Yhg8hfVZlxLmTKOciwWCIYZ7yHlXX+ZArCzWBMbNioWUWZSEYFjBIz90hYOiw8cNn1NJg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585661245; 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=n8HmSTm9WnCU4dZKskIiwKW5MV+WGIgJj9Ow7s72VtQ=; b=TseNSBXpPbaJ1Px1gECXt7UYOp438Jt+evuK3KzKE9yx1Qf6o1kSqLXN2CPCzaLuo49cb468WbVbZF+rUCGWDs3NWeXUA5i4y87qnyw4qusJsDlAvvRVOmTL0FqtYCIbWSeVbh5bmzTDdf6qloP+p7aD+iJ2EcuNrpwcWS1sFpw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1585661245516357.4526893709916; Tue, 31 Mar 2020 06:27:25 -0700 (PDT) Received: from localhost ([::1]:38018 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJGvM-0000UB-Bd for importer@patchew.org; Tue, 31 Mar 2020 09:27:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41975) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJGqF-0000I8-2J for qemu-devel@nongnu.org; Tue, 31 Mar 2020 09:22:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jJGqD-0005lE-KX for qemu-devel@nongnu.org; Tue, 31 Mar 2020 09:22:06 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:44367 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jJGqD-0005kc-H9 for qemu-devel@nongnu.org; Tue, 31 Mar 2020 09:22:05 -0400 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-64-9hi62n6oOYGbecItYSsOqg-1; Tue, 31 Mar 2020 09:22:01 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 10E7C1052BA7; Tue, 31 Mar 2020 13:22:01 +0000 (UTC) Received: from jason-ThinkPad-T430s.redhat.com (ovpn-12-118.pek2.redhat.com [10.72.12.118]) by smtp.corp.redhat.com (Postfix) with ESMTP id 650C91036D00; Tue, 31 Mar 2020 13:21:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1585660924; 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=n8HmSTm9WnCU4dZKskIiwKW5MV+WGIgJj9Ow7s72VtQ=; b=Z7JcdjQHIGcwtQ/GJRKlkp2YpxPmSxY5/eXsKvXXzKAK8H8eUhEgI+xOV+/0ds0pGsF6d8 8xsINY/mPGN/zrKjzDSiHszyPAKskIUJtL2/WoJLKS7ncVvRLXNsWPcTRHeS4DDtVd43oR UJZRPf5KUaYbjoP/ebZ+rRByxvlBg3Y= X-MC-Unique: 9hi62n6oOYGbecItYSsOqg-1 From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Subject: [PULL V2 05/14] hw/net/smc91c111: Let smc91c111_can_receive() return a boolean Date: Tue, 31 Mar 2020 21:21:30 +0800 Message-Id: <1585660899-11228-6-git-send-email-jasowang@redhat.com> In-Reply-To: <1585660899-11228-1-git-send-email-jasowang@redhat.com> References: <1585660899-11228-1-git-send-email-jasowang@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jason Wang , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Philippe Mathieu-Daud=C3=A9 The smc91c111_can_receive() function simply returns a boolean value. Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Alistair Francis Reviewed-by: C=C3=A9dric Le Goater Signed-off-by: Jason Wang --- hw/net/smc91c111.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/hw/net/smc91c111.c b/hw/net/smc91c111.c index e9eb6f6..02be60c 100644 --- a/hw/net/smc91c111.c +++ b/hw/net/smc91c111.c @@ -130,16 +130,16 @@ static void smc91c111_update(smc91c111_state *s) qemu_set_irq(s->irq, level); } =20 -static int smc91c111_can_receive(smc91c111_state *s) +static bool smc91c111_can_receive(smc91c111_state *s) { if ((s->rcr & RCR_RXEN) =3D=3D 0 || (s->rcr & RCR_SOFT_RST)) { - return 1; + return true; } if (s->allocated =3D=3D (1 << NUM_PACKETS) - 1 || s->rx_fifo_len =3D=3D NUM_PACKETS) { - return 0; + return false; } - return 1; + return true; } =20 static inline void smc91c111_flush_queued_packets(smc91c111_state *s) --=20 2.5.0 From nobody Mon May 6 08:14:37 2024 Delivered-To: importer@patchew.org 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; Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1585661297; cv=none; d=zohomail.com; s=zohoarc; b=bSMqIeoRnUx0Zm0kup9fJut/kgHlGLQ4KR44Hp5Er34IeMazNlHjnSSm9yPkbx7GWsGU+uiUB8ppl9/kc1zCOzdC4kRDCX2ExieL7hOqhtcsQQTLFzu1efiEwLBK4HgqZ7kN6AoAaxGQyCODa6VWjrmREEWxLjbkj+wQPGHcbuA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585661297; 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=Vr+3UYJLFSKZG8ktFtie/vjm4Z4gRJhmEP9NL974v7c=; b=Cva6NOpWnDDM8Glw2eimaQurThMogNiWQQrPEF0MrPPXCkZwLcSuJi4t1nExB+oTeari51/9WSM2Xt238Cr4Ji0qtzIYy3KcBtiLQH77jAFVGCvwbSpeFoGHPJNiySMp/Flc8dr8yFsMiKBanACFAPPyJENgArs0bUPee/Faj1U= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1585661297273794.1572942697453; Tue, 31 Mar 2020 06:28:17 -0700 (PDT) Received: from localhost ([::1]:38032 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJGwC-0001s4-2Y for importer@patchew.org; Tue, 31 Mar 2020 09:28:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41993) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJGqG-0000KQ-55 for qemu-devel@nongnu.org; Tue, 31 Mar 2020 09:22:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jJGqF-0005mA-1h for qemu-devel@nongnu.org; Tue, 31 Mar 2020 09:22:08 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:24236 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jJGqE-0005lY-Ag for qemu-devel@nongnu.org; Tue, 31 Mar 2020 09:22:07 -0400 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-100-lj0_-5pLPJuguTByGOWBaA-1; Tue, 31 Mar 2020 09:22:04 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3F353801E74; Tue, 31 Mar 2020 13:22:03 +0000 (UTC) Received: from jason-ThinkPad-T430s.redhat.com (ovpn-12-118.pek2.redhat.com [10.72.12.118]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8FBE210002B5; Tue, 31 Mar 2020 13:22:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1585660926; 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=Vr+3UYJLFSKZG8ktFtie/vjm4Z4gRJhmEP9NL974v7c=; b=Jh+rhCaVHTsOCbfYiBo3eNbwpj6DqeMaV/TjNL5P7odqLret2Gmuu1RRkmzyyUtiPg0V4x nJe5fuhQRBahyoCe90+jHFlywhY+XbA2JzVLbsmESEqiqGtvGyhwgTWNFq4MXcJ7nZYFIo okflmnUtZK7AnZ9QTAF8CsyrAe0lsHY= X-MC-Unique: lj0_-5pLPJuguTByGOWBaA-1 From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Subject: [PULL V2 06/14] hw/net/rtl8139: Simplify if/else statement Date: Tue, 31 Mar 2020 21:21:31 +0800 Message-Id: <1585660899-11228-7-git-send-email-jasowang@redhat.com> In-Reply-To: <1585660899-11228-1-git-send-email-jasowang@redhat.com> References: <1585660899-11228-1-git-send-email-jasowang@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jason Wang , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Philippe Mathieu-Daud=C3=A9 Rewrite: if (E) { return A; } else { return B; } /* EOF */ } as: if (E) { return A; } return B; } Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Alistair Francis Reviewed-by: C=C3=A9dric Le Goater Signed-off-by: Jason Wang --- hw/net/rtl8139.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/hw/net/rtl8139.c b/hw/net/rtl8139.c index ae4739b..ef32115 100644 --- a/hw/net/rtl8139.c +++ b/hw/net/rtl8139.c @@ -808,11 +808,11 @@ static int rtl8139_can_receive(NetClientState *nc) /* ??? Flow control not implemented in c+ mode. This is a hack to work around slirp deficiencies anyway. */ return 1; - } else { - avail =3D MOD2(s->RxBufferSize + s->RxBufPtr - s->RxBufAddr, - s->RxBufferSize); - return (avail =3D=3D 0 || avail >=3D 1514 || (s->IntrMask & RxOver= flow)); } + + avail =3D MOD2(s->RxBufferSize + s->RxBufPtr - s->RxBufAddr, + s->RxBufferSize); + return avail =3D=3D 0 || avail >=3D 1514 || (s->IntrMask & RxOverflow); } =20 static ssize_t rtl8139_do_receive(NetClientState *nc, const uint8_t *buf, = size_t size_, int do_interrupt) --=20 2.5.0 From nobody Mon May 6 08:14:37 2024 Delivered-To: importer@patchew.org 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; Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1585661381; cv=none; d=zohomail.com; s=zohoarc; b=Rh9mM/nJdRqPxZLyv4/cyxEzdolL7/9knDEpZM5REYY4KHUNekILY2qCSnO9TopPoQ/mdDBeSLNLmG14l1euQOq+1ehVZsRvNSrrddqCiTa51annKUAbyU6ggwCe9wzNXZqCd6VVLEbLvS+MNq18494EC1ndoP/7PN3CMPuO3BU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585661381; 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=F7lsvVfDt43GLXQvzT5ILRR0yj/AariZe663BO1vf+Y=; b=F/sV5CO9P28T6ywDsD2BFloQLolxD/tWZ9ynAS307zUbL9nPEjndGR2TUF9Fi2yiTVrt5TNwGJoPkZGaKvgQT3C9L7WsirBifJsvDvt6ZLE9Rhi+0W+l6XRmRS1VLt7AmKVZhXJHI7bH5g2ku6jzypXVlHpkG/nZxkxyFIwh6T4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1585661381120738.9513127685882; Tue, 31 Mar 2020 06:29:41 -0700 (PDT) Received: from localhost ([::1]:38048 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJGxX-0004wh-RT for importer@patchew.org; Tue, 31 Mar 2020 09:29:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42010) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJGqI-0000Og-2b for qemu-devel@nongnu.org; Tue, 31 Mar 2020 09:22:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jJGqG-0005nT-UM for qemu-devel@nongnu.org; Tue, 31 Mar 2020 09:22:09 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:42299 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jJGqG-0005nH-QU for qemu-devel@nongnu.org; Tue, 31 Mar 2020 09:22:08 -0400 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-71-Lpnda-IFOdmRe6oEj87zyQ-1; Tue, 31 Mar 2020 09:22:06 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 69440107ACC7; Tue, 31 Mar 2020 13:22:05 +0000 (UTC) Received: from jason-ThinkPad-T430s.redhat.com (ovpn-12-118.pek2.redhat.com [10.72.12.118]) by smtp.corp.redhat.com (Postfix) with ESMTP id BA96F10002B5; Tue, 31 Mar 2020 13:22:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1585660928; 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=F7lsvVfDt43GLXQvzT5ILRR0yj/AariZe663BO1vf+Y=; b=WXBoajj9R3NFkOfXFZSF4PXE4mxGafwnIbVXmBhSVkVSb5wt86w2XsL4p6Twzuo1XqNxK8 Qt//aJkBbHDfDumU0A9JVzWn/o3uC/HjNbYzpg+gojfJGvZNrpflDw6wuO2cLUn7nHenFP G4DxQWtzv5e+9D0GadHAUfDZEiHBW6Y= X-MC-Unique: Lpnda-IFOdmRe6oEj87zyQ-1 From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Subject: [PULL V2 07/14] hw/net/rtl8139: Update coding style to make checkpatch.pl happy Date: Tue, 31 Mar 2020 21:21:32 +0800 Message-Id: <1585660899-11228-8-git-send-email-jasowang@redhat.com> In-Reply-To: <1585660899-11228-1-git-send-email-jasowang@redhat.com> References: <1585660899-11228-1-git-send-email-jasowang@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jason Wang , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Philippe Mathieu-Daud=C3=A9 We will modify this code in the next commit. Clean it up first to avoid checkpatch.pl errors. Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Alistair Francis Reviewed-by: C=C3=A9dric Le Goater Signed-off-by: Jason Wang --- hw/net/rtl8139.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/hw/net/rtl8139.c b/hw/net/rtl8139.c index ef32115..be9a0af 100644 --- a/hw/net/rtl8139.c +++ b/hw/net/rtl8139.c @@ -799,10 +799,12 @@ static int rtl8139_can_receive(NetClientState *nc) int avail; =20 /* Receive (drop) packets if card is disabled. */ - if (!s->clock_enabled) - return 1; - if (!rtl8139_receiver_enabled(s)) - return 1; + if (!s->clock_enabled) { + return 1; + } + if (!rtl8139_receiver_enabled(s)) { + return 1; + } =20 if (rtl8139_cp_receiver_enabled(s) && rtl8139_cp_rx_valid(s)) { /* ??? Flow control not implemented in c+ mode. --=20 2.5.0 From nobody Mon May 6 08:14:37 2024 Delivered-To: importer@patchew.org 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; Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1585661339; cv=none; d=zohomail.com; s=zohoarc; b=feduUrECu1c1kwdG+2o4mnlnxPyibpIO6GIZyO0in9+x33FIMGrp05HS9xNv/IItnn5YlmqNajpnXDIsJ90PfdSMUbd1xS0UXewcv2kEkdEmMzR5HUaHfY+Tpc/Vs4AgBL/60VyB7tdrF6PYOzYD65t0Z62S87Sljo3YB8Hstq4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585661339; 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=yaOwtgmOb1WJgAzFCsAuhnSvk3thhHf/hjpROiOzOAM=; b=cR7bWSt+1v+MHc/2oGVdOUeHRX3i9+79wEwwZL3UAd7tZY50+Qmf5oFKOcaN+hOoOBwq6lJEJmatZKDbHyn23wrlhEljLDPTBYxTGeNTL8SE1mVsJkXymQqiLLufYSEsT/EOumS4MZwZEhYgbIB/li2U7LOMEdt0G/YrxgqSjV4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1585661339580238.70413274640146; Tue, 31 Mar 2020 06:28:59 -0700 (PDT) Received: from localhost ([::1]:38036 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJGwr-0003c4-55 for importer@patchew.org; Tue, 31 Mar 2020 09:28:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42046) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJGqS-0000Xk-Fk for qemu-devel@nongnu.org; Tue, 31 Mar 2020 09:22:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jJGqN-0005rE-Nl for qemu-devel@nongnu.org; Tue, 31 Mar 2020 09:22:20 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:32625 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jJGqN-0005qu-Hf for qemu-devel@nongnu.org; Tue, 31 Mar 2020 09:22:15 -0400 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-271-x25oJb0RMoaf-QWoJ1_WNg-1; Tue, 31 Mar 2020 09:22:08 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 94A451085926; Tue, 31 Mar 2020 13:22:07 +0000 (UTC) Received: from jason-ThinkPad-T430s.redhat.com (ovpn-12-118.pek2.redhat.com [10.72.12.118]) by smtp.corp.redhat.com (Postfix) with ESMTP id E84E810002B5; Tue, 31 Mar 2020 13:22:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1585660935; 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=yaOwtgmOb1WJgAzFCsAuhnSvk3thhHf/hjpROiOzOAM=; b=Rzx0f9+bpE1k7/LO3DeKDCL2xvXUgk4Sq9BQlIQqLVA5Sx/FZ6iXuomMiC88A7Xs4SlrTj SazvQy5/KUa8bD8TskoDNcBO2ww+wO81jMW4rapA8fXamgvdjxj4m2d0VYgmGqCH4J7nOb ATpUGqjKZn1VQT9xf3Hd3GCyPldGdMM= X-MC-Unique: x25oJb0RMoaf-QWoJ1_WNg-1 From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Subject: [PULL V2 08/14] hw/net: Make NetCanReceive() return a boolean Date: Tue, 31 Mar 2020 21:21:33 +0800 Message-Id: <1585660899-11228-9-git-send-email-jasowang@redhat.com> In-Reply-To: <1585660899-11228-1-git-send-email-jasowang@redhat.com> References: <1585660899-11228-1-git-send-email-jasowang@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.81 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jason Wang , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Philippe Mathieu-Daud=C3=A9 The NetCanReceive handler return whether the device can or can not receive new packets. Make it obvious by returning a boolean type. Signed-off-by: Philippe Mathieu-Daud=C3=A9 Acked-by: David Gibson Reviewed-by: Alistair Francis Reviewed-by: C=C3=A9dric Le Goater Signed-off-by: Jason Wang --- hw/net/allwinner_emac.c | 2 +- hw/net/cadence_gem.c | 8 ++++---- hw/net/dp8393x.c | 8 +++----- hw/net/e1000.c | 2 +- hw/net/e1000e.c | 2 +- hw/net/ftgmac100.c | 6 +++--- hw/net/i82596.c | 10 +++++----- hw/net/i82596.h | 2 +- hw/net/imx_fec.c | 2 +- hw/net/opencores_eth.c | 5 ++--- hw/net/rtl8139.c | 8 ++++---- hw/net/smc91c111.c | 2 +- hw/net/spapr_llan.c | 4 ++-- hw/net/sungem.c | 6 +++--- hw/net/sunhme.c | 4 ++-- hw/net/virtio-net.c | 10 +++++----- hw/net/xilinx_ethlite.c | 2 +- include/net/net.h | 2 +- net/filter-buffer.c | 2 +- net/hub.c | 6 +++--- 20 files changed, 45 insertions(+), 48 deletions(-) diff --git a/hw/net/allwinner_emac.c b/hw/net/allwinner_emac.c index e9bbff8..ddddf35 100644 --- a/hw/net/allwinner_emac.c +++ b/hw/net/allwinner_emac.c @@ -178,7 +178,7 @@ static uint32_t fifo8_pop_word(Fifo8 *fifo) return ret; } =20 -static int aw_emac_can_receive(NetClientState *nc) +static bool aw_emac_can_receive(NetClientState *nc) { AwEmacState *s =3D qemu_get_nic_opaque(nc); =20 diff --git a/hw/net/cadence_gem.c b/hw/net/cadence_gem.c index 6340c1e..51ec5a0 100644 --- a/hw/net/cadence_gem.c +++ b/hw/net/cadence_gem.c @@ -505,7 +505,7 @@ static void phy_update_link(CadenceGEMState *s) } } =20 -static int gem_can_receive(NetClientState *nc) +static bool gem_can_receive(NetClientState *nc) { CadenceGEMState *s; int i; @@ -518,7 +518,7 @@ static int gem_can_receive(NetClientState *nc) s->can_rx_state =3D 1; DB_PRINT("can't receive - no enable\n"); } - return 0; + return false; } =20 for (i =3D 0; i < s->num_priority_queues; i++) { @@ -532,14 +532,14 @@ static int gem_can_receive(NetClientState *nc) s->can_rx_state =3D 2; DB_PRINT("can't receive - all the buffer descriptors are busy\= n"); } - return 0; + return false; } =20 if (s->can_rx_state !=3D 0) { s->can_rx_state =3D 0; DB_PRINT("can receive\n"); } - return 1; + return true; } =20 /* diff --git a/hw/net/dp8393x.c b/hw/net/dp8393x.c index 1563c11..c54db0d 100644 --- a/hw/net/dp8393x.c +++ b/hw/net/dp8393x.c @@ -414,7 +414,7 @@ static void dp8393x_do_stop_timer(dp8393xState *s) dp8393x_update_wt_regs(s); } =20 -static int dp8393x_can_receive(NetClientState *nc); +static bool dp8393x_can_receive(NetClientState *nc); =20 static void dp8393x_do_receiver_enable(dp8393xState *s) { @@ -718,13 +718,11 @@ static void dp8393x_watchdog(void *opaque) dp8393x_update_irq(s); } =20 -static int dp8393x_can_receive(NetClientState *nc) +static bool dp8393x_can_receive(NetClientState *nc) { dp8393xState *s =3D qemu_get_nic_opaque(nc); =20 - if (!(s->regs[SONIC_CR] & SONIC_CR_RXEN)) - return 0; - return 1; + return !!(s->regs[SONIC_CR] & SONIC_CR_RXEN); } =20 static int dp8393x_receive_filter(dp8393xState *s, const uint8_t * buf, diff --git a/hw/net/e1000.c b/hw/net/e1000.c index 9233248..2a69eee 100644 --- a/hw/net/e1000.c +++ b/hw/net/e1000.c @@ -845,7 +845,7 @@ static bool e1000_has_rxbufs(E1000State *s, size_t tota= l_size) return total_size <=3D bufs * s->rxbuf_size; } =20 -static int +static bool e1000_can_receive(NetClientState *nc) { E1000State *s =3D qemu_get_nic_opaque(nc); diff --git a/hw/net/e1000e.c b/hw/net/e1000e.c index f2cc155..79ba158 100644 --- a/hw/net/e1000e.c +++ b/hw/net/e1000e.c @@ -199,7 +199,7 @@ static const MemoryRegionOps io_ops =3D { }, }; =20 -static int +static bool e1000e_nc_can_receive(NetClientState *nc) { E1000EState *s =3D qemu_get_nic_opaque(nc); diff --git a/hw/net/ftgmac100.c b/hw/net/ftgmac100.c index 2f92b65..041ed21 100644 --- a/hw/net/ftgmac100.c +++ b/hw/net/ftgmac100.c @@ -562,18 +562,18 @@ static void ftgmac100_do_tx(FTGMAC100State *s, uint32= _t tx_ring, ftgmac100_update_irq(s); } =20 -static int ftgmac100_can_receive(NetClientState *nc) +static bool ftgmac100_can_receive(NetClientState *nc) { FTGMAC100State *s =3D FTGMAC100(qemu_get_nic_opaque(nc)); FTGMAC100Desc bd; =20 if ((s->maccr & (FTGMAC100_MACCR_RXDMA_EN | FTGMAC100_MACCR_RXMAC_EN)) !=3D (FTGMAC100_MACCR_RXDMA_EN | FTGMAC100_MACCR_RXMAC_EN)) { - return 0; + return false; } =20 if (ftgmac100_read_bd(&bd, s->rx_descriptor)) { - return 0; + return false; } return !(bd.des0 & FTGMAC100_RXDES0_RXPKT_RDY); } diff --git a/hw/net/i82596.c b/hw/net/i82596.c index 3b0efd0..055c3a1 100644 --- a/hw/net/i82596.c +++ b/hw/net/i82596.c @@ -470,23 +470,23 @@ void i82596_h_reset(void *opaque) i82596_s_reset(s); } =20 -int i82596_can_receive(NetClientState *nc) +bool i82596_can_receive(NetClientState *nc) { I82596State *s =3D qemu_get_nic_opaque(nc); =20 if (s->rx_status =3D=3D RX_SUSPENDED) { - return 0; + return false; } =20 if (!s->lnkst) { - return 0; + return false; } =20 if (USE_TIMER && !timer_pending(s->flush_queue_timer)) { - return 1; + return true; } =20 - return 1; + return true; } =20 #define MIN_BUF_SIZE 60 diff --git a/hw/net/i82596.h b/hw/net/i82596.h index 1238ac1..f0bbe81 100644 --- a/hw/net/i82596.h +++ b/hw/net/i82596.h @@ -48,7 +48,7 @@ void i82596_ioport_writel(void *opaque, uint32_t addr, ui= nt32_t val); uint32_t i82596_ioport_readl(void *opaque, uint32_t addr); uint32_t i82596_bcr_readw(I82596State *s, uint32_t rap); ssize_t i82596_receive(NetClientState *nc, const uint8_t *buf, size_t size= _); -int i82596_can_receive(NetClientState *nc); +bool i82596_can_receive(NetClientState *nc); void i82596_set_link_status(NetClientState *nc); void i82596_common_init(DeviceState *dev, I82596State *s, NetClientInfo *i= nfo); extern const VMStateDescription vmstate_i82596; diff --git a/hw/net/imx_fec.c b/hw/net/imx_fec.c index 5c145a8..a35c336 100644 --- a/hw/net/imx_fec.c +++ b/hw/net/imx_fec.c @@ -1049,7 +1049,7 @@ static void imx_eth_write(void *opaque, hwaddr offset= , uint64_t value, imx_eth_update(s); } =20 -static int imx_eth_can_receive(NetClientState *nc) +static bool imx_eth_can_receive(NetClientState *nc) { IMXFECState *s =3D IMX_FEC(qemu_get_nic_opaque(nc)); =20 diff --git a/hw/net/opencores_eth.c b/hw/net/opencores_eth.c index 6b338c2..2ba0dc8 100644 --- a/hw/net/opencores_eth.c +++ b/hw/net/opencores_eth.c @@ -349,12 +349,11 @@ static void open_eth_reset(void *opaque) open_eth_set_link_status(qemu_get_queue(s->nic)); } =20 -static int open_eth_can_receive(NetClientState *nc) +static bool open_eth_can_receive(NetClientState *nc) { OpenEthState *s =3D qemu_get_nic_opaque(nc); =20 - return GET_REGBIT(s, MODER, RXEN) && - (s->regs[TX_BD_NUM] < 0x80); + return GET_REGBIT(s, MODER, RXEN) && (s->regs[TX_BD_NUM] < 0x80); } =20 static ssize_t open_eth_receive(NetClientState *nc, diff --git a/hw/net/rtl8139.c b/hw/net/rtl8139.c index be9a0af..70aca7e 100644 --- a/hw/net/rtl8139.c +++ b/hw/net/rtl8139.c @@ -793,23 +793,23 @@ static bool rtl8139_cp_rx_valid(RTL8139State *s) return !(s->RxRingAddrLO =3D=3D 0 && s->RxRingAddrHI =3D=3D 0); } =20 -static int rtl8139_can_receive(NetClientState *nc) +static bool rtl8139_can_receive(NetClientState *nc) { RTL8139State *s =3D qemu_get_nic_opaque(nc); int avail; =20 /* Receive (drop) packets if card is disabled. */ if (!s->clock_enabled) { - return 1; + return true; } if (!rtl8139_receiver_enabled(s)) { - return 1; + return true; } =20 if (rtl8139_cp_receiver_enabled(s) && rtl8139_cp_rx_valid(s)) { /* ??? Flow control not implemented in c+ mode. This is a hack to work around slirp deficiencies anyway. */ - return 1; + return true; } =20 avail =3D MOD2(s->RxBufferSize + s->RxBufPtr - s->RxBufAddr, diff --git a/hw/net/smc91c111.c b/hw/net/smc91c111.c index 02be60c..b3240b9 100644 --- a/hw/net/smc91c111.c +++ b/hw/net/smc91c111.c @@ -667,7 +667,7 @@ static void smc91c111_writefn(void *opaque, hwaddr addr, } } =20 -static int smc91c111_can_receive_nc(NetClientState *nc) +static bool smc91c111_can_receive_nc(NetClientState *nc) { smc91c111_state *s =3D qemu_get_nic_opaque(nc); =20 diff --git a/hw/net/spapr_llan.c b/hw/net/spapr_llan.c index 80f5a1d..a237702 100644 --- a/hw/net/spapr_llan.c +++ b/hw/net/spapr_llan.c @@ -110,11 +110,11 @@ typedef struct SpaprVioVlan { RxBufPool *rx_pool[RX_MAX_POOLS]; /* Receive buffer descriptor pools = */ } SpaprVioVlan; =20 -static int spapr_vlan_can_receive(NetClientState *nc) +static bool spapr_vlan_can_receive(NetClientState *nc) { SpaprVioVlan *dev =3D qemu_get_nic_opaque(nc); =20 - return (dev->isopen && dev->rx_bufs > 0); + return dev->isopen && dev->rx_bufs > 0; } =20 /** diff --git a/hw/net/sungem.c b/hw/net/sungem.c index 89da51f..b01197d 100644 --- a/hw/net/sungem.c +++ b/hw/net/sungem.c @@ -433,7 +433,7 @@ static bool sungem_rx_full(SunGEMState *s, uint32_t kic= k, uint32_t done) return kick =3D=3D ((done + 1) & s->rx_mask); } =20 -static int sungem_can_receive(NetClientState *nc) +static bool sungem_can_receive(NetClientState *nc) { SunGEMState *s =3D qemu_get_nic_opaque(nc); uint32_t kick, done, rxdma_cfg, rxmac_cfg; @@ -445,11 +445,11 @@ static int sungem_can_receive(NetClientState *nc) /* If MAC disabled, can't receive */ if ((rxmac_cfg & MAC_RXCFG_ENAB) =3D=3D 0) { trace_sungem_rx_mac_disabled(); - return 0; + return false; } if ((rxdma_cfg & RXDMA_CFG_ENABLE) =3D=3D 0) { trace_sungem_rx_txdma_disabled(); - return 0; + return false; } =20 /* Check RX availability */ diff --git a/hw/net/sunhme.c b/hw/net/sunhme.c index 8863601..9c38583 100644 --- a/hw/net/sunhme.c +++ b/hw/net/sunhme.c @@ -657,11 +657,11 @@ static void sunhme_transmit(SunHMEState *s) sunhme_update_irq(s); } =20 -static int sunhme_can_receive(NetClientState *nc) +static bool sunhme_can_receive(NetClientState *nc) { SunHMEState *s =3D qemu_get_nic_opaque(nc); =20 - return s->macregs[HME_MACI_RXCFG >> 2] & HME_MAC_RXCFG_ENABLE; + return !!(s->macregs[HME_MACI_RXCFG >> 2] & HME_MAC_RXCFG_ENABLE); } =20 static void sunhme_link_status_changed(NetClientState *nc) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 3627bb1..a46e3b3 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -1234,26 +1234,26 @@ static void virtio_net_handle_rx(VirtIODevice *vdev= , VirtQueue *vq) qemu_flush_queued_packets(qemu_get_subqueue(n->nic, queue_index)); } =20 -static int virtio_net_can_receive(NetClientState *nc) +static bool virtio_net_can_receive(NetClientState *nc) { VirtIONet *n =3D qemu_get_nic_opaque(nc); VirtIODevice *vdev =3D VIRTIO_DEVICE(n); VirtIONetQueue *q =3D virtio_net_get_subqueue(nc); =20 if (!vdev->vm_running) { - return 0; + return false; } =20 if (nc->queue_index >=3D n->curr_queues) { - return 0; + return false; } =20 if (!virtio_queue_ready(q->rx_vq) || !(vdev->status & VIRTIO_CONFIG_S_DRIVER_OK)) { - return 0; + return false; } =20 - return 1; + return true; } =20 static int virtio_net_has_buffers(VirtIONetQueue *q, int bufsize) diff --git a/hw/net/xilinx_ethlite.c b/hw/net/xilinx_ethlite.c index cf07e69..71d16fe 100644 --- a/hw/net/xilinx_ethlite.c +++ b/hw/net/xilinx_ethlite.c @@ -175,7 +175,7 @@ static const MemoryRegionOps eth_ops =3D { } }; =20 -static int eth_can_rx(NetClientState *nc) +static bool eth_can_rx(NetClientState *nc) { struct xlx_ethlite *s =3D qemu_get_nic_opaque(nc); unsigned int rxbase =3D s->rxbuf * (0x800 / 4); diff --git a/include/net/net.h b/include/net/net.h index 094e966..39085d9 100644 --- a/include/net/net.h +++ b/include/net/net.h @@ -42,7 +42,7 @@ typedef struct NICConf { /* Net clients */ =20 typedef void (NetPoll)(NetClientState *, bool enable); -typedef int (NetCanReceive)(NetClientState *); +typedef bool (NetCanReceive)(NetClientState *); typedef ssize_t (NetReceive)(NetClientState *, const uint8_t *, size_t); typedef ssize_t (NetReceiveIOV)(NetClientState *, const struct iovec *, in= t); typedef void (NetCleanup) (NetClientState *); diff --git a/net/filter-buffer.c b/net/filter-buffer.c index 88da78f..12e0254 100644 --- a/net/filter-buffer.c +++ b/net/filter-buffer.c @@ -74,7 +74,7 @@ static ssize_t filter_buffer_receive_iov(NetFilterState *= nf, * the filter can still accept packets until its internal queue is ful= l. * For example: * For some reason, receiver could not receive more packets - * (.can_receive() returns zero). Without a filter, at most one packet + * (.can_receive() returns false). Without a filter, at most one packet * will be queued in incoming queue and sender's poll will be disabled * unit its sent_cb() was called. With a filter, it will keep receiving * the packets without caring about the receiver. This is suboptimal. diff --git a/net/hub.c b/net/hub.c index 88cfb87..1375738 100644 --- a/net/hub.c +++ b/net/hub.c @@ -90,7 +90,7 @@ static NetHub *net_hub_new(int id) return hub; } =20 -static int net_hub_port_can_receive(NetClientState *nc) +static bool net_hub_port_can_receive(NetClientState *nc) { NetHubPort *port; NetHubPort *src_port =3D DO_UPCAST(NetHubPort, nc, nc); @@ -102,11 +102,11 @@ static int net_hub_port_can_receive(NetClientState *n= c) } =20 if (qemu_can_send_packet(&port->nc)) { - return 1; + return true; } } =20 - return 0; + return false; } =20 static ssize_t net_hub_port_receive(NetClientState *nc, --=20 2.5.0 From nobody Mon May 6 08:14:37 2024 Delivered-To: importer@patchew.org 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; Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1585661527; cv=none; d=zohomail.com; s=zohoarc; b=B9eGzj9g/+WGX9IDRJA0sPpZ49pyOai6fL8dYjAdz8bEoG9GygqRlKeix+DcY2oi/7r1+fyiJSodQORudE3lESvajDnlD3qWqEyMmk3L/sXqo21QLHUkw6D4mo7/l+w1XzMPNHyAUr2cQMjCh3CNDGL73UAJYK3EgqLLh6gRWys= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585661527; 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=oyUvM9cTct1BA2jEqDprwvL257zpUYCHUdEt2hUr7NM=; b=S7tJghS2gib7WovyRC5lJ8qcrB5vYK9hie6TE4ZuxI2sj2slYVd2Eb5GFyVv+x8/248oFrzQmXbxue6ZrCKRTuhjYTCnScHQ489QnMzLsi0yAjSkbQGBGiGSj1KSjqYg554JQebbNQz6zqTMvfOt9b4ggLNHUYEWbGWC1dD0K5M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1585661527390881.0303003745863; Tue, 31 Mar 2020 06:32:07 -0700 (PDT) Received: from localhost ([::1]:38110 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJGzu-0007ew-5t for importer@patchew.org; Tue, 31 Mar 2020 09:32:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42030) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJGqO-0000Xe-Hp for qemu-devel@nongnu.org; Tue, 31 Mar 2020 09:22:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jJGqN-0005qq-8m for qemu-devel@nongnu.org; Tue, 31 Mar 2020 09:22:16 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:52341 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jJGqN-0005qV-4d for qemu-devel@nongnu.org; Tue, 31 Mar 2020 09:22:15 -0400 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-125-qUNI-hOrMUaPdR96EwbS4A-1; Tue, 31 Mar 2020 09:22:10 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C5584800D50; Tue, 31 Mar 2020 13:22:09 +0000 (UTC) Received: from jason-ThinkPad-T430s.redhat.com (ovpn-12-118.pek2.redhat.com [10.72.12.118]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1F15510002B5; Tue, 31 Mar 2020 13:22:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1585660934; 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=oyUvM9cTct1BA2jEqDprwvL257zpUYCHUdEt2hUr7NM=; b=AF8nN1fFUzF+WroL2UMreWsP6IQoWr89+1lsaGTl3oU+G7J7vAUsTq6xCZUwQKv91Zof6Z QsTnlLB5jw/k2D2mUyGgpVrZWzE1jWu5wyKRHjGW7dzIl+de+mtK7qc95+/m1yyhBwoymO BIwGkpOIsIcqDlU/CJjLIPp4SLd8Axw= X-MC-Unique: qUNI-hOrMUaPdR96EwbS4A-1 From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Subject: [PULL V2 09/14] hw/net/can: Make CanBusClientInfo::can_receive() return a boolean Date: Tue, 31 Mar 2020 21:21:34 +0800 Message-Id: <1585660899-11228-10-git-send-email-jasowang@redhat.com> In-Reply-To: <1585660899-11228-1-git-send-email-jasowang@redhat.com> References: <1585660899-11228-1-git-send-email-jasowang@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jason Wang , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Philippe Mathieu-Daud=C3=A9 The CanBusClientInfo::can_receive handler return whether the device can or can not receive new frames. Make it obvious by returning a boolean type. Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Alistair Francis Reviewed-by: C=C3=A9dric Le Goater Signed-off-by: Jason Wang --- hw/net/allwinner-sun8i-emac.c | 2 +- hw/net/can/can_sja1000.c | 8 ++++---- hw/net/can/can_sja1000.h | 2 +- include/net/can_emu.h | 2 +- net/can/can_socketcan.c | 4 ++-- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/hw/net/allwinner-sun8i-emac.c b/hw/net/allwinner-sun8i-emac.c index 3fc5e34..033eaa8 100644 --- a/hw/net/allwinner-sun8i-emac.c +++ b/hw/net/allwinner-sun8i-emac.c @@ -395,7 +395,7 @@ static void allwinner_sun8i_emac_flush_desc(FrameDescri= ptor *desc, cpu_physical_memory_write(phys_addr, desc, sizeof(*desc)); } =20 -static int allwinner_sun8i_emac_can_receive(NetClientState *nc) +static bool allwinner_sun8i_emac_can_receive(NetClientState *nc) { AwSun8iEmacState *s =3D qemu_get_nic_opaque(nc); FrameDescriptor desc; diff --git a/hw/net/can/can_sja1000.c b/hw/net/can/can_sja1000.c index 39c78fa..ea915a0 100644 --- a/hw/net/can/can_sja1000.c +++ b/hw/net/can/can_sja1000.c @@ -733,21 +733,21 @@ uint64_t can_sja_mem_read(CanSJA1000State *s, hwaddr = addr, unsigned size) return temp; } =20 -int can_sja_can_receive(CanBusClientState *client) +bool can_sja_can_receive(CanBusClientState *client) { CanSJA1000State *s =3D container_of(client, CanSJA1000State, bus_clien= t); =20 if (s->clock & 0x80) { /* PeliCAN Mode */ if (s->mode & 0x01) { /* reset mode. */ - return 0; + return false; } } else { /* BasicCAN mode */ if (s->control & 0x01) { - return 0; + return false; } } =20 - return 1; /* always return 1, when operation mode */ + return true; /* always return true, when operation mode */ } =20 ssize_t can_sja_receive(CanBusClientState *client, const qemu_can_frame *f= rames, diff --git a/hw/net/can/can_sja1000.h b/hw/net/can/can_sja1000.h index 220a622..7ca9cd6 100644 --- a/hw/net/can/can_sja1000.h +++ b/hw/net/can/can_sja1000.h @@ -137,7 +137,7 @@ void can_sja_disconnect(CanSJA1000State *s); =20 int can_sja_init(CanSJA1000State *s, qemu_irq irq); =20 -int can_sja_can_receive(CanBusClientState *client); +bool can_sja_can_receive(CanBusClientState *client); =20 ssize_t can_sja_receive(CanBusClientState *client, const qemu_can_frame *frames, size_t frames_cnt); diff --git a/include/net/can_emu.h b/include/net/can_emu.h index d4fc51b..fce9770 100644 --- a/include/net/can_emu.h +++ b/include/net/can_emu.h @@ -83,7 +83,7 @@ typedef struct CanBusClientState CanBusClientState; typedef struct CanBusState CanBusState; =20 typedef struct CanBusClientInfo { - int (*can_receive)(CanBusClientState *); + bool (*can_receive)(CanBusClientState *); ssize_t (*receive)(CanBusClientState *, const struct qemu_can_frame *frames, size_t frames_cnt); } CanBusClientInfo; diff --git a/net/can/can_socketcan.c b/net/can/can_socketcan.c index 29bfacd..807f31f 100644 --- a/net/can/can_socketcan.c +++ b/net/can/can_socketcan.c @@ -110,9 +110,9 @@ static void can_host_socketcan_read(void *opaque) } } =20 -static int can_host_socketcan_can_receive(CanBusClientState *client) +static bool can_host_socketcan_can_receive(CanBusClientState *client) { - return 1; + return true; } =20 static ssize_t can_host_socketcan_receive(CanBusClientState *client, --=20 2.5.0 From nobody Mon May 6 08:14:37 2024 Delivered-To: importer@patchew.org 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; 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=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1585661208; cv=none; d=zohomail.com; s=zohoarc; b=NHs6uNi4ypuHsyc51iZ9YIRWJoZ7WbIJP/j9awSGerkYuaUZ8UbzUzuFrsVeelgyrmSnjtd+ODxly3lMuyMiCaFdwYZzLycwapTLlVINmyWwB7PMyLDbPNDb8M6Eig4uWNx8K2rjvE8Txj53eA+ZBuMduM3QweazQrKk7PfzAHY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585661208; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=uMenIUGdDmBnzKf4+9eU1fy5NRzIpPIs/nd9clirI9A=; b=ZrUBKO+qdw+8J9lgNJlHjmPiefWZQ1BgyytPAmmAJ4f5s9cDAULEXlcIAsjfcY0a9IMoY5jWe3m219bgmgdbHiXBA86yH8sdMmKxQAk5nDoI9HUbpDLaq3LxcU/sp7azAfzvUpXAqva3yHIUGiMxMzGtVxscuSV9muB2Y6EwUjU= 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=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1585661208758560.7209344336487; Tue, 31 Mar 2020 06:26:48 -0700 (PDT) Received: from localhost ([::1]:38016 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJGul-0007rC-Hn for importer@patchew.org; Tue, 31 Mar 2020 09:26:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42069) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJGqW-0000aw-5t for qemu-devel@nongnu.org; Tue, 31 Mar 2020 09:22:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jJGqS-0005uI-Iw for qemu-devel@nongnu.org; Tue, 31 Mar 2020 09:22:22 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:27398 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jJGqS-0005t8-EO for qemu-devel@nongnu.org; Tue, 31 Mar 2020 09:22:20 -0400 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-259-NFnqEUdPNpWVSaj6mtn3gQ-1; Tue, 31 Mar 2020 09:22:13 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id F3BD08017DF; Tue, 31 Mar 2020 13:22:11 +0000 (UTC) Received: from jason-ThinkPad-T430s.redhat.com (ovpn-12-118.pek2.redhat.com [10.72.12.118]) by smtp.corp.redhat.com (Postfix) with ESMTP id 508A910002B5; Tue, 31 Mar 2020 13:22:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1585660938; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uMenIUGdDmBnzKf4+9eU1fy5NRzIpPIs/nd9clirI9A=; b=TjTQ+TdIWkhzYOj7hxGVdCKBDeyloytQtu/KjAxdN16WJbdBeUS2PrXHFWntbg63yKQjaX 9Uqq4prG+iLQkXo/zx2Sequx+7JH0PDn2GvgtRACENlD3UEedJn10zEiedistl2+qSw9Ca i51+nA0vaAaaLkl03pEwTrAbRNaD9xQ= X-MC-Unique: NFnqEUdPNpWVSaj6mtn3gQ-1 From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Subject: [PULL V2 10/14] net/colo-compare.c: Expose "compare_timeout" to users Date: Tue, 31 Mar 2020 21:21:35 +0800 Message-Id: <1585660899-11228-11-git-send-email-jasowang@redhat.com> In-Reply-To: <1585660899-11228-1-git-send-email-jasowang@redhat.com> References: <1585660899-11228-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Zhang Chen , Jason Wang Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Zhang Chen The "compare_timeout" determines the maximum time to hold the primary net p= acket. This patch expose the "compare_timeout", make user have ability to adjest the value according to application scenarios. QMP command demo: { "execute": "qom-get", "arguments": { "path": "/objects/comp0", "property": "compare_timeout" } } { "execute": "qom-set", "arguments": { "path": "/objects/comp0", "property": "compare_timeout", "value": 5000} } Signed-off-by: Zhang Chen Signed-off-by: Jason Wang --- net/colo-compare.c | 47 +++++++++++++++++++++++++++++++++++++++++++++-- qemu-options.hx | 8 +++++--- 2 files changed, 50 insertions(+), 5 deletions(-) diff --git a/net/colo-compare.c b/net/colo-compare.c index 7ee17f2..ec09b2a 100644 --- a/net/colo-compare.c +++ b/net/colo-compare.c @@ -50,6 +50,7 @@ static NotifierList colo_compare_notifiers =3D =20 /* TODO: Should be configurable */ #define REGULAR_PACKET_CHECK_MS 3000 +#define DEFAULT_TIME_OUT_MS 3000 =20 static QemuMutex event_mtx; static QemuCond event_complete_cond; @@ -92,6 +93,7 @@ typedef struct CompareState { SocketReadState sec_rs; SocketReadState notify_rs; bool vnet_hdr; + uint32_t compare_timeout; =20 /* * Record the connection that through the NIC @@ -607,10 +609,9 @@ static int colo_old_packet_check_one_conn(Connection *= conn, CompareState *s) { GList *result =3D NULL; - int64_t check_time =3D REGULAR_PACKET_CHECK_MS; =20 result =3D g_queue_find_custom(&conn->primary_list, - &check_time, + &s->compare_timeout, (GCompareFunc)colo_old_packet_check_one); =20 if (result) { @@ -984,6 +985,39 @@ static void compare_set_notify_dev(Object *obj, const = char *value, Error **errp) s->notify_dev =3D g_strdup(value); } =20 +static void compare_get_timeout(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) +{ + CompareState *s =3D COLO_COMPARE(obj); + uint32_t value =3D s->compare_timeout; + + visit_type_uint32(v, name, &value, errp); +} + +static void compare_set_timeout(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) +{ + CompareState *s =3D COLO_COMPARE(obj); + Error *local_err =3D NULL; + uint32_t value; + + visit_type_uint32(v, name, &value, &local_err); + if (local_err) { + goto out; + } + if (!value) { + error_setg(&local_err, "Property '%s.%s' requires a positive value= ", + object_get_typename(obj), name); + goto out; + } + s->compare_timeout =3D value; + +out: + error_propagate(errp, local_err); +} + static void compare_pri_rs_finalize(SocketReadState *pri_rs) { CompareState *s =3D container_of(pri_rs, CompareState, pri_rs); @@ -1090,6 +1124,11 @@ static void colo_compare_complete(UserCreatable *uc,= Error **errp) return; } =20 + if (!s->compare_timeout) { + /* Set default value to 3000 MS */ + s->compare_timeout =3D DEFAULT_TIME_OUT_MS; + } + if (find_and_check_chardev(&chr, s->pri_indev, errp) || !qemu_chr_fe_init(&s->chr_pri_in, chr, errp)) { return; @@ -1185,6 +1224,10 @@ static void colo_compare_init(Object *obj) compare_get_notify_dev, compare_set_notify_dev, NULL); =20 + object_property_add(obj, "compare_timeout", "uint32", + compare_get_timeout, + compare_set_timeout, NULL, NULL, NULL); + s->vnet_hdr =3D false; object_property_add_bool(obj, "vnet_hdr_support", compare_get_vnet_hdr, compare_set_vnet_hdr, NULL); diff --git a/qemu-options.hx b/qemu-options.hx index 962a5eb..9e48e13 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -4615,7 +4615,7 @@ SRST stored. The file format is libpcap, so it can be analyzed with tools such as tcpdump or Wireshark. =20 - ``-object colo-compare,id=3Did,primary_in=3Dchardevid,secondary_in=3Dc= hardevid,outdev=3Dchardevid,iothread=3Did[,vnet_hdr_support][,notify_dev=3D= id]`` + ``-object colo-compare,id=3Did,primary_in=3Dchardevid,secondary_in=3Dc= hardevid,outdev=3Dchardevid,iothread=3Did[,vnet_hdr_support][,notify_dev=3D= id][,compare_timeout=3D@var{ms}]`` Colo-compare gets packet from primary\_inchardevid and secondary\_inchardevid, than compare primary packet with secondary packet. If the packets are same, we will output @@ -4624,8 +4624,10 @@ SRST outdevchardevid. In order to improve efficiency, we need to put the task of comparison in another thread. If it has the vnet\_hdr\_support flag, colo compare will send/recv packet with - vnet\_hdr\_len. If you want to use Xen COLO, will need the - notify\_dev to notify Xen colo-frame to do checkpoint. + vnet\_hdr\_len. Then compare\_timeout=3D@var{ms} determines the + maximum delay colo-compare wait for the packet. + If you want to use Xen COLO, will need the notify\_dev to + notify Xen colo-frame to do checkpoint. =20 we must use it with the help of filter-mirror and filter-redirector. --=20 2.5.0 From nobody Mon May 6 08:14:37 2024 Delivered-To: importer@patchew.org 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; 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=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1585661120; cv=none; d=zohomail.com; s=zohoarc; b=H6L4WH2X5ky2b6zzYab748zoPSVt3asPOO0r3EK3XVVuzRJugpgU8fJQu/dG2zFDbKOo1BTvrSXhgvGa9DaQ4++Sd6jVERy+uoZ/ncZ75cJqbUMoktn2S0oGK6unUqUxrwH7ZV/T0hCZH/QpM4B3IhrZ/mElatEUfpbFX72azz0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585661120; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=4MxJPowySKOhY+nUVAcYVxWerfqWXbqkq59mtjxRxZg=; b=EG74fn06ZmKqJbF+VqO7owKwjdOYdNIzeVsbZ1ASerSMYfqBiLIfKAUyECMzAATXERFytZXOXQ/ks4iaaX8xPG2jG0wiW1wnO8txZVeLZ5bsWhZ056dDdR7GfPTXIzGyU0R0tzfTDoKffBxlt0ZUEy5eK9Axnr6hOF9cJFAjcYk= 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=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1585661120630555.7019356184682; Tue, 31 Mar 2020 06:25:20 -0700 (PDT) Received: from localhost ([::1]:37982 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJGtK-00059M-IC for importer@patchew.org; Tue, 31 Mar 2020 09:25:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42064) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJGqT-0000aW-Uv for qemu-devel@nongnu.org; Tue, 31 Mar 2020 09:22:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jJGqS-0005uN-Iz for qemu-devel@nongnu.org; Tue, 31 Mar 2020 09:22:21 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:50473 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jJGqS-0005tb-EK for qemu-devel@nongnu.org; Tue, 31 Mar 2020 09:22:20 -0400 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-439-LvkfC5nXMOCUdW2IIYVysA-1; Tue, 31 Mar 2020 09:22:15 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2E55618FF660; Tue, 31 Mar 2020 13:22:14 +0000 (UTC) Received: from jason-ThinkPad-T430s.redhat.com (ovpn-12-118.pek2.redhat.com [10.72.12.118]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7DD0A1001B28; Tue, 31 Mar 2020 13:22:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1585660939; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4MxJPowySKOhY+nUVAcYVxWerfqWXbqkq59mtjxRxZg=; b=DfJ6M8f/Dijtppd3BPfA5UjUfI2UwlSoKJfKHiDhtZl6VQR8ZoYyinHQ1wCRJLkZ00CCbq HfWctaCxG9bUVMukZJMAHMA/TFZSoSWMfxb9GoOv/+t75oj7mf+2qXhS5SyMZ7Ih3v5MYn IwdWc3Vw1BFlcjYvoetw3e+uiqE/ypc= X-MC-Unique: LvkfC5nXMOCUdW2IIYVysA-1 From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Subject: [PULL V2 11/14] net/colo-compare.c: Expose "expired_scan_cycle" to users Date: Tue, 31 Mar 2020 21:21:36 +0800 Message-Id: <1585660899-11228-12-git-send-email-jasowang@redhat.com> In-Reply-To: <1585660899-11228-1-git-send-email-jasowang@redhat.com> References: <1585660899-11228-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Zhang Chen , Jason Wang Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Zhang Chen The "expired_scan_cycle" determines period of scanning expired primary node net packets. Signed-off-by: Zhang Chen Signed-off-by: Jason Wang --- net/colo-compare.c | 48 +++++++++++++++++++++++++++++++++++++++++++++--- qemu-options.hx | 4 +++- 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/net/colo-compare.c b/net/colo-compare.c index ec09b2a..10c0239 100644 --- a/net/colo-compare.c +++ b/net/colo-compare.c @@ -48,7 +48,6 @@ static NotifierList colo_compare_notifiers =3D #define COLO_COMPARE_FREE_PRIMARY 0x01 #define COLO_COMPARE_FREE_SECONDARY 0x02 =20 -/* TODO: Should be configurable */ #define REGULAR_PACKET_CHECK_MS 3000 #define DEFAULT_TIME_OUT_MS 3000 =20 @@ -94,6 +93,7 @@ typedef struct CompareState { SocketReadState notify_rs; bool vnet_hdr; uint32_t compare_timeout; + uint32_t expired_scan_cycle; =20 /* * Record the connection that through the NIC @@ -823,7 +823,7 @@ static void check_old_packet_regular(void *opaque) /* if have old packet we will notify checkpoint */ colo_old_packet_check(s); timer_mod(s->packet_check_timer, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL)= + - REGULAR_PACKET_CHECK_MS); + s->expired_scan_cycle); } =20 /* Public API, Used for COLO frame to notify compare event */ @@ -853,7 +853,7 @@ static void colo_compare_timer_init(CompareState *s) SCALE_MS, check_old_packet_regular, s); timer_mod(s->packet_check_timer, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL)= + - REGULAR_PACKET_CHECK_MS); + s->expired_scan_cycle); } =20 static void colo_compare_timer_del(CompareState *s) @@ -1018,6 +1018,39 @@ out: error_propagate(errp, local_err); } =20 +static void compare_get_expired_scan_cycle(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) +{ + CompareState *s =3D COLO_COMPARE(obj); + uint32_t value =3D s->expired_scan_cycle; + + visit_type_uint32(v, name, &value, errp); +} + +static void compare_set_expired_scan_cycle(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) +{ + CompareState *s =3D COLO_COMPARE(obj); + Error *local_err =3D NULL; + uint32_t value; + + visit_type_uint32(v, name, &value, &local_err); + if (local_err) { + goto out; + } + if (!value) { + error_setg(&local_err, "Property '%s.%s' requires a positive value= ", + object_get_typename(obj), name); + goto out; + } + s->expired_scan_cycle =3D value; + +out: + error_propagate(errp, local_err); +} + static void compare_pri_rs_finalize(SocketReadState *pri_rs) { CompareState *s =3D container_of(pri_rs, CompareState, pri_rs); @@ -1129,6 +1162,11 @@ static void colo_compare_complete(UserCreatable *uc,= Error **errp) s->compare_timeout =3D DEFAULT_TIME_OUT_MS; } =20 + if (!s->expired_scan_cycle) { + /* Set default value to 3000 MS */ + s->expired_scan_cycle =3D REGULAR_PACKET_CHECK_MS; + } + if (find_and_check_chardev(&chr, s->pri_indev, errp) || !qemu_chr_fe_init(&s->chr_pri_in, chr, errp)) { return; @@ -1228,6 +1266,10 @@ static void colo_compare_init(Object *obj) compare_get_timeout, compare_set_timeout, NULL, NULL, NULL); =20 + object_property_add(obj, "expired_scan_cycle", "uint32", + compare_get_expired_scan_cycle, + compare_set_expired_scan_cycle, NULL, NULL, NULL); + s->vnet_hdr =3D false; object_property_add_bool(obj, "vnet_hdr_support", compare_get_vnet_hdr, compare_set_vnet_hdr, NULL); diff --git a/qemu-options.hx b/qemu-options.hx index 9e48e13..16debd0 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -4615,7 +4615,7 @@ SRST stored. The file format is libpcap, so it can be analyzed with tools such as tcpdump or Wireshark. =20 - ``-object colo-compare,id=3Did,primary_in=3Dchardevid,secondary_in=3Dc= hardevid,outdev=3Dchardevid,iothread=3Did[,vnet_hdr_support][,notify_dev=3D= id][,compare_timeout=3D@var{ms}]`` + ``-object colo-compare,id=3Did,primary_in=3Dchardevid,secondary_in=3Dc= hardevid,outdev=3Dchardevid,iothread=3Did[,vnet_hdr_support][,notify_dev=3D= id][,compare_timeout=3D@var{ms}][,expired_scan_cycle=3D@var{ms}`` Colo-compare gets packet from primary\_inchardevid and secondary\_inchardevid, than compare primary packet with secondary packet. If the packets are same, we will output @@ -4626,6 +4626,8 @@ SRST vnet\_hdr\_support flag, colo compare will send/recv packet with vnet\_hdr\_len. Then compare\_timeout=3D@var{ms} determines the maximum delay colo-compare wait for the packet. + The expired\_scan\_cycle=3D@var{ms} to set the period of scanning + expired primary node network packets. If you want to use Xen COLO, will need the notify\_dev to notify Xen colo-frame to do checkpoint. =20 --=20 2.5.0 From nobody Mon May 6 08:14:37 2024 Delivered-To: importer@patchew.org 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; Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1585661299; cv=none; d=zohomail.com; s=zohoarc; b=ZEpwMZth4yOrxHsOlG9h6LsgAr/E9r9JJACbF8flMgejgqZrD1RqW8819DAt8uylsLWGwLEubDDvrVwsiPuIftaX+eWImLKrtByMTXVptEhj9SHE/hTAqkKPoxJV7dWBBCF1Eg7VX33hQOShuppPjOrskpnGV9OwDrJvNNaRcGg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585661299; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=gwuzM2jNqoM564i9vFKMIxyP47Rn9FTVs3Xjz/vfwQI=; b=QokKupDu15WxXanBAcgmJwshpOoekAlpdWf20SYscXczEUu3FgNCFafX6L0Xj5M7+/RwtlMPii+HCgS5PLx8zqQhcW5xcht5rrUkUOw5XPluLbSY9VeadynS5GEa3D5DCSRXYoqLS/CiPqY70fx0E0BU9Vw+awBdp8eTDTzBtIY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1585661299940625.9333149784374; Tue, 31 Mar 2020 06:28:19 -0700 (PDT) Received: from localhost ([::1]:38034 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJGwE-0002Gi-MO for importer@patchew.org; Tue, 31 Mar 2020 09:28:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42087) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJGqW-0000d3-VG for qemu-devel@nongnu.org; Tue, 31 Mar 2020 09:22:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jJGqT-0005uu-Fe for qemu-devel@nongnu.org; Tue, 31 Mar 2020 09:22:24 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:30921 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jJGqT-0005ud-AH for qemu-devel@nongnu.org; Tue, 31 Mar 2020 09:22:21 -0400 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-395-yYt2IVyPNQCGgPxvnJ3fJA-1; Tue, 31 Mar 2020 09:22:18 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5880B18FF663; Tue, 31 Mar 2020 13:22:17 +0000 (UTC) Received: from jason-ThinkPad-T430s.redhat.com (ovpn-12-118.pek2.redhat.com [10.72.12.118]) by smtp.corp.redhat.com (Postfix) with ESMTP id AA21E1001B28; Tue, 31 Mar 2020 13:22:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1585660941; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gwuzM2jNqoM564i9vFKMIxyP47Rn9FTVs3Xjz/vfwQI=; b=G7rM3XcQhK7YZPsuAHrneUSE/0tBSPEhmh4/BE2Nm/T09WoA4dQ2l+9QyKL3v1c+8KiFrY CNXhhqIbdk/RQePyNE8MLPltcFKGax0RJhw32Su3lB8AcnFgG4cvYYtXnSIYoIYYfRmBdy Gr9vJ2yg0P33AsT2dRvzNKT353Z4vWw= X-MC-Unique: yYt2IVyPNQCGgPxvnJ3fJA-1 From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Subject: [PULL V2 12/14] net: tulip: check frame size and r/w data length Date: Tue, 31 Mar 2020 21:21:37 +0800 Message-Id: <1585660899-11228-13-git-send-email-jasowang@redhat.com> In-Reply-To: <1585660899-11228-1-git-send-email-jasowang@redhat.com> References: <1585660899-11228-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jason Wang , Prasad J Pandit Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Prasad J Pandit Tulip network driver while copying tx/rx buffers does not check frame size against r/w data length. This may lead to OOB buffer access. Add check to avoid it. Limit iterations over descriptors to avoid potential infinite loop issue in tulip_xmit_list_update. Reported-by: Li Qiang Reported-by: Ziming Zhang Reported-by: Jason Wang Tested-by: Li Qiang Reviewed-by: Li Qiang Signed-off-by: Prasad J Pandit Signed-off-by: Jason Wang --- hw/net/tulip.c | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/hw/net/tulip.c b/hw/net/tulip.c index cfac271..1295f51 100644 --- a/hw/net/tulip.c +++ b/hw/net/tulip.c @@ -170,6 +170,10 @@ static void tulip_copy_rx_bytes(TULIPState *s, struct = tulip_descriptor *desc) } else { len =3D s->rx_frame_len; } + + if (s->rx_frame_len + len > sizeof(s->rx_frame)) { + return; + } pci_dma_write(&s->dev, desc->buf_addr1, s->rx_frame + (s->rx_frame_size - s->rx_frame_len), len); s->rx_frame_len -=3D len; @@ -181,6 +185,10 @@ static void tulip_copy_rx_bytes(TULIPState *s, struct = tulip_descriptor *desc) } else { len =3D s->rx_frame_len; } + + if (s->rx_frame_len + len > sizeof(s->rx_frame)) { + return; + } pci_dma_write(&s->dev, desc->buf_addr2, s->rx_frame + (s->rx_frame_size - s->rx_frame_len), len); s->rx_frame_len -=3D len; @@ -227,7 +235,8 @@ static ssize_t tulip_receive(TULIPState *s, const uint8= _t *buf, size_t size) =20 trace_tulip_receive(buf, size); =20 - if (size < 14 || size > 2048 || s->rx_frame_len || tulip_rx_stopped(s)= ) { + if (size < 14 || size > sizeof(s->rx_frame) - 4 + || s->rx_frame_len || tulip_rx_stopped(s)) { return 0; } =20 @@ -275,7 +284,6 @@ static ssize_t tulip_receive_nc(NetClientState *nc, return tulip_receive(qemu_get_nic_opaque(nc), buf, size); } =20 - static NetClientInfo net_tulip_info =3D { .type =3D NET_CLIENT_DRIVER_NIC, .size =3D sizeof(NICState), @@ -558,7 +566,7 @@ static void tulip_tx(TULIPState *s, struct tulip_descri= ptor *desc) if ((s->csr[6] >> CSR6_OM_SHIFT) & CSR6_OM_MASK) { /* Internal or external Loopback */ tulip_receive(s, s->tx_frame, s->tx_frame_len); - } else { + } else if (s->tx_frame_len <=3D sizeof(s->tx_frame)) { qemu_send_packet(qemu_get_queue(s->nic), s->tx_frame, s->tx_frame_len); } @@ -570,23 +578,31 @@ static void tulip_tx(TULIPState *s, struct tulip_desc= riptor *desc) } } =20 -static void tulip_copy_tx_buffers(TULIPState *s, struct tulip_descriptor *= desc) +static int tulip_copy_tx_buffers(TULIPState *s, struct tulip_descriptor *d= esc) { int len1 =3D (desc->control >> TDES1_BUF1_SIZE_SHIFT) & TDES1_BUF1_SIZ= E_MASK; int len2 =3D (desc->control >> TDES1_BUF2_SIZE_SHIFT) & TDES1_BUF2_SIZ= E_MASK; =20 + if (s->tx_frame_len + len1 > sizeof(s->tx_frame)) { + return -1; + } if (len1) { pci_dma_read(&s->dev, desc->buf_addr1, s->tx_frame + s->tx_frame_len, len1); s->tx_frame_len +=3D len1; } =20 + if (s->tx_frame_len + len2 > sizeof(s->tx_frame)) { + return -1; + } if (len2) { pci_dma_read(&s->dev, desc->buf_addr2, s->tx_frame + s->tx_frame_len, len2); s->tx_frame_len +=3D len2; } desc->status =3D (len1 + len2) ? 0 : 0x7fffffff; + + return 0; } =20 static void tulip_setup_filter_addr(TULIPState *s, uint8_t *buf, int n) @@ -651,13 +667,15 @@ static uint32_t tulip_ts(TULIPState *s) =20 static void tulip_xmit_list_update(TULIPState *s) { +#define TULIP_DESC_MAX 128 + uint8_t i =3D 0; struct tulip_descriptor desc; =20 if (tulip_ts(s) !=3D CSR5_TS_SUSPENDED) { return; } =20 - for (;;) { + for (i =3D 0; i < TULIP_DESC_MAX; i++) { tulip_desc_read(s, s->current_tx_desc, &desc); tulip_dump_tx_descriptor(s, &desc); =20 @@ -675,10 +693,10 @@ static void tulip_xmit_list_update(TULIPState *s) s->tx_frame_len =3D 0; } =20 - tulip_copy_tx_buffers(s, &desc); - - if (desc.control & TDES1_LS) { - tulip_tx(s, &desc); + if (!tulip_copy_tx_buffers(s, &desc)) { + if (desc.control & TDES1_LS) { + tulip_tx(s, &desc); + } } } tulip_desc_write(s, s->current_tx_desc, &desc); --=20 2.5.0 From nobody Mon May 6 08:14:37 2024 Delivered-To: importer@patchew.org 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; 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=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1585661734; cv=none; d=zohomail.com; s=zohoarc; b=g16Ocl4S2SWA9KrRZuMSUSLjVytXidlKxY9tdXmNLY32ncgUmVBq+bBuPxrBucNMGd71VzYJrvBftcq/JTX6Rl76ydrFV3ldMrx2+HmMOfc9N6ujbnViVXSgUINipvH4d/d9Arzh1gqQxP96SQ5X0nqwBo5cgRQemz4i+2L1OmQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585661734; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=e2MtJXqXrK00L/Pg7ncr4ONHm/ufHOeDphL4A31MD7k=; b=IgxPy3synEnN1EJQlQVe4O6v31b+hAhkjtqS1iv7NkZXvQOFfb+1bJSTpFqq/HNUmKx+5cN/i0ifXtXjkeLS8nytM466yP+GQ9gj6SKg96E6MyH+NvN9z4R9LQJjnBnpmFTTWq3LVKAJ9U22uaz5854I7IhcocNf3bJTOCaL2d4= 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=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1585661734608464.58183073877876; Tue, 31 Mar 2020 06:35:34 -0700 (PDT) Received: from localhost ([::1]:38178 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJH3F-0004Nq-8a for importer@patchew.org; Tue, 31 Mar 2020 09:35:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42111) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJGqZ-0000hD-6Y for qemu-devel@nongnu.org; Tue, 31 Mar 2020 09:22:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jJGqY-0005yG-47 for qemu-devel@nongnu.org; Tue, 31 Mar 2020 09:22:27 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:23412 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jJGqX-0005xU-WC for qemu-devel@nongnu.org; Tue, 31 Mar 2020 09:22:26 -0400 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-135-8kQxrIl1O6CN6riw5Hu-sg-1; Tue, 31 Mar 2020 09:22:20 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3FD45107B267; Tue, 31 Mar 2020 13:22:19 +0000 (UTC) Received: from jason-ThinkPad-T430s.redhat.com (ovpn-12-118.pek2.redhat.com [10.72.12.118]) by smtp.corp.redhat.com (Postfix) with ESMTP id D72801001B28; Tue, 31 Mar 2020 13:22:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1585660945; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=e2MtJXqXrK00L/Pg7ncr4ONHm/ufHOeDphL4A31MD7k=; b=XK4II3KmupQ9QldskIz3TequTmVzdJELICFdFO0eZlP/F98KehM4qA+SBoVrT84VPoJ5o6 LtL8l/JLJOvsja9xUPfRd4zxUgS3tVTeR9MFNyA2JIKuJYiUJ8DC1rajDD8f0ZlVGpg7Qk V7UV4ACuoXbYTCUgqpfeAoY6Sp5HYlg= X-MC-Unique: 8kQxrIl1O6CN6riw5Hu-sg-1 From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Subject: [PULL V2 13/14] hw/net/allwinner-sun8i-emac.c: Fix REG_ADDR_HIGH/LOW reads Date: Tue, 31 Mar 2020 21:21:38 +0800 Message-Id: <1585660899-11228-14-git-send-email-jasowang@redhat.com> In-Reply-To: <1585660899-11228-1-git-send-email-jasowang@redhat.com> References: <1585660899-11228-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jason Wang Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Peter Maydell Coverity points out (CID 1421926) that the read code for REG_ADDR_HIGH reads off the end of the buffer, because it does a 32-bit read from byte 4 of a 6-byte buffer. The code also has an endianness issue for both REG_ADDR_HIGH and REG_ADDR_LOW, because it will do the wrong thing on a big-endian host. Rewrite the read code to use ldl_le_p() and lduw_le_p() to fix this; the write code is not incorrect, but for consistency we make it use stl_le_p() and stw_le_p(). Reviewed-by: Richard Henderson Tested-by: Niek Linnenbank Reviewed-by: Niek Linnenbank Signed-off-by: Peter Maydell Signed-off-by: Jason Wang --- hw/net/allwinner-sun8i-emac.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/hw/net/allwinner-sun8i-emac.c b/hw/net/allwinner-sun8i-emac.c index 033eaa8..28637ff 100644 --- a/hw/net/allwinner-sun8i-emac.c +++ b/hw/net/allwinner-sun8i-emac.c @@ -611,10 +611,10 @@ static uint64_t allwinner_sun8i_emac_read(void *opaqu= e, hwaddr offset, value =3D s->mii_data; break; case REG_ADDR_HIGH: /* MAC Address High */ - value =3D *(((uint32_t *) (s->conf.macaddr.a)) + 1); + value =3D lduw_le_p(s->conf.macaddr.a + 4); break; case REG_ADDR_LOW: /* MAC Address Low */ - value =3D *(uint32_t *) (s->conf.macaddr.a); + value =3D ldl_le_p(s->conf.macaddr.a); break; case REG_TX_DMA_STA: /* Transmit DMA Status */ break; @@ -728,14 +728,10 @@ static void allwinner_sun8i_emac_write(void *opaque, = hwaddr offset, s->mii_data =3D value; break; case REG_ADDR_HIGH: /* MAC Address High */ - s->conf.macaddr.a[4] =3D (value & 0xff); - s->conf.macaddr.a[5] =3D (value & 0xff00) >> 8; + stw_le_p(s->conf.macaddr.a + 4, value); break; case REG_ADDR_LOW: /* MAC Address Low */ - s->conf.macaddr.a[0] =3D (value & 0xff); - s->conf.macaddr.a[1] =3D (value & 0xff00) >> 8; - s->conf.macaddr.a[2] =3D (value & 0xff0000) >> 16; - s->conf.macaddr.a[3] =3D (value & 0xff000000) >> 24; + stl_le_p(s->conf.macaddr.a, value); break; case REG_TX_DMA_STA: /* Transmit DMA Status */ case REG_TX_CUR_DESC: /* Transmit Current Descriptor */ --=20 2.5.0 From nobody Mon May 6 08:14:37 2024 Delivered-To: importer@patchew.org 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; Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1585661631; cv=none; d=zohomail.com; s=zohoarc; b=MRc1rbo+4/vIBrxnchjJvOw0Oi5KhZ39rvr+nAAH3lcvwoL5jshWAX45XkCAdIdx03S8bll0Dlz46jBBrMSw/3lZlKoW1g042HmxCXhac1eNLI8eyS0vrxE5BgzbmhMeuayULQp6CjlZySxoMOJWnfuegRTVgPXncyhqsb5gRDY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585661631; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=+pTlxa/x9EP+upjPVUSiOgJyID2EhyRKFM+xAXG+zpU=; b=X4ZyEoRvNgPu5oH+JhHmIIKXffyDHZXyQM1BBxG0l1uXmtGrXJyFV+w76MeAS4WLrt9ASDjnsLBXKJDSFMCkQ1RL+GlZuIGyw1zOIbKmkOg8tN8a7T1Htjkgdwytvy9y8SpAwPVGlQ35bZo0e2JTJDi1qD+kGN8b7wzcHUX0EY4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1585661631108608.1403985919569; Tue, 31 Mar 2020 06:33:51 -0700 (PDT) Received: from localhost ([::1]:38154 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJH1Z-0001r5-SL for importer@patchew.org; Tue, 31 Mar 2020 09:33:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42105) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJGqY-0000gW-II for qemu-devel@nongnu.org; Tue, 31 Mar 2020 09:22:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jJGqX-0005wl-2Y for qemu-devel@nongnu.org; Tue, 31 Mar 2020 09:22:26 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:47005 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jJGqW-0005w1-Tc for qemu-devel@nongnu.org; Tue, 31 Mar 2020 09:22:24 -0400 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-45-SCYK1mAUOtWTJfCNoPfK1w-1; Tue, 31 Mar 2020 09:22:22 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6B6E018FF66D; Tue, 31 Mar 2020 13:22:21 +0000 (UTC) Received: from jason-ThinkPad-T430s.redhat.com (ovpn-12-118.pek2.redhat.com [10.72.12.118]) by smtp.corp.redhat.com (Postfix) with ESMTP id BE15D1001B28; Tue, 31 Mar 2020 13:22:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1585660944; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+pTlxa/x9EP+upjPVUSiOgJyID2EhyRKFM+xAXG+zpU=; b=ZdhGlM8Mz6rLRN8rHTiAaOY39tbv8y8J/u908m0lcfnjtck/kaZCeTFQbjqVmVerbIpQuJ 3UJj7kikzgR7osxzAO4hQzDStEl/7SKStqivKRhR17eFNyCZvqNnUL3c91MEJcFIm/9Ngk NfwZrtmLF9fmXsrr+f+x3A7nIYltl5s= X-MC-Unique: SCYK1mAUOtWTJfCNoPfK1w-1 From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Subject: [PULL V2 14/14] qtest: add tulip test case Date: Tue, 31 Mar 2020 21:21:39 +0800 Message-Id: <1585660899-11228-15-git-send-email-jasowang@redhat.com> In-Reply-To: <1585660899-11228-1-git-send-email-jasowang@redhat.com> References: <1585660899-11228-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jason Wang , Li Qiang Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Li Qiang The tulip networking card emulation has an OOB issue in 'tulip_copy_tx_buffers' when the guest provide malformed descriptor. This test will trigger a ASAN heap overflow crash. To trigger this issue we can construct the data as following: 1. construct a 'tulip_descriptor'. Its control is set to '0x7ff | 0x7ff << 11', this will make the 'tulip_copy_tx_buffers's 'len1' and 'len2' to 0x7ff(2047). So 'len1+len2' will overflow 'TULIPState's 'tx_frame' field. This descriptor's 'buf_addr1' and 'buf_addr2' should set to a guest address. 2. write this descriptor to tulip device's CSR4 register. This will set the 'TULIPState's 'current_tx_desc' field. 3. write 'CSR6_ST' to tulip device's CSR6 register. This will trigger 'tulip_xmit_list_update' and finally calls 'tulip_copy_tx_buffers'. Following shows the backtrack of crash: =3D=3D31781=3D=3DERROR: AddressSanitizer: heap-buffer-overflow on address 0= x628000007cd0 at pc 0x7fe03c5a077a bp 0x7fff05b46770 sp 0x7fff05b45f18 WRITE of size 2047 at 0x628000007cd0 thread T0 #0 0x7fe03c5a0779 (/usr/lib/x86_64-linux-gnu/libasan.so.4+0x79779) #1 0x5575fb6daa6a in flatview_read_continue /home/test/qemu/exec.c:3194 #2 0x5575fb6daccb in flatview_read /home/test/qemu/exec.c:3227 #3 0x5575fb6dae66 in address_space_read_full /home/test/qemu/exec.c:3240 #4 0x5575fb6db0cb in address_space_rw /home/test/qemu/exec.c:3268 #5 0x5575fbdfd460 in dma_memory_rw_relaxed /home/test/qemu/include/syse= mu/dma.h:87 #6 0x5575fbdfd4b5 in dma_memory_rw /home/test/qemu/include/sysemu/dma.h= :110 #7 0x5575fbdfd866 in pci_dma_rw /home/test/qemu/include/hw/pci/pci.h:787 #8 0x5575fbdfd8a3 in pci_dma_read /home/test/qemu/include/hw/pci/pci.h:= 794 #9 0x5575fbe02761 in tulip_copy_tx_buffers hw/net/tulip.c:585 #10 0x5575fbe0366b in tulip_xmit_list_update hw/net/tulip.c:678 #11 0x5575fbe04073 in tulip_write hw/net/tulip.c:783 Signed-off-by: Li Qiang Signed-off-by: Jason Wang --- tests/qtest/Makefile.include | 1 + tests/qtest/tulip-test.c | 91 ++++++++++++++++++++++++++++++++++++++++= ++++ 2 files changed, 92 insertions(+) create mode 100644 tests/qtest/tulip-test.c diff --git a/tests/qtest/Makefile.include b/tests/qtest/Makefile.include index 10a28de..9e5a51d 100644 --- a/tests/qtest/Makefile.include +++ b/tests/qtest/Makefile.include @@ -217,6 +217,7 @@ qos-test-obj-y +=3D tests/qtest/es1370-test.o qos-test-obj-y +=3D tests/qtest/ipoctal232-test.o qos-test-obj-y +=3D tests/qtest/megasas-test.o qos-test-obj-y +=3D tests/qtest/ne2000-test.o +qos-test-obj-y +=3D tests/qtest/tulip-test.o qos-test-obj-y +=3D tests/qtest/nvme-test.o qos-test-obj-y +=3D tests/qtest/pca9552-test.o qos-test-obj-y +=3D tests/qtest/pci-test.o diff --git a/tests/qtest/tulip-test.c b/tests/qtest/tulip-test.c new file mode 100644 index 0000000..2fb6c4d --- /dev/null +++ b/tests/qtest/tulip-test.c @@ -0,0 +1,91 @@ +/* + * QTest testcase for DEC/Intel Tulip 21143 + * + * Copyright (c) 2020 Li Qiang + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include "libqtest.h" +#include "qemu/module.h" +#include "libqos/qgraph.h" +#include "libqos/pci.h" +#include "qemu/bitops.h" +#include "hw/net/tulip.h" + +typedef struct QTulip_pci QTulip_pci; + +struct QTulip_pci { + QOSGraphObject obj; + QPCIDevice dev; +}; + +static void *tulip_pci_get_driver(void *obj, const char *interface) +{ + QTulip_pci *tulip_pci =3D obj; + + if (!g_strcmp0(interface, "pci-device")) { + return &tulip_pci->dev; + } + + fprintf(stderr, "%s not present in tulip_pci\n", interface); + g_assert_not_reached(); +} + +static void *tulip_pci_create(void *pci_bus, QGuestAllocator *alloc, void = *addr) +{ + QTulip_pci *tulip_pci =3D g_new0(QTulip_pci, 1); + QPCIBus *bus =3D pci_bus; + + qpci_device_init(&tulip_pci->dev, bus, addr); + tulip_pci->obj.get_driver =3D tulip_pci_get_driver; + + return &tulip_pci->obj; +} + +static void tulip_large_tx(void *obj, void *data, QGuestAllocator *alloc) +{ + QTulip_pci *tulip_pci =3D obj; + QPCIDevice *dev =3D &tulip_pci->dev; + QPCIBar bar; + struct tulip_descriptor context; + char guest_data[4096]; + uint64_t context_pa; + uint64_t guest_pa; + + qpci_device_enable(dev); + bar =3D qpci_iomap(dev, 0, NULL); + context_pa =3D guest_alloc(alloc, sizeof(context)); + guest_pa =3D guest_alloc(alloc, 4096); + memset(guest_data, 'A', sizeof(guest_data)); + context.status =3D TDES0_OWN; + context.control =3D TDES1_BUF2_SIZE_MASK << TDES1_BUF2_SIZE_SHIFT | + TDES1_BUF1_SIZE_MASK << TDES1_BUF1_SIZE_SHIFT; + context.buf_addr2 =3D guest_pa; + context.buf_addr1 =3D guest_pa; + + qtest_memwrite(dev->bus->qts, context_pa, &context, sizeof(context)); + qtest_memwrite(dev->bus->qts, guest_pa, guest_data, sizeof(guest_data)= ); + qpci_io_writel(dev, bar, 0x20, context_pa); + qpci_io_writel(dev, bar, 0x30, CSR6_ST); + guest_free(alloc, context_pa); + guest_free(alloc, guest_pa); +} + +static void tulip_register_nodes(void) +{ + QOSGraphEdgeOptions opts =3D { + .extra_device_opts =3D "addr=3D04.0", + }; + add_qpci_address(&opts, &(QPCIAddress) { .devfn =3D QPCI_DEVFN(4, 0) }= ); + + qos_node_create_driver("tulip", tulip_pci_create); + qos_node_consumes("tulip", "pci-bus", &opts); + qos_node_produces("tulip", "pci-device"); + + qos_add_test("tulip_large_tx", "tulip", tulip_large_tx, NULL); +} + +libqos_init(tulip_register_nodes); --=20 2.5.0