46 Commits
Author SHA1 Message Date
Ayush RanjanandgVisor bot b5fcff511e Make atomicbitops.Bool savable.
Earlier the atomicbitops_state_autogen.go was not being built because it had
an impossible build condition: `(amd64 || arm64) && !amd64 && !arm64`.

This is a known deficiency in go_stateify tool. This was solved via having
two identical files like 32b_32bit.go and 32b_64bit.go. Just piggyback this.

This changes also enhances `atomicbitops.Bool` in the following ways:
- Added RacyLoad(), RacyStore() and CompareAndSwap() for Bool to bring it up to
  speed with the other types.
- Delegated the actual atomic operations work to the underlying Uint32.
- Cleaned up code with b32(); similar to what sync/atomic.Bool does.

PiperOrigin-RevId: 597607982
2024-01-11 11:24:32 -08:00
Etienne PerotandgVisor bot fead3284fa atomicbitops: Add atomic float64.
This adds a new atomic type, `atomicbitops.Float64`, which has similar
operations as `atomicbitops.Uint64`. It actually uses `atomicbitops.Uint64`
for storing its bits.

`atomicbitops.Float64` supports `Swap`, `CompareAndSwap`, and `Add`
operations.

This is useful in gVisor's metric library for keeping track of the
sum-of-squared-deviation statistic of distribution metrics.

PiperOrigin-RevId: 537127647
2023-06-01 14:24:59 -07:00
Adin ScannellandgVisor bot daafc82dd5 Add explicit NOFRAME annotation in assembly functions.
For all trivial and zero frame-sized functions, we now require an explicit
NOFRAME annotation as the heuristic has changed. See go.dev/cl/466316.

Most of these functions do not  *require* NOFRAME, but this change encodes
the existing behavior in order to avoid accidental bugs or regressions.

PiperOrigin-RevId: 513946210
2023-03-04 00:53:20 -08:00
Adin ScannellandgVisor bot 2911d8c3b8 Add default_applicable_licenses rules to packages.
PiperOrigin-RevId: 513581243
2023-03-02 10:50:04 -08:00
Adin ScannellandgVisor bot f230d5d6f2 Fix assembly declarations.
PiperOrigin-RevId: 511648708
2023-02-22 18:14:26 -08:00
Nicolas LacasseandgVisor bot c6df9c8269 Make nic.spoofing and nic.promiscuous atomic Bools to avoid lock contention.
Also add atomicbitops.Bool which is just a Uint32, but behaves as a boolean.

PiperOrigin-RevId: 495103870
2022-12-13 13:08:11 -08:00
gVisor bot f8ef17272f Merge pull request #7850 from bradfitz:bradfitz/cpuid
PiperOrigin-RevId: 464643287
2022-08-01 15:54:39 -07:00
Brad Fitzpatrick c78e4eea1a atomicbitops, cpuid: fix warnings, lack of atomics on macOS
Updates google/gvisor#7849
2022-07-31 19:26:54 -07:00
Ayush RanjanandgVisor bot 2026e1f078 Reformat codebase.
PiperOrigin-RevId: 449358041
2022-05-17 17:48:35 -07:00
gVisor bot d7ef1e68fd Merge pull request #7391 from zhlhahaha:2477
PiperOrigin-RevId: 446793644
2022-05-05 13:07:01 -07:00
Kevin KrakauerandgVisor bot 7ad228f148 prohibit direct use of sync/atomic (u)int32 functions
Also adds the "// +checkalignedignore" escape hatch for packages to opt out of
checking.

