Received: by 2002:ab2:7855:0:b0:1f9:5764:f03e with SMTP id m21csp995941lqp; Thu, 23 May 2024 06:25:26 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXZNcH3QtSwZ6b8AWrrgV9I4MTIU6nZeM264IFvzBWMgG5LbbywvJws25q/8DBO2IOpEarGLsTSrojqO7dZPFWDBY3xlapNqLuMb8RYIw== X-Google-Smtp-Source: AGHT+IGsbfPfu2/KzQ19hj2X61LCaz/9GZM6Uxd812J0pOKQd8tBnIyVrDoYChPCjbNRd/XxODKQ X-Received: by 2002:a05:6808:428d:b0:3c9:6bdd:27f9 with SMTP id 5614622812f47-3cdb1cd9fffmr4893205b6e.6.1716470726071; Thu, 23 May 2024 06:25:26 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716470726; cv=pass; d=google.com; s=arc-20160816; b=IxUj1CYBEUTWPGycF4Wc9fF5bxN4eP3ZpWZyPh+dC48SBWQX3eCFyGC+cSegwG1Rqm EN1Krzx6HnIzFdGlP/dbcddIIVlpxuXiKP2uk4oN3926RZlaigrDFcsFTiTMHMCpp6Js 3CeUI2/zwaVGfTuRPDiimCSWFpBOq5bOuJYRsABVebCVZdrvNB3nI/AALp54Vtc4yxgQ p+2cVyhZcWpi/mCivRWwPqyOtcMSssXqPAQjPrmt9tAs6NmYy0OGhzPFC0NuE9TE79fQ Ws4hdXHMTPt9sAnXIRyGxPwgXHyROwWeW8WYE0EpSmpOnNJ52eoOvmQYF8vMmB3694/j LSNg== 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=hZaXl/A5WHiaH2oO+6QLAbQ7TN64I9qcyK7qMK8Xtlg=; fh=uc6F0Ohn3UW1w84uHLY77zlgWj4U4PYcMZ6239x5PoQ=; b=IGbp5dxmD4PxqGWRddAsE6hhsSXbULLOEMw0g5erwELI0VfRpn8BxvNttw1HqX78W8 oUaAOsimInRyARt0PW8HXyoHkZMLFBB87xYwVQkWV1CsnPCMHzyqQuv6Vnv6OT/8fWK1 aQEkuRwJMnoLtWbgTX1kxdV1GoryLlyFRAaQgyBUf0q1McI6N8yUZg3V2kudiLnv3Z4x LZJ7x53U5Og48GxF6+CdX3RM+vKn2YoLJ8EvCOR6giWku6hva3vNdcI1yNBhMa2q/C+L 9XfJv5l4gna+bYM3WXSkjIK+VjFmHUvw6uG2/3AncvPQN6k4A4Gz7f2kigOBB/VOJFTM ZMjg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=MgXuYmXq; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-187574-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-187574-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 af79cd13be357-792cd48798csi582865285a.557.2024.05.23.06.25.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 May 2024 06:25:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-187574-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=MgXuYmXq; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-187574-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-187574-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 BC98B1C217B5 for ; Thu, 23 May 2024 13:25:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5547714B084; Thu, 23 May 2024 13:24:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="MgXuYmXq" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.11]) (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 2072D14AD25 for ; Thu, 23 May 2024 13:24:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.11 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716470685; cv=none; b=LLrJ1JcGc+INSkVrgU0O74JvSz/fk/9O0NOh3ZofCkqcWyiCzao0IFHyulaYcMfR0pXDfDulpBfYfpMAIl0Av/x5FELTyVoY3m3sdogUxDlmV2gcgNP1AhVvVT9dQiIWw7jdffFMg6d8QzMEuK9OJBh7DgwgmdVGQTDvaImwav4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716470685; c=relaxed/simple; bh=/Me5wMpR/UwA1YVs+dIUucOW/F8h8aXT6I9AFyhY514=; h=Message-ID:Date:MIME-Version:Cc:Subject:To:References:From: In-Reply-To:Content-Type; b=AZ1ZStl1TefnVTDgEdW326VecK8CkniN6qU0/Y9OnlUzLoZptvnfVWSxRIq7C3KRMxMClYn68OUIDfexrbgIhegwr0BRNMw80MLjcrX6hSIcX0b1GlY5bs/59FnsTyrIGe75l5q3pHPq3wZu9J8lBQPvYoWiZH7c5/Q+MNvoNmE= 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=MgXuYmXq; arc=none smtp.client-ip=192.198.163.11 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=1716470683; x=1748006683; h=message-id:date:mime-version:cc:subject:to:references: from:in-reply-to:content-transfer-encoding; bh=/Me5wMpR/UwA1YVs+dIUucOW/F8h8aXT6I9AFyhY514=; b=MgXuYmXqU8zjF3Q4/NDELQzqrmzPFGiF0Po+RNNNqd81W81qjtXAI0bc 5bKmCl3TWukOkVEZFEGvy/kaTSfhpv8ciDaoVYw2RhHJDhDkak7PVRDIO GZdihTYiUB+sVIbKep02q3ukW6KziU9zNNnPcSIHNkOR1BHECS32JMLry w/mUxVS3w6bllg95c2umRizzRSvB51fIYcoh3W614ueSUb5CNOWfn/tr9 UfroUVldw6iZuHneLFHg5GsIc15iB6KAPGFiaZgAnNQ80kpTlYEBqA5x7 2z8p7xQuNYIEB1JBBO72gmhCM019DOgXapILXuTmTaFdtArfwbJwkmcaj w==; X-CSE-ConnectionGUID: X/DzJtNeTjm1v4LEwL3AuQ== X-CSE-MsgGUID: 8CSdqm+IQjSL5S2zZ+MDLA== X-IronPort-AV: E=McAfee;i="6600,9927,11081"; a="23397304" X-IronPort-AV: E=Sophos;i="6.08,182,1712646000"; d="scan'208";a="23397304" Received: from fmviesa002.fm.intel.com ([10.60.135.142]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 May 2024 06:24:43 -0700 X-CSE-ConnectionGUID: K1Q2J8ZtSjmfR1VKNQcxgA== X-CSE-MsgGUID: pSlsOeNWRbq/lZqw/acuUg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,182,1712646000"; d="scan'208";a="56899634" Received: from blu2-mobl.ccr.corp.intel.com (HELO [10.125.248.220]) ([10.125.248.220]) by fmviesa002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 May 2024 06:24:39 -0700 Message-ID: Date: Thu, 23 May 2024 21:24:36 +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, 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 , iommu@lists.linux.dev, linux-kernel@vger.kernel.org References: <20240522082729.971123-1-ubizjak@gmail.com> <20240522082729.971123-2-ubizjak@gmail.com> Content-Language: en-US From: Baolu Lu In-Reply-To: <20240522082729.971123-2-ubizjak@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 2024/5/22 16:26, Uros Bizjak wrote: > Use try_cmpxchg64() instead of cmpxchg64 (*ptr, old, new) != old in > intel_pasid_get_entry(). cmpxchg returns success in ZF flag, so > this change saves a compare after cmpxchg (and related move > instruction in front of cmpxchg). > > Signed-off-by: Uros Bizjak > Cc: David Woodhouse > Cc: Lu Baolu > Cc: Joerg Roedel > Cc: Will Deacon > Cc: Robin Murphy > --- > drivers/iommu/intel/pasid.c | 7 +++++-- > 1 file changed, 5 insertions(+), 2 deletions(-) > > diff --git a/drivers/iommu/intel/pasid.c b/drivers/iommu/intel/pasid.c > index abce19e2ad6f..9bf45bc4b967 100644 > --- a/drivers/iommu/intel/pasid.c > +++ b/drivers/iommu/intel/pasid.c > @@ -146,6 +146,8 @@ static struct pasid_entry *intel_pasid_get_entry(struct device *dev, u32 pasid) > retry: > entries = get_pasid_table_from_pde(&dir[dir_index]); > if (!entries) { > + u64 tmp; > + > entries = iommu_alloc_page_node(info->iommu->node, GFP_ATOMIC); > if (!entries) > return NULL; > @@ -156,8 +158,9 @@ static struct pasid_entry *intel_pasid_get_entry(struct device *dev, u32 pasid) > * clear. However, this entry might be populated by others > * while we are preparing it. Use theirs with a retry. > */ > - if (cmpxchg64(&dir[dir_index].val, 0ULL, > - (u64)virt_to_phys(entries) | PASID_PTE_PRESENT)) { > + tmp = 0ULL; nit: can this simply be tmp = 0; ? > + 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 if (try_cmpxchg64(&dir[dir_index].val, &tmp, (u64)virt_to_phys(entries) | PASID_PTE_PRESENT)) { > iommu_free_page(entries); > goto retry; > } Best regards, baolu