Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4200984imw; Tue, 19 Jul 2022 01:43:28 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vJuBhC3Y6QQXbCQnMF92ScyqE3XjG+HNIYuXYVLuGl3iP2QF53aNkazpp1cU7jurr0SVzO X-Received: by 2002:a05:6402:320b:b0:43a:73ee:6273 with SMTP id g11-20020a056402320b00b0043a73ee6273mr42300675eda.365.1658220207896; Tue, 19 Jul 2022 01:43:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658220207; cv=none; d=google.com; s=arc-20160816; b=FJNSFOHZoxo+zv03KkWJ9JT3uWEIHT/dt6Vysl6nAPyiiVamj1ogCuMOWD70pWoueW XM5+mcgIJEu4o+vDq466K5dNr02vcfm7qxG+B+QaVwTpi0osH2I/IvvDMt8B/3NqgCW8 Qy3Yq3Ifq+o7ec7uz44wO+DwL6m0beKLKxfJze+qw0CeMW2/tSBTr2z8gvcYtzunV4IJ LyIXrcJ4a+xH5MppmW4rjlS6UIAl3U2ZGSORQSkoQ3AyfW+9lz8U/vwHp9dDn6HEjCz1 zSAr3umdD85qFqaGle4tBV/RqTjPn8U0dvLlDmEV7GLBX9kOeedRFk0tRTR2KdtbRbvh iSsg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:subject:cc:to:from:message-id :date:dkim-signature; bh=24dKMwpmkzZfyLBC3d62CbNwZNorQ1W5oW39N/jUkmI=; b=KxHXdpWOLssdSdVSCGAO67tSVAELC7FeYeiBt1jml82OLqcIYiyfLkXf32/ocBH3k3 e9T1rDhjlrYTj19kFOYLUUGa8EsxJDABHJFQSNo7OSaxQ0G03AQnpCdT8LzpnQ4Zh5V2 q3+32/Vk50+aIxG1yKtv/mc3UchSgvpScKbIabuQHv44vhAvr5mGh5Z7q18HkKfdSmbm 5hi11pv5YJxhGR/DPXM87o6/PHk7KzwNpgFLR1EbDEGSjQwXxvSXuLujXb8TCWQi4oPc BGSIU3XJTTt6c6mPIrD03WGOXiSB3XOXhVJPXCBnXN76ZIWP5HPbMuRZZXtqdwv97yjW XTlw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Mkt7fI80; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b18-20020a0564021f1200b0043a6f83255asi17574470edb.40.2022.07.19.01.43.03; Tue, 19 Jul 2022 01:43:27 -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=@kernel.org header.s=k20201202 header.b=Mkt7fI80; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235873AbiGSIdj (ORCPT + 99 others); Tue, 19 Jul 2022 04:33:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43306 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229647AbiGSIdi (ORCPT ); Tue, 19 Jul 2022 04:33:38 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 649AF3246F for ; Tue, 19 Jul 2022 01:33:37 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id F174D6177D for ; Tue, 19 Jul 2022 08:33:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4BE4CC341C6; Tue, 19 Jul 2022 08:33:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1658219616; bh=bTJlSNPu/OVu5OQPTRDZbaMP5OPr04EDRmJVIpEFVLk=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=Mkt7fI80F4wjLh8VzZncJL7LYhrjyqVt2CmIC844bgqRBHtXgo7Xlmc04RhQ8U7ov 8ueG7AvyV/nsz6xgnLT2S6ulQTxhkUOI4xBoeugudIKbQerwqkXaI5/37V1n7b3fXk Ljr33t56FtEUUbaO9eS8wCQBuerGCmaRHMEj0YaRHWFN5nyq7MsrGLl2F8uogo7l6a YY2BtmSuxoRwN5VnWXPLUTReN91D6U/EvNSwVodK3h3uYejYz/mDOkHN3Vhmq8/mGp /wxh+9P3wWUYYy4Bwj4/SAdglUEGSeSZXvF04BCnMbhyKkLYrSIvsSY7+Iuhwt6y8f FHWYpEuCZChyw== Received: from sofa.misterjones.org ([185.219.108.64] helo=why.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1oDife-008QV9-1C; Tue, 19 Jul 2022 09:33:34 +0100 Date: Tue, 19 Jul 2022 09:33:33 +0100 Message-ID: <87mtd5zele.wl-maz@kernel.org> From: Marc Zyngier To: wangwudi Cc: , Thomas Gleixner , Subject: Re: [PATCH] drivers: irqchip: Allocate alignment addr by ITS_BASER.Page_size In-Reply-To: <945e4200-9555-b6a4-5588-0d1c1b0be152@hisilicon.com> References: <1657955136-6622-1-git-send-email-wangwudi@hisilicon.com> <87tu7h4d78.wl-maz@kernel.org> <945e4200-9555-b6a4-5588-0d1c1b0be152@hisilicon.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/27.1 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: wangwudi@hisilicon.com, linux-kernel@vger.kernel.org, tglx@linutronix.de, lizixian@hisilicon.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-Spam-Status: No, score=-7.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS 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 Mon, 18 Jul 2022 08:35:47 +0100, wangwudi wrote: >=20 > Hi Marc, >=20 > =E5=9C=A8 2022/7/16 17:30, Marc Zyngier =E5=86=99=E9=81=93: > > On Sat, 16 Jul 2022 08:05:36 +0100, > > wangwudi wrote: > >> > >> The description of the ITS_BASER.Physical_Address field in the ARM GIC= spec is as=20 > >> follows: > >> "The address must be aligned to the size specified in the Page Size fi= eld." > >> The Page_Size field in ITS_BASER might be RO. > >> > >> Currently, the address is aligned based on the system page_size, not t= he HW=20 > >> Page_Size field. In some case, this is in contradiction with the spec. > >> > >> For example: > >> ITS_BASER.Page_Size indicate 16K, and kernel page size is 4K. > >> If HW need 4K-size memory, the driver may alloc a 4K aligned address. > >> This has been proven in hardware. > >=20 > > Ah, interesting bug. Thanks for bringing this up. Can you describe how > > this occurs? I suspect you are using indirect tables. > >=20 >=20 > Sure. In the system, kernel page size is 4K, and ITS_BASER.Page_Size is 1= 6K. >=20 > As you suspected, HW used indirect VPE table and indication supports a sm= all > number of vpeids, like 2-bits vpeid. So that HW requires only less than 4= K- > size memory, and 16K aligned base address. But driver alloctes 4K aligend= base > address. Well, that I dispute, see below. >=20 > >> > >> Cc: Thomas Gleixner > >> Cc: Marc Zyngier > >> Signed-off-by: wangwudi > >> --- > >> drivers/irqchip/irq-gic-v3-its.c | 3 +++ > >> 1 file changed, 3 insertions(+) > >> > >> diff --git a/drivers/irqchip/irq-gic-v3-its.c b/drivers/irqchip/irq-gi= c-v3-its.c > >> index 5ff09de6c48f..0e25e887d45c 100644 > >> --- a/drivers/irqchip/irq-gic-v3-its.c > >> +++ b/drivers/irqchip/irq-gic-v3-its.c > >> @@ -2310,6 +2310,9 @@ static int its_setup_baser(struct its_node *its,= struct its_baser *baser, > >> order =3D get_order(GITS_BASER_PAGES_MAX * psz); > >> } > >> =20 > >> + if ((psz > PAGE_SIZE) && (PAGE_ORDER_TO_SIZE(order) < psz)) { > >> + order =3D get_order(psz); > >> + } > >> page =3D alloc_pages_node(its->numa_node, GFP_KERNEL | __GFP_ZERO, o= rder); > >> if (!page) > >> return -ENOMEM; > >=20 > > However, I don't see how you end-up with the incorrect value here. > >=20 > > * No indirect table: > > alloc_its_tables(): > > order =3D get_order(baser->psz); > >=20 > > * Indirect tables: > > alloc_its_tables(): > > order =3D get_order(baser->psz); > > its_parse_indirect_baser(): > > new_order =3D *order; > > new_order =3D max_t(u32, get_order(esz << ids), new_order); > >=20 > > So in both cases, we should end-up with order >=3D get_order(psz). > Yes, totally agree. OK. So what does your patch actually fixes? >=20 > >=20 > > Clearly, I'm missing a path, but your commit message doesn't make it > > obvious. Can you please enlighten me? > >=20 > My commit is based on the premise: > "alloc_pages_node gives a size-aligend address". > For example, if HW apply for 4K-size memory, then allocated address is 4K > aligned. Right. And if baser->psz is 16K, the memory returned will be 16K aligned. The only thing I can imagine is that there is a code path that doesn't use baser->psz as the minimum value when allocating memory programmed into a ITS_BASER register. But I can't see that path. Can you? M. --=20 Without deviation from the norm, progress is not possible.