netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Laight <David.Laight@ACULAB.COM>
To: 'Maxim Mikityanskiy' <maximmi@nvidia.com>
Cc: Jakub Kicinski <kuba@kernel.org>,
	"David S. Miller" <davem@davemloft.net>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Paolo Abeni <pabeni@redhat.com>,
	Boris Pismenny <borisp@nvidia.com>,
	Tariq Toukan <tariqt@nvidia.com>,
	"Saeed Mahameed" <saeedm@nvidia.com>,
	Gal Pressman <gal@nvidia.com>,
	"netdev@vger.kernel.org" <netdev@vger.kernel.org>
Subject: RE: [PATCH net-next] tls: Add opt-in zerocopy mode of sendfile()
Date: Fri, 6 May 2022 08:09:44 +0000	[thread overview]
Message-ID: <1f45be856eae43a5bca0af524f5b02b9@AcuMS.aculab.com> (raw)
In-Reply-To: <f1fa7f2c-d5ef-256b-0bc3-87950c2b6ab7@nvidia.com>

From: Maxim Mikityanskiy
> Sent: 05 May 2022 19:28
> 
> On 2022-05-05 16:48, David Laight wrote:
> > From: Maxim Mikityanskiy
> >> Sent: 05 May 2022 13:40
> >>
> >> On 2022-05-04 12:49, David Laight wrote:
> >>>>> If you declare the union on the stack in the callers, and pass by value
> >>>>> - is the compiler not going to be clever enough to still DDRT?
> >>>>
> >>>> Ah, OK, it should do the thing. I thought you wanted me to ditch the
> >>>> union altogether.
> >>>
> >>> Some architectures always pass struct/union by address.
> >>> Which is probably not what you had in mind.
> >>
> >> Do you have any specific architecture in mind? I couldn't find any
> >> information that it happens anywhere, x86_64 ABI [1] (pages 20-21)
> >> aligns with my expectations, and my common sense can't explain why would
> >> some architectures do what you say.
> >>
> >> In C, when the caller passes a struct as a parameter, the callee can
> >> freely modify it. If the compiler silently replaced it with a pointer,
> >> the callee would corrupt the caller's local variable, so such approach
> >> requires the caller to make an extra copy.
> >
> > Yes, that is what happens.
> 
> I did a quick experiment with gcc 9 on m68k and i386, and it doesn't
> confirm what you claim.
> 
> #include <stdint.h>
> #include <stdio.h>
> 
> union test {
>          uint32_t x;
>          uint32_t *y;
> };
> 
> void func1(void *ptr, union test t)
> {
>          if (ptr) {
>                  printf("%p %u\n", ptr, t.x);
>          } else {
>                  printf("%u\n", *t.y);
>          }
> }
> 
> void func2(void *ptr, uint32_t *y)
> {
>          if (ptr) {
>                  printf("%p %u\n", ptr, (uint32_t)y);
>          } else {
>                  printf("%u\n", *y);
>          }
> }
> 
> gcc -S test.c -fno-strict-aliasing -o -
> 
> I believe this minimal example reflects well enough what happens in my
> code. The assembly generated for func1 and func2 are identical. In both
> cases the second parameter is passed on the stack by value, not by pointer.

Hmmm, perhaps it is/was only sparc32 that passed all structures by reference.
godbolt doesn't seem to have a sparc compiler and I don't have a
working sparc system any more.

It is also possible that the calling conventions are slightly
different than the ones I remember using years ago.

Certainly on i386 even 4 byte structures are returned by reference.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)

  reply	other threads:[~2022-05-06  8:09 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-27 17:50 [PATCH net-next] tls: Add opt-in zerocopy mode of sendfile() Maxim Mikityanskiy
2022-04-28 22:11 ` Jakub Kicinski
2022-04-29 14:21   ` Maxim Mikityanskiy
2022-04-29 19:11     ` Jakub Kicinski
2022-05-03 18:56       ` Maxim Mikityanskiy
2022-05-03 19:24         ` Jakub Kicinski
2022-05-04  9:49         ` David Laight
2022-05-05 12:40           ` Maxim Mikityanskiy
2022-05-05 13:48             ` David Laight
2022-05-05 18:27               ` Maxim Mikityanskiy
2022-05-06  8:09                 ` David Laight [this message]
2022-05-06 16:34                   ` Maxim Mikityanskiy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1f45be856eae43a5bca0af524f5b02b9@AcuMS.aculab.com \
    --to=david.laight@aculab.com \
    --cc=borisp@nvidia.com \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=gal@nvidia.com \
    --cc=kuba@kernel.org \
    --cc=maximmi@nvidia.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=saeedm@nvidia.com \
    --cc=tariqt@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).