Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1241442ybt; Sat, 27 Jun 2020 02:25:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzmlTqmIGNQ2waPITvCLDyQNb4L/wYV3x7wqrKznBbPA7SY0rrVG3SjKIVFQqqJ0F8iywUg X-Received: by 2002:a17:907:42cb:: with SMTP id nz19mr5852604ejb.447.1593249940342; Sat, 27 Jun 2020 02:25:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593249940; cv=none; d=google.com; s=arc-20160816; b=cUD+6NyCx2irjUeWjeKRmAk/wIFB+Nfqwsals1U7gtAfZ6CXemniIYrT1JBy4emAWR e7393Rfi/teG+IB1TErmnMLFqd6q1hFp6iW2c+v+ZwX7lWHn6U7sXrmcvoPLj03O/6aG C25XNK+mpgGHmyxV7NeeBwU1ggMmVZkQD8OMKkbY12swpl17ONwZ8zkYeP0KWOJWuGKg SFGTzRGvRQetoCTtUaK0cmQ0L/Ux4i9BEgyeNCBOVUWMBfKBcrDpLLjQomYC/IU6uRxi +74cp2kmt1Qz1cYeDNHlYHhKnoBhoPR7kuxW+GPEHwYtC/KZ2/RPMnjNuFm3nLe8bxPP p5XQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=KNnmAV6YEwVHH3YlOTosOUW/DNCgcr0G4chF+ObrEVk=; b=x3p0+xyPR9SxPpDJyrV9e3FQd/Pi3fEsAZDiXMod4fPRtL7II9oBdA1o6X2sAAbx8z SpcALFWAFAkZM8SgYGSyfFrpI2WEtLLIGNMjEj97tKekI7YPk3LlXQcuTwj0hJS1US0G ATIscpxhXjfQq7CijJM8qMedG4UBj6pAq0c8I4w6/o2Y8SwhV/7RmVh1P7+7Q+lPoBkY Pfki8hROuZiT/3mn2yCU+P1FsQ+KW7GNcinoU0t3roE7KSsC/DEdiV9/k+iTBYSN7NzR uHxMcW9YU3Ery0dM9sc6+xIoG9qppKI8XwUSXRP4k05yEjHSbEHaxkprXZ6pOnURnSqN fWXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=alfu06Hd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d17si6781968edu.223.2020.06.27.02.25.16; Sat, 27 Jun 2020 02:25:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=alfu06Hd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726424AbgF0JW7 (ORCPT + 99 others); Sat, 27 Jun 2020 05:22:59 -0400 Received: from mail.kernel.org ([198.145.29.99]:43404 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725850AbgF0JW7 (ORCPT ); Sat, 27 Jun 2020 05:22:59 -0400 Received: from mail-oi1-f178.google.com (mail-oi1-f178.google.com [209.85.167.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 6B8AE20768; Sat, 27 Jun 2020 09:22:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1593249778; bh=ARyWigMo4Grv0OKY/VJy1kBAOavs8Wcx2VYSGAzPgks=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=alfu06HdLDJlx9dHguCZCd6adJiGTpaZut2AgOBHIUONCJOpM+pf1RfMeMpQX6gYd FFWtixphoW0dkd7a4aOvlC3PWm4n10zA6kxsxqPe/qEi8Kxn9UDb4YPbPD8+DxA4/b Akehks0sO8iSVKe/feBFTukUQUImHpfY1YR2Gh18= Received: by mail-oi1-f178.google.com with SMTP id e4so2061302oib.1; Sat, 27 Jun 2020 02:22:58 -0700 (PDT) X-Gm-Message-State: AOAM53299oY+WOB4chkyeghUjkLw2/LlpvqcNZceQA/pHpSDC4dex6eh fybCaAN4Ajy+2m3cTgOe0EhWA3Q/8Gdf0V4WCnE= X-Received: by 2002:aca:d0d:: with SMTP id 13mr5614620oin.174.1593249777771; Sat, 27 Jun 2020 02:22:57 -0700 (PDT) MIME-Version: 1.0 References: <20200625234516.31406-1-atish.patra@wdc.com> <20200625234516.31406-2-atish.patra@wdc.com> <5e2ce2ae-5458-8579-576a-76721f7d3b08@gmx.de> In-Reply-To: From: Ard Biesheuvel Date: Sat, 27 Jun 2020 11:22:46 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [RFC PATCH 01/11] efi: Fix gcc error around __umoddi3 for 32 bit builds To: Atish Patra Cc: Heinrich Schuchardt , Atish Patra , "linux-kernel@vger.kernel.org List" , linux-efi , linux-riscv , Masahiro Yamada , Palmer Dabbelt , "linux-arm-kernel@lists.infradead.org" Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, 27 Jun 2020 at 00:03, Ard Biesheuvel wrote: > > On Fri, 26 Jun 2020 at 23:56, Atish Patra wrote: > > > > On Thu, Jun 25, 2020 at 7:43 PM Heinrich Schuchardt wrote: > > > > > > On 6/26/20 1:45 AM, Atish Patra wrote: > > > > 32bit gcc doesn't support modulo operation on 64 bit data. It results in > > > > a __umoddi3 error while building EFI for 32 bit. > > > > > > > > Use bitwise operations instead of modulo operations to fix the issue. > > > > > > > > Signed-off-by: Atish Patra > > > > --- > > > > drivers/firmware/efi/libstub/alignedmem.c | 2 +- > > > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > > > > > diff --git a/drivers/firmware/efi/libstub/alignedmem.c b/drivers/firmware/efi/libstub/alignedmem.c > > > > index cc89c4d6196f..1de9878ddd3a 100644 > > > > --- a/drivers/firmware/efi/libstub/alignedmem.c > > > > +++ b/drivers/firmware/efi/libstub/alignedmem.c > > > > @@ -44,7 +44,7 @@ efi_status_t efi_allocate_pages_aligned(unsigned long size, unsigned long *addr, > > > > *addr = ALIGN((unsigned long)alloc_addr, align); > > > > > > > > if (slack > 0) { > > > > - int l = (alloc_addr % align) / EFI_PAGE_SIZE; > > > > + int l = (alloc_addr & (align - 1)) / EFI_PAGE_SIZE; > > > > > > Here you rely on the compiler to silently convert the division by > > > EFI_PAGE_SIZE into a right shift. Wouldn't it be cleaner to use > > > EFI_PAGE_SHIFT to explicitly avoid a dependency on __udivdi3()? > > > > > > slack = (align >> EFI_PAGE_SHIFT) - 1; > > > ... > > > int l = (alloc_addr & (align - 1)) >> EFI_PAGE_SHIFT; > > > > > > > Sure. I will update it in the next version. Thanks for the suggestion. > > Please don't. Dividing by EFI_PAGE_SIZE is perfectly fine, and is more readable. Actually, I will take this patch as a fix right away - 32-bit ARM has the same issue (although it does not actually incorporate this object file) In the meantime, please check how the stub gets pulled into your kernel: the idea of a static library is that only the objects that are used are included in the final build, but this turned out to be broken for arm64 [0]. IOW, simply applying a similar change might fix your build issue as well (assuming RISC-V does not actually call efi_allocate_pages_aligned() anywhere) [0] https://lore.kernel.org/linux-arm-kernel/20200604022031.164207-1-masahiroy@kernel.org/