Received: by 2002:ab2:1689:0:b0:1f7:5705:b850 with SMTP id d9csp1671071lqa; Mon, 29 Apr 2024 16:00:41 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXzwzcytYkIUKWxWtaAtra1U364pIv/V+N7bText4Ni6LWbfnqN59CUizrbyN7kThdfalAKTpq5GAmS0KBqbvmT0D3QL2sr4EZgB8uwJA== X-Google-Smtp-Source: AGHT+IGQzCy3YXQbSnZos2l3PhuPjTixgog6vXrKCwfjELbxTQuvGHsKCA/u4QgM9+qQFh6nu/Qz X-Received: by 2002:a67:b909:0:b0:47a:2cab:75ad with SMTP id q9-20020a67b909000000b0047a2cab75admr1125418vsn.14.1714431641474; Mon, 29 Apr 2024 16:00:41 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714431641; cv=pass; d=google.com; s=arc-20160816; b=ps6xlHn74Hw6jmOLQlZK8M2dNgyAG2r65UbFKaE0gihqgfszppJ5GMzuAyxkPv3Yhx wHjovYVzeM78m3RnlN+pbVxQobSpWIrry7f0Nde6/dPhK6vZS1NbKzdEjVihhfzS37Bn Aa9HkGcJ8p7AbSsjbBhsMbxOPyF66buqBRw6/uh/N7f+Iq5RoLXtZo1HGdUBqs5+aISE dtvjT+kWi2MvF+UObK1kDrjnVQhcuTWYBFaN1kaKsSwAUxZLN68s5ZqfsloWPw+ap8sn aKtAtvqNII3KBb4MXfKZJV54Cpe8qmMJwuE5HquQ+BZiGfZRGvhV1W4wpK11I+SRswNv KVcQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=uTpDjsWrbDelUOoovp9TM5pcXXPdflIY1tu9If4E9h0=; fh=84UGWylxoVmaDj3OYvQVU834hJUUwXVktVOCZCPYTzA=; b=gGrysfZWA168TcIKfLrORn76fz87uTwpDEXhLn55XP77wlIOoUyYEQQEzWArBliov7 5Mz37D0wN5DvvWlKoVoglX0LJTuOpTsWOBGdfiX/P1qVsg/q4hCsEc2KLA4WfDJD5jeT WwfubzHIjBGEtV3tXdLJWtxicvLG6VyGsRJ4Wvx//o/BInsZgGprPLOTNt6TF/7XxcwL qLW1scng0srzskTB4VKsznPqoEcn61UQasNAMtUStg2+vO5VR1vRWrIFgxZYBLjMhv1Y TKbxiMnmj8g+vfb/L1fTqZUycnIwvnPkNFSW6N/sYW/ddF3MyI77P/3CjWbJEXQSpvZS LloA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Y0Z2txDD; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-163120-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-163120-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id h4-20020a056102104400b0047c3699221csi768930vsq.613.2024.04.29.16.00.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Apr 2024 16:00:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-163120-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=@redhat.com header.s=mimecast20190719 header.b=Y0Z2txDD; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-163120-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-163120-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.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 32A161C2147F for ; Mon, 29 Apr 2024 23:00:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E83CB7BB1A; Mon, 29 Apr 2024 23:00:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Y0Z2txDD" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7D60D1E886 for ; Mon, 29 Apr 2024 23:00:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714431633; cv=none; b=NRv/PIqE1KvSfgSdQZEZsdjqJWo41Ue9NBvDpZrQXLjyT0pFnrWjOZVXzTjODlBeYgphZxDaFSEC52qBnu/lcJewHvRVyY5hqLT3CqiomteIKxechfNW2+5rq8D21Cdgx4l6/y2U5giYLK/cUrbjOTIegvA5wXhEu/NFkid4MH4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714431633; c=relaxed/simple; bh=p+U0/z6qpWvhxLpDOQ9kwr52CI9MOZsHkOK0yPzOXU0=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=qqJoLN1EQTZVNNFu31wXaVwPT+UPi1TrnuSsaYCNj1D8ksVzodFy2UbweaxZsxzajgIfs14IOlRu6wxgthf0ej6dbJc8iLmd0LoSwlsHHjPYrhupljsFj+0lJFefYVWbpYIRXu3uKEEeMHJXU4jChVHD/im9+jQGpBCgIZI5wgc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Y0Z2txDD; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1714431630; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uTpDjsWrbDelUOoovp9TM5pcXXPdflIY1tu9If4E9h0=; b=Y0Z2txDDlfKxwTrCVciAGauorNE/zuHCgs5SYzOWqpBw6Hf4aCZ7N+QFB0b0kZELeaWSHV /2oKC+ygObiykzhQpPkfGcpsKDJKNCacLjrz2/fHqEVkdt9v1Xr+pq7BIL/RkpqWoEzTzu JZun2MXvcp2MbM6aAk6Ty7BeL9Xec50= Received: from mail-pg1-f200.google.com (mail-pg1-f200.google.com [209.85.215.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-55-BHe5j8KVMXOW1_FjEbMdbA-1; Mon, 29 Apr 2024 19:00:28 -0400 X-MC-Unique: BHe5j8KVMXOW1_FjEbMdbA-1 Received: by mail-pg1-f200.google.com with SMTP id 41be03b00d2f7-5c65e666609so5473702a12.1 for ; Mon, 29 Apr 2024 16:00:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714431628; x=1715036428; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=uTpDjsWrbDelUOoovp9TM5pcXXPdflIY1tu9If4E9h0=; b=Bmz0jsq9iI2mY0Ij3+j074BuaAg5cGkfhS79oC0eUFqqBTFgstO2Gh0J1haD/OV3OG QKBChcdHLXRGvNQeKLx2fhxtXuzSSTn+tvAFg18+lzHsRHej2dPsCGWz2ikK3wskltjx GqHmB0vXjKGWoq9gatqQ/GZCbgdrRf226kM5PIzqYZXPMWk5HAORbDzudAny8FJTGypW b/vQ7ecEkghhUcGuGXLdXvk/6nrvqKJCTK2FlosjzechUACza4XqVH1E9u9AIbTw4ehL kVvyRdXn0ZsdNG0/jV1Fkx8yxFbc+KFhobf28FjMN+CVlIJ9cDFtPlVZs5frIB0uEtbe iRYg== X-Forwarded-Encrypted: i=1; AJvYcCX0cgTJSod/3eB3LM8LFoS2RAkwqWrM3Ujok8RZrOR5cbHDALt2kIK7ZVDqgl1sGWAcPbxDsvt1LhpcsOu8M941RhBHQFsS/VcTfjey X-Gm-Message-State: AOJu0YyQ6xcPNyoPBPPpVGwHwXOrg474bdXiQRl91DbR5jc4gDih1TeJ pLQOw+4Vm3hFOyy56a+nJOfi1MoXNDY9blqX+fSo8jcZPqYmyR9oHRDe+A/A1XP5vCpajZHY2mv PBE58nctFeuSrRzEldYnw5D4utlfFau94hmJyw1kDq3XhKjuylw1pNEp1KwPS7w== X-Received: by 2002:a05:6a20:4f28:b0:1a9:9547:1145 with SMTP id gi40-20020a056a204f2800b001a995471145mr950596pzb.47.1714431627673; Mon, 29 Apr 2024 16:00:27 -0700 (PDT) X-Received: by 2002:a05:6a20:4f28:b0:1a9:9547:1145 with SMTP id gi40-20020a056a204f2800b001a995471145mr950579pzb.47.1714431627299; Mon, 29 Apr 2024 16:00:27 -0700 (PDT) Received: from [192.168.68.50] ([43.252.112.88]) by smtp.gmail.com with ESMTPSA id p9-20020a170902780900b001eab1fb1093sm8782186pll.102.2024.04.29.16.00.24 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 29 Apr 2024 16:00:26 -0700 (PDT) Message-ID: <4e133a86-a2e5-43ed-acd0-fe6f1aa9eed2@redhat.com> Date: Tue, 30 Apr 2024 09:00:21 +1000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 2/4] vhost: Drop variable last_avail_idx in vhost_get_vq_desc() Content-Language: en-US To: "Michael S. Tsirkin" Cc: virtualization@lists.linux.dev, linux-kernel@vger.kernel.org, jasowang@redhat.com, shan.gavin@gmail.com References: <20240429101400.617007-1-gshan@redhat.com> <20240429101400.617007-3-gshan@redhat.com> <20240429144522-mutt-send-email-mst@kernel.org> From: Gavin Shan In-Reply-To: <20240429144522-mutt-send-email-mst@kernel.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 4/30/24 04:45, Michael S. Tsirkin wrote: > On Mon, Apr 29, 2024 at 08:13:58PM +1000, Gavin Shan wrote: >> The local variable @last_avail_idx is equivalent to vq->last_avail_idx. >> So the code can be simplified a bit by dropping the local variable >> @last_avail_idx. >> >> No functional change intended. >> >> Signed-off-by: Gavin Shan >> --- >> drivers/vhost/vhost.c | 7 +++---- >> 1 file changed, 3 insertions(+), 4 deletions(-) >> >> diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c >> index 7aa623117aab..b278c0333a66 100644 >> --- a/drivers/vhost/vhost.c >> +++ b/drivers/vhost/vhost.c >> @@ -2524,7 +2524,6 @@ int vhost_get_vq_desc(struct vhost_virtqueue *vq, >> { >> struct vring_desc desc; >> unsigned int i, head, found = 0; >> - u16 last_avail_idx = vq->last_avail_idx; >> __virtio16 ring_head; >> int ret, access; >> >> @@ -2539,10 +2538,10 @@ int vhost_get_vq_desc(struct vhost_virtqueue *vq, >> >> /* Grab the next descriptor number they're advertising, and increment >> * the index we've seen. */ >> - if (unlikely(vhost_get_avail_head(vq, &ring_head, last_avail_idx))) { >> + if (unlikely(vhost_get_avail_head(vq, &ring_head, vq->last_avail_idx))) { >> vq_err(vq, "Failed to read head: idx %d address %p\n", >> - last_avail_idx, >> - &vq->avail->ring[last_avail_idx % vq->num]); >> + vq->last_avail_idx, >> + &vq->avail->ring[vq->last_avail_idx % vq->num]); >> return -EFAULT; >> } > > I don't see the big advantage and the line is long now. > The point is to avoid the local variable @last_avail_idx since it's equivalent to vq->last_avail_idx, as stated in the commit log. Besides, it paves the way for PATCH[v2 3/4] where the whole logic fetching the head and sanity check is moved to vhost_get_avail_head(), so that vhost_get_vq_desc() is simplified I will drop PATCH[2, 3, 4] as you suggested. Thanks, Gavin