From patchwork Fri Jul 26 23:52:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13743547 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 692C6C3DA4A for ; Sat, 27 Jul 2024 00:24:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Reply-To: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: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=eM04pE2oItbps9DzmNWUdptdfO1yLAvOtXUsQdNxOmg=; b=14WRp+SWolwDSqujhas/Wp7Vr1 wKF+Oi9Bel454hjHQLivbSPsZQALaoje1qCfzA/S1lNEvGtDD3fTg3DdQ8XibyKcrVgAO2vvEgUah Qi9wDviWVwrhptneUPoCNdr8YdT2fy2yYfPXmHsry7DIOobptm4K9fe0BNzKAQeW2dGmNZWcs+IXf UTYrcEcxbCldGlhN3YRXLr3SYjI4T/HcudO9ldQD/0LRLybwE/LhUOO2KqLukmOzQPEiTMeTJDgHY rwfrL0DqZpOQ2f9Kbx3UZ49px426+RP9ZPRuN2uCmtCmFb4v/AMSz9wPGbnD7/pObvoweHdv8CMbc iytlNXqQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sXVEj-00000005gBi-005R; Sat, 27 Jul 2024 00:24:37 +0000 Received: from mail-pl1-x649.google.com ([2607:f8b0:4864:20::649]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sXUlm-00000005QnR-0Dy9 for linux-arm-kernel@lists.infradead.org; Fri, 26 Jul 2024 23:54:44 +0000 Received: by mail-pl1-x649.google.com with SMTP id d9443c01a7336-1fc52d3c76eso12300865ad.3 for ; Fri, 26 Jul 2024 16:54:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1722038081; x=1722642881; darn=lists.infradead.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=eM04pE2oItbps9DzmNWUdptdfO1yLAvOtXUsQdNxOmg=; b=uZNIDEchj1DUpSbAExGQ2gxdUyZ5XEFg43Ir2gS9nJJQQQaFG3FUUDejjwRrhZDKFE bvRpyKj7seBMkPDNMbMVx8P80bvD/UzxH3fjCGf9NMGaoeKaE2Fhaj5Nv17Je21cXySH JyXY/9ANtL3fGhU3TqrOADJoc90XTprKVm6nVZ19gvLwymJWrhLooIEb8MiB4NDpUyrO Hxhn3wq3tPahUd7ZsFA7GIhyVDy8XQ/S8BHfZrQOOMtCSnN4toEkNftRm7Y0wtmWacDP Z3DpuLx6MZ+LzSgaeJUCXLH9VRtQXPo+257A2WZzC3X5JY8bIo0vehH6kPdIiYLXTqA1 dIfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722038081; x=1722642881; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=eM04pE2oItbps9DzmNWUdptdfO1yLAvOtXUsQdNxOmg=; b=Np/9fcfmV/LNO50q0E9Vof4UZlhR74tQGqvKv43zXk4gcqzM+efvNT9StT0yYj/N04 /u/CGK1vKPTjJG06JQrN97bezRcC5L9UxhuoljstSrDzqyiVn2L+cwTLzks9JLu6rpUQ UK0os/scCO4J4+ej7rFV0pzB75tSKgqoUEl1Db93xvYhDQD8tS1slg2A/gyELyv3eRSH uR6F7F4isLDKcIiE7/HUg0TT7Jxr1rpu/rwWRMqR/qoVqhnH50DBaA2nEd2G8988ZDYp gADGYPV//ZkkDxgM1iECOsNW46SHVZBICt4KPhnb7oTeXDcI74Xjk4oaypRAxc4VvqHA Zbdw== X-Forwarded-Encrypted: i=1; AJvYcCWjVi51OYJ/+f9VpLVNaeCi36c0829MvS9fZTDvZl9M3evQaWSzuLeBjam4a3HbfSeEfeGLRJ9HES8Vrg1b2EPTOYfa+1Wc0NBhjxcXzXDlveJQr7k= X-Gm-Message-State: AOJu0YzAI4DSUhpuuQJERNGLPDhRId7hopTjNFcpKqE0hAF84L0qrYr7 K/w4Yi5yDFI3gcJhFEiru31LBNWyYH+13vNDlbKK7PS1ZdPZUXFM65MtZ9qgz0gOxo1drN4OOsb FGw== X-Google-Smtp-Source: AGHT+IHO8zzuGkjlMSTl8Rqd7iW1pR8+tgiNg2ojfeAF3X7ugPbzXNjRAQyOFKQ91J/aSe/NwOtEVPH7LtU= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:902:db11:b0:1f8:44f4:efd9 with SMTP id d9443c01a7336-1ff047d0af0mr1044175ad.2.1722038080667; Fri, 26 Jul 2024 16:54:40 -0700 (PDT) Date: Fri, 26 Jul 2024 16:52:08 -0700 In-Reply-To: <20240726235234.228822-1-seanjc@google.com> Mime-Version: 1.0 References: <20240726235234.228822-1-seanjc@google.com> X-Mailer: git-send-email 2.46.0.rc1.232.g9752f9e123-goog Message-ID: <20240726235234.228822-60-seanjc@google.com> Subject: [PATCH v12 59/84] KVM: PPC: Use __kvm_faultin_pfn() to handle page faults on Book3s HV From: Sean Christopherson To: 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 , Sean Christopherson Cc: 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-20240726_165442_139935_97580C9F X-CRM114-Status: GOOD ( 13.90 ) 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: , Reply-To: Sean Christopherson Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Replace Book3s HV's homebrewed fault-in logic with __kvm_faultin_pfn(), which functionally does pretty much the exact same thing. Note, when the code was written, KVM indeed didn't do fast GUP without "!atomic && !async", but that has long since changed (KVM tries fast GUP for all writable mappings). Signed-off-by: Sean Christopherson --- arch/powerpc/kvm/book3s_64_mmu_hv.c | 25 ++++--------------------- 1 file changed, 4 insertions(+), 21 deletions(-) diff --git a/arch/powerpc/kvm/book3s_64_mmu_hv.c b/arch/powerpc/kvm/book3s_64_mmu_hv.c index 2f1d58984b41..f305395cf26e 100644 --- a/arch/powerpc/kvm/book3s_64_mmu_hv.c +++ b/arch/powerpc/kvm/book3s_64_mmu_hv.c @@ -603,27 +603,10 @@ int kvmppc_book3s_hv_page_fault(struct kvm_vcpu *vcpu, write_ok = writing; hva = gfn_to_hva_memslot(memslot, gfn); - /* - * Do a fast check first, since __gfn_to_pfn_memslot doesn't - * do it with !atomic && !async, which is how we call it. - * We always ask for write permission since the common case - * is that the page is writable. - */ - if (get_user_page_fast_only(hva, FOLL_WRITE, &page)) { - write_ok = true; - } else { - /* Call KVM generic code to do the slow-path check */ - pfn = __gfn_to_pfn_memslot(memslot, gfn, false, NULL, - writing, &write_ok); - if (is_error_noslot_pfn(pfn)) - return -EFAULT; - page = NULL; - if (pfn_valid(pfn)) { - page = pfn_to_page(pfn); - if (PageReserved(page)) - page = NULL; - } - } + pfn = __kvm_faultin_pfn(memslot, gfn, writing ? FOLL_WRITE : 0, + &write_ok, &page); + if (is_error_noslot_pfn(pfn)) + return -EFAULT; /* * Read the PTE from the process' radix tree and use that