Received: by 2002:ab2:7855:0:b0:1f9:5764:f03e with SMTP id m21csp196591lqp; Wed, 22 May 2024 01:27:43 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVTZ04skSBxxxUyHv7nQRHIhTG2pxBVqeh9NjCtz69z3NLijXIV7naTwhwHJoKcTuZbfg5BTDsoG9cbYsbqCUYNZr+XlevJtSKAS+kFkw== X-Google-Smtp-Source: AGHT+IE9f5eZjCfPfbvkuh4DvNTWmDqc+pxxcb9fEOf6sxggeIrI0n2CIKopj9J5iTMj7akugTOv X-Received: by 2002:a05:6359:2d93:b0:196:c46b:de62 with SMTP id e5c5f4694b2df-19791f23174mr90571955d.18.1716366462782; Wed, 22 May 2024 01:27:42 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716366462; cv=pass; d=google.com; s=arc-20160816; b=B88PrZGWlpE+j2V5vE/U3PC6go35+QEcqvMFgHh4By8jMSR9KO9aGznaJ6aV03X/GO UubarqiN62z+v8jhjbOS0l/hhSUkaDq65ct2VQkQY3PyBBeXEYG1E42ZUIOs0AfKVmwD /VboxYRjZfVzEmee/6ROn8CR4CLW0+tgskJXJf7t7MZq+3Y6NYmxoljBDR3v1FH4IBos sKLQtnzgXE+0X1g7JTUQAoZXz5mCvOiqz/CM8Qv7u8TgC6bRUWQ32RvuJXpH8ZzrlBpw G2DK3FLFMu2WFilwbTAW8fLyvEIU7ETDxiIhTU8dNeOAEY3vjbf54qy7BvpFhkEY9Rt/ EfIA== 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:message-id:date:subject:cc:to :from:dkim-signature; bh=OIn2hFlLwHZLk8/r/RwHC6tgKkycOicAcOyv0sMfHLA=; fh=N/TaDAXNm9Og9gYpb3XphMxZCMD4Q9knHI0IGJv9shg=; b=ANpLA7to/3xs8XLO7Q5cFM70MDE4ZARA5HEXCVlSSXVnqYGaeUnJIvT13LkBs5Cut6 eji1fDxqC7WQ6pvuDZBQrY9y2QIZ1GP8JJABMSBWf3D9g5PRQalHcDY8Vnym3YSDZ6HR Q43Y71pO8M/VRTBn+6cy4fMwPMTFT3KxqfNgMVwGjJRP2cE5yxXSp1cdjFhhe8EztGLL 0fpV6rgq3Fhw2atmta7LcLhlBtKVrCIgYCEn01eAtYud7vndJT2aZZKRN5eLx5oeR02S SXz/7Zdmgtc+4uMQPMaXFr6C5hzDYkSo7UhDdH0XfQnc0iIvqCKFwKcW51rtJlutl6xC yX0Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="fwcxVZ/M"; 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-185922-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-185922-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 41be03b00d2f7-64de7499816si15003643a12.610.2024.05.22.01.27.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 May 2024 01:27:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-185922-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="fwcxVZ/M"; 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-185922-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-185922-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 1AB91281916 for ; Wed, 22 May 2024 08:27:42 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B2CB07FBBD; Wed, 22 May 2024 08:27:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fwcxVZ/M" Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.46]) (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 5E1457710B for ; Wed, 22 May 2024 08:27:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.46 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716366455; cv=none; b=IgmJR+JvnDDwnrY5Y/thNdrUuUPpj+r7ItgzaLysP1+KeNpQtjA2wQmRvhSd5134QBVaIG4NkHz28sXOyPanJlndRfOeYos3+4kAHZJFJxR5w5f14RR+G+iln5eKFVWer6Cpg3uIwd7X/i7Fcvac4BaRP8Ga9HdtwKPEZdcZek8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716366455; c=relaxed/simple; bh=OmtWAKQ6saASpj2ARv+RA8pwd2Z/VtPuUOeaHHH/InA=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=M62SAywPlQIESQdAZDeklMkd/Jk8zFVAFBzeyP2D2gOYvsxZY8TifhioMr+7C42XEb+5P8qpuOQKwQb1uwKz9PQ5Iwaw7Yaup+fR/ecFdxpUERkbuSwLcbK+2lVPqI7lWh3YeLmFDDZO1wsbkqKskuv9OEIY+bmmqQrnBCXCd5k= 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=fwcxVZ/M; arc=none smtp.client-ip=209.85.221.46 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-wr1-f46.google.com with SMTP id ffacd0b85a97d-350513d2c6aso3532713f8f.2 for ; Wed, 22 May 2024 01:27:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716366453; x=1716971253; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=OIn2hFlLwHZLk8/r/RwHC6tgKkycOicAcOyv0sMfHLA=; b=fwcxVZ/MXHkIfXqEb85f6+vB5kHpp5tFyZcb9KK+kDrNKn+YZC0ye0W9q0zOfVuvMD JascecsnzflJOraeSe9tSS5EYIGFflAVVEMKZtxbzPHyRMVPoflVmO/kEGBCOf2oD+Sb 2axtbkjSYcLKpbwo4Zp0Ze7e0EbP+aFtChyqGUh35DNRpYYKwZTF6UbORrYp2qlWlUb+ NH8gHVzk9UM5NtgZJAkdE3lpk6u8ah3AzMxYIB/vwXsup3e6mSKFioQBieY/1CpG/1vm BEKDXIiL6msExwva+xjKWOCsjg219dYvzxBpTwoSCStEdrP4BlkMxku+NPqZooK8LQsN Us8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716366453; x=1716971253; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=OIn2hFlLwHZLk8/r/RwHC6tgKkycOicAcOyv0sMfHLA=; b=mhvotzUJBd8SZVSkM2Q8WX5fenuZKg0CRT6IiC6T2jb+aR4rsYd9DspvkwL6EWVLw/ g09ATastQrCW5yKQ4lWTERCdTuijV/HDNmzTgjIE4znVHFxx7GQwL9zcEjcLbiCL5A1P HXqbHshZOAouZdMe3PcpLZyc+qKTvOxfHdB9uSzBM3cmKiZfzF9vnwvbC/LLVlOVeblB ywVbjoPoPrlty5/g1dk/kjCFhiTWreie2vrvEJFVicWs1F1Xpu31qSJ7lfO8yb3TL1CX mToUSPLIAnCOfyESWfjAGUrVeGQe5LvbdPISV40ss77rx1lW6/KVFoNreHw+JDs94les mpgg== X-Forwarded-Encrypted: i=1; AJvYcCU/ca6bN/bTcKn6GjGEnuNlLEjgLDuBquQ6WbQsjjxC5gB6SXXz7VJZXgozkuKNH06sqs/PHeAApMFQpLfhnRAC5xuovXXm7xi51018 X-Gm-Message-State: AOJu0YwD8oLisyUQptbpT8LshGcdPQ5NlIc9kilDFMw8G6tu5FBWivmc eoyGKvcHDhifdQUbz2LcDcgH/E+nzSgluu8I/Zx0hxcJDS9efS3e X-Received: by 2002:a05:6000:2810:b0:354:db7f:a6a8 with SMTP id ffacd0b85a97d-354db7fa7camr699059f8f.55.1716366452466; Wed, 22 May 2024 01:27:32 -0700 (PDT) Received: from fedora.iskraemeco.si (84-255-245-182.static.t-2.net. [84.255.245.182]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3502b79bc0asm33964495f8f.1.2024.05.22.01.27.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 May 2024 01:27:31 -0700 (PDT) From: Uros Bizjak To: iommu@lists.linux.dev, linux-kernel@vger.kernel.org Cc: Uros Bizjak , Joerg Roedel , Suravee Suthikulpanit , Will Deacon , Robin Murphy Subject: [PATCH 1/3] iommu/amd: Use try_cmpxchg64() in v2_alloc_pte() Date: Wed, 22 May 2024 10:26:47 +0200 Message-ID: <20240522082729.971123-1-ubizjak@gmail.com> X-Mailer: git-send-email 2.45.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Use try_cmpxchg64() instead of cmpxchg64 (*ptr, old, new) != old in v2_alloc_pte(). cmpxchg returns success in ZF flag, so this change saves a compare after cmpxchg (and related move instruction in front of cmpxchg). This is the same improvement as implemented for alloc_pte() in: commit 0d10fe759117 ("iommu/amd: Use try_cmpxchg64 in alloc_pte and free_clear_pte") Signed-off-by: Uros Bizjak Cc: Joerg Roedel Cc: Suravee Suthikulpanit Cc: Will Deacon Cc: Robin Murphy --- drivers/iommu/amd/io_pgtable_v2.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/iommu/amd/io_pgtable_v2.c b/drivers/iommu/amd/io_pgtable_v2.c index 78ac37c5ccc1..664e91c88748 100644 --- a/drivers/iommu/amd/io_pgtable_v2.c +++ b/drivers/iommu/amd/io_pgtable_v2.c @@ -158,7 +158,7 @@ static u64 *v2_alloc_pte(int nid, u64 *pgd, unsigned long iova, __npte = set_pgtable_attr(page); /* pte could have been changed somewhere. */ - if (cmpxchg64(pte, __pte, __npte) != __pte) + if (!try_cmpxchg64(pte, &__pte, __npte)) iommu_free_page(page); else if (IOMMU_PTE_PRESENT(__pte)) *updated = true; -- 2.45.1