See cl/439349432 for justification (https://github.com/google/gvisor/pull/7376).

PiperOrigin-RevId: 444918125
2022-04-27 11:25:14 -07:00
howard zhang 45498e1633 Arm64 atomic: add LSE atomics instructions to arm64
benchmark for the atomics instructions:
Without LSE instructions:
BenchmarkAndUint32-80                           138205774                8.562 ns/op
BenchmarkAndUint64-80                           139365404                8.571 ns/op
BenchmarkAndUint32Parallel-80                   16887577               259.6 ns/op
BenchmarkAndUint64Parallel-80                    6202482               281.2 ns/op
BenchmarkOrUint32-80                            138791865                8.592 ns/op
BenchmarkOrUint64-80                            138424888                8.670 ns/op
BenchmarkOrUint32Parallel-80                    15080332               175.1 ns/op
BenchmarkOrUint64Parallel-80                     8891142               262.2 ns/op
BenchmarkXorUint32-80                           139146337                8.611 ns/op
BenchmarkXorUint64-80                           138612325                8.627 ns/op
BenchmarkXorUint32Parallel-80                    3651159               548.5 ns/op
BenchmarkXorUint64Parallel-80                   17135235               350.2 ns/op
BenchmarkCompareAndSwapUint32-80                11712571                95.49 ns/op
BenchmarkCompareAndSwapUint64-80                12229885                87.32 ns/op
BenchmarkCompareAndSwapUint32Parallel-80        11853363               115.6 ns/op
BenchmarkCompareAndSwapUint64Parallel-80        15574476                87.91 ns/op

With LSE instructions:
BenchmarkAndUint32-80                           172129803                6.933 ns/op
BenchmarkAndUint64-80                           170516512                6.993 ns/op
BenchmarkAndUint32Parallel-80                   60089396                20.14 ns/op
BenchmarkAndUint64Parallel-80                   59266794                20.01 ns/op
BenchmarkOrUint32-80                            174805162                6.835 ns/op
BenchmarkOrUint64-80                            174935716                6.836 ns/op
BenchmarkOrUint32Parallel-80                    60084607                19.89 ns/op
BenchmarkOrUint64Parallel-80                    51555650                19.99 ns/op
BenchmarkXorUint32-80                           170525718                6.835 ns/op
BenchmarkXorUint64-80                           175269829                6.842 ns/op
BenchmarkXorUint32Parallel-80                   60005954                20.15 ns/op
BenchmarkXorUint64Parallel-80                   51590584                19.95 ns/op
BenchmarkCompareAndSwapUint32-80                27096822                40.69 ns/op
BenchmarkCompareAndSwapUint64-80                27516450                39.02 ns/op
BenchmarkCompareAndSwapUint32Parallel-80        27194458                40.69 ns/op
BenchmarkCompareAndSwapUint64Parallel-80        27614142                39.25 ns/op

Signed-off-by: howard zhang <[email protected]>
2022-04-20 14:57:40 +08:00
Kevin KrakauerandgVisor bot f37cdb0bef introduce atomicbitops 32-bit types
Part of a series of changes that will end with prohibiting use of sync/atomic
(u)int32 functions. See cl/440484071 for more details.

PiperOrigin-RevId: 442673296
2022-04-18 17:41:53 -07:00
Kevin KrakauerandgVisor bot b8dd528b97 prohibit direct use of sync/atomic (u)int64 functions
All atomic 64 bit ints are changed to atomicbitops.(Ui|I)nt64. A nogo checker
enforces that sync/atomic 64 bit functions are not called.

For reviewers: the interesting changes are in the atomicbitops and checkaligned
packages.

Why do this?
- It is very easy to accidentally use atomic values without sync/atomic funcs.
- We have checkatomics, but this is optional and is forgotten in several places.
  - Using a type+checker to enforce this seems less error prone and simpler.
- We get NoCopy protection.
- Use of 64 bit atomics can break 32 bit builds. We have types to handle this
  without any runtime cost, so we might as well use them.

PiperOrigin-RevId: 440473398
2022-04-08 16:06:26 -07:00
Brad Fitzpatrick 83e70d1c6e pkg/atomicbitops: support 32-bit GOARCH value "mipsle"
mips was supported, but mipsle had been forgotten.

Fixes google/gvisor#6804
2021-11-01 08:22:07 -07:00
Koichi Shiraishi 7cfc612533 No split to assembly and noasm functions on atomicbitops package
Signed-off-by: Koichi Shiraishi <[email protected]>
2021-10-04 19:22:09 +09:00
gVisor bot 897600c2a7 Merge pull request #6182 from zchee:atomicbitops-bp
PiperOrigin-RevId: 397432940
2021-09-17 17:48:24 -07:00
Kevin KrakauerandgVisor bot e797aa6dd3 fix typo
PiperOrigin-RevId: 390463819
2021-08-12 14:43:45 -07:00
Koichi Shiraishi 3120f9d82a Use BX instead of BP at AX second op
Signed-off-by: Koichi Shiraishi <[email protected]>
2021-08-12 06:28:30 +09:00
Koichi Shiraishi 0d9dcdc72e Use BX insted of BP
Signed-off-by: Koichi Shiraishi <[email protected]>
2021-08-12 06:22:36 +09:00
Andrei Vagin 0bf1722a53 Reduce overhead of AlignedAtomic types
AlignedAtomicUint64 is 15 bytes and it takes 16 bytes in structures.  On
32-bit systems, variables and structure fields is guaranteed to be
32-bit aligned and this means that we need only 12 bytes to find 8
contiguous bytes.
2021-08-04 21:17:21 -07:00
Jamie LiuandgVisor bot f53b8a38e5 Add go:build directives as required by Go 1.17's gofmt.
PiperOrigin-RevId: 385894869
2021-07-20 16:28:45 -07:00
Koichi Shiraishi 0dbe27b4df Fix frame pointer is clobbered before saving vet issue on BP register
BP should be callee-save. It will be saved automatically if there is nonzero frame size.

$ go vet -framepointer ./pkg/atomicbitops
pkg/atomicbitops/atomicbitops_amd64.s:27:1: frame pointer is clobbered before saving
pkg/atomicbitops/atomicbitops_amd64.s:34:1: frame pointer is clobbered before saving
pkg/atomicbitops/atomicbitops_amd64.s:50:1: frame pointer is clobbered before saving
pkg/atomicbitops/atomicbitops_amd64.s:57:1: frame pointer is clobbered before saving
pkg/atomicbitops/atomicbitops_amd64.s:64:1: frame pointer is clobbered before saving

Signed-off-by: Koichi Shiraishi <[email protected]>
2021-06-14 11:09:14 +09:00
Kevin Krakauer 0abb8e5418 Use an exhaustive list of architectures 2021-05-12 10:26:21 -07:00
Kevin Krakauer 54df878b74 enable building //pkg/tcpip on 32-bit MIPS
N.B. we don't explicitly support MIPS, but there's no reason it
shouldn't work.
2021-05-12 10:14:56 -07:00
Kevin Krakauer abc05a9b25 explicitly 0-index backing array 2021-05-07 13:51:09 -07:00
Kevin Krakauer 574bb6c134 fix build constraints 2021-05-06 15:01:09 -07:00
Kevin Krakauer d72226fc46 mark types as saveable 2021-05-06 13:04:59 -07:00
Kevin Krakauer 0d7c13a2c5 Added more comments 2021-05-06 13:04:59 -07:00
Kevin Krakauer f0e6958d13 Added comments 2021-05-06 13:04:59 -07:00
Kevin Krakauer 9a5ebd49c0 Moved to atomicbitops and renamed files 2021-05-06 13:04:59 -07:00
Adin ScannellandgVisor bot 1bfa4bdd15 Automated rollback of changelist 303799678
PiperOrigin-RevId: 304221302
2020-04-01 11:06:26 -07:00
Adin ScannellandgVisor bot 11602b71b4 kvm: handle exit reasons even under EINTR.
In the case of other signals (preemption), inject a normal bounce and
defer the signal until the vCPU has been returned from guest mode.

PiperOrigin-RevId: 303799678
2020-03-30 12:37:57 -07:00
gVisor botandCopybara-Service 92eb8f11d9 Re-add atomicbitops_arm64.s to BUILD.
This was inadverently dropped by cl/295811743.

PiperOrigin-RevId: 296254482
2020-02-20 11:16:08 -08:00
gVisor bot 8f2f1ec125 atomicbitops package cleanups
- Redocument memory ordering from "no ordering" to "acquire-release". (No
  functional change: both LOCK WHATEVER on x86, and LDAXR/STLXR loops on ARM64,
  already have this property.)

- Remove IncUnlessZeroInt32 and DecUnlessOneInt32, which were only faster than
  the equivalent loops using sync/atomic before the Go compiler inlined
  non-unsafe.Pointer atomics many releases ago.

PiperOrigin-RevId: 295811743
2020-02-18 13:43:28 -08:00
Adin ScannellandgVisor bot 5cd5c2536a Standardize on tools directory.
PiperOrigin-RevId: 291745021
2020-01-27 12:21:00 -08:00
Ian GudgerandgVisor bot ee0336e6f1 New sync package.
* Rename syncutil to sync.
* Add aliases to sync types.
* Replace existing usage of standard library sync package.

This will make it easier to swap out synchronization primitives. For example,
this will allow us to use primitives from github.com/sasha-s/go-deadlock to
check for lock ordering violations.

Updates #1472

PiperOrigin-RevId: 289033387
2020-01-09 22:02:24 -08:00
Haibo Xu b50ae4b502 Enable pkg/atomicbitops support on arm64.
Signed-off-by: Haibo Xu <[email protected]>
Change-Id: I1646aaa6f07b5ec31c39c318b70f48693fe59a7c
2019-10-09 03:09:52 +00:00
Michael PrattandgVisor bot c1ace9a854 Remove go_test from go_stateify and go_marshal
They are no-ops, so the standard rule works fine.

PiperOrigin-RevId: 268776264
2019-09-12 15:10:17 -07:00
Adin ScannellandShentubot add40fd6ad Update canonical repository.
This can be merged after:
https://github.com/google/gvisor-website/pull/77
  or
https://github.com/google/gvisor-website/pull/78

PiperOrigin-RevId: 253132620
2019-06-13 16:50:15 -07:00
Michael PrattandShentubot 4d52a55201 Change copyright notice to "The gVisor Authors"
Based on the guidelines at
https://opensource.google.com/docs/releasing/authors/.

1. $ rg -l "Google LLC" | xargs sed -i 's/Google LLC.*/The gVisor Authors./'
2. Manual fixup of "Google Inc" references.
3. Add AUTHORS file. Authors may request to be added to this file.
4. Point netstack AUTHORS to gVisor AUTHORS. Drop CONTRIBUTORS.

Fixes #209

PiperOrigin-RevId: 245823212
Change-Id: I64530b24ad021a7d683137459cafc510f5ee1de9
2019-04-29 14:26:23 -07:00
Michael PrattandShentubot 2a0c69b19f Remove license comments
Nothing reads them and they can simply get stale.

Generated with:
$ sed -i "s/licenses(\(.*\)).*/licenses(\1)/" **/BUILD

PiperOrigin-RevId: 231818945
Change-Id: Ibc3f9838546b7e94f13f217060d31f4ada9d4bf0
2019-01-31 11:12:53 -08:00
Adin ScannellandShentubot 75cd70ecc9 Track paths and provide a rename hook.
This change also adds extensive testing to the p9 package via mocks. The sanity
checks and type checks are moved from the gofer into the core package, where
they can be more easily validated.

PiperOrigin-RevId: 218296768
Change-Id: I4fc3c326e7bf1e0e140a454cbacbcc6fd617ab55
2018-10-23 00:20:15 -07:00
Ian GudgerandShentubot 8fce67af24 Use correct company name in copyright header
PiperOrigin-RevId: 217951017
Change-Id: Ie08bf6987f98467d07457bcf35b5f1ff6e43c035
2018-10-19 16:35:11 -07:00
Zhaozhong NiandShentubot be7fcbc558 stateify: support explicit annotation mode; convert refs and stack packages.
We have been unnecessarily creating too many savable types implicitly.

PiperOrigin-RevId: 206334201
Change-Id: Idc5a3a14bfb7ee125c4f2bb2b1c53164e46f29a8
2018-07-27 10:17:21 -07:00
GooglerandAdin Scannell d02b74a5dc Check in gVisor.
PiperOrigin-RevId: 194583126
Change-Id: Ica1d8821a90f74e7e745962d71801c598c652463
2018-04-28 01:44:26 -04:00