From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.208.198 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796137315; b=QP4SlBHzGBXoJLiwO3ulcQZqqdJuhqLCgR+N1LlQNPuZ+1eTZNsuSV+gLaDYuZxwlkyo khxQwsAFsWIYnYB9aGhStZpjFUqVtYdOnLzAhv+f286JmqPWQoCs4YAC41PN+6oFxhq7J aOZ/gRaD83NMKJXNP/Mwi/5TpCG/fv8XiHtRymiO9QY8lxGxFot9Z6yAQ3yFBSiMTXQ5J aa834nHHru4jw8CqDPP98kBhF8LO8L/kVMJeLKvJPDW5pwqThUNoeHXB32E0qQc4DdSXF uWiR9bN9vWoq2PmFFL6CQu/gWsdRywGyWQatxjAyV1X6OZSvurxnLxKHLjmOeBgVXgg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796137315; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:In-Reply-To: Mime-Version:References:X-Mailer:Message-ID:Subject:From:To:Cc: Content-Type:Content-Transfer-Encoding; bh=Zv65PsLuVay/r5+HAgw7mX5CNnYXOE2oU2BuiwY3sJQ=; b=HUD5u7gCg23EINgtjSw6r/9ljvLuzDVOcHGPDIN9v5+V+kC3WtEnCxSnUFHFjFaxCfXR SMRNwkFTu7s3h6vCGfN6Uj8RASoK9AF/J3r5m/N6Wf+5itHONuFHECSFQLmxc+33XGuqh rt3/yytGa96avc+BHNzSlaNFr4pqNP+hlsgWsz+8gISGa4/slZTFve3EGZJ9vhJzIL8Pu 7dXSr4EUtMhL9utrygPK4ccBnRMm5CGlkPP/ryWsGBZYvDaVwKmUfLO+B+hoQcfAnJfQP 3k6BCYAA0Z4t8wLSyauTeH9cEoJfMS8+10oOPohou/2ZS7c3Yo4hsx+W5sclc+YxbZA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--ptosi.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=HyYCjRsZ; arc=none smtp.remote-ip=209.85.208.198 Received: from mail-lj1-f198.google.com (mail-lj1-f198.google.com [209.85.208.198]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F3285606A689 for ; Tue, 1 Dec 2026 15:01:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org F3285606A689 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ptosi.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=HyYCjRsZ Received: by mail-lj1-f198.google.com with SMTP id 38308e7fff4ca-3ab36a71c66so43408231fa.1 for ; Tue, 01 Dec 2026 07:01:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796137313; x=1796742113; darn=vger.kernel.org; h=content-transfer-encoding:content-type:cc:to:from:subject :message-id:references:mime-version:in-reply-to:date:from:to:cc :subject:date:message-id:reply-to:content-type; bh=Zv65PsLuVay/r5+HAgw7mX5CNnYXOE2oU2BuiwY3sJQ=; b=HyYCjRsZ9Mak0bkM7Ra3QugywZ/qbYRZRdynVdJ7/dLW1QXp/eIV5cR9Kdp4QHhap4 TAVOxZrij/cP0Ptskmj19Av/yjT0xl10mEDOgjnj1VKFohOq7/Rd7A9Q/5kjoBuc8R3J HX6geINmIpgmZ09znj0ibjjCDCRHGeKoRir8GnIT7CsxcY6oW+j+it6gTsAug4dtWoy3 lTYeUt7Xph+rVEKS7WRT2toHpQ8UVXt0KbfZUZrY+jAE44ZedohPDgKV8ilN8lOm2ASU AJMda3DUPqtiiPrWO2AHcgRbpOQcB6tgv6MIjghNjpRFmaMk0jPlPHTqSFTjR/7/ZSJ1 65VA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796137313; x=1796742113; h=content-transfer-encoding:content-type:cc:to:from:subject :message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=Zv65PsLuVay/r5+HAgw7mX5CNnYXOE2oU2BuiwY3sJQ=; b=US7qW+LnRx++z+m9AKjAP/jQD70xCNT/qo89IytEy1Ht+A/YZ1TrOLDDjRljw+mPiJ s7nO8PKXtr2niIh8IXhFXtqtM3jZ+6yvrtmWGct9V2GPT7Nwfp3d+IetR2DR+3VtP8km CPfQnA9XhIA2kIskt9tpjm/INbsMOWHy3SFu8c3HJlWaVHctO0AI1iWvX/GP5J4DRTDC 1N79RXIblYBkKMtVdK0ameIOvugJ26nw+MiSgCgsB6xJAogEwjMFwkG2Yoh0dZnLBeqs IMslr6C4h8ScdMo0UCEJlYniTw6BbXTcYPy5bl4Ym9Q+Yv3MKFxdzFCFmfDR6C08NgVu EiVQ== X-Forwarded-Encrypted: i=1; AL+hErGReYrGQhe3ZIQJXdqDHBIsJyz56JafHk8SAYSVje/BIHERsho7Ax+H5D7Pt7s+yfZdUkWDT7PrFPrOxPY=@vger.kernel.org X-Gm-Message-State: APuU4Z+akBG/LHL/vpIa2d5SJLEfhNoYGBSR+NPU7qQT+cibRvHypWCK tB9eB3fbfmhSZFhawwqQ0hq/MQEJep3yd0i90oG217f/qGJE3ivDNrX6+YPnzQ/f5drQ4o0D3fG sYQ== X-Received: from ejbq22.prod.google.com ([2002:a17:906:3616:b0:c31:98e2:b157]) (user=ptosi job=prod-delivery.src-stubby-dispatcher) by 2002:a17:906:c113:b0:c46:7645:861 with SMTP id a640c23a62f3a-c513a3a7228mr3024816366b.7.1796137294075; Tue, 01 Dec 2026 07:01:34 -0800 (PST) Date: Tue, 01 Dec 2026 16:00:55 +0100 In-Reply-To: <20261201-mte-page-optim-v1-0-322b9e4096c7@google.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 References: <20261201-mte-page-optim-v1-0-322b9e4096c7@google.com> X-Mailer: b4 0.14.3 Message-ID: <20261201-mte-page-optim-v1-4-322b9e4096c7@google.com> Subject: [PATCH 4/5] arm64: cpufeature: Add cpucap for DCZID_EL0.DZP From: "=?utf-8?q?Pierre-Cl=C3=A9ment_Tosi?=" To: Catalin Marinas , Will Deacon Cc: Mark Rutland , Ryan Roberts , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, "=?utf-8?q?Pierre-Cl=C3=A9ment_Tosi?=" , Marc Zyngier Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Enable the use of static branches on a system-wide CPU capability matching a (sanitized) DCZID_EL0.DZP by introducing ARM64_HAS_DC_ZVA. Note that the architecture does not guarantee this field to be constant (EL2 can alter it for EL1, and EL1 for EL0) but it seems impossible to me to have a well-behaved system using DZP-dependent instructions under conditions where the bit flips dynamically as the check MRS DCZID_EL0 followed by DC *VA is inherently TOCTOU-prone. If EL2 lets Linux boot with DZP=3D0 and then decides to set it, it must emulate the instructions. Also note that the polarity of the capability means that instructions patched with this cpucap default to an always-valid fallback e.g. STZGM instead of DC GZVA. Similarly, heterogeneous systems with differing DZP values get sanitized to not having the capability. Cc: Marc Zyngier Signed-off-by: Pierre-Cl=C3=A9ment Tosi --- arch/arm64/kernel/cpufeature.c | 14 ++++++++++++++ arch/arm64/tools/cpucaps | 1 + 2 files changed, 15 insertions(+) diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.= c index e817d49037a6..09302f5ebc91 100644 --- a/arch/arm64/kernel/cpufeature.c +++ b/arch/arm64/kernel/cpufeature.c @@ -2424,6 +2424,13 @@ test_has_gicv5_legacy(const struct arm64_cpu_capabil= ities *entry, int scope) return !!(read_sysreg_s(SYS_ICC_IDR0_EL1) & ICC_IDR0_EL1_GCIE_LEGACY); } =20 +static bool has_dc_zva(const struct arm64_cpu_capabilities *entry, int sco= pe) +{ + u64 dczid =3D read_scoped_sysreg(entry, scope); + + return !SYS_FIELD_GET(DCZID_EL0, DZP, dczid); +} + static const struct arm64_cpu_capabilities arm64_features[] =3D { { .capability =3D ARM64_ALWAYS_BOOT, @@ -2619,6 +2626,13 @@ static const struct arm64_cpu_capabilities arm64_fea= tures[] =3D { ARM64_CPUID_FIELDS(ID_AA64PFR0_EL1, AMU, IMP) }, #endif /* CONFIG_ARM64_AMU_EXTN */ + { + .desc =3D "Data cache zero by VA permitted (DCZID_EL0.DZP =3D=3D 0)", + .capability =3D ARM64_HAS_DC_ZVA, + .type =3D ARM64_CPUCAP_SYSTEM_FEATURE, + .sys_reg =3D SYS_DCZID_EL0, + .matches =3D has_dc_zva, + }, { .desc =3D "Data cache clean to the PoU not required for I/D coherence", .capability =3D ARM64_HAS_CACHE_IDC, diff --git a/arch/arm64/tools/cpucaps b/arch/arm64/tools/cpucaps index 51f5683374b0..283cc1c8fbe6 100644 --- a/arch/arm64/tools/cpucaps +++ b/arch/arm64/tools/cpucaps @@ -21,6 +21,7 @@ HAS_CNP HAS_CRC32 HAS_DCPODP HAS_DCPOP +HAS_DC_ZVA HAS_DIT HAS_E0PD HAS_ECV --=20 2.56.1.839.g22a8290db9-goog