From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (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 2914630DD3C for ; Fri, 29 May 2026 09:21:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780046510; cv=none; b=mTsJBN4T+9rtlj1JK9dZoKaCFwqK9L/2XgYN6mtn4mcPjogWAepvNvhi/rO6b2a4895UOaOVmbow2iwkwVMudF9KYk1M5qF2CbImvqFEJn/k63BPm0AxyPB7nhB+gAOiJTcXS1j7lvXMKkurENz2pgKvxLiqzIpR/F89KD3tTiw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780046510; c=relaxed/simple; bh=jjFJRevPABeTTWmt7r98pZx1/KWmbzdlaoFhk5O6S0g=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=DXDRUSVqSNEx2aG8MLrxovmIosVQoLJfBXpdtS7IxS/oikuCuC0TjUipKx9YtcMvWfp0DgvjQbqRm7MTm0Rea2PLcSwS5mrY1hOtofztSku8lWj66AmIw5AcuZqWEyuC8F7zekUnKMm5mX8RNrpEDC1G6220x5g3UECnVn4Qgo4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=n8M5cKe9; arc=none smtp.client-ip=209.85.128.41 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=google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="n8M5cKe9" Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-49068493267so37851575e9.1 for ; Fri, 29 May 2026 02:21:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1780046508; x=1780651308; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=vqAhzSB+vg9kKyzDEDNMhRArlwjWlt4Tgxtrau4bCQU=; b=n8M5cKe9mGq/jwasbY9uHwUZZwn71ikKF4EJnedFXFEuYGpFhVEIbuLOpQfytlvBFo +AxMSitDiRv8njFDVuETLvcuXec2RyY4xDxkd78o6kE+IypRnCPeo4ibv2X2ztrXjmSt eWkyYGCG4ovKlABb2636fk1JdeTn5BhPM6OmXOFaNtHZwrFp3I5wkr7f0/bjijLljU22 Y6+Ub4EAM+uTcEKUKnZ+7nQkNxXSbF1PuqBc0QxkUrsrArWuTjYMkmD8Y+Od9WLSuSKS CdhTpBgln1yPiyle+ofnzsbfhnHlNk+N3c4/jDonTzNmTze61oW2Ph8YZB8hEuKl7ba7 Pb3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780046508; x=1780651308; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vqAhzSB+vg9kKyzDEDNMhRArlwjWlt4Tgxtrau4bCQU=; b=rSCdTP1T0BvFNzVLp+WQYik9HUoD2t+G/1aEF4LZEcY+yI/ulOmCYHABIELGRQC5og L/AYU6SypUkPFQeTQP4ih3eTB74XO+ghaulElFue0fA2fkaHAJmoCQu7A+aY6P6pH/vz PmvVbi4eEhfNHA087eIr72Y4YsIpvtTN1YUDhU+j6Z3e/XJkK2MFCGrQo6dKVG8DxUBB Jx/Wzd0ou8UkpNsPjIwYyxrOpp7ov9wI5A/zmbK7nV5H+anvx7bg8nB/5w519AVnYkOL 8KlAZQJU0vEyvOXWLgqS9q9OFz//0lNdBBOXCxQzUk+EhxrgpoQvX2mFU4pe2jv078sd LlkA== X-Forwarded-Encrypted: i=1; AFNElJ/B3WEcHUcfesYOdmMdHwO8lp/J69puesiqtXcx/rYuyqPKpVT1AiaqhjBrT2litjzGa4Yw9mom8ICXMWI=@vger.kernel.org X-Gm-Message-State: AOJu0YwtmCZFY04Gv1g/GEEKbykL540PnHYuAYRWt9ym+lGih8czuckf 0pvAjkTtb6VNf3s+8bPJPUKGCjJF0E66OhtzPGmrzxXCDks+NjHVtQp4KjcBNi7CcQ== X-Gm-Gg: Acq92OFgeZdfD1H3ARM98G36qiAtqM6luaryM6FF+NIt0b6lzyZyWIxteBORX5i/p97 rAPontwCQsDsnjP4/hblJtSlwIrEG/yaUcFSYwliad2ib9MJqpLT0IUMXB9nWM/MVOaikbzwbJA 5xgH0LoxglWO/Gp3wju+bmfuc/RcZNxM45iE/IyMumV8KJk+fVmzpvH0W/WInjoimqDW4AtiDvl XczLrtuDqsmJLs56yBIHsZZWvSn0soze7eJmrYn6KLN5yFrFyQluLTQEr1+hkQsYEBYu5qe6jFh jMNo+2OGxrLHaUM+UuYJmW1BO2RhUbICWf0vP+muTbJ2mJnv0yHXMOhsEuYeoCiNxIXdqPuvjbG DO/dZCuwDuxkmD9m+0lMLKwC9D/0Yyqn132Omb9CrViEcfOe5Bow/rmCwN4QmLi0g2HvjnbRuiL v+Ty6/q7wG1BedX6oJ/nMeOa6QdapAOma4o135coMCcIQWDulLb0Qg4Mn4McCP+0BrCQ68yaacg Id8Zg== X-Received: by 2002:a05:600c:8582:b0:48f:e230:72fc with SMTP id 5b1f17b1804b1-4909c0cbd2dmr25839285e9.33.1780046507168; Fri, 29 May 2026 02:21:47 -0700 (PDT) Received: from google.com (135.91.155.104.bc.googleusercontent.com. [104.155.91.135]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4909d6f3612sm26265365e9.12.2026.05.29.02.21.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 May 2026 02:21:46 -0700 (PDT) Date: Fri, 29 May 2026 10:21:42 +0100 From: Vincent Donnefort To: Fuad Tabba Cc: Marc Zyngier , Oliver Upton , Joey Gouly , Suzuki K Poulose , Zenghui Yu , Catalin Marinas , Will Deacon , Quentin Perret , linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org Subject: Re: [PATCH 0/2] KVM: arm64: Fix host/hyp tracking on share/unshare hypercall failure Message-ID: References: <20260529074341.2271950-1-tabba@google.com> <86a4tivdh3.wl-maz@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Fri, May 29, 2026 at 09:20:50AM +0100, Fuad Tabba wrote: > On Fri, 29 May 2026 at 09:15, Marc Zyngier wrote: > > > > On Fri, 29 May 2026 09:05:35 +0100, > > Fuad Tabba wrote: > > > > > > On Fri, 29 May 2026 at 09:02, Vincent Donnefort wrote: > > > > > > > > On Fri, May 29, 2026 at 08:43:39AM +0100, tabba@google.com wrote: > > > > > Hi folks, > > > > > > > > > > Yet another bug I found while testing Sashiko locally with fixes to > > > > > review-prompts. > > > > > > > > > > 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. Both invoke a hypercall that can fail (page-state mismatch, > > > > > EL2 refcount still held), but neither cleans up on failure: > > > > > > > > > > - share_pfn_hyp() inserts the tracking node before the hypercall > > > > > and leaves it in the tree on failure, leaking the allocation and > > > > > presenting a phantom share to a later unshare. > > > > > > > > > > - unshare_pfn_hyp() erases the tracking node before the hypercall; > > > > > on failure the host loses its record while EL2 still owns the > > > > > share, breaking later operations on the same pfn. > > > > > > > > > > Severity is low (no isolation impact) and the failure paths are rare > > > > > in practice, but the desync is real. Both patches are independent and > > > > > apply cleanly to current mainline. In other words, this can wait for > > > > > 7.2. > > > > > > > > > > > > I believe I fixed that here lore.kernel.org/all/acyKhZL2di_QQ9xm@google.com but > > > > as Quentin pointed-out, there's absolutely no reason for the hypercall to fail. > > > > So I haven't sent a v2. > > > > > > At the very least we need to add a comment, otherwise, people like me > > > and LLMs like Sashiko would stumble upon it. > > > > > > That said, this fix adds no real overhead, makes the code clearer, and > > > guards us against a future where that call might fail. > > > Self-documenting in essense. > > > > > > WDYT? > > > > If a hypercall really cannot fail, why does it have a return value? > > Good point. If we know it cannot fail, how about just `void`? > > That said, Vincen't exact words are: `very much unlikely`, not the > same as cannot fail :) > > https://lore.kernel.org/all/acyKhZL2di_QQ9xm@google.com/ The error would happen only if the host tries to share/unshare a page with the wrong state. This would only happen in the case of a misbehaving host. And Quentin's point was that this is anyway incomplete. To handle this error properly, kvm_share_hyp/kvm_unshare_hyp would also need to rollback things... The callers of the unshare should also leak the memory which couldn't be unshared properly. This isn't the case now, (however we do WARN_ON). > > /fuad > > > > > M. > > > > -- > > Without deviation from the norm, progress is not possible.