From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 80F49ECAAD5 for ; Sat, 3 Sep 2022 22:03:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9FBBD8016A; Sat, 3 Sep 2022 18:03:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 983B68015A; Sat, 3 Sep 2022 18:03:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7FDD88016A; Sat, 3 Sep 2022 18:03:55 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 6A3F48015A for ; Sat, 3 Sep 2022 18:03:55 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 3839C1C7188 for ; Sat, 3 Sep 2022 22:03:55 +0000 (UTC) X-FDA: 79872152430.12.67FF324 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf16.hostedemail.com (Postfix) with ESMTP id 2D291180061 for ; Sat, 3 Sep 2022 22:03:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: Content-Type:In-Reply-To:From:References:To:Subject:MIME-Version:Date: Message-ID:Sender:Reply-To:Cc:Content-ID:Content-Description; bh=U9dsdD9qqwlZ8b7AI29WXyQh7gcYJ6Pm2kKhDtUST74=; b=ddyH0oIhik5ygDu2PxTS98mw9i DoyTzVda/DHbD5Z1mfvrSDeE8YhU2RRYwkqeUPuNQ8UT8QP+6ChxEDD3zHKkvfHvphj905H0m3xac u+riMym2pLLcgSG9jYReVJO29gNZjCJ7xifDrfzNK1No2M70mf3b1PPaxJ832DIdQjN+HAsrwjbZA 4CfDWH8e6xPfRyb6NFDrr1VOTOwxvEVOiQddF2Dtx6qYJqWTvVrx0ChZLyoq7UMxCzzpoge1Cm3Fz tgBflcLQ2EzXREz6nA9whfHZgbyRJaEC+XMS9weaknvF3Nx1AHwMmkCrcMmGEONqQUkTHZOSibc+h aC5BEFiw==; Received: from [2601:1c0:6280:3f0::a6b3] by bombadil.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1oUbEz-004bEQ-9t; Sat, 03 Sep 2022 22:03:49 +0000 Message-ID: Date: Sat, 3 Sep 2022 15:03:47 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.0 Subject: Re: Fwd: [PATCH] tools/headers: Fix undefined behaviour (34 << 26) Content-Language: en-US To: =?UTF-8?Q?Matthias_G=c3=b6rgens?= , linux-arch@vger.kernel.org, linux-mm References: From: Randy Dunlap In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1662242634; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=U9dsdD9qqwlZ8b7AI29WXyQh7gcYJ6Pm2kKhDtUST74=; b=6xKEOBixTw7zUUDqCErhZ+cHBe2c2kDGal13EbG/z9iuJVtpQzFhmbTAN8Z0u6qed1yOp+ odoQHfzlenEXI8MbSYGTH2ws3FAzRdgUshg9qi/M+9yWzL45rkRjUgkGNi2yHec6lFdbA+ q8dk7ICXxn7Yg5LVSsn40MmiWQN5GXI= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=ddyH0oIh; spf=none (imf16.hostedemail.com: domain of rdunlap@infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=rdunlap@infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1662242634; a=rsa-sha256; cv=none; b=1ZZvFJAQKkYOON8O0Go/7m6ocFfCC78uvTKjcGroqvkjjLdxAsozrPjX0fBHwziZN3JI0K zyBGJykYpJ+u0rpAu6CmGI7u0lZT6JjWNm/7N4DH9x4j5RkZGf945Xsg7mvd/JWbEjDUR5 EM+IaCdmnxEzhqZzztWVh1l45HFf9XE= X-Rspam-User: Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=ddyH0oIh; spf=none (imf16.hostedemail.com: domain of rdunlap@infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=rdunlap@infradead.org; dmarc=none X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 2D291180061 X-Stat-Signature: dzqao493khjy34cx8z8m9spgurg4zqnx X-HE-Tag: 1662242634-64434 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Hi-- [adding linux-mm mailing list] On 9/2/22 23:59, Matthias Görgens wrote: > Hello, > > This is my first patch to the Linux kernel. I hope sending it via > gmail is OK? I have attached the git-generated patch file. > gmail's web UI won't do it AFAIK. And most people won't accept patches as attachments. (more difficult to review and reply with comments to them) The easiest fix for that (IMO) while continuing to use gmail is to use 'git send-email'. > This is a simple fix to a problem I encountered when I tried to build > CPython. Some digging suggested that the problem is actually with > kernel header files. > > Basically the problem is that when calculating > `HUGETLB_FLAG_ENCODE_16GB` we essentially run (34 << 26). That's > undefined behaviour in C, because C tries to do these calculations as > signed ints, but signed signed ints don't have enough bits. > > The fix is to cast to unsigned first: ((unsigned) 32 << 26). Unsigned > ints have enough bits, at least on 32 bit systems and above. Instead of casting to (unsigned), can you use a constant suffix format, like 34U << 26 ? > I suspect the way the kernel build uses GCC and Clang this is probably > not a problem, but the headers are used by outside projects (like > CPython), and for that it's probably best to stick to the C standard, > when it's easy to do so. > > Thanks, > Matthias. > > P.S. Please pardon, if you received this email a second time, I had > some trouble getting GMail to send in plain text. -- ~Randy