Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp3687678imm; Mon, 18 Jun 2018 02:18:17 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIxy157nydwcBdN4c2EgRoQ3KClx0DbpiBmlRLs9k6ys15j5AFCuj0zdpISYoJBPrridv9x X-Received: by 2002:a63:449:: with SMTP id 70-v6mr10363930pge.229.1529313497455; Mon, 18 Jun 2018 02:18:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529313497; cv=none; d=google.com; s=arc-20160816; b=jBv0+nMuuXbdRYEGpMjlgc9kldaoXJqwqAcagi8qX5FGvf7+z6mo2efsl0otFIsvCy uyno+uOt2pRNko0TUjNHZt78NjjaMRL7/bGzXqYtdocMc8zzn5v5af20sH4tXSuXw0bD 05KWOwPdftLw5i3jdYuEthHOZos40EzLNu6vWPBr7YCeFrZLrDLL77F4g+1NBhWoByw2 uPTT9bhxQ6nSCTHpHJgyLQ+jkadu3M8yO7Us0iOCuoDiKcRFmtX+qAzTFZZep1yWd82L 9Z/fxVOla3HZ8MOzseTVnOQUPCfEsnZU7ZLLy0gHS7Ow9IPtm+Pj2YqRcSFrIVwa4qRg BJHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=MP7gM3zLs/pQrmTjGF18flSdL6Hc0C+asf4FQdZW+d0=; b=w5McnX4njNdpMx/9B7uoknhVO/iblK0HgJVr0/a0XJIwtXjN4RSMQpSoSbKhQrYi9u /xNqtNw2CpJUVo5/R4yIk/ZxtWPxXTlPKn5aksfWwbEpQI7guuDRCq1O80RkYSImxk9z vYrzbq+1Lve960LLFJEVJumzSgcOocNeTQH1yWlPmMb4Gyq1E/rADQeW79f3ozIyF44+ N4tnD+spKkKY2IXjvEKUyj3JQ90UEgtj1UbrbAwoEuL19c8A+ORfyZcpKccIRQZ+vL3H Yx5ah3rNsUeWzC4tS3xc9NxzQh45WBIzzpKCq5S+gk6P7mjLL/DJ3weBR+wHGq38NT5s +YUg== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g15-v6si14126303plq.242.2018.06.18.02.18.03; Mon, 18 Jun 2018 02:18:17 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966643AbeFRI2Z (ORCPT + 99 others); Mon, 18 Jun 2018 04:28:25 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:59128 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S966622AbeFRI2T (ORCPT ); Mon, 18 Jun 2018 04:28:19 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id CE5C3C7A; Mon, 18 Jun 2018 08:28:18 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Amir Goldstein , Waiman Long , Peter Zijlstra , Andrew Morton , Davidlohr Bueso , Jan Kara , Linus Torvalds , Matthew Wilcox , Oleg Nesterov , "Paul E. McKenney" , "Theodore Y. Tso" , Thomas Gleixner , Will Deacon , linux-fsdevel@vger.kernel.org, Ingo Molnar , Sasha Levin Subject: [PATCH 4.16 268/279] locking/percpu-rwsem: Annotate rwsem ownership transfer by setting RWSEM_OWNER_UNKNOWN Date: Mon, 18 Jun 2018 10:14:13 +0200 Message-Id: <20180618080619.779208657@linuxfoundation.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180618080608.851973560@linuxfoundation.org> References: <20180618080608.851973560@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.16-stable review patch. If anyone has any objections, please let me know. ------------------ From: Waiman Long [ Upstream commit 5a817641f68a6399a5fac8b7d2da67a73698ffed ] The filesystem freezing code needs to transfer ownership of a rwsem embedded in a percpu-rwsem from the task that does the freezing to another one that does the thawing by calling percpu_rwsem_release() after freezing and percpu_rwsem_acquire() before thawing. However, the new rwsem debug code runs afoul with this scheme by warning that the task that releases the rwsem isn't the one that acquires it, as reported by Amir Goldstein: DEBUG_LOCKS_WARN_ON(sem->owner != get_current()) WARNING: CPU: 1 PID: 1401 at /home/amir/build/src/linux/kernel/locking/rwsem.c:133 up_write+0x59/0x79 Call Trace: percpu_up_write+0x1f/0x28 thaw_super_locked+0xdf/0x120 do_vfs_ioctl+0x270/0x5f1 ksys_ioctl+0x52/0x71 __x64_sys_ioctl+0x16/0x19 do_syscall_64+0x5d/0x167 entry_SYSCALL_64_after_hwframe+0x49/0xbe To work properly with the rwsem debug code, we need to annotate that the rwsem ownership is unknown during the tranfer period until a brave soul comes forward to acquire the ownership. During that period, optimistic spinning will be disabled. Reported-by: Amir Goldstein Tested-by: Amir Goldstein Signed-off-by: Waiman Long Acked-by: Peter Zijlstra Cc: Andrew Morton Cc: Davidlohr Bueso Cc: Jan Kara Cc: Linus Torvalds Cc: Matthew Wilcox Cc: Oleg Nesterov Cc: Paul E. McKenney Cc: Theodore Y. Ts'o Cc: Thomas Gleixner Cc: Will Deacon Cc: linux-fsdevel@vger.kernel.org Link: http://lkml.kernel.org/r/1526420991-21213-3-git-send-email-longman@redhat.com Signed-off-by: Ingo Molnar Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- include/linux/percpu-rwsem.h | 6 +++++- include/linux/rwsem.h | 6 ++++++ kernel/locking/rwsem-xadd.c | 2 ++ 3 files changed, 13 insertions(+), 1 deletion(-) --- a/include/linux/percpu-rwsem.h +++ b/include/linux/percpu-rwsem.h @@ -133,7 +133,7 @@ static inline void percpu_rwsem_release( lock_release(&sem->rw_sem.dep_map, 1, ip); #ifdef CONFIG_RWSEM_SPIN_ON_OWNER if (!read) - sem->rw_sem.owner = NULL; + sem->rw_sem.owner = RWSEM_OWNER_UNKNOWN; #endif } @@ -141,6 +141,10 @@ static inline void percpu_rwsem_acquire( bool read, unsigned long ip) { lock_acquire(&sem->rw_sem.dep_map, 0, 1, read, 1, NULL, ip); +#ifdef CONFIG_RWSEM_SPIN_ON_OWNER + if (!read) + sem->rw_sem.owner = current; +#endif } #endif --- a/include/linux/rwsem.h +++ b/include/linux/rwsem.h @@ -44,6 +44,12 @@ struct rw_semaphore { #endif }; +/* + * Setting bit 0 of the owner field with other non-zero bits will indicate + * that the rwsem is writer-owned with an unknown owner. + */ +#define RWSEM_OWNER_UNKNOWN ((struct task_struct *)-1L) + extern struct rw_semaphore *rwsem_down_read_failed(struct rw_semaphore *sem); extern struct rw_semaphore *rwsem_down_read_failed_killable(struct rw_semaphore *sem); extern struct rw_semaphore *rwsem_down_write_failed(struct rw_semaphore *sem); --- a/kernel/locking/rwsem-xadd.c +++ b/kernel/locking/rwsem-xadd.c @@ -352,6 +352,8 @@ static inline bool rwsem_can_spin_on_own struct task_struct *owner; bool ret = true; + BUILD_BUG_ON(!rwsem_has_anonymous_owner(RWSEM_OWNER_UNKNOWN)); + if (need_resched()) return false;