Received: by 2002:a05:6500:1b41:b0:1fb:d597:ff75 with SMTP id cz1csp60567lqb; Tue, 4 Jun 2024 05:15:14 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUT8vMaqMF9oRoVxpD4HGQP2RxQJDtbjJF9yp3DWsKe+DsCCZpsrQgcB4+pW7B4tpgduJYQPMJZgm3AI0lP5Q8OY+uUX1VmirmbfCgOoA== X-Google-Smtp-Source: AGHT+IHwuQ202ocZUUSHw3bl//ItAqlGwO5vaRG+Wb9sl5Z8kLleBdKn7LNasxJ+rgqGcCaVT2ek X-Received: by 2002:a17:903:2448:b0:1f6:673c:ff2f with SMTP id d9443c01a7336-1f6673d026emr82116305ad.68.1717503314540; Tue, 04 Jun 2024 05:15:14 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717503314; cv=pass; d=google.com; s=arc-20160816; b=d9AyQY8+Sma6mN50U1HvdXh41d/j9boCjq83gebhU6OeQiVuogLQtFjbuz0kPhNE7i xSYF5iEnKxL1+R7EsERdfUqMRKBnSSS+J71pGcPHXfL5Aw6ap0CpQAM++lIpYmqqlCgd v22bx9TyBtHKNfAlLF/z4zWXddD69cuq6m3vmsNpF6KHMm+vfiLOav3dWCWhY9F4LHwZ +A5cjir5057S1v2EfTw1+k1OehThHlkwmL3s2csvT28x/iSYiZXK6JZ8YmB14jJUSqCg CaF3+n8WcZf1RRpGKk/loVWSZ2FlpIDrIlQUc9IIOQBbiv87gYzowATuBDR3QvuHcnda vMXw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=uEzEt5w5TiJi0WycAaU8ZIY8vFjYd4wGSW3bQxvFd4s=; fh=JOrDXAv7dX9lqUsWenmIinruxsV5NNS7FV+l4Q4onAY=; b=kZSnecL3PBu1t0LLR2ntTZxdbIvkXIHH3cLxFXJVXNfeYy+6kha8h3439YZuZUTVya d+arObQXqr8w8UoanaZIfcodCf1SLbC7ij5jniRDgaHR+h5CxFR0Ic8wEG2vLxVvrIUm YybtOK890/s3Flj45HIu2x72frKsT2IlMTNdFTlV9mF7v/TPEiLIQU2k28E6tdRnzjBL uuVvcbYF0UC8XJEMbiWW+Rof5CzTHZiH161k07l0K0A+5K7sN9QFOcWtLV5oAaeHeUB6 xI4DxO7kTrEM9Rer4mpqGE2uumrLhWVEpOO5UFiwY0RwZDM0LhtCDwcSzM6GDiLBDm25 2L2A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=loongson.cn); spf=pass (google.com: domain of linux-kernel+bounces-200573-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-200573-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id d9443c01a7336-1f6323eb061si83647355ad.372.2024.06.04.05.15.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jun 2024 05:15:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-200573-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=loongson.cn); spf=pass (google.com: domain of linux-kernel+bounces-200573-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-200573-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id ECDA5281FA2 for ; Tue, 4 Jun 2024 12:15:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A6F2E146005; Tue, 4 Jun 2024 12:15:07 +0000 (UTC) Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6489B145FF6; Tue, 4 Jun 2024 12:15:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=114.242.206.163 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717503307; cv=none; b=K5aqyTpAFLcMjhGRNshWsZ6FrbTdUHDphcg/E6fXacHcbAM0x/92aAeyK3Fthu8j2YNd+8+ZwDh1FDPK071Eoe71z2BrfpZw5gWtEmEYzY8I3bzw5lERXe4GJhtCvmojGJaEoCMRcxySlF8iG9wiFpwVKToHeVqwvxgUrZlzEuM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717503307; c=relaxed/simple; bh=WFVQjWH0ZoiMDGK+S3K+zIY7KmR/jPZqZ71uWqigK70=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=fW2+FXujkGYgRXKEEJQAlVYsShIBfA1d4QpvYe2vTVzU9SGdsRz9DQiG+kK01v9IbcjekghhKc0Hb4HLo/qLc9wknuYxrkFAW1SFxIji/dlKMN5/eAjSmuYpEk8zNBqrfVEu1pKswmbI0ou53jbSau/CdQFzmKGkQYFNybFdN3U= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=loongson.cn; spf=pass smtp.mailfrom=loongson.cn; arc=none smtp.client-ip=114.242.206.163 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=loongson.cn Received: from loongson.cn (unknown [10.2.5.213]) by gateway (Coremail) with SMTP id _____8DxSupGBV9mXmEDAA--.14543S3; Tue, 04 Jun 2024 20:15:02 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.213]) by localhost.localdomain (Coremail) with SMTP id AQAAf8AxDMdGBV9mFzkUAA--.50896S2; Tue, 04 Jun 2024 20:15:02 +0800 (CST) From: Bibo Mao To: Tianrui Zhao , Huacai Chen Cc: WANG Xuerui , kvm@vger.kernel.org, loongarch@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH] LoongArch: KVM: Discard dirty page tracking on readonly memslot Date: Tue, 4 Jun 2024 20:15:02 +0800 Message-Id: <20240604121502.1985410-1-maobibo@loongson.cn> X-Mailer: git-send-email 2.39.3 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID:AQAAf8AxDMdGBV9mFzkUAA--.50896S2 X-CM-SenderInfo: xpdruxter6z05rqj20fqof0/ X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== For readonly memslot such as UEFI bios or UEFI var space, guest can not write this memory space directly. So it is not necessary to track dirty pages for readonly memslot. Here there is such optimization in function kvm_arch_commit_memory_region(). Signed-off-by: Bibo Mao --- arch/loongarch/kvm/mmu.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/arch/loongarch/kvm/mmu.c b/arch/loongarch/kvm/mmu.c index 98883aa23ab8..ec8c43aad724 100644 --- a/arch/loongarch/kvm/mmu.c +++ b/arch/loongarch/kvm/mmu.c @@ -444,6 +444,17 @@ void kvm_arch_commit_memory_region(struct kvm *kvm, enum kvm_mr_change change) { int needs_flush; + u32 old_flags = old ? old->flags : 0; + u32 new_flags = new ? new->flags : 0; + bool log_dirty_pages = new_flags & KVM_MEM_LOG_DIRTY_PAGES; + + /* only track memslot flags changed */ + if (change != KVM_MR_FLAGS_ONLY) + return; + + /* Discard dirty page tracking on readonly memslot */ + if ((old_flags & new_flags) & KVM_MEM_READONLY) + return; /* * If dirty page logging is enabled, write protect all pages in the slot @@ -454,9 +465,7 @@ void kvm_arch_commit_memory_region(struct kvm *kvm, * MOVE/DELETE: The old mappings will already have been cleaned up by * kvm_arch_flush_shadow_memslot() */ - if (change == KVM_MR_FLAGS_ONLY && - (!(old->flags & KVM_MEM_LOG_DIRTY_PAGES) && - new->flags & KVM_MEM_LOG_DIRTY_PAGES)) { + if (!(old_flags & KVM_MEM_LOG_DIRTY_PAGES) && log_dirty_pages) { spin_lock(&kvm->mmu_lock); /* Write protect GPA page table entries */ needs_flush = kvm_mkclean_gpa_pt(kvm, new->base_gfn, base-commit: 2ab79514109578fc4b6df90633d500cf281eb689 -- 2.39.3