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 lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2F13BCDB47E for ; Thu, 12 Oct 2023 09:10:34 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qqrhn-0002cL-Tz; Thu, 12 Oct 2023 05:10:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qqrhk-0002c0-9F for qemu-devel@nongnu.org; Thu, 12 Oct 2023 05:10:05 -0400 Received: from frasgout.his.huawei.com ([185.176.79.56]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qqrhg-0001tE-UV for qemu-devel@nongnu.org; Thu, 12 Oct 2023 05:10:02 -0400 Received: from lhrpeml500005.china.huawei.com (unknown [172.18.147.207]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4S5kKN4jHsz67CtD; Thu, 12 Oct 2023 17:06:48 +0800 (CST) Received: from localhost (10.48.155.47) by lhrpeml500005.china.huawei.com (7.191.163.240) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Thu, 12 Oct 2023 10:09:53 +0100 Date: Thu, 12 Oct 2023 10:09:52 +0100 To: Ani Sinha CC: Paolo Bonzini , Richard Henderson , Eduardo Habkost , "Michael S. Tsirkin" , Marcel Apfelbaum , Subject: Re: [PATCH] hw/i386/cxl: ensure maxram is greater than ram size for calculating cxl range Message-ID: <20231012100952.000064e2@Huawei.com> In-Reply-To: <8E01874E-9B9D-41C5-9D88-29D9B4071BC6@redhat.com> References: <20231011105335.42296-1-anisinha@redhat.com> <20231011173104.000016f5@Huawei.com> <8E01874E-9B9D-41C5-9D88-29D9B4071BC6@redhat.com> Organization: Huawei Technologies Research and Development (UK) Ltd. X-Mailer: Claws Mail 4.1.0 (GTK 3.24.33; x86_64-w64-mingw32) MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.48.155.47] X-ClientProxiedBy: lhrpeml500001.china.huawei.com (7.191.163.213) To lhrpeml500005.china.huawei.com (7.191.163.240) X-CFilter-Loop: Reflected Received-SPF: pass client-ip=185.176.79.56; envelope-from=jonathan.cameron@huawei.com; helo=frasgout.his.huawei.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Jonathan Cameron From: Jonathan Cameron via Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org On Thu, 12 Oct 2023 10:10:36 +0530 Ani Sinha wrote: > > On 11-Oct-2023, at 10:01 PM, Jonathan Cameron wrote: > >=20 > > On Wed, 11 Oct 2023 16:23:35 +0530 > > Ani Sinha wrote: > > =20 > >> pc_get_device_memory_range() finds the device memory size by calculati= ng the > >> difference between maxram and ram sizes. This calculation makes sense = only when > >> maxram is greater than the ram size. Make sure we check for that befor= e calling > >> pc_get_device_memory_range(). > >>=20 > >> Signed-off-by: Ani Sinha =20 > >=20 > > Whilst this is similar to other cases, I can't remember or quickly work > > out if the 'else' path here is appropriate. Can we add something to the > > patch description to talk about that? > >=20 > > For reference it's: > >=20 > > cxl_base =3D pc_above_4g_end(pcms); =20 >=20 > Leaving the alignment adjustments aside, the hotplugged memory devices ar= e mapped starting from where the =E2=80=9Cabove_4g=E2=80=9D memory ends. > The cxl memory starts after the region reserved for hot plugged memory de= vices. If there is no hot plugged memory device region (maxmem =3D=3D mem),= the cxl memory can start right after where =E2=80=9Cabove_4g=E2=80=9D memo= ry ends. > See also pc_pci_hole64_start() and pc_max_used_gpa(). > I did not want to add any alignment adjustments because I was not sure if= it would add regression and incompatibility with older machine types.=20 >=20 Thanks for explanation. Acked-by: Jonathan Cameron >=20 > > =20 > >> --- > >> hw/i386/pc.c | 4 +++- > >> 1 file changed, 3 insertions(+), 1 deletion(-) > >>=20 > >> diff --git a/hw/i386/pc.c b/hw/i386/pc.c > >> index f72e2c3b35..948c58171c 100644 > >> --- a/hw/i386/pc.c > >> +++ b/hw/i386/pc.c > >> @@ -820,10 +820,12 @@ static void pc_get_device_memory_range(PCMachine= State *pcms, > >> static uint64_t pc_get_cxl_range_start(PCMachineState *pcms) > >> { > >> PCMachineClass *pcmc =3D PC_MACHINE_GET_CLASS(pcms); > >> + MachineState *ms =3D MACHINE(pcms); > >> hwaddr cxl_base; > >> ram_addr_t size; > >>=20 > >> - if (pcmc->has_reserved_memory) { > >> + if (pcmc->has_reserved_memory && > >> + (ms->ram_size < ms->maxram_size)) { > >> pc_get_device_memory_range(pcms, &cxl_base, &size); > >> cxl_base +=3D size; > >> } else { =20 > > =20 >=20 From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1qqrhn-0002cM-1c for mharc-qemu-devel@gnu.org; Thu, 12 Oct 2023 05:10:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qqrhk-0002c0-9F for qemu-devel@nongnu.org; Thu, 12 Oct 2023 05:10:05 -0400 Received: from frasgout.his.huawei.com ([185.176.79.56]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qqrhg-0001tE-UV for qemu-devel@nongnu.org; Thu, 12 Oct 2023 05:10:02 -0400 Received: from lhrpeml500005.china.huawei.com (unknown [172.18.147.207]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4S5kKN4jHsz67CtD; Thu, 12 Oct 2023 17:06:48 +0800 (CST) Received: from localhost (10.48.155.47) by lhrpeml500005.china.huawei.com (7.191.163.240) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Thu, 12 Oct 2023 10:09:53 +0100 Date: Thu, 12 Oct 2023 10:09:52 +0100 From: Jonathan Cameron To: Ani Sinha CC: Paolo Bonzini , Richard Henderson , Eduardo Habkost , "Michael S. Tsirkin" , Marcel Apfelbaum , Subject: Re: [PATCH] hw/i386/cxl: ensure maxram is greater than ram size for calculating cxl range Message-ID: <20231012100952.000064e2@Huawei.com> In-Reply-To: <8E01874E-9B9D-41C5-9D88-29D9B4071BC6@redhat.com> References: <20231011105335.42296-1-anisinha@redhat.com> <20231011173104.000016f5@Huawei.com> <8E01874E-9B9D-41C5-9D88-29D9B4071BC6@redhat.com> Organization: Huawei Technologies Research and Development (UK) Ltd. X-Mailer: Claws Mail 4.1.0 (GTK 3.24.33; x86_64-w64-mingw32) MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.48.155.47] X-ClientProxiedBy: lhrpeml500001.china.huawei.com (7.191.163.213) To lhrpeml500005.china.huawei.com (7.191.163.240) X-CFilter-Loop: Reflected Received-SPF: pass client-ip=185.176.79.56; envelope-from=jonathan.cameron@huawei.com; helo=frasgout.his.huawei.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 12 Oct 2023 09:10:05 -0000 Message-ID: <20231012090952.1RyupoflkVaPNms-xbJ5wEFeCe3is9_YRpAD4fObx-I@z> On Thu, 12 Oct 2023 10:10:36 +0530 Ani Sinha wrote: > > On 11-Oct-2023, at 10:01 PM, Jonathan Cameron wrote: > >=20 > > On Wed, 11 Oct 2023 16:23:35 +0530 > > Ani Sinha wrote: > > =20 > >> pc_get_device_memory_range() finds the device memory size by calculati= ng the > >> difference between maxram and ram sizes. This calculation makes sense = only when > >> maxram is greater than the ram size. Make sure we check for that befor= e calling > >> pc_get_device_memory_range(). > >>=20 > >> Signed-off-by: Ani Sinha =20 > >=20 > > Whilst this is similar to other cases, I can't remember or quickly work > > out if the 'else' path here is appropriate. Can we add something to the > > patch description to talk about that? > >=20 > > For reference it's: > >=20 > > cxl_base =3D pc_above_4g_end(pcms); =20 >=20 > Leaving the alignment adjustments aside, the hotplugged memory devices ar= e mapped starting from where the =E2=80=9Cabove_4g=E2=80=9D memory ends. > The cxl memory starts after the region reserved for hot plugged memory de= vices. If there is no hot plugged memory device region (maxmem =3D=3D mem),= the cxl memory can start right after where =E2=80=9Cabove_4g=E2=80=9D memo= ry ends. > See also pc_pci_hole64_start() and pc_max_used_gpa(). > I did not want to add any alignment adjustments because I was not sure if= it would add regression and incompatibility with older machine types.=20 >=20 Thanks for explanation. Acked-by: Jonathan Cameron >=20 > > =20 > >> --- > >> hw/i386/pc.c | 4 +++- > >> 1 file changed, 3 insertions(+), 1 deletion(-) > >>=20 > >> diff --git a/hw/i386/pc.c b/hw/i386/pc.c > >> index f72e2c3b35..948c58171c 100644 > >> --- a/hw/i386/pc.c > >> +++ b/hw/i386/pc.c > >> @@ -820,10 +820,12 @@ static void pc_get_device_memory_range(PCMachine= State *pcms, > >> static uint64_t pc_get_cxl_range_start(PCMachineState *pcms) > >> { > >> PCMachineClass *pcmc =3D PC_MACHINE_GET_CLASS(pcms); > >> + MachineState *ms =3D MACHINE(pcms); > >> hwaddr cxl_base; > >> ram_addr_t size; > >>=20 > >> - if (pcmc->has_reserved_memory) { > >> + if (pcmc->has_reserved_memory && > >> + (ms->ram_size < ms->maxram_size)) { > >> pc_get_device_memory_range(pcms, &cxl_base, &size); > >> cxl_base +=3D size; > >> } else { =20 > > =20 >=20