From patchwork Fri Jul 26 23:52:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13743545 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 6217EC3DA49 for ; Sat, 27 Jul 2024 00:23:56 +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=8WWxSeEhwRY8Kz5lKN5dweAMeNFVe6itBQweyIKsQVg=; b=4kt+/d8E3JgY9qq+/mhiUkqGUx oHS0658Q8BsnqSQN7aE+HEnaITrT3skkE4q1yMUdJRhRQIAD7AFnrjZvR2Df4Or18Csq9vCFGeFoT Ky347/S83vO/D82X2WRSZiGZIjxp6l7gmlYU8abIJ0DgEZMRWt33CA6qFm3J1/N6zT2Uw5vHNq6z5 nxX+M/Y5VKPnqCEbJDQwlu9MV1FLPwy/yCMJeWB6PR7h8AsIwLZut9R4GtajhJip0FQ8YoW9yh3xn 6s9LsJUMWeW8s9LApRcsFdN+HOgdoDTSyEaugAdxC1lOOb5tOmXUMBRFGFWKlX3NR2LZOoDIPA9E1 qD0tueHQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sXVDs-00000005flV-0ZO3; Sat, 27 Jul 2024 00:23:44 +0000 Received: from mail-pf1-x44a.google.com ([2607:f8b0:4864:20::44a]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sXUlh-00000005Qkp-2scc for linux-arm-kernel@lists.infradead.org; Fri, 26 Jul 2024 23:54:38 +0000 Received: by mail-pf1-x44a.google.com with SMTP id d2e1a72fcca58-70d14d11f42so1334369b3a.2 for ; Fri, 26 Jul 2024 16:54:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1722038077; x=1722642877; 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=8WWxSeEhwRY8Kz5lKN5dweAMeNFVe6itBQweyIKsQVg=; b=gUINzmv3ccwPURuliTih7NZtM154wXvsdSsrcafg+DMUmCf4ubpEHFwzZ05zre7bTh hrS5r72dQVe4ry6XCpkWWN2tEcgyx1OADXToRRHJUfR8qXlmq3iN31aRq+taolnPt5gW uL1ZlmyxVfCLD014XsrVbKzEjXs3Xjb6VKo1vV1q1fEtfLbRUdufKsHYHACmV3Ipp0kC UQWjJS8enQt7lX5Sh1bNa/dygf/L8ljU5U8tvLht0KfAiQoA++7cAHJfU2M7g93az7nz ibGjXPVRk4tFkZVXDCLsOGyJbLhlzcOhXbm0lk5GVtsUOQiWUlU9SdjcpKDY5dMTu6U6 9e0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722038077; x=1722642877; 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=8WWxSeEhwRY8Kz5lKN5dweAMeNFVe6itBQweyIKsQVg=; b=YZSLU78Ra1I+uDK29HmHpFY4AtNzCraFYuOrZioKkmsFkwM/7TpJfcDDazEuEfq2HX mFSxI2oEOlX8UD9rtC0SPK7AJ59EDMJJ2nfskXQ1j/nQzG64UjQjmqszRrSWaClFoKXU AQ0BJG060nmwMw3rx10tvZtg+PLP62XmKQ4CXk2SggVgIGE0fAwfm69nQ7bjpy7gNOkq JFertuCC8bNwjX+nZv2FsSienDfx93DzdhdVk7kKKUn321lrCOvVCAphfrjfbUxtVoa2 b/U6Sfpz0gcq2FLVM5wsgNbTenNlzqeJdvoRDa8AFC0EOK/2hZi5Wq5hTMZCe017H+st Bhhw== X-Forwarded-Encrypted: i=1; AJvYcCWTXbECd7H4ptBrMPK+q8kIpMFBCYTgfz4H6kiS63ho3LNATRTbjn2praAi2Qs+GVLXNtNOqW80opOwRTzRvke1Ml/mkbZzns9l3ngfqd9mkUlEu3c= X-Gm-Message-State: AOJu0YzoO+MaSrG+blGNiqOeTGezJjD6NIB1uvSFApGaIQ3GS1UL/I9n Emcv5QsKUNQJRc7f7DsToeTBWxUnv4a8KfWdOW+Oue3fkajNL8n6eZqM2bUvRSsni4itEy5+PKb gCA== X-Google-Smtp-Source: AGHT+IFil497nfsH36PcPgD5gbB02jEmsX2CuGy2fe2s5ytKElT5nFsSQdr9eHlR2IIEavfJT4DgKyMZ3iM= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6a00:66e5:b0:70d:1e28:1c33 with SMTP id d2e1a72fcca58-70ece9ecd04mr10022b3a.1.1722038076443; Fri, 26 Jul 2024 16:54:36 -0700 (PDT) Date: Fri, 26 Jul 2024 16:52:06 -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-58-seanjc@google.com> Subject: [PATCH v12 57/84] KVM: RISC-V: Mark "struct page" pfns accessed before dropping mmu_lock 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_165437_745962_D97D4A04 X-CRM114-Status: GOOD ( 10.99 ) 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 Mark pages accessed before dropping mmu_lock when faulting in guest memory so that RISC-V can convert to kvm_release_faultin_page() without tripping its lockdep assertion on mmu_lock being held. Marking pages accessed outside of mmu_lock is ok (not great, but safe), but marking pages _dirty_ outside of mmu_lock can make filesystems unhappy. Signed-off-by: Sean Christopherson Reviewed-by: Andrew Jones Acked-by: Anup Patel --- arch/riscv/kvm/mmu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/riscv/kvm/mmu.c b/arch/riscv/kvm/mmu.c index 06aa5a0d056d..806f68e70642 100644 --- a/arch/riscv/kvm/mmu.c +++ b/arch/riscv/kvm/mmu.c @@ -683,10 +683,10 @@ int kvm_riscv_gstage_map(struct kvm_vcpu *vcpu, out_unlock: if ((!ret || ret == -EEXIST) && writable) kvm_set_pfn_dirty(hfn); + else + kvm_release_pfn_clean(hfn); spin_unlock(&kvm->mmu_lock); - kvm_set_pfn_accessed(hfn); - kvm_release_pfn_clean(hfn); return ret; }