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 C7771C3DA7F for ; Tue, 30 Jul 2024 20:15:49 +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=C8yo2cbMxRjf1SYFGiWaoP3WEwWP/CuFq0W0aGvMAlc=; b=DmixqMNoynGiDQeE2LLpQNRWS/ HTjWNVz9kn41zzTwCRQN0yNPOpbirx+lZeU0fKkqna+pSBq10nYf2p2B7jW88vdyaO2B0KVFUAWgs mST4YFNPh6PFukp9R/uI8HsiFri7hcwehN37njRp7GZzRZM4gGkjkgf0PvzGV3+ez0Bdr0f//i/CI GwWwd7zIbXEF4GbfyxGOFCjEi8U2I/WgvsDUPBCBIyKyUZsqY2bxM+fjYMqqO8+9VSWuMY3f4sO1P F58A5cd9X/vb6E/K75xasAP76mXh4cjB6oUzfaP+liY4gZ5oFgzsae578Wl7dPflb2ccfyBsNZcyR Br4v8TtQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sYtG0-0000000GP46-03Zh; Tue, 30 Jul 2024 20:15:40 +0000 Received: from mail-pl1-x64a.google.com ([2607:f8b0:4864:20::64a]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sYtFQ-0000000GOp1-2LJm for linux-arm-kernel@lists.infradead.org; Tue, 30 Jul 2024 20:15:07 +0000 Received: by mail-pl1-x64a.google.com with SMTP id d9443c01a7336-1fc51ea72abso42455015ad.1 for ; Tue, 30 Jul 2024 13:15:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1722370502; x=1722975302; 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=C8yo2cbMxRjf1SYFGiWaoP3WEwWP/CuFq0W0aGvMAlc=; b=AZgzCKGhpeAS5u168y5tMvlJ3pcoO1WDVLAyVQ5tJ+Ss22QR7/0cFCBv5paQ1UthIN 3Minn0sMLo0hmpG0upxKrSVjZqcxFokp12w9P8Y0Ys4/lgurFPAAwpBHNp4UiGkxnMd+ YB01vltwKR5kHq4fzrOu9rf2uUOBqvM6xM7Q+Q02B73F6X0RsS+ral7c+qBqWusmlki3 muVhr0t2gTmJ8MEdH42ANgO1zdelbD3Rd9jTGQDB9YMv82kK7+T2VWkAmhrv1SJIwRF4 YO8t+jBrKAyjcPadFhDghkYoQQAZR0V6VKDFtUM/NK7OOBfJXHtF1GDwgB/vNG7rGJE8 NqHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722370502; x=1722975302; 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=C8yo2cbMxRjf1SYFGiWaoP3WEwWP/CuFq0W0aGvMAlc=; b=Ioj+l09QxKKvc+Z8FmBQ3568llD36V1U/iW/Z4g3x9yesvTD/AEmIDH5pjqnhT2UX5 5olqJulkqSaTjro67HtNhAZnXygERf7owoyMZoNyH0fZu86tO6E+LF2KMedetSMfWm/+ spiGs3POIQCddz7s1GMKWShSsmmwUBKlbv9oxGDmOXLQ2XjtSg7GSDxB/Z19wA3zZit7 HoXUe3AZF0Ze503wDJQPOg5yQx3tsQDDtNnQ0uWLleneDEY8CAOUhC8EIPwE2sQDSW0z uSx7Q92uq/bjWaMrT/l6Y2Ic9WnIetZpXTJ/7lk1h5+Bpt3gAGk53NaMMwStal3q2YNm ZGLg== X-Forwarded-Encrypted: i=1; AJvYcCWfR0PztOM+DpvOtG1qBzPwITU9/Avc77iRgJa1xqXbmJKCiL3sEi/6T0ENBJ6ksUEXPQ8u+TObFppGZ9kEGUjcoerisP2gB5FYAxePtKx8Za6aPsk= X-Gm-Message-State: AOJu0YxavxU5LXMrZThxv3aZCvrJ3Ald19NuWKcWqIAn90KDfDB7QCXj bH0tmNK6lgYvijOuAT8uSYOE/cGjbbkBzHdBaJxchTCRJ/XyWoMXIbPrvwTmJ+0+jwXjw/UjTAY S2g== X-Google-Smtp-Source: AGHT+IH9iITYoLB/ZN9Oi4VKGOQu9lhx7HYkDR9WKhrc/jsriwfmp+7ZOuZAysZ686xisdvdjIEEvamlnSs= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:902:ea01:b0:1fb:54d9:ebb3 with SMTP id d9443c01a7336-1ff04828eb3mr5974125ad.6.1722370502109; Tue, 30 Jul 2024 13:15:02 -0700 (PDT) Date: Tue, 30 Jul 2024 13:15:00 -0700 In-Reply-To: <63c41e25-2523-4397-96b4-557394281443@redhat.com> Mime-Version: 1.0 References: <20240726235234.228822-1-seanjc@google.com> <20240726235234.228822-35-seanjc@google.com> <63c41e25-2523-4397-96b4-557394281443@redhat.com> Message-ID: Subject: Re: [PATCH v12 34/84] KVM: Add a helper to lookup a pfn without grabbing a reference 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_131504_653819_C19BD490 X-CRM114-Status: GOOD ( 19.41 ) 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:51, Sean Christopherson wrote: > > Add a kvm_follow_pfn() wrapper, kvm_lookup_pfn(), to allow looking up a > > gfn=>pfn mapping without the caller getting a reference to any underlying > > page. The API will be used in flows that want to know if a gfn points at > > a valid pfn, but don't actually need to do anything with the pfn. > > Can you rename the function kvm_gfn_has_pfn(), or kvm_gfn_can_be_mapped(), > and make it return a bool? Heh, sure. I initially planned on having it return a bool, but I couldn't figure out a name, mainly because the kernel's pfn_valid() makes things like kvm_gfn_has_valid_pfn() confusing/misleading :-( > (As an aside, I wonder if reexecute_instruction() could just use > kvm_is_error_hva(kvm_vcpu_gfn_to_hva(vcpu, gpa_to_gfn(gpa)) instead of going > all the way to a pfn. But it's ok to be more restrictive). Heh #2, I wondered the same thing. I think it would work? Verifying that there's a usable pfn also protects against retrying an access that hit -EHWPOISON, but I'm prety sure that would require a rare race, and I don't think it could result in the guest being put into an infinite loop.