From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by passt.top (Postfix) with ESMTP id A61F85A027B for ; Fri, 16 Feb 2024 10:14:44 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1708074883; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=cLdHx2k+PDumPAj0+9TISXg1EcyHoXAMBUD9JgSMwBA=; b=fd2ph9rJ5f/pXbvvOe9amhE10oN/IP4+a7lUj8bVPDeNyKImmmsKsgTSGaSkTpD4jtj8yB fv+7PZVhkaNR205zbz+3cyiYDiNXNgzFPjKJMemdwRFlW6BUjgbxb45PR19MI9PP53bC0z x4Iqevxi+0IWnvYZRWlE0U317ubyr6Y= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-213-R9Vjv8VuPKmPyn5bOjLWgw-1; Fri, 16 Feb 2024 04:14:42 -0500 X-MC-Unique: R9Vjv8VuPKmPyn5bOjLWgw-1 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-33cd063f475so150157f8f.0 for ; Fri, 16 Feb 2024 01:14:41 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708074881; x=1708679681; h=mime-version:user-agent:content-transfer-encoding:autocrypt :references:in-reply-to:date:cc:to:from:subject:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=7kgqAsAFIfE8DhFVU3oR5UKeDnB57As+Gq2juWY9v64=; b=CCPXwTEufge+7XNC0HfHdyJy2xGIfs1KJuSfpQ14rLoupfBMjdXLw3/FmBHUGcnv8x E07N42wJq4a6jmoel8hvm8wU3WPuzlhjsLOLJbZJS59UPazQTYvY4mmikfpCggSfRpO8 W6JrCGcW8hW5dC+fbunbOclOXtULEoBU3k/vzay66TnDPe/hPNnBCjOnQmnn4i4dRZ6P 8ggsF2Bp46/S1z45H8go3gTGq2lHeo4GqdTQnB0rT+kJTJE0hOWDERqqHXq8SXASxbmg JMkhAOAEzfuJ940C8BmDQBY9cHUAXT2e5v8ADzrioDu1Hqbj2E44MS2US8FDkKwdFQOX /ZdQ== X-Forwarded-Encrypted: i=1; AJvYcCU9X8dZOEQQzBw2F/ZSSoOjge+sj15miIp7yryMDw2ywA8vzUna0c5DqMLMuBlZcsZFYo2gZD3/er5sf6J/shcg8Udg X-Gm-Message-State: AOJu0YzlRDr28ezPzlsQY5DRCpUQPPMKpQPdOiWmfl3EpE+hiWLB75hE 1UON96t+MX0D3Hfgaw/ZRmOHIrpP8xSepCvbaDlqZDyHK05woXvJqayceLPukQnTlAl0TugpCUn jnMB/zdAmafLRR/ZQla2wmTYBWBjoqMkWmgfg2YxECpkV6syoog== X-Received: by 2002:a5d:6f0e:0:b0:33d:2270:89f5 with SMTP id ay14-20020a5d6f0e000000b0033d227089f5mr240617wrb.3.1708074880937; Fri, 16 Feb 2024 01:14:40 -0800 (PST) X-Google-Smtp-Source: AGHT+IGxsuF0Vn1bTsbRz9oL1Tw8TdiH4baw9wTtYRKRmUQ4HdYrvyG5r0D7FSumcX8TXWe7/SDS7g== X-Received: by 2002:a5d:6f0e:0:b0:33d:2270:89f5 with SMTP id ay14-20020a5d6f0e000000b0033d227089f5mr240605wrb.3.1708074880571; Fri, 16 Feb 2024 01:14:40 -0800 (PST) Received: from gerbillo.redhat.com (146-241-239-108.dyn.eolo.it. [146.241.239.108]) by smtp.gmail.com with ESMTPSA id x11-20020adff64b000000b0033d157bb26esm1620399wrp.32.2024.02.16.01.14.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 01:14:40 -0800 (PST) Message-ID: <9cb12376da3f6cd316320b29f294cc84eaba6cfa.camel@redhat.com> Subject: Re: [PATCH v3] tcp: add support for SO_PEEK_OFF From: Paolo Abeni To: Jon Maloy , Eric Dumazet Date: Fri, 16 Feb 2024 10:14:38 +0100 In-Reply-To: <89f263be-3403-8404-69ed-313539d59669@redhat.com> References: <20240209221233.3150253-1-jmaloy@redhat.com> <8d77d8a4e6a37e80aa46cd8df98de84714c384a5.camel@redhat.com> <20072ba530b34729589a3d527c420a766b49e205.camel@redhat.com> <725a92b4813242549f2316e6682d3312b5e658d8.camel@redhat.com> <20687849-ec5c-9ce5-0a18-cc80f5b64816@redhat.com> <178b9f2dbb3c56fcfef46a97ea395bdd13ebfb59.camel@redhat.com> <89f263be-3403-8404-69ed-313539d59669@redhat.com> Autocrypt: addr=pabeni@redhat.com; prefer-encrypt=mutual; keydata=mQINBGISiDUBEAC5uMdJicjm3ZlWQJG4u2EU1EhWUSx8IZLUTmEE8zmjPJFSYDcjtfGcbzLPb63BvX7FADmTOkO7gwtDgm501XnQaZgBUnCOUT8qv5MkKsFH20h1XJyqjPeGM55YFAXc+a4WD0YyO5M0+KhDeRLoildeRna1ey944VlZ6Inf67zMYw9vfE5XozBtytFIrRyGEWkQwkjaYhr1cGM8ia24QQVQid3P7SPkR78kJmrT32sGk+TdR4YnZzBvVaojX4AroZrrAQVdOLQWR+w4w1mONfJvahNdjq73tKv51nIpu4SAC1Zmnm3x4u9r22mbMDr0uWqDqwhsvkanYmn4umDKc1ZkBnDIbbumd40x9CKgG6ogVlLYeJa9WyfVMOHDF6f0wRjFjxVoPO6p/ZDkuEa67KCpJnXNYipLJ3MYhdKWBZw0xc3LKiKc+nMfQlo76T/qHMDfRMaMhk+L8gWc3ZlRQFG0/Pd1pdQEiRuvfM5DUXDo/YOZLV0NfRFU9SmtIPhbdm9cV8Hf8mUwubihiJB/9zPvVq8xfiVbdT0sPzBtxW0fXwrbFxYAOFvT0UC2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HMiUZhLKoZzCcU/AEFjQsPTATACGsWf3JYPnWxL9 User-Agent: Evolution 3.50.3 (3.50.3-1.fc39) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-MailFrom: pabeni@redhat.com X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation Message-ID-Hash: JGTO6NNZPNGBIGE3HOIXVSF6LS7WKCEO X-Message-ID-Hash: JGTO6NNZPNGBIGE3HOIXVSF6LS7WKCEO X-Mailman-Approved-At: Fri, 16 Feb 2024 11:51:52 +0100 CC: kuba@kernel.org, passt-dev@passt.top, sbrivio@redhat.com, lvivier@redhat.com, dgibson@redhat.com, netdev@vger.kernel.org, davem@davemloft.net X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: On Thu, 2024-02-15 at 17:24 -0500, Jon Maloy wrote: >=20 > On 2024-02-15 12:46, Eric Dumazet wrote: > > On Thu, Feb 15, 2024 at 6:41=E2=80=AFPM Paolo Abeni = wrote: > > > Note: please send text-only email to netdev. > > >=20 > > > On Thu, 2024-02-15 at 10:11 -0500, Jon Maloy wrote: > > > > I wonder if the following could be acceptable: > > > >=20 > > > > if (flags & MSG_PEEK) > > > > sk_peek_offset_fwd(sk, used); > > > > else if (peek_offset > 0) > > > > sk_peek_offset_bwd(sk, used); > > > >=20 > > > > peek_offset is already present in the data cache, and if it has t= he value > > > > zero it means either that that sk->sk_peek_off is unused (-1) or = actually is zero. > > > > Either way, no rewind is needed in that case. > > > I agree the above should avoid touching cold cachelines in the > > > fastpath, and looks functionally correct to me. > > >=20 > > > The last word is up to Eric :) > > >=20 > > An actual patch seems needed. > >=20 > > In the current form, local variable peek_offset is 0 when !MSG_PEEK. > >=20 > > So the "else if (peek_offset > 0)" would always be false. > >=20 > Yes, of course. This wouldn't work unless we read sk->sk_peek_off at the= =20 > beginning of the function. > I will look at the other suggestions. I *think* that moving sk_peek_off this way: --- diff --git a/include/net/sock.h b/include/net/sock.h index a9d99a9c583f..576a6a6abb03 100644 --- a/include/net/sock.h +++ b/include/net/sock.h @@ -413,7 +413,7 @@ struct sock { =09unsigned int=09=09sk_napi_id; #endif =09int=09=09=09sk_rcvbuf; -=09int=09=09=09sk_disconnects; +=09int=09=09=09sk_peek_off; =20 =09struct sk_filter __rcu=09*sk_filter; =09union { @@ -439,7 +439,7 @@ struct sock { =09=09struct rb_root=09tcp_rtx_queue; =09}; =09struct sk_buff_head=09sk_write_queue; -=09__s32=09=09=09sk_peek_off; +=09int=09=09=09sk_disconnects; =09int=09=09=09sk_write_pending; =09__u32=09=09=09sk_dst_pending_confirm; =09u32=09=09=09sk_pacing_status; /* see enum sk_pacing */ --- should avoid problematic accesses, The relevant cachelines layout is as follow: =09 /* --- cacheline 4 boundary (256 bytes) --- */ struct sk_buff * tail; /* 256 8 */ } sk_backlog; /* 240 24 */ int sk_forward_alloc; /* 264 4 */ u32 sk_reserved_mem; /* 268 4 */ unsigned int sk_ll_usec; /* 272 4 */ unsigned int sk_napi_id; /* 276 4 */ int sk_rcvbuf; /* 280 4 */ int sk_disconnects; /* 284 4 */ =09=09=09=09// will become sk_peek_off struct sk_filter * sk_filter; /* 288 8 */ union { struct socket_wq * sk_wq; /* 296 8 */ struct socket_wq * sk_wq_raw; /* 296 8 */ }; /* 296 8 */ struct xfrm_policy * sk_policy[2]; /* 304 16 */ /* --- cacheline 5 boundary (320 bytes) --- */ =09// ... =09 /* --- cacheline 6 boundary (384 bytes) --- */ __s32 sk_peek_off; /* 384 4 */ =09=09=09=09// will become sk_diconnects int sk_write_pending; /* 388 4 */ __u32 sk_dst_pending_confirm; /* 392 4 *= / u32 sk_pacing_status; /* 396 4 */ long int sk_sndtimeo; /* 400 8 */ struct timer_list sk_timer; /* 408 40 */ /* XXX last struct has 4 bytes of padding */ /* --- cacheline 7 boundary (448 bytes) --- */ sk_peek_off will be in the same cachline of sk_forward_alloc / sk_reserved_mem / backlog tail, that are already touched by the tcp_recvmsg_locked() main loop. WDYT? thanks! Paolo