Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp90082iof; Sun, 5 Jun 2022 22:03:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJysyBQPFEj/4yYYMcdF2ZGhSBXAgMszGV7nVr8R2XJTl8jKAxWqVvwOH/e6h9gmKvQcwDAV X-Received: by 2002:a63:5f0d:0:b0:3fd:7b18:bad8 with SMTP id t13-20020a635f0d000000b003fd7b18bad8mr7484955pgb.213.1654491804575; Sun, 05 Jun 2022 22:03:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654491804; cv=none; d=google.com; s=arc-20160816; b=vbuE28835uQh4yi2P8kavfwssEl53Iz6y1K4j+BniO/ShMmTp28nhjsVbqC7GxrL4J CQwhAkBITabMjDaSJFOP+wKslWh7qnUMg80cRbQLY1YKvw5/nNPcML/bCON2L/jmVjoe R4ocuZaHTELdEjCddKLUhEkrtKJXmJ20wGzfyEwVFGQVUAfZxsh6mZZPEWZzVqeUuvBh cX7mJDl+OOxQRGVWbIreEV0xDcQm6xNrctFjImHzFeDktF77YrfikGMC7uWsMP/NO80k o0BCWwLcstx44ip2hbfffE2IYlRu0ioiy6UVv8S86DtRybfF8exFx11HH1vMt9aJQbKF kWWQ== 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=eRhx2eaLr3TFccLw3nBcZBCcJxnFKJB35E34RRzKgneBC43nBKjSPQAuNb9iWNDFxz h4cxj5qslLTYfGjMLQ+HAuUN1IuYnuNdCzkTrTFO5doVBP/ZnqIx/bQ7uMG5xjOxwDZo IA0lpv2S4AOXPGssAkBJnOUckywIYLzOmRLZ01C51v18iagiQ0tu09H2ZSg9eP21ACNW fF6vKFEeOkVJc8cLofdJgG7MBYsyXfW7+Bsmh3sxpBTmxLrlULDa8UNQPZjeCkFL/tnZ k+Teqw2Oz5pHwtcYRNwbj6xd7jT37sVOUE6Q7qqFvBz+f7lws0bG8USAugnLAGbp7J2E 3ZPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=l52wWfUE; 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 t3-20020a17090ae50300b001dfb7951890si17760367pjy.160.2022.06.05.22.03.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Jun 2022 22:03:24 -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=l52wWfUE; 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 B8EEE71D90; Sun, 5 Jun 2022 21:11:56 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345441AbiFCRtm (ORCPT + 99 others); Fri, 3 Jun 2022 13:49:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345381AbiFCRsN (ORCPT ); Fri, 3 Jun 2022 13:48:13 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B8F6541A6; Fri, 3 Jun 2022 10:45:19 -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 3914660A24; Fri, 3 Jun 2022 17:45:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 42503C385A9; Fri, 3 Jun 2022 17:45:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654278318; bh=yojwAR4GeocO+V0acQYXPAOcPk/e68dRzRXpL5OJFns=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=l52wWfUEVGH94drrkI8DWznPgt6TGsxu8xfjxLNbOqIjwYUKUTzx5FWfyRoPp3Ity ZdMbsWnOleYotA2N1HxnG+5oReQZ2PhhgxKCMpy1g7thLTdvYajSub0NcaTNtUGUsX wSDALUuVDUS0cSqSra0anW0uuM8s/aevSmZGS3I8= 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.4 10/34] ACPI: sysfs: Fix BERT error region memory mapping Date: Fri, 3 Jun 2022 19:43:06 +0200 Message-Id: <20220603173816.297006586@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220603173815.990072516@linuxfoundation.org> References: <20220603173815.990072516@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 @@ -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)