Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp4356742ybi; Fri, 19 Jul 2019 21:00:35 -0700 (PDT) X-Google-Smtp-Source: APXvYqw7FLKcaFSc0QJ1YhBUQxLMc+tQNwO8K2jS0G2OI8dAsQeTyGWRzNpgE6WFwlPicMoG01gT X-Received: by 2002:a17:90a:bd8c:: with SMTP id z12mr62165454pjr.60.1563595235478; Fri, 19 Jul 2019 21:00:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563595235; cv=none; d=google.com; s=arc-20160816; b=GWfrg+Hh9SyhUZlEhkNspIxwniCL1NzxZgiAvR9+qEEm3WIx7kZYu/k9FB6etO6f/A kGsGA6cJOuofjT42IJzOZwn2JXts8ACi9lSa5JcsN6+2OpSfIM43Bvvlzgp/aFxXn1Hb 3nhrUaBNL4pDY/gokg8YypIb9/T9Cr/QrqCrTQd1v87IIHVQKluO0Q0jp3VSfzzoD4Se Lxe7NEiwT5P6yYa/1Hy1k8d3eAi8nF0Y4rczIwU1YP/pyokTAB3ti3F5GtDVFAte00H9 wClpSCdK/53XGlLQMCrE3RtXlz0t0JdWDibPlVkMbLHNksqjckHZzaUJPwavA6k6VdrE RQPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:organization:from:references:cc:to:subject; bh=5hZ+59zsNjSTZyz7TVFnF+O2AGTQ8qFmct0ynfPQWlo=; b=Y3IUJ0njd304eTP4rIFhxsLp9RQtm6FVbqSKLYInU6PxFT2j60NPlspb3i2M7D1kFY AFB8ST6SIPpkSTqzBGwqPTfW5XyhXUsnXudQcWVVRcQ83xjHBxWPBSiQUt2zQjneE7uM 5bcB2sOucCv5L2Xe2Nopxh5Nb+yRBDkNpEa+d/muYEKMUpxUAXdxyjHu2DlyWNfaoCsi QVAjWYfxZDq2n7Eso16hPhW6EhY9/7KeK9vJ10HT6PYh8DJu2m1jJjcnjc8X9a7X51/V QJlrt1Ix/NNMLDnaaJmOUOk40tMrlX4LVFbxqJIABaJ9myeV2hibMbitF80Szm87KH3q x6ow== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v27si3562643pgn.14.2019.07.19.21.00.20; Fri, 19 Jul 2019 21:00:35 -0700 (PDT) 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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730238AbfGSUOh (ORCPT + 99 others); Fri, 19 Jul 2019 16:14:37 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52506 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728636AbfGSUOg (ORCPT ); Fri, 19 Jul 2019 16:14:36 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 48E4530C1E2F; Fri, 19 Jul 2019 20:14:36 +0000 (UTC) Received: from llong.remote.csb (dhcp-17-160.bos.redhat.com [10.18.17.160]) by smtp.corp.redhat.com (Postfix) with ESMTP id 79EB451DE6; Fri, 19 Jul 2019 20:14:34 +0000 (UTC) Subject: Re: [PATCH v8 13/19] locking/rwsem: Make rwsem->owner an atomic_long_t To: Luis Henriques Cc: Borislav Petkov , Will Deacon , huang ying , Peter Zijlstra , x86@kernel.org, Thomas Gleixner , Linus Torvalds , Tim Chen , Ingo Molnar , Davidlohr Bueso , linux-kernel@vger.kernel.org, "H. Peter Anvin" References: <20190520205918.22251-1-longman@redhat.com> <20190520205918.22251-14-longman@redhat.com> <20190719184538.GA20324@hermes.olymp> <2ed44afa-4528-a785-f188-2daf24343f97@redhat.com> <87lfwtlsf7.fsf@suse.com> From: Waiman Long Organization: Red Hat Message-ID: Date: Fri, 19 Jul 2019 16:14:33 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.0 MIME-Version: 1.0 In-Reply-To: <87lfwtlsf7.fsf@suse.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Content-Language: en-US X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Fri, 19 Jul 2019 20:14:36 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 7/19/19 3:45 PM, Luis Henriques wrote: > Waiman Long writes: > >> On 7/19/19 2:45 PM, Luis Henriques wrote: >>> On Mon, May 20, 2019 at 04:59:12PM -0400, Waiman Long wrote: >>>> The rwsem->owner contains not just the task structure pointer, it also >>>> holds some flags for storing the current state of the rwsem. Some of >>>> the flags may have to be atomically updated. To reflect the new reality, >>>> the owner is now changed to an atomic_long_t type. >>>> >>>> New helper functions are added to properly separate out the task >>>> structure pointer and the embedded flags. >>> I started seeing KASAN use-after-free with current master, and a bisect >>> showed me that this commit 94a9717b3c40 ("locking/rwsem: Make >>> rwsem->owner an atomic_long_t") was the problem. Does it ring any >>> bells? I can easily reproduce it with xfstests (generic/464). >>> >>> Cheers, >>> -- >>> Luís >> This patch shouldn't change the behavior of the rwsem code. The code >> only access data within the rw_semaphore structures. I don't know why it >> will cause a KASAN error. I will have to reproduce it and figure out >> exactly which statement is doing the invalid access. > Yeah, screwing the bisection is something I've done in the past so I may > have got the wrong commit. Another detail is that I was running > xfstests against CephFS, I didn't tried with any other filesystem. I > can try to reproduce with btrfs or xfs next week. > > Cheers, Oh, I don't have a CephFS setup. Will you use the scripts/decode_stacktrace.sh to find what line number is the offending statement? That will help in figuring out what has gone wrong. Anyway, it seems like a structure that include a rwsem is freed while another cpu is still waiting to acquire the lock. It is probably a hidden bug in the filesystem code somewhere that the recent changes in rwsem behavior make it easier for  the problem to show up. Cheers, Longman