Received: by 2002:a05:6358:701b:b0:131:369:b2a3 with SMTP id 27csp2179215rwo; Sun, 23 Jul 2023 09:09:36 -0700 (PDT) X-Google-Smtp-Source: APBJJlGVXUudJaX7H1LqSlEEBUlWv8Y5SG61t/WDCVtP0DBAd9yW8lq2D8zh1vhMGdI/DM7kOh0U X-Received: by 2002:a05:6358:9909:b0:134:cb1d:6737 with SMTP id w9-20020a056358990900b00134cb1d6737mr2897786rwa.7.1690128576578; Sun, 23 Jul 2023 09:09:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690128576; cv=none; d=google.com; s=arc-20160816; b=tIFNUb+QVuJjR01f26djY7fMCI2ko4WzyTnIofw0dN3Ykh9pTvMmcb20uNMEuyYN/y 2Z6cRlII2iDisgNAexC+x/SY8IIPtH3noPnhGLmZBS3ernnv037pc18D4QbiEHXgdBkn uInOaTi9gYWUEoq9Ew3KvK2S87Ouea10QUlqrN+03q0/2UPi5vFnPZeSDfO86N2Lwi+j BnL9T3VZ3MRyklmrSMEsSavLypmeD4FzxF2Wtzu2+7vz54l5gXu+W2C5bkP+z/Vl1lG8 cPl+z+T4cFuVpHpl8Xk82xTaMwjU6WsPw+kSmZrVpInrs8zOWoXpJvTpDGwOQw9uRcYT 0Zzg== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=Eu16HQ4OcruSJQofjc02TY9kOytBuyjJiF1LEsu4nUQ=; fh=bKq58Q1fTORvr7XzrLw/Gaej7DfUpSShbqNQVpqVsKo=; b=Yxp2zWakROWcesnuhMZHBW/7jfEH9GNYhUzKvx7BMkoprUCgwlh02mGbTKcSne1LRs +cdMpCgb8d3cQzkFP1RWffEs3agLI/Og5ergwlTL1Zh7v3D0rpoRJjM60lInKWn2WflF MCZVYzRQkRwNgy4C0guvIFTbXkiGFFMIIizL0IzV9kA1bq5zrTTCsvsoNTTtlxsdx5w9 qBQDWjQttdpr3ad+VGkXG71ajiov5o/g+CA5mYRDcbMx2fpyF89apxFRRn7ENU4tnXLV uqmx4xmk+3kOcCZ0wxkZx/NpeMrWT6KRwA/40juSGNLeT10HNGi7/Al4ZLKgfxDUuHB+ rwMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=TlqShghq; 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 j193-20020a638bca000000b0054392750edfsi7248455pge.744.2023.07.23.09.09.24; Sun, 23 Jul 2023 09:09:36 -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=TlqShghq; 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 S229737AbjGWPEo (ORCPT + 99 others); Sun, 23 Jul 2023 11:04:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52776 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229487AbjGWPEn (ORCPT ); Sun, 23 Jul 2023 11:04:43 -0400 Received: from mail-il1-x12f.google.com (mail-il1-x12f.google.com [IPv6:2607:f8b0:4864:20::12f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C55E2D1 for ; Sun, 23 Jul 2023 08:04:41 -0700 (PDT) Received: by mail-il1-x12f.google.com with SMTP id e9e14a558f8ab-3460815fde5so20673015ab.2 for ; Sun, 23 Jul 2023 08:04:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1690124681; x=1690729481; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=Eu16HQ4OcruSJQofjc02TY9kOytBuyjJiF1LEsu4nUQ=; b=TlqShghqrhz17x7MmVFH5LTHDrveCfVh85QwDOnLArUI3ciz/2m86DHS6OeQJkkBlV sXJ904QbkbHAJNsF2XQSqWiokQ9dx46rzk0JQ+b52Rm7JjMPAhbd1OCbqijxEQDo9O1I g0oS6KDu95lHjKV75RjWR0yVE1zaKs8eOoZ27Gv3JfIfdO/mL69sqXiqgF5q1cf0dmQt 8Mwl+z0UZLjutEo2tvEmG7ZKuikcBLIlhWwAa1gj4McLYsOCBIqB3ETz0WQjrDGiv5HG i+rXn79Vb9ZphOPS6Uk+fs0dvNiyhOOF+kR9h38i1NY0Xi35kNe4CJ7R0XKNO+okFADD qQHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690124681; x=1690729481; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Eu16HQ4OcruSJQofjc02TY9kOytBuyjJiF1LEsu4nUQ=; b=GdB8pwgVKIdpwKT0UU64ppLS0CslGlMAxLXhIUX6Az8sprFVsbJR85sDc/LVl4ovul 0CUADUFulD+mzpZD4aC4zP+BiKYf/Q1BpoMmmdQnWbxdlrqhfR/0ZGzsz5c1bPzHg/+z lO3W6sYtkxppPnA/bQVK/fT8JbfystV2wF4DvAeH3HFnOHc9iQ/NMA0+uHdkNE9hfsX2 YtlsfYyfNNkn8nZ5pFsHqZY+cmKqtHvrsFPTNZ4rmKqnaDTw+KFRe0qZpYxlhnmv5oJD mp9yvPjRjeA+51qjSwEpLgv2ttUbWMyLC+tK/gRMYH4d/NK/FKf2w/3oMjAFCg6weN6D 984w== X-Gm-Message-State: ABy/qLb6apC+xDXLWwXuwHqimn5hdX+cPFuHccQAGX8/7pZYjjWa+4AO UNcWHwlGaeoSsDXUQ/CFzqlSCnPz5kpzO4EvqmY= X-Received: by 2002:a05:6e02:1c8a:b0:346:d51:9922 with SMTP id w10-20020a056e021c8a00b003460d519922mr6732380ill.13.1690124681070; Sun, 23 Jul 2023 08:04:41 -0700 (PDT) Received: from sunil-pc.Dlink ([106.51.190.25]) by smtp.gmail.com with ESMTPSA id o2-20020a639202000000b00563397f1624sm6596583pgd.69.2023.07.23.08.04.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Jul 2023 08:04:40 -0700 (PDT) From: Sunil V L To: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Paul Walmsley , Palmer Dabbelt , Albert Ou , Conor Dooley , Andrew Jones , Sunil V L , kernel test robot Subject: [PATCH -fixes] RISC-V: ACPI: Fix acpi_os_ioremap to return iomem address Date: Sun, 23 Jul 2023 20:34:34 +0530 Message-Id: <20230723150434.1055571-1-sunilvl@ventanamicro.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 Fix the acpi_os_ioremap() to return iomem address and use memory attributes from EFI memory map while remapping. Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-kbuild-all/202307230357.egcTAefj-lkp@intel.com/ Fixes: a91a9ffbd3a5 ("RISC-V: Add support to build the ACPI core") Signed-off-by: Sunil V L --- arch/riscv/Kconfig | 1 + arch/riscv/kernel/acpi.c | 88 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 87 insertions(+), 2 deletions(-) diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index 4c07b9189c86..4892418e0821 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 5ee03ebab80e..ce28a530c81d 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; @@ -215,9 +216,92 @@ void __init __acpi_unmap_table(void __iomem *map, unsigned long size) early_iounmap(map, size); } -void *acpi_os_ioremap(acpi_physical_address phys, acpi_size size) +void __iomem *acpi_os_ioremap(acpi_physical_address phys, acpi_size size) { - return 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