From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by mx.groups.io with SMTP id smtpd.web11.19909.1594733773214746671 for ; Tue, 14 Jul 2020 06:36:13 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@nuviainc-com.20150623.gappssmtp.com header.s=20150623 header.b=w2zReIMG; spf=pass (domain: nuviainc.com, ip: 209.85.221.66, mailfrom: leif@nuviainc.com) Received: by mail-wr1-f66.google.com with SMTP id r12so21577509wrj.13 for ; Tue, 14 Jul 2020 06:36:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nuviainc-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=FTTtE/WJlmpAZmH2NosTyj95Uti0CTOvNjIuAu3A498=; b=w2zReIMGC4RE0WVcoI5dh/W9A6ngu7LR3VQNl0nioNq7iaQgYh2rYxmWfoFcrEVFyz lWVS74PDEo8TCpeQcv5hsMlqOHz3CrqIV5PhUfsnythpUC15cxb2wK7d9JDvHNLbhYvS 7GCfsRNCgaQLyWET6ORoLHepNUlL6QWEv+dR5LIH34BNAEkXLi+LU3uOxUrW/DvZFGjS degRNlcDxBLSAb5ebG6bz+LAXo9UdOuTL351/MTVDw8AHdjZaBCz3F1L0TO18RBDZkM8 1BkzVF1r/X5V7JhrO9ADb2SgxUjEAAxce6uAZrzkZxOTANpkFX4XwYqiLLTkA1ggwG6L j4zg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=FTTtE/WJlmpAZmH2NosTyj95Uti0CTOvNjIuAu3A498=; b=NbFe9lNzuaPbzFUMDomqYRVmt3TFSG20uZ+FAU3lKA0i9Fmi8ItHVI/HRZv7u/bx6G jZQF7QWx6QKpP9BftP27Os6c2zsV3ygVfB5hMIzl8wE7IqSkJIbX6whDo60ZtPl/D8h8 mZygxFztC21x6p/YTDRVIgKZRxVo5potVxPauM33mbU24Du9+SfAh8odWD6aGeTCkDXA ESeUMD3RltcnGSdmEgM6TF2jZYs3EfPhzEZtWFShQyvgxDYfErHL8JaJnscVEHggaaEp Sn0y3Xzl00dhp/zM3mb5ZLIpNBIffBsDc2c+oyCNHRLWeBGzh0mt4h0CaFRhy7PB9VF5 nx1A== X-Gm-Message-State: AOAM532I0sKFOBb8eZEESHc7AB1UGg6imCyYf6YI2L50Kha9X+g4ctbe aW5ekzSyka+jK6MAX8kBBNEGyQ== X-Google-Smtp-Source: ABdhPJzpEsjynws8T4hMkiV8WEp6AukceO+hThh4T3l49X5Mk4B6AsBuG247f8Un5spHwmy6D+FzSw== X-Received: by 2002:a5d:6990:: with SMTP id g16mr5471932wru.131.1594733771682; Tue, 14 Jul 2020 06:36:11 -0700 (PDT) Return-Path: Received: from vanye ([2001:470:1f09:12f0:b26e:bfff:fea9:f1b8]) by smtp.gmail.com with ESMTPSA id 207sm5356181wme.13.2020.07.14.06.36.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jul 2020 06:36:10 -0700 (PDT) Date: Tue, 14 Jul 2020 14:36:09 +0100 From: "Leif Lindholm" To: Pete Batard , Andrei Warkentin Cc: devel@edk2.groups.io, ard.biesheuvel@arm.com, philmd@redhat.com Subject: Re: [edk2][PATCH 1/1] BcmGenetDxe: don't consume RX buffer until it's actually copied Message-ID: <20200714133608.GX12303@vanye> References: <20200712042850.117715-1-andrey.warkentin@gmail.com> MIME-Version: 1.0 In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Mon, Jul 13, 2020 at 12:25:18 +0100, Pete Batard wrote: > One very minor formatting issue inline (that can be sorted during > integration): I would also like to prepend "Silicon/" to the subject line. If I can do those two things: Reviewed-by: Leif Lindholm > On 2020.07.12 05:28, Andrei Warkentin wrote: > > This was originally a bit sloppy, and could hypothetically under heavy > > load result in a buffer being overwritten by hardware before the received > > buffer is copied. > > > > Signed-off-by: Andrei Warkentin > > --- > > Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.h | 15 +++++ > > Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c | 59 +++++++++++++++----- > > Silicon/Broadcom/Drivers/Net/BcmGenetDxe/SimpleNetwork.c | 26 ++++++--- > > 3 files changed, 77 insertions(+), 23 deletions(-) > > > > diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.h b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.h > > index 1a117b25..b39a1326 100644 > > --- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.h > > +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.h > > @@ -358,6 +358,16 @@ GenetTxIntr ( > > OUT VOID **TxBuf > > ); > > +UINT32 > > +GenetRxPending ( > > + IN GENET_PRIVATE_DATA *Genet > > + ); > > + > > +UINT32 > > +GenetTxPending ( > > + IN GENET_PRIVATE_DATA *Genet > > + ); > > + > > EFI_STATUS > > GenetRxIntr ( > > IN GENET_PRIVATE_DATA *Genet, > > @@ -365,4 +375,9 @@ GenetRxIntr ( > > OUT UINTN *FrameLength > > ); > > +VOID > > +GenetRxComplete ( > > + IN GENET_PRIVATE_DATA *Genet > > + ); > > + > > #endif /* GENET_UTIL_H__ */ > > diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c > > index 1c4c8527..a0097b0d 100644 > > --- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c > > +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c > > @@ -661,6 +661,7 @@ GenetDmaMapRxDescriptor ( > > Genet->RxBufferMap[DescIndex].PhysAddress & 0xFFFFFFFF); > > GenetMmioWrite (Genet, GENET_RX_DESC_ADDRESS_HI (DescIndex), > > (Genet->RxBufferMap[DescIndex].PhysAddress >> 32) & 0xFFFFFFFF); > > + GenetMmioWrite (Genet, GENET_RX_DESC_STATUS (DescIndex), 0); > > return EFI_SUCCESS; > > } > > @@ -753,12 +754,9 @@ GenetTxIntr ( > > OUT VOID **TxBuf > > ) > > { > > - UINT32 ConsIndex, Total; > > + UINT32 Total; > > - ConsIndex = GenetMmioRead (Genet, > > - GENET_TX_DMA_CONS_INDEX (GENET_DMA_DEFAULT_QUEUE)) & 0xFFFF; > > - > > - Total = (ConsIndex - Genet->TxConsIndex) & 0xFFFF; > > + Total = GenetTxPending (Genet); > > if (Genet->TxQueued > 0 && Total > 0) { > > DmaUnmap (Genet->TxBufferMap[Genet->TxNext]); > > *TxBuf = Genet->TxBuffer[Genet->TxNext]; > > @@ -770,6 +768,46 @@ GenetTxIntr ( > > } > > } > > +UINT32 > > +GenetRxPending ( > > + IN GENET_PRIVATE_DATA *Genet > > + ) > > +{ > > + UINT32 ProdIndex; > > + UINT32 ConsIndex; > > + > > + ConsIndex = GenetMmioRead (Genet, > > + GENET_RX_DMA_CONS_INDEX (GENET_DMA_DEFAULT_QUEUE)) & 0xFFFF; > > + ASSERT (ConsIndex == Genet->RxConsIndex); > > + > > + ProdIndex = GenetMmioRead (Genet, > > + GENET_RX_DMA_PROD_INDEX (GENET_DMA_DEFAULT_QUEUE)) & 0xFFFF; > > + return (ProdIndex - Genet->RxConsIndex) & 0xFFFF; > > +} > > + > > +UINT32 > > +GenetTxPending ( > > + IN GENET_PRIVATE_DATA *Genet > > + ) > > +{ > > + UINT32 ConsIndex; > > + > > + ConsIndex = GenetMmioRead (Genet, > > + GENET_TX_DMA_CONS_INDEX (GENET_DMA_DEFAULT_QUEUE)) & 0xFFFF; > > If we want to be pedantic about EDK2 formatting, this should be indented to > start after the "Ge" of GenetMmioRead above, like the previous calls. > > > + > > + return (ConsIndex - Genet->TxConsIndex) & 0xFFFF; > > +} > > + > > +VOID > > +GenetRxComplete ( > > + IN GENET_PRIVATE_DATA *Genet > > + ) > > +{ > > + Genet->RxConsIndex = (Genet->RxConsIndex + 1) & 0xFFFF; > > + GenetMmioWrite (Genet, GENET_RX_DMA_CONS_INDEX (GENET_DMA_DEFAULT_QUEUE), > > + Genet->RxConsIndex); > > +} > > + > > /** > > Simulate an "RX interrupt", returning the index of a completed RX buffer and > > corresponding frame length. > > @@ -790,21 +828,14 @@ GenetRxIntr ( > > ) > > { > > EFI_STATUS Status; > > - UINT32 ProdIndex, Total; > > + UINT32 Total; > > UINT32 DescStatus; > > - ProdIndex = GenetMmioRead (Genet, > > - GENET_RX_DMA_PROD_INDEX (GENET_DMA_DEFAULT_QUEUE)) & 0xFFFF; > > - > > - Total = (ProdIndex - Genet->RxConsIndex) & 0xFFFF; > > + Total = GenetRxPending (Genet); > > if (Total > 0) { > > *DescIndex = Genet->RxConsIndex % GENET_DMA_DESC_COUNT; > > DescStatus = GenetMmioRead (Genet, GENET_RX_DESC_STATUS (*DescIndex)); > > *FrameLength = SHIFTOUT (DescStatus, GENET_RX_DESC_STATUS_BUFLEN); > > - > > - Genet->RxConsIndex = (Genet->RxConsIndex + 1) & 0xFFFF; > > - GenetMmioWrite (Genet, GENET_RX_DMA_CONS_INDEX (GENET_DMA_DEFAULT_QUEUE), > > - Genet->RxConsIndex); > > Status = EFI_SUCCESS; > > } else { > > Status = EFI_NOT_READY; > > diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/SimpleNetwork.c b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/SimpleNetwork.c > > index 371216ca..1bda18f1 100644 > > --- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/SimpleNetwork.c > > +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/SimpleNetwork.c > > @@ -502,9 +502,19 @@ GenetSimpleNetworkGetStatus ( > > Genet->SnpMode.MediaPresent = FALSE; > > } else { > > Genet->SnpMode.MediaPresent = TRUE; > > + } > > + > > + if (TxBuf != NULL) { > > + GenetTxIntr (Genet, TxBuf); > > + } > > - if (TxBuf != NULL) { > > - GenetTxIntr (Genet, TxBuf); > > + if (InterruptStatus != NULL) { > > + *InterruptStatus = 0; > > + if (GenetRxPending (Genet) > 0) { > > + *InterruptStatus |= EFI_SIMPLE_NETWORK_RECEIVE_INTERRUPT; > > + } > > + if (GenetTxPending (Genet) > 0) { > > + *InterruptStatus |= EFI_SIMPLE_NETWORK_TRANSMIT_INTERRUPT; > > } > > } > > @@ -741,13 +751,8 @@ GenetSimpleNetworkReceive ( > > DEBUG ((DEBUG_ERROR, > > "%a: Buffer size (0x%X) is too small for frame (0x%X)\n", > > __FUNCTION__, *BufferSize, FrameLength)); > > - Status = GenetDmaMapRxDescriptor (Genet, DescIndex); > > - if (EFI_ERROR (Status)) { > > - DEBUG ((DEBUG_ERROR, "%a: Failed to remap RX descriptor!\n", > > - __FUNCTION__)); > > - } > > - EfiReleaseLock (&Genet->Lock); > > - return EFI_BUFFER_TOO_SMALL; > > + Status = EFI_BUFFER_TOO_SMALL; > > + goto out; > > } > > if (DestAddr != NULL) { > > @@ -773,11 +778,14 @@ GenetSimpleNetworkReceive ( > > Status = EFI_NOT_READY; > > } > > +out: > > Status = GenetDmaMapRxDescriptor (Genet, DescIndex); > > if (EFI_ERROR (Status)) { > > DEBUG ((DEBUG_ERROR, "%a: Failed to remap RX descriptor!\n", __FUNCTION__)); > > } > > + GenetRxComplete (Genet); > > + > > EfiReleaseLock (&Genet->Lock); > > return Status; > > } > > > > Reviewed-by: Pete Batard