Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp36929ybk; Tue, 19 May 2020 14:52:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxQgq8SpQV2JAxZjk3DtfSkxFlspl0GjFU7mxFENjQujDDHwFWWaM1HB2MJ8kijBE7B7ZJH X-Received: by 2002:a17:906:4d0d:: with SMTP id r13mr1259525eju.282.1589925143649; Tue, 19 May 2020 14:52:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589925143; cv=none; d=google.com; s=arc-20160816; b=IR2XUcFBTunW/73O51GheK4byFAFNGMYATJHb9v2pHCNso5ht9nqXP3tf6zHE66Nmw ppfMx/lqt7p3eagl/8ptkGhXsxGXR6Atk1MPdGSDVkTns1+PcWC3GjfBQpR1k9fBNpHl rVWda4rt/TkVh4QQtKws+QZnoxcHWs+N/yv/ZnJhEcozgYZMldhJU4sl+vvIxYqFXIQD +KfASDR3z1IuSos4bC52Onh+StqQOkiU60sQ2E+wvdy7lqxwUA3kSqHA9EiHJ3P3A2uf Uv/pj/HN7zuQa27q1vzgudYGUcm1u3SZ6D7efBSOrzzGePacMBQf+sjotSkNf8vubTSY NXgQ== 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:from; bh=BkpULIGMgLT/SMkNaKHHo0qEQ8l0pWgCv67n1LZh+jQ=; b=Pdf8TCODKgO9Wvz3qP66Edw6CEk3os35T7gjFRJFQdz8jPHA+bLoK0/LPaiRd4sLlZ JVuQLx9a2f/yM/EGZMBdzNSIEsjLKJU3XkWTbd/pf4Z3yAVTvkbaPndkF5EfTzOPPdsS 7IFKAN+J784O7S9OOopUaayrr7sySxriThLQ7hjlwMUWpt+GNTqCijnV1oqEA6K0gROV Dvgj7XGdbvD4XjKg7bLn7nwESxlsBMOVz3zswDN0vt4LQVsma+tuGQq8vHpxvtioQfhS JeUy3QVGOHPSF+a2zlP3UbmCdbAbrSYgLDLv7WNc24NVLpAxZ6FQsvv8xAirMQ6Nrlc9 6iQw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b8si694142ejg.687.2020.05.19.14.52.00; Tue, 19 May 2020 14:52:23 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728588AbgESVr5 (ORCPT + 99 others); Tue, 19 May 2020 17:47:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41038 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728566AbgESVry (ORCPT ); Tue, 19 May 2020 17:47:54 -0400 Received: from Galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B8BC7C08C5C1; Tue, 19 May 2020 14:47:54 -0700 (PDT) Received: from [5.158.153.53] (helo=debian-buster-darwi.lab.linutronix.de.) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1jbA5R-0002xn-8E; Tue, 19 May 2020 23:47:45 +0200 From: "Ahmed S. Darwish" 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 v1 23/25] userfaultfd: Use sequence counter with associated spinlock Date: Tue, 19 May 2020 23:45:45 +0200 Message-Id: <20200519214547.352050-24-a.darwish@linutronix.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200519214547.352050-1-a.darwish@linutronix.de> References: <20200519214547.352050-1-a.darwish@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 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 e39fdec8a0b0..dd3aab31c50f 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