Received: by 2002:a89:413:0:b0:1fd:dba5:e537 with SMTP id m19csp547118lqs; Thu, 13 Jun 2024 19:58:33 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUK9MYESjXEB+nls64Tf51ejf9U6N+r5wg+6oQYpaFDt6TuL7TNBMr+8OCjtYgSx3bw2wJXDrSSaVqpSIsBTqzGy6/8ogZthmde8hd9tQ== X-Google-Smtp-Source: AGHT+IHigeTlliUycu8Z7WeEnOd80nQjs6fFu/B2Ad6aff3IJ3eE9gouPNjXCfFanXnubUuQTAJF X-Received: by 2002:a0c:c68d:0:b0:6b2:b060:c7d3 with SMTP id 6a1803df08f44-6b2b060c874mr11875726d6.52.1718333913365; Thu, 13 Jun 2024 19:58:33 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718333913; cv=pass; d=google.com; s=arc-20160816; b=WNZ0IL86fQGBJgNTHrIoMaOHfIN4NhUfr5HxOOKnpVnxnXQqodSvCPIXG7dCLBlMBI oru1/jxVXx2wQZqFRsABYn6sl4R6FLLE+i2enXbKeTV9ciO0wQyQWEtS6KuOO0567G8h DcbhLCI2qQ4AudPj5FvBcQSB7YCTejlbuM6o2GL5OrkatxPUjCwljMmjWdYN/DYaMa0R rpH0d65nVaEHwjdVUdBLKofPaKl8cSNuB+5V1trVXh1UUF0qZHBzH0VfQF/f+W1NhxaN ENUnMvk/CPH0fYmwVFTnI1FVDriM5RchC84z6a58+bPYII+Qq3uwuBylecz33vbU1jgD Qckw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:content-language:in-reply-to:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:user-agent:date :message-id:from:references:cc:to:subject; bh=W8Dw9QKQzxk9Tku9p9OD16dyZhtrZhkVGlZUXD8e/4I=; fh=IczE/FYqinQ7k7O3D1SswHC93QrfXqbblVYzr34TRlc=; b=lvXmtcN1TlCz2tJe7dNRsIQ4LzSOLC49a9hsFptq+qGXFyKBzZV2558tEWoRoK0voX E6l0aVZ4sIj4hfqgLAFm8aaIGkNR+WjP1aRvvJqyyjX7KqUg9NZsx58HI+E+FQeZt7NK FU1s20kJZ2Yc6yUxOm2aABU0oVQuIhuvA7AuThzpt0SXpTvx/qZ6CyQqB9ZPL5v67sOg Ghjswm3HH4c0kY1StKXqnxgKQlfyRAf+6CVALRp5aaGQIYTvr+o/A5qBu/YD4kGJmlgF z+J+K5CxN8NP4+x6w7shISkhAln1PS0wPMu29QasZTdLkxlEZ+dzAgQkAp2Qj+Hm8W5i 2mVw==; 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-214276-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-214276-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id 6a1803df08f44-6b2a70d80f9si26542466d6.179.2024.06.13.19.58.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jun 2024 19:58:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-214276-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=loongson.cn); spf=pass (google.com: domain of linux-kernel+bounces-214276-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-214276-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 1A3F61C20995 for ; Fri, 14 Jun 2024 02:58:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8005C1836C5; Fri, 14 Jun 2024 02:58:18 +0000 (UTC) Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1606D801; Fri, 14 Jun 2024 02:58:13 +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=1718333898; cv=none; b=s4BVW3oOg7fUduZ8LmGZ7p9VDR8Zpyi4Gq35oQN4Z1p2W2Dogtpdv/iC9YNK01VvHWQ5lSqvGpO6pw9Z58UwbhYJzkbRf/S5cHzFdKmTD2lYDO17vuA8GIm5XGliqZ/DoS4EugW6+JVBWEZ4+0mrAsb6Gm+NnNFhDNid/bRNoTU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718333898; c=relaxed/simple; bh=/qaUwTmFTohtImbhL/sGW1eeZWtwNzwPZFtjccd2G7s=; h=Subject:To:Cc:References:From:Message-ID:Date:MIME-Version: In-Reply-To:Content-Type; b=YLWzsc1gYdlK64nb3o25vf9vmvwUbJTKOS96JcLKKZ/4n3PK1K+yW9l2LYYXATKzpeOTdfS4X3pOOeVOGvTIXPE5aFvQathPrpWHwJdU3kQjSHNGIghoARmsezhIBbBEHtTWeyOxQhRbdff1ZuGnZkRUR/S+domw55xwr5q1qGE= 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.20.42.62]) by gateway (Coremail) with SMTP id _____8CxvOrDsWtmKMEGAA--.27070S3; Fri, 14 Jun 2024 10:58:11 +0800 (CST) Received: from [10.20.42.62] (unknown [10.20.42.62]) by localhost.localdomain (Coremail) with SMTP id AQAAf8AxDMfBsWtmRakfAA--.12078S3; Fri, 14 Jun 2024 10:58:11 +0800 (CST) Subject: Re: [PATCH] KVM: Discard zero mask with function kvm_dirty_ring_reset To: Sean Christopherson Cc: Paolo Bonzini , kvm@vger.kernel.org, linux-kernel@vger.kernel.org References: <20240613122803.1031511-1-maobibo@loongson.cn> From: maobibo Message-ID: <3cf851a2-be51-f227-82a4-090de01bc8be@loongson.cn> Date: Fri, 14 Jun 2024 10:58:09 +0800 User-Agent: Mozilla/5.0 (X11; Linux loongarch64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-CM-TRANSID:AQAAf8AxDMfBsWtmRakfAA--.12078S3 X-CM-SenderInfo: xpdruxter6z05rqj20fqof0/ X-Coremail-Antispam: 1Uk129KBj93XoW7CF4fKr43CFWxAF1xWF47Jrc_yoW8Cw17pF s3t3WkGF4Svas0g39xAw1DXrnIv392qFykJFyDGw4DK3sIyr15W3WUta40vrnruF1xAFyf AF4aqF47ZF17CwcCm3ZEXasCq-sJn29KB7ZKAUJUUUU8529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUUvFb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r106r15M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_JFI_Gr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVWxJVW8Jr1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6r4UJVWxJr1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqjxCEc2xF0cIa020Ex4CE44I27w Aqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_JF0_Jw1lYx0Ex4A2jsIE 14v26r1j6r4UMcvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvEwIxGrwCYjI0SjxkI62AI1c AE67vIY487MxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8C rVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUAVWUtw CIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r1j6r1xMIIF0xvE2Ix0cI8IcVCY1x02 67AKxVWUJVW8JwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Jr 0_Gr1lIxAIcVC2z280aVCY1x0267AKxVWUJVW8JbIYCTnIWIevJa73UjIFyTuYvjxU7Mmh UUUUU On 2024/6/14 上午12:43, Sean Christopherson wrote: > On Thu, Jun 13, 2024, Bibo Mao wrote: >> 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); > > Given that mask must be checked before __fls(), just do: That is ok for me. To be frankly I am not familiar with kvm common code, I submit this patch just when I look through the migration source code. Regards Bibo Mao > > diff --git a/virt/kvm/dirty_ring.c b/virt/kvm/dirty_ring.c > index 86d267db87bb..7bc74969a819 100644 > --- a/virt/kvm/dirty_ring.c > +++ b/virt/kvm/dirty_ring.c > @@ -55,6 +55,9 @@ static void kvm_reset_dirty_gfn(struct kvm *kvm, u32 slot, u64 offset, u64 mask) > struct kvm_memory_slot *memslot; > int as_id, id; > > + if (!mask) > + return; > + > as_id = slot >> 16; > id = (u16)slot; >