Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp8462987ioo; Sat, 4 Jun 2022 08:58:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyhS4kFX3oQ6O7ALSC+ySpDT9Q5TAZkfsU+IL57pFnrzuz9XXGmxvI7T3aWTurSt0FJx1q3 X-Received: by 2002:a17:903:248:b0:155:e8c6:8770 with SMTP id j8-20020a170903024800b00155e8c68770mr14883492plh.129.1654358297420; Sat, 04 Jun 2022 08:58:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654358297; cv=none; d=google.com; s=arc-20160816; b=EmqiS5XY7bVqDW4VcSNdv7Dr5B47zrkQNJh5RkKUDwIgdvtl5V753HacuZFv6QM4Zg g8XL1F2IZ2PnYgg2MiWJ5ZjODtwMZjBy5HdErFyPHyaShWlu8NuNLxU4gkwJ7yV+8H20 AUht0a5+Ccj38NFy/P+DztSIJh+zJnzDRQh1sROtLIZ6omY3oUIdclZWAfW4oQPzSwDY +mFdFfc3W23/DYJeBYYamm0HlTmEifaZoEy1l1LldB2T/loM9DWKV+o3KHKKM4Ozrgnn bKVcUWZdo1ZfzKVxZacHYWbySEj5lg8sPmPw8/jZW7uqOp3zlrWgo9HZls6HOSxoMjxQ hocg== 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=+w2uydS6ZUkEZFJuBl47OyomCcXzfOzC2RIcaMcCYhw=; b=f70OwAQKYQaLn2mq7E8UothUbT2dG8hLy6m/sqPVDZHaosEtP1f65DkHx4zfVxJb9R yp1HUDg2JqmnWXoZOLQQkXrQZid4CZ5R0rJ9mxYlqrYPEMe8LMy8W1EggMbSSt7fr4Wo kdOCPFVJOe1z38cCAjm8AV2TIj1euywuBZTxgcHM9k2i1vw48UzjFpFds2VaW8cmUA6S 6rOPcOEjnQHv8hycKHi36qLvXDWTXXRUCiI+OncNmalG0Xhufe92RrEjWoRBQQ9ctpYP 24bKHkPtXP9ojtC3xhR7C41FkKN4+tQgr8XIR0O0DtHmeULStTZGsAhNNBjholrkFyFF BvGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=eZ3eo7bx; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b9-20020a170902d50900b00164179afee4si2906017plg.376.2022.06.04.08.58.04; Sat, 04 Jun 2022 08:58:17 -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=@linuxfoundation.org header.s=korg header.b=eZ3eo7bx; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344675AbiFCRpY (ORCPT + 99 others); Fri, 3 Jun 2022 13:45:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56552 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345126AbiFCRoj (ORCPT ); Fri, 3 Jun 2022 13:44:39 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F254D55203; Fri, 3 Jun 2022 10:42:37 -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 ams.source.kernel.org (Postfix) with ESMTPS id C2F92B8242D; Fri, 3 Jun 2022 17:42:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3D47AC385A9; Fri, 3 Jun 2022 17:42:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654278154; bh=yojwAR4GeocO+V0acQYXPAOcPk/e68dRzRXpL5OJFns=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eZ3eo7bx5ky5onfl1dUg9rdFnyZ17nSFNbFefMjoDnopUCUuKy28Qnfnfjx5u5Ryf zf2gGj6wLqb2rmD9ik9rrIXblx56uCsuFEVejNFH/d0EZwox+7+JJnj8JcfET2lyW9 cY7EbObEGKVLdto+shB0Cy9Tr7slXV7gjOcbYTPk= 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 4.19 06/30] ACPI: sysfs: Fix BERT error region memory mapping Date: Fri, 3 Jun 2022 19:39:34 +0200 Message-Id: <20220603173815.280377951@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220603173815.088143764@linuxfoundation.org> References: <20220603173815.088143764@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=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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 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 @@ -438,19 +438,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)