From patchwork Sun Jul 23 15:04:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sunil V L X-Patchwork-Id: 124476 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9010:0:b0:3e4:2afc:c1 with SMTP id l16csp1328663vqg; Sun, 23 Jul 2023 09:09:30 -0700 (PDT) X-Google-Smtp-Source: APBJJlFSoKjqFd4xcdX8it1Fl94meoPLkZqlpzw2RnnvQDyGLrwbXLn/RES/dU4zxkSg1cf7WlFA X-Received: by 2002:a05:6358:e486:b0:135:9281:3542 with SMTP id by6-20020a056358e48600b0013592813542mr2066998rwb.9.1690128569967; Sun, 23 Jul 2023 09:09:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690128569; cv=none; d=google.com; s=arc-20160816; b=QN6ocbD7FppR/qsmGNXRh1FjDM5hYtuCCELketPGtr4r/2iMOEBMgdwMNAIAbn2fBl tFc/8uyOm6EzliAi1MejHb3yPhS8/l4MK/UBc/jew9fJFylksuLLgETGSr4YkPLiTzhz Um41Wrk89efkHwMPANp4ciLXiP+1PJ9Eem6WKc74R9tsPJRi403s7ry29cjDMhF7rLw2 O/7LHu9JaTmmnFkdleZKK2ENac1CqTD8rfDju+V6etCC6A2V4olSSUyaM/HeNEIPmv+C 3UcFq6TTXTiKycLaFBry8JhyBfqhMeLMqKUhDTXFDXmX5UP8PK+Fj4n4n8OVHOYHdse/ vvhA== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s129-20020a632c87000000b00553800fe4dcsi7364368pgs.583.2023.07.23.09.09.16; Sun, 23 Jul 2023 09:09:29 -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 S229745AbjGWPEo (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 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772228255779459868 X-GMAIL-MSGID: 1772228255779459868 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