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=-9.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT 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 7FD74C33CB7 for ; Tue, 14 Jan 2020 16:12:44 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 3E86A24672 for ; Tue, 14 Jan 2020 16:12:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="LRd1rAVd" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3E86A24672 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 61F428E0008; Tue, 14 Jan 2020 11:12:42 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 55CD38E0003; Tue, 14 Jan 2020 11:12:42 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 35EE38E0008; Tue, 14 Jan 2020 11:12:42 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0058.hostedemail.com [216.40.44.58]) by kanga.kvack.org (Postfix) with ESMTP id 1B52B8E0003 for ; Tue, 14 Jan 2020 11:12:42 -0500 (EST) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with SMTP id F0D3840D9 for ; Tue, 14 Jan 2020 16:12:41 +0000 (UTC) X-FDA: 76376732922.25.fuel83_349985abf4a2d X-HE-Tag: fuel83_349985abf4a2d X-Filterd-Recvd-Size: 3231 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf21.hostedemail.com (Postfix) with ESMTP for ; Tue, 14 Jan 2020 16:12:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From :Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=kUvZdbrxgXYM+XtmN49YBQ9SrUjZBQUmtmFMa7zViEA=; b=LRd1rAVdu7xTOpYjtX3JQ4QZqG OqE7DLd8J2fmEAv0BXF5eYeuB+Q4dCGgSpqnyXC/I+SAPH2yKKm2W8AGVklxNeHrCc1aMXKfFPqh3 FftbCFmQR9IbEawSShE+O3RO0vdHjoG5zBSXk6SDvo6YgfFtI01W1ebtS0qaocS8cQyK9O7GSYqZx 5UM81HbcAvgOK6roMBpJ7uqBXhC5VacnY/zdsuGhGItpqfMqGz3rcy0umTAJQXsjxlnxGk4qs8+UO mklssD83lByYvKT7G3flWLK7WiKJVLPSMW6Cg4vdkf0oaB2HzWfW+ruX2oiypP9+wwGm7uH9HiCzy 9qiyXnxw==; Received: from [2001:4bb8:18c:4f54:fcbb:a92b:61e1:719] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1irOnw-00007u-QN; Tue, 14 Jan 2020 16:12:33 +0000 From: Christoph Hellwig To: linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, Waiman Long , Peter Zijlstra , Thomas Gleixner , Ingo Molnar , Will Deacon , Andrew Morton , linux-ext4@vger.kernel.org, cluster-devel@redhat.com Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 02/12] locking/rwsem: Exit early when held by an anonymous owner Date: Tue, 14 Jan 2020 17:12:15 +0100 Message-Id: <20200114161225.309792-3-hch@lst.de> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200114161225.309792-1-hch@lst.de> References: <20200114161225.309792-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: The rwsem code overloads the owner field with either a task struct or negative magic numbers. Add a quick hack to catch these negative values early on. Without this spinning on a writer that replaced the owner with RWSEM_OWNER_UNKNOWN, rwsem_spin_on_owner can crash while deferencing the task_struct ->on_cpu field of a -8 value. XXX: This might be a bit of a hack as the code otherwise doesn't use the ERR_PTR family macros, better suggestions welcome. Signed-off-by: Christoph Hellwig --- kernel/locking/rwsem.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kernel/locking/rwsem.c b/kernel/locking/rwsem.c index 44e68761f432..6adc719a30a1 100644 --- a/kernel/locking/rwsem.c +++ b/kernel/locking/rwsem.c @@ -725,6 +725,8 @@ rwsem_spin_on_owner(struct rw_semaphore *sem, unsigne= d long nonspinnable) state =3D rwsem_owner_state(owner, flags, nonspinnable); if (state !=3D OWNER_WRITER) return state; + if (IS_ERR(owner)) + return state; =20 rcu_read_lock(); for (;;) { --=20 2.24.1