Received: by 2002:ab2:6309:0:b0:1fb:d597:ff75 with SMTP id s9csp1056989lqt; Fri, 7 Jun 2024 07:02:23 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVpR3M9lgzYLtyfEzRZqRKWBmY4xV+FduHVbfbPU3+zonITSKcvGin3WBnQ3p7yiTwk4uCX+j77pU1ZoKhadDdux8EOLrwlcb+GxCEe9Q== X-Google-Smtp-Source: AGHT+IHIun2MvJ8i8foaiYEbqaWKYC23CnV4VaHKohl97daMLrH8SMpr5UJtxm1BIOCcZIfGGBGq X-Received: by 2002:a50:f60d:0:b0:57a:1fef:619e with SMTP id 4fb4d7f45d1cf-57c508a12dfmr1516284a12.18.1717768943212; Fri, 07 Jun 2024 07:02:23 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717768943; cv=pass; d=google.com; s=arc-20160816; b=C0+uOvf9w4mmQN3pIVYTLgDnfRD1DdDUjDieKR6SdZauMGbDnFmnWyq+Z3FHAowrML w5oge/H6Eiwf1yZvpmDBEBPVA32vesPA0bSGPsEDOLoMT6lpxv1tZgJgkXS6XYK39Slm zJi7HHDGCOgEuvJrVy9lpJfyBbgcEMPjlCY4z6NFBmEqLG/Dz4noVvoubApnnmSsFgAN JvGVM2+ynZvmdcfhNDHuUwDplaJlRPTJdc2BwmFLZMTcFLZhGU4VLtH2jEPep/m9QeKq C8oALes8VcsLFzWup66eZRqIp6vFmMT//mpEnwN2yM5A6SbUGSYF/vpw+JVzfweAIJ9Z nt2g== 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=3ribtvx7UcAeRnuatyTSMVEWHwe95f5+/jZlD6/wM8Q=; fh=i+pR0Y9t94OKZsARqUkLMEmtPQHvmw7bpTYa9QkhXpo=; b=KkOVyaFMMNmAGTa2owDdqMKirmi/klFAm35FSFb1P5+xBhATU9rnWYIjl/p1z4F4kP xsJbR3NwYs3OD7LfZr+ntCPbn9wjg7q9JNqje5IhHbTja1WT+reCmzPttywV3e0/Ua0f OflZUkJyqEgkMKMsOKQhx4AzlimEyjugY47Y+GnikgNLwjcpeXP0OOwJ0h5nJJ7Hs7wl aVti3T6/VwDjBPZVAkTcHzySsfS1g6I51s0111PvCfUYGKeFtA+mfoPxCi4VohZ/Zgbx RhymdWbcrTal+XFl2AhT+O+7ZqxITFHH8iAXXaNmat34EZt3HQuggMTcSZVA/LcGc9mB 8urA==; 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-8694-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-wireless+bounces-8694-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-57aae230235si1921264a12.432.2024.06.07.07.02.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jun 2024 07:02:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless+bounces-8694-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=realtek.com); spf=pass (google.com: domain of linux-wireless+bounces-8694-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-wireless+bounces-8694-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 8C1CF1F2228F for ; Fri, 7 Jun 2024 14:02:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BE0951953AA; Fri, 7 Jun 2024 14:02:14 +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 31B15FC0A for ; Fri, 7 Jun 2024 14:02:11 +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=1717768934; cv=none; b=YvWteRiSH2GHEckvmovoKo/4jOZf8LCqx3+DkcgdWn9uUDsvQWFGDC38S/2Uz4AKyPn14erinCeL61tvG1MnNZSQrJOSGertKumGe99qaC5cia+4Q2RFaVE3CM9KWz3sfCAJ0KrflbAtmCX5SQyKvpLjfpW0WomXm/GYNVcI9XQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717768934; c=relaxed/simple; bh=CCYeF1IU4NZbdQsZT3CnB9HzR8SgNaMN8HnMS12ZZjA=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=NeAbQLZ4IYoTDeqD9kHLrtthhmL22gmPXr4vx7s7yJ3qtIO6yh7pn25pvCKLDhWcaxax8rhj6EcuVBBvRiqAuiYJN2aIxTKVjjWbN8ag/yWVim5GsJXwD0cnOIDYMEAI0a4tvJhMdOAT55AndxH/P08PYYhrbzipV8zhz5vRtII= 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 457E2A0Z04076724, This message is accepted by code: ctloc85258 Received: from mail.realtek.com (rtexh36506.realtek.com.tw[172.21.6.27]) by rtits2.realtek.com.tw (8.15.2/2.95/5.92) with ESMTPS id 457E2A0Z04076724 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 7 Jun 2024 22:02:10 +0800 Received: from RTEXMBS04.realtek.com.tw (172.21.6.97) by RTEXH36506.realtek.com.tw (172.21.6.27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Fri, 7 Jun 2024 22:02:10 +0800 Received: from [127.0.1.1] (172.16.16.228) 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; Fri, 7 Jun 2024 22:02:09 +0800 From: Ping-Ke Shih To: Subject: [PATCH 2/2] wifi: rtw89: pci: fix RX tag race condition resulting in wrong RX length Date: Fri, 7 Jun 2024 22:01:45 +0800 Message-ID: <20240607140145.8180-2-pkshih@realtek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240607140145.8180-1-pkshih@realtek.com> References: <20240607140145.8180-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 --- 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 5e6df70513b3..b7d10a1b2d09 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