Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp29074ybh; Mon, 20 Jul 2020 09:33:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJws88A0CDirF7wkcv4qbq8TfIyMdZi+uC9FYGlpbG1RLxUTs9zqkzvvPhmj9LiFil6lkjVf X-Received: by 2002:a17:906:3e54:: with SMTP id t20mr20943483eji.471.1595262792143; Mon, 20 Jul 2020 09:33:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595262792; cv=none; d=google.com; s=arc-20160816; b=qVm3ZTFhWXT/kEtLLlQhOQD+nSuXqqFO9a17KdLLWXDnoLUHe+Cd9IHOOPtChh48Jv Ks0tDb9y3LmXmRFXGr7d8fdMxljQ570okCU3Z6xyKYoI5rVR6/m8cUDcZbpUiTFtpmew DH6HipnkkIMHOonhGsJQ3uJBA16JBVFEQOsgApZjw7L8nfAYqTtbZkPLbHOmeq7sLTGN s95JwHXozzYTFt59dyeP1VU2XrWEc8ZFK/ZIPQqExwASINAOuVV3Wzq8LkBkLzlhnfuH CiwQx2aGuDEy2yGlbd8lylefEoglUh3YBwZZX/FIqUp4W6fjsStExJNWZDZEnk/y3MKQ R1gw== 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=W+svDpdoW7z85tRWa3k9fdfud9M8z1MDD+dGurBsojAgymc9GX0k1hoaohKaOzQHTm e7RSXV3/1/iU7CgLEViYGO9lVvBX3JMxMp9Era72tFhqKuhdB5g5O9quViVj4aX8VZvw zidz13rnWIUye9q9PnZPg8b0yKIr+J0eDbZLrrIMqRv4QPgXrKja2bp78fSqzRTCJbqz i+SMZv5nvHt3nMRk8zsAf9J7CoUSnzv5HBzOmsbMB5ys7ZjHpQ+zua5vSINx0ySMSQr7 tthxneEaCve5xeG/yU9+eezm9Sv2x4vgAGQA1KhuQPHLRKlh50SWEaLQ4pWiFtYAu5rB mtyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=fKkNvz+s; dkim=neutral (no key) header.i=@vger.kernel.org; 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 c19si6547424ejz.484.2020.07.20.09.32.48; Mon, 20 Jul 2020 09:33:12 -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=fKkNvz+s; dkim=neutral (no key) header.i=@vger.kernel.org; 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 S2388826AbgGTQb1 (ORCPT + 99 others); Mon, 20 Jul 2020 12:31:27 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:58998 "EHLO galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731437AbgGTP5T (ORCPT ); Mon, 20 Jul 2020 11:57:19 -0400 From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1595260637; 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=fKkNvz+sadq6MPtMrYCh1hy00dP2dOSzfdRQN7EFfsRTJkll8GG15efprHHbZHbujucspz GrrBR8wSSY1IkWuuVUKvLiq7s6VTWcmcpECI0Lr0z0YgfkUPvmMgHfqwEpxZV1mA5SFe2/ x+bv7GZCzTUwybveKzvh9CV1eFaanAC5UVLD0ziL0ZBau7GlzpZaiWZARmQWaoy7CRFFyC srNwxWbDPcgEtC4g3fos/GNmjaLPZjGYVUreGlcMG4o9z6mQsWlV/jUBFhkmEsNaXSbwXJ Q4GVBCAT7ohlN2Keax5E6zkEMnWihieJdWOPv4dlx3LnQQN86yhTMWbkkgJu8Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1595260637; 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=5h+33h9aI9H+JMNqGwWtY/kxX9VViJN4xQBCWUDdC+EEq5nuc6hhdknJAEfGXsKfSBKIMN DCxM+f/3wIts5rBw== 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 v4 22/24] userfaultfd: Use sequence counter with associated spinlock Date: Mon, 20 Jul 2020 17:55:28 +0200 Message-Id: <20200720155530.1173732-23-a.darwish@linutronix.de> In-Reply-To: <20200720155530.1173732-1-a.darwish@linutronix.de> References: <20200519214547.352050-1-a.darwish@linutronix.de> <20200720155530.1173732-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