Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp437100imn; Fri, 29 Jul 2022 11:30:14 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uJjLgW3yVSEEgNNE7jl0bep3ZCUn6KFoDE4YIRzarZXKZdGVKZyL4VxmUgeiIqvamiRJ4F X-Received: by 2002:a17:906:9754:b0:72f:38ff:efd7 with SMTP id o20-20020a170906975400b0072f38ffefd7mr3755895ejy.216.1659119413893; Fri, 29 Jul 2022 11:30:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659119413; cv=none; d=google.com; s=arc-20160816; b=vjwS0e7FtiCXNBTK+udw1HhRLixJpYGZWH5v2QqihRCZuprqSJ62xK+90gBWK6wj0t LctpXGzQ/EPHh7S56WSAgV4uBWBOhU/Q0rOqqyacEbX1PqTlU5rNAPwwsCmEMwOQGADT QOnFzxAUtnTCFtqEJoGmBrCxFBvogHGCtjUg3ht/8WsTbsV7ihMWCm1lBuaybwxp4V1e qDTW+HMfrxn3KkDwC6cWyyc41JyiD2n88iC5U6NYaqn7KkeOlXAN6mX6M/HKG2CmYmCZ jHZUUQFLLgpOSPqaJLIco+k0B3JWpTwM2hXTo4LgiapL4dvUbICVAZFga5fxKUCjLp5H 96mg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:organization:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=nRVXR2i/rBPPbGNlB+6vKMxA+2c1CxHE5pdQtE8ONvk=; b=JiWsYhC0aIqiT0BtBIUieuwBbC9Ej5eS0NbVqfolHFPQLAaTxCqtVR+bRCq4bxDCX0 xQap+BTY6Aq4O7x1weNZgpP3+Zr1EzvF/vBRYc/WuaAISuHDCAzcU/Sen3MXKpYn/7/u wolq9F/DoSxGdB83+VVgjfX0fslP5K5uo2cAV9TTXCC8KLDKJzcwIS4j13Rvko/wdcB2 MuZp+ERaefNzQHMQDhOW5Js6fQ/z9IGBwXrp+vl9uJiauSMbcsIA0UfUTWmaDThFFhTi kNTmF+ywUgYq/wbnGNqDM80pOXViKquP4tqbkl+R6r5hl+TJpWEDnW4tvF3bS51pZDX/ Mdzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ICv9sTvP; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id wv6-20020a170907080600b00706b9787b43si4463060ejb.319.2022.07.29.11.29.47; Fri, 29 Jul 2022 11:30:13 -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=@intel.com header.s=Intel header.b=ICv9sTvP; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238384AbiG2SX2 (ORCPT + 99 others); Fri, 29 Jul 2022 14:23:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54738 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238287AbiG2SXZ (ORCPT ); Fri, 29 Jul 2022 14:23:25 -0400 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0377A62A67 for ; Fri, 29 Jul 2022 11:23:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1659119004; x=1690655004; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=X2VF3pNp8E/hZzwDvRsZjaNCBkmtMXVopMiWXQZ7zTY=; b=ICv9sTvPXKXviwoSVJlnrvRBuq6DR5284aAxslYdveaUeiOIam7Sn90G qWpfwra8rOwMjKZ7uaZsP9+3wQWfIalh1zix4dMAWD4BENSi7/bnKbBsi XKuQJTrPaBh36pmYfpY/hJZ0fTcSw7bzU/6VcfR738zZ8QBu5ZZayMdem /JKOwM4/KLOOJ8aquoz1szsewWXXf0ZqJx63N1qJr4MqfoZxednkb4QN2 grtD9aCWS10rRGIt71D3d97ZuQzFjXWwK5EWAEVk35HgFhnHAQEGmYdIi jtBIScyvYnHw4n6hLjar2sXiE3Nd76ePxoMRIq7yezkpsnbgDqEU97OIU w==; X-IronPort-AV: E=McAfee;i="6400,9594,10423"; a="375126867" X-IronPort-AV: E=Sophos;i="5.93,201,1654585200"; d="scan'208";a="375126867" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Jul 2022 11:23:12 -0700 X-IronPort-AV: E=Sophos;i="5.93,201,1654585200"; d="scan'208";a="743616506" Received: from smile.fi.intel.com ([10.237.72.54]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Jul 2022 11:23:11 -0700 Received: from andy by smile.fi.intel.com with local (Exim 4.96) (envelope-from ) id 1oHUdg-001eiV-3C; Fri, 29 Jul 2022 21:23:08 +0300 Date: Fri, 29 Jul 2022 21:23:08 +0300 From: Andy Shevchenko To: Jean Delvare Cc: linux-kernel@vger.kernel.org Subject: Re: [PATCH v1 1/1] firmware: dmi: Don't take garbage into consideration in dmi_smbios3_present() Message-ID: References: <20220726094329.1725-1-andriy.shevchenko@linux.intel.com> <20220727102504.6bbefcf9@endymion.delvare> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220727102504.6bbefcf9@endymion.delvare> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo X-Spam-Status: No, score=-4.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE autolearn=ham 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 Wed, Jul 27, 2022 at 10:25:04AM +0200, Jean Delvare wrote: > On Tue, 26 Jul 2022 12:43:29 +0300, Andy Shevchenko wrote: > > The byte at offset 6 represent length. Don't take it and drop it immediately > > by using proper accessor, i.e. get_unaligned_be24(). > > The subject sounds like you are fixing a bug, while this is only, at > best, a minor optimization. I don't know how to improve it, but it kinda a bug in a logic for non-prepared reader, esp. as specification suggests different thing about version offset. ... > > - dmi_ver = get_unaligned_be32(buf + 6) & 0xFFFFFF; > > + dmi_ver = get_unaligned_be24(buf + 7); > I admit I did not know about get_unaligned_be24(). While I agree that > it makes the source code look better, one downside is that it actually > increases the binary size on x86_64. The reason is that > get_unaligned_be32() is optimized by assembly instruction bswapl, while > get_unaligned_be24() is not. Situation appears to be the same on ia64 > and arm. Only arm64 would apparently benefit from your proposed > change. Good to know! But here it's not a hot path, right? > I'm not too sure what is preferred in such situations. For cold paths I think the correctness prevail the performance. Alternatively we might add a comment in the code explaining the trick, although I won't like to do it. Another way is to have a subset of 24-/48-bit unaligned accessors that use the trick specifically for hot paths with a caveat that they may access data out of the 24-/48-bit boundaries. -- With Best Regards, Andy Shevchenko