Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp256474lqb; Thu, 23 May 2024 18:10:13 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXyjiw/SENmrYhDfN5BjTkRUR61W9uyMsOlpPNyPZT2pnt7lZfPiQAyomMdKE799+ozQMGShQNO6F9jFxlc9tVvX7kRmmOmoorUCvUq/A== X-Google-Smtp-Source: AGHT+IEtiPOhZoI1q93TNkFokB7bNhw8oFCcONePAbxsxHJUhrIhCsK9T4t8wRQVfjEs5o1AUZgV X-Received: by 2002:a05:6902:507:b0:df4:d692:93b7 with SMTP id 3f1490d57ef6-df772266789mr872524276.44.1716513013378; Thu, 23 May 2024 18:10:13 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716513013; cv=pass; d=google.com; s=arc-20160816; b=gEk7kNv0nqL+UCJ6XHwuvjwb/oaDD2XzT4aKPIjiJJDuf6iS0PAWhNK6RBIq1/04A1 mwW2J50OR+siP9QlffynGYj1Wsa/ZQUzsbeNanT/wyIvzHrs5zw3m7cIvWgLRie0EPjK ZxqBqCVus/j2pl6bSQrWFkyuEt1fc6Hwnh1DKF+cSV3VQHBiyTxv0zx1DnSDjgCJwYbg 55/TZv+tYVDhI8qbNPeAVAFM12YU7mPoDKtB+R7i4+11NYNdibb5ayw6fPhNmmLfQ9Qj SmY4iqDj5WN9XtIOLns6LZihSoAyZ8TGd9TXxjZtPcDI9r5kmBdNLyhBZWGSTL8BjSeu AVSw== 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:content-language :references:to:subject:cc:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=7AZYNa3dubwm1b1iVOfjYS5QjstXr+yLk57rteK8jlE=; fh=S1wo+dgkJfy/33Amumj/7lhiQ+pjh6vInOGd3w6wILQ=; b=Z5tFsaoCrW7oqdmdpxEQBCYuqcXvQnSYLv6y00GWVpBqfY8fe1XZTmWT2SwEj6oHU4 LhCyvC1wAOnLLA4zEnM78RRwTkOA2z+JN52rT95hVc4U0/mAE2P8DCVYi2e1FTjNeyLW ohapsKsqVG0tSXQl7+T4BgvRI/0yw8t19ERK6wCW/Rti6VOBYte4ISUvVcDFKEVBFtJP G2eCmMPG+KBumoRrLGwBYfWTSCPXB0VKvJwrgDN9ETKRwowb0zlwfnHB0QyfCbHf2q/1 a3M32N64brwTU5ypT9kL6UedECj37rmG7AyaRZ7sLPSfdh2+GZeqBe7ZjIeG1cbwwZZN tpMw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=DK5VZN6k; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-188200-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-188200-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id d75a77b69052e-43fb18ca67fsi6807511cf.675.2024.05.23.18.10.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 May 2024 18:10:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-188200-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=@intel.com header.s=Intel header.b=DK5VZN6k; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-188200-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-188200-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.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 1D0A41C20F80 for ; Fri, 24 May 2024 01:10:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E41E1749C; Fri, 24 May 2024 01:10:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="DK5VZN6k" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.15]) (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 C714963CB for ; Fri, 24 May 2024 01:10:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.15 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716513005; cv=none; b=Z7eqXr+sEHB+dlp3k3wSkYzdLFCtypvkaGahIfkZOcY1Zg+Yi0ItO9rAyjdmKFHXgRvbEN6dJ46SQvzKECZPCOZhRzwjVZOIIxEu2wvsyknFyRjI9FMKbW77KsjUhZ411fWnsMHxEz+NwBXAMSMoo6poxCRD/PBK0x4SVinsbV8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716513005; c=relaxed/simple; bh=9zABepybl5Xgb4WhZA5zrlZW3sm8pmuNcyyKqdDjNS4=; h=Message-ID:Date:MIME-Version:Cc:Subject:To:References:From: In-Reply-To:Content-Type; b=RKv+SZLy8MsQFmnKbcxS2B6bpVZNNlHyPb9H1LZ1oqjaroux4oNBHg/9OndBEG6BPBS0h+oww5hqy1WuM4l+1l27aGifaA9VyM7sBtPD6AH9g7F+UskHvZV2D6tPwWMEY31uTsYIHxzakUJ+YpntyQzepQa4202itc/0rb0PbXI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=DK5VZN6k; arc=none smtp.client-ip=198.175.65.15 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1716513004; x=1748049004; h=message-id:date:mime-version:cc:subject:to:references: from:in-reply-to:content-transfer-encoding; bh=9zABepybl5Xgb4WhZA5zrlZW3sm8pmuNcyyKqdDjNS4=; b=DK5VZN6k3femHbGi+X8L/hKRLIAv1H8lua4wQFTd9+fMcUKlfCAfjOBS xZ8ZoJjESAnkQ5yXo3qVguzL3OZalo/XpQQA/Dzc2l3xcmV+xohazXFKZ jAaCFfcLERI4mnV4YVjKKa2Q2hE+adqHg817B1O25CFAyTmWQR2FUHT/U eRoUnz/ODH9RHJK1Twbh4HX6XnsUzYMYHtwkbP4rePB/cVIdWD+JnR+dF pL96Um7h1TH5EesHqD51htp1H5yf6323tIeKwsZ7wAGYQ1f9Fe2QuzJWF ynLfFnwtGI/5+n2hVEYmICkxcCYBiPE9dMKwHZZ2oiAeZ0kqnFzzCSN/x g==; X-CSE-ConnectionGUID: kv++gFWsSfGFvSEuHmMIwg== X-CSE-MsgGUID: 07d4GZTaRAyZynor4Q3rxg== X-IronPort-AV: E=McAfee;i="6600,9927,11081"; a="16662216" X-IronPort-AV: E=Sophos;i="6.08,184,1712646000"; d="scan'208";a="16662216" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by orvoesa107.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 May 2024 18:10:03 -0700 X-CSE-ConnectionGUID: g7IsVQLASryIB31Jt5lnsw== X-CSE-MsgGUID: VClbEt7rTEarGLeuFs+a+g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,184,1712646000"; d="scan'208";a="65065176" Received: from unknown (HELO [10.239.159.127]) ([10.239.159.127]) by fmviesa001.fm.intel.com with ESMTP; 23 May 2024 18:10:01 -0700 Message-ID: Date: Fri, 24 May 2024 09:08:04 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Cc: baolu.lu@linux.intel.com, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, David Woodhouse , Joerg Roedel , Will Deacon , Robin Murphy Subject: Re: [PATCH 2/3] iommu/vt-d: Use try_cmpxchg64() in intel_pasid_get_entry() To: Uros Bizjak References: <20240522082729.971123-1-ubizjak@gmail.com> <20240522082729.971123-2-ubizjak@gmail.com> Content-Language: en-US From: Baolu Lu In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 5/23/24 9:57 PM, Uros Bizjak wrote: > On Thu, May 23, 2024 at 3:44 PM 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_PTE_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) != 0) >>> >>> this is equivalent to: >>> >>> tmp = 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. Oh! I misunderstood this. > > tmp = 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. Okay, it's fine. Best regards, baolu