From owner-svn-src-all@freebsd.org Thu Feb 6 23:45:56 2020 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id C08B923E3EF; Thu, 6 Feb 2020 23:45:56 +0000 (UTC) (envelope-from jkim@FreeBSD.org) Received: from smtp.freebsd.org (smtp.freebsd.org [IPv6:2610:1c1:1:606c::24b:4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "smtp.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 48DFS44bxfz3NH9; Thu, 6 Feb 2020 23:45:56 +0000 (UTC) (envelope-from jkim@FreeBSD.org) Received: from freefall.freebsd.org (static-71-168-218-4.cmdnnj.fios.verizon.net [71.168.218.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) (Authenticated sender: jkim/mail) by smtp.freebsd.org (Postfix) with ESMTPSA id 884052A5EF; Thu, 6 Feb 2020 23:45:56 +0000 (UTC) (envelope-from jkim@FreeBSD.org) Subject: Re: svn commit: r357641 - head/sys/kern To: Michael Tuexen , Jeff Roberson Cc: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org References: <202002062051.016KpkjY000137@repo.freebsd.org> <7AE9BE83-5240-4708-81B9-989DCF398940@macmic.franken.de> From: Jung-uk Kim Autocrypt: addr=jkim@FreeBSD.org; prefer-encrypt=mutual; keydata= mQENBFJBztUBCAChqNyGqmFuNo0U7MBzsD+q/G6Cv0l7LGVrOAsgh34M8wIWhD+tztDWMVfn AhxNDd0ceCj2bYOe67sTQxAScEcbt2FfvPOLp9MEXb9qohZj172Gwkk7dnhOhZZKhVGVZKM4 NcsuBDUzgf4f3Vd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ACgkQfJ+WJvzb8UZcJQf+IsTCxUEqY7W/pT84sMg5/QD3s6ufTRncvq14fEOxCNq1Rf4Q 9P+tOFa8GZfKDGB2BFGIrW7uT5mlmKdK1vO6ZIA930y5kUsnCmBUEBJkE2ciSQk01aB/1o62 Q3Gk/F6BwtNY9OXiqF7AcAo+K/BMIaqb26QKeh+IIgK1NN9dQiq3ByTbl4zpGZa6MmsnnRTu mzGKt2nkz7vBzH6+hZp1OzGZikgjjhYWVFoJo1dvf/rv4obs0ZJEqFPQs/1Qa1dbkKBv6odB XJpPH0ssOluTY24d1XxTiKTwmWvHeQkOKRAIfD7VTtF4TesoZYkf7hsh3e3VwXhptSLFnEOi WwYofg== Message-ID: <0a518d40-063a-c6d2-e974-0f976600196b@FreeBSD.org> Date: Thu, 6 Feb 2020 18:45:51 -0500 User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:68.0) Gecko/20100101 Thunderbird/68.4.2 MIME-Version: 1.0 In-Reply-To: <7AE9BE83-5240-4708-81B9-989DCF398940@macmic.franken.de> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="Rtt1v3CWJSnKhITqQYFNbjPB66tUdp2Uk" X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 06 Feb 2020 23:45:56 -0000 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 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--