From nobody Tue Apr 7 04:21:21 2026 Received: from mail-wr1-f74.google.com (mail-wr1-f74.google.com [209.85.221.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 C790033A708 for ; Mon, 16 Mar 2026 17:35:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773682533; cv=none; b=DkS/LOMKrVERCkaqpwXC5EOr5sjtML090zolCLKhxvogrzkoB5HfVBLUb3tLy3b1rjE7NFyCScRpMo5iz+sfUcWAnIFuDzbBzHgiv8KyZ1JFn8CuNGufFYoKJJiJFc+bbq4EPhi2QdXntBu9n8tto45eixcjWMetHdnsDh24+kI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773682533; c=relaxed/simple; bh=mascMBHyMxL7+rhIsZVuyrQ1poIA8jNmRxptuWKdwlo=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=C+V3FX1uum1xsLRrjb2/orTW/J0OKBq+JUuRQTqJkAXfwIZYpb1qNZ1ViZIOL/05eKEHwMnETWIElUNkRv7p/pTJjbzxI3vwawzOT2FkkXIhbFmH8WDVojzIvXdtawILlqJVj86V50K65K8xq5UfQusTRYQEptVpC3SV+1tp+Do= 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=vEDKeUnZ; arc=none smtp.client-ip=209.85.221.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="vEDKeUnZ" Received: by mail-wr1-f74.google.com with SMTP id ffacd0b85a97d-439a85832c0so4204597f8f.2 for ; Mon, 16 Mar 2026 10:35:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1773682530; x=1774287330; 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=V0ORKdqRW0mEfmd4VRP/igA0BU9vYKKtq0fYCFbuf90=; b=vEDKeUnZXsL7QXxIkUr5eVWlOvUx44odG/bUXSRtwiI80ec4ZkfuCGrllPOll5Gfx4 fCFPLupUMc9X5Cgp1wNoYIF36A4Txq4gIwka8/osLMhQwj+MUK/nWUHYMmpX12elQ0Tj /mKxHv3Y8asJMa17G0zAOWhual0N0+HQh+KIJeI4/n+yyNyfApnW5/A5MUtDYPT4EC5a Lfz+rkV5sjfAuggoncTnC4EavEfGhj7Qlt5KrqkrwlNtPrM4hVDs2lzS3YwyQwJvoS5j J6BHMBqY+LgH7zizFgERWO1G14xH5Bx4NHHwgcntkOwk2P3qZ4lVLrgUI0YYdaxsPY6A Gb3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773682530; x=1774287330; 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=V0ORKdqRW0mEfmd4VRP/igA0BU9vYKKtq0fYCFbuf90=; b=b/rImdwll5DPkmuh2qxFklhkKZ82VUethP4A4ljfcVOy57cKdBrTTotoYTHla4I0v5 pOxAf2o+D6myNt9/THxAIpJzLxajc6CjFGjRkOBLI4fVojrVtxxw04MtUDsM/6Pijpp/ WXaNJt/8Us6sniXR1deUIbtGgBFyCA9SBokHO+37JPsjlCwNQ38Bh0eOhpBCUh9xnYS8 B3lnG9caCJuPFKgXoBEOSsRANfuHPspWJP31eJbgDs2bC5KPQv1fbIjM9GLZgsTEwjvi OdrRfIrJ4qZxHwfy50XKqr5l0RZVIKNKGFQpEwCx3Gz5OA6YWqW09IO/tPMdZqRMMyOD 09gg== X-Forwarded-Encrypted: i=1; AJvYcCW9hZxRFE1Boj5eq40X/1NC5ttd3Aar7hEDJRReQRrRmn+tQPwNRM96OxhHp7xmLGIkN/tCUvOTw8VQYyM=@vger.kernel.org X-Gm-Message-State: AOJu0Yw4eVnCwri90vFyK4eWlpBU0OZOCV16MD+3bxVEwRoyege4f5iT 0Dptdvugd/33erLSuvpSmSIVolEPX8KzYA9MOdxWhGZ9gbY9v647kFD/2ocG5uBfXA1lpu6IRJF pPA== X-Received: from wmtf12.prod.google.com ([2002:a05:600c:8b4c:b0:483:6fe1:c054]) (user=tabba job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:46d2:b0:485:3a03:ced1 with SMTP id 5b1f17b1804b1-4855672737fmr240611635e9.28.1773682530109; Mon, 16 Mar 2026 10:35:30 -0700 (PDT) Date: Mon, 16 Mar 2026 17:35:23 +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-2-456875a2c6db@google.com> Subject: [PATCH 02/10] KVM: arm64: Use guard(hyp_spinlock) in page_alloc.c 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 Migrate the manual hyp_spin_lock() and hyp_spin_unlock() calls in hyp_put_page, hyp_get_page, and hyp_alloc_pages to use the new guard(hyp_spinlock) macro. This eliminates the need for manual unlock calls on return paths. Specifically, in hyp_alloc_pages, this simplifies the early return error path by removing the manual unlock and resolving single-line curly brace styling, reducing the potential for future lock-leak regressions. Change-Id: I37bb8236dbfff9b58bda0937a78d2057036599b4 Signed-off-by: Fuad Tabba --- arch/arm64/kvm/hyp/nvhe/page_alloc.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/arch/arm64/kvm/hyp/nvhe/page_alloc.c b/arch/arm64/kvm/hyp/nvhe= /page_alloc.c index a1eb27a1a747..f43d8ad507e9 100644 --- a/arch/arm64/kvm/hyp/nvhe/page_alloc.c +++ b/arch/arm64/kvm/hyp/nvhe/page_alloc.c @@ -167,18 +167,16 @@ void hyp_put_page(struct hyp_pool *pool, void *addr) { struct hyp_page *p =3D hyp_virt_to_page(addr); =20 - hyp_spin_lock(&pool->lock); + guard(hyp_spinlock)(&pool->lock); __hyp_put_page(pool, p); - hyp_spin_unlock(&pool->lock); } =20 void hyp_get_page(struct hyp_pool *pool, void *addr) { struct hyp_page *p =3D hyp_virt_to_page(addr); =20 - hyp_spin_lock(&pool->lock); + guard(hyp_spinlock)(&pool->lock); hyp_page_ref_inc(p); - hyp_spin_unlock(&pool->lock); } =20 void hyp_split_page(struct hyp_page *p) @@ -200,22 +198,19 @@ void *hyp_alloc_pages(struct hyp_pool *pool, u8 order) struct hyp_page *p; u8 i =3D order; =20 - hyp_spin_lock(&pool->lock); + guard(hyp_spinlock)(&pool->lock); =20 /* Look for a high-enough-order page */ while (i <=3D pool->max_order && list_empty(&pool->free_area[i])) i++; - if (i > pool->max_order) { - hyp_spin_unlock(&pool->lock); + if (i > pool->max_order) return NULL; - } =20 /* Extract it from the tree at the right order */ p =3D node_to_page(pool->free_area[i].next); p =3D __hyp_extract_page(pool, p, order); =20 hyp_set_page_refcounted(p); - hyp_spin_unlock(&pool->lock); =20 return hyp_page_to_virt(p); } --=20 2.53.0.851.ga537e3e6e9-goog