Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp3522046lqp; Tue, 26 Mar 2024 11:18:44 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXZeMp8AbTFTFwcDqdw0iWVS4r3q8b5nOFalYsisfdMCf8B6dQQQoMTnxltnTdkpe2Uk5gRKlG0e92wS+MAmUo3OtyU73EbUV9wISdUEw== X-Google-Smtp-Source: AGHT+IFCqPfHXsS5lY6OkwgdGmCSam+VSDsS7iFp/x43JtAMxemjyC70QezVaxuiCZMaZB89ZR7f X-Received: by 2002:a05:6a00:18a1:b0:6ea:aaf5:e1b0 with SMTP id x33-20020a056a0018a100b006eaaaf5e1b0mr3308759pfh.6.1711477124625; Tue, 26 Mar 2024 11:18:44 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711477124; cv=pass; d=google.com; s=arc-20160816; b=O+MKIr6pjhK85vrovN/CeSfPYUxn/YahJ1hps/zigIizyd3/2xZ27aQfXBCGjkkFmz 8Xh4LkWFWEIk1+rh3YWTrBdtX71Q3dwGtCO5wF/mA5UpyfQMOBvHVN6xJMTVD0Y6EfRy Q572ee6+Lc8+vpdgTnrcOX/DFEJktmlVymsVLpSun4V6rFVPTFwFZ3JB4FWDvjF6QpW2 ZqV3oiTNvgi0bUNv0bgOWiR6+sModoL5OMPXPHQzUci6DJCm5618wVsvDtJa7XKJofX4 iE/zbWMoc6DtK4j4fllqP/dXCKl7NMiylck0xjnJcH56UEvHiMXOtVVJGmq/Scv+PMYc RyHg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=yVY+k0bCY8V+f1tWPazFzhaQVK84czaU9rMRMtoZXzs=; fh=EOHghtb/+9Fjv70yUJSxjW9mga7MYntvIwM15mT85Xw=; b=tSWRMrT4+Wu+pLFE/U3zpdM9pUioIzk9BZk4UrYNWm99N12JkesvCKv0DzGb5Jj5sx GOD1CWYYaMfJnb7PLVxGbI4FBkXfefNg2n+R/Wm3Zq93TYzHNBevfMksCJeDms2DTB0T lQKBS5CucqOH4jr69gfEL41/igIt2Zp4Mgwzus7f+8dEtoS/GJGh7ntHjTmm7MaQj3J/ QLFVtie6+1b5TNYbivkMO3kkxp7WQwud/fjxw2q3HAEuUFfUQzEngTacL2pfjsoIi8Yp BD8AdtmNpyxS5BvLLopLlCzIw8JT4vdaX6MRmMXbgnIRd48qdNs3WoMtp6QEXGpvt9bF 8hZg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=lizna5Tv; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-119635-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-119635-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id x64-20020a636343000000b005e85aa17485si10035032pgb.713.2024.03.26.11.18.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Mar 2024 11:18:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-119635-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=lizna5Tv; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-119635-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-119635-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 226E7B224EA for ; Tue, 26 Mar 2024 17:58:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 144C5208BC; Tue, 26 Mar 2024 17:58:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="lizna5Tv" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6E5271C6A4 for ; Tue, 26 Mar 2024 17:58:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.11 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711475905; cv=none; b=PjjPb9AChPEhzI6Ctn5qJV6Op8PAqTaXw+y3coSUgU1b+mJWOz74+KY8a6JLNMagmICd/nIHwKKlSeVEbVVKzPL21ClVGuON7/F5AQJozgMl6sF2YRoNNdnAFK3vj8A0h50yX6XIU8Uul/dq6dwTX0MzOsG9PeCN3iah7qP6Zqk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711475905; c=relaxed/simple; bh=imhNP8y+g5T4b+no8Hjc+kCYVt8bGQtnN/kFSTFcj1s=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=Heq/WDe/BcgFxhNwt4nIWIsaJ3TKSyPrEEdCqfkeDNqXBjplf2c7Q/j6k3sXZrBybEg2IPwpDJSjm9LCPyg9whJrG1PPCLr+QsikOc2EgDSV9G0TSTF8g/3ElIeWJRLJiIquK/jNQLIPTqudbjNfge3tf6/cZxlK5qUBEuHezBA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=lizna5Tv; arc=none smtp.client-ip=198.175.65.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1711475902; x=1743011902; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=imhNP8y+g5T4b+no8Hjc+kCYVt8bGQtnN/kFSTFcj1s=; b=lizna5TvA0L3FXI3nS4cbaFWBOeeCguca6AD2mKZ7IGUkjX1jStkzfuQ 9jN7pyG+giYfNg4CV8iq05ZsViX2Q5eQCDSZTuSrjzkg4CLJhdcPJO9Du UsgpgOfOk2yG/hv0RQn30eyzLB0b3ey3HQd5RkZn0kRkIgVACX2+cvebM 5fUpYSacA72WqeV2LnAVqsu0m9NAwLQE6B6a0IG92jlrqcBavLFws2mpU UDgqD8mi+hngVZFFd7UBd9n4h1A10JerZYTsu4+EI114Fazx721D/+RE3 L3CzQlksu2z/qHAvQOoUtH9fwmMAqRhvravrBlpDFQQscrQxkmvkLIghI w==; X-CSE-ConnectionGUID: klFhrPKfRwW2H6sfp4oVog== X-CSE-MsgGUID: 1J6+whn7S7u/VclVNSfsdw== X-IronPort-AV: E=McAfee;i="6600,9927,11025"; a="17092337" X-IronPort-AV: E=Sophos;i="6.07,156,1708416000"; d="scan'208";a="17092337" Received: from orviesa005.jf.intel.com ([10.64.159.145]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Mar 2024 10:58:22 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,156,1708416000"; d="scan'208";a="20757732" Received: from irvmail002.ir.intel.com ([10.43.11.120]) by orviesa005.jf.intel.com with ESMTP; 26 Mar 2024 10:58:22 -0700 Received: from [10.249.156.251] (unknown [10.249.156.251]) by irvmail002.ir.intel.com (Postfix) with ESMTP id E276A2876B; Tue, 26 Mar 2024 17:58:19 +0000 (GMT) Message-ID: <11c0a997-f283-476b-bdf6-47b440538f8b@intel.com> Date: Tue, 26 Mar 2024 18:58:18 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 1/2] wordpart.h: Helpers for making u16/u32/u64 values Content-Language: en-US To: Kees Cook Cc: linux-kernel@vger.kernel.org, Andy Shevchenko , Alexey Dobriyan , Jani Nikula References: <20240214214654.1700-1-michal.wajdeczko@intel.com> <202402141408.0E78D47@keescook> <202402151446.D9AE0626@keescook> From: Michal Wajdeczko In-Reply-To: <202402151446.D9AE0626@keescook> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 15.02.2024 23:47, Kees Cook wrote: > On Thu, Feb 15, 2024 at 09:40:40PM +0100, Michal Wajdeczko wrote: >> On 14.02.2024 23:09, Kees Cook wrote: >>> On Wed, Feb 14, 2024 at 10:46:53PM +0100, Michal Wajdeczko wrote: >>>> It is quite common practice to make u16, u32 or u64 values from >>>> smaller words. Add simple helpers for that. >>>> >>>> Signed-off-by: Michal Wajdeczko >>>> --- >>>> v2: new macro names due to conflict with crypto/aria.h >>>> explicit cast and truncation everywhere (Alexey) >>>> moved to wordpart.h (Andy) >>>> --- >>>> Cc: Kees Cook >>>> Cc: Andy Shevchenko >>>> Cc: Alexey Dobriyan >>>> Cc: Jani Nikula >>>> --- >>>> include/linux/wordpart.h | 32 ++++++++++++++++++++++++++++++++ >>>> 1 file changed, 32 insertions(+) >>>> >>>> diff --git a/include/linux/wordpart.h b/include/linux/wordpart.h >>>> index f6f8f83b15b0..8c75a5355112 100644 >>>> --- a/include/linux/wordpart.h >>>> +++ b/include/linux/wordpart.h >>>> @@ -31,6 +31,38 @@ >>>> */ >>>> #define lower_16_bits(n) ((u16)((n) & 0xffff)) >>>> >>>> +/** >>>> + * make_u16_from_u8 - make u16 value from two u8 values >>>> + * @hi: value representing upper 8 bits >>>> + * @lo: value representing lower 8 bits >>>> + */ >>>> +#define make_u16_from_u8(hi, lo) ((u16)((u16)(u8)(hi) << 8 | (u8)(lo))) >>> >>> Do we want to actually do type validation here? Right now it's just >>> cast/truncating, which based on the version log is by design. Is silent >>> truncation the right thing to do? >> >> note that even FIELD_PREP() is doing silent truncation and these macros >> here could be treated as specialized/simplified variants of FIELD_PREP() >> as alternate implementation can look like: > > Also, isn't all of this endian-specific? endianness shouldn't matter here so I guess the only question now is whether we want to have simple direct macros like lower|upper_bits() or go with macros build on top of the FIELD_PREP_CONST() or drop the idea completely and force the drivers to invent the wheel on its own