From patchwork Fri Jul 26 23:52:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13743544 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 E6B1CC3DA4A for ; Sat, 27 Jul 2024 00:23:29 +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=EmJI7mCwitfWH+6LwHkJyXugWKEFSS3lkF1NSC2iA8Y=; b=SMNgEiEfreTVUYlua+pcoueVTX 5jfU5DxelvaLTGme9z1+3noiQqqPKa8TCUeHAtgG0SsRap+Ppe9Yd4Oz8C4YbD8nrZslH0hlYXLox 0H8T5Yk4U6UezONueYJXnLlx1K8ssOkkgkSqupYi+i6i+/eiVFMMcLwsUVnsyN1K/46CnY9cQpyla dTpvQ5mvKXkd7k0vydkg5fQd0G0w8ATSNXZzubA0cx/7SeP96h/vVsiuiU9PPt/ORIRqEPHD0jeDr Ide4zLkeZ4XQJ5V0hvijchKetJP4ppdE/kMm6iHjEnaAxuUEfojaMfi9garpF82g1dBzXnUPpeyy6 0CaprTsg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sXVDT-00000005fcq-2jWD; Sat, 27 Jul 2024 00:23:19 +0000 Received: from mail-pj1-x104a.google.com ([2607:f8b0:4864:20::104a]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sXUlf-00000005QjG-2ey1 for linux-arm-kernel@lists.infradead.org; Fri, 26 Jul 2024 23:54:37 +0000 Received: by mail-pj1-x104a.google.com with SMTP id 98e67ed59e1d1-2cb7364bac9so1380487a91.0 for ; Fri, 26 Jul 2024 16:54:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1722038074; x=1722642874; 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=EmJI7mCwitfWH+6LwHkJyXugWKEFSS3lkF1NSC2iA8Y=; b=z/sWPq8X0VYqLhknX9wnJ8pXC+1A7eAW2aJnlwjy8GR1ksgusnC8d3Yb1Huny3aFac AcUaSzDAR7VC+YPqYT3xPg789wnEtxX5ItNPiIFAU4F/tnWH1dBId8uvmpXq31g29WHf 95aAzf1GbIJkdyBKFP3XLYLig6eH9JMoweZ5GwVq3kw+ibUKp9L7wb3ts/13u73m4IeQ klaLUmKW3xsswtoFMkd/I728xnRThLuJIIEdpVSFfbezLZ+IStWfiBB+5kuV9ejmxVcg Fo1UV230/5WOg+ScK+qEBEjhOWG1qclEXxyvMaAW8IFYQmo900uqR5SyuF42EviuNDmO jDdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722038074; x=1722642874; 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=EmJI7mCwitfWH+6LwHkJyXugWKEFSS3lkF1NSC2iA8Y=; b=JB+/7EQkvVj+f1ueEBJse39dReVaa0VbZ33gqXUVj48p6X35RXmJWgx4+iZxTKhr7K D2VY9OZLJe55ZVrYnX2S8TltMipqjVgn4xs3lO16qZ0zk2RbY9RrTAGhGbaS53HgpJKY UDXUd/ByC8DOyG5BZ0vGrhTTuAovrFZU4Fgmkr70CZXzYEUIByzhXT/mVsw8EwlLpCgA CxB99V6CM3/Qab4Q0E/L6dfAfUaz8+vA62P2hjVoa/BPTHKgoVsWmoxyygWAzPuCDEEh lhMGT5/CeZqwNtbXc2n6p121JtM5UU9SNSJzD//jk04Fb42jV6WJCKqsE7k1d6bWK7wO vtbQ== X-Forwarded-Encrypted: i=1; AJvYcCWkEGIGKrbErqMhpvB6QZhbyFsSBYmj2Y6A1eb3yyt/3m0qp880iT8JK+FcImz/qnGNGgZsWJLruvqbOem/+F6R7TuSLoycqcQncMS0/W0vnFE03DQ= X-Gm-Message-State: AOJu0YwUjAOdg50r9gXd1nWhcrBl2ePz73IvECRWsPrAXH3bjn1Z392u zeQzJv1lhVDsCknfwQqjgEeynGBQCCLfetV+Zif7lRipHPXd6kioHyIyP4GoJrr1Yh6jtmJ229Y xAQ== X-Google-Smtp-Source: AGHT+IG4DskQJpICSO/7ZhzoCwUBvTBXkkJhFyAvydTVcsfBboV7ccXE3z2KESMy5r+D4xCglFGTF0FLhYg= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:90a:470e:b0:2c8:632:7efe with SMTP id 98e67ed59e1d1-2cf7d1673aamr10630a91.4.1722038073062; Fri, 26 Jul 2024 16:54:33 -0700 (PDT) Date: Fri, 26 Jul 2024 16:52:05 -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-57-seanjc@google.com> Subject: [PATCH v12 56/84] KVM: RISC-V: Mark "struct page" pfns dirty iff a stage-2 PTE is installed 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_165435_710603_E5721D23 X-CRM114-Status: GOOD ( 11.92 ) 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 Don't mark pages dirty if KVM bails from the page fault handler without installing a stage-2 mapping, i.e. if the page is guaranteed to not be written by the guest. In addition to being a (very) minor fix, this paves the way for converting RISC-V to use kvm_release_faultin_page(). Signed-off-by: Sean Christopherson Reviewed-by: Andrew Jones Acked-by: Anup Patel --- arch/riscv/kvm/mmu.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/arch/riscv/kvm/mmu.c b/arch/riscv/kvm/mmu.c index b63650f9b966..06aa5a0d056d 100644 --- a/arch/riscv/kvm/mmu.c +++ b/arch/riscv/kvm/mmu.c @@ -669,7 +669,6 @@ int kvm_riscv_gstage_map(struct kvm_vcpu *vcpu, goto out_unlock; if (writable) { - kvm_set_pfn_dirty(hfn); mark_page_dirty(kvm, gfn); ret = gstage_map_page(kvm, pcache, gpa, hfn << PAGE_SHIFT, vma_pagesize, false, true); @@ -682,6 +681,9 @@ int kvm_riscv_gstage_map(struct kvm_vcpu *vcpu, kvm_err("Failed to map in G-stage\n"); out_unlock: + if ((!ret || ret == -EEXIST) && writable) + kvm_set_pfn_dirty(hfn); + spin_unlock(&kvm->mmu_lock); kvm_set_pfn_accessed(hfn); kvm_release_pfn_clean(hfn);