Received: by 2002:a89:413:0:b0:1fd:dba5:e537 with SMTP id m19csp277899lqs; Thu, 13 Jun 2024 09:44:03 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVs3boQG+L9NwG+EkmjNF0P7i0B3KHPxRS5nddcD0Iqu6TtRDb03m97PUX/z1HlZ6JmSLsEanunu/C3IzpXhuHa37s4PCpC94UPCtny8g== X-Google-Smtp-Source: AGHT+IFGZQOdm2WwV/Am7BH6yQipfnb1ies8Av57EdQ2eWfB56E24w3Af8RY2Ga5NOdtbuRoK/IW X-Received: by 2002:a05:620a:4628:b0:795:532a:addd with SMTP id af79cd13be357-798d23c4411mr5964885a.3.1718297042914; Thu, 13 Jun 2024 09:44:02 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718297042; cv=pass; d=google.com; s=arc-20160816; b=GXwLCBXWE9jrzD5jZODxg4jaKml655Ur0P17tu1soUyqB+NNxRNHYKzDny9NzMqrGM s/Vc1yJXNsuZpWt6RKvMHN/ete5YZkt3gWJMPHYlQK/O5PICRw1p+wCi2wGlaJ0QdVa/ PkzV+DD+L0FEzd3UFPT8t08Og+afS9Z5GZySn857D4DfDB3FiqbJGdWBsYqajQIvGu89 qVP5MYeJ3V4YzQxWicUKuoHTV7RWsevMYWrhMCYyaeIRGNoWy3YwS8zV7I2Ag299+oiA nLx2/dgetVwYFe8lsN0JlbUvQO8k+UQ0wsxy1DuWMqr7zte4mnWBVwJNU1RpHpo2xxEu pb+Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :dkim-signature; bh=bxjiAwnYIG7/luxCNc9XCi7cU7Sed/5iGmGsAhazkBY=; fh=WH3u+jgURlmgB0AYtETLe52HXXtrH01/xD2Tnacscuw=; b=zoWJtehpHU0qTKhy52tj+W9k5X2V3eSIAz4Bsutb+wtBW5BpPN6Pb9Xj6y1pv8SJqb AKE+bnaJ6mF0uorub9mX/RC6VLrABnVzd6srmc/9IzTGfxdnjLwqtq/1cu/zEeUw1Bop qon9qSoksg1TSI2m4y58jsAG+SExBpEie1e7BaisTw0ds7Cx5P5EsDhQPHl3137qVUZS RZr5xj6YsMIAP87Eou65EdLLSQbjlFQlWwVb3GMfBXvKirKp3VYFs+prcBW4trWMxZhz EHLLLrX+LyoNdvlfmmd6Y5jpC1AaDSTQp2b2B5DT3HOnVezzDH6R6Q+6WyR6xpf4QMOZ MPiA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=UTmvtuSy; arc=pass (i=1 spf=pass spfdomain=flex--seanjc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-213668-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-213668-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id af79cd13be357-798aacc2ffasi186153585a.163.2024.06.13.09.44.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jun 2024 09:44:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-213668-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; dkim=pass header.i=@google.com header.s=20230601 header.b=UTmvtuSy; arc=pass (i=1 spf=pass spfdomain=flex--seanjc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-213668-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-213668-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com 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 9CB9A1C227AC for ; Thu, 13 Jun 2024 16:44:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 84CBA149C4B; Thu, 13 Jun 2024 16:43:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="UTmvtuSy" Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5440812D757 for ; Thu, 13 Jun 2024 16:43:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718297022; cv=none; b=OzXQzFpzgWQiJhijzhWSs3IBWdutHMXWFCHnyaAmw7/0DQtmGlVocHTyW1sa+nmESKgaTmciD9tbXUx8hY2BV6ynhXT4dodlI2wYvKvM4oxFWTZoUGMstP6vh3f8MMUh9FldWhAhuliO3Jt4wPVJml1FBdn+W+9JV9hybnhh28s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718297022; c=relaxed/simple; bh=Mez2tR7LHp61PQ+7LTtQTabYS9beKcDIfS/XBjc8Prg=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=KHKwMDviL3U3YlYLmCyrt4RYmFcFu3Wx8PGljGquYAfCtyn4c5As+ayODkt50+r0rXW/SgIF0muHqeH+9K8MxQBi58YaFiVVckT6wuPQqLj/hIFyjwFAnZwn2/xOqAEH7MwbKSdKxizbT4r6iYwwdyk8p1HEw35iI5gXKahe6XA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=UTmvtuSy; arc=none smtp.client-ip=209.85.219.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-dfa73db88dcso1771792276.0 for ; Thu, 13 Jun 2024 09:43:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1718297020; x=1718901820; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=bxjiAwnYIG7/luxCNc9XCi7cU7Sed/5iGmGsAhazkBY=; b=UTmvtuSyEysg7WUL3TFNRubIr5PQuSpKq2aeJNOk7tARaJRwE6FytWLmWYGZtjONDY tdXZpRiKf3r3dL6Yw/hVfRMvzTjkYxTbAFo7xeyBpHz2ckwcal1DAadOTC1P1xS7CPbW mVzKg/SZHlcrlgMwEWWX9TXA3sfWtGFoNgW/wk4ZrGWASbYhkSA/auDOtOJOW36jlwBV pmbxpxCoEoTGB+Kf61RL8yAfJUvEISQ/Rn673r1mgNG0GloLmLt5vcKdiBpzbtmL4gDQ m404kRMnIXhL6BtlRTGClBd7jWQd/6a8YP8Vz6N7AoE4TSD+aHKRCFWWPtzT4mMF4Nhl uHWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718297020; x=1718901820; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=bxjiAwnYIG7/luxCNc9XCi7cU7Sed/5iGmGsAhazkBY=; b=UmJc8Q+IuTFUZ/J0lyaz6s7lz2zpEXmiqkho8PBgCN1Q5NNIVUPT2f8Eq4P+ZhfgTz p/Fa4Vf/WAny6E7krH9MUe93Acwd1WL4BpKJLHEjd6q+DCbskQfBDwjXHxFPfNY6G0pb EFHe8kDYwcl0dssHa4IpEuhyoWTLTXxwXKdBOMNZcLwp56JkfdyQqYJyyERCZzpNDPAy cQYllMGXNLaTFGGPYZkuNdLCI0I4ys4sDnLYKnEpbbRlmMbgw+HlNJPXUwVLUGZrXqTg 3U279/DhNgSHjV4vz8jOaPfDGFEaPaYh6FaB1v18/hBGguM0mCgfuEgMWL+MyTDmbwco OrUg== X-Forwarded-Encrypted: i=1; AJvYcCWm2cLV3M/LVEyUP5uTaV72kQYTTpTsL9i7l/iBAhKuOTB2FMV4K6nC0gW7ZyRlSGzmt5pLDoHgKlVUucgDfAw2sN4CpMCoTEiE9/6C X-Gm-Message-State: AOJu0YzVNgFxKZBR+s6f+4p+V557SHRpd7iil4MIcsuHpN9pkCLOHWj/ AJzq4TeoBE467GvNa8lq7vpOs3tJi8JmvaoR9sO0SGURs2VjXnbUZy/PSOYL2qRq/FbV9CNnUJ+ 7TQ== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6902:18d0:b0:dfe:ed69:7861 with SMTP id 3f1490d57ef6-dff1535946emr370276.1.1718297020402; Thu, 13 Jun 2024 09:43:40 -0700 (PDT) Date: Thu, 13 Jun 2024 09:43:38 -0700 In-Reply-To: <20240613122803.1031511-1-maobibo@loongson.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240613122803.1031511-1-maobibo@loongson.cn> Message-ID: Subject: Re: [PATCH] KVM: Discard zero mask with function kvm_dirty_ring_reset From: Sean Christopherson To: Bibo Mao Cc: Paolo Bonzini , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="us-ascii" 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: 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;