From patchwork Fri Jul 26 23:51:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13743517 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 9CDAAC3DA49 for ; Sat, 27 Jul 2024 00:17:30 +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=kZSI1KNdqk//fOFhZYsFCszCldNWPUNapLOmZmlQ+ic=; b=P7dXHG04NEF/4xYAt8eL/9YJwg cLZHtdWzos84ghCO5kmjqI1yTKtlv+idqvDdHJm1UXI9gM0cdkVH3emAUXKzVGGU5OZUabU5vy+e1 8zd853m14JtGRMorcuTJLVki87uofl26qKmGsgnedr6Kt8LhlGN09HxuIRZWYkfj0TqrdMUWCT3Jl avWwPVZomNyLD9KVCV6skgwsGGCP9SzV0kBHWrln8xQUzQsY+0aJF/8Y224xQmstoWVO5uXTAAFS9 zzXezHSR+xoXuZG39tKmuBUpmfJab/OBbAgMlH+BFjW0/YsVqSMkIgMVpL8VJpOVr/+g6kXyNsSyk WVYNAenw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sXV7g-00000005cH0-2j7m; Sat, 27 Jul 2024 00:17:20 +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 1sXUlG-00000005QMN-1WGe for linux-arm-kernel@lists.infradead.org; Fri, 26 Jul 2024 23:54:12 +0000 Received: by mail-pg1-x549.google.com with SMTP id 41be03b00d2f7-7a134fd9261so1530999a12.3 for ; Fri, 26 Jul 2024 16:54:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1722038049; x=1722642849; 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=kZSI1KNdqk//fOFhZYsFCszCldNWPUNapLOmZmlQ+ic=; b=s4wASBRKd6BS3GoU1RdqDdxBDalyKO12lNqDuIYh4MVTNjAuLy36JY84ZLVgdcEGMb YvI4e0Ofx6jKjpuqwTowN8nJ/Ab2zvOh4hk8KjGaCt2ZHMUwHYVbpBxwM3dhOgVPuC/a oai1U9/6QbhjLtBFtQVVhKp9YroEuFbePchwAp+3FWJmVytWvPBVkBTXePTVhwo7PFq7 85qPm5S8VQbcp+nizVjn79vVSXmv3qKwpcOG5APokn/f22Lr8/VryJ7Qfse7pxAWF7LJ 8F+dbCjoZw9VX/Uh5JFVzoFS5DlLpOo9VGO/UwJ67EszDXRqY39U3gd1vhmYJYQEPraG BhfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722038049; x=1722642849; 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=kZSI1KNdqk//fOFhZYsFCszCldNWPUNapLOmZmlQ+ic=; b=D5VCF6+NaHRdaUIYIhKXwtbtjsu76JFIR9jUWl8y1PFihu75/As2qUX2Gtc5DmTsPp Vz8rN9KaM1jlvZuZj1JguU8SEWqnmZJ1XwPfFdrzdviSd2/5N+eHgraJUYXRyR2KiGbR 63lwVnAszKkbNmvv07pdC/OcLrWoHiMHIaQk8dJtE5v5j0y3YUO0QIc14NzhpQuT4zeT jYomLFWUQ0izvnmmtqDeBebt1OYk/lICpm5pONYnFN1kWV8wY6nfirIh2m54IGjozJTE NL90vqjxiDGAGUVjRWv0GebznW7dCQ1akl90xi2XDx8x3DRmBjvsg4KBfDzXT1ZmPp3o oKkA== X-Forwarded-Encrypted: i=1; AJvYcCUS6xK7aSDUJbezq0Rx/atnxOlxQaOpMgIQlRoiyCdf4EXv10p7jtcdr9/B6pF9mL2F/6lNu8Kgfrs8ZK6F2vcxgkg4USuZkCrq2gFcRwOHVBNEcCM= X-Gm-Message-State: AOJu0YwSjIs1rEVrBAoz5++6xg40V66N78q4m8QohZrb57r49KJqJH+m 6ea6to/TRvpdlZQTOARW686JKBqB27fkEKzMeveyjcIcf7zTn4h+3iSMFqCovAWuajv4RUvCFpk /JA== X-Google-Smtp-Source: AGHT+IHwPJ/UM6h8kXfIVs09j5bz4zlDvOcU2rq/epWSbhMGMPOGMhlwxlAMNu8ktgd9HGr+mJ5fl7Shz2c= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a63:360a:0:b0:7a1:4462:412e with SMTP id 41be03b00d2f7-7ac8fd30864mr2218a12.9.1722038048851; Fri, 26 Jul 2024 16:54:08 -0700 (PDT) Date: Fri, 26 Jul 2024 16:51:53 -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-45-seanjc@google.com> Subject: [PATCH v12 44/84] KVM: x86/mmu: Convert page fault paths to kvm_faultin_pfn() 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_165410_456707_FCD3515E X-CRM114-Status: GOOD ( 14.58 ) 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 Convert KVM x86 to use the recently introduced __kvm_faultin_pfn(). Opportunstically capture the refcounted_page grabbed by KVM for use in future changes. No functional change intended. Signed-off-by: Sean Christopherson --- arch/x86/kvm/mmu/mmu.c | 14 ++++++++++---- arch/x86/kvm/mmu/mmu_internal.h | 1 + 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index 7e7b855ce1e1..53555ea5e5bb 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -4369,11 +4369,14 @@ static int kvm_mmu_faultin_pfn_private(struct kvm_vcpu *vcpu, static int __kvm_mmu_faultin_pfn(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault) { + unsigned int foll = fault->write ? FOLL_WRITE : 0; + if (fault->is_private) return kvm_mmu_faultin_pfn_private(vcpu, fault); - fault->pfn = __gfn_to_pfn_memslot(fault->slot, fault->gfn, false, true, - fault->write, &fault->map_writable); + foll |= FOLL_NOWAIT; + fault->pfn = __kvm_faultin_pfn(fault->slot, fault->gfn, foll, + &fault->map_writable, &fault->refcounted_page); /* * If resolving the page failed because I/O is needed to fault-in the @@ -4400,8 +4403,11 @@ static int __kvm_mmu_faultin_pfn(struct kvm_vcpu *vcpu, * to wait for IO. Note, gup always bails if it is unable to quickly * get a page and a fatal signal, i.e. SIGKILL, is pending. */ - fault->pfn = __gfn_to_pfn_memslot(fault->slot, fault->gfn, true, true, - fault->write, &fault->map_writable); + foll |= FOLL_INTERRUPTIBLE; + foll &= ~FOLL_NOWAIT; + fault->pfn = __kvm_faultin_pfn(fault->slot, fault->gfn, foll, + &fault->map_writable, &fault->refcounted_page); + return RET_PF_CONTINUE; } diff --git a/arch/x86/kvm/mmu/mmu_internal.h b/arch/x86/kvm/mmu/mmu_internal.h index a5113347bb12..e1f8385105a5 100644 --- a/arch/x86/kvm/mmu/mmu_internal.h +++ b/arch/x86/kvm/mmu/mmu_internal.h @@ -238,6 +238,7 @@ struct kvm_page_fault { /* Outputs of kvm_mmu_faultin_pfn(). */ unsigned long mmu_seq; kvm_pfn_t pfn; + struct page *refcounted_page; bool map_writable; /*