Received: by 2002:ab2:69cc:0:b0:1fd:c486:4f03 with SMTP id n12csp77011lqp; Mon, 10 Jun 2024 19:20:44 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVXBP4pGD2hXdQxTEXSj47sgwahfOQEK0m8iSVx01W4xQ60m5fuA5/1eb965Zn8fH4J2Ze4iRpwLKVDl3+msHuVX9etQpcey7o1oeZtLQ== X-Google-Smtp-Source: AGHT+IGnotcZKNcu5ZLQLgYMNckEr+IL2cScjFm7UmVzWXZ/nEoI0k5OyHliaIsw5oXDlA2gaosW X-Received: by 2002:a05:6358:9389:b0:19f:3348:e3d4 with SMTP id e5c5f4694b2df-19f3348e49cmr765303955d.17.1718072444490; Mon, 10 Jun 2024 19:20:44 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718072444; cv=pass; d=google.com; s=arc-20160816; b=XRBH/AcjyTRATl0UyzqlBfg+RROvdtp4/RtDAKQxh/bnSoAvlkkqvADQ50e7IXBWe2 7o5rFLhAJmzi1RVlQcv8iPqzmA09o2zGN3qCR6baGRNlvKV4ddMZ/JYdyY6iSKWsO4QQ tM/VUIZ4j6eQPtm1mhlTWpQ3JNtrPM833JYGUzljuxTilEH0zgoF4NrIyaVuTOcXCLqM CtrC3OKnc3KB/GAU701kZF8xVNE1BLaXZo1rgy00l4Jhx9ELyBGGWH8qbhGLzisxdpQ6 dO9tggjeW9P1aMo8+pvueVEN8qB+iKw/zIW/uuhTRuDDN34CIjb/cP2SMhmvRgH7WMA6 Fnig== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:to:from; bh=lLlb3ap6a/NWkFItWjVfh9uTw3x9Z9pwYoz9qudCyMQ=; fh=i+pR0Y9t94OKZsARqUkLMEmtPQHvmw7bpTYa9QkhXpo=; b=HuLPbsQLXG9jI87Nm0L9l+JQaX3aQ54BHGBufuBV7P5ZwkfxeoBhVGSRoatzDG6JiM aG55nY9MQKuerK/gCwFxW7ILuiD+aOFIoIRY0C+RyQQMQYw+ML67IuQcU09LM1CQVzNE xEMsMoyQqbjHjK8PG0ENSdEdGgnMaXyK5UoJqYBz1ERGyC/g9KNnVX8omRaAP0whdkvu 36amiMVin4qTQJMZiKGuHL8o9DtPm6tXZuxG2h65CCfFKPri9oK0I4BqJivxgD1Q49vo 3tUU8ed1WDN111crjAQgVlHP6vbAkFev6vfXV88gxVh5fjzcwgPKa/QBtm9w1V5MEPjA xjYA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=realtek.com); spf=pass (google.com: domain of linux-wireless+bounces-8771-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-wireless+bounces-8771-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id 41be03b00d2f7-6de2073c95csi4321406a12.97.2024.06.10.19.20.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jun 2024 19:20:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless+bounces-8771-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=realtek.com); spf=pass (google.com: domain of linux-wireless+bounces-8771-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-wireless+bounces-8771-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id B9911B2114E for ; Tue, 11 Jun 2024 02:20:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 756918485; Tue, 11 Jun 2024 02:20:35 +0000 (UTC) X-Original-To: linux-wireless@vger.kernel.org Received: from rtits2.realtek.com.tw (rtits2.realtek.com [211.75.126.72]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C25E4AD4C for ; Tue, 11 Jun 2024 02:20:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=211.75.126.72 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718072435; cv=none; b=Hsd5rYPGgBGCy56JispSSWAsVfB9FDbBhw+NRGdFLIYVFha6wclD/OL4eIFQxo1alCjn6D7YJ8Sz3I9osBKkZvRAStv703GE7M3u228RASbnlZ8TpqgPbKoQHy0UP46uKoQFP3xgLNqZXyz74BH97PMmH/kRV+b1bLDvuGNomO0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718072435; c=relaxed/simple; bh=4q/nBkmvdNQs4zjWiG9Nw5F9VRs3K0QSxS+mxJR/Cho=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=OEMgVMQUlJf5NeSpk0barbOwTITEGdf9ZhxSS3KVgqihDgbyhwjLJNkHV79I/vYvTqpIK9uQjGwgS/CcFy+axRZNarbJwE0H2SZu85L+dkBakSsPk7ZIU3tqAfcNwFyns3OPBY8QzNvawES2KGHC0eELTsW6Z/9QRvTs2Aedd5g= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=realtek.com; spf=pass smtp.mailfrom=realtek.com; arc=none smtp.client-ip=211.75.126.72 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=realtek.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=realtek.com X-SpamFilter-By: ArmorX SpamTrap 5.78 with qID 45B2KTaiC3648981, This message is accepted by code: ctloc85258 Received: from mail.realtek.com (rtexh36505.realtek.com.tw[172.21.6.25]) by rtits2.realtek.com.tw (8.15.2/2.95/5.92) with ESMTPS id 45B2KTaiC3648981 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 11 Jun 2024 10:20:29 +0800 Received: from RTEXMBS04.realtek.com.tw (172.21.6.97) by RTEXH36505.realtek.com.tw (172.21.6.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Tue, 11 Jun 2024 10:20:29 +0800 Received: from [127.0.1.1] (172.21.69.94) by RTEXMBS04.realtek.com.tw (172.21.6.97) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.35; Tue, 11 Jun 2024 10:20:28 +0800 From: Ping-Ke Shih To: Subject: [PATCH v2 2/2] wifi: rtw89: pci: fix RX tag race condition resulting in wrong RX length Date: Tue, 11 Jun 2024 10:19:01 +0800 Message-ID: <20240611021901.26394-2-pkshih@realtek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240611021901.26394-1-pkshih@realtek.com> References: <20240611021901.26394-1-pkshih@realtek.com> Precedence: bulk X-Mailing-List: linux-wireless@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: RTEXMBS02.realtek.com.tw (172.21.6.95) To RTEXMBS04.realtek.com.tw (172.21.6.97) Read 32 bits RX info to a local variable to fix race condition between reading RX length and RX tag. Another solution is to get RX tag at first statement, but adopted solution can save some memory read, and also save 15 bytes binary code. RX tag, a sequence number, is used to ensure that RX data has been DMA to memory completely, so driver must check sequence number is expected before reading other data. This potential problem happens only after enabling 36-bit DMA. Signed-off-by: Ping-Ke Shih --- v2: no change --- drivers/net/wireless/realtek/rtw89/pci.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/drivers/net/wireless/realtek/rtw89/pci.c b/drivers/net/wireless/realtek/rtw89/pci.c index 6b7fb533e264..15c633042ad6 100644 --- a/drivers/net/wireless/realtek/rtw89/pci.c +++ b/drivers/net/wireless/realtek/rtw89/pci.c @@ -183,14 +183,17 @@ static void rtw89_pci_sync_skb_for_device(struct rtw89_dev *rtwdev, static void rtw89_pci_rxbd_info_update(struct rtw89_dev *rtwdev, struct sk_buff *skb) { - struct rtw89_pci_rxbd_info *rxbd_info; struct rtw89_pci_rx_info *rx_info = RTW89_PCI_RX_SKB_CB(skb); + struct rtw89_pci_rxbd_info *rxbd_info; + __le32 info; rxbd_info = (struct rtw89_pci_rxbd_info *)skb->data; - rx_info->fs = le32_get_bits(rxbd_info->dword, RTW89_PCI_RXBD_FS); - rx_info->ls = le32_get_bits(rxbd_info->dword, RTW89_PCI_RXBD_LS); - rx_info->len = le32_get_bits(rxbd_info->dword, RTW89_PCI_RXBD_WRITE_SIZE); - rx_info->tag = le32_get_bits(rxbd_info->dword, RTW89_PCI_RXBD_TAG); + info = rxbd_info->dword; + + rx_info->fs = le32_get_bits(info, RTW89_PCI_RXBD_FS); + rx_info->ls = le32_get_bits(info, RTW89_PCI_RXBD_LS); + rx_info->len = le32_get_bits(info, RTW89_PCI_RXBD_WRITE_SIZE); + rx_info->tag = le32_get_bits(info, RTW89_PCI_RXBD_TAG); } static int rtw89_pci_validate_rx_tag(struct rtw89_dev *rtwdev, -- 2.25.1