Received: by 2002:ab2:7855:0:b0:1f9:5764:f03e with SMTP id m21csp1016578lqp; Thu, 23 May 2024 06:58:05 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXIDLUbV1UIYBdTVaW+hxd4eN8XjYzYHzUuU0ACKtozyfM59HjG40ACkDh41Lpoh1k5EO3YyDgOj8DG4otJk6rbWw/9kpvSx3DtXBaUAQ== X-Google-Smtp-Source: AGHT+IGQ6Kbzam7G98Io6ARUufmx3GssSKTJuwEjRwkeb+dAowH1AS4SAielfD9Yhb60P+hJZqh0 X-Received: by 2002:a17:906:1915:b0:a5d:191:7b96 with SMTP id a640c23a62f3a-a623e9d4dbamr211244166b.29.1716472684966; Thu, 23 May 2024 06:58:04 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716472684; cv=pass; d=google.com; s=arc-20160816; b=rJ3tlinAPhRHYXFG9wj3XmnjbZ7xzuzM9k81Tv26wCtAKX0IUkTYELLjDTUaDtXQ7t 2BMnoweCZx8EYwyLoZQIDPVhPSNQxKz96t5ZcIzr6qOsFXsvMEAj5PXMVdAHcX2H88v/ qeFalhssFjOfSmNE9hz7xGSSJmWfsdxJbHGmBvAqRBKqdwPGQQEx5DDMdMFEV4iOmVEp ykfXsJKVBOQiBq+USHuVOQ5V8sz3Rrytvuo/krfFedCQlfrWUKz0yzj5WPZ7QoHE8fXK pCfyH2OTlaV4we7hnKLyDm+4I6iKPKNuMhahDZjMbx2ui8pMniHOzQXCrl4ZJQ5wVU/u z3Og== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=OMOUYCMFihJdUjCJHbJ9rJQeq23/qVjfUy+xhBp831s=; fh=gprcuzMwYL2OE/AdRHaTB9RI+05WDX35r9EW57ba5tg=; b=E/v/G/preXh0RSIZdQ411hpssf03+1dm0kJYOxLnJAhBUqZO2ME3rDzxs50AqyRP5K MZ0ivKZcPKbAIzjKJijnd8R7dBest2ALt+VK/VU9UhytWvL8XGpfqmr9oprXktRCvLDq 8C8AQ79CejI1apeu/vze7ilYLkXMLUWN52d4oO9bxH3JB8U1+Bv2OI3QARdGoYPxs1Ad ltEs3l6yHL3TWmq7Tg69YBQC7IzpK0dMX1W2lyXrNRjh5ijOKbaMLWGRJdZAxbGdrANj bP/dpbdbeiD/MNzvVcpneJYxxcqggJJtAYHa+ZEdOmnJ8hybB7s7Nf2oH/ZPKvYm2QMZ SKhw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=UZF4ZtN7; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-187603-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-187603-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id a640c23a62f3a-a621c9bf1absi230289266b.454.2024.05.23.06.58.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 May 2024 06:58:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-187603-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=UZF4ZtN7; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-187603-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-187603-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.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 am.mirrors.kernel.org (Postfix) with ESMTPS id AE1381F216A5 for ; Thu, 23 May 2024 13:58:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F1EF414B06E; Thu, 23 May 2024 13:57:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="UZF4ZtN7" Received: from mail-lj1-f181.google.com (mail-lj1-f181.google.com [209.85.208.181]) (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 9ADA814AD17 for ; Thu, 23 May 2024 13:57:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716472676; cv=none; b=fdxr+yUkszzFvHSA7+WYzkUI3IUA5ROkSAevwblHuCesFec7r30e/vLCWUtuhE4otqSFj/M8Tay6yxxcXX42fk+NKJIIL15Vamw8dj1zxbEEt8tHonK0uFKvkAiIftQ+jbUj1vUC2QaUDqP+HZmnLFNDA9F7l1fxH8L9jUMFlA0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716472676; c=relaxed/simple; bh=9x+M+9APIGN3rhHl/tijNJMgK0ojb20CQmY/C3fB0G8=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=lk/slsZN5Bkr+8i8WgVpaX+qnjMlwJD1lxzd4a8yNX6JhuDC3R/8HU/l6xUh9qcwtyFF8KPC6oVGgSK7IbpgZGsqiCoeYdG9SSN5lU9hGVfpzPcVWU5cCEfpRMCizW+lXo7ox9TJ1FQ38cRPA+FaA38SYPd5JJqFu3YFQt5pz1Y= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=UZF4ZtN7; arc=none smtp.client-ip=209.85.208.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lj1-f181.google.com with SMTP id 38308e7fff4ca-2e8a8ff4083so19308781fa.1 for ; Thu, 23 May 2024 06:57:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716472673; x=1717077473; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=OMOUYCMFihJdUjCJHbJ9rJQeq23/qVjfUy+xhBp831s=; b=UZF4ZtN70DUqUlcCiUtNrvPG9Gi3Vvl0eAP6SWtwXOzk+yxCEFJhuY+HB48QmZQb1T h12mdi+Vzl5DC3wY75Oq01ssl+wUJJTARO1cDExgeZApPa/GkGMC7synFQHVTjITQkL4 BmdnmHZuxTpfrKJA6dga92N0DR2gsyzP1E7UMicfL7OI+h8fKrmV113H9pRA+tx9DvTK WiD/ZSmptMLR8+T3/zTDqEFYJRS+fgkkBKEhfRzD+ca3YmJiKzooyUVLBJJCOxCTjdNa A4ig2x3kIb4wa/lC5no1gX/bzLw2SQmPpzFXiSRLKyy9B9e7Vr499YdwCRyCXRcToPK0 WqBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716472673; x=1717077473; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OMOUYCMFihJdUjCJHbJ9rJQeq23/qVjfUy+xhBp831s=; b=Poas+JrNbv3XkbJNR+9SlE1qF0vq4hsA0E38cVYK1TZkpKoaEV2X5UEa8AoSY0bNVz cM/Pasq2ilbJLk2WFMLJzWXl4/d6N9RECLvS4akAr10ZSTcOAaCbL5Ha/pmDIioo+MIa XAOrFEDgFlx4qgdMS5b3ahHvg2FQ7UHREbSvJ5V3pkW/dcTOjUWPtzd48TlzHDEW4p/0 3pspo6PWIt0bVcbD9v2ilXaYnaS34cHqVH4XLUN5J/W7akyz8RqYuwHFlT3FxwPfxerV fq6fR4oeUhNQlejl1Zszpn+FkgWISFRFa80ljaLIlwvo5+5zrjHnC48LiVVrOSkRGAfc DaCQ== X-Forwarded-Encrypted: i=1; AJvYcCXwQ4oNXunpMM0PmCt4z8k0aPRkk2k7/B+d/VBd0TEz3LDg8FLje7fmexgfYbtDZIe60FvVjNsdBNBx6w/RjhLCWwjaOdKn8GIWSHyC X-Gm-Message-State: AOJu0YyyFbfCs5ZT1sligumD8PA1QGcnBnms1txdm7OP4KKqZoNEcFUa tibhodwQPvZzHmGHYPFZTg6h5w8+Ui8gA5mE3n/Y7dx2INLDt0xGUjUHp5LasBdlS8UVxCz4BkV 5/E15g2eNpBtPlgEPIsEKojlMduLOzDtVt62K6Q== X-Received: by 2002:a2e:9087:0:b0:2e1:c97b:6f25 with SMTP id 38308e7fff4ca-2e951b4f30bmr7752721fa.1.1716472672458; Thu, 23 May 2024 06:57:52 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240522082729.971123-1-ubizjak@gmail.com> <20240522082729.971123-2-ubizjak@gmail.com> In-Reply-To: From: Uros Bizjak Date: Thu, 23 May 2024 15:57:40 +0200 Message-ID: Subject: Re: [PATCH 2/3] iommu/vt-d: Use try_cmpxchg64() in intel_pasid_get_entry() To: Baolu Lu Cc: iommu@lists.linux.dev, linux-kernel@vger.kernel.org, David Woodhouse , Joerg Roedel , Will Deacon , Robin Murphy Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, May 23, 2024 at 3:44=E2=80=AFPM Baolu Lu = wrote: > > On 2024/5/23 21:34, Uros Bizjak wrote: > >>> + if (!try_cmpxchg64(&dir[dir_index].val, &tmp, > >>> + (u64)virt_to_phys(entries) | PASID_P= TE_PRESENT)) { > >> Above change will cause a dead loop during boot. It should be > > No, it is correct as written: > > > > if (cmpxchg64(*ptr, 0, new)) > > > > can be written as: > > > > if (cmpxchg64(*ptr, 0, new) !=3D 0) > > > > this is equivalent to: > > > > tmp =3D 0ULL; > > if (!try_cmpxchg64(*ptr, &tmp, new)) > > The return value of both cmpxchg64() and try_cmpxchg64() is the old > value that was loaded from the memory location, right? Actually, try_cmpxchg() returns true if successful and false if it fails. tmp =3D 0ULL; if (!try_cmpxchg64(*ptr, &tmp, new)) The logic in the above snippet can be interpreted as: if we fail to compare *ptr with 0, then: iommu_free_page(entries); goto retry; as intended in the original code. Thanks, Uros.