Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp1790862rdb; Mon, 9 Oct 2023 03:08:27 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFn6TZjwPpuF7aalrgLPjMqkMcffdtFEiw3cB4vFouYDy1HorstyfMGiOxhrfw86HtGWU+u X-Received: by 2002:a05:6358:9042:b0:143:788c:2560 with SMTP id f2-20020a056358904200b00143788c2560mr17305282rwf.15.1696846107655; Mon, 09 Oct 2023 03:08:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696846107; cv=none; d=google.com; s=arc-20160816; b=gS0qu41p/u57H+1cF5zSPagRXZTrzzIyyz6iuh8bqDiiCX9nFY4UpzntUAE8rN9tB/ WUXtpRJ92jyDSNPmp7zkv9hhGEsqrAYSGrsNKprO1yOyrzv9X2AvbBGL+4p03gIA3ym2 5jlParfEjqFVhIEovlYj2fQ/4Bv7QXb7osgTzY4o0g9lzDS0yVnkZ9uD0qbID3UmFCmh qe43ie0k99xSs0SgNs8QZM81M9rMak/pIsnTFe0QKbiytOCg8MI4L1ByHxXhvei7TEha SD/B7+r4EhqjYtBy28LEIjKbBijjYgoLCjyxjgJywG77fLGqwnh4fM2Yu253Kci5fFnN OlUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=vbHOermRMrKRk+X0HGNdbhFKu1xqDfORpCgcvsbzg3U=; fh=aeUE1vhIzgES3jiV/KeS+NvJyPFZAHKLI4bkTDWUfZ0=; b=KH0fTiK/w3kevbrJ6/Grv8wS19eOoKmBoUO6Qs0+wEyO3SFNIamMd6J+asf3ay84C+ xVSIUMDBzbFgzfpkM74Cq94fnlPNYAxmhbkXQxRZF5i7spszwLdC/oykI1c8TT3NYeZD 3JhexxV+QxCsPrXSMFQV3NJ1wKi70kdK2txa0nqxq2H2PCXx90OPtygW0XvrZuVPhGtD BXIoB0opl8Hy7OSUfD2NDteWXWEkTracPhc1LiMjMCZpRIO6E92rDFJ3Nam5yd2/y5sr EMn3B7lxxPk2zxWVE9Y3oe7wlqDIL2pGvv2ugCWVh3ElKNit37z/uTptdC1UWurbzo32 ByRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=cCBn5jir; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id kb11-20020a17090ae7cb00b0027cd01b6cb0si734296pjb.125.2023.10.09.03.08.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 03:08:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=cCBn5jir; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 1199780412EA; Mon, 9 Oct 2023 03:08:25 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346069AbjJIKIK (ORCPT + 99 others); Mon, 9 Oct 2023 06:08:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48544 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346048AbjJIKII (ORCPT ); Mon, 9 Oct 2023 06:08:08 -0400 Received: from mail-ua1-x932.google.com (mail-ua1-x932.google.com [IPv6:2607:f8b0:4864:20::932]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 30D909F; Mon, 9 Oct 2023 03:08:06 -0700 (PDT) Received: by mail-ua1-x932.google.com with SMTP id a1e0cc1a2514c-7ab8696d047so1686299241.1; Mon, 09 Oct 2023 03:08:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696846085; x=1697450885; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=vbHOermRMrKRk+X0HGNdbhFKu1xqDfORpCgcvsbzg3U=; b=cCBn5jiriDqSzevJshBcOQc8IDRPUcX1eQmDGtDWD6utbaNLS2p+kOUmCBfmOsda9V FFU7YCticytSCMEExNC3iTruqgwYbLzWa8x3PeNQAfU0bSFiVIi8OllX8uBEXvX992oB JnPDpf6brX95o0WJ2a7kyP9cUdqQ069JKUyROoZt6tzEco7pdexv9xtVYDShlHLplPZL ycPJqUG6RGq+XrLhAxy+3Ve9l0sjPeGHDYa0/jTegwMftoxMvZlUqAmQxu9Cs2CpVa0j 45yLDr1cXlYgLeuHVL59XKfUIirCqq8k3gcQ6TRgyxc73bAVv4UegFDa8YNIeEXvY7uS fz+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696846085; x=1697450885; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vbHOermRMrKRk+X0HGNdbhFKu1xqDfORpCgcvsbzg3U=; b=t+XF1YUcQ7iH4duBzNtXuzMCRGg9agH99CmjZDgw5G0uIYLAhAGiLmPTjzkMK2EmyM lCdVdlxYpSQMJ+ECOAbM54EtkSuDDaxMz9d4vgvAXSlNAEnOmd7MLo+Phzjz2UcK38g+ twMy8Jiynxm3PjQ9WareubC9oQ6Wd/BXwppTU84a3wIJ/gOU+cmhq1E3CTdPVAmE2sDh s+LpMS62RJEZd6+GyXx8G19uSaOaka9uVsNOyMSyFS+Q0SrOszdaYSS788Tf+hhJ72b6 D39TQqKNKb/H9+cwA0j0t8LeDWBtlN00Te4cRfI1aWEzUJMbwpMJDsYyNBJuiBsl2cDZ as0g== X-Gm-Message-State: AOJu0Yw/grej5DmUdMAZu3J5ySG7DkQNyoje8QIq8SHtXhC7+81IIjrI H3evpq+qv4Z9cAOQ4Ezoq7+ooSxaQO2cdOAc7Lw= X-Received: by 2002:a67:f6c1:0:b0:452:635e:2710 with SMTP id v1-20020a67f6c1000000b00452635e2710mr13995568vso.0.1696846085188; Mon, 09 Oct 2023 03:08:05 -0700 (PDT) MIME-Version: 1.0 References: <20231008052101.144422-1-akihiko.odaki@daynix.com> <20231008052101.144422-6-akihiko.odaki@daynix.com> <48e20be1-b658-4117-8856-89ff1df6f48f@daynix.com> <6a698c99-6f02-4cfb-a709-ba02296a05f7@daynix.com> In-Reply-To: <6a698c99-6f02-4cfb-a709-ba02296a05f7@daynix.com> From: Willem de Bruijn Date: Mon, 9 Oct 2023 03:07:27 -0700 Message-ID: Subject: Re: [RFC PATCH 5/7] tun: Introduce virtio-net hashing feature To: Akihiko Odaki 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=3.0 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, 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 howler.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 (howler.vger.email [0.0.0.0]); Mon, 09 Oct 2023 03:08:25 -0700 (PDT) X-Spam-Level: ** On Mon, Oct 9, 2023 at 3:05=E2=80=AFAM Akihiko Odaki wrote: > > > > On 2023/10/09 18:54, Willem de Bruijn wrote: > > On Mon, Oct 9, 2023 at 3:44=E2=80=AFAM Akihiko Odaki wrote: > >> > >> On 2023/10/09 17:13, Willem de Bruijn wrote: > >>> On Sun, Oct 8, 2023 at 12:22=E2=80=AFAM 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 overc= ome > >>>> thse challenges. An alternative solution is to extend the eBPF steer= ing > >>>> program so that it will be able to report to the userspace, but it m= akes > >>>> 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 conforman= t > >>>> with the specification. > >>>> > >>>> Signed-off-by: Akihiko Odaki > >>> > >>>> @@ -2116,31 +2172,49 @@ static ssize_t tun_put_user(struct tun_struc= t *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 >=3D sizeof(hdr.v1_hash_hdr) && > >>>> + skb->tun_vnet_hash) { > >>> > >>> Isn't vnet_hdr_sz guaranteed to be >=3D 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 a= re > >> 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. One option is to fail any control path that tries to re-negotiate header size once this hash option is enabled? There is no practical reason to allow feature re-negotiation at any arbitrary time.