From nobody Mon Feb 9 20:30:11 2026 Received: from mail-ej1-f44.google.com (mail-ej1-f44.google.com [209.85.218.44]) (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 987693191C2 for ; Sat, 27 Dec 2025 17:57:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766858264; cv=none; b=b8B65sGk+B1IzU7PK0BieFSa5HedFQQOlegg/+i0Wc489HP1x60kGhq8eOCGaDxAdLMUoco0Exaan6UjZcO8Hy58wfBkPKbJjcV/qPsYjBGK+fSih0H1pA8yWJVsb1OxxJT3AD0udgdu+PsGUlXJ+sCumrhR5W4x+e7ObrhJSyg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766858264; c=relaxed/simple; bh=L2cWEnsnmqmCQzCnbYA8nIWFQ0fDcP2mowaYRIAu7wg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=no3SRtfzFIIUahO/rTZ91PRp6RoEFXggBJZ5jWRhAt03ZhEMjWDl9oDodITEuY1AMc8l5cy9duFZz79lxzTIxuPA6muPRApU+p6Vq8NBDsTkj4RY4oeVoeIygQEPTyvOynvcsLJ+JmTGcwe2BgAeacDOrKwBC+/+JY3Hwiw4nWo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=Rwdz/YS3; arc=none smtp.client-ip=209.85.218.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="Rwdz/YS3" Received: by mail-ej1-f44.google.com with SMTP id a640c23a62f3a-b8018eba13cso1182290766b.1 for ; Sat, 27 Dec 2025 09:57:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1766858261; x=1767463061; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=by93Ld+GfKq9Xqr4JG5suCzUM+FwELjVjEj4XbD8EvU=; b=Rwdz/YS3+wYJeJkmT66kLa0zqkMapLO7G9bXL0F1D9Qbt17uAbzZAnjubsCb4q1/Zv wBfl242Ch41A2CStu8S68Zxov/CR7SxRpPClhMOvLS99wlq/Vbonfk/odp1SwQ5ILre6 t3URZrasRa76oRz0QaAWUriAjSJJoWkaye7Ng= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766858261; x=1767463061; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=by93Ld+GfKq9Xqr4JG5suCzUM+FwELjVjEj4XbD8EvU=; b=T4frVUwn9hM9R053xOOA7a2ggClegw0NF1Ny8B6o+HmRo/bhPawfGkQUObw9eXCwiS SS+3g+0QPfOvR8jATlEf14Tfh+iugDCz5dfUTPScQbL6VWJFFg2XSc60l75ohOUwocxs 815Pc4reywCtrfITHSNCnS9sp1iX6qk0OWGmkJvx/t5kmNqmvYYUrRYd0Z8UcriW1Hne KZ2jiokgv7+etYCTUdU3aX0ifI94rxgP4hAcnBykthVWb3z1Nuwzu7mBfcLKr7Dlkjp6 +AQMKtwlO/MsL+aB+5IiSOfCz1YDV6vO2wJYu3tcKOTyypcZeNPZ3o81wLHmyGgtO9ym rcDg== X-Forwarded-Encrypted: i=1; AJvYcCXigskwZY8r25M9p8DHIj6VJFWRUfEoGiX/ZPIr8YcXbnBwiJNqk+XYei2gAz+fTT3xNSCdfrOXC23phcY=@vger.kernel.org X-Gm-Message-State: AOJu0Yx0725fjiAhs8atwkSKIxJa/NEiIz+vf4EG9nqQU9Kr1hztk02m My4ARyufyOl4sGx6OvsIHnk3JlOcF/9SA6nGOYziew1zWLKlyX2JbF6YxWl/4koLkg== X-Gm-Gg: AY/fxX7FVMzAnvxcW2f27NfGROQ0JNSDA/w3ZMrwGMNE/evpEc8cfEG6YiIYNU1RYyk v6tBhdxK9HqxMzlk4CpoKHFcsuBq93ctCfZaU9vumHYhhdC3Fl14KtvstvFJFw8Tj/ZojCcXvlg 2svrk/jIlVIiN1ur775FXH+7A/HKmKvK1lrnSAV8a07nQUrMMJV9RcigrCbkx40RpuRECMV4GjO eavZVXItS2jKh1VNziqff42/8cbbhLWYvaduDT/TFIiDVnRYET2JB+tqZvh6ztTeXPdx3QAuLGK ATzqeBrFJjY8voYJOHb524RRld7eNAr3CMIUGwOKorv3+FJGpQ7PBuAPPgSQfrk7ds70UmMMbim aMbXL9+mT7fPeqLh4YyCKowFVz5+hvDJ7Cj6wPQ37gpOMxdTH6KdwxXZOqDRghRIOBTt+N4ojdj lZidWFrHpkJ+tjEQiPlCq32BICR8a4HA== X-Google-Smtp-Source: AGHT+IFmzdtl5jfVaKvWxxK43j+CYwbmf9H50vWu1IS0KH+i9ok4izITqTpUSDgTiAKLwwYd3TnYcg== X-Received: by 2002:a17:907:7e82:b0:b79:ff94:50ff with SMTP id a640c23a62f3a-b8037178545mr2698889366b.34.1766858260857; Sat, 27 Dec 2025 09:57:40 -0800 (PST) Received: from localhost.localdomain ([2a02:a31b:20c3:6680:3d12:d2ea:4ee0:347a]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b8037de1421sm2793889166b.41.2025.12.27.09.57.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 27 Dec 2025 09:57:40 -0800 (PST) From: Dmytro Maluka To: David Woodhouse , Lu Baolu , iommu@lists.linux.dev Cc: Joerg Roedel , Will Deacon , Robin Murphy , linux-kernel@vger.kernel.org, "Vineeth Pillai (Google)" , Aashish Sharma , Grzegorz Jaszczyk , Chuanxiao Dong , Kevin Tian , Dmytro Maluka Subject: [PATCH v2 2/5] iommu/vt-d: Generalize pasid_set_bits() Date: Sat, 27 Dec 2025 18:57:25 +0100 Message-ID: <20251227175728.4358-3-dmaluka@chromium.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20251227175728.4358-1-dmaluka@chromium.org> References: <20251227175728.4358-1-dmaluka@chromium.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" To prepare for reusing the pasid_set_bits() for context entries as well, rename it to entry_set_bits() and move its definition to iommu.h. Signed-off-by: Dmytro Maluka --- drivers/iommu/intel/iommu.h | 9 ++++++++ drivers/iommu/intel/pasid.h | 42 +++++++++++++++---------------------- 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/drivers/iommu/intel/iommu.h b/drivers/iommu/intel/iommu.h index 25c5e22096d4..2fab7ff4b932 100644 --- a/drivers/iommu/intel/iommu.h +++ b/drivers/iommu/intel/iommu.h @@ -897,6 +897,15 @@ static inline int pfn_level_offset(u64 pfn, int level) return (pfn >> level_to_offset_bits(level)) & LEVEL_MASK; } =20 +static inline void entry_set_bits(u64 *ptr, u64 mask, u64 bits) +{ + u64 old; + + WARN_ON_ONCE(bits & ~mask); + + old =3D READ_ONCE(*ptr); + WRITE_ONCE(*ptr, (old & ~mask) | (bits & mask)); +} =20 static inline void context_set_present(struct context_entry *context) { diff --git a/drivers/iommu/intel/pasid.h b/drivers/iommu/intel/pasid.h index 39acd3efa3ab..f8fc73676192 100644 --- a/drivers/iommu/intel/pasid.h +++ b/drivers/iommu/intel/pasid.h @@ -10,6 +10,8 @@ #ifndef __INTEL_PASID_H #define __INTEL_PASID_H =20 +#include "iommu.h" + #define PASID_MAX 0x100000 #define PASID_PTE_MASK 0x3F #define PASID_PTE_PRESENT 1 @@ -109,16 +111,6 @@ static inline void pasid_clear_entry_with_fpd(struct p= asid_entry *pe) WRITE_ONCE(pe->val[7], 0); } =20 -static inline void pasid_set_bits(u64 *ptr, u64 mask, u64 bits) -{ - u64 old; - - WARN_ON_ONCE(bits & ~mask); - - old =3D READ_ONCE(*ptr); - WRITE_ONCE(*ptr, (old & ~mask) | (bits & mask)); -} - static inline u64 pasid_get_bits(u64 *ptr) { return READ_ONCE(*ptr); @@ -131,7 +123,7 @@ static inline u64 pasid_get_bits(u64 *ptr) static inline void pasid_set_domain_id(struct pasid_entry *pe, u64 value) { - pasid_set_bits(&pe->val[1], GENMASK_ULL(15, 0), value); + entry_set_bits(&pe->val[1], GENMASK_ULL(15, 0), value); } =20 /* @@ -150,7 +142,7 @@ pasid_get_domain_id(struct pasid_entry *pe) static inline void pasid_set_slptr(struct pasid_entry *pe, u64 value) { - pasid_set_bits(&pe->val[0], VTD_PAGE_MASK, value); + entry_set_bits(&pe->val[0], VTD_PAGE_MASK, value); } =20 /* @@ -160,7 +152,7 @@ pasid_set_slptr(struct pasid_entry *pe, u64 value) static inline void pasid_set_address_width(struct pasid_entry *pe, u64 value) { - pasid_set_bits(&pe->val[0], GENMASK_ULL(4, 2), value << 2); + entry_set_bits(&pe->val[0], GENMASK_ULL(4, 2), value << 2); } =20 /* @@ -170,7 +162,7 @@ pasid_set_address_width(struct pasid_entry *pe, u64 val= ue) static inline void pasid_set_translation_type(struct pasid_entry *pe, u64 value) { - pasid_set_bits(&pe->val[0], GENMASK_ULL(8, 6), value << 6); + entry_set_bits(&pe->val[0], GENMASK_ULL(8, 6), value << 6); } =20 /* @@ -179,7 +171,7 @@ pasid_set_translation_type(struct pasid_entry *pe, u64 = value) */ static inline void pasid_set_fault_enable(struct pasid_entry *pe) { - pasid_set_bits(&pe->val[0], 1 << 1, 0); + entry_set_bits(&pe->val[0], 1 << 1, 0); } =20 /* @@ -189,7 +181,7 @@ static inline void pasid_set_fault_enable(struct pasid_= entry *pe) */ static inline void pasid_set_ssade(struct pasid_entry *pe) { - pasid_set_bits(&pe->val[0], 1 << 9, 1 << 9); + entry_set_bits(&pe->val[0], 1 << 9, 1 << 9); } =20 /* @@ -199,7 +191,7 @@ static inline void pasid_set_ssade(struct pasid_entry *= pe) */ static inline void pasid_clear_ssade(struct pasid_entry *pe) { - pasid_set_bits(&pe->val[0], 1 << 9, 0); + entry_set_bits(&pe->val[0], 1 << 9, 0); } =20 /* @@ -218,7 +210,7 @@ static inline bool pasid_get_ssade(struct pasid_entry *= pe) */ static inline void pasid_set_sre(struct pasid_entry *pe) { - pasid_set_bits(&pe->val[2], 1 << 0, 1); + entry_set_bits(&pe->val[2], 1 << 0, 1); } =20 /* @@ -227,7 +219,7 @@ static inline void pasid_set_sre(struct pasid_entry *pe) */ static inline void pasid_set_wpe(struct pasid_entry *pe) { - pasid_set_bits(&pe->val[2], 1 << 4, 1 << 4); + entry_set_bits(&pe->val[2], 1 << 4, 1 << 4); } =20 /* @@ -236,7 +228,7 @@ static inline void pasid_set_wpe(struct pasid_entry *pe) */ static inline void pasid_set_present(struct pasid_entry *pe) { - pasid_set_bits(&pe->val[0], 1 << 0, 1); + entry_set_bits(&pe->val[0], 1 << 0, 1); } =20 /* @@ -245,7 +237,7 @@ static inline void pasid_set_present(struct pasid_entry= *pe) */ static inline void pasid_set_page_snoop(struct pasid_entry *pe, bool value) { - pasid_set_bits(&pe->val[1], 1 << 23, value << 23); + entry_set_bits(&pe->val[1], 1 << 23, value << 23); } =20 /* @@ -255,7 +247,7 @@ static inline void pasid_set_page_snoop(struct pasid_en= try *pe, bool value) static inline void pasid_set_pgsnp(struct pasid_entry *pe) { - pasid_set_bits(&pe->val[1], 1ULL << 24, 1ULL << 24); + entry_set_bits(&pe->val[1], 1ULL << 24, 1ULL << 24); } =20 /* @@ -265,7 +257,7 @@ pasid_set_pgsnp(struct pasid_entry *pe) static inline void pasid_set_flptr(struct pasid_entry *pe, u64 value) { - pasid_set_bits(&pe->val[2], VTD_PAGE_MASK, value); + entry_set_bits(&pe->val[2], VTD_PAGE_MASK, value); } =20 /* @@ -275,7 +267,7 @@ pasid_set_flptr(struct pasid_entry *pe, u64 value) static inline void pasid_set_flpm(struct pasid_entry *pe, u64 value) { - pasid_set_bits(&pe->val[2], GENMASK_ULL(3, 2), value << 2); + entry_set_bits(&pe->val[2], GENMASK_ULL(3, 2), value << 2); } =20 /* @@ -284,7 +276,7 @@ pasid_set_flpm(struct pasid_entry *pe, u64 value) */ static inline void pasid_set_eafe(struct pasid_entry *pe) { - pasid_set_bits(&pe->val[2], 1 << 7, 1 << 7); + entry_set_bits(&pe->val[2], 1 << 7, 1 << 7); } =20 extern unsigned int intel_pasid_max_id; --=20 2.47.3