Date: Thu, 6 Feb 2020 18:45:51 -0500 From: Jung-uk Kim <jkim@FreeBSD.org> To: Michael Tuexen <Michael.Tuexen@macmic.franken.de>, Jeff Roberson <jeff@freebsd.org> Cc: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: Re: svn commit: r357641 - head/sys/kern Message-ID: <0a518d40-063a-c6d2-e974-0f976600196b@FreeBSD.org> In-Reply-To: <7AE9BE83-5240-4708-81B9-989DCF398940@macmic.franken.de> References: <202002062051.016KpkjY000137@repo.freebsd.org> <7AE9BE83-5240-4708-81B9-989DCF398940@macmic.franken.de>
next in thread | previous in thread | raw e-mail | index | archive | help
This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --Rtt1v3CWJSnKhITqQYFNbjPB66tUdp2Uk Content-Type: multipart/mixed; boundary="6cqrPkMlZL8wLtuUmSQX9VAUd7ctxRTZU" --6cqrPkMlZL8wLtuUmSQX9VAUd7ctxRTZU Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: quoted-printable On 2/6/20, Michael Tuexen wrote: >=20 >=20 >> On 6. Feb 2020, at 21:51, Jeff Roberson <jeff@freebsd.org> wrote: >> >> Author: jeff >> Date: Thu Feb 6 20:51:46 2020 >> New Revision: 357641 >> URL: https://svnweb.freebsd.org/changeset/base/357641 >> >> Log: >> Fix a race in smr_advance() that could result in unnecessary poll cal= ls. >> >> This was relatively harmless but surprising to see in counters. The >> race occurred when rd_seq was read after the goal was updated and we >> incorrectly calculated the delta between them. >> >> Reviewed by: rlibby >> Differential Revision: https://reviews.freebsd.org/D23464 >> >> Modified: >> head/sys/kern/subr_smr.c >> >> Modified: head/sys/kern/subr_smr.c >> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D >> --- head/sys/kern/subr_smr.c Thu Feb 6 20:47:50 2020 (r357640) >> +++ head/sys/kern/subr_smr.c Thu Feb 6 20:51:46 2020 (r357641) >> @@ -160,7 +160,7 @@ static uma_zone_t smr_zone; >> #define SMR_SEQ_INCR (UINT_MAX / 10000) >> #define SMR_SEQ_INIT (UINT_MAX - 100000) >> /* Force extra polls to test the integer overflow detection. */ >> -#define SMR_SEQ_MAX_DELTA (1000) >> +#define SMR_SEQ_MAX_DELTA (SMR_SEQ_INCR * 32) >> #define SMR_SEQ_MAX_ADVANCE SMR_SEQ_MAX_DELTA / 2 >> #endif >> >> @@ -188,7 +188,7 @@ smr_seq_t >> smr_advance(smr_t smr) >> { >> smr_shared_t s; >> - smr_seq_t goal; >> + smr_seq_t goal, s_rd_seq; >> >> /* >> * It is illegal to enter while in an smr section. >> @@ -203,12 +203,18 @@ smr_advance(smr_t smr) >> atomic_thread_fence_rel(); >> >> /* >> + * Load the current read seq before incrementing the goal so >> + * we are guaranteed it is always < goal. >> + */ >> + s =3D zpcpu_get(smr)->c_shared; >> + s_rd_seq =3D atomic_load_acq_int(&s->s_rd_seq); >> + >> + /* >> * Increment the shared write sequence by 2. Since it is >> * initialized to 1 this means the only valid values are >> * odd and an observed value of 0 in a particular CPU means >> * it is not currently in a read section. >> */ >> - s =3D zpcpu_get(smr)->c_shared; >> goal =3D atomic_fetchadd_int(&s->s_wr_seq, SMR_SEQ_INCR) + SMR_SEQ_IN= CR; >> counter_u64_add(advance, 1); >> >> @@ -217,7 +223,7 @@ smr_advance(smr_t smr) >> * far ahead of the read sequence number. This keeps the >> * wrap detecting arithmetic working in pathological cases. >> */ >> - if (goal - atomic_load_int(&s->s_rd_seq) >=3D SMR_SEQ_MAX_DELTA) { >> + if (SMR_SEQ_DELTA(goal, s_rd_seq) >=3D SMR_SEQ_MAX_DELTA) { > SMR_SEQ_DELTA is not defined, therefore compilation fails. https://reviews.freebsd.org/D23464#516866 https://reviews.freebsd.org/D23464#516881 Jung-uk Kim > Best regards > Michael >> counter_u64_add(advance_wait, 1); >> smr_wait(smr, goal - SMR_SEQ_MAX_ADVANCE); >> } --6cqrPkMlZL8wLtuUmSQX9VAUd7ctxRTZU-- --Rtt1v3CWJSnKhITqQYFNbjPB66tUdp2Uk Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAEBCAAdFiEEl1bqgKaRyqfWXu/CfJ+WJvzb8UYFAl48pTQACgkQfJ+WJvzb 8UaazQgAkVny0K6ZT+ZtG5lH+9M/Uky1NRDwqLQv6IJxcTY5IfsJ/M+so21nKJch Bfl4Tt4Cjr7HOI3sa8qbX3JnqkdF/85aENgcUFFj7WjifeWTzKn/I9is9NQBIuML PMQ7txvN2BriLyc0cgOeyhlI4PgiVtcGWXBv0vQuCOik4J6TIYZvei2bqoFVKjN3 MAbYlkvj0jm3QdlsKhKLrlxYbVs/QF04+WyVUcsibiGi/h/nLQ6ILBKDzsyQUzEr LVDG1CX3wJDObxz/4kdgVQZTPkNZk6j58hqqzdyiEbnue2YN6UXXmP2HlZwHUenZ d4F6q1zaKE7xi7qFJI5cAuSiHDfKGg== =Gyf4 -----END PGP SIGNATURE----- --Rtt1v3CWJSnKhITqQYFNbjPB66tUdp2Uk--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?0a518d40-063a-c6d2-e974-0f976600196b>