Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp2187584pxb; Wed, 30 Mar 2022 18:46:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzljiNQmZHFZK6bzd5pE9eKbmrP3fnJmbMg8NiIg70cX7UlaXloIAw++xIQYdWf4V+gHERH X-Received: by 2002:a17:90a:2a8d:b0:1c9:f79c:926c with SMTP id j13-20020a17090a2a8d00b001c9f79c926cmr3270579pjd.80.1648691207391; Wed, 30 Mar 2022 18:46:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648691207; cv=none; d=google.com; s=arc-20160816; b=mxRxjAP6wgk2h/J0M0Tpo0ECM9rxmgGspM//vfZwVr6jhWR6/UgHlUJ7oUbUSb4wiq cuO5y2XP0SKGYu/2R3UZdd+KUddtMQKmry4PaadTm8cFXIlDiSLYtr5tBAgAqT09Dqux sIb1uvhCU7QVLfwg4t9fXwBQCZ8071rGBH5g/DW9QQ5twEaomdcHBkhTRKd7hXbIh49d cDlKfVrZ7EdRzPSHKGxqgZ8RdGaR/hKHyAfPZUG84FBy3cRxRgYpJXO1KEDWHJWsHZYx PV4MQQ608slK5BVwRnTpogm4LtBPWf4vb9fb+c2j9Gzfzu2P22+/Mb6/TP5kfiH6Dirj zIfw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=z8M3KAysw2cAlI5blF2AQCWcA3BO8/nSsMsedWb5w/k=; b=aa6l4ubHlXKMmqjwj6BJWtG3G5Fnnx8F0BM+VeAMVqoMEgdwozPqqucBcgl0OajUN7 3sYUOBsdR5kY2YrdNgG7GKTCEhN5aaKwK7/vPTA088nZCKQ0FpWLhb/3Z93hpMxJb0/3 5RY1dsQh6kc/JbYGYZpGUo9THNCwhR64Oiv8tDwhFDNWhwrLoWbHhB7K1Hrjgijc6hAj k4xMc16c/8/Yo+G2+/jaPYNlyr4qLvaz8bb5W7KS/fX7R2g3d+tEdx1qJKc2W5lm7BE9 NgPJpXAL5088UDPAlX7OC5lyWLWPGv8qnGBDB1MB0cXoz9LCusLj0jTaVxtxxDbXQxmN lQtQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=U0YUIk6F; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o26-20020a63731a000000b003816043ee23si21064955pgc.24.2022.03.30.18.46.31; Wed, 30 Mar 2022 18:46:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=U0YUIk6F; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244022AbiC3H6h (ORCPT + 99 others); Wed, 30 Mar 2022 03:58:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49102 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239731AbiC3H6f (ORCPT ); Wed, 30 Mar 2022 03:58:35 -0400 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6068DB39 for ; Wed, 30 Mar 2022 00:56:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1648627010; x=1680163010; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=QwwXpU5i2/ZnjurXHD4hkkWhEcts0d2cgS8JfDuixaQ=; b=U0YUIk6FFHTfJB2gaXhZheWV2lEeSOAWaSCBKsuv/ANGKWkEhn3Oj8CG jXYq7F8kZ6vMbt8MXW/Wo1WkMVOmb89qDN7sGs/4eTI6wCFME0Of9R4X0 KT1g8HliScbovAMJrc3O711DIVgBXqX0vDahWxNnOrUk2kMJnKjr2yikX 40R8GpBvzycCxIhMR79N1Bf7ZL22islgmhaTnI17dWaRC7C3vtvVrihrr hVawHdnoLz3wJoBvX/FFiIQLy+WaQErFc1XGwSlmsthqlZtX0weGPYsgn LICsuPzGsl+DhoW0yIIwmGiHHUvwAqWJgSWhnaZQjKqIZC7D2MZWnUJN/ w==; X-IronPort-AV: E=McAfee;i="6200,9189,10301"; a="322658819" X-IronPort-AV: E=Sophos;i="5.90,222,1643702400"; d="scan'208";a="322658819" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Mar 2022 00:56:49 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.90,222,1643702400"; d="scan'208";a="653692953" Received: from louislifei-optiplex-7050.sh.intel.com (HELO louislifei-OptiPlex-7050) ([10.239.81.43]) by orsmga004.jf.intel.com with ESMTP; 30 Mar 2022 00:56:47 -0700 Date: Wed, 30 Mar 2022 15:57:42 +0800 From: Li Fei1 To: Jakob Koschel Cc: linux-kernel@vger.kernel.org, rppt@kernel.org, bjohannesmeyer@gmail.com, c.giuffrida@vu.nl, h.j.bos@vu.nl, fei1.li@intel.com Subject: Re: [PATCH] virt: acrn: fix invalid check past list iterator Message-ID: <20220330075742.GA22544@louislifei-OptiPlex-7050> References: <20220319203819.2559993-1-jakobkoschel@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220319203819.2559993-1-jakobkoschel@gmail.com> User-Agent: Mutt/1.9.4 (2018-02-28) X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Mar 19, 2022 at 09:38:19PM +0100, Jakob Koschel wrote: > The condition retry == 0 is theoretically possible even if 'client' > does not point to a valid element because no break was hit. > > To only execute the dev_warn if actually a break within the loop was > hit, a separate variable is used that is only set if it is ensured to > point to a valid client struct. > Hi Koschel Thanks for you to help us to try to improve the code. Maybe you don't get the point. The dev_warn should only been called when has_pending = true && retry == 0 If retry > 0 and has_pending is true, we would call schedule_timeout_interruptible to schedule out to wait all the pending I/O requests would been completed. Thanks. > Signed-off-by: Jakob Koschel > --- > drivers/virt/acrn/ioreq.c | 13 ++++++++----- > 1 file changed, 8 insertions(+), 5 deletions(-) > > diff --git a/drivers/virt/acrn/ioreq.c b/drivers/virt/acrn/ioreq.c > index 5ff1c53740c0..bdf7cedce926 100644 > --- a/drivers/virt/acrn/ioreq.c > +++ b/drivers/virt/acrn/ioreq.c > @@ -211,7 +211,7 @@ static int ioreq_task(void *data) > */ > void acrn_ioreq_request_clear(struct acrn_vm *vm) > { > - struct acrn_ioreq_client *client; > + struct acrn_ioreq_client *client, *iter; > bool has_pending = false; > unsigned long vcpu; > int retry = 10; > @@ -228,17 +228,20 @@ void acrn_ioreq_request_clear(struct acrn_vm *vm) > */ > do { > spin_lock_bh(&vm->ioreq_clients_lock); > - list_for_each_entry(client, &vm->ioreq_clients, list) { > - has_pending = has_pending_request(client); > - if (has_pending) > + client = NULL; > + list_for_each_entry(iter, &vm->ioreq_clients, list) { > + has_pending = has_pending_request(iter); > + if (has_pending) { > + client = iter; > break; > + } > } > spin_unlock_bh(&vm->ioreq_clients_lock); > > if (has_pending) > schedule_timeout_interruptible(HZ / 100); > } while (has_pending && --retry > 0); > - if (retry == 0) > + if (client) > dev_warn(acrn_dev.this_device, > "%s cannot flush pending request!\n", client->name); > > > base-commit: 34e047aa16c0123bbae8e2f6df33e5ecc1f56601 > -- > 2.25.1 >