Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp1789491rdb; Mon, 9 Oct 2023 03:05:41 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF9XORwnrGfMoN96TrIxpwbHkbXsQPPtMmaJPXNnNUc8fAAQOEWxlx4UA1Ok+DEO2xo7zrd X-Received: by 2002:a17:903:41c4:b0:1c6:294c:f89c with SMTP id u4-20020a17090341c400b001c6294cf89cmr17112125ple.63.1696845941163; Mon, 09 Oct 2023 03:05:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696845941; cv=none; d=google.com; s=arc-20160816; b=HC/lnMkuvERqY6Raq3gl3NJc5mG1dVrA3rO1nbf/UdywXxmDcC0cXeedZao0WxpD7b cztPhupHv5miodII3s0JAwupi28giklv0n2zXF1yH22CfHrzMp4beAuDBNHaisfTX9c4 3WRa9KkgQ23thd+V+ssaajRO5P/8wGRAItjc7FjIIgyjDIr3BAC9KVI0pPGNVGI0yZDR +o7hlIb8PXW+9oylG0pisdKgawcJzFmj52JvxeNzpGbB7SsqjXO7RNj9nRvhV+MKgrR8 lkC1D2Gv9dD9YB6P36sEMrf2jt42zByFle3m/2+dJ1rnRhSIjhCRy7FmVYnH7FMaMCoP o26w== 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=tU1LzqCUZS3h8pX7+UKm34RoTSScep7fx/DPCoe38tw=; fh=rvA6+mpTFR+bDtNgVM8f2ZolmredGNfNaQmjMHCI1BM=; b=MZ1SDrGnF/SnnxszOrASoyJg15Oc2iMHfrlsGJ8svdN1CdyJP3WOKUc7qMrlDKRwwN iOCbXrbDPQIfHpYCZw4MolBCdZ+z8ZYkDiuu8wU4PtYMhFGJrPvDa2F00jmI39eA3WD2 mm4Z9ywXbqkxgJnxmKnFQLRu0PePtJQrh1Ezk9A+u5wdRw9MuPP7Y3xjSCYeOzD3rzt2 P7WjUihiw6KMAIUfmY49qyQDmZOyDsU2IERFVkI3lTfx6w15e75QwhTwxMGwcNTnmfsn BMBpohEuCZPfGls7AuHZf0RqCP1Ag3FwSO3O7QqJmlw/W06WwARfjdRNgrs8++rSOy12 GAcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@daynix-com.20230601.gappssmtp.com header.s=20230601 header.b=BK+39T5y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id li11-20020a170903294b00b001bc553d16e0si8667181plb.507.2023.10.09.03.05.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 03:05:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@daynix-com.20230601.gappssmtp.com header.s=20230601 header.b=BK+39T5y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (Postfix) with ESMTP id 6B93C8021E23; Mon, 9 Oct 2023 03:05:38 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346037AbjJIKF2 (ORCPT + 99 others); Mon, 9 Oct 2023 06:05:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46344 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346026AbjJIKF1 (ORCPT ); Mon, 9 Oct 2023 06:05:27 -0400 Received: from mail-oi1-x235.google.com (mail-oi1-x235.google.com [IPv6:2607:f8b0:4864:20::235]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 43D299C for ; Mon, 9 Oct 2023 03:05:25 -0700 (PDT) Received: by mail-oi1-x235.google.com with SMTP id 5614622812f47-3af6bd48093so3152514b6e.3 for ; Mon, 09 Oct 2023 03:05:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1696845924; x=1697450724; 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=tU1LzqCUZS3h8pX7+UKm34RoTSScep7fx/DPCoe38tw=; b=BK+39T5yy4phl4G/9d9cDalQbZaRXrtX8+wNINltCQsBkDF9Fzsv1q107gGFyDbnBA TVXlTSPK0Ho+HJq6gd2YstKKmMM5U6QoGoBAX3oANf7yPA4drbmoVdAR2inQVpsCMxAV lQfzI9TgHAAOsTCRuhJkms+ODpex6oLKMdhVJRwd7D4YD1BDJyFDimMLjJnkKz25dJSr /jSVY3eQczLNFIT1IFI6t/oEKExn3oXv7IpFsmvPypbqMlYT0QSc+Rec5A2uqqdzHA5m mb2G+5hY3w3WGdacxUbq4PbDsxGBSPmyXSy2BiKjCEoyND87o7wMlDfspTDvitAfb7E8 XrcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696845924; x=1697450724; 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=tU1LzqCUZS3h8pX7+UKm34RoTSScep7fx/DPCoe38tw=; b=Ew9mL7vvZiaall/nV87+Ehqu/z4lkA0RQ1wksnLmnPeyDBCCF2X5KDk2eCGLmnSjB3 bFqcYKPK/ATFjBggy54xPsxT4j0QXIciZ8+C6BcHxYIyxhaNqjLWAhxHdOHrYYhfpG73 ttceWdjKvaCjybkk/vKjwuZURpun+LCY/lUw6wDNKIY+GykWZJadyHmjB5p9yH7n3yW4 aKkVSwKL7epYxjRMWUFyJWGRHpiCc4ZTsuPEhz4lw14f+XnWdHefj2kCBejfUS8Tlwa9 o9eiBXFjkT5UrP3uFXG3psxvA+DLUlyPvSqmPwHMtague2GSdl0ODFrpzkqHT1/G459I QPPA== X-Gm-Message-State: AOJu0YwOgfmY+KH2VRD6q03ZsKUe1DJSqtCxJZaNi/3Tb3QTW4ucBL8W ZpxQD6FXtEFEZnaRamDaR0ca0w== X-Received: by 2002:a05:6808:2a43:b0:3a0:41d4:b144 with SMTP id fa3-20020a0568082a4300b003a041d4b144mr13646173oib.1.1696845924629; Mon, 09 Oct 2023 03:05:24 -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 c6-20020a633506000000b0058579ef9577sm7860030pga.79.2023.10.09.03.05.18 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 09 Oct 2023 03:05:24 -0700 (PDT) Message-ID: <6a698c99-6f02-4cfb-a709-ba02296a05f7@daynix.com> Date: Mon, 9 Oct 2023 19:05:17 +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: Willem de Bruijn Cc: Jason Wang , "Michael S. Tsirkin" , 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> From: Akihiko Odaki In-Reply-To: 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 fry.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 (fry.vger.email [0.0.0.0]); Mon, 09 Oct 2023 03:05:38 -0700 (PDT) X-Spam-Level: ** On 2023/10/09 18:54, Willem de Bruijn wrote: > On Mon, Oct 9, 2023 at 3:44 AM 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. > > It should not be possible to downgrade the hdr_sz once v1 is selected. I see nothing that prevents shrinking the header size. tun->vnet_hash.flags is read after vnet_hdr_sz so the race can happen even for the case the header size grows though this can be fixed by reordering the two reads.