Skip to content

Commit f10b01c

Browse files
Chunfeng Yungregkh
authored andcommitted
usb: mtu3: add memory barrier before set GPD's HWO
commit a7aae76 upstream. There is a seldom issue that the controller access invalid address and trigger devapc or emimpu violation. That is due to memory access is out of order and cause gpd data is not correct. Add mb() to prohibit compiler or cpu from reordering to make sure GPD is fully written before setting its HWO. Fixes: 48e0d37 ("usb: mtu3: supports new QMU format") Cc: stable@vger.kernel.org Reported-by: Eddie Hung <eddie.hung@mediatek.com> Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com> Link: https://lore.kernel.org/r/20211218095749.6250-2-chunfeng.yun@mediatek.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 1c4ace3 commit f10b01c

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

drivers/usb/mtu3/mtu3_qmu.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,8 @@ static int mtu3_prepare_tx_gpd(struct mtu3_ep *mep, struct mtu3_request *mreq)
273273
gpd->dw3_info |= cpu_to_le32(GPD_EXT_FLAG_ZLP);
274274
}
275275

276+
/* prevent reorder, make sure GPD's HWO is set last */
277+
mb();
276278
gpd->dw0_info |= cpu_to_le32(GPD_FLAGS_IOC | GPD_FLAGS_HWO);
277279

278280
mreq->gpd = gpd;
@@ -306,6 +308,8 @@ static int mtu3_prepare_rx_gpd(struct mtu3_ep *mep, struct mtu3_request *mreq)
306308
gpd->next_gpd = cpu_to_le32(lower_32_bits(enq_dma));
307309
ext_addr |= GPD_EXT_NGP(mtu, upper_32_bits(enq_dma));
308310
gpd->dw3_info = cpu_to_le32(ext_addr);
311+
/* prevent reorder, make sure GPD's HWO is set last */
312+
mb();
309313
gpd->dw0_info |= cpu_to_le32(GPD_FLAGS_IOC | GPD_FLAGS_HWO);
310314

311315
mreq->gpd = gpd;
@@ -445,7 +449,8 @@ static void qmu_tx_zlp_error_handler(struct mtu3 *mtu, u8 epnum)
445449
return;
446450
}
447451
mtu3_setbits(mbase, MU3D_EP_TXCR0(mep->epnum), TX_TXPKTRDY);
448-
452+
/* prevent reorder, make sure GPD's HWO is set last */
453+
mb();
449454
/* by pass the current GDP */
450455
gpd_current->dw0_info |= cpu_to_le32(GPD_FLAGS_BPS | GPD_FLAGS_HWO);
451456

0 commit comments

Comments
 (0)