Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp3315078ybt; Mon, 29 Jun 2020 22:48:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzgWn+imnWFiLY35XDX8WWiN2KqeUfoEfu4Wnr85Fg1u2/rq50cKIgjdRlv5DrZtW1ZI1qP X-Received: by 2002:a05:6402:22a5:: with SMTP id cx5mr22112006edb.246.1593496088354; Mon, 29 Jun 2020 22:48:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593496088; cv=none; d=google.com; s=arc-20160816; b=ql4H7wTsuNmTD1hn7Bo9TJaRt1XByxDR8XSlW0YwRHIWNa79OtQz8KYRx1yVP/X14Q iJNBE7oM8kFY36ocwV3jR+KNzNoghmV9RIxhdiciykz5OscCbNKdaOJWKYgsKZzGmZZy KVsnY2WTFhxw+ROldL1H7olZCCr3cVTGCMPIs1YuMBX3qfJZ5Cm9DaEkTcNAKY774Qxh oWVelU/qSqqw+VeAlU7aCUscuSCEwYI1EAwAlUyyFYbw2xi8GwZObhyKZhLYEBh8urmB 98+0uXXpK+DKp9KUtEhwCVPVZEIshPhiwoRbwB8mtmu9SZ4MO+PHvxlAtsoKxnLUstos gmww== 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 :references:in-reply-to:message-id:date:subject:cc:to:dkim-signature :dkim-signature:from; bh=mpdDlH3EimGLSv4f750ktc+2OOIPAdppOAHvCqowA5Q=; b=uhnpdss2H+3vW4dRPGcRUzj+zGrL8sTLDfWoU31rlfvBQhlQqqctVP69jwC8mksGYv YyHpjVg96gz/REaakUfkyPV2zaHmuPXQYLWS3fXyOJO0FvTGEJFv8Q3L417NQvMRbDkB OBSSxhDnXQxTkIdNkzptB6nuWKwqNx+st6fZx+WsX/ZobCr5ataabDHtLrsoHpdrdKGA wKLYnHQ4iy1aSIDRQuBPSFArt+6X4sYezyJDwUNWcpVEc59tdmLjSZ7jKh2IOFin7IVs iAAs2tJhhFfqPgv7LRY9Z1z2Q/yczWexKrm3c637I8Lu5gnTooTDBa1wCCBRtLy7mJ7d HYcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=XKGouWsv; dkim=neutral (no key) header.i=@linutronix.de header.b="f+ZWM/A0"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g1si1122812ejd.517.2020.06.29.22.47.46; Mon, 29 Jun 2020 22:48:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=XKGouWsv; dkim=neutral (no key) header.i=@linutronix.de header.b="f+ZWM/A0"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730027AbgF3Fqb (ORCPT + 99 others); Tue, 30 Jun 2020 01:46:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57628 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730013AbgF3Fq1 (ORCPT ); Tue, 30 Jun 2020 01:46:27 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E73EFC061755; Mon, 29 Jun 2020 22:46:26 -0700 (PDT) From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1593495983; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mpdDlH3EimGLSv4f750ktc+2OOIPAdppOAHvCqowA5Q=; b=XKGouWsvcT94/l0qMXp+/hXRs4c1E/UJ83u5UoMayTs6s2VhUCg9o6zp7BvgOgI5XJaxPk eGdwDOg2vGbZ2SSI3sTICCEMQFVZfHaR3+ts/0pbo1tzLCpMj2W9sFtJR96Jv3jNeHoA6B 9l7lRXO90k+wqIczEZo0jUPCNM7OGpQFl6gpDQ8Za4RzydTBqxXxZ0F63HW5ua6S9i+Hg4 fwUuQ8krJ3aX/vPBe8RXQx4u5M8k/3H2aSdwHqA8K1JNG6SBgSDx3mE7Wuo8OuzNmfAUlb oIH3Zxxjmno55CQYlYF5JWofRhEHMlCdc7o0SauzGR0HKGoMeC5Ifn+jNk6Y7g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1593495983; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mpdDlH3EimGLSv4f750ktc+2OOIPAdppOAHvCqowA5Q=; b=f+ZWM/A07foL8uf6oaT9CXPbIv8JhLqZTjQJ08b9nb3g62n6CE6/tE9bF2okgV8b1m+aQ0 QAE53rJfJjJA54BQ== To: Peter Zijlstra , Ingo Molnar , Will Deacon Cc: Thomas Gleixner , "Paul E. McKenney" , "Sebastian A. Siewior" , Steven Rostedt , LKML , "Ahmed S. Darwish" , Alexander Viro , linux-fsdevel@vger.kernel.org Subject: [PATCH v3 18/20] userfaultfd: Use sequence counter with associated spinlock Date: Tue, 30 Jun 2020 07:44:50 +0200 Message-Id: <20200630054452.3675847-19-a.darwish@linutronix.de> In-Reply-To: <20200630054452.3675847-1-a.darwish@linutronix.de> References: <20200519214547.352050-1-a.darwish@linutronix.de> <20200630054452.3675847-1-a.darwish@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org A sequence counter write side critical section must be protected by some form of locking to serialize writers. A plain seqcount_t does not contain the information of which lock must be held when entering a write side critical section. Use the new seqcount_spinlock_t data type, which allows to associate a spinlock with the sequence counter. This enables lockdep to verify that the spinlock used for writer serialization is held when the write side critical section is entered. If lockdep is disabled this lock association is compiled out and has neither storage size nor runtime overhead. Signed-off-by: Ahmed S. Darwish --- fs/userfaultfd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c index 52de29000c7e..26e8b23594fb 100644 --- a/fs/userfaultfd.c +++ b/fs/userfaultfd.c @@ -61,7 +61,7 @@ struct userfaultfd_ctx { /* waitqueue head for events */ wait_queue_head_t event_wqh; /* a refile sequence protected by fault_pending_wqh lock */ - struct seqcount refile_seq; + seqcount_spinlock_t refile_seq; /* pseudo fd refcounting */ refcount_t refcount; /* userfaultfd syscall flags */ @@ -1998,7 +1998,7 @@ static void init_once_userfaultfd_ctx(void *mem) init_waitqueue_head(&ctx->fault_wqh); init_waitqueue_head(&ctx->event_wqh); init_waitqueue_head(&ctx->fd_wqh); - seqcount_init(&ctx->refile_seq); + seqcount_spinlock_init(&ctx->refile_seq, &ctx->fault_pending_wqh.lock); } SYSCALL_DEFINE1(userfaultfd, int, flags) -- 2.20.1