Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp126318iof; Sun, 5 Jun 2022 23:09:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwH2ETJH+QgYaR7OSwqXYZGCg/m2bqNbpA8cNYPLY1qTN9X8blVanJwrktOhvI8tANp8ulS X-Received: by 2002:a17:902:b703:b0:15e:ea16:2c6e with SMTP id d3-20020a170902b70300b0015eea162c6emr22628411pls.100.1654495749601; Sun, 05 Jun 2022 23:09:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654495749; cv=none; d=google.com; s=arc-20160816; b=UZoGmaBUeveq46HRC/cwZ7JSRK97ntaQ4j+Km6vECi3wJwmOt0/1RVqvuPpqRUDZg0 Ze38BzPgslqDLEVed1ZBsgvzoeL+jwlurRHJaLOACvbeNMbgbytLR4Mo/elYeGcNpTJ7 v39MBpeou/G84d6xh9ZeUwiEd776Ff78njqEId8SwBFdq0hJsKkA4NoXYMtY72gsCkbm ZgW1W3Myaam3x/3JgtFH+dZ/lnS+6NW3dRU9cgSdpzVkD50Gtv9MQKfRJ2gPm9VkB39w gWd1o5wLc2LGCVxFyiOnA9HdkUihwoVUqrFQ4MSQU4ocVifwbJqiHoiBy4i1PyoHIAlh 4CkQ== 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=qNQqTiVwIpjkmkMXA5gAdqQ/nP872BnauROb6fD7ijw=; b=JDfgfo9rYWBKlYus53GOl6tHehQA8ghCcm6Yldo+9QImw8ao8OYgjbx2FGZyb/RGzt 32RPNHLfvyM2flDMiO3SwMvY8P2VsuS1w4LhZe+K6m5FKADtl67e8S20hFW7UT+ePv7K vIUW3w458U+8uBa9gLUIvNH1aecYzbAxi8v7/zv08sJ5h6vcRvMxbXfCyQF7wpCPgdIt JHen5SJ46Czqenv3HoAX76e76nsodKiFthQAbCo6itUAlUVWjXEf/PAAaDJwCqVdF18y 9RbLenhvB7JPHUDOwlPhrKivicgT6vg1F5FfTdqeOfhDFrDDkbBA2kZ6OPLLzBHdn0Yx tHgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=My2MvMuv; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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. [23.128.96.19]) by mx.google.com with ESMTPS id o31-20020a635d5f000000b003fc85b4f6b7si18832884pgm.95.2022.06.05.23.09.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Jun 2022 23:09:09 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=My2MvMuv; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 D46ED119908; Sun, 5 Jun 2022 21:59:54 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238455AbiFCRlm (ORCPT + 99 others); Fri, 3 Jun 2022 13:41:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56986 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344830AbiFCRlL (ORCPT ); Fri, 3 Jun 2022 13:41:11 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C043E53B7F; Fri, 3 Jun 2022 10:40:52 -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 B43DEB82430; Fri, 3 Jun 2022 17:40:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 09ABDC385B8; Fri, 3 Jun 2022 17:40:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654278049; bh=/6hYpM1FK3HHsmFSHCUL41bDLJyzzxRtY/h7B9oAOTY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=My2MvMuvQ0uThSJEgIYuHvXedoTOE7Fe7QxLd68OCzVbmRq/dCB7YTLH0zaLuRamz ad7pJRRAnG5mfcrYyHUY4vaDQ4CPg16rPlGF6qy7BWZ4vFXkV5t6omIyAIblGOsJgr OAApAtTOgjRv9Xodi+gUZSPRPwTUIEefq9ATRFtg= 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.14 06/23] ACPI: sysfs: Fix BERT error region memory mapping Date: Fri, 3 Jun 2022 19:39:33 +0200 Message-Id: <20220603173814.558870162@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220603173814.362515009@linuxfoundation.org> References: <20220603173814.362515009@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=-3.1 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 @@ -435,19 +435,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)