Received: by 2002:ab2:710b:0:b0:1ef:a325:1205 with SMTP id z11csp155079lql; Sun, 10 Mar 2024 19:35:29 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVo5reDQYYkxRPm/5UWLfSWwGoLgNeEXtn1kwnGPWvwWL1zLNXZ01vWupWnR7P3Geh3MmMyUMZy6lZr1KvoJvDqkp2ALMCzXgtrZnZahg== X-Google-Smtp-Source: AGHT+IEhJLDbDSKehnYWY2rb7DhdfoRfC8Op4RaxanmmN7M1vp8qPiDlkMBJcctfjxwZmOGCGMHc X-Received: by 2002:a05:622a:1341:b0:42e:71bf:6a35 with SMTP id w1-20020a05622a134100b0042e71bf6a35mr8538712qtk.3.1710124529632; Sun, 10 Mar 2024 19:35:29 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710124529; cv=pass; d=google.com; s=arc-20160816; b=HBtGCyDGE4zCY4pi+kEcb3nB29tVKmCzVOY6ENvYhlpDg5MuRnfdPgVR6kc+PG0R5N n807C82kwgFPoV13jxhiPj3Nyr2V5B7IdJrpEtkNXZtilnupvjkB1FfHXSXnKAKRiOrj r5mEqerGzPzV9VTAD5FQiDhZcthnO1fFQQRHNhXuLBK/N1jpwmHJZV/87c32UJC6OMTA TqIUkKROLAbnPXYpFjNUNR0jDWKXUF6KUoKsAa4mXTIiVPQvL/rgLawgngNwyE6UZ2VS pyz5Uj+aylqWl8f8TtrXl5k1p67TD4oeKMxf1cnyXzHznEfCWEZPvdLAUuzAqkRzIpRi kd6g== 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:date :subject:cc:to:from:message-id:dkim-signature; bh=C+MiEF4qC6FAaylAML0xdTY2YhM7+veLwzKbbzTLXok=; fh=VEgFVeNVaZe6htATt+FxTp6GQZo63iVHzcSLM5a5Y5I=; b=0M5IuRg3kN5hlltDtFFFErTZTCo4ifQJcsbDcBO+h2nBSJSIbzzo4WcWD6l3PxsNhc 39SsLCssTFVNqNagCpHdADW9KIWUQxD0HLj5zWuCjoL8YEAqpMZwps05D6gDJUg4kC54 r/q9Ki3HUjwkBkYE6mmdqhit4TiYP9TviiX97JBw004vAd1tVUwaNEexPKIz7IwJXlws FQq+EWb3TFLU+I0avzx5TJ40xytPyZ0ztXlsqI1In1NHAQpbHhxnQVN5uNfqeHTgYHsH f7Zdzo54j6Oq2FfigLZAOQtb+PAQ6dJmMFbwTksHJvcUqS0qfprurl6onjfX3hp/Mvuf fthQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@qq.com header.s=s201512 header.b=kmIFnJcN; arc=pass (i=1 spf=pass spfdomain=qq.com dkim=pass dkdomain=qq.com dmarc=pass fromdomain=qq.com); spf=pass (google.com: domain of linux-kernel+bounces-98421-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-98421-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=qq.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id g3-20020ac87f43000000b0042e8ce272dfsi4634686qtk.297.2024.03.10.19.35.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 Mar 2024 19:35:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-98421-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@qq.com header.s=s201512 header.b=kmIFnJcN; arc=pass (i=1 spf=pass spfdomain=qq.com dkim=pass dkdomain=qq.com dmarc=pass fromdomain=qq.com); spf=pass (google.com: domain of linux-kernel+bounces-98421-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-98421-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=qq.com 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 5D7E91C2074A for ; Mon, 11 Mar 2024 02:35:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AA4CD138C; Mon, 11 Mar 2024 02:35:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=qq.com header.i=@qq.com header.b="kmIFnJcN" Received: from out162-62-57-252.mail.qq.com (out162-62-57-252.mail.qq.com [162.62.57.252]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 78BC93D62; Mon, 11 Mar 2024 02:35:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=162.62.57.252 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710124519; cv=none; b=f7dywNLf2ahrtQ9Zd07XmGOYt3IMz6lqBFFLhcrZxmRbRE3h386ffrtuSHfN5CnKkFXmVhTEsV/CSOJFGw1qVx6+1x9T8J/fQa4jYpkvaRo8T/0hXRwtR351ljsszFaN8JSv4AmIjHxBCeFI8OIJS+75dH3FtDcJJ/kDkLrLfBU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710124519; c=relaxed/simple; bh=WhmjuGV1kq2WCEIDtuCaWUDhxbU/+ZMX+LPouv4Jpx0=; h=Message-ID:From:To:Cc:Subject:Date:In-Reply-To:References: MIME-Version; b=L89hs5MoeMju+LRWzfT86ju7B8Ogp83j21FZheAe1VmC+nJQ2J2D4JR/GzSriFuOmSIu118taK/W4IRNnFyUQXvb/WNiPa+F6BQE17adUf/x43Hl2hXHvNMMJevD/+JNnPsOlTsd8YgiqCvepVVrugZTgcXS3M8Dygdbn6kFuEk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=qq.com; spf=pass smtp.mailfrom=qq.com; dkim=pass (1024-bit key) header.d=qq.com header.i=@qq.com header.b=kmIFnJcN; arc=none smtp.client-ip=162.62.57.252 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=qq.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=qq.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qq.com; s=s201512; t=1710124500; bh=C+MiEF4qC6FAaylAML0xdTY2YhM7+veLwzKbbzTLXok=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=kmIFnJcNDNfWAj2bmooSKy0uGNvlwfJ3NDxvHOlFQGUiSdV68TvplEgqoqUnVgrw3 zHSrLBS4L1Vgt+9aeMb3va51KsCYeuS40sawoo2c53Kj1hnZLnFnl9IGWj2wCs6Uut JI/Yk7NjdX/gfvHofLH4v1PqQSANFmHAVoVJsvPo= Received: from localhost.localdomain ([58.213.8.34]) by newxmesmtplogicsvrszb9-0.qq.com (NewEsmtp) with SMTP id 8B995E48; Mon, 11 Mar 2024 10:34:57 +0800 X-QQ-mid: xmsmtpt1710124497t5plveddw Message-ID: X-QQ-XMAILINFO: Mm/8i8/T4yneLFjWWrRIGkqbOZu0z8AIxOyq+RGDR2OmIiGfEHfbT3yggaBppe x+5Owg6mNNjoEAAbIRdkBqJmqPPOxnSWCkL/x8/JNqrlqyr/Er8NPHOPK2Odgdf3Wfl9trvb45r1 ZGgig1CzHGTZfkcGQjSWqtyY2RhcBFCl6VKvTw4d4J/pHCgi6J2TcThOgZC0sBpFmImg9qMnKdQk ZkzOGkc9dOXrK6MuUyouiFAyyWm7Y/u1jLFogBqT1wD61ak2kJdUGphZWVM8TAElO25Jd6/2AWO5 252H1Ps7ELnyxV/rIJTh4zeJaFtKg3fQdFY/md//rE7EErZ634ACM1PVhb7mYkqHy/c9URVhydQr 4BqDq32dWXFz4w7mIA76jUA/BwZZR2eItyGigLDf3PIZhwZ/BwReudQ8sIFfVAKvIn4TIs/ntp9X D//eMiXXxqUwaaUHTVR36y7xImPkBSn8WXagPj2/anSS1Klud7FUESIAem3UfM/XLnXCHZjmu3y2 NQy/RdUHppO4D9GqL7ML1pdfu/ODveaAjc0lHjHtjQz+BrT38XG3s9mL+SIxEZZYhJOHUMAh91eT GKL0fwkdfktYZAleB9eg8GBosG8hf6YpEdmj3O/5dEXX8r9Vw2LxNsevcSCpAcXCXlCfD9LyjGvE clQCLafmM6Ddts/jB8oteHDFz++v2ljoZobAXBUUSlRKf2O7IzMPZ+zGeumlRplpB22Qh0Csj+J1 yeKW+edaCYbPkC4u3jO1hKO6XWAl4/h+Lb6vylBUh2o2yEgvFhPN+NuFxAHNXs/qKW6uBOodBAW6 VOeXQA6q2AlCIlHOaJ2zYcL+mBxR58ADNrjaRYUs+04VKscHopX9VJVdHLZl6B/dDRADFJGrL3dp Kv+RAiEO/ceg8ZE15tQJCauMW3etZXV1IR98g6UneFwyUQtRMmEvUPBCF54FsRVzaI0gZRGdMMso KMtOJxzM+3nTgqmbH9u0ZGduadSmvG04a6j9bVZYN48MSpqQDV04O6GlOxwCTp X-QQ-XMRINFO: MPJ6Tf5t3I/ycC2BItcBVIA= From: linke li To: leon@kernel.org Cc: bmt@zurich.ibm.com, jgg@ziepe.ca, lilinke99@qq.com, linux-kernel@vger.kernel.org, linux-rdma@vger.kernel.org Subject: Re: [PATCH] RDMA/siw: Reuse value read using READ_ONCE instead of re-reading it Date: Mon, 11 Mar 2024 10:34:55 +0800 X-OQ-MSGID: <20240311023455.72601-1-lilinke99@qq.com> X-Mailer: git-send-email 2.39.3 (Apple Git-146) In-Reply-To: <20240310191910.GG12921@unreal> References: <20240310191910.GG12921@unreal> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit > If value can change between subsequent reads, then you need to use locks > to make sure that it doesn't happen. Using READ_ONCE() doesn't solve the > concurrency issue, but makes sure that compiler doesn't reorder reads > and writes. This code do not need to prevent other thread from writing on the flags. This topic got quite a bit of discussion [1], quote from it: (READ_ONCE and WRITE_ONCE) That's often useful - lots of code doesn't really care if you get the old or the new value, but the code *does* care that it gets *one* value, and not some random mix of "I tested one value for validity, then it got reloaded due to register pressure, and I actually used another value". And not some "I read one value, and it was a mix of two other values". From the original code, the first read seems to do the same things. So READ_ONCE is probably ok here. I just want to make sure the flags stored to wqe->sqe.flags is consistent with the read used in the if condition. [1]https://lore.kernel.org/lkml/CAHk-=wgG6Dmt1JTXDbrbXh_6s2yLjL=9pHo7uv0==LHFD+aBtg@mail.gmail.com/