From mboxrd@z Thu Jan 1 00:00:00 1970 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id DC3ECC433EF for ; Fri, 17 Dec 2021 17:29:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 16C506B0072; Fri, 17 Dec 2021 12:29:20 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 11AB76B0073; Fri, 17 Dec 2021 12:29:20 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EAF466B0074; Fri, 17 Dec 2021 12:29:19 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0245.hostedemail.com [216.40.44.245]) by kanga.kvack.org (Postfix) with ESMTP id D69236B0072 for ; Fri, 17 Dec 2021 12:29:19 -0500 (EST) Received: from smtpin11.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 8E7B2180CC184 for ; Fri, 17 Dec 2021 17:29:09 +0000 (UTC) X-FDA: 78927972018.11.B40E8FB Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf30.hostedemail.com (Postfix) with ESMTP id 230A680020 for ; Fri, 17 Dec 2021 17:29:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1639762148; 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=QgM5OKxy2ebbpOfrvZEWcaXxpBQFY0BBq/cx7UULpgE=; b=Vp+PWHIUVog1/fIIigU0WWJbosJRe9kgqsMpQXK3bX7tppJuG1ZJ5FzFCWMFKSjwi2eCqH JUdn5ZOoucjTn++BfVUlapf8J/CwthDx3jq0LnxJ93etvKe7cRH4y0vYonN4gNnKyH+Xus I1HirD+mpz1BHukiywJcx66qRtIT20Q= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-512-V3oBBdsNNGGC-4JL2Z1H_Q-1; Fri, 17 Dec 2021 12:29:07 -0500 X-MC-Unique: V3oBBdsNNGGC-4JL2Z1H_Q-1 Received: by mail-wr1-f71.google.com with SMTP id h7-20020adfaa87000000b001885269a937so828122wrc.17 for ; Fri, 17 Dec 2021 09:29:06 -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 :content-language:to:cc:references:from:organization:subject :in-reply-to:content-transfer-encoding; bh=QgM5OKxy2ebbpOfrvZEWcaXxpBQFY0BBq/cx7UULpgE=; b=wDO9JYSirC204pZFLggQBYwYWhbsZ6LAVLWHiL9/FnPwMU4NxwGpgepBrjDf4ieMwQ +fJAl1Yl0c4OeKwJPcEqF+Hbip8BIQjnLk3GH6EXwoLeRFczfdW84dHs31rR+UkcAAuQ qFOV9J9AV0imPqA0bG6Eq6oGPoKyst9ZNdBRtmv24DiC9RZgL6mwQUykfsD0D8OUnZ5o gNolqNyLj9RsjbQ8e1yT5cOuN0qw2PMGA5IvX0hmY+mSFjcRAn2xi3/O10rXPMldsFr1 pCjI4Lx0KZLTi+gzIKGALtMMtQlkBIH2TOaoveYe5N5/BalolTb9h9Dxm4rP+4vxaLiV Vj2g== X-Gm-Message-State: AOAM5314Jc9R4WpTPF4chegrWSZVmAVTnX6K1Y5oLUdSga365mXjYqLm BLtIA4moXBXIG4CzXGIcMi/07hodZ72sIhAX5w/V1tsLo12scNfbZjhziSTYjC1Brtpxn8HQCvC xVl0QtAn02Js= X-Received: by 2002:a05:600c:154f:: with SMTP id f15mr10430330wmg.86.1639762145889; Fri, 17 Dec 2021 09:29:05 -0800 (PST) X-Google-Smtp-Source: ABdhPJw7gC5YUCkIZUZCWG8Ebu8/gjKEd1bTxSMHmYM6ftIz/BMjlPy8ZbBH4hQzbwEvNufDCZ3BZw== X-Received: by 2002:a05:600c:154f:: with SMTP id f15mr10430292wmg.86.1639762145666; Fri, 17 Dec 2021 09:29:05 -0800 (PST) Received: from [192.168.3.132] (p4ff234b8.dip0.t-ipconnect.de. [79.242.52.184]) by smtp.gmail.com with ESMTPSA id k7sm7910833wri.110.2021.12.17.09.29.04 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 17 Dec 2021 09:29:05 -0800 (PST) Message-ID: <058e97eb-1489-3d59-c6ee-94175dc13134@redhat.com> Date: Fri, 17 Dec 2021 18:29:03 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.2.0 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> From: David Hildenbrand Organization: Red Hat Subject: Re: [PATCH v1 01/11] seqlock: provide lockdep-free raw_seqcount_t variant In-Reply-To: <38BCB153-7E7C-4AAD-8657-E5C6F9E1EF9B@vmware.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 230A680020 X-Stat-Signature: y8zj5dzssuoack1rnruo6tyhd1dsrirt Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Vp+PWHIU; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf30.hostedemail.com: domain of david@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=david@redhat.com X-Rspamd-Server: rspam02 X-HE-Tag: 1639762148-653057 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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). > [ snip ] > >> +/** >> + * raw_seqcount_init() - runtime initializer for raw_seqcount_t >> + * @s: Pointer to the raw_seqcount_t instance >> + */ >> +# define raw_seqcount_init(s) __raw_seqcount_init(s) >> + >> #ifdef CONFIG_DEBUG_LOCK_ALLOC >> >> # define SEQCOUNT_DEP_MAP_INIT(lockname) \ >> @@ -111,11 +129,16 @@ static inline void seqcount_lockdep_reader_access(const seqcount_t *s) >> # define seqcount_lockdep_reader_access(x) >> #endif >> >> +/** >> + * RAW_SEQCNT_ZERO() - static initializer for raw_seqcount_t >> + */ >> +#define RAW_SEQCNT_ZERO() 0 > > I am not sure why RAW_SWQCNT_ZERO() should be a function-like macro. > I think I just went for consistency with SEQCNT_ZERO() -- but I agree, that can just be simplified! Thanks! -- Thanks, David / dhildenb