Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp4820287ybl; Wed, 22 Jan 2020 05:22:40 -0800 (PST) X-Google-Smtp-Source: APXvYqwH3UkWpOKavVzwSovCHTH8gF5+jwLWHHsKgnW5n69/+5+Bm1cBMbptf4SlUdl+IQ/0Z8XS X-Received: by 2002:aca:b608:: with SMTP id g8mr6882533oif.142.1579699360398; Wed, 22 Jan 2020 05:22:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579699360; cv=none; d=google.com; s=arc-20160816; b=DMV9fOxDtH3GjVl84OnzV1XLGNCOtBKMezX08UEIcpbdTUnWJc51pXaWRSdmHC/EeD VQQzVWKPcmotKmKbIkBz62lP9c7MaBHY2zFlauz14uYhsWkgz7npwgJnOqiela7YVO4s f9moJpXuhBVGlLq3xgKsXDR/XzIq3AXlgmi+B4OQlu08x828jVuo+39241sfe36HxuO0 liL8EuWnwKJQ6w9isWa73Q4J2fgbpeV8RMsZvhrNIA+ggEt3IX+BfBTKNcDmyj7LwdEc O9ltax4MIr2168twLN7hsusYJ+2HqQB2b9v42FXC4NiigCi9Z4OF3W0SWuVLJIqn3RMR PdWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ziN/3CQUTSE/nK+nlspuNLKiZr/puekpmZKbtXZi0zM=; b=jmW311PJURnA2/+QXDv3nmg9CjUhZEbPksPUftEBPu/VEqjFNDIj2NLqh7RtarwP47 e97OAwDQMjcq3QTjLshvWgWBAyxNvs95h7jvWh7Cc37BbSwWS4NcHKku1Ws3n/ekW3bA GBwx+PrHZrfnUBaY/FknALaO/D9UvBlgddSt6pN63o8NCRONTlW8yOQSQlaz59jidua0 bNR8TNyVw7wZeFvCrsiv5LfGyIcYQ9RE9ICSD5A9dUbT/RqWdScAJIDxUxtbc5RS444g JK3ULvcZZMOv+j9bqVRnfy6Ixrl3XOpR+xJmG/KClnamdZ+osAwXjkr8y3+X+I+uc75L nIQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=fgrJwao8; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a205si21781602oii.95.2020.01.22.05.22.28; Wed, 22 Jan 2020 05:22:40 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=fgrJwao8; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729782AbgAVNTp (ORCPT + 99 others); Wed, 22 Jan 2020 08:19:45 -0500 Received: from mail.kernel.org ([198.145.29.99]:35656 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728811AbgAVNTl (ORCPT ); Wed, 22 Jan 2020 08:19:41 -0500 Received: from localhost (unknown [84.241.205.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id DE3A62467E; Wed, 22 Jan 2020 13:19:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579699180; bh=gmGK9lkkptqNYlJQsr4NkvPPXlub+fNWnEWdTp6g9Gc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fgrJwao8olqlDMXBKaCdaBt9khykdLigSkIWDWx96U1zLmHACW4pBLXPNIKfYHZ7t o2eU2ZAjFu88gJFVoKkqwjrfgJNDTSat6uoS8Uqxcuprgej7ShP0cpBFWxCgUCxJOH I7PFLc8WJh4oV0o68AWVTVTI50JBDKPoPZjmM89Y= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Christoph Hellwig , Waiman Long , "Peter Zijlstra (Intel)" Subject: [PATCH 5.4 064/222] locking/rwsem: Fix kernel crash when spinning on RWSEM_OWNER_UNKNOWN Date: Wed, 22 Jan 2020 10:27:30 +0100 Message-Id: <20200122092838.302318765@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200122092833.339495161@linuxfoundation.org> References: <20200122092833.339495161@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Waiman Long commit 39e7234f00bc93613c086ae42d852d5f4147120a upstream. The commit 91d2a812dfb9 ("locking/rwsem: Make handoff writer optimistically spin on owner") will allow a recently woken up waiting writer to spin on the owner. Unfortunately, if the owner happens to be RWSEM_OWNER_UNKNOWN, the code will incorrectly spin on it leading to a kernel crash. This is fixed by passing the proper non-spinnable bits to rwsem_spin_on_owner() so that RWSEM_OWNER_UNKNOWN will be treated as a non-spinnable target. Fixes: 91d2a812dfb9 ("locking/rwsem: Make handoff writer optimistically spin on owner") Reported-by: Christoph Hellwig Signed-off-by: Waiman Long Signed-off-by: Peter Zijlstra (Intel) Tested-by: Christoph Hellwig Cc: stable@vger.kernel.org Link: https://lkml.kernel.org/r/20200115154336.8679-1-longman@redhat.com Signed-off-by: Greg Kroah-Hartman --- kernel/locking/rwsem.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/kernel/locking/rwsem.c +++ b/kernel/locking/rwsem.c @@ -1226,8 +1226,8 @@ wait: * In this case, we attempt to acquire the lock again * without sleeping. */ - if ((wstate == WRITER_HANDOFF) && - (rwsem_spin_on_owner(sem, 0) == OWNER_NULL)) + if (wstate == WRITER_HANDOFF && + rwsem_spin_on_owner(sem, RWSEM_NONSPINNABLE) == OWNER_NULL) goto trylock_again; /* Block until there are no active lockers. */