Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp3615698iog; Mon, 27 Jun 2022 21:51:34 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sk2O2m9J0GARx2A/Lo322uN3d3PFHdG11E1583kxJ6z4H++mjIdB54XgFDcD/VWoo/Q8ho X-Received: by 2002:a17:903:2490:b0:168:d4d0:54da with SMTP id p16-20020a170903249000b00168d4d054damr3159646plw.42.1656391894745; Mon, 27 Jun 2022 21:51:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656391894; cv=none; d=google.com; s=arc-20160816; b=HP+XXC+ORFlefFz/yh+gT00PkhXYQdoqAKj4viX510g64QHihaZt2mrMx0BVAIePVg wh1ikVeXcDTmuUfG+DSMtl5nTrhP5m8kaDq1/NLzP7dODgbm8Oy5PJ6du9es93yobUMV pjT8QI7pr/odY2QplXVmUCOyEfXpk1fPU0oHbgDKi8DQOzqBHJaU/+CKYv0fMsxm5J2H 7YbjISRl2gmT2EDhSTf5YR7MRpJx6t0j+XclRzhxdSm5U2AbmjLIsLM9jm3hzlaLtr0P Jbgc0U4PrfHiZznUB9de5cvYlE/0tvLTc90rRsF9yBbboN1Yj8tKbu+TcfTuO1HlNSZr LviQ== 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=IKRmGyRbmPbpYMHg1O4vbVKpORj0jUhyWGskFyhwzGY=; b=hBdgj3ZxRmmjd6rgo5M0Gk939Glz0pNMjgxqWs+UwqFawk17RJkhlM1UdKtSr1OlCh TgUXBebHJ7S5JlKAavLCfWD9RInxku42TuvQQyojpLZJwzx5jRdIiq27sU3Ivk16djpD KKAo1Uuxzgu2KNO11LLyhVEVKyD5OspllYw/QWv5EigJFGlQ5tiebS8Sj0f29Qx+JMUQ nseOnOWzrCe4NHApRiM1wcogxrb0Az0Qskrrcqx1LynIQCezMLnACAS1rrsvQmxwM3I0 lZutW5SrNaxSGKSvjsOVxBCxAeL2sFkv5eCbONXi7ZgfEuWpf9CWV5kDLCWjTiHg4UsT kd+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=Rb2JUfmW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o14-20020a63f14e000000b004051797ce4asi16623262pgk.654.2022.06.27.21.51.22; Mon, 27 Jun 2022 21:51:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=Rb2JUfmW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244345AbiF1ErI (ORCPT + 99 others); Tue, 28 Jun 2022 00:47:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38892 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244328AbiF1ErG (ORCPT ); Tue, 28 Jun 2022 00:47:06 -0400 Received: from mail-ej1-x629.google.com (mail-ej1-x629.google.com [IPv6:2a00:1450:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7A14564D3 for ; Mon, 27 Jun 2022 21:47:05 -0700 (PDT) Received: by mail-ej1-x629.google.com with SMTP id cw10so23269470ejb.3 for ; Mon, 27 Jun 2022 21:47:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=IKRmGyRbmPbpYMHg1O4vbVKpORj0jUhyWGskFyhwzGY=; b=Rb2JUfmWT4hO+HV0M84lp0uCxvI4n/eYH6RMPut4GOhNr9jqOc41Mxxe6srHwjzK03 Or6+3nNApcPf8DQny1+/LWn8sQkG4VfazSNA2uZvyq/R++q5sotXuNUjTrWhg7c2QnJg THO79QsngMWu2Z5xvkDv1mkro6RquN/UjEgcQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=IKRmGyRbmPbpYMHg1O4vbVKpORj0jUhyWGskFyhwzGY=; b=0pt/pvJEUb4iTGhl5ODiSksqksg+Jzz1lF7KKxdidN7G+FOa1O6/SWD1azVWboJoxk VOsISQxiZnX8H1U64UCb1Vudne308hi1CPEj82HQ/6g+aFnKGaeGbOW/sppgmH0Sv3XZ RxoqiEtRQJYEVfM+sYa3ZpiDJN3gkp6kdafFTk5UwkoMWLlVFgFwLlR3k2w+TDqh1/eR 3Kmo1BcWpf5GswHYkBk4MY4hsSaw1GlDShaQtKoVFKO8Uq94ZaDrXS6XwZ1qxVdXrQBP T9AJ/e1RKOrsm9+dxzLmi7gNEuhghGWWVjIxPv5LL0arKs0GEt2vNJq8gY0XwirkaoGY D+yw== X-Gm-Message-State: AJIora8RJllmxcrtK6BbEkRojjYyLfUdSuYQsb3NHrmp+0EukMF0PyT4 JXcW2IEAxrF7BdkrBlirYIsXMAINvHxfFLh0avk= X-Received: by 2002:a17:907:1693:b0:726:4322:c330 with SMTP id hc19-20020a170907169300b007264322c330mr15213877ejc.9.1656391623722; Mon, 27 Jun 2022 21:47:03 -0700 (PDT) Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com. [209.85.128.49]) by smtp.gmail.com with ESMTPSA id v19-20020a170906381300b00721d8e5bf0bsm5896048ejc.6.2022.06.27.21.47.02 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 27 Jun 2022 21:47:03 -0700 (PDT) Received: by mail-wm1-f49.google.com with SMTP id v193-20020a1cacca000000b003a051f41541so455006wme.5 for ; Mon, 27 Jun 2022 21:47:02 -0700 (PDT) X-Received: by 2002:a05:600c:681:b0:3a0:2da6:d173 with SMTP id a1-20020a05600c068100b003a02da6d173mr23684632wmn.68.1656391622410; Mon, 27 Jun 2022 21:47:02 -0700 (PDT) MIME-Version: 1.0 References: <20220628032439.3314451-1-kent.overstreet@gmail.com> In-Reply-To: <20220628032439.3314451-1-kent.overstreet@gmail.com> From: Linus Torvalds Date: Mon, 27 Jun 2022 21:46:46 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v5whatever, now with typechecking] vsprintf: %pf(%p) To: Kent Overstreet Cc: Linux Kernel Mailing List , Matthew Wilcox , Petr Mladek Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jun 27, 2022 at 8:24 PM Kent Overstreet wrote: > > Linus, here's an updated version of the patch implementing %pf(%p) that > implements your typechecking macro and cookie idea we discussed This still has a fundamental problem: you insist on that double '%p' form. Why? That makes no sense when to a user, there is only *one* value. A user will ever see two values, because you should probably never use "CALL_PP()" (which is a horrible name anyway) directly. You'd presumably either use a per-type "print_dentry()" kind of function, or it would all be hidden by a macro that does _Generic() to match up the right pretty-printing function based on the type of the pointer. IOW, your "CALL_PP()" macro is something disgusting that normally should never be visible to any user. The real use might be something like printk("%pf\n", pretty_print(dentry)); where all the magic is hidden behind that "pretty_print()" macro. End result: that "%pf{%p}" format you have tried before is entirely broken. And that's what I tried to tell you earlier. There should be only one pointer, and there should be just a "%pf". Having two '%p' things is just wrong. It makes no sense to the actual use-case that a user would ever see. And there is only one pointer argument in the ARGV array too, because the way you'd actually then implement pretty_print() would most naturally be something like this: #include #define __PP_MAGIC (0xdeadbeef) struct pretty_print_struct { unsigned long magic; void *fn; void *p; }; // type warning *and* link-time failure extern int not_a_pointer; extern int pretty_print_int(int *); extern int pretty_print_long_long(long long *); #define __PP_FN(ptr) _Generic(*(ptr), \ int: pretty_print_int, \ long long: pretty_print_long_long, \ default: not_a_pointer ) #define __PP_CHECK(fn,ptr) \ __PP_MAGIC+(__typeof__ ((fn)(ptr)))0, fn, ptr #define pretty_fn(fn,ptr) &(struct pretty_print_struct) \ { __PP_CHECK(__PP_FN(ptr), ptr) } #define pretty_print(ptr) pretty_fn(__PP_FN(ptr), ptr) void test_me(int val) { printf("%pf\n", pretty_print(&val)); } Note how at no point does something like the above want two '%p' entries in the printf string, and in the concept of that line that the programmer actually uses: printf("%pf\n", pretty_print(&val)); there is only ONE value as far as the user is concerned.. Ergo: there should be only one '%p'. And the compiler only sees one pointer too, because we hide all the metadata as a pointer to that metadata structure. And obviously, the above is silly: the above example is doing ridiculous types like 'int' and 'long long' that don't need this. For the kernel, we'd do things like dentry pointers etc. And maybe not all users would use that "_Generic" thing to pick a printout function based on type, and you could just have special-case things, and sure, you can then use printf("%pf\n", pretty_fn(mny_dentry_print, file->f_dentry)); and it would do the obvious thing, but it would still be just one pointer as far as "printf" would be concerned. (I did test all of the above except for the 'dentry' case in a compiler to see that I got the syntax right, but then I ended up editing it later in the MUA, so I might have screwed something up after testing) Linus