From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 94184CD68E3 for ; Tue, 10 Oct 2023 02:34:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1441899AbjJJCee (ORCPT ); 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-Google-Smtp-Source: AGHT+IELXt5RxDd99HhYrJ2ArNSDl8Q/Eg48hdKp68VYC8fzBqBQqbw7nJq8UjoTvhZf2i/opBAQ0A== 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.