From nobody Mon Jun 8 12:11:53 2026 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-Transfer-Encoding: quoted-printable 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 =3D 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); =20 --=20 2.54.0.929.g9b7fa37559-goog From nobody Mon Jun 8 12:11:53 2026 Received: from mail-wr1-f73.google.com (mail-wr1-f73.google.com [209.85.221.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 56E853AA1B6 for ; Fri, 29 May 2026 07:43:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780040627; cv=none; b=H18jwIc7WMDZwZkVQ1CcpE5GAIJ1D8nFA2RRjhK8oOLggne09mSG2e0QqKg5SeFNRpwnCl3CILcnDEgLL8yC1yC3Jz3obWBoYjHMDy81Iafmn/IQLTYgDnRUO7GPO5AaCM5kXL8dNEflmR5dwZN5If7c00OIevwLJV/t1IdufL4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780040627; c=relaxed/simple; bh=Qps6o6tLw+5Z7L4LX52l3zL+jrsDKX3MK74mb9UYQZA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=udzj0F7caF69xW+W5vg0TzmMfsqCPUta1F6VC04weMtgqYJoW3j+4wInN/TdqsNA0p0PR8dh06ni38PISz3h+qrHQinnUVMzysBHT0Yb6zTfO+si3ypzmVedc/lHFOXTTkyiWHYkw6bj10r+adsEe4gF/fkN5yfyqnV/HU3Jk+E= 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=Wfk8dPa0; arc=none smtp.client-ip=209.85.221.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="Wfk8dPa0" Received: by mail-wr1-f73.google.com with SMTP id ffacd0b85a97d-449b2a183d3so8556878f8f.0 for ; Fri, 29 May 2026 00:43:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1780040625; x=1780645425; 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=u7WGxRyEbovaCEk6n++MhLN9S+efqVE7Q4ikibcd+yY=; b=Wfk8dPa0/p3wPBEo2V7LSK2zNGUZMnsWb0Mva00AXK57xkuIq2wrfR4aVYufcrYuaz dN0IDuVZdlH0p4mtKA6GIFEWmeBGNN8Dh2s8VceN3On0rxyhM9chGPi/gPCm0REJfwF/ +hOv40RBbVpmvJAlrbkHdkuzAlewoPBCnH/Iv/q4n+MAXx6ICO87zrdmyHBsfxVaaZTt DfT/y1DVhjqh3MXzVpKVGabvD2ARwhv8MpO8KIuiXIUXsIwRGTfJwGAHpyMsqX5crPnK Z17Mgr3liKIPU7/7CPbdxSQJQpY3BDXO5fNSUywSX3L3e7vkmZDAhacD9azm80lYGDCZ ruOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780040625; x=1780645425; 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=u7WGxRyEbovaCEk6n++MhLN9S+efqVE7Q4ikibcd+yY=; b=gzuztSkF/grh4QaGmsNtnsiS/DqGs8BEUdh3lelEH7tg51jG2a60Lovh70USftkeJu ZCcL4tNsxy3PP8GZGGHdkAmZlQzC9of6N8p+3iWNzu8H2A9MYvMT+OvlMKEfL+Rgbok9 j/+7G2XgwofGLvhVi79cSmPFqKT4i9fFkRUabrmeOrKTROnW7+VfI9D06egTNVQhejPa kpVyGyAl0ea792e8we3d1Oo1uSYlYku0k5Zut0wSPvn1erqxlJnoX+wp6QHFROmnrxdp ZpuJla7z25h0ci1+lj+DXPyl491cS+okcoShHGp+V7JdjbHzXxYamKQGH9MhvpgDpgqX QsVQ== X-Forwarded-Encrypted: i=1; AFNElJ8U5fDmjlZfbLwhUXMxODvWCqnInjns658PPjb39Eytm0DvbJ/K7O3ZdxHJdtmCjJu9Nr4LywIiv9gVabw=@vger.kernel.org X-Gm-Message-State: AOJu0YxPSUu+YgUPi81Obyc5VOFoJixVPSPhxjl8Iuap4bvebBqSKnil 54jeCLIg+obRJl6QGafLrQpwdqcd+c8A3i4OjQTqPmQIyVxeUTRRsWs2lQBOboOgq+E1YFezjo7 j/A== X-Received: from wrzf10.prod.google.com ([2002:a05:6000:1b0a:b0:450:e76e:87e1]) (user=tabba job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6000:4683:b0:453:9897:76aa with SMTP id ffacd0b85a97d-45ef1385c29mr1854131f8f.21.1780040624606; Fri, 29 May 2026 00:43:44 -0700 (PDT) Date: Fri, 29 May 2026 08:43:41 +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-3-tabba@google.com> Subject: [PATCH 2/2] KVM: arm64: Avoid host/hyp share desync on unshare hypercall failure 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-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" unshare_pfn_hyp() erases the tracking node from hyp_shared_pfns and frees it before invoking __pkvm_host_unshare_hyp. If the hypercall fails (e.g. EL2 refcount still held, or page-state mismatch), the host loses its record while EL2 still holds the share, breaking later share/unshare attempts on the same pfn. Invoke the hypercall first; erase and free only on success. Fixes: 52b28657ebd7 ("KVM: arm64: pkvm: Unshare guest structs during teardo= wn") Reported-by: Sashiko (local):gemini-3.1-pro Signed-off-by: Fuad Tabba --- arch/arm64/kvm/mmu.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index 4a928fb003ff..8026e834528d 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -524,13 +524,17 @@ static int unshare_pfn_hyp(u64 pfn) goto unlock; } =20 - this->count--; - if (this->count) + if (this->count > 1) { + this->count--; + goto unlock; + } + + ret =3D kvm_call_hyp_nvhe(__pkvm_host_unshare_hyp, pfn); + if (ret) goto unlock; =20 rb_erase(&this->node, &hyp_shared_pfns); kfree(this); - ret =3D kvm_call_hyp_nvhe(__pkvm_host_unshare_hyp, pfn); unlock: mutex_unlock(&hyp_shared_pfns_lock); =20 --=20 2.54.0.929.g9b7fa37559-goog