Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp1759180rdb; Mon, 9 Oct 2023 01:44:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGvva9KWhv3wOsa2XwzWpS0gFCNn1lkkj6GHuxtPKoTTd/MaE6AV/AdKbAOW1D8TfOQtOrS X-Received: by 2002:a17:902:ce8b:b0:1bc:7441:d81a with SMTP id f11-20020a170902ce8b00b001bc7441d81amr15116490plg.6.1696841099154; Mon, 09 Oct 2023 01:44:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696841099; cv=none; d=google.com; s=arc-20160816; b=n32vwOan1l4e3BVTyetYar2ldpQORS+jI+jXNTunVuEKZRE48i/PoFTUFUntq9Ezz6 jnRwa1V4M/dovZcVuOkM4IdWE1YuNzKN5nMOznph758bnZABrTga/ifU5ea8dHVkjPV+ N9S3uH364UtrHLjZwY0aB6Fu1ZqPIjyPPsJSYUuiFD5UeCbDbYE0ClejIuSij21mBFOg sc3Dc944+44vtNvHvKTmH6QDjmEZYv/9QtJTS3BgqO3322rA7T4H5JEXXtYjVD6g+FfY pwAgmsoYFn7f5aJGcdC+LI2XwRuoKW4aJnwEW82eyHQlcp9zRQM1lk0TskP1Wv1MiTqP OEwA== 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 :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=2NgGjX5YpaL52FNYH4ty5Y7bA0h/vA8gQAgoFoY58+k=; fh=rvA6+mpTFR+bDtNgVM8f2ZolmredGNfNaQmjMHCI1BM=; b=NvYMm3Grun9fx25tI/n984rOTdXNI0LHZ6Q7g7QXuuRII7IIWluaAKZ/oDUc84wqFK 94vZ6il6ATmH5VdGcwVCMnXcNyuGHlmC7O2fADjQBhGZ33PnHV1pHzq4zTHYlAg4f1c/ 4Bp37QoAV/Py9aHu1/BwCjJiddQ/HwgNc/9Enlm+i0rkdzBNU5PMuyx1Jco+ke9UejB2 yXLso63ft/g0ZVssn3AjQ2xatap3qU60az9apTfsEYL22yihc7uq3/NSQ7Z6M5J9H8Pr vpH6jnZ0ITFmRlMRSAycOAnsnQ+5dgxoOrrlQgXVIoDU7/mjFruEaMV0qrU83L9jUZEL IPoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@daynix-com.20230601.gappssmtp.com header.s=20230601 header.b="qJFvg8/1"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id y14-20020a170902b48e00b001c3e8a6748asi5234879plr.644.2023.10.09.01.44.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 01:44:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@daynix-com.20230601.gappssmtp.com header.s=20230601 header.b="qJFvg8/1"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 B5E188021723; Mon, 9 Oct 2023 01:44:56 -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 S1345527AbjJIIod (ORCPT + 99 others); Mon, 9 Oct 2023 04:44:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345506AbjJIIoa (ORCPT ); Mon, 9 Oct 2023 04:44:30 -0400 Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3CED09F for ; Mon, 9 Oct 2023 01:44:29 -0700 (PDT) Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-692a885f129so3124031b3a.0 for ; Mon, 09 Oct 2023 01:44:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1696841068; x=1697445868; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=2NgGjX5YpaL52FNYH4ty5Y7bA0h/vA8gQAgoFoY58+k=; b=qJFvg8/1UQjpzWGLwmhfH00/0lkT4jImKvjzwp2hDS/aOBQNVTpG0POeQ6cKGGPK8p rf7z2ZsEpX3gloi21jYM4THdYPgLGsgZKZUcALwD+rNztpgZhfDe57/2FdP2yszVkB0K vUhepehp2OvuSv71WfEGXL8l+HOb/zLXGJvc945HB4/13JTnixq3wzPer1D+KsVICzAT qi3zRPO+DwUU9lT4FkOTExfcW5WCxnEfl3/o9cq9mTf9bP13Th4KkCbwCks/S73A+f1v Q4pkncYWHMRQMYhb5b1qp2sqqXdTXV/yDAhEL25srHWBDymeQIs+jQs+JhFO1eYoOCEl 0wNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696841068; x=1697445868; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=2NgGjX5YpaL52FNYH4ty5Y7bA0h/vA8gQAgoFoY58+k=; b=iE53+FHq+u/fPaaq0bilUvAXXlrC0iC9LLyNAeSD5PGQYvvMypPsHBCzSrXPb4LOBk iXtWk5/Vr90AkMBIrzVWNHyYYNE4cBxXel+cj6gCgj+9QzvySx+WsTBe6ByJZ2jj5Pqv co3lmt56P7OXkjiOtBtvZtMN86cR5tPy3yy5VVmMVQbA3Ozfydi6kHcvDsBbYglNpLMz UWH3mF88Hhs6r4ca6DczvhP+ETsJBw6pe6AQnfT3PHmtEv6lsU3cm/KRE9W71HrT+BIb 8Tuxwiks1dz+5t7gLfpKe67+7apj4X0Xf0iseZ/G+ChBeZrDKOacBnAFGejfjazJYHMZ evew== X-Gm-Message-State: AOJu0Yz896GU6N2DahnH6nrRcSLozRjAQz3C/MvwMTSc8IBVyyQ1KMTH 6lH9vp51UBuigTlcDp5prd9A3w== X-Received: by 2002:a05:6a20:2445:b0:14e:3ba7:2933 with SMTP id t5-20020a056a20244500b0014e3ba72933mr14489341pzc.54.1696841068641; Mon, 09 Oct 2023 01:44:28 -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 h19-20020aa786d3000000b0068ff267f092sm5777762pfo.216.2023.10.09.01.44.22 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 09 Oct 2023 01:44:28 -0700 (PDT) Message-ID: <48e20be1-b658-4117-8856-89ff1df6f48f@daynix.com> Date: Mon, 9 Oct 2023 17:44:20 +0900 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RFC PATCH 5/7] tun: Introduce virtio-net hashing feature 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> Content-Language: en-US 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 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 01:44:56 -0700 (PDT) X-Spam-Level: ** 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.