Received: by 2002:a89:413:0:b0:1fd:dba5:e537 with SMTP id m19csp108477lqs; Thu, 13 Jun 2024 05:30:45 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVYTIt6uKRlhaqBy3uR9WpwuabGuklKEz8ISbiR36hBp1qSSOf0ZHRZdKYacUQUs73zDsSqjKuwIInjdUeNmvQ+S/lTA0/hiImwbpLq7Q== X-Google-Smtp-Source: AGHT+IFHsz9tsy0zyzbLrrQ15BL8gLoWmaWjqUA02ceQBfC9Yj9qiErLIPA6VV7mAIHlq8hHcZim X-Received: by 2002:a05:6a20:d48f:b0:1b7:ad9:1a06 with SMTP id adf61e73a8af0-1b8a9c82277mr5662341637.60.1718281845665; Thu, 13 Jun 2024 05:30:45 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718281845; cv=pass; d=google.com; s=arc-20160816; b=FSPjCOnbibTBZ2SLL+bEsD9aqbfJrrW7ITM3kRQOU6SIdEbIuY0a4qTwINeDLOwtQE bKK5bT/5w0sBtpbm+RBjA0bccSD8DiiM/Y/C1xsAjBlc+ODk4LI3n9sa3YMcwqsG/Hhx w0S4fuY35pHa+Swgv8N31yv77/Zv6guexFf8tKYPk8adUHgP8wFGmr9IWtMylK0VOWo2 Otec4WsXvlJAtVYUp6j4i4rFB+kqmdsXz8BhtCN5WcgN6/GFfKzgC9vmyXOH6a4Pl4A4 98FS7z3fFdO+aC2JXCy/88RNGRCU2d8+ICTGPG9WogXsoIhOvBR2JNxGUNskQz1T1clo GXZg== 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=vnk2quL6dbuOt6us59LzsPqm5LKNBHBGZyxC+ARGI3A=; fh=f7vpHwWVnc1Gm69Jh4Dv0SPVMxn3OzCXH/wd4ss2rUQ=; b=H1akLxEi30kots2vcZ+qQnodRbNuzYwIHFmODtVd60FN+0U7vGLWRpHBf5GC+5UH19 VJkJB2lixkiDuw+DmgxYcxlyD095BxyoxXKjs3TYlslN3r5AR8Tz+/Y7jtEt6db4sLHV EPUBRDp3N+sLLiGvPAZ2n8wUtFE6Z1/YkBUVyn4Q66ZmqyK/ROVlOnIbAjVBQqPGENNO /Cn0SiQZrOvyXXxjUrf3Pv7Gyojq3zU1IYwHNjrG14myljdBBb7qtJtDAwlowV6msRD7 gJqZQQMLeKUSM/pxWS+ln2oNxVnFAz7kmHT27hlaX1KJXTsCujKqOGIbT1VHUUVdVsMS 8Nyw==; 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-213199-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-213199-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 41be03b00d2f7-6fee4167a32si1191004a12.447.2024.06.13.05.30.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jun 2024 05:30:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-213199-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-213199-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-213199-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 98C5628600C for ; Thu, 13 Jun 2024 12:28:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 06783143C67; Thu, 13 Jun 2024 12:28:10 +0000 (UTC) Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CAEFC8614D; Thu, 13 Jun 2024 12:28:05 +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=1718281689; cv=none; b=eUtz9rEsPmSM0YjF/IpAIYWItvOyscnEs+7ZBTrauiIo2GJWxHGE0BoJwzucYuOyvsolP2Tud/U7Q5wNVk/88kJghrtcrVT8Uwj90HzRmeeWEiK7kYlrxBHhnq3p/tsbe+GaogTYSDe3WtnIBTceqBC0pbCbz6qhTtkDa0TQIxo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718281689; c=relaxed/simple; bh=t+YxrqktIQ1UgUE74tLuPrJjYqGy3UZK/hCvf3JLA5c=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=ijsgbmzA/QKahcMJ7pcKUa/82i2/+Yl84P15WICGJebTDcXr8cnYxMHqTatL/dQOKsHqTp1i0GRB8qq0C5QfZr1tVi9cIk5WM09BQMRL6GW6wZH4fFZG3AeYsfXNN534CEv4bTUcGgWNskDLZeDgf3QlxL/YM6OcjaIGJQquRaA= 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 _____8BxrOrU5Wpm1oEGAA--.26381S3; Thu, 13 Jun 2024 20:28:04 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.213]) by localhost.localdomain (Coremail) with SMTP id AQAAf8CxacbU5WpmB7UeAA--.9477S2; Thu, 13 Jun 2024 20:28:04 +0800 (CST) From: Bibo Mao To: Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] KVM: Discard zero mask with function kvm_dirty_ring_reset Date: Thu, 13 Jun 2024 20:28:03 +0800 Message-Id: <20240613122803.1031511-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:AQAAf8CxacbU5WpmB7UeAA--.9477S2 X-CM-SenderInfo: xpdruxter6z05rqj20fqof0/ X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== Function kvm_reset_dirty_gfn may be called with parameters cur_slot / cur_offset / mask are all zero, it does not represent real dirty page. It is not necessary to clear dirty page in this condition. Also return value of macro __fls() is undefined if mask is zero which is called in funciton kvm_reset_dirty_gfn(). Here just discard it. Signed-off-by: Bibo Mao --- virt/kvm/dirty_ring.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/virt/kvm/dirty_ring.c b/virt/kvm/dirty_ring.c index 86d267db87bb..05f4c1c40cc7 100644 --- a/virt/kvm/dirty_ring.c +++ b/virt/kvm/dirty_ring.c @@ -147,14 +147,16 @@ int kvm_dirty_ring_reset(struct kvm *kvm, struct kvm_dirty_ring *ring) continue; } } - kvm_reset_dirty_gfn(kvm, cur_slot, cur_offset, mask); + if (mask) + kvm_reset_dirty_gfn(kvm, cur_slot, cur_offset, mask); cur_slot = next_slot; cur_offset = next_offset; mask = 1; first_round = false; } - kvm_reset_dirty_gfn(kvm, cur_slot, cur_offset, mask); + if (mask) + kvm_reset_dirty_gfn(kvm, cur_slot, cur_offset, mask); /* * The request KVM_REQ_DIRTY_RING_SOFT_FULL will be cleared base-commit: 83a7eefedc9b56fe7bfeff13b6c7356688ffa670 -- 2.39.3