From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (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 E6C253403E3 for ; Fri, 29 May 2026 10:08:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.49 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780049289; cv=none; b=Vp02qUcbNGyvnYTAfWou+WGIYP5TiTgDXsUrjP9E26s3CLYsTLhMg9d8qrQNBkvolTbGOEV38gIt2lc6AjY/bzpYLUHjthNQHoFbBMZYYf6Vwg3aCqZfTBVUY+62EmNqATbDiuUL1qF5aSfzlUTf8XyOSEwgQKRoXeDwyEc1NV4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780049289; c=relaxed/simple; bh=VLrSr6znP2Jb1CNBZKlAy9slLm27Fo1ks9K+hx9L70Q=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=R+ogXX53PIDC/J7Pjx4C6bc/xUUCb0r1JI5Qp1pPUWQPkF/pg/gdqzv1KHsohcJxsbXPpxfRT4mphy6nqOb077PWxK35u87puMFzg6AI7vv0m5SJikDSbUzV6YYnBmIlbmnv4o0cOqPkJp//faLhnJ9vwONAI1GcBPlpbEZC/vQ= 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=EYQKSYUS; arc=none smtp.client-ip=209.85.128.49 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="EYQKSYUS" Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-4905529b933so54000575e9.0 for ; Fri, 29 May 2026 03:08:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1780049286; x=1780654086; 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=695o6Vsk+rg4TEq2m0E4aPhfvl/ze1rK746wt9maXiQ=; b=EYQKSYUS21V8KIdW4NIezTpdInQfz44dXttv/hszVkfLoB1tqmRV3KU68LkGzxD3sg bzSsjuXNyLqzMUBUUNxhWZJa3jpOyTHQdbueF5tMNsVYKFofpAJBXATtaf8oig7v2Vya 2efWoqvL1edW4LRJfY0+bwIqaxUVLNzqnIZwkq/mdNaKnpQhhOR+7gh/QM122pwVSdcv Cu9G/QkJtLjEcinafFm/hV5K+COsgJrJpB6KpJHwUmJG1j1W7/yd8Vj8eZZ/hkRIHrSc Af3H0kWpDTd83EBmyY7Q0Ivey9vBHGv0SjOZ1I8wcJWH+t6EihIeTA7HuP7n+Z6XbDwA 9x4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780049286; x=1780654086; 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=695o6Vsk+rg4TEq2m0E4aPhfvl/ze1rK746wt9maXiQ=; b=CvHXGKXCJXhUuwyVflZVtB5gjVaaQEuD9XSsd28Ee5D0ErpcxnnCuI7Ojj0xicUWko Salk8izF8+i4P28tm4EDRzHWs0zaPmoI6xlMYSgFM8/9LTJcC85GTrY4btBf32G7MF+P ngHjFEfgITKdWyDY7r3yKC+ryjYoKi+QpyQFuYMLrj++tplicRnTxtOBdaLh4zaXWIGm 6FO3mAN6w+90q7OIU/p4FMbGxpG4jcyrZf1eoIdHrvBiuY8FC2Af8XaXPxT+PIV0xYKv rkYVfQb8t5Mt2/rJMBqRqTTtTJ1zktjyE3QMslD1maonOdDdavyWj7UkGW1paaV/TWgZ Ux7g== X-Forwarded-Encrypted: i=1; AFNElJ/A0WeCSWRJ9TZ9V0aP5deITv8SJUZ/ft+SnLqaC2n6B0FS0rNREySmFBFnj4rHkaslCs/RH3H/X2JhaqQ=@vger.kernel.org X-Gm-Message-State: AOJu0YwrTbCKjCBNwDIP4GexkfTFHj29t/FpUQ8cpFHIgz1dV1twvDQH +qYCYf56QazqrsdxWAbJDMa+efPMOm1Tm2EyN0gm+fscNeQAF4KQunxJn7dvIgFBUA== X-Gm-Gg: Acq92OGjQvn3+Lmmd/evi+KJXCgSSk9FVw2LWDPbqtN6n/gaj/vQqmOEH53P5rQ2nSL Vuz/Nmv2UYC7KYwk9k/ubMjlT3KUk76h4ipqExB6x13a8Z3lBYRe2i9NwBPg7s5a9+JeQvGwCkj 8jDBMeTBR2QfIlGTGRsrEEqHnWRjysHsvOQHmKwZ2eAE9iAQkcbIzPe5Ulzr5+QP44zbavQ5ayE lWuIgF9LKEhOH9ecqwmYxR+pMxE9lz1P/aIBgMjo/ivPLISUrm4W9fx0BoSAOOJ2PIngZnUcQI+ 3/czhiWDWpcFcnMOkYYikZP3jaT7QjJonSsozzOD8y1Duna8uz6shNGysV2tIhJgTimdx/jAZ9L q+CXzhGBn31Ft0X16GXGl7HxzhhMAn5VkJ41nHMzg4xqFH7dF4amL6xCLbZqnNd/c0VpWju6KgL M/CYwqK1MlyK1MQRdd8og6jRmqD6Zrikezk7tBQM2m96VnikSPP8MfKow9o9pcboitk4PsyhLGw VZDuA== X-Received: by 2002:a05:600c:6287:b0:488:a882:c7 with SMTP id 5b1f17b1804b1-4909c0bce7bmr41795985e9.25.1780049285690; Fri, 29 May 2026 03:08:05 -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-4909c12f4d0sm11602305e9.34.2026.05.29.03.08.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 May 2026 03:08:04 -0700 (PDT) Date: Fri, 29 May 2026 11:07:59 +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 10:23:22AM +0100, Fuad Tabba wrote: > On Fri, 29 May 2026 at 10:21, Vincent Donnefort wrote: > > > > 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). > > If we WARN_ON() in hyp, then I argue we shouldn't have a return value. I meant the WARN_ON in the host's kvm_hyp_unshare() > Or at least add a comment, BUG_ON() here. Think of the poor LLMs and > the people who run them :) > > /fuad > > > > > > > > > /fuad > > > > > > > > > > > M. > > > > > > > > -- > > > > Without deviation from the norm, progress is not possible.