Received: by 2002:a05:6602:2086:0:0:0:0 with SMTP id a6csp4571892ioa; Wed, 27 Apr 2022 06:44:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyj4bhopl9JOz+m57cxKmCjfZQs+Xcp5Z7enT0S6bHCl83MwqoimcnxfxzdE97n4r3KZ29+ X-Received: by 2002:a17:90a:6445:b0:1d6:a69e:406c with SMTP id y5-20020a17090a644500b001d6a69e406cmr36115424pjm.49.1651067073024; Wed, 27 Apr 2022 06:44:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651067073; cv=none; d=google.com; s=arc-20160816; b=bov8tev1V2bJrQQrnr0Eo/jEZom1o+ygN5vjWtdDaocaM5ZmR59YNUtsw7AiP5SjkI 9UoV3MJAyVC31eutpvtJSDvBH0boSv/YA3SBA0o+jlU1+wKe2d8PO5b0PMDV2a8nlouU OQW0rIVUV4kUUHhYAr/e34Bm9hDSd7LhH3Oag5g02CGtaDAfqawY/GW+owQkz59J6uj/ nJ9SzvjU58RsjHXJGur4LbokEirPaekq9gd7/2H13nG5yF7zRRKCQfQkrKOMyTg0rtKS 1myaVQKU5MPvCZd0x0VyzjlsgWftpYVyOHp4F7hk2Xcv0q7qVoMNmZ1NKEgF9Tk6b6Vg M9Dg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=mBP/GAzMTLsxy2cYFH2pCl1g7q1hH9iiBkvTHN3bMu4=; b=OFWVcvVhgiYkHPIARnra+yTezIsIRsKJRm7M4vV7ECH2Lq3EOY3YO0G2hcgCQ7QygH K/9xUttuo5pKFtarTwc16+Ibef/aTSfWiUCUEG8EeY9+aqqozwdIKXdrd0ogH1bdbUjB exlMDQ2cNAU+8/G18tW1J3/fBQ5zVhyRvG+rZz6UmKxgq9S+L7OPpOrHJj+ONrq7mG2O HJ1VnVhwtKH0UPiZ1bFZgs/emUc/tUfOW/6U5DFdoC81jnrADBQ+GTWFI0tVbCgJX65X 2YWIExXj0sSkPRqT2vEKkN/MtiWV+lcUfG2b4bAs3/7MH6XEKpEmWEtEFwfKB9W5joCt shjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="ZmL/tGhg"; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id n127-20020a632785000000b003ab40bd491fsi1519531pgn.648.2022.04.27.06.44.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Apr 2022 06:44:33 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="ZmL/tGhg"; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 9DB38DFA9; Wed, 27 Apr 2022 06:16:45 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235842AbiD0NR2 (ORCPT + 99 others); Wed, 27 Apr 2022 09:17:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51344 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235421AbiD0NQx (ORCPT ); Wed, 27 Apr 2022 09:16:53 -0400 Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [IPv6:2a00:1450:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8AFC21BA7AD; Wed, 27 Apr 2022 06:13:07 -0700 (PDT) Received: by mail-ej1-x62e.google.com with SMTP id k23so3339098ejd.3; Wed, 27 Apr 2022 06:13:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=mBP/GAzMTLsxy2cYFH2pCl1g7q1hH9iiBkvTHN3bMu4=; b=ZmL/tGhgkZj1WGf42JDRnueRaVLUnPsmgFIIo9CjBqLzZ3qYJf0ZF96Uz3+BwwWGQ2 D6VUAixplWRmPP9ozGjmrzgFINgzde9jH0XwBdWm9IGdees9RzZFX1GocwromdmdGO2M q3F2x37B6Ye3Wii8jphtjVzJeuhxosY7b4lRHvJXzp77rli8G+gC/UV/P1vO8sVDCWkp xs6VQm8rEaeywfzYmZecNH8NjvNkAbZJv28J1LUA9/T+67FOVM2AkvHelneXs38zBFZG 8Oe6hO60Jx60CBPrJbr+L66RHFX0YMxB5wyUWFTFkBHr2oQWu2UMpDA0ZO90y8CUN3Az hqGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=mBP/GAzMTLsxy2cYFH2pCl1g7q1hH9iiBkvTHN3bMu4=; b=hRe8AkHDjhNKhUAIxkUqTqMmPJAtvNz2O6V29hjz9ylfky2RIHiSldoM5dvvKvCRi7 EzcnN9rjgXNq2dT4oNV8bnFHzGkjIdQ6lW2G7g7TJqKudspzgK3Mn5uSC4urcPwyoC93 29kq0GdF4ubg35j1fkrnW22DCICFGDHQngK8RZOnbhZK07dKLgGJL6LPuHUX/iExGZhL EHjCYL0VM86ZwQo/ydntfaEqzmie0yifEa9OLT1A8Z0BHh48hAjM5rQO0fEWnsEu/fC2 oH7qpR4TOyt40LzrhlYutLzH18cxwz5HIm9O8xN9BIEz4vgof4G/V5PvhZIyFwcKWMxY xwZQ== X-Gm-Message-State: AOAM532dETAXAwMHSaoDrkafO1CI0T1YzjIHQQdsnF/JcU5jZad04WEJ 51AwNVyijZAjBP8jNQHatME= X-Received: by 2002:a17:907:6d23:b0:6d9:ac9d:222 with SMTP id sa35-20020a1709076d2300b006d9ac9d0222mr26640258ejc.595.1651065185974; Wed, 27 Apr 2022 06:13:05 -0700 (PDT) Received: from anparri.mshome.net (host-79-49-65-106.retail.telecomitalia.it. [79.49.65.106]) by smtp.gmail.com with ESMTPSA id u6-20020a170906124600b006e843964f9asm6668987eja.55.2022.04.27.06.13.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Apr 2022 06:13:05 -0700 (PDT) From: "Andrea Parri (Microsoft)" To: KY Srinivasan , Haiyang Zhang , Stephen Hemminger , Wei Liu , Dexuan Cui , Michael Kelley , Stefano Garzarella , David Miller , Jakub Kicinski , Paolo Abeni Cc: linux-hyperv@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, "Andrea Parri (Microsoft)" Subject: [PATCH v2 5/5] Drivers: hv: vmbus: Refactor the ring-buffer iterator functions Date: Wed, 27 Apr 2022 15:12:25 +0200 Message-Id: <20220427131225.3785-6-parri.andrea@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220427131225.3785-1-parri.andrea@gmail.com> References: <20220427131225.3785-1-parri.andrea@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE autolearn=no 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 With no users of hv_pkt_iter_next_raw() and no "external" users of hv_pkt_iter_first_raw(), the iterator functions can be refactored and simplified to remove some indirection/code. Signed-off-by: Andrea Parri (Microsoft) Reviewed-by: Michael Kelley --- drivers/hv/ring_buffer.c | 32 +++++++++----------------------- include/linux/hyperv.h | 35 ++++------------------------------- 2 files changed, 13 insertions(+), 54 deletions(-) diff --git a/drivers/hv/ring_buffer.c b/drivers/hv/ring_buffer.c index 3d215d9dec433..fa98b3a91206a 100644 --- a/drivers/hv/ring_buffer.c +++ b/drivers/hv/ring_buffer.c @@ -421,7 +421,7 @@ int hv_ringbuffer_read(struct vmbus_channel *channel, memcpy(buffer, (const char *)desc + offset, packetlen); /* Advance ring index to next packet descriptor */ - __hv_pkt_iter_next(channel, desc, true); + __hv_pkt_iter_next(channel, desc); /* Notify host of update */ hv_pkt_iter_close(channel); @@ -456,22 +456,6 @@ static u32 hv_pkt_iter_avail(const struct hv_ring_buffer_info *rbi) return (rbi->ring_datasize - priv_read_loc) + write_loc; } -/* - * Get first vmbus packet without copying it out of the ring buffer - */ -struct vmpacket_descriptor *hv_pkt_iter_first_raw(struct vmbus_channel *channel) -{ - struct hv_ring_buffer_info *rbi = &channel->inbound; - - hv_debug_delay_test(channel, MESSAGE_DELAY); - - if (hv_pkt_iter_avail(rbi) < sizeof(struct vmpacket_descriptor)) - return NULL; - - return (struct vmpacket_descriptor *)(hv_get_ring_buffer(rbi) + rbi->priv_read_index); -} -EXPORT_SYMBOL_GPL(hv_pkt_iter_first_raw); - /* * Get first vmbus packet from ring buffer after read_index * @@ -483,11 +467,14 @@ struct vmpacket_descriptor *hv_pkt_iter_first(struct vmbus_channel *channel) struct vmpacket_descriptor *desc, *desc_copy; u32 bytes_avail, pkt_len, pkt_offset; - desc = hv_pkt_iter_first_raw(channel); - if (!desc) + hv_debug_delay_test(channel, MESSAGE_DELAY); + + bytes_avail = hv_pkt_iter_avail(rbi); + if (bytes_avail < sizeof(struct vmpacket_descriptor)) return NULL; + bytes_avail = min(rbi->pkt_buffer_size, bytes_avail); - bytes_avail = min(rbi->pkt_buffer_size, hv_pkt_iter_avail(rbi)); + desc = (struct vmpacket_descriptor *)(hv_get_ring_buffer(rbi) + rbi->priv_read_index); /* * Ensure the compiler does not use references to incoming Hyper-V values (which @@ -534,8 +521,7 @@ EXPORT_SYMBOL_GPL(hv_pkt_iter_first); */ struct vmpacket_descriptor * __hv_pkt_iter_next(struct vmbus_channel *channel, - const struct vmpacket_descriptor *desc, - bool copy) + const struct vmpacket_descriptor *desc) { struct hv_ring_buffer_info *rbi = &channel->inbound; u32 packetlen = desc->len8 << 3; @@ -548,7 +534,7 @@ __hv_pkt_iter_next(struct vmbus_channel *channel, rbi->priv_read_index -= dsize; /* more data? */ - return copy ? hv_pkt_iter_first(channel) : hv_pkt_iter_first_raw(channel); + return hv_pkt_iter_first(channel); } EXPORT_SYMBOL_GPL(__hv_pkt_iter_next); diff --git a/include/linux/hyperv.h b/include/linux/hyperv.h index 1112c5cf894e6..370adc9971d3e 100644 --- a/include/linux/hyperv.h +++ b/include/linux/hyperv.h @@ -1673,55 +1673,28 @@ static inline u32 hv_pkt_len(const struct vmpacket_descriptor *desc) return desc->len8 << 3; } -struct vmpacket_descriptor * -hv_pkt_iter_first_raw(struct vmbus_channel *channel); - struct vmpacket_descriptor * hv_pkt_iter_first(struct vmbus_channel *channel); struct vmpacket_descriptor * __hv_pkt_iter_next(struct vmbus_channel *channel, - const struct vmpacket_descriptor *pkt, - bool copy); + const struct vmpacket_descriptor *pkt); void hv_pkt_iter_close(struct vmbus_channel *channel); static inline struct vmpacket_descriptor * -hv_pkt_iter_next_pkt(struct vmbus_channel *channel, - const struct vmpacket_descriptor *pkt, - bool copy) +hv_pkt_iter_next(struct vmbus_channel *channel, + const struct vmpacket_descriptor *pkt) { struct vmpacket_descriptor *nxt; - nxt = __hv_pkt_iter_next(channel, pkt, copy); + nxt = __hv_pkt_iter_next(channel, pkt); if (!nxt) hv_pkt_iter_close(channel); return nxt; } -/* - * Get next packet descriptor without copying it out of the ring buffer - * If at end of list, return NULL and update host. - */ -static inline struct vmpacket_descriptor * -hv_pkt_iter_next_raw(struct vmbus_channel *channel, - const struct vmpacket_descriptor *pkt) -{ - return hv_pkt_iter_next_pkt(channel, pkt, false); -} - -/* - * Get next packet descriptor from iterator - * If at end of list, return NULL and update host. - */ -static inline struct vmpacket_descriptor * -hv_pkt_iter_next(struct vmbus_channel *channel, - const struct vmpacket_descriptor *pkt) -{ - return hv_pkt_iter_next_pkt(channel, pkt, true); -} - #define foreach_vmbus_pkt(pkt, channel) \ for (pkt = hv_pkt_iter_first(channel); pkt; \ pkt = hv_pkt_iter_next(channel, pkt)) -- 2.25.1