Skip to content

build: add go runtime patch to bound non-preemptible work#118605

Merged
craig[bot] merged 3 commits intocockroachdb:masterfrom
nicktrav:nickt.go-crypto-patches
Feb 15, 2024
Merged

build: add go runtime patch to bound non-preemptible work#118605
craig[bot] merged 3 commits intocockroachdb:masterfrom
nicktrav:nickt.go-crypto-patches

Conversation

@nicktrav
Copy link
Copy Markdown
Collaborator

@nicktrav nicktrav commented Feb 1, 2024

There are two commits in this patch set, and are best reviewed individually.


The first is a purely mechanical change to reapply our existing Go runtime patches to the upstream, and then port the diff back into Cockroach. This shuffles around the ordering of the various patches, making subsequent patching simpler.

The second patch is cribbed from golang/go#64417, and is the material change, touching #115192.

Epic: None.

@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

@nicktrav nicktrav marked this pull request as ready for review February 2, 2024 15:08
@nicktrav nicktrav requested a review from a team as a code owner February 2, 2024 15:08
@nicktrav nicktrav requested review from dt, nvb and sumeerbhola February 2, 2024 15:09
@nicktrav
Copy link
Copy Markdown
Collaborator Author

nicktrav commented Feb 2, 2024

Also probably a good idea to get someone from security to take a look at the second commit that has the crypto package changes.

@nicktrav nicktrav force-pushed the nickt.go-crypto-patches branch from 94d6d35 to 45b0365 Compare February 2, 2024 17:22
@nicktrav
Copy link
Copy Markdown
Collaborator Author

nicktrav commented Feb 2, 2024

Test failure is #118520. I'll rebase.

We currently maintain a set of patches to the Go runtime. To-date, our
various patches have accumulated in a single patch file. Ideally, our
set of patches should be periodically re-applied to the base of the Go
runtime that we build, to ensure that our patches still apply cleanly.
However, the lack of ordering in the patch currently file makes this
difficult.

Alphabetize the patches to avoid future diff cheese.

The changes in this patch were generated using the following:

```
_patch_file="$CRDB_SRC_ROOT/build/teamcity/internal/release/build-and-publish-patched-go/diff.patch"
$ cd go
$ git checkout go1.21.5
$ git apply "$_patch_file"
$ git diff > "$_patch_file"
```

Release note: None.
Assembly code is non-preemptible, and goroutines running such
pre-emptible calls can delay stop-the-world GC pauses, impacting tail
latency if they are timed poorly.

Certain backup codepaths in Cockroach will spend a material amount of
time encrypting large blocks of data. These calls involve
non-preemptible calls.

Mitigate the risk for these crypto libraries by bounding the work that
any single call into an assembly routine performs.

The impact of this change on the `BenchmarkLatencyWhileHashing` can be
found here. In particular, for the SHA256 algorithm, the impact on
latency was observed to improve by close to 2x, when encrypting larger
block sizes.

Inspiration taken from golang/go#/64417.

Touches cockroachdb#115192.

Release note: None.
@nicktrav nicktrav force-pushed the nickt.go-crypto-patches branch from 45b0365 to b018b1b Compare February 2, 2024 20:07
@dt
Copy link
Copy Markdown
Contributor

dt commented Feb 2, 2024

get someone from security to take a look

Filed https://cockroachlabs.atlassian.net/browse/SECSERV-28

Copy link
Copy Markdown
Contributor

@rsevinsky-cr rsevinsky-cr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 3 of 3 files at r2, all commit messages.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @dt, @nvanbenschoten, and @sumeerbhola)

Copy link
Copy Markdown
Contributor

@rsevinsky-cr rsevinsky-cr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @dt, @nvanbenschoten, and @sumeerbhola)

@dt dt removed their request for review February 15, 2024 17:31
This commit updates the go stdlib patch from the previous commit to
include testing that exercises the sha256 portion.

Epic: None
Release note: None
Copy link
Copy Markdown
Contributor

@nvb nvb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewed 1 of 1 files at r1, 2 of 3 files at r2.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @nicktrav, @rsevinsky-cr, and @sumeerbhola)


