Development discussion of WireGuard
 help / color / mirror / Atom feed
From: Lev Stipakov <lstipakov@gmail.com>
To: wireguard@lists.zx2c4.com
Subject: Volatile in Wintun
Date: Mon, 19 Aug 2019 10:26:34 +0300	[thread overview]
Message-ID: <CAGyAFMWzGbheVD6iOm=UZxbkmHOWCPHq7QzCi3_BpGbZT4f2kA@mail.gmail.com> (raw)


[-- Attachment #1.1: Type: text/plain, Size: 1261 bytes --]

Hi,

I am working on Wintun support for OpenVPN..

I am a bit unsure about the purpose of volatile in Wintun.

According to https://en.cppreference.com/w/cpp/atomic/memory_order,
volatile ensures that accesses are not reordered within the thread of
execution, but order is not guaranteed to be observed by another thread.

On the other hand, Visual Studio generates memory barriers while accessing
volatile objects and targeting non-ARM architectures
https://docs.microsoft.com/en-us/cpp/cpp/volatile-cpp?view=vs-2019#microsoft-specific.
However, it also says that "for architectures other than ARM we strongly
recommend that you specify /volatile:iso, and use explicit synchronization
primitives and compiler intrinsics when you are dealing with memory that is
shared across threads."

A few question I would like to ask:

- Is guarantee that accesses are not reordered within the thread of
execution is enough?

- Do we rely on Microsoft-specific behavior of volatile for non-ARM
architecture?

- Could reordering performed in ARM be a problem? If yes, shouldn't we
(wintun and client app) use memory fences to synchronize accesses between
threads? In openvpn3 we use C++11 so we were thinking about
std::atomic_long with acquire/release semantics.

-- 
-Lev

[-- Attachment #1.2: Type: text/html, Size: 1807 bytes --]

[-- Attachment #2: Type: text/plain, Size: 148 bytes --]

_______________________________________________
WireGuard mailing list
WireGuard@lists.zx2c4.com
https://lists.zx2c4.com/mailman/listinfo/wireguard

             reply	other threads:[~2019-08-19 17:39 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-19  7:26 Lev Stipakov [this message]
2019-08-19 18:15 ` Jason A. Donenfeld
2019-08-21 13:14   ` Lev Stipakov
2019-08-24 12:41     ` Jason A. Donenfeld

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='CAGyAFMWzGbheVD6iOm=UZxbkmHOWCPHq7QzCi3_BpGbZT4f2kA@mail.gmail.com' \
    --to=lstipakov@gmail.com \
    --cc=wireguard@lists.zx2c4.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).