Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp523152rdg; Thu, 12 Oct 2023 12:25:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEHMebSWEMD/l7gQtVJLWnEO5L0fCrvLfUrIXmytNVaIsbA2jAgls5oyZszfCxu712sVKmQ X-Received: by 2002:a05:6a00:391d:b0:68e:496a:7854 with SMTP id fh29-20020a056a00391d00b0068e496a7854mr23668985pfb.18.1697138710890; Thu, 12 Oct 2023 12:25:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697138710; cv=none; d=google.com; s=arc-20160816; b=mo9ofD6p9Icab/CnTGHqq8moYXjOAku7W2x4LCa2X0l8PNi+SSny9mlaKe2Ctzfxs2 dp7boBj5CI6tk08yr+DfQA3RwUfZJMVbFfQtDgU8JRDXnD3r+PYJQQxL+VKQvxOz9lyg pn8Y+udvL7o++DgrKwiunAlfS0SYmKar0r4V2oNtHA8u190o/mBYNdSlV+iVpcFZmCHN H9ZQsAzgjbNNjzlnlbOXV/dZvTvV1oljtdBTcckf0Hjru6yvLe3yOfjPYiw7ODrAlwRl eQChfVnhr7pIb6u8KPhx43peZUUETySDgby1DdaJx5AMmn3NGh1QJojpJCl1hCL/OsSa 3gSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=pQgjxjgdz0Jx9fhWH2hRFe0ialjJ6rtancxgASfDniE=; fh=yTmSS/gXxn46KuQCTngsZS/Qb6St7MyzpgEG+7IMYzg=; b=BMX7N+i5wqh0recCNoYSAnEmZxMlr8wmj1vMMTIS9ilr1tHAH/45IhjtyFKnWzGkwO /wofLt26AmKQ8B+XgHzajyDNuZFsG0GYLbCZY82cLlxd7iWIqLqLRE/J5WF05AaId+dg moN1BnDGWZQdR0x72XnumJIhO8o0BZRRWNgCvsAmb3tITsoFrVQsu6g2NiojecFz4WBG zboTETA1is6pmw8BqLNqtLaB1IMvSPw4stbi7nXscP47RUhPkndDGAMMMgg+fQF4J4fw FQ0Z1ZbwmwfIEnd54rrrbbaxU7RAYJaAblODFlT5Qq7XlGH4QYa3uyVQ5PSqUoM+DBPy Aq/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=HmKsczK5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id 37-20020a631865000000b00578faac74a4si2783978pgy.577.2023.10.12.12.25.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Oct 2023 12:25:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=HmKsczK5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 386058293C68; Thu, 12 Oct 2023 12:25:08 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1442009AbjJLTZA (ORCPT + 99 others); Thu, 12 Oct 2023 15:25:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48008 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379697AbjJLTY7 (ORCPT ); Thu, 12 Oct 2023 15:24:59 -0400 Received: from mail-ej1-x62a.google.com (mail-ej1-x62a.google.com [IPv6:2a00:1450:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 79AADB7 for ; Thu, 12 Oct 2023 12:24:57 -0700 (PDT) Received: by mail-ej1-x62a.google.com with SMTP id a640c23a62f3a-9ae75ece209so218550566b.3 for ; Thu, 12 Oct 2023 12:24:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; t=1697138696; x=1697743496; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=pQgjxjgdz0Jx9fhWH2hRFe0ialjJ6rtancxgASfDniE=; b=HmKsczK5ISJfEsL8NvZ1rtBB6tHM+DWYv7MSFqBkBREVGBeODKiPVV+ZR6WNT2+/WB O5wL0UETNCdtamVU8pdnIjUyMdP2s8jGxaB39YE6P6XwmOANpLsQYDRUw9ig+TzXbSC+ Y9ocL1y4KI2v06a9Co2Ni+4BzYpZMCA9fpC0o= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697138696; x=1697743496; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=pQgjxjgdz0Jx9fhWH2hRFe0ialjJ6rtancxgASfDniE=; b=g+FOA3K0i1FxQ3TYhruG7gW9mgYgeA1lW2zh1jmLIG75gAJspa7lrU7T+1XypJgBoe ptv7ASx8kM0dmJI4xgtORi+/zQ/d5DufL1QK5lBN6bgOe7/a7xM3BXlX540PNUSSxOhS lsMl2Pk1jKXSR8K6b8QQTDN/DDIp1Mctl5EVJx/JeDFEeExRH6twI3kTcFmHIpTqssYp z8Vq1j6qjE4m4vo1dl8kl28mTqAVknkfJ5VZaExzcIaOzAf/+kPA8trmwI9uRXOIIDgh FB0a1Xi6bzQNrnKGacIRiKKHzj9UNejpxPyxcN4HKTRklYiQ8hA40xtLETKXmJBgy0sb 1AYQ== X-Gm-Message-State: AOJu0YwYhn8kR7LXy+mLn94vM1ULiDRxkcbZ4MZxkcoxw9wkjbNDFQ9q riso/6/RRJ9CixVDf0J2Ok/9p9zl+a0hPFiHCKzj65E7 X-Received: by 2002:a17:906:10ce:b0:9a1:e233:e627 with SMTP id v14-20020a17090610ce00b009a1e233e627mr24619363ejv.42.1697138695614; Thu, 12 Oct 2023 12:24:55 -0700 (PDT) Received: from mail-ej1-f50.google.com (mail-ej1-f50.google.com. [209.85.218.50]) by smtp.gmail.com with ESMTPSA id oy3-20020a170907104300b009ae482d70besm11339465ejb.134.2023.10.12.12.24.55 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 12 Oct 2023 12:24:55 -0700 (PDT) Received: by mail-ej1-f50.google.com with SMTP id a640c23a62f3a-99c1c66876aso218017066b.2 for ; Thu, 12 Oct 2023 12:24:55 -0700 (PDT) X-Received: by 2002:a17:906:14e:b0:9ae:74d1:4b42 with SMTP id 14-20020a170906014e00b009ae74d14b42mr23002308ejh.76.1697138694810; Thu, 12 Oct 2023 12:24:54 -0700 (PDT) MIME-Version: 1.0 References: <20231012143158.GA16133@redhat.com> <20231012143227.GA16143@redhat.com> In-Reply-To: From: Linus Torvalds Date: Thu, 12 Oct 2023 12:24:37 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2 2/2] seqlock: change __seqprop() to return the function pointer To: Ingo Molnar Cc: Oleg Nesterov , Peter Zijlstra , Alexey Gladkov , Ingo Molnar , Will Deacon , Waiman Long , Boqun Feng , linux-kernel@vger.kernel.org, Thomas Gleixner Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Thu, 12 Oct 2023 12:25:08 -0700 (PDT) On Thu, 12 Oct 2023 at 11:21, Ingo Molnar wrote: > > Okay, so dropping 'const' makes sense in terms of staying bug-compatible > with the previous API and not build-breaking the world - but could we > perhaps follow this up with fixups of the type misuse and then a removal > of the forced type casts from these APIs? No. The use of 'const' here is *not* a bug. The thing is, 'const' doesn't mean what you seem to think it means. A 'const' pointer in C in no way means that the target is constant - it means that *THIS* use of the pointer will not write to the target! Those may sound similar, but they are very very very different. In particular, for the sequence seq = raw_seqcount_begin(seq_ptr); ... if (read_seqcount_retry(seq_ptr, seq)) goto retry; then 'seq_ptr' really *is* a 'const' pointer. The reader very much does not write to it, and this very much is part of the fundamental design. The above is *literally* what sequence locking is all about: readers are pure readers. So no, making it a 'const seqptr_t' is absolutely not a bug. It's very much a FUNDAMENTAL FEATURE of sequence locks. Now, I'm not sure how much we actually take advantage of this and there may not be very many cases of this all, but I really think this is fundamental to the whole data structure, and there are most definitely cases where we probably *should* take more advantage of the fact that a read_seqcount is a read-only op. For example, I think a function like 'dget_parent()' should actually take a 'const struct dentry *dentry' as its argument, and the seqcount is embedded inside that dentry and as such would also be const. Right now the dentry code doesn't actually do that, because this isn't one of the areas we have constified, but it's conceptually the right thing to do. We use the dentry argument in a read-only manner (although the *parent* that we look up then is written to, and in the case of a root dentry, the parent may end up being the same as the original). Note that the 'const' should only be an issue for the begin/retry cases, and obviously not for the write ones, but those readers do use the seqprop_ptr() helper. So those absolutely need to handle the const case. So no, the cast wasn't "masking" anything at all. The 'const' is real. Linus