Received: by 2002:ab2:5d18:0:b0:1ef:7a0f:c32d with SMTP id j24csp467068lqk; Sat, 9 Mar 2024 20:54:28 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUmbvlEFVKfULjOozoF9Juij/8Z1yWz9jpuVhaMF6ZkSNaDV1aLbT1h0CNg8U/GQLT6ruu2tGFalvqGKhGlz94fSBe/G++P+y+GjME1tw== X-Google-Smtp-Source: AGHT+IFLqHWg8pfbj291+KHlgbSEDXukODxnnKIQw/xRCFQNN3kSC5Nfc7jgsUFp/g8WeHAOQxiC X-Received: by 2002:a17:907:7d90:b0:a46:2105:a371 with SMTP id oz16-20020a1709077d9000b00a462105a371mr200747ejc.2.1710046468601; Sat, 09 Mar 2024 20:54:28 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1710046468; cv=pass; d=google.com; s=arc-20160816; b=TU3HIVfbu86WP0AJL+YJdZ2GVDwYD+7h15U85SbK9gemkAw2G7dLedofob2MBd8ORo v/6EpXWJDm1irTfM/BWi77AKv9kHZuBMd5/bgeE4weS6FfyTU0G/TQM0mv3EKEfcYqhg YypFe3UsGgXBqhQnJIRdg/Ou6FTQ0k/K6VR3z3XmpHFALH6PPelHgMV9+wb/TuhSsble ShAHX6YMS3QJ7FXThFStgfMRV+EIjGOnwxgVztRoTknqp+zYf1hXKOrj4GCMoSGvG0dG G0Fyx9LG/4b6YRD1etzb3Ho9BSGfiqgyIYvP7r8x2IratdSEXegHrYGNpXym38/p5R7R 3q+A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to:subject :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :date:dkim-signature:message-id; bh=MfpnvfCFCpDGN6RtbnA1IMFWuCTDp/YHUNDd+urhXvA=; fh=4NlUyfzP/nvmSTgaD6vdyQxMA7Kw6592usXxU5WqxcI=; b=YWG9sI2mUjq7eKYgu0wa6GMK0CIaI68e5uynuDckBSzQT6KC9woOnDk86tS5u33f9R gVkYlcXZk62m2BI7VmUGLN9aNkfI3Y5Jy6OgLrsxi9Q2ZNJC7mfTO9wvBsR5ZhUmSpXP YHVIFThHnEylRq0ShBcuHS3abV6BazRA61V/cR/ShdS5+j6lzX4qilfCHoF7UDfWSGRk UK/aN8zhV4vv0j1Y+cr1aWPWcOGqO5pej+f58KR4kdUK0xDTvV5nXHRNNvW8MkZYBhGj iYnCJ1vL8ru8rM1/rSLWUqR8j/jD3tNkShLDnLNaIa2ZCqzP5lGESorKeC/w93muCk0n OWhA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=Y9elywXD; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-98119-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-98119-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id n23-20020a170906379700b00a461f722a55si188427ejc.511.2024.03.09.20.54.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 09 Mar 2024 20:54:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-98119-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; dkim=pass header.i=@linux.dev header.s=key1 header.b=Y9elywXD; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-98119-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-98119-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev 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 5459A1F2150C for ; Sun, 10 Mar 2024 04:54:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 779B2FC11; Sun, 10 Mar 2024 04:53:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="Y9elywXD" Received: from out-183.mta1.migadu.com (out-183.mta1.migadu.com [95.215.58.183]) (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 90E229445 for ; Sun, 10 Mar 2024 04:53:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.183 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710046415; cv=none; b=DGaDcb/XjMfBF+YCsmuOpidbalMIqltlvnJCv8g/ercYllBAISusF73ho7BDziozf7k9Uh9d0iSgOYUAmyq/AbOnJSy4HUAsP4eTngusUybdNWrGrcqSQnqdOLG7VEUZ3ODUNIEUI2bTyi2RQ4HmBJE0bwnNYj5hjR0nGZ20RyQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710046415; c=relaxed/simple; bh=+M5/D3rA/Qm/pKCZPYWYSQSBNzUmBrlAdlHD3eIkNA4=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=jfDZoaMdjgBCh8ODsFqtI+FaLJBVx2O+WCLD0oRai+qbIMGILUfV1BFyIxzUCknC6dUCaFBZm5b5JNKnTWbSv00epzQa+y89C48A64nAj7F5vhhK2V4Yx6o4NNcrC/WpIhXnxyHywXt/c5H5bf+2XOtPFOxTL/nBw1V3OGMK4/4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=Y9elywXD; arc=none smtp.client-ip=95.215.58.183 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Message-ID: <2d508574-c2b8-489b-a26d-71b1c36961cf@linux.dev> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1710046409; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MfpnvfCFCpDGN6RtbnA1IMFWuCTDp/YHUNDd+urhXvA=; b=Y9elywXDtnQ7uLAWp0rfk8mONQnZAu/7agWecQM5Gv2K4KTPbcYKM15DxzYmucCl5V84av m0rOdUylsJDu2i9diwUnOzmyuZv1K6kI2j4OojqmyoT+SWIiG6l4Dh0DOlYKe/YXQ112Uv NTCTStj7A5nv0mJ2Wpwtvsdl6xQXYcs= Date: Sun, 10 Mar 2024 05:53:26 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Subject: Re: [PATCH] RDMA/siw: Reuse value read using READ_ONCE instead of re-reading it To: linke li Cc: Bernard Metzler , Jason Gunthorpe , Leon Romanovsky , linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org References: X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Zhu Yanjun In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT 在 2024/3/9 13:27, linke li 写道: > In siw_orqe_start_rx, the orqe's flag in the if condition is read using > READ_ONCE, checked, and then re-read, voiding all guarantees of the > checks. Reuse the value that was read by READ_ONCE to ensure the > consistency of the flags throughout the function. > > Signed-off-by: linke li > --- > drivers/infiniband/sw/siw/siw_qp_rx.c | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) > > diff --git a/drivers/infiniband/sw/siw/siw_qp_rx.c b/drivers/infiniband/sw/siw/siw_qp_rx.c > index ed4fc39718b4..f5f69de56882 100644 > --- a/drivers/infiniband/sw/siw/siw_qp_rx.c > +++ b/drivers/infiniband/sw/siw/siw_qp_rx.c > @@ -740,6 +740,7 @@ static int siw_orqe_start_rx(struct siw_qp *qp) > { > struct siw_sqe *orqe; > struct siw_wqe *wqe = NULL; > + u16 orqe_flags; > > if (unlikely(!qp->attrs.orq_size)) > return -EPROTO; > @@ -748,7 +749,8 @@ static int siw_orqe_start_rx(struct siw_qp *qp) > smp_mb(); > > orqe = orq_get_current(qp); > - if (READ_ONCE(orqe->flags) & SIW_WQE_VALID) { In this if test, READ_ONCE is needed to read orqe->flags. But in this commit, this READ_ONCE is moved to other places. In a complicated environment, for example, this function is called many times at the same time and orqe->flags is changed at the same time, I am not sure if this will introduce risks or not. if you need to ensure the consistency of the flags throughout the function, not sure if the following is better or not. if (((orqe_flags=READ_ONCE(orqe->flags))) & SIW_WQE_VALID) { Thanks, Zhu Yanjun > + orqe_flags = READ_ONCE(orqe->flags); > + if (orqe_flags & SIW_WQE_VALID) { > /* RRESP is a TAGGED RDMAP operation */ > wqe = rx_wqe(&qp->rx_tagged); > wqe->sqe.id = orqe->id; > @@ -756,7 +758,7 @@ static int siw_orqe_start_rx(struct siw_qp *qp) > wqe->sqe.sge[0].laddr = orqe->sge[0].laddr; > wqe->sqe.sge[0].lkey = orqe->sge[0].lkey; > wqe->sqe.sge[0].length = orqe->sge[0].length; > - wqe->sqe.flags = orqe->flags; > + wqe->sqe.flags = orqe_flags; > wqe->sqe.num_sge = 1; > wqe->bytes = orqe->sge[0].length; > wqe->processed = 0;