From patchwork Fri Dec 13 13:43:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mykyta Poturai X-Patchwork-Id: 13907035 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.xenproject.org (lists.xenproject.org [192.237.175.120]) (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 AA029E7717F for ; Fri, 13 Dec 2024 13:44:05 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.856699.1269245 (Exim 4.92) (envelope-from ) id 1tM5xH-0002tH-Pf; Fri, 13 Dec 2024 13:43:43 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 856699.1269245; Fri, 13 Dec 2024 13:43:43 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tM5xH-0002tA-Ml; Fri, 13 Dec 2024 13:43:43 +0000 Received: by outflank-mailman (input) for mailman id 856699; Fri, 13 Dec 2024 13:43:42 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tM5xG-0002su-5D for xen-devel@lists.xenproject.org; Fri, 13 Dec 2024 13:43:42 +0000 Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on20613.outbound.protection.outlook.com [2a01:111:f403:2612::613]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 42ac9a5c-b958-11ef-99a3-01e77a169b0f; Fri, 13 Dec 2024 14:43:40 +0100 (CET) Received: from PAVPR03MB10102.eurprd03.prod.outlook.com (2603:10a6:102:30d::12) by AS8PR03MB9747.eurprd03.prod.outlook.com (2603:10a6:20b:61c::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8230.18; Fri, 13 Dec 2024 13:43:38 +0000 Received: from PAVPR03MB10102.eurprd03.prod.outlook.com ([fe80::35ac:8893:c31c:b971]) by PAVPR03MB10102.eurprd03.prod.outlook.com ([fe80::35ac:8893:c31c:b971%5]) with mapi id 15.20.8251.015; Fri, 13 Dec 2024 13:43:38 +0000 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 42ac9a5c-b958-11ef-99a3-01e77a169b0f ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=kAzDxXP+PGPfqPvkLRzNqzMgOwwNTp4qSumEsWBBMxd8BbL2I5cDM2ZjZGMKSNccjgXuT7/e9Yuboj4vfcssm7TRAHhRUcHpIeGH089cebA2s15NTBAcqrCtH6vd3A/vVEJ6o36KrVY1kliukUPFknwX+OgLNHsBx+aITJJVptVbOaC+t1UAuBdIsclVGA+0jbmRTQXZvPF1BV+cV20OW8fyZKECcrK183PxDVeoBJlAzPIicwr14ioTDaJFjJWyJt06YeP6/d6i7vPn1hedXBIvQC3QqU5Gk7/w7wyVcnJNCpGUqNFvpsYC3xYa/5W0LVrY2erZ2yLYDpTjwZ3PPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=8m82pZphfIXwF4z/QxJwwNRwFlrHF7j9oOsgHJHvG7M=; b=gvvTxVr4fNTFohG8qpFEf9YF+q0NznZAx6RCxPpBs7WkRaF5rvA+9RoQAVqssqg6LJYnZubWop/aEYaq1BG8jBvI6hNgdzELO0z0yBF3EIltH9l8193WQe+9XCPA73UtoHRRNSA7vDdzOXmmPlsUOCbEY/yoncw29stytIb4dvOU4RF3WbKRMa8IzHO4NC2AleHf+RZj4zs2Ld1WG6qy1Uq9bzxWFHUNUoTYf2fKeD62vZH1xNetqqy4LWmZrEQeeNN3yNlYi6NGDlwr86fjkbZbObyCxaluqjrQXRYbelJICuazEa40sf6VqkWtrMcro6JcKo/dZq7gxxZ2Z8Mw3g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=epam.com; dmarc=pass action=none header.from=epam.com; dkim=pass header.d=epam.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=epam.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=8m82pZphfIXwF4z/QxJwwNRwFlrHF7j9oOsgHJHvG7M=; b=Cc7ukpAIpV7dc9jztd2CIl3FoNx1upwPD2nwwFdPa8KlnmA5A667Ya+fIPerl+C3CtaQCD61qle6Q95c/inG41ErpRq1xrLF+vn8JR+A8C9/okgldoHKHr6p7rNAodcBC4WpcIfV2/zDknTWVeTyAm7zCI6IkKhW1RJYkBmLoOgBhmHICrSxLjb3VN91tofa8oWcx2ZtNuT2n6GFlFXODxYlNi+GYK6UT06zmj1MWtPHnDDR3lc21AsLydDfUFoA7mIsZ1S3TiGZAo9tiewDFt9SS2l3E5/6APqezflQbPAawp7f9P8Guy2X38OTpl6vOq+w+qaXFnHPDci9fEUL9Q== From: Mykyta Poturai To: "xen-devel@lists.xenproject.org" CC: Oleksandr Andrushchenko , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , Andrew Cooper , Anthony PERARD , Jan Beulich , =?iso-8859-1?q?Roger_Pau_Monn=E9?= , Mykyta Poturai Subject: [PATCH 1/2] ARM: ITS: implement quirks and add support for Renesas Gen4 ITS Thread-Topic: [PATCH 1/2] ARM: ITS: implement quirks and add support for Renesas Gen4 ITS Thread-Index: AQHbTWUDkPvtOs/CJU+9P/F/tFzopw== Date: Fri, 13 Dec 2024 13:43:38 +0000 Message-ID: <2ea26be2689585ea254a9c0177816722bcb2db8d.1734096752.git.mykyta_poturai@epam.com> References: In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=epam.com; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: PAVPR03MB10102:EE_|AS8PR03MB9747:EE_ x-ms-office365-filtering-correlation-id: 2b1849ca-faf7-400c-261a-08dd1b7c25ea x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0;ARA:13230040|366016|1800799024|376014|38070700018; x-microsoft-antispam-message-info: =?iso-8859-1?q?xnUBcbig9o+7RZWWGjo1yf7UpO?= =?iso-8859-1?q?7YiNXapL4DN4EJjSv+bKmupyrVdzymvfi2do+1DuRKWFNIYFgpKpPzIGffEn?= =?iso-8859-1?q?oNwHVquY4a9r8IhNUbLJkK8nwqsFaukmERftUA9Zb9Fw0pLPcu0ll/q8c/fB?= =?iso-8859-1?q?Tc+/r3tA48MPeQmXpaeFEJGPydag/yMF/8TL+2If2x3euyOwo2ctdx6Ud3QR?= =?iso-8859-1?q?zJmxrzcqE9Li+Q44RF/aG6NxWvwfRr/gID2+7nZxI7AB+LfphIBz0GQPk1xg?= =?iso-8859-1?q?cGQe3zDawONNJz31q70cAX6FwYJSAnnBqgC6LZ4sdcr0ExU1jPL1eZWhahN3?= =?iso-8859-1?q?gYW/dSt2qa5Cj8Xfymi4SQW74T651eDLHfaW7B9KtjX6F1ShuoU0w2PovIbb?= =?iso-8859-1?q?6rmywDu4BcLnoZ1JdZthBbbMBf9mSD3UqWwGzFdV4nToph2QpHStR1zfjXtN?= =?iso-8859-1?q?8FQ6rUmfhvareGPL6mjOO+DAUAO/HTvqyZ1JOO84haO/By3steYgU2Zq4WNB?= =?iso-8859-1?q?wCGcHecmJ/Yn2muo5a3NCblkIIZaOsfr0IZO6wmlhFf+zjLBxtzUgUkbr6gN?= =?iso-8859-1?q?7W+vEx1V8ZANomA8puoT5k4BLdTd/bTq03S+Ec2veyPr3LTxXcidkx8SnMI9?= =?iso-8859-1?q?EGKt8c+s1McsC62v0tBkrTuTH5Kz/h+oyb/7G9ryfxR0QSaxf+izD0VkeEj2?= =?iso-8859-1?q?7qjKy7ZZ4qgbkXXWhnc8+JI+7bYtYXoLuS6GAWVbglv4gizkZ7bitc3vats2?= =?iso-8859-1?q?82QHDUVFU2XdVMfSdN7iTjXWZZGrlu0XxCwlf5Utq8+sLboSAFfMVXEkSV0r?= =?iso-8859-1?q?f0U+oH0JZ+gIT3qwnDd1RsTxyyiF+b/yHuqiY65ql7f+4XjeUs5Q3FKF9O6Y?= =?iso-8859-1?q?X44DVtifp+E2DFq8OTDOL6F2/wcaJHYcxVdXlh1Ay1yODCimBboKP8xV793D?= =?iso-8859-1?q?tDy8A/eOh5JrB8vQaimYASQvbjFTApIU/F0jyHyRr3uaVIbQbPYDRU3qSRyZ?= =?iso-8859-1?q?uUXcYomP6FINNak6sg/2o4B3sUXtRGKVRBOL+xhvopqatrn3/A6urkIuZ1Qn?= =?iso-8859-1?q?Fq8q+bJM+/nYm8++2iVmLDMd0YDUZl8Pw38ApWuAByxdkjvzqHLP8v4aeWY2?= =?iso-8859-1?q?xsern5vKzCkumSWQH2V+g9nQusXnmFcMoctELLE/xiLVkE40EUsYx2SSixuP?= =?iso-8859-1?q?zOk4ZCDrwbzL3jqLSOgL6fxrAStoCjBHeX/8/hUOP7Hnfnby177PZkuIC4nn?= =?iso-8859-1?q?XOGOobXKsR9X1dU17HeLCDVpn1t3MPrVYyldJULLaNMvJe9c3IupoUI62K/i?= =?iso-8859-1?q?7SFMxBW8v2RUmybPJmO9MwrRh1p0tsmr8Y20XlHYYQzl6RqnzYEmuKYVwknV?= =?iso-8859-1?q?xiJ8N+tD02sdgxKDahFsbIInF1vviWXZfq06xsKSM=3D?= x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PAVPR03MB10102.eurprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(1800799024)(376014)(38070700018);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?3a3Yc+ZkJ8u6mJY1A+e25bL?= =?iso-8859-1?q?jGEpjPINyNqr/GG92le9LoAQ/q8Kwm/LDJ3hpob7abZKMLxukDVCapx0DiBM?= =?iso-8859-1?q?xgl6bFs2SSHR5ygZQiPk5yO2C07qbmHoYdH59QIDtSw00eNtGpoSWSBPpz4d?= =?iso-8859-1?q?mos7tx5jfGT6EfgyR9Y19tDKR/v7x053IQ/ZH6go5c2pobpp3+OL/QcnAdXg?= =?iso-8859-1?q?r9NOEyqBS2NWeBJrIan+nbyimYH8bosMEnNv10nj1xdkAkLjRQ6dJhG0nZ6L?= =?iso-8859-1?q?2qjX56vkK3jtUXO1H6Qwwjf9jW2J7i7RcQiieAQJwTen+NwpQCsPhyiYZ5Ds?= =?iso-8859-1?q?hH/VTZD4C+ZgqfJDIPhRcHWEl9ljurxvMpjgoH7pkQmJJH4u3HbtQ8A5dUzd?= =?iso-8859-1?q?+1Y92DfdWRXbGmKyMqthRnJ7R7bEYEMGBJtqu/hmtPdWxolOJtWcZ+aFSxbZ?= =?iso-8859-1?q?68/+LqL9QL3S4l0jNUUvd3iORsUYum9QsypolvErFioQSlJy1r0qN2IxhkN5?= =?iso-8859-1?q?2I5e3CgiveEZq9UKH3vIFQrJdkokFoPZAuoazxdgYgvdobBFYT2yJMduoWgR?= =?iso-8859-1?q?ZGsCzg7NgGjyWDGMZsbZsHAx3KEzz/XnCWlrC9sV9A6Xd2TL2iCd7vkt2q+z?= =?iso-8859-1?q?Tk/QWIGEf3Ednl0gVZAdWTyVg/egXvPyw7p3hIUjiUqP1ZIdO8WCKfi6ukq+?= =?iso-8859-1?q?7hgvYm9cFQg2mUoPLfUNadToPBhMmVwEXaMbrT8hXXf4nF102mJpCagM6/IW?= =?iso-8859-1?q?Rnhfeh6SPi1RO73BQ0wF5avmvq62WmP1R5CeymrxDNY07DQq/syYUJ+Xv/dD?= =?iso-8859-1?q?hoRlW0fBasEWqJsTFeL1z1v5b3MGnWrEvfF2CPVdzGuGG4ugx5NN27VNml/D?= =?iso-8859-1?q?+P6gmyre00tnFEjq+qb1mkuW6x1ac6PF4NspB91hUYt6JjZ9En85Vkc6Snly?= =?iso-8859-1?q?4I3hjFBhaJW50kA8RlEf2SZud/hri9qfinE6PHs1Q9CAJQrenivGBI+IS9d6?= =?iso-8859-1?q?0LZC7ilw66gMNeTdsXUdprf7m+wB9rpFkXvRQgdLhwtmF+ENpv49/gKso0kM?= =?iso-8859-1?q?VgGu6m5mLjy5Q/d4YPfSmTXCPir4FI9EpnQRut1kfDhznIYYaSwJ5oJpW1m+?= =?iso-8859-1?q?1v0zynsAFZJUmNk1+n78FSxCfhAnm3uE79bQBYD8QVW1MHLb9/NSzsS+vTib?= =?iso-8859-1?q?/T1bo9QPU+glR+cK7huPIVzQYQPCdav3GNgxeUYTOmGlRO59/shJBCdnVuXB?= =?iso-8859-1?q?57wN/f5KGd3j+TbIk3Zd5xrOWrdJ2pGFa3FAO2fBiOsCxTFspS7YarVeyFgh?= =?iso-8859-1?q?7eZNA/IXiP+m1qaS6brOxdMVBQKSc06XzzB0TwLLCGqad7braE48j9zOa+f7?= =?iso-8859-1?q?6Jogqywoq+/HSaHAy54/eKwTNt+RuKWKqcrFF5F0AqcHUvjunvg9FsFOwnzq?= =?iso-8859-1?q?g6VhAwN8T1GHcS5ou+JiFmwAtflh7iCDpnr0ANw7U0FElFUzNLlrY5gbafJF?= =?iso-8859-1?q?O7RWXEkyd5gZUvZXQ3pxGSnwJsPA8HKjrVu1jV45igd/1pxTSfQrpacpdQfd?= =?iso-8859-1?q?x4fHcx13frRjhzpBPSmNoklNvza9NzuPfxHSe62ZqLHupkGPmASFXuCJTSaL?= =?iso-8859-1?q?9j+wHE3KNK7vMU0Sd++gdHfVcR5Yk3oF1BJ/ijA=3D=3D?= MIME-Version: 1.0 X-OriginatorOrg: epam.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: PAVPR03MB10102.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2b1849ca-faf7-400c-261a-08dd1b7c25ea X-MS-Exchange-CrossTenant-originalarrivaltime: 13 Dec 2024 13:43:38.2425 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: b41b72d0-4e9f-4c26-8a69-f949f367c91d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: aePkeOQXJ/fgWAb5vj4hpg5Y0AkWpuqYYZIZpjmkWms6DtvZbfCzULoX+CaecbEWXbvPaCEm8xdSD2DLdHykdQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR03MB9747 From: Oleksandr Andrushchenko There are number of ITS implementations exist which are different from the base one which have number of functionalities defined as is "IMPLEMENTATION DEFINED", e.g. there may exist differences in cacheability, shareability and memory requirements and others. This requires appropriate handling of such HW requirements which are implemented as ITS quirks: GITS_IIDR (ITS Implementer Identification Register) is used to differentiate the ITS implementations and select appropriate set of quirks if any. As an example of such ITSes add quirk implementation for Renesas Gen4 ITS: - add possibility to override default cacheability and shareability settings used for ITS memory allocations; - add possibility to allocate memory used by ITS with specific memory requirements: introduce _x{z|m}alloc_whole_pages functions and free the memory with xfree as usual. The idea of the quirk implementation is inspired by the Linux kernel ITS quirk implementation [1]. Signed-off-by: Oleksandr Andrushchenko Signed-off-by: Mykyta Poturai [1] https://elixir.bootlin.com/linux/v5.16.1/source/drivers/irqchip/irq-gic-v3-its.c --- xen/arch/arm/gic-v3-its.c | 90 ++++++++++++++++++++++++--- xen/arch/arm/gic-v3-lpi.c | 14 +++-- xen/arch/arm/include/asm/gic_v3_its.h | 8 +++ xen/arch/arm/vgic-v3-its.c | 8 +-- xen/common/xmalloc_tlsf.c | 18 +++++- xen/include/xen/xmalloc.h | 4 ++ 6 files changed, 122 insertions(+), 20 deletions(-) diff --git a/xen/arch/arm/gic-v3-its.c b/xen/arch/arm/gic-v3-its.c index 5fd83af25a..b1a2cdccc5 100644 --- a/xen/arch/arm/gic-v3-its.c +++ b/xen/arch/arm/gic-v3-its.c @@ -50,6 +50,77 @@ struct its_device { struct pending_irq *pend_irqs; /* One struct per event */ }; +/* + * It is unlikely that a platform implements ITSes with different quirks, + * so assume they all share the same. + */ +struct its_quirk { + const char *desc; + bool (*init)(struct host_its *hw_its); + uint32_t iidr; + uint32_t mask; +}; + +uint32_t its_quirk_flags; + +static bool gicv3_its_enable_quirk_gen4(struct host_its *hw_its) +{ + its_quirk_flags |= HOST_ITS_WORKAROUND_NC_NS | + HOST_ITS_WORKAROUND_32BIT_ADDR; + + return true; +} + +static const struct its_quirk its_quirks[] = { + { + .desc = "R-Car Gen4", + .iidr = 0x0201743b, + .mask = 0xffffffff, + .init = gicv3_its_enable_quirk_gen4, + }, + { + /* Sentinel. */ + } +}; + +static void gicv3_its_enable_quirks(struct host_its *hw_its) +{ + const struct its_quirk *quirks = its_quirks; + uint32_t iidr = readl_relaxed(hw_its->its_base + GITS_IIDR); + + for ( ; quirks->desc; quirks++ ) + { + if ( quirks->iidr != (quirks->mask & iidr) ) + continue; + if ( quirks->init(hw_its) ) + printk("GICv3: enabling workaround for ITS: %s\n", quirks->desc); + } +} + +uint64_t gicv3_its_get_cacheability(void) +{ + if ( its_quirk_flags & HOST_ITS_WORKAROUND_NC_NS ) + return GIC_BASER_CACHE_nC; + + return GIC_BASER_CACHE_RaWaWb; +} + +uint64_t gicv3_its_get_shareability(void) +{ + if ( its_quirk_flags & HOST_ITS_WORKAROUND_NC_NS ) + return GIC_BASER_NonShareable; + + return GIC_BASER_InnerShareable; +} + +unsigned int gicv3_its_get_memflags(void) +{ + if ( its_quirk_flags & HOST_ITS_WORKAROUND_32BIT_ADDR ) + return MEMF_bits(32); + + return 0; +} + bool gicv3_its_host_has_its(void) { return !list_empty(&host_its_list); @@ -291,11 +362,12 @@ static void *its_map_cbaser(struct host_its *its) uint64_t reg; void *buffer; - reg = GIC_BASER_InnerShareable << GITS_BASER_SHAREABILITY_SHIFT; + reg = gicv3_its_get_shareability() << GITS_BASER_SHAREABILITY_SHIFT; reg |= GIC_BASER_CACHE_SameAsInner << GITS_BASER_OUTER_CACHEABILITY_SHIFT; - reg |= GIC_BASER_CACHE_RaWaWb << GITS_BASER_INNER_CACHEABILITY_SHIFT; + reg |= gicv3_its_get_cacheability() << GITS_BASER_INNER_CACHEABILITY_SHIFT; - buffer = _xzalloc(ITS_CMD_QUEUE_SZ, SZ_64K); + buffer = _xzalloc_whole_pages(ITS_CMD_QUEUE_SZ, SZ_64K, + gicv3_its_get_memflags()); if ( !buffer ) return NULL; @@ -342,9 +414,9 @@ static int its_map_baser(void __iomem *basereg, uint64_t regc, unsigned int table_size; void *buffer; - attr = GIC_BASER_InnerShareable << GITS_BASER_SHAREABILITY_SHIFT; + attr = gicv3_its_get_shareability() << GITS_BASER_SHAREABILITY_SHIFT; attr |= GIC_BASER_CACHE_SameAsInner << GITS_BASER_OUTER_CACHEABILITY_SHIFT; - attr |= GIC_BASER_CACHE_RaWaWb << GITS_BASER_INNER_CACHEABILITY_SHIFT; + attr |= gicv3_its_get_cacheability() << GITS_BASER_INNER_CACHEABILITY_SHIFT; /* * Setup the BASE register with the attributes that we like. Then read @@ -357,7 +429,8 @@ retry: /* The BASE registers support at most 256 pages. */ table_size = min(table_size, 256U << BASER_PAGE_BITS(pagesz)); - buffer = _xzalloc(table_size, BIT(BASER_PAGE_BITS(pagesz), UL)); + buffer = _xzalloc_whole_pages(table_size, BIT(BASER_PAGE_BITS(pagesz), UL), + gicv3_its_get_memflags()); if ( !buffer ) return -ENOMEM; @@ -453,6 +526,8 @@ static int gicv3_its_init_single_its(struct host_its *hw_its) if ( ret ) return ret; + gicv3_its_enable_quirks(hw_its); + reg = readq_relaxed(hw_its->its_base + GITS_TYPER); hw_its->devid_bits = GITS_TYPER_DEVICE_ID_BITS(reg); hw_its->evid_bits = GITS_TYPER_EVENT_ID_BITS(reg); @@ -681,7 +756,8 @@ int gicv3_its_map_guest_device(struct domain *d, ret = -ENOMEM; /* An Interrupt Translation Table needs to be 256-byte aligned. */ - itt_addr = _xzalloc(nr_events * hw_its->itte_size, 256); + itt_addr = _xzalloc_whole_pages(nr_events * hw_its->itte_size, 256, + gicv3_its_get_memflags()); if ( !itt_addr ) goto out_unlock; diff --git a/xen/arch/arm/gic-v3-lpi.c b/xen/arch/arm/gic-v3-lpi.c index de4b0eb4a4..72b725a624 100644 --- a/xen/arch/arm/gic-v3-lpi.c +++ b/xen/arch/arm/gic-v3-lpi.c @@ -237,7 +237,8 @@ static int gicv3_lpi_allocate_pendtable(unsigned int cpu) * The GICv3 imposes a 64KB alignment requirement, also requires * physically contiguous memory. */ - pendtable = _xzalloc(lpi_data.max_host_lpi_ids / 8, SZ_64K); + pendtable = _xmalloc_whole_pages(lpi_data.max_host_lpi_ids / 8, SZ_64K, + gicv3_its_get_memflags()); if ( !pendtable ) return -ENOMEM; @@ -272,9 +273,9 @@ static int gicv3_lpi_set_pendtable(void __iomem *rdist_base) ASSERT(!(virt_to_maddr(pendtable) & ~GENMASK(51, 16))); - val = GIC_BASER_CACHE_RaWaWb << GICR_PENDBASER_INNER_CACHEABILITY_SHIFT; + val = gicv3_its_get_cacheability() << GICR_PENDBASER_INNER_CACHEABILITY_SHIFT; val |= GIC_BASER_CACHE_SameAsInner << GICR_PENDBASER_OUTER_CACHEABILITY_SHIFT; - val |= GIC_BASER_InnerShareable << GICR_PENDBASER_SHAREABILITY_SHIFT; + val |= gicv3_its_get_shareability() << GICR_PENDBASER_SHAREABILITY_SHIFT; val |= GICR_PENDBASER_PTZ; val |= virt_to_maddr(pendtable); @@ -301,9 +302,9 @@ static int gicv3_lpi_set_proptable(void __iomem * rdist_base) { uint64_t reg; - reg = GIC_BASER_CACHE_RaWaWb << GICR_PROPBASER_INNER_CACHEABILITY_SHIFT; + reg = gicv3_its_get_cacheability() << GICR_PROPBASER_INNER_CACHEABILITY_SHIFT; reg |= GIC_BASER_CACHE_SameAsInner << GICR_PROPBASER_OUTER_CACHEABILITY_SHIFT; - reg |= GIC_BASER_InnerShareable << GICR_PROPBASER_SHAREABILITY_SHIFT; + reg |= gicv3_its_get_shareability() << GICR_PROPBASER_SHAREABILITY_SHIFT; /* * The property table is shared across all redistributors, so allocate @@ -312,7 +313,8 @@ static int gicv3_lpi_set_proptable(void __iomem * rdist_base) if ( !lpi_data.lpi_property ) { /* The property table holds one byte per LPI. */ - void *table = _xmalloc(lpi_data.max_host_lpi_ids, SZ_4K); + void *table = _xmalloc_whole_pages(lpi_data.max_host_lpi_ids, SZ_4K, + gicv3_its_get_memflags()); if ( !table ) return -ENOMEM; diff --git a/xen/arch/arm/include/asm/gic_v3_its.h b/xen/arch/arm/include/asm/gic_v3_its.h index c24d4752d0..0737e67aa6 100644 --- a/xen/arch/arm/include/asm/gic_v3_its.h +++ b/xen/arch/arm/include/asm/gic_v3_its.h @@ -110,6 +110,9 @@ #define HOST_ITS_FLUSH_CMD_QUEUE (1U << 0) #define HOST_ITS_USES_PTA (1U << 1) +#define HOST_ITS_WORKAROUND_NC_NS (1U << 0) +#define HOST_ITS_WORKAROUND_32BIT_ADDR (1U << 1) + /* We allocate LPIs on the hosts in chunks of 32 to reduce handling overhead. */ #define LPI_BLOCK 32U @@ -197,6 +200,11 @@ struct pending_irq *gicv3_assign_guest_event(struct domain *d, void gicv3_lpi_update_host_entry(uint32_t host_lpi, int domain_id, uint32_t virt_lpi); +/* ITS quirks handling. */ +uint64_t gicv3_its_get_cacheability(void); +uint64_t gicv3_its_get_shareability(void); +unsigned int gicv3_its_get_memflags(void); + #else #ifdef CONFIG_ACPI diff --git a/xen/arch/arm/vgic-v3-its.c b/xen/arch/arm/vgic-v3-its.c index c65c1dbf52..f5deb18497 100644 --- a/xen/arch/arm/vgic-v3-its.c +++ b/xen/arch/arm/vgic-v3-its.c @@ -1191,7 +1191,7 @@ static void sanitize_its_base_reg(uint64_t *reg) { case GIC_BASER_OuterShareable: r &= ~GITS_BASER_SHAREABILITY_MASK; - r |= GIC_BASER_InnerShareable << GITS_BASER_SHAREABILITY_SHIFT; + r |= gicv3_its_get_shareability() << GITS_BASER_SHAREABILITY_SHIFT; break; default: break; @@ -1203,7 +1203,7 @@ static void sanitize_its_base_reg(uint64_t *reg) case GIC_BASER_CACHE_nCnB: case GIC_BASER_CACHE_nC: r &= ~GITS_BASER_INNER_CACHEABILITY_MASK; - r |= GIC_BASER_CACHE_RaWb << GITS_BASER_INNER_CACHEABILITY_SHIFT; + r |= gicv3_its_get_cacheability() << GITS_BASER_INNER_CACHEABILITY_SHIFT; break; default: break; @@ -1455,9 +1455,9 @@ static int vgic_v3_its_init_virtual(struct domain *d, paddr_t guest_addr, if ( !its ) return -ENOMEM; - base_attr = GIC_BASER_InnerShareable << GITS_BASER_SHAREABILITY_SHIFT; + base_attr = gicv3_its_get_shareability() << GITS_BASER_SHAREABILITY_SHIFT; base_attr |= GIC_BASER_CACHE_SameAsInner << GITS_BASER_OUTER_CACHEABILITY_SHIFT; - base_attr |= GIC_BASER_CACHE_RaWaWb << GITS_BASER_INNER_CACHEABILITY_SHIFT; + base_attr |= gicv3_its_get_cacheability() << GITS_BASER_INNER_CACHEABILITY_SHIFT; its->cbaser = base_attr; base_attr |= 0ULL << GITS_BASER_PAGE_SIZE_SHIFT; /* 4K pages */ diff --git a/xen/common/xmalloc_tlsf.c b/xen/common/xmalloc_tlsf.c index 5e55fc463e..f7f00db044 100644 --- a/xen/common/xmalloc_tlsf.c +++ b/xen/common/xmalloc_tlsf.c @@ -537,14 +537,15 @@ static void cf_check xmalloc_pool_put(void *p) free_xenheap_page(p); } -static void *xmalloc_whole_pages(unsigned long size, unsigned long align) +void *_xmalloc_whole_pages(unsigned long size, unsigned long align, + unsigned int memflags) { unsigned int i, order; void *res, *p; order = get_order_from_bytes(max(align, size)); - res = alloc_xenheap_pages(order, 0); + res = alloc_xenheap_pages(order, memflags); if ( res == NULL ) return NULL; @@ -562,6 +563,17 @@ static void *xmalloc_whole_pages(unsigned long size, unsigned long align) return res; } +void *_xzalloc_whole_pages(unsigned long size, unsigned long align, + unsigned int memflags) +{ + void *p = _xmalloc_whole_pages(size, align, memflags); + + if ( p ) + memset(p, 0, size); + + return p; +} + static void tlsf_init(void) { xenpool = xmem_pool_create("xmalloc", xmalloc_pool_get, @@ -628,7 +640,7 @@ void *_xmalloc(unsigned long size, unsigned long align) if ( size < PAGE_SIZE ) p = xmem_pool_alloc(size, xenpool); if ( p == NULL ) - return xmalloc_whole_pages(size - align + MEM_ALIGN, align); + return _xmalloc_whole_pages(size - align + MEM_ALIGN, align, 0); /* Add alignment padding. */ p = add_padding(p, align); diff --git a/xen/include/xen/xmalloc.h b/xen/include/xen/xmalloc.h index b903fa2e26..3b05e992ef 100644 --- a/xen/include/xen/xmalloc.h +++ b/xen/include/xen/xmalloc.h @@ -79,6 +79,10 @@ extern void xfree(void *p); extern void *_xmalloc(unsigned long size, unsigned long align); extern void *_xzalloc(unsigned long size, unsigned long align); extern void *_xrealloc(void *ptr, unsigned long size, unsigned long align); +extern void *_xmalloc_whole_pages(unsigned long size, unsigned long align, + unsigned int memflags); +extern void *_xzalloc_whole_pages(unsigned long size, unsigned long align, + unsigned int memflags); static inline void *_xmalloc_array( unsigned long size, unsigned long align, unsigned long num)