build/teamcity/internal/release/build-and-publish-patched-go/diff.patch line 177 at r2 (raw file):

 	if len(p) >= chunk {
 		n := len(p) &^ (chunk - 1)
+		for n > maxAsmSize {

Without any new testing, we won't have any test coverage for the sha256 version of this logic. I've gone ahead and pushed a new commit to this PR to add testing for sha256. Since this is just testing, I won't rebuild the custom go sdk.

@dt
Copy link
Copy Markdown
Contributor

dt commented Feb 15, 2024

CI failure appears to just be that merge base is too old to have #118665

@dt
Copy link
Copy Markdown
Contributor

dt commented Feb 15, 2024

bors r=nvanbenschoten,rickystewart,rsevinsky-cr

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Feb 15, 2024

Build succeeded:

@craig craig bot merged commit e1459bd into cockroachdb:master Feb 15, 2024
@nicktrav nicktrav deleted the nickt.go-crypto-patches branch April 13, 2024 02:59
@dt
Copy link
Copy Markdown
Contributor

dt commented Apr 18, 2024

blathers backport 23.2

@blathers-crl
Copy link
Copy Markdown

blathers-crl bot commented Apr 18, 2024

Encountered an error creating backports. Some common things that can go wrong:

  1. The backport branch might have already existed.
  2. There was a merge conflict.
  3. The backport branch contained merge commits.

You might need to create your backport manually using the backport tool.


error creating merge commit from b018b1b to blathers/backport-release-23.2-118605: POST https://api.github.com/repos/cockroachdb/cockroach/merges: 409 Merge conflict []

you may need to manually resolve merge conflicts with the backport tool.

Backport to branch 23.2 failed. See errors above.


🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

@dt
Copy link
Copy Markdown
Contributor

dt commented Apr 18, 2024

Yeah, figured that was going to be its answer :(

aadityasondhi added a commit to aadityasondhi/cockroach that referenced this pull request Apr 22, 2024
This commit applies changes from cockroachdb#118605 into v23.2. It includes the
following commits:

---

build: bound work in non-preemptible assembly loops

Assembly code is non-preemptible, and goroutines running such
pre-emptible calls can delay stop-the-world GC pauses, impacting tail
latency if they are timed poorly.

Certain backup codepaths in Cockroach will spend a material amount of
time encrypting large blocks of data. These calls involve
non-preemptible calls.

Mitigate the risk for these crypto libraries by bounding the work that
any single call into an assembly routine performs.

The impact of this change on the `BenchmarkLatencyWhileHashing` can be
found here. In particular, for the SHA256 algorithm, the impact on
latency was observed to improve by close to 2x, when encrypting larger
block sizes.

Inspiration taken from golang/go#/64417.

---

build: add testing for crypto/sha256 patch

This commit updates the go stdlib patch from the previous commit to
include testing that exercises the sha256 portion.

Epic: None
Release note: None
aadityasondhi added a commit to aadityasondhi/cockroach that referenced this pull request Apr 23, 2024
This commit applies changes from cockroachdb#118605 into v23.1. It includes the
following commits:

---

build: bound work in non-preemptible assembly loops

Assembly code is non-preemptible, and goroutines running such
pre-emptible calls can delay stop-the-world GC pauses, impacting tail
latency if they are timed poorly.

Certain backup codepaths in Cockroach will spend a material amount of
time encrypting large blocks of data. These calls involve
non-preemptible calls.

Mitigate the risk for these crypto libraries by bounding the work that
any single call into an assembly routine performs.

The impact of this change on the `BenchmarkLatencyWhileHashing` can be
found here. In particular, for the SHA256 algorithm, the impact on
latency was observed to improve by close to 2x, when encrypting larger
block sizes.

Inspiration taken from golang/go#/64417.

---

build: add testing for crypto/sha256 patch

This commit updates the go stdlib patch from the previous commit to
include testing that exercises the sha256 portion.

Epic: None
Release note: None
@irfansharif
Copy link
Copy Markdown
Contributor

Cool!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants