Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp2251283rdb; Mon, 9 Oct 2023 19:34:47 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEfuwO1ruNAJDZYXa9iunIbMDuErsb+xpCUvPmMaoo/KXLYwbpTvEcIjs8hofzfI+LdvI6x X-Received: by 2002:a17:902:d702:b0:1c5:f4c7:b4e4 with SMTP id w2-20020a170902d70200b001c5f4c7b4e4mr13681541ply.39.1696905286852; Mon, 09 Oct 2023 19:34:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696905286; cv=none; d=google.com; s=arc-20160816; b=jI22iyA/gi4N11IJU13HPdX7qSlMWZMXHRiGXZI8uixiMsL/fTc84+CKmNjxFaIKva 7DxDJHemnj1mDIqSDrZPoDtLk0Z5UjVe0jPgXWNdZNnzSLAxoZ+gHMdfi2n1DJ3s99Jp /XAKyhsdAO0trmT5GhqTp6gxtQNF3HASCIyzLKtbZ1nUWZ6g4k/Fc7Gaf1MYO4Hy2gdO VuOhNa5WcvBA9wDbOcgMQ6Sd4V+pu/h9kUSR0v3GXTJTBDBwhfTeFyz9enmZiLCHJwQ7 8I8uT5JRXZeUXBli3N1n6219rNurxudRvf0QZpQgP6kMtBQwuSgXNHwGDGe1oBBimvlg xEmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=7eyfqJMsAjtR1XTGi5WJSGOZUAbzaEU+L92vGk2MLy8=; fh=1mZTzjaPWCc+iFwpuqh4Fn85VNPOfb6lpPbgQzTTSJM=; b=U4EJj72ijxAkvizrWsqfgna90fA9hSD5qw5Iot2mwtHzHjj146kb+A+0H69Jb0mkv0 muJb9ok1XLG0QlVVy0usyMN9QZn/BUD7m38SOXSGWWrTjqTbhoGW/sWxx/AFawimArZ7 l/anVVWpuy29AfgkmLyvVBTD2J5wGRxSB5tCwGkmcpBrijG2qYFNaK5EAqo3x2VW0cEB P6AYwtIEoao+DQmNgKdDsO1Tqk7s2rkofZnjXoGKTkAjJunt+JmgqlVh4mHtV/mwmtn0 S4QAS3MM3h6072ELU7hcnNLIYh/w+/SSv2Z4tvHjfJwAJ0wfZ9YRQhcyWMeGTMQXiWdM FxNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@daynix-com.20230601.gappssmtp.com header.s=20230601 header.b=NZN06aM8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id u5-20020a17090341c500b001c5f37aeebdsi6501415ple.579.2023.10.09.19.34.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 19:34:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@daynix-com.20230601.gappssmtp.com header.s=20230601 header.b=NZN06aM8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id AF45581FAD93; Mon, 9 Oct 2023 19:34:44 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1441896AbjJJCee (ORCPT + 99 others); Mon, 9 Oct 2023 22:34:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47534 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1441912AbjJJCec (ORCPT ); Mon, 9 Oct 2023 22:34:32 -0400 Received: from mail-oo1-xc32.google.com (mail-oo1-xc32.google.com [IPv6:2607:f8b0:4864:20::c32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8C5E19C for ; Mon, 9 Oct 2023 19:34:30 -0700 (PDT) Received: by mail-oo1-xc32.google.com with SMTP id 006d021491bc7-57f02eeabcaso2505597eaf.0 for ; Mon, 09 Oct 2023 19:34:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1696905270; x=1697510070; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=7eyfqJMsAjtR1XTGi5WJSGOZUAbzaEU+L92vGk2MLy8=; b=NZN06aM8AUnsmgvJQy26qFdVqSoD8fJY8Br3ri6MwG0TFBK4RaJ8f9zJNIMDYg31f9 zzHJ79Vv+t/GJV/ugm1QMkEVM7IhIzFUxyehxXhZ0TTd5//BbWYnOTMZFmZMqDQW1cRw gbxnxYB4JSffzoLXfc0W3cRNpWF39RgUnHF1kE4dDqhBjT2ID/maRi/5q5Vt50aKntzF +9j8pM5GWUocuTI1tWAPHXiZNoc1XmkOVEYxDepj3ccdg9yuueFXN2VZJ+OvV9VqzLJZ YUQblGXS9L1voCUoueZEKCSQlly/oEpDJybiSKNecq1tBKqubaKnLR2CTYHC4eZBX1OM MkNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696905270; x=1697510070; 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=7eyfqJMsAjtR1XTGi5WJSGOZUAbzaEU+L92vGk2MLy8=; b=BGcyTkx5B10Xs00UHA4du8r3+pwBVcDhQnS1gkq0hj5wgILiKtuFk4bB32iDqg6ac4 yeBQxgI9ea5qQ515QLRQpaN65fB9jNr71iceDo/xNt31UfP+upCuQJLsaIZqO3mcpADe eVgxnieSViuV6Om7BW5kw72Wo8EieCrv8bERyZcg1BgRzQzQo1gW6JAYCMtokzqdFXpE eKk5QzqRTisCEi2s/glCtcsih7rWbabKOP8WPArbKrS4n1qZDhqc4HBxK+ux7HFFh+Xo iJ0CWBZUwaa+gUg44A07h2vx9AwEz69BVPjml5nVq396kyf0OvHpIG+i9MTpHpwPhamg 5EOA== X-Gm-Message-State: AOJu0YwwowjT5Bvkfh8gl8N54ieLWdrDMyJMFGEFzNqGgeCG1FZlAZ/q tBhyxx+ibFqVM+zrDJCc1iWizA== X-Received: by 2002:a05:6358:8812:b0:139:cb15:ecd3 with SMTP id hv18-20020a056358881200b00139cb15ecd3mr16915710rwb.8.1696905269713; Mon, 09 Oct 2023 19:34:29 -0700 (PDT) Received: from ?IPV6:2400:4050:a840:1e00:78d2:b862:10a7:d486? ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with ESMTPSA id fa9-20020a17090af0c900b0027360359b70sm11068223pjb.48.2023.10.09.19.34.23 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 09 Oct 2023 19:34:29 -0700 (PDT) Message-ID: <14ae9e85-38da-4665-8aea-3ce93e280de2@daynix.com> Date: Tue, 10 Oct 2023 11:34:21 +0900 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RFC PATCH 5/7] tun: Introduce virtio-net hashing feature Content-Language: en-US To: "Michael S. Tsirkin" Cc: Willem de Bruijn , Jason Wang , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, linux-kselftest@vger.kernel.org, bpf@vger.kernel.org, davem@davemloft.net, kuba@kernel.org, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, kafai@fb.com, songliubraving@fb.com, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, rdunlap@infradead.org, willemb@google.com, gustavoars@kernel.org, herbert@gondor.apana.org.au, steffen.klassert@secunet.com, nogikh@google.com, pablo@netfilter.org, decui@microsoft.com, cai@lca.pw, jakub@cloudflare.com, elver@google.com, pabeni@redhat.com, Yuri Benditovich References: <20231008052101.144422-1-akihiko.odaki@daynix.com> <20231008052101.144422-6-akihiko.odaki@daynix.com> <48e20be1-b658-4117-8856-89ff1df6f48f@daynix.com> <20231009074840-mutt-send-email-mst@kernel.org> From: Akihiko Odaki In-Reply-To: <20231009074840-mutt-send-email-mst@kernel.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=2.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_SBL_CSS, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Mon, 09 Oct 2023 19:34:44 -0700 (PDT) X-Spam-Level: ** On 2023/10/09 20:50, Michael S. Tsirkin wrote: > On Mon, Oct 09, 2023 at 05:44:20PM +0900, Akihiko Odaki wrote: >> On 2023/10/09 17:13, Willem de Bruijn wrote: >>> On Sun, Oct 8, 2023 at 12:22 AM Akihiko Odaki wrote: >>>> >>>> virtio-net have two usage of hashes: one is RSS and another is hash >>>> reporting. Conventionally the hash calculation was done by the VMM. >>>> However, computing the hash after the queue was chosen defeats the >>>> purpose of RSS. >>>> >>>> Another approach is to use eBPF steering program. This approach has >>>> another downside: it cannot report the calculated hash due to the >>>> restrictive nature of eBPF. >>>> >>>> Introduce the code to compute hashes to the kernel in order to overcome >>>> thse challenges. An alternative solution is to extend the eBPF steering >>>> program so that it will be able to report to the userspace, but it makes >>>> little sense to allow to implement different hashing algorithms with >>>> eBPF since the hash value reported by virtio-net is strictly defined by >>>> the specification. >>>> >>>> The hash value already stored in sk_buff is not used and computed >>>> independently since it may have been computed in a way not conformant >>>> with the specification. >>>> >>>> Signed-off-by: Akihiko Odaki >>> >>>> @@ -2116,31 +2172,49 @@ static ssize_t tun_put_user(struct tun_struct *tun, >>>> } >>>> >>>> if (vnet_hdr_sz) { >>>> - struct virtio_net_hdr gso; >>>> + union { >>>> + struct virtio_net_hdr hdr; >>>> + struct virtio_net_hdr_v1_hash v1_hash_hdr; >>>> + } hdr; >>>> + int ret; >>>> >>>> if (iov_iter_count(iter) < vnet_hdr_sz) >>>> return -EINVAL; >>>> >>>> - if (virtio_net_hdr_from_skb(skb, &gso, >>>> - tun_is_little_endian(tun), true, >>>> - vlan_hlen)) { >>>> + if ((READ_ONCE(tun->vnet_hash.flags) & TUN_VNET_HASH_REPORT) && >>>> + vnet_hdr_sz >= sizeof(hdr.v1_hash_hdr) && >>>> + skb->tun_vnet_hash) { >>> >>> Isn't vnet_hdr_sz guaranteed to be >= hdr.v1_hash_hdr, by virtue of >>> the set hash ioctl failing otherwise? >>> >>> Such checks should be limited to control path where possible >> >> There is a potential race since tun->vnet_hash.flags and vnet_hdr_sz are not >> read at once. > > And then it's a complete mess and you get inconsistent > behaviour with packets getting sent all over the place, right? > So maybe keep a pointer to this struct so it can be > changed atomically then. Maybe even something with rcu I donnu. I think it's a good idea to use RCU for the vnet_hash members, but vnet_hdr_sz is something not specific to vnet_hash so this check will be still necessary.