Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp2507886rdb; Wed, 4 Oct 2023 03:33:22 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEOi7BtIllWB8K7YtfCl8+LFiLdDj14p3dG7df+PF3rd/BybbUfljopdxzMdKzI9yH1i2yj X-Received: by 2002:a05:6870:1718:b0:1be:f0b4:b9bc with SMTP id h24-20020a056870171800b001bef0b4b9bcmr2316030oae.39.1696415602564; Wed, 04 Oct 2023 03:33:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696415602; cv=none; d=google.com; s=arc-20160816; b=IQSqAyEankEVkS5pVTWcDsH4wt6mguPpcPqUA0dZsmbcWj526z8ZIJOKj2Q5ddrWM9 jTDM1Mp30L57e0sEWFqyWnHkydA91bdPrDL8n31a7290A62/WEiuABVn0bHkGOCTSpl4 IEMBlb7el7DQhfzkjnKiMp0PodBqN5HQY2deEM1+9j+J+WARjl1URVqnUV5+GD1zbpUY aiEzgQfgfcjxiMHVIBdwV3DOjB8Krqx9O84zP+Qjo7HROdpn55bQTsTR1D6DGQznyV7d NxjRWUWqJzG4+cWXcGojuvEc8gB1Ex7MO/TlnoUbHo1bbfvLBn+49jtKcLTConPqWPI3 J/Gg== 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-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=IPdQhoPm+GbgN7ZVx8L+id2JS3S18F2GF5veflK7uBA=; fh=4vHyZd+iGFcz+j4heNTqPbiwFZRSyDI98D7fzYcxjBc=; b=l2cpVzSYaymoTWG2u29gqRFpFRoe23MSPAs2RUlpLSEslz+deEzqw4kAu1FcyZD1MR v8NUNVFwAnltgtE6z3RUAFzmnbWDtzIqjKF9g2YjD6YlZPR3A5GL4ZrRT+xPiMDMcCH5 ptRhLFJ/c1v0POGodAOoRcxX615Yo17HInMpP/vYa+d6lxBUbxEzAujHIIQLmvHF29fd LURcSo/4AG/BaEEDsueXvjmxISAhePwbuFhjrpqOwLTk+0DR95TDaB/89GBJ2mZeHfI3 z3dqaxdJAvu2eXb+JbrXcKL6SSvX6+HUIS5CbQIqJYAb5Dxl1fKrReEeMbI/scKVeTGv v/lA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=Op2PYtDp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id g20-20020a056a0023d400b006935df301a3si3514136pfc.8.2023.10.04.03.33.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Oct 2023 03:33:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=Op2PYtDp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id A20B2809B9C3; Wed, 4 Oct 2023 03:33:21 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233291AbjJDKdU (ORCPT + 99 others); Wed, 4 Oct 2023 06:33:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55838 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232987AbjJDKdS (ORCPT ); Wed, 4 Oct 2023 06:33:18 -0400 Received: from mail-il1-x136.google.com (mail-il1-x136.google.com [IPv6:2607:f8b0:4864:20::136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9586FA1 for ; Wed, 4 Oct 2023 03:33:14 -0700 (PDT) Received: by mail-il1-x136.google.com with SMTP id e9e14a558f8ab-3515aad4a87so7458565ab.3 for ; Wed, 04 Oct 2023 03:33:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1696415594; x=1697020394; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=IPdQhoPm+GbgN7ZVx8L+id2JS3S18F2GF5veflK7uBA=; b=Op2PYtDpFrHc1akmTsxCpbVdmtfuLFCwO5GpNBgKPD5FGjg1sgJjbnT/EIKKFfW0Up Qv0e0bGhIgMv0evMJvth0fKEWQSJUuFK7+ldB4wIvsCC55PvHV2vZG47BR13DGJyrovp viarD5XYFdo87beZyfbd4Vc59Pa79phdkPa/X2/AalplV6Ho1NKikXw7nQRbGaHxlTiL JynCZGvLYcq/2YL3JYhtERKkxGtrEi1+FrhbXW0fMPYyPk/S6IULRIAxjOxVI6c/BFoI 0cNqvraokX2AYG/5MW7U0WXFwilHIstNVlLWIXMuPIiO2U8HSUQGnfIH6/8PTFCV8K8w uQbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696415594; x=1697020394; h=in-reply-to:content-transfer-encoding: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=IPdQhoPm+GbgN7ZVx8L+id2JS3S18F2GF5veflK7uBA=; b=M88lymqUFzMJAtQNUYTC1xZQi8YdJ+wiUU2Q1eQki8funIRcMHXh58f+U+i1Ix6Ffa AgJ/2yKYTlVpUvN4lLCF1Ujen/54EtIlUcyxyinIFlNluyEIvP16HMYIHgQISlvQowiL X8+CYs/jrMZ0Ws51Hg8crtxj15ha0F+f9zUGuvhWQEzmfHhAzSx+BaoMWrVUFayePmV4 odjSnySs9dOdgUc/BbGMxwQRYgXIvEKJYCkPGsnHRQQVaZdBoZd1shQnS2sGaByvCy6U sWDrJxquMcs/HDUkIRDkamH3pMM2/NcI+bxfSilnIZtGMkJ3CJVYsTHSMaAo/Yra5a5U tcoA== X-Gm-Message-State: AOJu0YyHr43y4PjIpRKvM+UrAeAAPeziho11xeklA36x4UOwZkvaKVIW q/rE6c3gPYJhs52NHkzZu0NOpaPHDxXhrk4zZUI= X-Received: by 2002:a05:6e02:219b:b0:351:2053:c6cd with SMTP id j27-20020a056e02219b00b003512053c6cdmr2074083ila.3.1696415593914; Wed, 04 Oct 2023 03:33:13 -0700 (PDT) Received: from sunil-laptop ([106.51.188.78]) by smtp.gmail.com with ESMTPSA id a7-20020a92d107000000b0034f6f2eca21sm898204ilb.69.2023.10.04.03.33.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Oct 2023 03:33:13 -0700 (PDT) Date: Wed, 4 Oct 2023 16:03:02 +0530 From: Sunil V L To: Alexandre Ghiti Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, Paul Walmsley , Palmer Dabbelt , Albert Ou , "Rafael J . Wysocki" , Len Brown , Daniel Lezcano , Thomas Gleixner , Andrew Jones , Conor Dooley , Anup Patel , Ard Biesheuvel , Andy Shevchenko , Atish Kumar Patra Subject: Re: [PATCH v2 -next 1/4] RISC-V: ACPI: Enhance acpi_os_ioremap with MMIO remapping Message-ID: References: <20230927170015.295232-1-sunilvl@ventanamicro.com> <20230927170015.295232-2-sunilvl@ventanamicro.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: 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,URIBL_BLOCKED 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-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Wed, 04 Oct 2023 03:33:21 -0700 (PDT) Hi Alex, On Tue, Oct 03, 2023 at 08:53:12PM +0200, Alexandre Ghiti wrote: > Hi Sunil, > > On Wed, Sep 27, 2023 at 7:00 PM 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. > > > > Signed-off-by: Sunil V L > > Reviewed-by: Andrew Jones > > --- > > arch/riscv/Kconfig | 1 + > > arch/riscv/kernel/acpi.c | 87 +++++++++++++++++++++++++++++++++++++++- > > 2 files changed, 86 insertions(+), 2 deletions(-) > > > > diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig > > index d607ab0f7c6d..ac039cf8af7a 100644 > > --- a/arch/riscv/Kconfig > > +++ b/arch/riscv/Kconfig > > @@ -39,6 +39,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 > > Shouldn't we restrict this to ACPI? > Sure, Let me update. > > 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..e619edc8b0cc 100644 > > --- a/arch/riscv/kernel/acpi.c > > +++ b/arch/riscv/kernel/acpi.c > > @@ -14,9 +14,10 @@ > > */ > > > > #include > > +#include > > #include > > +#include > > #include > > -#include > > > > int acpi_noirq = 1; /* skip ACPI IRQ initialization */ > > int acpi_disabled = 1; > > @@ -217,7 +218,89 @@ 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\n"); > > + 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); > > I have to ask: why is write-through mapped to write-combined here? > IIUC, write-through ensures the copy in the cache and memory are always in sync. So, instead of using WB, non-cacheable WC is used as RISC-V doesn't really define these attributes. Let me know if this is not correct. > > + } > > + } > > + > > + return ioremap_prot(phys, size, pgprot_val(prot)); > > } > > > > #ifdef CONFIG_PCI > > -- > > 2.39.2 > > > > Like Andrew said in v1, too bad we can't merge that with arm64 instead > of duplicating. > I agree. But since acpi_os_ioremap() is supposed to be arch function, I kept is separate. Also, I need feedback from Ard whether we should make it common and where to add this common function. > But otherwise, you can add: > > Reviewed-by: Alexandre Ghiti > Thanks! Sunil