Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp4828663rdb; Fri, 15 Sep 2023 13:41:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFlS8awKcGfgOFKoQ9jzuOGiPpxR80UYUuW1XlUPDV4lb4ZDD2KEy4IlPJDPdpjykGXqHku X-Received: by 2002:a05:6a20:9147:b0:14b:3681:567e with SMTP id x7-20020a056a20914700b0014b3681567emr3215916pzc.29.1694810477253; Fri, 15 Sep 2023 13:41:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694810477; cv=none; d=google.com; s=arc-20160816; b=KwgFchz8LaGr5mUfK156UtbwfI+f0GbKJYj+7KrlauL4EsVGeN1ozi73YO+Cp0gmy3 Fz+kZzkJHlU8qdDq1rchcFm0yiWCp6hGho8RE2uTvLhpzUFl9k2sIgWe58LCuL8AS1H1 a6mT51P6SmY991ozJIgChcQqVFkfzFTVQ7Vafbv2owkopwihGMihAgVGxhoeJEooYNj0 DU1Ukq2XdnAykzn32vomwYpSmD4Ak8WYavGRiSD3O+iWjeM2HMUZAUh6cv7d86zIE3m7 vQUJqSKTduAsmhi2oVVlV47u6BeAy6OxAjx89PPdIun7jvm1ah/++od7uH3eYr8yaRqX R6bQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=/NNdNMoPNLRC5J4Us7rjn5YK+Bn2P8ki5j52BrAmQfc=; fh=zmgHSO8dSxpb3RARXgXUByPa0uJXGqIJcOpo2obF6sI=; b=vL6GWdK6QHBZ8i9cYe4og9632nBvaHsfFOWkssZNl6KPlXnTC5wr0t7y+fAZ1br+0J li/CrlfvA9ry4q7KiXyPMLDzP4nwoHtXwBbFjWMlhN5FlHU5U/JZZWS3p2Y56scT9NVt 3ySCDH3s03lvjMSifNcHDCq369tHzfHwOFJfU0cuy8LZfrRXRoyfvZ2iN0Hn6lqrs0uv ILRXdksXIzhFUwei4IG75wIS4T5c+YM2agtTzmijxTyVUhuhUDe+ilGsoV9zVrtGH717 Ke3JClzEApLERO3bU1otXfZD5eOu9Pnua3B0/lPDvnLCCy343pPjGCw6ahBBqySC6hkO iWKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=IcUP3ZTh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id j11-20020a170902da8b00b001c3b2d40b3csi4137798plx.330.2023.09.15.13.41.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 13:41:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=IcUP3ZTh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id CD8AB8087B42; Fri, 15 Sep 2023 12:07:13 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236990AbjIOTGm (ORCPT + 99 others); Fri, 15 Sep 2023 15:06:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34506 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237061AbjIOTGe (ORCPT ); Fri, 15 Sep 2023 15:06:34 -0400 Received: from mail-qv1-xf35.google.com (mail-qv1-xf35.google.com [IPv6:2607:f8b0:4864:20::f35]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 035A2E7 for ; Fri, 15 Sep 2023 12:06:29 -0700 (PDT) Received: by mail-qv1-xf35.google.com with SMTP id 6a1803df08f44-65643a83758so1000186d6.0 for ; Fri, 15 Sep 2023 12:06:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1694804788; x=1695409588; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=/NNdNMoPNLRC5J4Us7rjn5YK+Bn2P8ki5j52BrAmQfc=; b=IcUP3ZThw4r0yzR1wPf2MKuL86qqJTY3lGmO5wVIwizbo32mHmJNZZSk/HLCKHmzhW Gla9MXisJOcGl205VuT46VlfVlhP6xgjKUvgEbqifKysED3psNQ5hqW3CZOjgckLmjeX 43LkHAbC+H1FUTt/bAuUJd+MV8LWoq2/Z74adGTaSMb3PVcM6bURd5o8B0Dd8ZnDhmch F88soN5Lthi1YPNktkbKNwEd2wMiZaMQllXBNNsrJx1dLyIgTkvZTwdgw5Ap7ERCiBEj aEE4u5wKUgjHR8vyQY0ZFUpZ7YEJ7LxF7BwF+AgWpkAv65snr4p5kovPzR4wE932OWEy 6kNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694804788; x=1695409588; h=content-transfer-encoding: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=/NNdNMoPNLRC5J4Us7rjn5YK+Bn2P8ki5j52BrAmQfc=; b=nJJSmCsdUAagRRzx2jioivhBvLTRQcmwNy9HMWsEx7EVg9zkiTUdOmW/DtFF1VowFI EJrLbvGpTYRlNO1aun7P0wqmRgVwvN9NBn1XAH4pxGWx4i314FFtcZC0e82W/+/VrqOB vA25VR5igYhl/xfKNF6ha6Da0iHhWQh3X3hZDar7bBF2edB/5pgwJolCXpk3fl/zVnLC 7OT3pife13q+YYTAlVziMYPl2TtdeHS31OGVqLzMlFhHI3ofV0JfrecjSTFAY+uO5Amb qqZiYOwMYDm6klx2vllA8k5p+EHVlwbS9QHfQPkkvIYxu6wiosSEb9d4k5ma8MFL+jJi 3eTw== X-Gm-Message-State: AOJu0Yx0gQQSeP2xm0qkrSSUcYoGzCIm0ZWv80al3NJxukG2waHUllXI WQPMIw850gX/yFRpZhtL+PQlvDtuQMOniG9l5RvOTw== X-Received: by 2002:a0c:e301:0:b0:651:65ca:141d with SMTP id s1-20020a0ce301000000b0065165ca141dmr2504505qvl.37.1694804787931; Fri, 15 Sep 2023 12:06:27 -0700 (PDT) MIME-Version: 1.0 References: <20230915050125.3609689-1-davidgow@google.com> In-Reply-To: <20230915050125.3609689-1-davidgow@google.com> From: Sami Tolvanen Date: Fri, 15 Sep 2023 12:05:50 -0700 Message-ID: Subject: Re: [RFC PATCH] kunit: Add a macro to wrap a deferred action function To: David Gow Cc: Nathan Chancellor , Kees Cook , Brendan Higgins , Rae Moar , dlatypov@google.com, Benjamin Berg , Maxime Ripard , Richard Fitzgerald , llvm@lists.linux.dev, linux-kernel@vger.kernel.org, kunit-dev@googlegroups.com, linux-kselftest@vger.kernel.org, linux-hardening@vger.kernel.org, Nick Desaulniers , Tom Rix Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.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 (fry.vger.email [0.0.0.0]); Fri, 15 Sep 2023 12:07:13 -0700 (PDT) Hi David, On Thu, Sep 14, 2023 at 10:01=E2=80=AFPM David Gow wr= ote: > > KUnit's deferred action API accepts a void(*)(void *) function pointer > which is called when the test is exited. However, we very frequently > want to use existing functions which accept a single pointer, but which > may not be of type void*. While this is probably dodgy enough to be on > the wrong side of the C standard, it's been often used for similar > callbacks, and gcc's -Wcast-function-type seems to ignore cases where > the only difference is the type of the argument, assuming it's > compatible (i.e., they're both pointers to data). > > However, clang 16 has introduced -Wcast-function-type-strict, which no > longer permits any deviation in function pointer type. This seems to be > because it'd break CFI, which validates the type of function calls. > > This rather ruins our attempts to cast functions to defer them, and > leaves us with a few options: > 1. Stick our fingers in our ears an ignore the warning. (It's worked so > far, but probably isn't the right thing to do.) > 2. Find some horrible way of casting which fools the compiler into > letting us do the cast. (It'd still break CFI, though.) > 3. Disable the warning, and CFI for this function. This isn't optimal, > but may make sense for test-only code. However, I think we'd have to > do this for every function called, not just the caller, so maybe it's > not practical. > 4. Manually write wrappers around any such functions. This is ugly (do > we really want two copies of each function, one of which has no type > info and just forwards to the other). It could get repetitive. > 5. Generate these wrappers with a macro. That's what this patch does. > > I'm broadly okay with any of the options above, though whatever we go > with will no doubt require some bikeshedding of details (should these > wrappers be public, do we dedupe them, etc). > > Thoughts? Using a macro to generate a wrapper is a reasonable approach IMO, and we've used it before in the kernel to fix type mismatches in indirectly called functions (v4l2-ioctl and cfg80211 come to mind at least). Sami