From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.3 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BF3D7C33CB1 for ; Wed, 15 Jan 2020 06:50:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9C69C2075B for ; Wed, 15 Jan 2020 06:50:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726075AbgAOGu7 (ORCPT ); Wed, 15 Jan 2020 01:50:59 -0500 Received: from verein.lst.de ([213.95.11.211]:49204 "EHLO verein.lst.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726018AbgAOGu7 (ORCPT ); Wed, 15 Jan 2020 01:50:59 -0500 Received: by verein.lst.de (Postfix, from userid 2407) id 0255C68AFE; Wed, 15 Jan 2020 07:50:56 +0100 (CET) Date: Wed, 15 Jan 2020 07:50:55 +0100 From: Christoph Hellwig To: Waiman Long Cc: Peter Zijlstra , Ingo Molnar , Will Deacon , linux-kernel@vger.kernel.org, Christoph Hellwig , stable@vger.kernel.org Subject: Re: [PATCH] locking/rwsem: Fix kernel crash when spinning on RWSEM_OWNER_UNKNOWN Message-ID: <20200115065055.GA21219@lst.de> References: <20200114190303.5778-1-longman@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200114190303.5778-1-longman@redhat.com> User-Agent: Mutt/1.5.17 (2007-11-01) Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org On Tue, Jan 14, 2020 at 02:03:03PM -0500, Waiman Long wrote: > 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 This survives all the tests that showed the problems with the original code: Tested-by: Christoph Hellwig > if ((wstate == WRITER_HANDOFF) && > - (rwsem_spin_on_owner(sem, 0) == OWNER_NULL)) > + rwsem_spin_on_owner(sem, RWSEM_NONSPINNABLE) == OWNER_NULL) Nit: the inner braces in the first half of the conditional aren't required either.