From nobody Tue Apr 7 04:21:19 2026 Received: from mail-wm1-f74.google.com (mail-wm1-f74.google.com [209.85.128.74]) (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 A26A133859C for ; Mon, 16 Mar 2026 17:35:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773682531; cv=none; b=arqZWH1GvYUsxQ5zSesDKWzbyqL28Qn99rREvcCNsXUfITxti1bAU0hHfzsTDsT/kztdtZX4CoVspOjClpZ1hlGeHEu2HKjVX3uGGc6MeHZcGQ1IjSvK3CUm5qzNGsObvdgyIkdzcDrFSTq4q6PxD1VLJKLkNIsBQxh58pJXSrA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773682531; c=relaxed/simple; bh=AALkJl92/GpB0vDXcTqf/Xhr5ubXN5L/mRxqftaIeJI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=tIznjr9cjgrnnwRGvD9dnqCS0EnG5sDrgMeardokl+amj9jQ3A79xQUiT0Z6wvb6RzG3l+iUdLUJWnEU5osadEr9Zg7OOKqdoWoE3wYmxFgtktbXNr/1Q1BAjeX1Kkxyflx4HF8MHR+a5yBUTLqgB1EfaLzfivO8TzniPDZfYPs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--tabba.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=nNB57eJR; arc=none smtp.client-ip=209.85.128.74 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--tabba.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="nNB57eJR" Received: by mail-wm1-f74.google.com with SMTP id 5b1f17b1804b1-485390246c8so40738765e9.0 for ; Mon, 16 Mar 2026 10:35:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1773682529; x=1774287329; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=DrkEb2n12YyrcySqlJ1Endt4MHN6ko+q0The82lLn1s=; b=nNB57eJRNHOM2ZV7boIZI1BNOyP176SjbM/CTZX8L24H9MiNjLzwC5wx9lyWqgs6Fj 4k4rPvyFyEwBk4IL6BIAqODaPz3XzPQ+OL/JDiUKAh7c1S6EaB5IV+cYT/FCgwh9Gz14 UJ81JNzRUDtcStNzom8k1SKoe5cQfLiBBo7QFAJibGqdLDj0uYlQVXhCw10S3hR3OzOr kCpl7z3tJtDUsXZvtwkkR4RaWJ6pAXbJL6RAorYXFVeBmWtxKf5cJwgS84wsJgaOSs22 C75DFr49I/hkfLg4iysaA3AvNepuICAASeXYWc6ZMx6IOWfo9ZQbxOwbQCVZPXdrMjhB 8C4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773682529; x=1774287329; h=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; bh=DrkEb2n12YyrcySqlJ1Endt4MHN6ko+q0The82lLn1s=; b=hsAcHwpN+45OC+HkQTEci7RLPec3lNQuH9l4yUGCdLpfu1JoJDHhj7LknKIyLrGI0f /hSQtioi4bOoW8LPu3y//SnTcarwsXvmCNXuFS8fFmqpNCo3lJFc7u8WU+hWKkBN2+B0 B+c5bFUSeC3FdRYqXVamdialbP206R1abSSZP0ZgaC0H9gn3aJ5vAzUoIFaqHMIEW9fn BgkEZWSYL9UB4w1qwZ9M1FvJQ4W7TWyfIFmThZ5jGNoITFpnYPdKE/NqORRGI3i+mbIW HYMSfTS/14SqNUQZMUaWoMdKr3aHaxbYuNkHSKZgnn++b3xlf0gcelO9wBR5sQs5xVUY UGPw== X-Forwarded-Encrypted: i=1; AJvYcCVMuXxV/7zekkRs6j1wHegAMzgffjfq30sSWhybUyV1NZNER3eeWaLszOBOfTP+N+SuSYIDGLFbgBkMBVw=@vger.kernel.org X-Gm-Message-State: AOJu0YxbddAvv3KrAK2hGMR6frwrOmqNhgwkIgPthoHDeHscJklK1jE8 EA0G72rNK+drJEG6yVXrcyML+3irBAVf9BqPOm3RI1QHoz8g2SVcPbxghAlICXw5p0z9bEuXtYk IRA== X-Received: from wmno9.prod.google.com ([2002:a05:600c:1649:b0:485:38ca:51c9]) (user=tabba job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:354b:b0:480:2521:4d92 with SMTP id 5b1f17b1804b1-485567071a0mr226576455e9.24.1773682528999; Mon, 16 Mar 2026 10:35:28 -0700 (PDT) Date: Mon, 16 Mar 2026 17:35:22 +0000 In-Reply-To: <20260316-tabba-el2_guard-v1-0-456875a2c6db@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260316-tabba-el2_guard-v1-0-456875a2c6db@google.com> X-Mailer: b4 0.14.3 Message-ID: <20260316-tabba-el2_guard-v1-1-456875a2c6db@google.com> Subject: [PATCH 01/10] KVM: arm64: Add scoped resource management (guard) for hyp_spinlock From: Fuad Tabba To: Marc Zyngier , Oliver Upton , Joey Gouly , Suzuki K Poulose , Zenghui Yu , Catalin Marinas , Will Deacon , "KERNEL VIRTUAL MACHINE FOR ARM64 KVM/arm64" , "KERNEL VIRTUAL MACHINE FOR ARM64 KVM/arm64" , open list Cc: Fuad Tabba Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The Linux kernel recently introduced scoped resource management macros in , enabling RAII-like patterns such as guard() and scoped_guard(). These macros significantly reduce the risk of resource leaks, deadlocks, and messy unwinding paths. The arm64 KVM EL2 hypervisor heavily relies on its own locking primitive, hyp_spinlock_t. Managing these locks carefully across complex failure paths is critical, as missing an unlock at EL2 typically results in a lethal system-wide panic. Add support for the guard(hyp_spinlock) and scoped_guard(hyp_spinlock) macros by including and using the DEFINE_LOCK_GUARD_1 infrastructure in the spinlock header. This paves the way for converting error-prone manual locking into automatic scoped management. Change-Id: Iba6d43c081b5fdf2496dc599fd6a781294493cb9 Signed-off-by: Fuad Tabba --- arch/arm64/kvm/hyp/include/nvhe/spinlock.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/arch/arm64/kvm/hyp/include/nvhe/spinlock.h b/arch/arm64/kvm/hy= p/include/nvhe/spinlock.h index 7c7ea8c55405..2681f8d2fde5 100644 --- a/arch/arm64/kvm/hyp/include/nvhe/spinlock.h +++ b/arch/arm64/kvm/hyp/include/nvhe/spinlock.h @@ -16,6 +16,7 @@ #include #include #include +#include =20 typedef union hyp_spinlock { u32 __val; @@ -98,6 +99,10 @@ static inline void hyp_spin_unlock(hyp_spinlock_t *lock) : "memory"); } =20 +DEFINE_LOCK_GUARD_1(hyp_spinlock, hyp_spinlock_t, + hyp_spin_lock(_T->lock), + hyp_spin_unlock(_T->lock)) + static inline bool hyp_spin_is_locked(hyp_spinlock_t *lock) { hyp_spinlock_t lockval =3D READ_ONCE(*lock); --=20 2.53.0.851.ga537e3e6e9-goog