From mboxrd@z Thu Jan 1 00:00:00 1970 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 228423E0C7A for ; Fri, 29 May 2026 12:17:58 +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=1780057082; cv=none; b=gDgsFCjV3ASKaAwiSOw/HUKkmbwcaF7bQEZc66BILGfPHVN9Ql+5TfBKMxCfZsd2nYFVWSAC1N/6DvkTfo+ZlMB46HP1J5IHGClH0WuuJPiRt/NqAd5/rNqMORmCNVLoWMjrPFXJRcRwWUKKZz0+4I2DHL58k369Rk0cCikpHwY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780057082; c=relaxed/simple; bh=fpxesCo8LSuN66VhAk2gnQnxJf129JDdYilqmDpGag4=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=uZxEfEtTJUkkjU8OjeOTp3HKKFAOqFdX+YDFy2Yq2IMTF+t7DKdmDJxDZIVXbOvssTDzbB+D5fzoQPjDddHMa77WB2a52bDUZV3eLo7eK16/XQLXSUKUUxczE2MILK3AWFTPoCRRrt2Sz0AQTN99WHe9LKqAXbEdh+qQpnFPOp8= 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=k4hsfRIr; 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="k4hsfRIr" Received: by mail-wr1-f74.google.com with SMTP id ffacd0b85a97d-44d9ace59efso7980958f8f.1 for ; Fri, 29 May 2026 05:17:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1780057077; x=1780661877; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=a4SS+MLrRfo7JjMGlt0hzA5ZHD4Vfkl52EAZVg4EXVU=; b=k4hsfRIrFMKY/4MqcKQs2FGGeUzGur7V+vy9aWW1X8cW+gS3q2QIAw+4nU0F3tyKR9 9UHdda9mOFcp9acpmyq704T8qALHk5i4Z0pBdF2rYRNIbz6/zTPDQb/YQdZt9Ryg+1Gu 7Hc8iDxWyCcVjQ2k4SBrXphZ2cs5pJgocIlMOJB4i24EMt+o+2Ab8M6grwWAsaq3ij4u mIAp2T76Y+gkb+swjrQipotVWhB+7f5gebUab+AymdvSQ8ylhWgqdr1IIlW9SbGyjMIc Yd7paHIsScFBtkLetecyfZZX9RBV+HHrWOurimCteio2IKvgRuR4O4jNYaV8d3XbRJHf 1s3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780057077; x=1780661877; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=a4SS+MLrRfo7JjMGlt0hzA5ZHD4Vfkl52EAZVg4EXVU=; b=UlHJtK7Xfc1GAaxukhwQ3dLz0pS+3vz4TS5S+zFkHWpc+MVtOalJp1N91dyUdnBwf2 LzbQE//jVerKpr/pazgp+hVSMSIEae3p2YnhSuWFtKTylC9WpiwpBwia8IhavZgTnpvT AUj2qYb+/aMxA9alAcUJIXpRvYZzOv6qaT+8dBAhXYtm0a0FOo4h+WiKHW1e57ntauRA VdJ4Ccz8gZmv9Cz9f6Vh1jR2y+zmtDm7X8fipBhVMxQYZoOWBYOYpQC2Knc/1smxl5XZ uXN3FzZ7lznUubzjFtycYkvExOY6+3XI4UPaKCIgoR7v2MYyyBnbWeIDzfeCFUHN7zOc le/A== X-Forwarded-Encrypted: i=1; AFNElJ+YMI99kmwyM9QgI2VUNatbgsqSZzob3P09k1GuUKJDsbE/cprTrPQ2SvfDIMVPc6dmY0bVnM/qLRITkJk=@vger.kernel.org X-Gm-Message-State: AOJu0YzuHmO9qfB0aQGpCnkfgsrTJeUX1olmNLLeync69IUj00jJT+YA 0ib9gJaQoBPc0c0mH84vnZIg6+TVhgJv0TEjYPwN5qiKKsks5LCDHcYGD4SeG6oH2nVe1XmOmOZ D4g== X-Received: from wroz13.prod.google.com ([2002:adf:f1cd:0:b0:43d:732c:5800]) (user=tabba job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6000:468d:b0:45e:ed7e:f8fc with SMTP id ffacd0b85a97d-45ef142a676mr3373752f8f.12.1780057077301; Fri, 29 May 2026 05:17:57 -0700 (PDT) Date: Fri, 29 May 2026 13:17:52 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.54.0.929.g9b7fa37559-goog Message-ID: <20260529121755.2923500-1-tabba@google.com> Subject: [PATCH v2 0/3] KVM: arm64: Fix host/hyp tracking on share/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-Type: text/plain; charset="UTF-8" Hi folks, The first two started as bugs I found testing Sashiko locally with fixes to review-prompts. The third grew out of the v1 discussion. share_pfn_hyp() and unshare_pfn_hyp() in arch/arm64/kvm/mmu.c maintain a host-side RB-tree mirroring the set of pages shared with EL2. The hypercalls they wrap can fail (page-state mismatch, EL2 refcount still held), and neither the per-pfn helpers nor the multi-page wrappers cleaned up correctly on failure: - share_pfn_hyp() left its tracking node in the tree on failure, leaking the allocation and presenting a phantom share to a later unshare (patch 1). - unshare_pfn_hyp() erased its tracking node before the hypercall, so on failure the host lost its record while EL2 still owned the share (patch 2). - kvm_share_hyp() returned on the first per-page failure, stranding the pages already shared by that call: the caller treats the whole range as failed and never unshares them (patch 3). As Vincent and Marc noted on v1, none of this compromises isolation. A page that cannot be unshared is simply leaked: it stays shared with the hypervisor and is no longer reusable for pKVM. So kvm_share_hyp() now rolls back on failure, and the unshare WARN_ON()s are left non-fatal and documented rather than promoted to BUG_ON(). The system keeps running, and only later pKVM reuse of a leaked page would fail. We do not expect any of these paths to trigger in practice. Severity is low and this can wait for 7.2. Patch 3 builds on patch 2, otherwise they are independent. Changes since v1: - New patch 3: roll back partial shares in kvm_share_hyp(); document the deliberate leak-on-WARN in kvm_unshare_hyp() (Vincent, Marc). - Patches 1 and 2 functionally unchanged (patch 2 gains the call-site comment). - v1: https://lore.kernel.org/all/20260529074341.2271950-1-tabba@google.com/ Cheers, /fuad Fuad Tabba (3): KVM: arm64: Free hyp-share tracking node when share hypercall fails KVM: arm64: Avoid host/hyp share desync on unshare hypercall failure KVM: arm64: Roll back partial shares on kvm_share_hyp() failure arch/arm64/kvm/mmu.c | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) -- 2.54.0.929.g9b7fa37559-goog