From owner-freebsd-bugs@freebsd.org Tue Apr 18 23:17:26 2017 Return-Path: Delivered-To: freebsd-bugs@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id A2ABAD451D9 for ; Tue, 18 Apr 2017 23:17:26 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from kenobi.freebsd.org (kenobi.freebsd.org [IPv6:2001:1900:2254:206a::16:76]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 78A92F4F for ; Tue, 18 Apr 2017 23:17:26 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from bugs.freebsd.org ([127.0.1.118]) by kenobi.freebsd.org (8.15.2/8.15.2) with ESMTP id v3INHQCG095459 for ; Tue, 18 Apr 2017 23:17:26 GMT (envelope-from bugzilla-noreply@freebsd.org) From: bugzilla-noreply@freebsd.org To: freebsd-bugs@FreeBSD.org Subject: [Bug 218597] [CRYPTODEV] spurious wakeup and synchronisation problem Date: Tue, 18 Apr 2017 23:17:26 +0000 X-Bugzilla-Reason: AssignedTo X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: Base System X-Bugzilla-Component: kern X-Bugzilla-Version: CURRENT X-Bugzilla-Keywords: patch X-Bugzilla-Severity: Affects Only Me X-Bugzilla-Who: jhb@FreeBSD.org X-Bugzilla-Status: New X-Bugzilla-Resolution: X-Bugzilla-Priority: --- X-Bugzilla-Assigned-To: freebsd-bugs@FreeBSD.org X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: https://bugs.freebsd.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 18 Apr 2017 23:17:26 -0000 https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D218597 --- Comment #3 from John Baldwin --- There's certainly nothing to prevent multiple threads from issuing ioctls against the same session. (However, having 'error' in the cse is buggy, bu= t it should also just be removed as all the uses of it check the crp->crp_etype = it is copied from just before using it anyway.) The problem is that CRYPTO_F_DONE isn't really safe for how the /dev/crypto ioctl handlers are using it (and probably isn't safe to use at all and shou= ld arguably be removed). Instead, the sleeps need to be conditional on a flag that the callback function itself sets. Probably the right way to handle t= his is to allocate a separate structure that crp_opaque points to that contains= the "done" flag and a pointer to the cse. The callback would set the done flag under the cse lock and then issue the wakeup, and the ioctl routines would sleep on this done flag in the new structure. Something like: struct crypt_op_data { bool done; struct csession *cse; } crypto_dev_op() { struct crypt_op_data *cod; ... cod =3D malloc(sizeof(*cod), M_WAITOK | M_ZERO); cod->cse =3D cse; ... crp->crp_opaque =3D cod; /* not 'cse' anymore */ ... crypto_dispatch(); mtx_lock(&cse->lock); while (error =3D=3D 0 && !cod->done) mtx_sleep(crp, &cse->lock, ...); mtx_unlock(&cse->lock); ... /* be sure to clear done if retrying */ } cryptodev_cb() { struct cryptop *crp =3D op; struct crypto_op_data *cod =3D crp->crp_opaque; mtx_lock(&cod->cse->lock); cod->done =3D true; mtx_unlock(&cod->cse->lock); wakeup(crp);=20=20=20=20 } --=20 You are receiving this mail because: You are the assignee for the bug.=