[{"id":1768991,"web_url":"http://patchwork.ozlabs.org/comment/1768991/","msgid":"<1505460680.18776.1.camel@redhat.com>","list_archive_url":null,"date":"2017-09-15T07:31:20","subject":"Re: [Qemu-devel] [PATCH v2 1/2] virtio-gpu: Handle endian conversion","submitter":{"id":589,"url":"http://patchwork.ozlabs.org/api/people/589/","name":"Gerd Hoffmann","email":"kraxel@redhat.com"},"content":"Hi,\n\n> +static void\n> +virtio_gpu_ctrl_hdr_bswap_cpu(struct virtio_gpu_ctrl_hdr *hdr)\n> +{\n> +    hdr->type =  le32_to_cpu(hdr->type);\n> +    hdr->flags = le32_to_cpu(hdr->flags);\n> +    hdr->fence_id = le64_to_cpu(hdr->fence_id);\n> +    hdr->ctx_id = le32_to_cpu(hdr->ctx_id);\n> +    hdr->padding = le32_to_cpu(hdr->padding);\n> +}\n> +\n> +static void\n> +virtio_gpu_ctrl_hdr_bswap_le(struct virtio_gpu_ctrl_hdr *hdr)\n> +{\n> +    hdr->type =  cpu_to_le32(hdr->type);\n> +    hdr->flags = cpu_to_le32(hdr->flags);\n> +    hdr->fence_id = cpu_to_le64(hdr->fence_id);\n> +    hdr->ctx_id = cpu_to_le32(hdr->ctx_id);\n> +    hdr->padding = cpu_to_le32(hdr->padding);\n> +}\n\nThese two functions do exactly the same thing because cpu_to_le32 and\nle32_to_cpu are the same operation.  The two variants only exist to\nmake the code more readable.  So this isn't needed twice.  I'd suggest\nto just call the functions \"*_bswap\" and drop any _le or _cpu postfix. \nNote that there are also variants for in-place swapping.\n\nHave a look at the comments in include/qemu/bswap.h\n\n> +\n> +static void virtio_gpu_bswap_cpu_32(void *ptr,\n> +                                    size_t size)\n> +{\n\n#ifdef HOST_WORDS_BIGENDIAN\n\n> +    size_t i;\n> +    struct virtio_gpu_ctrl_hdr *hdr = (struct virtio_gpu_ctrl_hdr *)\n> ptr;\n> +\n> +    virtio_gpu_ctrl_hdr_bswap_cpu(hdr);\n> +\n> +    i = sizeof(struct virtio_gpu_ctrl_hdr);\n> +    while (i < size) {\n> +        *(uint32_t *)(ptr + i) = le32_to_cpu(*(uint32_t *)(ptr +\n> i));\n> +        i = i + sizeof(uint32_t);\n> +    }\n\n#endif\n\nI suspect the compiler isn't clever enough to figure the whole function\nis a nop on little endian hosts.\n\ncheers,\n  Gerd","headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=nongnu.org\n\t(client-ip=2001:4830:134:3::11; helo=lists.gnu.org;\n\tenvelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n\treceiver=<UNKNOWN>)","ext-mx08.extmail.prod.ext.phx2.redhat.com;\n\tdmarc=none (p=none dis=none) header.from=redhat.com","ext-mx08.extmail.prod.ext.phx2.redhat.com;\n\tspf=fail smtp.mailfrom=kraxel@redhat.com"],"Received":["from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11])\n\t(using TLSv1 with cipher AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xtnCq6r8tz9sPs\n\tfor <incoming@patchwork.ozlabs.org>;\n\tFri, 15 Sep 2017 17:32:07 +1000 (AEST)","from localhost ([::1]:51744 helo=lists.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.71) (envelope-from\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>)\n\tid 1dsl6b-0002Sd-OM\n\tfor incoming@patchwork.ozlabs.org; Fri, 15 Sep 2017 03:32:05 -0400","from eggs.gnu.org ([2001:4830:134:3::10]:46941)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <kraxel@redhat.com>) id 1dsl60-0002Ql-M1\n\tfor qemu-devel@nongnu.org; Fri, 15 Sep 2017 03:31:29 -0400","from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <kraxel@redhat.com>) id 1dsl5y-0000Th-Kx\n\tfor qemu-devel@nongnu.org; Fri, 15 Sep 2017 03:31:28 -0400","from mx1.redhat.com ([209.132.183.28]:39186)\n\tby eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32)\n\t(Exim 4.71) (envelope-from <kraxel@redhat.com>) id 1dsl5y-0000T3-CE\n\tfor qemu-devel@nongnu.org; Fri, 15 Sep 2017 03:31:26 -0400","from smtp.corp.redhat.com\n\t(int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15])\n\t(using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby mx1.redhat.com (Postfix) with ESMTPS id BAC78C058EA9;\n\tFri, 15 Sep 2017 07:31:24 +0000 (UTC)","from sirius.home.kraxel.org (ovpn-116-19.ams2.redhat.com\n\t[10.36.116.19])\n\tby smtp.corp.redhat.com (Postfix) with ESMTP id 747F669AC6;\n\tFri, 15 Sep 2017 07:31:22 +0000 (UTC)","from localhost (localhost [IPv6:::1])\n\tby sirius.home.kraxel.org (Postfix) with ESMTP id AB0FB3F106;\n\tFri, 15 Sep 2017 09:31:20 +0200 (CEST)"],"DMARC-Filter":"OpenDMARC Filter v1.3.2 mx1.redhat.com BAC78C058EA9","Message-ID":"<1505460680.18776.1.camel@redhat.com>","From":"Gerd Hoffmann <kraxel@redhat.com>","To":"Farhan Ali <alifm@linux.vnet.ibm.com>, qemu-devel@nongnu.org","Date":"Fri, 15 Sep 2017 09:31:20 +0200","In-Reply-To":"<f6c9e7ec8ad585ce7c8f401aae2ec1fddf157fd7.1505403478.git.alifm@linux.vnet.ibm.com>","References":"<cover.1505403478.git.alifm@linux.vnet.ibm.com>\n\t<f6c9e7ec8ad585ce7c8f401aae2ec1fddf157fd7.1505403478.git.alifm@linux.vnet.ibm.com>","Content-Type":"text/plain; charset=\"UTF-8\"","Mime-Version":"1.0","X-Scanned-By":"MIMEDefang 2.79 on 10.5.11.15","X-Greylist":"Sender IP whitelisted, not delayed by milter-greylist-4.5.16\n\t(mx1.redhat.com [10.5.110.32]);\n\tFri, 15 Sep 2017 07:31:24 +0000 (UTC)","Content-Transfer-Encoding":"quoted-printable","X-detected-operating-system":"by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]\n\t[fuzzy]","X-Received-From":"209.132.183.28","Subject":"Re: [Qemu-devel] [PATCH v2 1/2] virtio-gpu: Handle endian conversion","X-BeenThere":"qemu-devel@nongnu.org","X-Mailman-Version":"2.1.21","Precedence":"list","List-Id":"<qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<http://lists.nongnu.org/archive/html/qemu-devel/>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Cc":"borntraeger@de.ibm.com, thuth@redhat.com, cohuck@redhat.com","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"\"Qemu-devel\"\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>"}},{"id":1769167,"web_url":"http://patchwork.ozlabs.org/comment/1769167/","msgid":"<2d100ec2-a09b-159c-5d8e-68b2a845b36a@linux.vnet.ibm.com>","list_archive_url":null,"date":"2017-09-15T12:56:41","subject":"Re: [Qemu-devel] [PATCH v2 1/2] virtio-gpu: Handle endian conversion","submitter":{"id":71051,"url":"http://patchwork.ozlabs.org/api/people/71051/","name":"Farhan Ali","email":"alifm@linux.vnet.ibm.com"},"content":"On 09/15/2017 03:31 AM, Gerd Hoffmann wrote:\n>   Hi,\n>\n>> +static void\n>> +virtio_gpu_ctrl_hdr_bswap_cpu(struct virtio_gpu_ctrl_hdr *hdr)\n>> +{\n>> +    hdr->type =  le32_to_cpu(hdr->type);\n>> +    hdr->flags = le32_to_cpu(hdr->flags);\n>> +    hdr->fence_id = le64_to_cpu(hdr->fence_id);\n>> +    hdr->ctx_id = le32_to_cpu(hdr->ctx_id);\n>> +    hdr->padding = le32_to_cpu(hdr->padding);\n>> +}\n>> +\n>> +static void\n>> +virtio_gpu_ctrl_hdr_bswap_le(struct virtio_gpu_ctrl_hdr *hdr)\n>> +{\n>> +    hdr->type =  cpu_to_le32(hdr->type);\n>> +    hdr->flags = cpu_to_le32(hdr->flags);\n>> +    hdr->fence_id = cpu_to_le64(hdr->fence_id);\n>> +    hdr->ctx_id = cpu_to_le32(hdr->ctx_id);\n>> +    hdr->padding = cpu_to_le32(hdr->padding);\n>> +}\n>\n> These two functions do exactly the same thing because cpu_to_le32 and\n> le32_to_cpu are the same operation.  The two variants only exist to\n> make the code more readable.  So this isn't needed twice.  I'd suggest\n> to just call the functions \"*_bswap\" and drop any _le or _cpu postfix.\n> Note that there are also variants for in-place swapping.\n>\n> Have a look at the comments in include/qemu/bswap.h\n>\nThanks for pointing that out. I will re-spin another version.\n\n>> +\n>> +static void virtio_gpu_bswap_cpu_32(void *ptr,\n>> +                                    size_t size)\n>> +{\n>\n> #ifdef HOST_WORDS_BIGENDIAN\n>\n>> +    size_t i;\n>> +    struct virtio_gpu_ctrl_hdr *hdr = (struct virtio_gpu_ctrl_hdr *)\n>> ptr;\n>> +\n>> +    virtio_gpu_ctrl_hdr_bswap_cpu(hdr);\n>> +\n>> +    i = sizeof(struct virtio_gpu_ctrl_hdr);\n>> +    while (i < size) {\n>> +        *(uint32_t *)(ptr + i) = le32_to_cpu(*(uint32_t *)(ptr +\n>> i));\n>> +        i = i + sizeof(uint32_t);\n>> +    }\n>\n> #endif\n>\n> I suspect the compiler isn't clever enough to figure the whole function\n> is a nop on little endian hosts.\n\nThis makes sense.\n\nThanks\nFarhan\n>\n> cheers,\n>   Gerd\n>","headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":"ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=nongnu.org\n\t(client-ip=2001:4830:134:3::11; helo=lists.gnu.org;\n\tenvelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n\treceiver=<UNKNOWN>)","Received":["from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11])\n\t(using TLSv1 with cipher AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xtwRB1my3z9s4s\n\tfor <incoming@patchwork.ozlabs.org>;\n\tFri, 15 Sep 2017 22:57:26 +1000 (AEST)","from localhost ([::1]:53271 helo=lists.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.71) (envelope-from\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>)\n\tid 1dsqBQ-0001OO-DX\n\tfor incoming@patchwork.ozlabs.org; Fri, 15 Sep 2017 08:57:24 -0400","from eggs.gnu.org ([2001:4830:134:3::10]:36896)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <alifm@linux.vnet.ibm.com>) id 1dsqAu-0001ML-4s\n\tfor qemu-devel@nongnu.org; Fri, 15 Sep 2017 08:56:53 -0400","from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <alifm@linux.vnet.ibm.com>) id 1dsqAp-0005gE-6m\n\tfor qemu-devel@nongnu.org; Fri, 15 Sep 2017 08:56:52 -0400","from mx0a-001b2d01.pphosted.com ([148.163.156.1]:38083)\n\tby eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32)\n\t(Exim 4.71) (envelope-from <alifm@linux.vnet.ibm.com>)\n\tid 1dsqAo-0005fN-Sv\n\tfor qemu-devel@nongnu.org; Fri, 15 Sep 2017 08:56:47 -0400","from pps.filterd (m0098404.ppops.net [127.0.0.1])\n\tby mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id\n\tv8FCsR60006746\n\tfor <qemu-devel@nongnu.org>; Fri, 15 Sep 2017 08:56:45 -0400","from e12.ny.us.ibm.com (e12.ny.us.ibm.com [129.33.205.202])\n\tby mx0a-001b2d01.pphosted.com with ESMTP id 2d0cn37qte-1\n\t(version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT)\n\tfor <qemu-devel@nongnu.org>; Fri, 15 Sep 2017 08:56:45 -0400","from localhost\n\tby e12.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use\n\tOnly! Violators will be prosecuted\n\tfor <qemu-devel@nongnu.org> from <alifm@linux.vnet.ibm.com>;\n\tFri, 15 Sep 2017 08:56:44 -0400","from b01cxnp23032.gho.pok.ibm.com (9.57.198.27)\n\tby e12.ny.us.ibm.com (146.89.104.199) with IBM ESMTP SMTP Gateway:\n\tAuthorized Use Only! Violators will be prosecuted; \n\tFri, 15 Sep 2017 08:56:42 -0400","from b01ledav005.gho.pok.ibm.com (b01ledav005.gho.pok.ibm.com\n\t[9.57.199.110])\n\tby b01cxnp23032.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP\n\tid v8FCugEq29098190; Fri, 15 Sep 2017 12:56:42 GMT","from b01ledav005.gho.pok.ibm.com (unknown [127.0.0.1])\n\tby IMSVA (Postfix) with ESMTP id 94B2BAE034;\n\tFri, 15 Sep 2017 08:57:11 -0400 (EDT)","from [9.56.58.52] (unknown [9.56.58.52])\n\tby b01ledav005.gho.pok.ibm.com (Postfix) with ESMTP id 5BE89AE051;\n\tFri, 15 Sep 2017 08:57:11 -0400 (EDT)"],"To":"Gerd Hoffmann <kraxel@redhat.com>, qemu-devel@nongnu.org","References":"<cover.1505403478.git.alifm@linux.vnet.ibm.com>\n\t<f6c9e7ec8ad585ce7c8f401aae2ec1fddf157fd7.1505403478.git.alifm@linux.vnet.ibm.com>\n\t<1505460680.18776.1.camel@redhat.com>","From":"Farhan Ali <alifm@linux.vnet.ibm.com>","Date":"Fri, 15 Sep 2017 08:56:41 -0400","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101\n\tThunderbird/45.7.0","MIME-Version":"1.0","In-Reply-To":"<1505460680.18776.1.camel@redhat.com>","Content-Type":"text/plain; charset=utf-8; format=flowed","Content-Transfer-Encoding":"7bit","X-TM-AS-GCONF":"00","x-cbid":"17091512-0048-0000-0000-000001E56CB5","X-IBM-SpamModules-Scores":"","X-IBM-SpamModules-Versions":"BY=3.00007742; HX=3.00000241; KW=3.00000007;\n\tPH=3.00000004; SC=3.00000228; SDB=6.00917382; UDB=6.00460764;\n\tIPR=6.00697609; \n\tBA=6.00005589; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009;\n\tZB=6.00000000; \n\tZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00017168;\n\tXFM=3.00000015; UTC=2017-09-15 12:56:43","X-IBM-AV-DETECTION":"SAVI=unused REMOTE=unused XFE=unused","x-cbparentid":"17091512-0049-0000-0000-00004291CBEE","Message-Id":"<2d100ec2-a09b-159c-5d8e-68b2a845b36a@linux.vnet.ibm.com>","X-Proofpoint-Virus-Version":"vendor=fsecure engine=2.50.10432:, ,\n\tdefinitions=2017-09-15_05:, , signatures=0","X-Proofpoint-Spam-Details":"rule=outbound_notspam policy=outbound score=0\n\tspamscore=0 suspectscore=0\n\tmalwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam\n\tadjust=0 reason=mlx scancount=1 engine=8.0.1-1707230000\n\tdefinitions=main-1709150188","X-detected-operating-system":"by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy]","X-Received-From":"148.163.156.1","Subject":"Re: [Qemu-devel] [PATCH v2 1/2] virtio-gpu: Handle endian conversion","X-BeenThere":"qemu-devel@nongnu.org","X-Mailman-Version":"2.1.21","Precedence":"list","List-Id":"<qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<http://lists.nongnu.org/archive/html/qemu-devel/>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Cc":"borntraeger@de.ibm.com, thuth@redhat.com, cohuck@redhat.com","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"\"Qemu-devel\"\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>"}}]