Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp1721721rdb; Sun, 8 Oct 2023 23:58:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHYyHleHoNuUI7gUw6JkYJLD1PNvKe8doJj5oPIM75+8zvXgDy9P3kNZ1km6p/lRlrsVG1L X-Received: by 2002:a05:6a20:8402:b0:15d:e8ce:145 with SMTP id c2-20020a056a20840200b0015de8ce0145mr15579108pzd.21.1696834686816; Sun, 08 Oct 2023 23:58:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696834686; cv=none; d=google.com; s=arc-20160816; b=lW5flV4/x3bCjUV1n4ShsW5TDqykzSjg97JTD9Wm/9nnKAmPS43w2V14+1uwWuQnDL PbGWLleZQSB5zKKbhQdvMCPnEpRrIyFXYlfBmhzRWCGKwaZCJ+S9nb87g+h7TfhM8XWz Btr+kC658pG1QtJHTw3n63gACCQEMcNGVEJ7MtOXU6T7a+qVAaIyjvC82r+rFHR4x8u1 Ox1SS8mx581k6In3sBA4XqH0JsYOQHi9xtsxp1JqCqHOMX27KvNg50nGQSeOeE4bS4YD Xh/owDJ+b3zNSS1wNM3qiQsmmWcwiX+IV2+FLE7+WX28fKW/xLSnUu3pgh0AFchm4aJV daPg== 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=57gTqeenZnFXtET9uW2JszJU5Ks7U8ou/I3OQXy2Bu4=; fh=xMqA8rSa5Fx8xqiFeHR4WrYRQth7F4ktogWaArA4Fn8=; b=Z+mU4vi9U5uQ64yKG3XtnO7caq4XZ71hxzJXnx5CgHLi4918VowXG5o9yuFIFGx+lm eOLcZdrO19pRGMUhpsDBIwbhV9cozfkAQ99P1BLCVq9kdROWK4WEjCsETPJ/2eXwJtei iwaf5RICDCYyyy8q7MB0CLq8A+l5evP8BBVEMCM9KEkpXvA5AAmVEXe7d5c+5zuxeWfN W38i5UXGD+jcdFLcU6x5WoR+rLxjolk9GIgHXgLEl9mAJmnIHCPMQyJiaF5XOcAShkxl advYY5/pVg8MlotsFibn7OJxT/OgenxgUG9FU/v5xzFE2es2xr78R9+LH5FtuWYlmkTg KLGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=KkRUwOLf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id h12-20020a056a00170c00b0069341622984si7053477pfc.147.2023.10.08.23.58.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Oct 2023 23:58:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=KkRUwOLf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 791A2804C616; Sun, 8 Oct 2023 23:58:03 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345354AbjJIG5x (ORCPT + 99 others); Mon, 9 Oct 2023 02:57:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40270 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344922AbjJIG5w (ORCPT ); Mon, 9 Oct 2023 02:57:52 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A47A1A3; Sun, 8 Oct 2023 23:57:50 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4CF25C433CB; Mon, 9 Oct 2023 06:57:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1696834670; bh=WfMc89OGvQiyW+o0qptkoI9flKRYwOtSlIq18M32yQI=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=KkRUwOLfzXI9SPkP6GKCIofqMZ9JKj9RkT0DMadrPpl3bjV6JbA/zcOpCXIXD3HCr DbRul+e5KyKUQO+sNeN/G6t/G1NjW/SW6cEnkXryMN1F6YZQc/k4Z/MIE6F9md3DZJ FtckpgMJZK9nydDjH6/TXXNajXBFd3zZbOz9nE0nRWGeZL/94n3p2k7V9AB1mrEsgh GPWkf1Y0ZQLRDr0bOPF5G0+OHglejBFDgHrJwT6/i7quzXCbjiWIhwEVTpCRDOIfbu kPbRwQk6EXagdLs7nzkQ8D2AxQ51pOwNUWcJUPO3Dee3WrzWl1FNC8YuYkMcx7xRgq Vn58dKBusd7hQ== Received: by mail-ot1-f41.google.com with SMTP id 46e09a7af769-6c67060fdfaso2949751a34.2; Sun, 08 Oct 2023 23:57:50 -0700 (PDT) X-Gm-Message-State: AOJu0Yzw4hZpTvXPz9NtDl/8E1PmPR8HMSyeOIKMEWaPbKupGp9RpYbx 0TrnnT9bEHqKwxdr67/ZOAqPUz5d6KFfXH764Y8= X-Received: by 2002:a05:6870:56ac:b0:1d5:a3b5:d89c with SMTP id p44-20020a05687056ac00b001d5a3b5d89cmr16414304oao.3.1696834669675; Sun, 08 Oct 2023 23:57:49 -0700 (PDT) MIME-Version: 1.0 References: <20231007170448.505487-1-masahiroy@kernel.org> In-Reply-To: From: Masahiro Yamada Date: Mon, 9 Oct 2023 15:57:13 +0900 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 1/5] modpost: fix tee MODULE_DEVICE_TABLE built on big endian host To: Sumit Garg Cc: linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, Bhupesh Sharma , Daniel Thompson , Jens Wiklander , Nathan Chancellor , Nick Desaulniers , Nicolas Schier Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=2.4 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.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 (agentk.vger.email [0.0.0.0]); Sun, 08 Oct 2023 23:58:03 -0700 (PDT) X-Spam-Level: ** On Mon, Oct 9, 2023 at 3:27=E2=80=AFPM Sumit Garg w= rote: > > Hi Masahiro, > > On Sat, 7 Oct 2023 at 22:34, Masahiro Yamada wrote= : > > > > When MODULE_DEVICE_TABLE(tee, ) is built on a host with a different > > endianness from the target architecture, it results in an incorrect > > MODULE_ALIAS(). > > > > For example, see a case where drivers/char/hw_random/optee-rng.c > > is built as a module. > > > > If you build it on a little endian host, you will get the correct > > MODULE_ALIAS: > > > > $ grep MODULE_ALIAS drivers/char/hw_random/optee-rng.mod.c > > MODULE_ALIAS("tee:ab7a617c-b8e7-4d8f-8301-d09b61036b64*"); > > > > However, if you build it on a big endian host, you will get a wrong > > MODULE_ALIAS: > > > > $ grep MODULE_ALIAS drivers/char/hw_random/optee-rng.mod.c > > MODULE_ALIAS("tee:646b0361-9bd0-0183-8f4d-e7b87c617aab*"); > > > > This issue has been unnoticed because the ARM kernel is most likely bui= lt > > on a little endian host (cross-build on x86 or native-build on ARM). > > > > The uuid field must not be reversed because uuid_t is an array of __u8. > > > > To me it wasn't obvious that DEF_FIELD() has certain endianness limitatio= ns. > > > Fixes: 0fc1db9d1059 ("tee: add bus driver framework for TEE based devic= es") > > Signed-off-by: Masahiro Yamada > > --- > > > > scripts/mod/file2alias.c | 10 +++++----- > > 1 file changed, 5 insertions(+), 5 deletions(-) > > > > diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c > > index 7056751c29b1..70bf6a2f585c 100644 > > --- a/scripts/mod/file2alias.c > > +++ b/scripts/mod/file2alias.c > > @@ -1348,13 +1348,13 @@ static int do_typec_entry(const char *filename,= void *symval, char *alias) > > /* Looks like: tee:uuid */ > > static int do_tee_entry(const char *filename, void *symval, char *alia= s) > > { > > - DEF_FIELD(symval, tee_client_device_id, uuid); > > As you have mentioned in patch #3: the limitations of TO_NATIVE(), if > you can update comments for DEF_FIELD() as well to make it clear that > it doesn't support byte arrays/strings would be helpful. I think the > following check that you have introduced in patch #3 can still be > bypassed for byte arrays/strings. > > + _Static_assert(sizeof(x) =3D=3D 1 || sizeof(x) =3D=3D 2 || \ > + sizeof(x) =3D=3D 4 || sizeof(x) =3D=3D 8, "bug"); I am afraid you missed the point. bswap_2, bswap_4, bswap_8 do not take a pointer. If you pass an array or a string, it will result in a build error due to the compiler's prototype checking. The kbuild test robot will catch a build error anyway. "You cannot build it in the first place" is better than a comment. > BTW, for this fix feel free to add: > > Reviewed-by: Sumit Garg > > -Sumit > > > + DEF_FIELD_ADDR(symval, tee_client_device_id, uuid); > > > > sprintf(alias, "tee:%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x= -%02x%02x%02x%02x%02x%02x", > > - uuid.b[0], uuid.b[1], uuid.b[2], uuid.b[3], uuid.b[4], > > - uuid.b[5], uuid.b[6], uuid.b[7], uuid.b[8], uuid.b[9], > > - uuid.b[10], uuid.b[11], uuid.b[12], uuid.b[13], uuid.b[= 14], > > - uuid.b[15]); > > + uuid->b[0], uuid->b[1], uuid->b[2], uuid->b[3], uuid->b= [4], > > + uuid->b[5], uuid->b[6], uuid->b[7], uuid->b[8], uuid->b= [9], > > + uuid->b[10], uuid->b[11], uuid->b[12], uuid->b[13], uui= d->b[14], > > + uuid->b[15]); > > > > add_wildcard(alias); > > return 1; > > -- > > 2.39.2 > > -- Best Regards Masahiro Yamada