From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([209.51.188.92]:46274) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hINeM-0005oi-GV for qemu-devel@nongnu.org; Sun, 21 Apr 2019 21:21:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hINeL-0003EH-83 for qemu-devel@nongnu.org; Sun, 21 Apr 2019 21:21:38 -0400 Received: from mail-oi1-x22b.google.com ([2607:f8b0:4864:20::22b]:43960) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hINeL-0003Dp-1T for qemu-devel@nongnu.org; Sun, 21 Apr 2019 21:21:37 -0400 Received: by mail-oi1-x22b.google.com with SMTP id t81so7435727oig.10 for ; Sun, 21 Apr 2019 18:21:36 -0700 (PDT) MIME-Version: 1.0 References: <20190420161446.2274-1-liq3ea@163.com> <20190420161446.2274-4-liq3ea@163.com> <4eb444fe-7e45-1072-770b-17f0db493b6d@redhat.com> In-Reply-To: <4eb444fe-7e45-1072-770b-17f0db493b6d@redhat.com> From: Li Qiang Date: Mon, 22 Apr 2019 09:21:00 +0800 Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v2 3/3] edu: uses uint64_t in dma operation List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: =?UTF-8?Q?Philippe_Mathieu=2DDaud=C3=A9?= Cc: Li Qiang , Jiri Slaby , Paolo Bonzini , Qemu Developers Philippe Mathieu-Daud=C3=A9 =E4=BA=8E2019=E5=B9=B44=E6= =9C=8821=E6=97=A5=E5=91=A8=E6=97=A5 =E4=B8=8B=E5=8D=886:32=E5=86=99=E9=81= =93=EF=BC=9A > On 4/20/19 6:14 PM, Li Qiang wrote: > > The dma related variable is dma_addr_t, it is uint64_t in > > x64 platform. Change these usage from uint32_to uint64_t to > > avoid trancation. > > "to avoid address truncation"? > > The dma.dst/src/cnt..is from guest and is 64-bits. But in 'edu_dma_timer', it is assigned to uint32_t, If it is 0xffffffff 00000000, it will be ok by the check but it is of course not allowed. Though this is just an edu device, I think we should avoid this. Thanks, Li Qiang > > > > Signed-off-by: Li Qiang > > --- > > Change since v1: > > Fix format compile error on Windows > > > > hw/misc/edu.c | 15 ++++++++------- > > 1 file changed, 8 insertions(+), 7 deletions(-) > > > > diff --git a/hw/misc/edu.c b/hw/misc/edu.c > > index 4018dddcb8..f4a6d5f1c5 100644 > > --- a/hw/misc/edu.c > > +++ b/hw/misc/edu.c > > @@ -98,23 +98,24 @@ static void edu_lower_irq(EduState *edu, uint32_t > val) > > } > > } > > > > -static bool within(uint32_t addr, uint32_t start, uint32_t end) > > +static bool within(uint64_t addr, uint64_t start, uint64_t end) > > OK. > > > { > > return start <=3D addr && addr < end; > > } > > > > -static void edu_check_range(uint32_t addr, uint32_t size1, uint32_t > start, > > +static void edu_check_range(uint64_t addr, uint64_t size1, uint64_t > start, > > uint32_t size2) > > OK for addr. MMIO range is 1MiB so you can keep uint32_t for > size1/size2. Up to the maintainer (personally I'd prefer keep u32). > > Reviewed-by: Philippe Mathieu-Daud=C3=A9 > > > { > > - uint32_t end1 =3D addr + size1; > > - uint32_t end2 =3D start + size2; > > + uint64_t end1 =3D addr + size1; > > + uint64_t end2 =3D start + size2; > > > > if (within(addr, start, end2) && > > end1 > addr && within(end1, start, end2)) { > > return; > > } > > > > - hw_error("EDU: DMA range 0x%.8x-0x%.8x out of bounds > (0x%.8x-0x%.8x)!", > > + hw_error("EDU: DMA range 0x%016"PRIx64"-0x%016"PRIx64 > > + " out of bounds (0x%016"PRIx64"-0x%016"PRIx64")!", > > addr, end1 - 1, start, end2 - 1); > > } > > > > @@ -139,13 +140,13 @@ static void edu_dma_timer(void *opaque) > > } > > > > if (EDU_DMA_DIR(edu->dma.cmd) =3D=3D EDU_DMA_FROM_PCI) { > > - uint32_t dst =3D edu->dma.dst; > > + uint64_t dst =3D edu->dma.dst; > > edu_check_range(dst, edu->dma.cnt, DMA_START, DMA_SIZE); > > dst -=3D DMA_START; > > pci_dma_read(&edu->pdev, edu_clamp_addr(edu, edu->dma.src), > > edu->dma_buf + dst, edu->dma.cnt); > > } else { > > - uint32_t src =3D edu->dma.src; > > + uint64_t src =3D edu->dma.src; > > edu_check_range(src, edu->dma.cnt, DMA_START, DMA_SIZE); > > src -=3D DMA_START; > > pci_dma_write(&edu->pdev, edu_clamp_addr(edu, edu->dma.dst), > > > From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.5 required=3.0 tests=DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 48788C10F14 for ; Mon, 22 Apr 2019 01:22:26 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 07E8E2075A for ; Mon, 22 Apr 2019 01:22:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="BRUdwT71" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 07E8E2075A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([127.0.0.1]:59038 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hINf7-00065H-8k for qemu-devel@archiver.kernel.org; Sun, 21 Apr 2019 21:22:25 -0400 Received: from eggs.gnu.org ([209.51.188.92]:46274) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hINeM-0005oi-GV for qemu-devel@nongnu.org; Sun, 21 Apr 2019 21:21:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hINeL-0003EH-83 for qemu-devel@nongnu.org; Sun, 21 Apr 2019 21:21:38 -0400 Received: from mail-oi1-x22b.google.com ([2607:f8b0:4864:20::22b]:43960) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hINeL-0003Dp-1T for qemu-devel@nongnu.org; Sun, 21 Apr 2019 21:21:37 -0400 Received: by mail-oi1-x22b.google.com with SMTP id t81so7435727oig.10 for ; Sun, 21 Apr 2019 18:21:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Ce6txrQPf6xAV9RViWna9UEORiIips+B55ZMbpa48Zw=; b=BRUdwT7169E5iycgjegCqXpqmBNKOaRoefpW8JFmHy5jCreDtw/1PlM3eqD5dnjFul eXJqLFJ5kvfN2hWTXakXdXUOXStzvHMhW8LBFWrkWnZMxALi8nUW4Ss7ltn9FmnyyIgj 4IdthY0ktjv8IJZuu8RLfhI3+pftNBsSEaSHeCtGcX7JxsI82h3abQRdT+N6nKw1Dej1 AtMrAxL/5VNW1010/qQzwX6fOZ0yF8IvxI8e/kKi0z+5xI0FhhhO5npiKQm7aLxEoNpD b8HJIBfEsyEmQTrG7k0JGQ20SE8RAAhz95arVGgo/fqoy9FL/eon01pA5TFqmhWjwgFj gFug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Ce6txrQPf6xAV9RViWna9UEORiIips+B55ZMbpa48Zw=; b=SzV0TT4Z9P+/kq2z0+kBTnwdrI8Qr1vUVNoPt0E9HfqBfW88zz02WDc0SIU1xOxn04 4xhFgld1KRulOMVkLbnHHB1/An6t10bRS/lH8HX11UaXL6Tfe3Ry5n06QvIXcsnCp88P gJMe7rcFk6xYm3kfHLW9qafXdFJoxAbxu+neK7IWcY6wgnbvhFj1CAmhwOo3NJjYMXPF QjFSC9/hkE2IMJrgEAFkl6a5E4mxqeUEFF6owoe2KAMENtnGx8bg+B6xpHcPdE7zV9wH Pd2f3et14/NBicY1f/Pg9GFfWkrXDfh5agw+SDYYhlYsWAmfXAUQGXseRcfioiVehKnk DZpg== X-Gm-Message-State: APjAAAVoOWuU6RkNA1Pr3vCSJdHN70RWbbviLtLkmdtscQaz/RoG6FVW exF0UbsBbOCuuJxTM1c/OJfGaHrJSG01ol6UEuw= X-Google-Smtp-Source: APXvYqxY/KspagtSvMphEaGbs1zBKcgCOQ8pBSGhLOmYj1Lf4dawze4/woCXENLwA/Dhf7Fb3XviCiWBZvJu/IbVhjI= X-Received: by 2002:aca:c7c5:: with SMTP id x188mr8855396oif.129.1555896096221; Sun, 21 Apr 2019 18:21:36 -0700 (PDT) MIME-Version: 1.0 References: <20190420161446.2274-1-liq3ea@163.com> <20190420161446.2274-4-liq3ea@163.com> <4eb444fe-7e45-1072-770b-17f0db493b6d@redhat.com> In-Reply-To: <4eb444fe-7e45-1072-770b-17f0db493b6d@redhat.com> From: Li Qiang Date: Mon, 22 Apr 2019 09:21:00 +0800 Message-ID: To: =?UTF-8?Q?Philippe_Mathieu=2DDaud=C3=A9?= X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::22b Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Content-Filtered-By: Mailman/MimeDel 2.1.21 Subject: Re: [Qemu-devel] [PATCH v2 3/3] edu: uses uint64_t in dma operation X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jiri Slaby , Li Qiang , Qemu Developers , Paolo Bonzini Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Message-ID: <20190422012100.cECBXvsL7aFXp0YhviJKJ-wPv3FlNogw001oTV_QNdQ@z> Philippe Mathieu-Daud=C3=A9 =E4=BA=8E2019=E5=B9=B44=E6= =9C=8821=E6=97=A5=E5=91=A8=E6=97=A5 =E4=B8=8B=E5=8D=886:32=E5=86=99=E9=81= =93=EF=BC=9A > On 4/20/19 6:14 PM, Li Qiang wrote: > > The dma related variable is dma_addr_t, it is uint64_t in > > x64 platform. Change these usage from uint32_to uint64_t to > > avoid trancation. > > "to avoid address truncation"? > > The dma.dst/src/cnt..is from guest and is 64-bits. But in 'edu_dma_timer', it is assigned to uint32_t, If it is 0xffffffff 00000000, it will be ok by the check but it is of course not allowed. Though this is just an edu device, I think we should avoid this. Thanks, Li Qiang > > > > Signed-off-by: Li Qiang > > --- > > Change since v1: > > Fix format compile error on Windows > > > > hw/misc/edu.c | 15 ++++++++------- > > 1 file changed, 8 insertions(+), 7 deletions(-) > > > > diff --git a/hw/misc/edu.c b/hw/misc/edu.c > > index 4018dddcb8..f4a6d5f1c5 100644 > > --- a/hw/misc/edu.c > > +++ b/hw/misc/edu.c > > @@ -98,23 +98,24 @@ static void edu_lower_irq(EduState *edu, uint32_t > val) > > } > > } > > > > -static bool within(uint32_t addr, uint32_t start, uint32_t end) > > +static bool within(uint64_t addr, uint64_t start, uint64_t end) > > OK. > > > { > > return start <=3D addr && addr < end; > > } > > > > -static void edu_check_range(uint32_t addr, uint32_t size1, uint32_t > start, > > +static void edu_check_range(uint64_t addr, uint64_t size1, uint64_t > start, > > uint32_t size2) > > OK for addr. MMIO range is 1MiB so you can keep uint32_t for > size1/size2. Up to the maintainer (personally I'd prefer keep u32). > > Reviewed-by: Philippe Mathieu-Daud=C3=A9 > > > { > > - uint32_t end1 =3D addr + size1; > > - uint32_t end2 =3D start + size2; > > + uint64_t end1 =3D addr + size1; > > + uint64_t end2 =3D start + size2; > > > > if (within(addr, start, end2) && > > end1 > addr && within(end1, start, end2)) { > > return; > > } > > > > - hw_error("EDU: DMA range 0x%.8x-0x%.8x out of bounds > (0x%.8x-0x%.8x)!", > > + hw_error("EDU: DMA range 0x%016"PRIx64"-0x%016"PRIx64 > > + " out of bounds (0x%016"PRIx64"-0x%016"PRIx64")!", > > addr, end1 - 1, start, end2 - 1); > > } > > > > @@ -139,13 +140,13 @@ static void edu_dma_timer(void *opaque) > > } > > > > if (EDU_DMA_DIR(edu->dma.cmd) =3D=3D EDU_DMA_FROM_PCI) { > > - uint32_t dst =3D edu->dma.dst; > > + uint64_t dst =3D edu->dma.dst; > > edu_check_range(dst, edu->dma.cnt, DMA_START, DMA_SIZE); > > dst -=3D DMA_START; > > pci_dma_read(&edu->pdev, edu_clamp_addr(edu, edu->dma.src), > > edu->dma_buf + dst, edu->dma.cnt); > > } else { > > - uint32_t src =3D edu->dma.src; > > + uint64_t src =3D edu->dma.src; > > edu_check_range(src, edu->dma.cnt, DMA_START, DMA_SIZE); > > src -=3D DMA_START; > > pci_dma_write(&edu->pdev, edu_clamp_addr(edu, edu->dma.dst), > > >