From nobody Mon Apr 29 19:36:05 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=1585307729; cv=none; d=zohomail.com; s=zohoarc; b=ka4i/yxX4vjcmOw0nUBFeYWRjiljQk+3tpl0VEYIGYlilSl2XKmJA0EiuMplSFDd/ujY2HAqk6BpzSVJ0w2OiVrcTqAi3PoZzFJcQm6Y2TvSFGc5ERxUz443gCdTiIZblPxL1kLKw9jXDN+ovZQDFSyrdVSHX0J/t8fyjut19oY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585307729; 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=GuWb6Liu7KNWP1vsSAec2RYzgL80kufcdg4oftzxiUB3PIc9yfFkizVB12pJn6avdFgofW7XcHg/PHNXhOCAnvwwL6ZLtaEQHvRRKGzQ87zaPiVLGof6ak6By31DM3wEMIceGpDO1lc/+jPNVeoyfc3mJkO0NIEYLqRw8+4v12M= 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 1585307729252733.2467517351465; Fri, 27 Mar 2020 04:15:29 -0700 (PDT) Received: from localhost ([::1]:40300 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jHmxT-000298-6d for importer@patchew.org; Fri, 27 Mar 2020 07:15:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37671) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jHmwN-0000cK-Fu for qemu-devel@nongnu.org; Fri, 27 Mar 2020 07:14:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jHmwM-0001Du-1P for qemu-devel@nongnu.org; Fri, 27 Mar 2020 07:14:19 -0400 Received: from us-smtp-delivery-74.mimecast.com ([216.205.24.74]:21047) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jHmwL-00018Q-TO for qemu-devel@nongnu.org; Fri, 27 Mar 2020 07:14:17 -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-115-Q0EmkO2QMyO8oLyBXwXSbA-1; Fri, 27 Mar 2020 07:14:14 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 926D1801E53; Fri, 27 Mar 2020 11:14:13 +0000 (UTC) Received: from jason-ThinkPad-T430s.redhat.com (ovpn-12-77.pek2.redhat.com [10.72.12.77]) by smtp.corp.redhat.com (Postfix) with ESMTP id DAF735E01F; Fri, 27 Mar 2020 11:14:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1585307657; 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=YOkKFWd04Yrt2ZtHxyqg5UDNq8xGGrFSWe8XMZE1vvLwqD0rgGqG3ESn2kYtgdb34Mf4km UccWpHn8W2Qu1dSyndd2+EldH7XdApTGyfJ3CMoIzZRLzL8M2hJTsiX11FHZIpj51OQl27 zjVQCeUyamNJgL8ycVXZZxJQg5PeO/k= X-MC-Unique: Q0EmkO2QMyO8oLyBXwXSbA-1 From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Subject: [PULL 01/13] hw/net/i82596: Correct command bitmask (CID 1419392) Date: Fri, 27 Mar 2020 19:13:55 +0800 Message-Id: <1585307647-24456-2-git-send-email-jasowang@redhat.com> In-Reply-To: <1585307647-24456-1-git-send-email-jasowang@redhat.com> References: <1585307647-24456-1-git-send-email-jasowang@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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: 216.205.24.74 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 Apr 29 19:36:05 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=1585307732; cv=none; d=zohomail.com; s=zohoarc; b=Ni7jGc35/lUJOlg7PDACrifDJVxyye+nUzfOl8iOY7MjQswJQTMHKu2X+35Z8Jzewz9R6lxyksONXx/ZoggAw286p45Ls/iV0kVF5wobvnJDAA628MIPxQ4DS+TTS5z+CUB978PkG0yB0ipuQKVFfLvJE4YvAjPnHH6EeuE/Q/E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585307732; 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=qtWw28fp9uAXP1+QUNc+crdXF5Chv0nlMJAFt9zgSUY=; b=ncQ3BGeFCyQGNxMADzQvZP56+D2XKm385DLFJsbuqweNKgebq5rXce1n5xyiPJ1GsDVSsXGbgkr+QNXZ5QTfUpHaXR7UowXQQwKWmUvA/8/74fdhvkpRG0f03Yin24nPWf5HqY9rb0Z0o4SMc8lRsqa0c6akZbc3J9bi3ZbemPE= 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 1585307732137826.2660698810922; Fri, 27 Mar 2020 04:15:32 -0700 (PDT) Received: from localhost ([::1]:40310 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jHmxW-0002F0-P3 for importer@patchew.org; Fri, 27 Mar 2020 07:15:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37735) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jHmwQ-0000dr-2I for qemu-devel@nongnu.org; Fri, 27 Mar 2020 07:14:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jHmwO-0001Qy-PM for qemu-devel@nongnu.org; Fri, 27 Mar 2020 07:14:21 -0400 Received: from us-smtp-delivery-74.mimecast.com ([216.205.24.74]:40931) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jHmwO-0001QE-Lj for qemu-devel@nongnu.org; Fri, 27 Mar 2020 07:14: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-177-G9Ugy_tQM5Kam8E336TqgQ-1; Fri, 27 Mar 2020 07:14:16 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7CF1D800D4E; Fri, 27 Mar 2020 11:14:15 +0000 (UTC) Received: from jason-ThinkPad-T430s.redhat.com (ovpn-12-77.pek2.redhat.com [10.72.12.77]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1C60F5E01D; Fri, 27 Mar 2020 11:14:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1585307660; 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=qtWw28fp9uAXP1+QUNc+crdXF5Chv0nlMJAFt9zgSUY=; b=g5JGauPmuWLyPT+vqcqJ0CFXP8Nj1dIP9LSJWv7Ufhd1taycD2AUN/ZJyIXc+YMRZ9on1m Z/B7ml1l+KTUnIJS0uj4Pin9X4HRqO1TmpJXOH7X/OSLRXS/aE3y15q3o672J8ubKxyHKX kHgPk0UoM6UNKcajGY2jEJIerH/4hYE= X-MC-Unique: G9Ugy_tQM5Kam8E336TqgQ-1 From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Subject: [PULL 02/13] hw/net/i82596.c: Avoid reading off end of buffer in i82596_receive() Date: Fri, 27 Mar 2020 19:13:56 +0800 Message-Id: <1585307647-24456-3-git-send-email-jasowang@redhat.com> In-Reply-To: <1585307647-24456-1-git-send-email-jasowang@redhat.com> References: <1585307647-24456-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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: 216.205.24.74 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..f9607ad 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 */ + bufsz -=3D bufcount; + assert(bufsz >=3D 0); + 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 Apr 29 19:36:05 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=1585307847; cv=none; d=zohomail.com; s=zohoarc; b=GYaetZgLL4nPwdk60/sg0NGLefsRh1bEIOUja8OLeeVpjd2hWJTADnP0fk93IM++otWPYlEiUR5hozael9qXuHOeakLxQox7PkXSBdwX9xYl0bEJ0afVp5nJfMtA2bbI8G2g9AcNTZclmF4R1voeyyTxcccmv3FY2SV3PN599zQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585307847; 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=dz8rlmq2vD17zCGAlPFu8eXWP++7MfwtrNopiuePqe0kmmuZ/QY8M6QbPaG2+o5CCVJWaDga4SxPQ59FmrH4GNX5yNKt7okywgQbs5FvpdkXTHzniUsGfTrHirXoRYJk2GXdSUu6b2xWMtoPoZKHiOQHWOGTwXQDe+DElY7mgcg= 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 15853078472661.314957678122937; Fri, 27 Mar 2020 04:17:27 -0700 (PDT) Received: from localhost ([::1]:40346 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jHmzN-0005gH-FF for importer@patchew.org; Fri, 27 Mar 2020 07:17:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37763) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jHmwQ-0000ek-Vy for qemu-devel@nongnu.org; Fri, 27 Mar 2020 07:14:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jHmwP-0001VE-Rb for qemu-devel@nongnu.org; Fri, 27 Mar 2020 07:14:22 -0400 Received: from us-smtp-delivery-74.mimecast.com ([63.128.21.74]:39088) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jHmwP-0001TE-NQ for qemu-devel@nongnu.org; Fri, 27 Mar 2020 07:14: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-486-ZNI5rlmEN4CVIge7hMCfWA-1; Fri, 27 Mar 2020 07:14:18 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id BA1A6800D4E; Fri, 27 Mar 2020 11:14:17 +0000 (UTC) Received: from jason-ThinkPad-T430s.redhat.com (ovpn-12-77.pek2.redhat.com [10.72.12.77]) by smtp.corp.redhat.com (Postfix) with ESMTP id 07E475E030; Fri, 27 Mar 2020 11:14:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1585307661; 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=RsBuIhKpkJCtLUWR6vu4Np2umNc9E0rByxtZaGvn0qt+9BBChc4IC9BF0nrX0D6/vp7L86 ChL3yICp4MAfSc/ty9iqIW98wHax4Wsb8oN3/342bA7ert3673rjz9DsQPJmA0VUX7m7+z KQsmnBjaLQM+UumhWDUaWBfTBGrpFc0= X-MC-Unique: ZNI5rlmEN4CVIge7hMCfWA-1 From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Subject: [PULL 03/13] Fixed integer overflow in e1000e Date: Fri, 27 Mar 2020 19:13:57 +0800 Message-Id: <1585307647-24456-4-git-send-email-jasowang@redhat.com> In-Reply-To: <1585307647-24456-1-git-send-email-jasowang@redhat.com> References: <1585307647-24456-1-git-send-email-jasowang@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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: 63.128.21.74 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 Apr 29 19:36:05 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=1585307908; cv=none; d=zohomail.com; s=zohoarc; b=Z98LVTSHCkWqRCNO/ftCJi+blDIAdWuVmhhN8VOL+lzVpkyGt0rrbYnFS8P/3ijtd77ybgOl9BWuEYs7VHQJ7W3rPC/zLCzCkWsiJRaIf+/xfNVSZtSnCRYpxTEpVpGRubBSCiEIMXShQgeJMwhFUbamexFEmkPgPpcCF8WJmu0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585307908; 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=DpWPxlpIy7iw3Stop+0YAqYQ0y5h6sfrSt8580Uk3pVyrAGyXyawDBITO3teLO+oCejtwn9Hj/8lOoNciZ7Yd4gIP4idJM/vKvZ2zZGduAQ3WGbWlWoxHEJM1RxNjGy/xUsvyHS7pPI6PFQxP/FqspPjRt4JMTj7HyAnKWbyxPU= 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 1585307908935338.0936853418365; Fri, 27 Mar 2020 04:18:28 -0700 (PDT) Received: from localhost ([::1]:40354 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jHn0M-000788-KM for importer@patchew.org; Fri, 27 Mar 2020 07:18:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37809) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jHmwS-0000hc-Rq for qemu-devel@nongnu.org; Fri, 27 Mar 2020 07:14:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jHmwR-0001dO-Oq for qemu-devel@nongnu.org; Fri, 27 Mar 2020 07:14:24 -0400 Received: from us-smtp-delivery-74.mimecast.com ([63.128.21.74]:37636) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jHmwR-0001bf-L1 for qemu-devel@nongnu.org; Fri, 27 Mar 2020 07:14:23 -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-14-StUdd3W8ME2-RVHWgbCztw-1; Fri, 27 Mar 2020 07:14:20 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EA277107ACC4; Fri, 27 Mar 2020 11:14:19 +0000 (UTC) Received: from jason-ThinkPad-T430s.redhat.com (ovpn-12-77.pek2.redhat.com [10.72.12.77]) by smtp.corp.redhat.com (Postfix) with ESMTP id 46FB75E01D; Fri, 27 Mar 2020 11:14:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1585307663; 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=RWSaz0N5Yg5K/5BY2eO+QmTycpEoSaIk+l8N0PZobOALHyUgGJm53KMvDMZnMCOE1w/hrD QN9MMdeNZurao0LKrIPnsrq26jE7MXGUmAycvmfBfOi/ylu861n6mWWGf7BkUzDCw6tnV1 jTWrMw4HNFyIHUeIWzyEqbfisNLidKU= X-MC-Unique: StUdd3W8ME2-RVHWgbCztw-1 From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Subject: [PULL 04/13] hw/net/e1000e_core: Let e1000e_can_receive() return a boolean Date: Fri, 27 Mar 2020 19:13:58 +0800 Message-Id: <1585307647-24456-5-git-send-email-jasowang@redhat.com> In-Reply-To: <1585307647-24456-1-git-send-email-jasowang@redhat.com> References: <1585307647-24456-1-git-send-email-jasowang@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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: 63.128.21.74 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 Apr 29 19:36:05 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=1585307980; cv=none; d=zohomail.com; s=zohoarc; b=mECTFVaX0ZjKFByYDKTNc1qjQjwVtG4Uq1DoWF6UsuBRRPsX4D6s/U2ZYgA68KfDpDyEBYGEPOxWqgnBSGE6fzgZ2pSfzvZEyv7lh/at4F7+sGxkI8FYv9iz+GBCdxI2LmYzNMJ9aYDq3Q5WzasX8JHjcEZsEaEeJsIBXlMKFDo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585307980; 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=DplfX2akMQQsQDHesbDDkJdmWAmCGl4domJpW8B/wMnE5Y/7LxRKHVyXiSqdfjwKqte3OfOVBaiSz30ljxyM815jFzV2I78/hlZtL9P6SXSa+Nigy5h4Aw7ajESoZwUs2q8gIbShjFoxVk/SrNr3b7hz8A4IPSmFhR8u6oDXhS4= 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 1585307980150714.1401448028354; Fri, 27 Mar 2020 04:19:40 -0700 (PDT) Received: from localhost ([::1]:40370 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jHn1W-0000Yd-NH for importer@patchew.org; Fri, 27 Mar 2020 07:19:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37849) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jHmwU-0000nI-OQ for qemu-devel@nongnu.org; Fri, 27 Mar 2020 07:14:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jHmwT-0001je-Mc for qemu-devel@nongnu.org; Fri, 27 Mar 2020 07:14:26 -0400 Received: from us-smtp-delivery-74.mimecast.com ([216.205.24.74]:34078) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jHmwT-0001ij-IB for qemu-devel@nongnu.org; Fri, 27 Mar 2020 07:14:25 -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-183-6lD9y5vkOu2ncYo-OELmaA-1; Fri, 27 Mar 2020 07:14:23 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2642F100550E; Fri, 27 Mar 2020 11:14:22 +0000 (UTC) Received: from jason-ThinkPad-T430s.redhat.com (ovpn-12-77.pek2.redhat.com [10.72.12.77]) by smtp.corp.redhat.com (Postfix) with ESMTP id 756A25E016; Fri, 27 Mar 2020 11:14:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1585307665; 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=LM2jyzFrGEG7RpxnJGvxvNJ4jpGpbpq0ii1iHnOMUt2KxXxn85LECl9cLzizj2x6biF1JS QyFw2S02Q/AatIp35b5iRL8kl8wtrsOA6rvNBphDbLaHUfG5TOTiYHn/DwbpabM8lg2foJ QPHfbb1khSQJmp9mpidNpQ2JMLiRWng= X-MC-Unique: 6lD9y5vkOu2ncYo-OELmaA-1 From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Subject: [PULL 05/13] hw/net/smc91c111: Let smc91c111_can_receive() return a boolean Date: Fri, 27 Mar 2020 19:13:59 +0800 Message-Id: <1585307647-24456-6-git-send-email-jasowang@redhat.com> In-Reply-To: <1585307647-24456-1-git-send-email-jasowang@redhat.com> References: <1585307647-24456-1-git-send-email-jasowang@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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: 216.205.24.74 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 Apr 29 19:36:05 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=1585307748; cv=none; d=zohomail.com; s=zohoarc; b=RkE1VqdkHUh/lji2gVCIMANgB+5p7YIXP51bQ3HBwQ+AodoF3NQBgkCdld2grK1ZwZDjnhpyTKQcrrIimF7wU8fG8yIo93zVw5OLmn1ncxQfast+hbKqs4fOkGoetFldWcvWw1YUjUPMiJXuFyQfhiaIMulrJg8031qThtKdDDk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585307748; 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=Lj7FSZtE+fDMaA657dqrnDjdVqOAkNTCtylbQhqA/LKepjUfGryhtQHWsZbYvWZb5+2FbCqf3UaMmI0ZAO8dElDS6eX3EL/BzAaTTNE/WPefVVJqLCS2HgI/R0WfpXNbb2SmDM+ofLZE5K0c31EMfluMUN+WOAE4poX18oTkTCg= 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 1585307748588407.24825217523505; Fri, 27 Mar 2020 04:15:48 -0700 (PDT) Received: from localhost ([::1]:40312 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jHmxn-0002gO-6v for importer@patchew.org; Fri, 27 Mar 2020 07:15:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37910) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jHmwX-0000sY-Pi for qemu-devel@nongnu.org; Fri, 27 Mar 2020 07:14:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jHmwW-0001pS-NW for qemu-devel@nongnu.org; Fri, 27 Mar 2020 07:14:29 -0400 Received: from us-smtp-delivery-74.mimecast.com ([63.128.21.74]:41358) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jHmwW-0001oj-Ju for qemu-devel@nongnu.org; Fri, 27 Mar 2020 07:14:28 -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-306-eu5EqtgkPx-XfFPVKRN1Zg-1; Fri, 27 Mar 2020 07:14:25 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 51B5F8010E3; Fri, 27 Mar 2020 11:14:24 +0000 (UTC) Received: from jason-ThinkPad-T430s.redhat.com (ovpn-12-77.pek2.redhat.com [10.72.12.77]) by smtp.corp.redhat.com (Postfix) with ESMTP id A51E85E030; Fri, 27 Mar 2020 11:14:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1585307668; 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=EGXb0TfganaKNljIixqJpX/2r3qxm0i6+uItXGxOnnjZDA5+dSmq22P6zZmgKo28+EuIWI 6Kuv8J6AtM1Xwi+h1CiuMsg1aswlueW6YlGN5ZPWoyDxbhDiqyFEzxmreSLHYOnXjXOgiC utxFHlWk8ioo0qpndPoZTlHe9/0kXFg= X-MC-Unique: eu5EqtgkPx-XfFPVKRN1Zg-1 From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Subject: [PULL 06/13] hw/net/rtl8139: Simplify if/else statement Date: Fri, 27 Mar 2020 19:14:00 +0800 Message-Id: <1585307647-24456-7-git-send-email-jasowang@redhat.com> In-Reply-To: <1585307647-24456-1-git-send-email-jasowang@redhat.com> References: <1585307647-24456-1-git-send-email-jasowang@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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: 63.128.21.74 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 Apr 29 19:36:05 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=1585308011; cv=none; d=zohomail.com; s=zohoarc; b=kywpHp9dubvlIPCbptR++yFXBk/1LdUa5OvUTDgcIkN7ePVhVZ/5TsvINw4A95WGMkDH6UFuHM/0rWubv5vXfr1fRGAEVChbBcKBM1Lrr/kf01YxEy5pnGutH63iodYWkazzI204OIvYXrlrTQxWVWfR6iZtxWao7A+I6D2E9AY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585308011; 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=WXfZZjMdRh+OLmLlQ2DYKIuVm6xYLO9bvx7+TAKCP2ZkTCBpyf9Lr4G6RTr9sT1Iant6k/Rn2c9vD38tfZyYR0E8hxor2zpQ+K/QwtmoVj7VAhiecXGs6j42oD5s1WDswfwNrxDPX2wqBCwI9fENNWC91IGPL+2anvnYqRQfsHo= 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 1585308011248679.8058247850677; Fri, 27 Mar 2020 04:20:11 -0700 (PDT) Received: from localhost ([::1]:40374 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jHn21-0001VT-WB for importer@patchew.org; Fri, 27 Mar 2020 07:20:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37948) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jHmwZ-0000ux-1v for qemu-devel@nongnu.org; Fri, 27 Mar 2020 07:14:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jHmwX-0001u5-VO for qemu-devel@nongnu.org; Fri, 27 Mar 2020 07:14:30 -0400 Received: from us-smtp-delivery-74.mimecast.com ([216.205.24.74]:50095) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jHmwX-0001te-RG for qemu-devel@nongnu.org; Fri, 27 Mar 2020 07:14:29 -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-329-_hMmcQwfOHCJGS0o8-9Vig-1; Fri, 27 Mar 2020 07:14:27 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7E249801E53; Fri, 27 Mar 2020 11:14:26 +0000 (UTC) Received: from jason-ThinkPad-T430s.redhat.com (ovpn-12-77.pek2.redhat.com [10.72.12.77]) by smtp.corp.redhat.com (Postfix) with ESMTP id D19985E01F; Fri, 27 Mar 2020 11:14:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1585307669; 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=cEXqXOHinalba+ueXtbwok1/4huVSCSiNdnjRRZISO2t/tv+LIzSUqbnf25nHSqxvnbx8k bFiM9Rix6zceOmNmYwzsfEJaVKs/3jdooGFZzC5Goovsu6j0S4mfzHlrY6wiXRThEFoiB2 zTa3L441ZwLXsVupPFJdkzpfdShTPaY= X-MC-Unique: _hMmcQwfOHCJGS0o8-9Vig-1 From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Subject: [PULL 07/13] hw/net/rtl8139: Update coding style to make checkpatch.pl happy Date: Fri, 27 Mar 2020 19:14:01 +0800 Message-Id: <1585307647-24456-8-git-send-email-jasowang@redhat.com> In-Reply-To: <1585307647-24456-1-git-send-email-jasowang@redhat.com> References: <1585307647-24456-1-git-send-email-jasowang@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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: 216.205.24.74 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 Apr 29 19:36:05 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=1585307880; cv=none; d=zohomail.com; s=zohoarc; b=BRcJQnzJpW0TuwBaYK/Vvq6DDjY0nkGa37ScRmlpt3YEEYt/Y+bcINfkhDoqe01ycyKJiv7MNxIdfZDu7M9dwXA6EPIlyeI3AvistTHpb//czLx4brZR1woUq/p4OOHKv6XfDWNm5heklJ5XN7FObzK5vP25uiYMTsh/sQwialA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585307880; 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=doSG/i8E4VMGbssH4qRjzgch0OxiSCqcVxJVB2DdHyU=; b=Vi1+QCjPqAhQfYGijNQw4GQQXajtjdmWhPJ4/SBxBi9uF/ufvpiBpOT7X/+tNOYypLn7bDM4VLxDXihJMsE1XlwRr6wWAfjPN8is3g3UCo5TjfHuosk2Jbz7mHaUumrigFUYblzDPxcW6T3S7aHDAbbBtareM+8vUmjffcn15+4= 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 1585307880777870.4579547819645; Fri, 27 Mar 2020 04:18:00 -0700 (PDT) Received: from localhost ([::1]:40351 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jHmzv-0006Hy-GB for importer@patchew.org; Fri, 27 Mar 2020 07:17:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38009) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jHmwc-00012M-El for qemu-devel@nongnu.org; Fri, 27 Mar 2020 07:14:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jHmwa-0001xs-36 for qemu-devel@nongnu.org; Fri, 27 Mar 2020 07:14:34 -0400 Received: from us-smtp-delivery-74.mimecast.com ([63.128.21.74]:31539) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jHmwZ-0001xK-Th for qemu-devel@nongnu.org; Fri, 27 Mar 2020 07:14:32 -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-206-SFoctZSNNfOYpRHCYvyRDA-1; Fri, 27 Mar 2020 07:14:29 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id ADA2B1005509; Fri, 27 Mar 2020 11:14:28 +0000 (UTC) Received: from jason-ThinkPad-T430s.redhat.com (ovpn-12-77.pek2.redhat.com [10.72.12.77]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0A0C75E02A; Fri, 27 Mar 2020 11:14:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1585307671; 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=doSG/i8E4VMGbssH4qRjzgch0OxiSCqcVxJVB2DdHyU=; b=QdcptvStY4omqXtEZAFy93uBAwiIas+Ge+WWxdRWE01EEoTj184z9XEElWCxxsEV/4br7j YEn9RDRqIo1NWLbAZA3WqutIjL4eQ4y84xkwI7aK8tNndy8cF/2NE0vE3pZes2b/lsJwyA 9r1Uldm/vvRiEV9cGxtf1niI8IvP/s8= X-MC-Unique: SFoctZSNNfOYpRHCYvyRDA-1 From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Subject: [PULL 08/13] hw/net: Make NetCanReceive() return a boolean Date: Fri, 27 Mar 2020 19:14:02 +0800 Message-Id: <1585307647-24456-9-git-send-email-jasowang@redhat.com> In-Reply-To: <1585307647-24456-1-git-send-email-jasowang@redhat.com> References: <1585307647-24456-1-git-send-email-jasowang@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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: 63.128.21.74 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 f9607ad..a9bdbac 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 Apr 29 19:36:05 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=1585308078; cv=none; d=zohomail.com; s=zohoarc; b=FHXCOG4S1ySXLAK+YGA8DNOT/y5Cv6Ly4BV445FSPeWy8vDDv/Ms+gG8P46KL+9V5SmmauqwCqNsImdzyugNVWcgRn5P8gN1wg1+7Nefte2QSFc7J8Z+v3Z0lyNSz2Elmd6JoJTZEdTIU0/zveLOSyu7UnaEBp8QmpCUiNqmGiM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585308078; 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=IfY2ZtlHiL4jateNZsER6EbnuIhItjbibF6E20oqA9o=; b=Bn0Yq0hyJniskEgg1DB09o26KZYaq1/C8U4XiFzvIvi8zB/vSJjo7uFp8BnVipu+Ztv9tlq3DognL6MuMWwOrf1xqjDWbmxbqePrPALnBcdzX6aKBpk4Evs/UDGnfNSNeU+Y0d6o51oEK73seUuIeAMBqGBnmpYvaAKE2EpowFk= 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 1585308078084912.0869923734608; Fri, 27 Mar 2020 04:21:18 -0700 (PDT) Received: from localhost ([::1]:40410 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jHn36-00033s-UH for importer@patchew.org; Fri, 27 Mar 2020 07:21:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38054) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jHmwf-0001B1-KZ for qemu-devel@nongnu.org; Fri, 27 Mar 2020 07:14:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jHmwe-00024d-Ee for qemu-devel@nongnu.org; Fri, 27 Mar 2020 07:14:37 -0400 Received: from us-smtp-delivery-74.mimecast.com ([63.128.21.74]:29030) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jHmwe-00024G-AN for qemu-devel@nongnu.org; Fri, 27 Mar 2020 07:14:36 -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-352-Z9M-zn0fMr2xy0fQZYsb7g-1; Fri, 27 Mar 2020 07:14:31 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DE7BA1005509; Fri, 27 Mar 2020 11:14:30 +0000 (UTC) Received: from jason-ThinkPad-T430s.redhat.com (ovpn-12-77.pek2.redhat.com [10.72.12.77]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3886E5E01F; Fri, 27 Mar 2020 11:14:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1585307676; 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=IfY2ZtlHiL4jateNZsER6EbnuIhItjbibF6E20oqA9o=; b=FPSO6Zytbm0kTuHhLCWULsmQRmmhtwebxViGwr+UBHZK59/4Xv9aVCzPEZXFdhlXaFs5JJ kQof5dlhp2zMv47SeUBp8yvwkvmNRECA78R1IC+y0BfbMjN7WqSKAClf00djVc60SP/CdX Do5vX3KFqPZ+zNHvTJL+WL2yW3IQztI= X-MC-Unique: Z9M-zn0fMr2xy0fQZYsb7g-1 From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Subject: [PULL 09/13] hw/net/can: Make CanBusClientInfo::can_receive() return a boolean Date: Fri, 27 Mar 2020 19:14:03 +0800 Message-Id: <1585307647-24456-10-git-send-email-jasowang@redhat.com> In-Reply-To: <1585307647-24456-1-git-send-email-jasowang@redhat.com> References: <1585307647-24456-1-git-send-email-jasowang@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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: 63.128.21.74 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/can/can_sja1000.c | 8 ++++---- hw/net/can/can_sja1000.h | 2 +- include/net/can_emu.h | 2 +- net/can/can_socketcan.c | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) 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 Apr 29 19:36:05 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=1585307865; cv=none; d=zohomail.com; s=zohoarc; b=QPh5xlWJNPxYxUaB1r7XFFnVe7/a2677pNA0gi54zJ6t9M6MIakuh+BNguNqBiX6z7B0HN3XYtKzrsRu7+A5ThqxVr8fG/ZlSCG7TQT0ZwCEFxDdHmuTc+2FeULYK+72VlZ9gQ6e3ddM0OiGTWgCwDtt8cUs9FTPmogta0kgo8s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585307865; 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=gaAnuFI6fmsUoI7pk6v8hfFCnCpmcI/UZml9KjZHkmO/uH6oo+JrfkrhWx7OTH6UwWZMSTFZhZTHN48CTlRxSETXL5T1p0LEpRIRGLHO5RksmKUj3v9KHmvchSp2X4+Q4rNq+7FZif40aW2O81R96D3VXrvOvjMA/e3W1upt4ls= 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 1585307865711570.3609446129003; Fri, 27 Mar 2020 04:17:45 -0700 (PDT) Received: from localhost ([::1]:40348 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jHmzf-0005yC-1L for importer@patchew.org; Fri, 27 Mar 2020 07:17:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38084) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jHmwh-0001FA-3M for qemu-devel@nongnu.org; Fri, 27 Mar 2020 07:14:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jHmwf-00027r-OA for qemu-devel@nongnu.org; Fri, 27 Mar 2020 07:14:39 -0400 Received: from us-smtp-delivery-74.mimecast.com ([216.205.24.74]:54359) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jHmwf-00026Z-Jr for qemu-devel@nongnu.org; Fri, 27 Mar 2020 07:14:37 -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-309-h2k1udPwMdyiFdT7T0jyfQ-1; Fri, 27 Mar 2020 07:14:35 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1A94D107ACC4; Fri, 27 Mar 2020 11:14:33 +0000 (UTC) Received: from jason-ThinkPad-T430s.redhat.com (ovpn-12-77.pek2.redhat.com [10.72.12.77]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6B7F25E01F; Fri, 27 Mar 2020 11:14:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1585307677; 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=SZyarX6oU0bz0JxoE+hOcKoL/ERZF1zgJY/CMwDiH6zF80y2X+n5QpigxUBy0RT5xqGNn4 vSqAI4hmKL4sAERR22nnmHRtv/lTFTAyK1eq2QnZweFXcvKnUhlvchgmGhlAgj9veiV2TV dxfk2MmpiPcvGW2wkoQeGBmT1VH/wqI= X-MC-Unique: h2k1udPwMdyiFdT7T0jyfQ-1 From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Subject: [PULL 10/13] net/colo-compare.c: Expose "compare_timeout" to users Date: Fri, 27 Mar 2020 19:14:04 +0800 Message-Id: <1585307647-24456-11-git-send-email-jasowang@redhat.com> In-Reply-To: <1585307647-24456-1-git-send-email-jasowang@redhat.com> References: <1585307647-24456-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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: 216.205.24.74 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 Apr 29 19:36:05 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=1585308111; cv=none; d=zohomail.com; s=zohoarc; b=MtIozekofhSMl9FMz5CT08QGDyERfE8cJpTc7eC4GgomNhnYP3FNAVbk6Zq6zBTU0x74NPP4vaGmdKc+INqg6BT4cHQfOB0v5JF/BR4V3JsBph1GiTHyY+UGFEErlNVjuPwmjFNkVzwvfO+lfTdfD9g+ij8ZkenFh5I8d0EbJTA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585308111; 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=hu8iO3tJhh8kGfKKHtHyDbGdGcwPBTN6HhSBPvurz5J2cCEYxubFQ94fJ2e4cy3tgNoTD52J0HcukRrEf9FuGJGTcHhoHSlfRMiuLUkO2KGPWtYUFFDo2MPEvEwy3SGH9c5QwoASsm4bvXD5r+a6lH6tN8+4aWKkP0SF8IXM908= 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 1585308111198876.3874142231826; Fri, 27 Mar 2020 04:21:51 -0700 (PDT) Received: from localhost ([::1]:40412 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jHn3e-0003py-00 for importer@patchew.org; Fri, 27 Mar 2020 07:21:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38141) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jHmwk-0001Ne-HC for qemu-devel@nongnu.org; Fri, 27 Mar 2020 07:14:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jHmwj-0002Ge-53 for qemu-devel@nongnu.org; Fri, 27 Mar 2020 07:14:42 -0400 Received: from us-smtp-delivery-74.mimecast.com ([216.205.24.74]:50960) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jHmwj-0002D6-0n for qemu-devel@nongnu.org; Fri, 27 Mar 2020 07:14:41 -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-167-6EBbNfLNPoWJGN2TObTrwQ-1; Fri, 27 Mar 2020 07:14:37 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9EEF8189F760; Fri, 27 Mar 2020 11:14:36 +0000 (UTC) Received: from jason-ThinkPad-T430s.redhat.com (ovpn-12-77.pek2.redhat.com [10.72.12.77]) by smtp.corp.redhat.com (Postfix) with ESMTP id 994065E036; Fri, 27 Mar 2020 11:14:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1585307679; 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=ZIzOuQ/3b1zLFXq1mmsE09CT6N4umQs+AgEbTf4Zi7lLHBMB6Ktwfg5Amzc9rQB4mMbYDl I4ddd4GHH1TfSHVw1shchJsHboCiwOvnMyDj2VWm/AaoCX2TXTyuMhiC12vUG+XEu9uxrp VqrSyVTKqkVThjUqFqwQHnOYUoY0Hhk= X-MC-Unique: 6EBbNfLNPoWJGN2TObTrwQ-1 From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Subject: [PULL 11/13] net/colo-compare.c: Expose "expired_scan_cycle" to users Date: Fri, 27 Mar 2020 19:14:05 +0800 Message-Id: <1585307647-24456-12-git-send-email-jasowang@redhat.com> In-Reply-To: <1585307647-24456-1-git-send-email-jasowang@redhat.com> References: <1585307647-24456-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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: 216.205.24.74 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 Apr 29 19:36:05 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=1585307988; cv=none; d=zohomail.com; s=zohoarc; b=Oj/Lc/7ZOkVa7hN8vpLyGbZpSb6RxYlVlMXhojydToBo6St7oQX0kNrA7MzIt2+W0HagbNnj3fLDWMuoC8puemLI47hcJCeAn5JNBlIKy1orYKJJn1z0TzWctp1y3YxAOu3KEvD6cGRbqBg3u7QSh/FjsVpcNSaBUrUbNjZUvtc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585307988; 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=Gyzi09SIYjrAod41mDXB+NK2YSn5FhmSMNIFTN91QpCZJJda6JE7IzrekqsSP9xdHYvblAisel+858qrS4Qi03GAZsMmjcpS+EtOXvl4MoOS7/A/sIo6z8uGKOGwWdAfl/537yQA8TVbOe4Bmj+SgbSts6A57T7OqRZuawz+0/s= 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 1585307988670455.6610007314936; Fri, 27 Mar 2020 04:19:48 -0700 (PDT) Received: from localhost ([::1]:40372 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jHn1f-0000oa-G9 for importer@patchew.org; Fri, 27 Mar 2020 07:19:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38164) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jHmwm-0001Rf-0r for qemu-devel@nongnu.org; Fri, 27 Mar 2020 07:14:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jHmwk-0002JL-IT for qemu-devel@nongnu.org; Fri, 27 Mar 2020 07:14:43 -0400 Received: from us-smtp-delivery-74.mimecast.com ([63.128.21.74]:41582) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jHmwk-0002Ia-Dx for qemu-devel@nongnu.org; Fri, 27 Mar 2020 07:14:42 -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-118-tF6MyFrWNuOWT5lY2swYHg-1; Fri, 27 Mar 2020 07:14:39 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CDE62800D48; Fri, 27 Mar 2020 11:14:38 +0000 (UTC) Received: from jason-ThinkPad-T430s.redhat.com (ovpn-12-77.pek2.redhat.com [10.72.12.77]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2C6855E016; Fri, 27 Mar 2020 11:14:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1585307682; 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=FogLkZV4End+4CvdH1romgVItazkeXwuyG5rzes6Xy3ZkL4nrKzNFytblayGxjb2bn9oaS /0rO+5QSai9Fdj+62oxyDzQ/CXVVbd/qRyLimfRNdWgoMBfaPYQb/s5f+vGH3bMEOxbXoP +azLf2gnTzRy/NktxVMyv+5CxZgpEjo= X-MC-Unique: tF6MyFrWNuOWT5lY2swYHg-1 From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Subject: [PULL 12/13] net: tulip: check frame size and r/w data length Date: Fri, 27 Mar 2020 19:14:06 +0800 Message-Id: <1585307647-24456-13-git-send-email-jasowang@redhat.com> In-Reply-To: <1585307647-24456-1-git-send-email-jasowang@redhat.com> References: <1585307647-24456-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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: 63.128.21.74 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 Apr 29 19:36:05 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=1585308174; cv=none; d=zohomail.com; s=zohoarc; b=TxXBKO9NYZAFDcJNO1uxlqm1FIHvRRIZ0Q5140NXeTkeg/jQcXZ6VJwwPFhtxZgTYeBBguy1w3p4D1JeO1YkaUjW7Y3LZsoKRr+zQKYbR6pvwjLI2nYTzZc6dV1XXCB12BazknQqimzxvxKf+DCVzLDgzp4QtRoT5GSUUGaFwgM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585308174; 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=pVjR52ndEVQzi/3Y7VF32r03ZxvHDDMkrTSaExrTLgI=; b=WGtw+Z3AMPFHvKRuLopFr9Hk1V+1TORh5GQk7cbNt+ZGRqTIMtQYkn8xTC99IPYVOU6rc8IqegBXZquTqCFPQ0UbOPR/UfWP1CKj3aGR7+zYH5UDj8pSK0z204dgbAkUV4v1Xn5FZdZwa5ZFsDz3QOT8J42qvi1vMpC7yUnamXg= 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 1585308174178517.344948248967; Fri, 27 Mar 2020 04:22:54 -0700 (PDT) Received: from localhost ([::1]:40436 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jHn4e-0004sm-Nc for importer@patchew.org; Fri, 27 Mar 2020 07:22:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38195) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jHmwn-0001Uq-Bz for qemu-devel@nongnu.org; Fri, 27 Mar 2020 07:14:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jHmwm-0002Ml-7s for qemu-devel@nongnu.org; Fri, 27 Mar 2020 07:14:45 -0400 Received: from us-smtp-delivery-74.mimecast.com ([63.128.21.74]:31951) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jHmwm-0002Kz-3X for qemu-devel@nongnu.org; Fri, 27 Mar 2020 07:14:44 -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-494-aVUtkcF2Pqi02TIcCnSVYQ-1; Fri, 27 Mar 2020 07:14:41 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id BD0CB13E2; Fri, 27 Mar 2020 11:14:40 +0000 (UTC) Received: from jason-ThinkPad-T430s.redhat.com (ovpn-12-77.pek2.redhat.com [10.72.12.77]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5AC9C5E01F; Fri, 27 Mar 2020 11:14:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1585307683; 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=pVjR52ndEVQzi/3Y7VF32r03ZxvHDDMkrTSaExrTLgI=; b=MNdqEt9sDALnn1gjlfATbXv8eXxVqgLa3N9bDs876JcHGGbhMQCAfsp54/fbmIfeRuHz7R qubghfJSdsfkjrpuhMTKNMLpD0UmoKJhjYg9i5aFckCbjubODkNp7loUBmh5zYpLRd5I7l zUVddAcg1/YIs73JKM+CIuMzpENWYzw= X-MC-Unique: aVUtkcF2Pqi02TIcCnSVYQ-1 From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Subject: [PULL 13/13] hw/net/allwinner-sun8i-emac.c: Fix REG_ADDR_HIGH/LOW reads Date: Fri, 27 Mar 2020 19:14:07 +0800 Message-Id: <1585307647-24456-14-git-send-email-jasowang@redhat.com> In-Reply-To: <1585307647-24456-1-git-send-email-jasowang@redhat.com> References: <1585307647-24456-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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: 63.128.21.74 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 3fc5e34..fc67a1b 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