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 0FA1EC3DA7F for ; Tue, 30 Jul 2024 20:22:28 +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-Type:Cc:To:From: Subject:Message-ID:References:Mime-Version:In-Reply-To:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=Lo0MEBygX1JypWEaHf/k6xfxdkehMYQ1A9Hdq1FNmkM=; b=UqjPYSv4nxVOw8zju0YnjZDQ9y D66trURZNYRFF8FeboCU8bJWmSFHWXDDSJMmcNxFAw4Pk7DiJHR7okuK/LswDYIJEmZptjtkDt1Ab qtkabjnIteMLbQcjZ7pr3daJk8opqdmNOgx46mvgsdTalmrW0czRIBhIVRD357Hyqn+aoB0YkUF9L ybOhHANhTQSTI+iDby48ZMWjL8UQQZ5LlpWpN5a1zJfCnF8OsdQJGzJxIQp16AK2+pORE+nSrZqsk h7vO4bzk+afz4m8m4+SmsuYYNikZtQh6Gzg77k4Zd6RiUKb1TUWDv1ejn7qx8o3b/j2A7qCNCHCB/ Slb9oJpA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sYtMP-0000000GQ83-24Gd; Tue, 30 Jul 2024 20:22:17 +0000 Received: from mail-pg1-x549.google.com ([2607:f8b0:4864:20::549]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sYtLx-0000000GQ1d-1i4U for linux-arm-kernel@lists.infradead.org; Tue, 30 Jul 2024 20:21:50 +0000 Received: by mail-pg1-x549.google.com with SMTP id 41be03b00d2f7-5e4df21f22dso197179a12.0 for ; Tue, 30 Jul 2024 13:21:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1722370908; x=1722975708; darn=lists.infradead.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Lo0MEBygX1JypWEaHf/k6xfxdkehMYQ1A9Hdq1FNmkM=; b=bzgYCYDolWd+D3xgRbjSrgpZ7nwu5z5MUud1PXxXYcXOnb6N50FTVyRJz5bTBPO47e 2Fyi1rPYHNJmZb67vmvoIIjexfSnIikbbZpB6Uu9e0loPKwy2UDNJgR/1PNBxMyEav/a diQfAaUXpEF6s7eHZofxkA5gXo1OJwq8XXZnuUfECIekhYGRvm7rrRDoLNUt41p/pZvz uC7hbaat7bsnDnCSYwFkwOBZOpfqjXe55uUi/Vp2jPtkaFo1Miii+1iBdFC24Rj70KmR iS6Bg88eaW5kWyk+A3Nz8ikKC4nRuReCKU/e1GSg+L7ClEoeMI5N8Jc3kzkB8aaq8ZPn U8Lg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722370908; x=1722975708; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Lo0MEBygX1JypWEaHf/k6xfxdkehMYQ1A9Hdq1FNmkM=; b=uiNlgD5yTaGqB77BFZKonmgqgQmsloY2Xtthe/qYLS21SL3hDmvKt2ImdAMvDO2FNm 7jf+uh6/19vnOsoCLELjFC6lB5QB8CyVHkhwts/GGRliU8QlXrRHV7LrF5Xkvt6fUaNQ SLQKcYLmoJlEvkp1crD2HwNgF5PtRwYePl3gVAE+op2+iNzMAlvYBRcHLIwseN8g2wrm l24YRJCH8tTOUGp0ye2jhcXvaLa+zfrhDOoW1PFdEUuTg/MRZb17IIlqnAioyH1nbC/A VEqzm2AbjMBf8YcwizAg6GpJqOPoOOMkbgTlSowNapU+/BGtGmNbXYWQF866idgpCpIk H0jQ== X-Forwarded-Encrypted: i=1; AJvYcCVeFP7C3JR3qAXZ91NeUlipPf2cTvmco/DNSXTE0HB20vSns3WSPD51PBi2rs0Ren8A0+FLnUdy4DbAGq4vy4qwbalzPjiEK64IJGpfMeY2E63tDAU= X-Gm-Message-State: AOJu0YxoAeD6UqGSuv2hMLnSJNxUyoxq6Wx5RDuftBip7j5Fq5l50pR3 JcdtcPVhsQMVkkWTHsMTy+GLhoEyUsYIU3cug+NJDanlKoFbPff4XA/9SRLOLITK7snRI6hIYfR lJg== X-Google-Smtp-Source: AGHT+IFRxL1KATidTTKhi0tYZI3Y5cQGXURHMsVQzSWYAdVw9bcIrYssZFg0WYN1ZfdRJ6uqRn8d2puX7Kc= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:90a:ca8b:b0:2cf:93dc:112d with SMTP id 98e67ed59e1d1-2cfcab4fa5emr42966a91.4.1722370907896; Tue, 30 Jul 2024 13:21:47 -0700 (PDT) Date: Tue, 30 Jul 2024 13:21:46 -0700 In-Reply-To: <992c4a07-fb84-42d8-93b3-96fb3a12c8e0@redhat.com> Mime-Version: 1.0 References: <20240726235234.228822-1-seanjc@google.com> <20240726235234.228822-85-seanjc@google.com> <992c4a07-fb84-42d8-93b3-96fb3a12c8e0@redhat.com> Message-ID: Subject: Re: [PATCH v12 84/84] KVM: Don't grab reference on VM_MIXEDMAP pfns that have a "struct page" From: Sean Christopherson To: Paolo Bonzini Cc: 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 Content-Type: text/plain; charset="us-ascii" X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240730_132149_472021_16D8209D X-CRM114-Status: GOOD ( 21.10 ) 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 Tue, Jul 30, 2024, Paolo Bonzini wrote: > On 7/27/24 01:52, Sean Christopherson wrote: > > Now that KVM no longer relies on an ugly heuristic to find its struct page > > references, i.e. now that KVM can't get false positives on VM_MIXEDMAP > > pfns, remove KVM's hack to elevate the refcount for pfns that happen to > > have a valid struct page. In addition to removing a long-standing wart > > in KVM, this allows KVM to map non-refcounted struct page memory into the > > guest, e.g. for exposing GPU TTM buffers to KVM guests. > > Feel free to leave it to me for later, but there are more cleanups that > can be made, given how simple kvm_resolve_pfn() is now: I'll revisit kvm_resolve_pfn(), Maxim also wasn't a fan of a similar helper that existed in v11. > Also, check_user_page_hwpoison() should not be needed anymore, probably > not since commit 234b239bea39 ("kvm: Faults which trigger IO release the > mmap_sem", 2014-09-24) removed get_user_pages_fast() from hva_to_pfn_slow(). Ha, I *knew* this sounded familiar. Past me apparently came to the same conclusion[*], though I wrongly suspected a memory leak and promptly forgot to ever send a patch. I'll tack one on this time around. [*] https://lore.kernel.org/all/ZGKC9fHoE+kDs0ar@google.com > The only way that you could get a poisoned page without returning -EHWPOISON, > is if FOLL_HWPOISON was not passed. But even without these patches, > the cases are: > - npages == 0, then you must have FOLL_NOWAIT and you'd not use > check_user_page_hwpoison() > - npages == 1 or npages == -EHWPOISON, all good > - npages == -EAGAIN from mmap_read_lock_killable() - should handle that like -EINTR > - everything else including -EFAULT can go downt the vma_lookup() path, because > npages < 0 means we went through hva_to_pfn_slow() which uses FOLL_HWPOISON > > This means that you can simply have > > if (npages == -EHWPOISON) > return KVM_PFN_ERR_HWPOISON; > > before the mmap_read_lock() line. You may either sneak this at the beginning > of the series or leave it for later. > > Paolo >