Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp2439828ioo; Sat, 28 May 2022 13:45:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwgpmICyO22QMNeFWcPq96Ib5eyJ3oj1OMuGbANd4Vv+W8OX6Z1hnVpO9b1S75cWFUSZJIZ X-Received: by 2002:a17:903:248:b0:155:e660:b774 with SMTP id j8-20020a170903024800b00155e660b774mr50035324plh.174.1653770756711; Sat, 28 May 2022 13:45:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653770756; cv=none; d=google.com; s=arc-20160816; b=c8LRBEfUgC3nt/8r6XMdPgV4RJ+MLn6CqpLoUwcJY8nHMRy+JdvTfJ6qnsuP3sOMu/ M60fSaaaJMZv6Dg9QOKwNjec+8isF7MlahbZbMeFcJv9To7/iGJk9aJLfwaU5M6nRP5w JSjYzfQ/h1oc22h8AR2G/XYPFyrfZxGssq0CVekN4YimhQ7tj7h0z6yxwUsvuLWbVOoi jUj59CXGX+pTFDJBZwB5hm3TDY58cxjzFKrucl2hv3ol7qCqERHyKtXk6N5GYvUOW7Yn 8bYWWmUIm5agu56MN7ryi7Mgwmv+n53FkJf7W2J708ItBHiV4fgAhV7bq8HK3Rluepan hP9g== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ScQKZk+sF2u8FOUXZCqEcJmznZn5Z8+t19qG24gINnM=; b=MDrAY3VkMc3WIozZ3bOaMRuIez1cexZu7FgdXrKMhcp4Y2DCY6pqhrkq4jA76NCf4F zczwLhAuaaeDZhDhTJOLemHNm9N/wcvkJoXtCw0YfL6b+US5YvxlgLOm8npioFfZea6i hDYy0u0/OSOQ6IauvB41gFERReSmZObI6Wnq3Xp70vdGM4Q1hbiZ/yo5dXxrd/4P6g1d 22tJtpJU4RBbnPrh25sFGUXmsWlV1Wy4pQn48skETxs3cmbC04xctSw1ZSRA6CQZStrG JHrNgPDoJgFYbTrCVmOcASDyKhI5pEsnCG1hif3Rs3lxMuTlj6vFVzdmgmnlnFfalj6s 2Y4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=vMA6kDG7; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id p1-20020a056a000a0100b0050de75d740asi11167083pfh.301.2022.05.28.13.45.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 May 2022 13:45:56 -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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=vMA6kDG7; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id BDB331BC7B9; Sat, 28 May 2022 12:45:14 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350457AbiE0JBq (ORCPT + 99 others); Fri, 27 May 2022 05:01:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59792 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350442AbiE0I76 (ORCPT ); Fri, 27 May 2022 04:59:58 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 491FB765C; Fri, 27 May 2022 01:55:54 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id D3DB461D91; Fri, 27 May 2022 08:55:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8EAA4C385B8; Fri, 27 May 2022 08:55:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1653641753; bh=Yy5gQPcfw9NC/kuApdrxoyH05hh4EnBXxxCCeB24uyw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vMA6kDG7Qjqjs8HGxmqmnpjctGDQaABSw/10hAdxT3cgRznt4bGuRicxE/jqFdcDA fAQ6yMJxB973r0mazlxYMEUszbsnm2xThFoK6jON5He085aMhRHjcX69If9Y20KOGl P/U8CIcRrzORgYh3HaG/vt+ih585qLsOyC3lq/ls= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lorenzo Pieralisi , Veronika Kabatova , Aristeu Rozanski , Ard Biesheuvel , "Rafael J. Wysocki" , dann frazier Subject: [PATCH 5.18 46/47] ACPI: sysfs: Fix BERT error region memory mapping Date: Fri, 27 May 2022 10:50:26 +0200 Message-Id: <20220527084808.833542561@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220527084801.223648383@linuxfoundation.org> References: <20220527084801.223648383@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE 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 From: Lorenzo Pieralisi commit 1bbc21785b7336619fb6a67f1fff5afdaf229acc upstream. 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 Tested-by: Veronika Kabatova Tested-by: Aristeu Rozanski Acked-by: Ard Biesheuvel Signed-off-by: Rafael J. Wysocki Cc: dann frazier Signed-off-by: Greg Kroah-Hartman --- drivers/acpi/sysfs.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) --- a/drivers/acpi/sysfs.c +++ b/drivers/acpi/sysfs.c @@ -415,19 +415,30 @@ static ssize_t acpi_data_show(struct fil 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; - base = acpi_os_map_memory(data_attr->addr, data_attr->attr.size); + if (offset < 0) + return -EINVAL; + + if (offset >= size) + return 0; + + 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)