Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933797AbbENRtK (ORCPT ); Thu, 14 May 2015 13:49:10 -0400 Received: from mail-ig0-f169.google.com ([209.85.213.169]:35358 "EHLO mail-ig0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933414AbbENRtG (ORCPT ); Thu, 14 May 2015 13:49:06 -0400 MIME-Version: 1.0 In-Reply-To: <1431624680-20153-11-git-send-email-aarcange@redhat.com> References: <1431624680-20153-1-git-send-email-aarcange@redhat.com> <1431624680-20153-11-git-send-email-aarcange@redhat.com> Date: Thu, 14 May 2015 10:49:06 -0700 X-Google-Sender-Auth: 0UF2qN4zCimo-AJiWr_T8haMNNs Message-ID: Subject: Re: [PATCH 10/23] userfaultfd: add new syscall to provide memory externalization From: Linus Torvalds To: Andrea Arcangeli Cc: Andrew Morton , Linux Kernel Mailing List , linux-mm , qemu-devel@nongnu.org, KVM list , Linux API , Pavel Emelyanov , Sanidhya Kashyap , zhang.zhanghailiang@huawei.com, "Kirill A. Shutemov" , Andres Lagar-Cavilla , Dave Hansen , Paolo Bonzini , Rik van Riel , Mel Gorman , Andy Lutomirski , Hugh Dickins , Peter Feiner , "Dr. David Alan Gilbert" , Johannes Weiner , "Huangpeng (Peter)" Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1254 Lines: 27 On Thu, May 14, 2015 at 10:31 AM, Andrea Arcangeli wrote: > +static __always_inline void wake_userfault(struct userfaultfd_ctx *ctx, > + struct userfaultfd_wake_range *range) > +{ > + if (waitqueue_active(&ctx->fault_wqh)) > + __wake_userfault(ctx, range); > +} Pretty much every single time people use this "if (waitqueue_active())" model, it tends to be a bug, because it means that there is zero serialization with people who are just about to go to sleep. It's fundamentally racy against all the "wait_event()" loops that carefully do memory barriers between testing conditions and going to sleep, because the memory barriers now don't exist on the waking side. So I'm making a new rule: if you use waitqueue_active(), I want an explanation for why it's not racy with the waiter. A big comment about the memory ordering, or about higher-level locks that are held by the caller, or something. Linus -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/