Received: by 2002:a05:6a10:83d0:0:0:0:0 with SMTP id o16csp44595pxh; Thu, 7 Apr 2022 13:29:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyttYiMBYcmGrtol9W/F0xlKmUF6DhcqdvUpop47i6+I2eTdWXGVMkaFz1BPnXj8EbTUe27 X-Received: by 2002:a63:5909:0:b0:399:b94:96f9 with SMTP id n9-20020a635909000000b003990b9496f9mr12814085pgb.622.1649363343855; Thu, 07 Apr 2022 13:29:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649363343; cv=none; d=google.com; s=arc-20160816; b=jM/bo1bo/jMgoPywtJ1ExHgzClJoBE1IkBAhYRHnT7YWfkOECAqb4xEWNoTkulWjPh mbvx1+OR7Pio5CUFbaI9CL9VvSQXSEefaPAo1jYW1YbWgacon6A+dQ0tQesmBXBTWpMd lNmdNptsOPnBFfl7I7or78iG2QUq7P9AZAeS0Wupd8DkbTv40l0MJ4rZtJ4MpP8QsqmQ fdhStlT+ZF4qTE8gaNDRNUTe1sRKEuitS7pfHIyILA8KNkCUp2/76PriBL7DPKHOgbIr gvoIYo998rWV3QOOk8S6YjRlsYKQ5JeGOvianBodqj59/VU9UmubgQbZfZnYtdKpywuo KTKQ== 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; bh=DAn1u0xvEUpn+R95s2Yuj2TItMlIAxPTjZW2iBQ4Uro=; b=Ivk3LLHyCtAuwDfi8PhNMS9OUGPJ8F/Voj+H8tjAHIz4Pn2ELbj2Pzo3D5VqR3ocCm As8YG4iBXR2OxAdhQGhuvVODgLpaQOjnYvm0Tu14q8Z/nz9r4vzYze3+J04ZFTkmbRUV Osq5J6hml1nJarsmlyoyTLDN4YqGU2QP8zOZZQGWfR09UqErPtlarHHxCmYFkg/ZoFLT hmIgaAV6WmavbnyuotMQWHB+vHJJtJG+xMnWmwOvlcv5a5F5wOamm1fW2lI2O7VPPMct ABwCbEmuvXETOhXTIxoaTXigLtn2DiISE0lMVDeb/qU+lRbCeuI8By53x3RmC74Mc4Kc BrFQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id p4-20020a635b04000000b0038171da8ae5si17816011pgb.661.2022.04.07.13.29.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Apr 2022 13:29:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 60770368ECE; Thu, 7 Apr 2022 12:43:44 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230474AbiDGKxg (ORCPT + 99 others); Thu, 7 Apr 2022 06:53:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44450 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230025AbiDGKxa (ORCPT ); Thu, 7 Apr 2022 06:53:30 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D34A3114DE9; Thu, 7 Apr 2022 03:51:29 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 9FE5512FC; Thu, 7 Apr 2022 03:51:29 -0700 (PDT) Received: from e123427-lin.arm.com (unknown [10.57.6.208]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id C58153F5A1; Thu, 7 Apr 2022 03:51:27 -0700 (PDT) From: Lorenzo Pieralisi To: linux-kernel@vger.kernel.org Cc: Lorenzo Pieralisi , Ard Biesheuvel , Will Deacon , Hanjun Guo , Sudeep Holla , Catalin Marinas , "Rafael J. Wysocki" , linux-acpi@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Veronika kabatova , Robin Murphy , Aristeu Rozanski Subject: [PATCH] ACPI: osl: Fix BERT error region memory mapping Date: Thu, 7 Apr 2022 11:51:20 +0100 Message-Id: <20220407105120.1280-1-lorenzo.pieralisi@arm.com> X-Mailer: git-send-email 2.31.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 Currently the sysfs interface maps the BERT error region as "memory" (through acpi_os_map_memory()) in order to copy the error records into memory buffers through memory operations (eg memory_read_from_buffer()). The OS system cannot detect whether the BERT error region is part of system RAM or it is "device memory" (eg BMC memory) and therefore it cannot detect which memory attributes the bus to memory support (and corresponding kernel mapping, unless firmware provides the required information). The acpi_os_map_memory() arch backend implementation determines the mapping attributes. On arm64, if the BERT error region is not present in the EFI memory map, the error region is mapped as device-nGnRnE; this triggers alignment faults since memcpy unaligned accesses are not allowed in device-nGnRnE regions. The ACPI sysfs code cannot therefore map by default the BERT error region with memory semantics but should use a safer default. Change the sysfs code to map the BERT error region as MMIO (through acpi_os_map_iomem()) and use the memcpy_fromio() interface to read the error region into the kernel buffer. Link: https://lore.kernel.org/linux-arm-kernel/31ffe8fc-f5ee-2858-26c5-0fd8bdd68702@arm.com Link: https://lore.kernel.org/linux-acpi/CAJZ5v0g+OVbhuUUDrLUCfX_mVqY_e8ubgLTU98=jfjTeb4t+Pw@mail.gmail.com Signed-off-by: Lorenzo Pieralisi Cc: Ard Biesheuvel Cc: Will Deacon Cc: Hanjun Guo Cc: Sudeep Holla Cc: Catalin Marinas Cc: "Rafael J. Wysocki" --- drivers/acpi/sysfs.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c index a4b638bea6f1..cc2fe0618178 100644 --- a/drivers/acpi/sysfs.c +++ b/drivers/acpi/sysfs.c @@ -415,19 +415,30 @@ static ssize_t acpi_data_show(struct file *filp, struct kobject *kobj, loff_t offset, size_t count) { struct acpi_data_attr *data_attr; - void *base; - ssize_t rc; + void __iomem *base; + ssize_t size; data_attr = container_of(bin_attr, struct acpi_data_attr, attr); + size = data_attr->attr.size; + + if (offset < 0) + return -EINVAL; + + if (offset >= size) + return 0; - base = acpi_os_map_memory(data_attr->addr, data_attr->attr.size); + if (count > size - offset) + count = size - offset; + + base = acpi_os_map_iomem(data_attr->addr, size); if (!base) return -ENOMEM; - rc = memory_read_from_buffer(buf, count, &offset, base, - data_attr->attr.size); - acpi_os_unmap_memory(base, data_attr->attr.size); - return rc; + memcpy_fromio(buf, base + offset, count); + + acpi_os_unmap_iomem(base, size); + + return count; } static int acpi_bert_data_init(void *th, struct acpi_data_attr *data_attr) -- 2.31.0