From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 24484C3DA4A for ; Thu, 8 Aug 2024 09:55:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type:In-Reply-To:From:References:Cc:To:Subject:MIME-Version:Date: Message-ID:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=BdZaziOT7rGTA2Gumq6j/eSb78GDFO0ilon9EoFMoWo=; b=kBJNIstIrmzfgAjIzHYfkcCKnJ f67dMh7G1H35PCKe8G4WQlG0AIKMoCSTZtVFEa4LuizXeU8jVSGmrZjQWAMiRScES6dpHGrNdBiQu PB214Dvu24n1iTJClvGUABMnOT1F6srmt0J2N/63T+usTl1tywqW2q79KKYjkrZs+2oWXnVkNBVq2 f/MBFB9nCVMA66FIWUyuwT5uDhv1JJnZPnqM7UQMJ4D03/CTFrHlNC5rAUhfJyj8e1pfhSZkmnd3n Ldw/hd8pftyDQz4PK8k4ApdIOGhZsW0CGELs+9znY0SjBhKW+DMDS4uzin9F3NVHafWRFpMNYJwkL u8VgkobA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbzrP-00000007n3Y-3bwf; Thu, 08 Aug 2024 09:55:08 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbzqq-00000007mue-159J; Thu, 08 Aug 2024 09:54:33 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 0E8C0DA7; Thu, 8 Aug 2024 02:54:55 -0700 (PDT) Received: from [10.1.26.21] (e122027.cambridge.arm.com [10.1.26.21]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 632F73F6A8; Thu, 8 Aug 2024 02:54:23 -0700 (PDT) Message-ID: <34468ff8-2159-4adb-b680-c6048eecee80@arm.com> Date: Thu, 8 Aug 2024 10:54:20 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v12 01/84] KVM: arm64: Release pfn, i.e. put page, if copying MTE tags hits ZONE_DEVICE To: Catalin Marinas , 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 References: <20240726235234.228822-1-seanjc@google.com> <20240726235234.228822-2-seanjc@google.com> From: Steven Price Content-Language: en-GB In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240808_025432_390574_B041E79D X-CRM114-Status: GOOD ( 14.05 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 07/08/2024 15:15, Catalin Marinas wrote: > 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 > Yep, as Catalin says, this is an 'obviously' correct fix - the reference needs releasing before bailing out. The comment there is perhaps misleading - it's not just ZONE_DEVICE memory that will be rejected, but this is the case that was in my mind when I wrote it. Although clearly I wasn't thinking hard enough when writing the code in the first place... ;) Reviewed-by: Steven Price Thanks, Steve