Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5C130C433EF for ; Fri, 17 Dec 2021 17:50:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239939AbhLQRt7 (ORCPT ); Fri, 17 Dec 2021 12:49:59 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:57499 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235805AbhLQRt6 (ORCPT ); Fri, 17 Dec 2021 12:49:58 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1639763397; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hH32Mr09T44842vxV3B7WrEoq/VpUbXtp4OtPbsiQ8A=; b=erL70+I9zHgpCdDx8j15YwYvBMpHhGuGp+svmFpFss2CEQY15lX1jIP0LtnIuepyD9Hfg9 agJVbqBydceyns5o6LN+KfvHlpr8CzbkWI8lYgwBXzg6Im80WTLAvZQHCcbcUKrTcjPuh7 8c6u5KITS+xqxYrXwQ4vUwQ83aR4Dvw= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-312-ATpLtO-uPMySZwtW8JVjWw-1; Fri, 17 Dec 2021 12:49:56 -0500 X-MC-Unique: ATpLtO-uPMySZwtW8JVjWw-1 Received: by mail-wm1-f69.google.com with SMTP id bi14-20020a05600c3d8e00b00345787d3177so1379304wmb.0 for ; Fri, 17 Dec 2021 09:49:56 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:from:to:cc:references:organization:in-reply-to :content-transfer-encoding; bh=hH32Mr09T44842vxV3B7WrEoq/VpUbXtp4OtPbsiQ8A=; b=cY1s+Z7PDCdW2X4ULwvU2ZS2wf1tgm+ukQYVK5yU/j/AA5o58LDGOdb7irLnZpaM8N 9Bbp4Q8gGiwOnB2aEA04SVjz2pgkNAKWvXbTNOt82D7LnDASWR5AKeLAKyojedooCjTw 6zTbRBkfDb0C8YCeKTyDjfHTKCvgSeZyorMXAjzr5j8VzvGCz+5qhS+CKu+HfhevPJx1 rydtvuWmLZT7ID1oUBdd3eTVNWLAwToAzFvBiq30kGcidLY7Gcz7HxocIxPZMH6VXYny N7ZJDM/CoABfMwvklfoSpPnCRvBJ53i6iA/DyZHQ4Tw6poFaV9n8hcAifWBgu2hyxb66 9Ykw== X-Gm-Message-State: AOAM5338uXcULoGLIcddnkYWxJS3/jxDjqfCeWtVswgYFnZhyCxPcAb8 dhvSotZN/rTppEyBwyXZSnuTC7Gp/lYuL++Vu0rAr9u+9Ez44iySXYP9mZI7ZEW5RJhfEwyubzJ 7p+Tdh0Ui/Di0xuFEOtSYYqKQ X-Received: by 2002:adf:e0cd:: with SMTP id m13mr906530wri.128.1639763395435; Fri, 17 Dec 2021 09:49:55 -0800 (PST) X-Google-Smtp-Source: ABdhPJyaFASAHJrtnfsNBUE2d+KqbUAQa6kV/aLZsG8AH+xUC0YXxdgETnWUDGLNs6zv4pSGuzN60g== X-Received: by 2002:adf:e0cd:: with SMTP id m13mr906488wri.128.1639763395173; Fri, 17 Dec 2021 09:49:55 -0800 (PST) Received: from [192.168.3.132] (p4ff234b8.dip0.t-ipconnect.de. [79.242.52.184]) by smtp.gmail.com with ESMTPSA id bh16sm12335864wmb.1.2021.12.17.09.49.51 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 17 Dec 2021 09:49:54 -0800 (PST) Message-ID: Date: Fri, 17 Dec 2021 18:49:50 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.2.0 Subject: Re: [PATCH v1 01/11] seqlock: provide lockdep-free raw_seqcount_t variant Content-Language: en-US From: David Hildenbrand To: Nadav Amit Cc: LKML , Andrew Morton , Hugh Dickins , Linus Torvalds , David Rientjes , Shakeel Butt , John Hubbard , Jason Gunthorpe , Mike Kravetz , Mike Rapoport , Yang Shi , "Kirill A . Shutemov" , Matthew Wilcox , Vlastimil Babka , Jann Horn , Michal Hocko , Rik van Riel , Roman Gushchin , Andrea Arcangeli , Peter Xu , Donald Dutile , Christoph Hellwig , Oleg Nesterov , Jan Kara , "linux-mm@kvack.org" , "linux-kselftest@vger.kernel.org" , "linux-doc@vger.kernel.org" , Peter Zijlstra , Ingo Molnar , Will Deacon , Waiman Long , Boqun Feng , Jonathan Corbet References: <20211217113049.23850-1-david@redhat.com> <20211217113049.23850-2-david@redhat.com> <38BCB153-7E7C-4AAD-8657-E5C6F9E1EF9B@vmware.com> <058e97eb-1489-3d59-c6ee-94175dc13134@redhat.com> Organization: Red Hat In-Reply-To: <058e97eb-1489-3d59-c6ee-94175dc13134@redhat.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 17.12.21 18:29, David Hildenbrand wrote: > On 17.12.21 18:02, Nadav Amit wrote: >> >> >>> On Dec 17, 2021, at 3:30 AM, David Hildenbrand wrote: >>> >>> Sometimes it is required to have a seqcount implementation that uses >>> a structure with a fixed and minimal size -- just a bare unsigned int -- >>> independent of the kernel configuration. This is especially valuable, when >>> the raw_ variants of the seqlock function will be used and the additional >>> lockdep part of the seqcount_t structure remains essentially unused. >>> >>> Let's provide a lockdep-free raw_seqcount_t variant that can be used via >>> the raw functions to have a basic seqlock. >>> >>> The target use case is embedding a raw_seqcount_t in the "struct page", >>> where we really want a minimal size and cannot tolerate a sudden grow of >>> the seqcount_t structure resulting in a significant "struct page" >>> increase or even a layout change. >>> >>> Provide raw_read_seqcount_retry(), to make it easy to match to >>> raw_read_seqcount_begin() in the code. >>> >>> Let's add a short documentation as well. >>> >>> Note: There might be other possible users for raw_seqcount_t where the >>> lockdep part might be completely unused and just wastes memory -- >>> essentially any users that only use the raw_ function variants. >>> >> >> Is it possible to force some policy when raw_seqcount_t is used to >> prevent its abuse? For instance not to allow to acquire other (certain?) >> locks when it is held? >> > > Good question ... in this series we won't be taking additional locks on > the reader or the writer side. Something like lockdep_forbid() / > lockdep_allow() to disallow any kind of locking. I haven't heard of > anything like that, maybe someone reading along has a clue? > > The writer side might be easy to handle, but some seqcount operations > that don't do the full read()->retry() cycle are problematic > (->raw_read_seqcount). Sorry, I forgot to mention an important point: the raw_seqcount_t doesn't give you any additional "power" to abuse. You can just use the ordinary seqcount_t with the raw_ functions. One example is mm->write_protect_seq . So whatever we would want to "invent" should also apply to the raw_ functions in general -- which might be undesired or impossible (IIRC IRQ context). -- Thanks, David / dhildenb