From mboxrd@z Thu Jan 1 00:00:00 1970 From: Sean Christopherson Date: Tue, 30 Jul 2024 13:15:00 -0700 Subject: [PATCH v12 34/84] KVM: Add a helper to lookup a pfn without grabbing a reference In-Reply-To: <63c41e25-2523-4397-96b4-557394281443@redhat.com> References: <20240726235234.228822-1-seanjc@google.com> <20240726235234.228822-35-seanjc@google.com> <63c41e25-2523-4397-96b4-557394281443@redhat.com> Message-ID: List-Id: To: kvm-riscv@lists.infradead.org MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 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. From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) (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 0AE0F18DF70 for ; Tue, 30 Jul 2024 20:15:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722370504; cv=none; b=gBA5gYYNcemXnZ5ek1IUy1Tcb1hPMr/ycjLDlUDQMHQDHMZcXrM+y4JA9bxeHsGHFPaV4fE71huO4jOz0FoA6niL8NaSs5pjml1iIEMN5zwmH++SCyakK1qKyvScYiaIlSMusjFRCZmAGKtWEc9H/8+2Zn+VO1sMUiCyYKIaCiI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722370504; c=relaxed/simple; bh=Xb56Rjm9GNT0X5C07vjpbr8J+7v+LjPM+oZnEZ2ZEvY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=tQ0bho7Q3qCFhs8vTqAEeU44veu++koYBh+RLtzPQYZL/yWwyyEUOxsvzL614BSitQ7fiHZdApUUcgmZSAy+ObWYFdUJDibEK6O5DuKkI41aU6wELowEeDngv6qVZFsaegN9AutbtWiRfJgWUUE/AyRrAbGHwhhccSxy6GXfG70= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=0wGCuw1p; arc=none smtp.client-ip=209.85.214.201 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=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="0wGCuw1p" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-1fc4e03a885so38638095ad.2 for ; Tue, 30 Jul 2024 13:15:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1722370502; x=1722975302; darn=lists.linux.dev; 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=0wGCuw1pbQXN7wWO26SSSHj3M3d46PTE6rXmKmePkT+Dqi9jPczInw+6S4J/zpDhRz UHQZyyo+eOFZLNMcPY5F/e3QbjYOiTisjGC1WC0RIP4wMhlq9nkEvcjfqKOLOLW2uq1I wJSoc7fpogC/VF5ENI0t3yDKzY4A+d7b7jFoPKKpO3atIpLOnjWKduL6cuXEKpBcLe5O /T3fhk7qHOEwBLjtM6W5BwMse89Os7Omy5ZsflWEk9QT1zXgvZxftCRfz8mfsP8G2vs+ 4vMXedK+OsCKfhBkrH+fDy5xWMWdJbV3SMR1ACssxvxRLe2UPEs7Qk9RoXBAROdFGBtX sCdw== 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=fCe1YUX4Eou894o2Hir7oWHJRYU9LpQFxRTkDWm46f3hD60RKnvSGeMFmz/81+uZuh auJjiMbnMMW2kivpPj83pY4Ecv21vtCg2pKgsrf3eMKbUYN0gojhNOc0sJsk20igYDuv L6iw7BC5M5WiihpQXNcc10Rpg6wzw7pMwg7JVj/LBnpXOz2tF3aOTp4gPmdU63KAZOmF +JXWCOoDlEZ29cXmx3zRcdp+dt7w+AWcaZNPC5CONfDvtebq9RtdrqqFFPCG2I6JCkJt yJABNuRcqgkpgVUpUMfNWA6VFeI8s69LdvYbnIqpfuEn4Tp/+G6idJWFN9v4c0648b7z M3GQ== X-Forwarded-Encrypted: i=1; AJvYcCWKWtvl+fUV75oaoHvun7hKENlMq4KfWhSuo/xaDQpqr9444/FoUhmNMAIDYbZ7KD1W8Kf9kSWShiB2MCxy5dTsUykOtphh X-Gm-Message-State: AOJu0YyRkI5JK/wOj1mJLL+rjP2bewLg69HYP49AQGR4SgR2tlTH84Np jXZyNhrpC41vxHUsVkvbk+1tvvgXbhjrb5VwanCXpe81m/DJ1nFKYiufmn5wlhLjspiIDAwP43D 3+g== 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> Precedence: bulk X-Mailing-List: kvmarm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: 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" 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. 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 0B256C3DA49 for ; Tue, 30 Jul 2024 20:15:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID: References:Mime-Version:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=SD7cN6YPwhnC0engRiUcNxRJWoFml7jDq4aHfeg7pI8=; b=ZqIqWHOcjYCCNeo/OV7SSkACFP dWVbEOxIKsoX4JXwMc7NRGT8sjBA9b3OVflhGSbUFzsdPu5VQdyAurF7RKjaUMfhkdWOOrSJCczk+ Oi54XC2G8KtBWEDzP8CdcjFNVyS2vCYp7uN4cilrMAbCH30n/6xAjQMWZMLYcsLfuB72jtOZDTahy fLj285z9aaGVh62z4qFdWYe5JnsKbER9Tx61aa8mhK3kAfG+/8YHaYW+EmbsfsPxHHWyJBu/EgfTp 7lvdoEJ80ynZ722fLYISVzsYgAI44NRbh7QZh56HcoKtUuDH/rwHId2bhYIHc1G+b9kfahooqRQPZ V/APTY7w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sYtFU-0000000GOrb-1Q80; Tue, 30 Jul 2024 20:15:08 +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-0000000GOp4-2Psu for linux-riscv@lists.infradead.org; Tue, 30 Jul 2024 20:15:06 +0000 Received: by mail-pl1-x64a.google.com with SMTP id d9443c01a7336-1fc47634e3dso37014295ad.0 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=trvaj7WJ6PTY9zoEbV6lYT+Tdi7cXPu2yorcuhKLr2o0OzBZb2bVbTkB2+iq/c5/nl A7EKhnbzxS+M51LXWpBsqdJdPIp+Y5lSwL/XhE/U1v8nho1dB/YRIfOYuORU4cSNlOBh UL5uePEu0WGwINAxJCqr5Z+g0j5/CfvvdWSXh2czgwb/hIF6Yq4mE0RCurn83VGSf0Jk GKVKS6CrGaYyZvWHm6Feo4UOfLXBxoSoXO7swV/jtCqn6DCJegGIbXFoKNz2yD1jVwgq QJph7C++mPeQOSbKWFvC20VMRMLo/AvZC888YfpVU49FTDZZhy1M01viXSJ7ZXIXB3FD 3leg== X-Forwarded-Encrypted: i=1; AJvYcCWzmVBjB2Gw/1r7aoh5NEdP4Xz2E2/Qxf87qClKcnZBM11gNnLbRBQPI3zORKoZmiflMv1COQTQZ4ovfsq0PXxFXfTMJCZVWg32tS3brpJ1 X-Gm-Message-State: AOJu0YzCzHXuEKYGElwbq1QvdUfcknEOaFTQZjL0zqsRPs7EpxdG2GUm MvCo2m5RvNjz+EBO0w31nL3h+VNa5U+r059bwR5ZUPUIbUyh2HrxWCCN7sK0Sy/Y+J1wTsAbq8u iHw== 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240730_131504_668542_D4F52F68 X-CRM114-Status: GOOD ( 17.99 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=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. _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv 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 lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (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 1EB05C3DA49 for ; Tue, 30 Jul 2024 20:15:48 +0000 (UTC) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=Wpt9ndkV; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4WYRLV5RxQz3dFH for ; Wed, 31 Jul 2024 06:15:46 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=Wpt9ndkV; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=flex--seanjc.bounces.google.com (client-ip=2607:f8b0:4864:20::64a; helo=mail-pl1-x64a.google.com; envelope-from=3xkmpzgykddspbxkgzdlldib.zljifkrummz-absifpqp.lwixyp.lod@flex--seanjc.bounces.google.com; receiver=lists.ozlabs.org) Received: from mail-pl1-x64a.google.com (mail-pl1-x64a.google.com [IPv6:2607:f8b0:4864:20::64a]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4WYRKk3pbDz3cZ9 for ; Wed, 31 Jul 2024 06:15:05 +1000 (AEST) Received: by mail-pl1-x64a.google.com with SMTP id d9443c01a7336-1fc4e03a885so38638075ad.2 for ; Tue, 30 Jul 2024 13:15:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1722370502; x=1722975302; darn=lists.ozlabs.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=Wpt9ndkVqVyqQkQIAKLBAbLOf7we0Ojpdi71TH5SLW14jSCmLoTbyKamD6QIAMSRlO tRrnkcfki+ZISch5ge/oI3TYji7aBqKw4LOjgodn/08v05IKJhwMz+nydnB1C3WKpay0 +kCVNKc7FFVYGZvP1OfrpChYjIqyt/VKYRPNavxYuiDx6J1c3XmRO8cyuxinKjiCN4Iu LpeXQyJf1pFHlpsTqDcRsFAvjR1BAooqB+aKVTf1d5AGoZFfQZ3A/QADJAOmlelije8M lJnxLtN1/4k6Sy20NGVQ3flpFY7efoTnnsRai2V9XTdPCl9bCwdNl/ntoU9Eq4eEkD8c UyDQ== 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=QsOa6C56secImSnpuC2ikZMgFbViqGjnJfXIDiJZDP8yjMKSUBD2VGQvCM2YdrJi2i Tu3wOV+7wYINVeNMm4ZCQNNf0lGSuziZl8NSM8xJFEVPWXaByH7c0nr5kq+rifg2w6Iz 6HMDpmywchFPo6RFNK0pcPhODmblAdQn/Heids8Kk7+4ry0+iZxL2M1YZmgNoRQqMix1 OZEys7ZI8hu7b/4VGpwMCISLvtLoangkcAGSBMtbPvpv/gCeGDo4HgKDD+5oykLyzJTI NZW9nmzTskAUtHO8D+nBjoECYNOVof3VWA3zql7P7LODfJBGp+CqiQ4LPOsXghs7WnHg pSQA== X-Forwarded-Encrypted: i=1; AJvYcCVyUQQRI2rZX2Rs7e7eJUERjzo7zB3gS6K2MCOEmuQt+73PHaOePxYodvvx7dx3eq2+RZWkGgfAtquhFdH6YqzhIQOrsP0FeLH87zCBIA== X-Gm-Message-State: AOJu0YxBA+1uLKEZH/ANUlpShQuc9X0SDNCbU7SCFeTKSi3vDu7Z4YE2 tAcSmVmFuIVxLAa3UxN7h6y2CYAvcSvEAqIL2dS54l/BYmo+CB59VcUuUFoXWRsG03gjUgMiIQk hpg== 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 Content-Type: text/plain; charset="us-ascii" X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, David Matlack , linux-riscv@lists.infradead.org, Claudio Imbrenda , Marc Zyngier , Janosch Frank , Huacai Chen , Christian Borntraeger , Albert Ou , Bibo Mao , loongarch@lists.linux.dev, Paul Walmsley , kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-mips@vger.kernel.org, Oliver Upton , Palmer Dabbelt , David Stevens , kvm-riscv@lists.infradead.org, Anup Patel , Tianrui Zhao , linuxppc-dev@lists.ozlabs.org Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" 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.