Received: by 2002:a05:6359:6284:b0:131:369:b2a3 with SMTP id se4csp2782082rwb; Mon, 7 Aug 2023 03:31:00 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF2RxNhsOzrLs8mZdwo3UgUXTljhz/RV1sX6xoj6N2iiF0ptsKKuh/dL5Gn2BmOwth0mxu1 X-Received: by 2002:a17:90a:4a95:b0:268:1e51:3496 with SMTP id f21-20020a17090a4a9500b002681e513496mr8587651pjh.21.1691404260571; Mon, 07 Aug 2023 03:31:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691404260; cv=none; d=google.com; s=arc-20160816; b=f1e9IvCjyuVgHjKPGsCwWwTSWVgPgTAcRhssA/lnixkKGmLeeNSfAhI2S+wCNenchB PCxHAtPBr19ahdUugheALuT2w1qroKMxVHrq3GdRXTkhLrxcirSLVMqkFQDdCDQeHJTn oJuIbOK2znrVOSbvzrDka9NUfDCDZTq/9tP0Hd/FoG/bHoISlsnZ5aTFQLzcyozQ2f5/ /ZKR/mkiLLy0qvRgSmhawgjd2SgHTEpdgC8utmKJ0XdFa1w86RsQFossqH3ZkGKFj8Es wd7lVb4DlknZkQMnH+Cd3U//tj7VFd0W4gwmm0B+KPYL8htOnH6KK8GO8k9ZZfEncAd4 pJ+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=0eZZxF7uLAsYX/m67q6Fvc/Im25NatC6UCV3VKiuk20=; fh=+cCKDMkeaZH55pPhoEpUYQ2V6QWvxJjsm3Ffy7/nY50=; b=XHrNic471wpI4U4Mi+Ol5QNVICKguzAfZYHae/h/y/iEQR7JLEfn2wmML2BRZqtdZ8 f+6IcVm7p4ey7vH9IBD3H3NWZMUZgGktvjRB7zGBg81orwTGjhVvRxbfTdEYooX97JSs zoXQK13aSFzIE4LtwBlrXw6oOJ1w4nk00mnFyiZRBTM7SOWawjTgrzf35dB2IAGkT3ni lnssZvFWvgx/YupXwVgJtJl1qpphz6g5D27Gr66r7fOkheANSAMyMDhKRizxEHTiECmA zoATLOPLZbp86st/uQw606m1NGu1vTCKDEzqRSZdgS+I/plAQz9FLTzbmcSyKXaQIiQg iE9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=SOtKNq3t; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g7-20020a17090a290700b002635643286fsi8859298pjd.133.2023.08.07.03.30.48; Mon, 07 Aug 2023 03:31:00 -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=@ventanamicro.com header.s=google header.b=SOtKNq3t; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230513AbjHGIlY (ORCPT + 99 others); Mon, 7 Aug 2023 04:41:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230484AbjHGIlW (ORCPT ); Mon, 7 Aug 2023 04:41:22 -0400 Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [IPv6:2a00:1450:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 896711724 for ; Mon, 7 Aug 2023 01:41:18 -0700 (PDT) Received: by mail-ed1-x529.google.com with SMTP id 4fb4d7f45d1cf-5232bb5e47bso1930312a12.2 for ; Mon, 07 Aug 2023 01:41:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1691397677; x=1692002477; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=0eZZxF7uLAsYX/m67q6Fvc/Im25NatC6UCV3VKiuk20=; b=SOtKNq3tep9e4rbOEALFWIYYuWuTYwXx9gYJwZykSKNXY7xG5QmRvc7w9rvFbKnLC/ R51Q64qs1ZO2UuY7kop5KJfapfNRxmjYA/Xm8u7dkaqYYh0pVL6z+yUzv++OnFUWs9O8 kEXwXJASlHhfNVRiNypwaUAxqZeN9tiAmltG4fm734KSgXPCmyOSjniZzrAdqFjRuOce uH61wEY4n02TtZC3DKv5GXoXAVRRbTCVNprBkkazK3gdeYqTZ3XBJAp+BmyM9F7+qoQ8 6HiRrmt+auMZQNH1/21rgV6b46Z7KIDPAeHmmnBQ3kd3hOTkPuXO3izLsesVyKuX/TJf pQhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691397677; x=1692002477; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=0eZZxF7uLAsYX/m67q6Fvc/Im25NatC6UCV3VKiuk20=; b=lviUUKUbyylnJAFZ7L9Me3gbSYJzBTllFy0zPEgIU5L1aUHdXv28OdMFdiwXaf4XvZ cvY3j05MJFQtkU3g71Fi/8K2w7pIb+HDZx1PDqOh5iqknGcDiHExdyhg6bmjVQ3cxOhl 5t8NfkZKRfgU/tTAFffpKpNy86NlRdlYlUyGFm7Quxj9FhhFK7XakDHTx/HD/W7isG/g r2pOegX9L7fjrEZbH5GE9ukafSVadZ81BQRMUR16PjN0sY35x6tbzFXI2NxVGm9rwiDS G/43RDkMRWwodexxi402OK4HI1l50mUk7VSNxe8BFJHQHSHIy5gY6TBVYWJhEKQ6DJCu HxpQ== X-Gm-Message-State: AOJu0YwUsxxF2iwO4633mNqt4eHpRSblY0jrrI2jgq/up1u2r2ULsW5i XnNx6/eRrPQOB3WgISVbJvsvJw== X-Received: by 2002:aa7:d284:0:b0:51e:53eb:88a3 with SMTP id w4-20020aa7d284000000b0051e53eb88a3mr6239145edq.25.1691397677007; Mon, 07 Aug 2023 01:41:17 -0700 (PDT) Received: from localhost (212-5-140-29.ip.btc-net.bg. [212.5.140.29]) by smtp.gmail.com with ESMTPSA id b20-20020a056402139400b00522d53bff56sm4769693edv.65.2023.08.07.01.41.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Aug 2023 01:41:16 -0700 (PDT) Date: Mon, 7 Aug 2023 11:41:15 +0300 From: Andrew Jones To: Sunil V L Cc: linux-doc@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-acpi@vger.kernel.org, linux-pci@vger.kernel.org, Jonathan Corbet , Paul Walmsley , Palmer Dabbelt , Albert Ou , Catalin Marinas , Will Deacon , "Rafael J . Wysocki" , Len Brown , Andy Shevchenko , Daniel Scally , Heikki Krogerus , Sakari Ailus , Greg Kroah-Hartman , Daniel Lezcano , Thomas Gleixner , Anup Patel , Marc Zyngier , Bjorn Helgaas , Robert Moore , Haibo Xu , Conor Dooley , Atish Kumar Patra , Ard Biesheuvel , Alexandre Ghiti Subject: Re: [RFC PATCH v1 04/21] RISC-V: ACPI: Enhance acpi_os_ioremap with MMIO remapping Message-ID: <20230807-767cb417c44ed5f1437f7b0d@orel> References: <20230803175916.3174453-1-sunilvl@ventanamicro.com> <20230803175916.3174453-5-sunilvl@ventanamicro.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230803175916.3174453-5-sunilvl@ventanamicro.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 Thu, Aug 03, 2023 at 11:28:59PM +0530, Sunil V L wrote: > Enhance the acpi_os_ioremap() to support opregions in MMIO > space. Also, have strict checks using EFI memory map > to allow remapping the RAM similar to arm64. > > Cc: Ard Biesheuvel > Cc: Alexandre Ghiti > > Signed-off-by: Sunil V L > --- > arch/riscv/Kconfig | 1 + > arch/riscv/kernel/acpi.c | 86 +++++++++++++++++++++++++++++++++++++++- > 2 files changed, 86 insertions(+), 1 deletion(-) > > diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig > index 318f62a0a187..e19f32c12a68 100644 > --- a/arch/riscv/Kconfig > +++ b/arch/riscv/Kconfig > @@ -38,6 +38,7 @@ config RISCV > select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST > select ARCH_HAS_UBSAN_SANITIZE_ALL > select ARCH_HAS_VDSO_DATA > + select ARCH_KEEP_MEMBLOCK > select ARCH_OPTIONAL_KERNEL_RWX if ARCH_HAS_STRICT_KERNEL_RWX > select ARCH_OPTIONAL_KERNEL_RWX_DEFAULT > select ARCH_STACKWALK > diff --git a/arch/riscv/kernel/acpi.c b/arch/riscv/kernel/acpi.c > index 56cb2c986c48..aa4433bca6d9 100644 > --- a/arch/riscv/kernel/acpi.c > +++ b/arch/riscv/kernel/acpi.c > @@ -17,6 +17,7 @@ > #include > #include > #include > +#include > > int acpi_noirq = 1; /* skip ACPI IRQ initialization */ > int acpi_disabled = 1; > @@ -217,7 +218,90 @@ void __init __acpi_unmap_table(void __iomem *map, unsigned long size) > > void __iomem *acpi_os_ioremap(acpi_physical_address phys, acpi_size size) > { > - return (void __iomem *)memremap(phys, size, MEMREMAP_WB); > + efi_memory_desc_t *md, *region = NULL; > + pgprot_t prot; > + > + if (WARN_ON_ONCE(!efi_enabled(EFI_MEMMAP))) > + return NULL; > + > + for_each_efi_memory_desc(md) { > + u64 end = md->phys_addr + (md->num_pages << EFI_PAGE_SHIFT); > + > + if (phys < md->phys_addr || phys >= end) > + continue; > + > + if (phys + size > end) { > + pr_warn(FW_BUG "requested region covers multiple EFI memory regions\n"); > + return NULL; > + } > + region = md; > + break; > + } > + > + /* > + * It is fine for AML to remap regions that are not represented in the > + * EFI memory map at all, as it only describes normal memory, and MMIO > + * regions that require a virtual mapping to make them accessible to > + * the EFI runtime services. > + */ > + prot = PAGE_KERNEL_IO; > + if (region) { > + switch (region->type) { > + case EFI_LOADER_CODE: > + case EFI_LOADER_DATA: > + case EFI_BOOT_SERVICES_CODE: > + case EFI_BOOT_SERVICES_DATA: > + case EFI_CONVENTIONAL_MEMORY: > + case EFI_PERSISTENT_MEMORY: > + if (memblock_is_map_memory(phys) || > + !memblock_is_region_memory(phys, size)) { > + pr_warn(FW_BUG "requested region covers kernel memory @ %p\n", > + &phys); > + return NULL; > + } > + > + /* > + * Mapping kernel memory is permitted if the region in > + * question is covered by a single memblock with the > + * NOMAP attribute set: this enables the use of ACPI > + * table overrides passed via initramfs. > + * This particular use case only requires read access. > + */ > + fallthrough; > + > + case EFI_RUNTIME_SERVICES_CODE: > + /* > + * This would be unusual, but not problematic per se, > + * as long as we take care not to create a writable > + * mapping for executable code. > + */ > + prot = PAGE_KERNEL_RO; > + break; > + > + case EFI_ACPI_RECLAIM_MEMORY: > + /* > + * ACPI reclaim memory is used to pass firmware tables > + * and other data that is intended for consumption by > + * the OS only, which may decide it wants to reclaim > + * that memory and use it for something else. We never > + * do that, but we usually add it to the linear map > + * anyway, in which case we should use the existing > + * mapping. > + */ > + if (memblock_is_map_memory(phys)) > + return (void __iomem *)__va(phys); > + fallthrough; > + > + default: > + if (region->attribute & EFI_MEMORY_WB) > + prot = PAGE_KERNEL; > + else if ((region->attribute & EFI_MEMORY_WC) || > + (region->attribute & EFI_MEMORY_WT)) > + prot = pgprot_writecombine(PAGE_KERNEL); > + } > + } > + > + return ioremap_prot(phys, size, pgprot_val(prot)); > } > > #ifdef CONFIG_PCI > -- > 2.39.2 > Such a faithful port of arm64's function that it begs the question as to whether or not we should refactor and share. Anyway, other than Andy's comments, LGTM Reviewed-by: Andrew Jones Thanks, drew