From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2932F26AFC; Wed, 7 Aug 2024 14:15:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723040139; cv=none; b=XjcUSKFSfXo2xNRVCnESDtCglSnmvBTPvoszpbeUZlAD07CZU/WSQpNJca0sy8SIwnKm9tLVC+yeFtXp+GBFVBbDMuNujSmDg5MbMpIJkXk0bg7IOpdALyUP5jsiHx3zRfut+M6Ibv6RblFVBMwLCtMlXFlgoay5/fJjTXDkAW8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723040139; c=relaxed/simple; bh=N3Upe6B3zDaIo7gAE4ChFYQqp1vXvS+k5/9lYXUJDpU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=hiLcJ7HrtVu155KlOSO584KLToKqbfUiVALPcqIXVD1UdkyKNTBHfPYpwv033Gxa9v67+R58ltJp/7O9tW9zVZhCD4h+0djzbd1qzW62KPHnPwe9yzCjbWuqHANxoWXAt1zl9W2+iK3O5hiN4wN8dxqnPRVKuWVBxiJUjNESAWw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id E3C09C4AF0B; Wed, 7 Aug 2024 14:15:33 +0000 (UTC) Date: Wed, 7 Aug 2024 15:15:31 +0100 From: Catalin Marinas To: Sean Christopherson Cc: Paolo Bonzini , Marc Zyngier , Oliver Upton , Tianrui Zhao , Bibo Mao , Huacai Chen , Michael Ellerman , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, loongarch@lists.linux.dev, linux-mips@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, David Matlack , David Stevens , Steven Price Subject: Re: [PATCH v12 01/84] KVM: arm64: Release pfn, i.e. put page, if copying MTE tags hits ZONE_DEVICE Message-ID: References: <20240726235234.228822-1-seanjc@google.com> <20240726235234.228822-2-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-mips@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: <20240726235234.228822-2-seanjc@google.com> On Fri, Jul 26, 2024 at 04:51:10PM -0700, Sean Christopherson wrote: > Put the page reference acquired by gfn_to_pfn_prot() if > kvm_vm_ioctl_mte_copy_tags() runs into ZONE_DEVICE memory. KVM's less- > than-stellar heuristics for dealing with pfn-mapped memory means that KVM > can get a page reference to ZONE_DEVICE memory. > > Fixes: f0376edb1ddc ("KVM: arm64: Add ioctl to fetch/store tags in a guest") > Signed-off-by: Sean Christopherson > --- > arch/arm64/kvm/guest.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/arch/arm64/kvm/guest.c b/arch/arm64/kvm/guest.c > index 11098eb7eb44..e1f0ff08836a 100644 > --- a/arch/arm64/kvm/guest.c > +++ b/arch/arm64/kvm/guest.c > @@ -1059,6 +1059,7 @@ int kvm_vm_ioctl_mte_copy_tags(struct kvm *kvm, > page = pfn_to_online_page(pfn); > if (!page) { > /* Reject ZONE_DEVICE memory */ > + kvm_release_pfn_clean(pfn); > ret = -EFAULT; > goto out; > } This patch makes sense irrespective of whether the above pfn is a ZONE_DEVICE or not. gfn_to_pfn_prot() increased the page refcount via GUP, so it must be released before bailing out of this loop. Reviewed-by: Catalin Marinas