From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f73.google.com (mail-wm1-f73.google.com [209.85.128.73]) (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 E06BA3A63F2 for ; Fri, 29 May 2026 07:43:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.73 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780040626; cv=none; b=E5SNMO26MNycul/2zthRZYPqLYUPGuSp81QvMLHOtsdBX5W4w66qbOT/K1QHnyPupYjrnEDADfPwD8DgK8hsyuRXPZpFFGCaKe73g7xnOPr1BMsXIpeKBiiUF71KurVjUamRZFqYbvS0H352UtzKDoTI3bRMQxxlQ9r6SiwksmY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780040626; c=relaxed/simple; bh=T+BBvU9dPmONncq6+SDVFvPjdvMQiwJ6JRgLwFD5SZs=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=TevN6TQRMwP1OP+EtMz2ahaw4xdq462fQjqPJrwv8MnLFENaUsCh7JyL53wZvL+Eg2tHU3SIhXb8OZ/prJpLYkrptyPUhe4Xb1Dxtgg7EhR4KwVK6D6hNjc6ScWBx99sGHzwGWRr1tjQp7ouG9Dx0O9raUfF97m8FEz9aTtvRrA= 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=ve3M4Ceq; arc=none smtp.client-ip=209.85.128.73 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="ve3M4Ceq" Received: by mail-wm1-f73.google.com with SMTP id 5b1f17b1804b1-4904ee02e72so57474825e9.1 for ; Fri, 29 May 2026 00:43:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1780040623; x=1780645423; 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=/7Mniq795v9HO00xIoc8A38A3iAvF/LweIfmdHSlDEU=; b=ve3M4CeqBg4+ETqUQOjmhRArFMbtUWIi2BYGbcd8QTK16LuLB0b6sqxbbwRQDO9Ch8 UJCZdnyaxmb6ajkP2WmNO4woxn1AHBHvHWpbn3B1EmOU/EOB99Y/dUnpAXxiWCdZ0umu Ep5NHsDJbyUx9MBkv/v1ODlXkccgTWkIQ+JS9A5KSyCjCiQHk3vx7u6JtBRQXCP35gfN bcvpjcZ6kS3qCyN/rlNPLvaV2CytKtVkDYCUeMPz/k1pwkFEM34wUWgJtPdUIJFVlkuc eDPpsBwn1BVaJGLPHRAnoCHHZ9LNW3HojGbGKwKsLwCw9+1HXOdyGBEd8FilQBANg9Ay ShGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780040623; x=1780645423; 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=/7Mniq795v9HO00xIoc8A38A3iAvF/LweIfmdHSlDEU=; b=lZtOdEFgAKbzVJ62sW68gCTUHPXRCKlUP87yf34ykcmSmLQJHwa/rDj1kXjz59GniC tUr/2tDO7lD4qF1S8RnOzevz7QKeoYmdi/v90ZfxN9OoXM+1ZGevifwRzShzENJzGezY CLkYyIGjglFd9TQVGI59ADTZiPniEP8cmY6kVer6/gPCFPlxbXXtN5gSfj5Fe/7Crg8f lC+BLlsByTcAyD60ce6I6BclZrH3qb2atal2RwiznlnG6XZHFqQSnGuI9DDfDEUHFwur +/iWon0i2F0m1x2JUcwFCb1FyOdEQr5QBXrYor5jdV+HBfBX55AWA/7vl8DFSdfrDcdT SGew== X-Forwarded-Encrypted: i=1; AFNElJ9FLdX7tjhIf/LVzT5KlBXkbXtHUjmheo5R7qPFlk/YWmvlAP5qdvK9k6CmDmi1nxqJJnNRHH8bhU5qB4k=@vger.kernel.org X-Gm-Message-State: AOJu0YzQKeJT0/2GgJtrXVoi5tCGYuz1R+OKs3aFt6YYv9vrcTPDSXEK TiXoDeoT9GMXBTx++CRsJan94jUZ7gGICxOrxk6tv2ZylaD2GwzMjjTnoSEChutY/A7d7Bsz+0t PNg== X-Received: from wmlz26.prod.google.com ([2002:a05:600c:221a:b0:490:4896:4968]) (user=tabba job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:8582:b0:48e:5fb8:f80f with SMTP id 5b1f17b1804b1-4909c0e4624mr19865835e9.24.1780040623192; Fri, 29 May 2026 00:43:43 -0700 (PDT) Date: Fri, 29 May 2026 08:43:40 +0100 In-Reply-To: <20260529074341.2271950-1-tabba@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260529074341.2271950-1-tabba@google.com> X-Mailer: git-send-email 2.54.0.929.g9b7fa37559-goog Message-ID: <20260529074341.2271950-2-tabba@google.com> Subject: [PATCH 1/2] KVM: arm64: Free hyp-share tracking node when share hypercall fails From: tabba@google.com To: Marc Zyngier , Oliver Upton , Joey Gouly , Suzuki K Poulose , Zenghui Yu , Catalin Marinas , Will Deacon , Quentin Perret , Vincent Donnefort Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" share_pfn_hyp() inserts a tracking node into hyp_shared_pfns and then invokes __pkvm_host_share_hyp. If the hypercall rejects the share (page-state mismatch at EL2), the node stays in the tree with refcount 1: a phantom share that leaks the allocation and that a later unshare will trust. Erase the node and free it on hypercall failure. Fixes: a83e2191b7f1 ("KVM: arm64: pkvm: Refcount the pages shared with EL2") Reported-by: Sashiko (local):gemini-3.1-pro Signed-off-by: Fuad Tabba --- arch/arm64/kvm/mmu.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index 4da9281312eb..4a928fb003ff 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -501,6 +501,10 @@ static int share_pfn_hyp(u64 pfn) rb_link_node(&this->node, parent, node); rb_insert_color(&this->node, &hyp_shared_pfns); ret = kvm_call_hyp_nvhe(__pkvm_host_share_hyp, pfn); + if (ret) { + rb_erase(&this->node, &hyp_shared_pfns); + kfree(this); + } unlock: mutex_unlock(&hyp_shared_pfns_lock); -- 2.54.0.929.g9b7fa37559-goog