Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp1397727pxb; Thu, 14 Apr 2022 05:26:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxH0t0vvoo9bvIdYYYvBhM4VMkQh262IvpUdIasxG0uSZUdSP5GOSNPPZxLQ9n2DvIDk8wO X-Received: by 2002:a17:902:f701:b0:14d:7cea:82af with SMTP id h1-20020a170902f70100b0014d7cea82afmr46417687plo.71.1649939186994; Thu, 14 Apr 2022 05:26:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649939186; cv=none; d=google.com; s=arc-20160816; b=LOlvFfnJNFnoLzrfk6yPkG9jQFDjcW0lQ25WxGafO7ouIvu2aSfvrCYwsDl4icJVPq hvVZbWKtlzPImgmAUY6tsimCYMMqZ1AFAAe/y6BSQaj5NDcb6qh8YrV2NoRvACAOrtGG rFazp/AFO+dn7R2ZsEOEmBQq7L1tUW9ZHgyI9+cc0bwgY5V4Tfn9poEznHoMzu8lxsI7 NiiK/T1O+o2v4SqLVtLnV0IJGkm+KQsaIAAA+Y5+mqK7aD0m5ylhrplArL3uAwU8dfam 4ltGQxzE0kTb0IufpzMFEDtsRSpFzQQmfWDzcwN/+XnJhtC5F0Dh92hLYKlMk+jH0rff 4d9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version; bh=XBIdc2r7ktDJVgL8jFR2huHb3Z5LWfWpJ3rv5dtCkOU=; b=uW64tmS6oUcP7iMNZOXB99iXnKLanSXUmZAMdAuALlSxEWznGHBkjqD8pf4NpNq1gS M5iEc5L0RekVTOMRXaKfoYnwEkyQFwHtqaOLJFCStYHanFaHIWVKCT+LDw/Dj+8nZBVp DjvsuuijMCnqYwwf3UGbrzGNdpZnwodyrcgdvjNJONnnN2IS6YBpZx1bAEaSUUIOrKr3 1sKYSoGIbhpBnJjpkts/KT1ksDHHUmqUVmP1r2aV9ZwAdR/sJ0SXG5qBMKbNLhRLCb+R H0Yc2gMGjFxbtyEbPwPMfKM6e40LMiXg5bmkpKZTHaPBVVVY7SoPcI/oHido33pVTuDC lJOQ== 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:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 35-20020a17090a0fa600b001caa4c5d4b6si1519968pjz.68.2022.04.14.05.26.09; Thu, 14 Apr 2022 05:26:26 -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; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236019AbiDMSBu (ORCPT + 99 others); Wed, 13 Apr 2022 14:01:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56348 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232587AbiDMSBs (ORCPT ); Wed, 13 Apr 2022 14:01:48 -0400 Received: from mail-yw1-f169.google.com (mail-yw1-f169.google.com [209.85.128.169]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD4B813F75; Wed, 13 Apr 2022 10:59:25 -0700 (PDT) Received: by mail-yw1-f169.google.com with SMTP id 00721157ae682-2eba37104a2so31848017b3.0; Wed, 13 Apr 2022 10:59:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=XBIdc2r7ktDJVgL8jFR2huHb3Z5LWfWpJ3rv5dtCkOU=; b=X0EHu8AB3E7C2rMBd7nzhXHMjHG8IK1I9W9Nco1mhr8YXvkzSZHUUw+Or0xEfBAgDl FwKdjduWTZ6ctquCmxaBCx98ePOtwOtshxjqjsfUOP+Nb/CdzGty5JD+dFoZlyIV5m5z NbUmI0BDoh5p9Wv2yaF2XTj7JjtHstmpSxtwB7fQQCzcMh2ODKBTspmnSUh9nKSV8bWx X1eAvxxkabcO12rSOq2YDwn11bGVzYFa45zzsAtCDSZ1onF6YMPMBOk7qaTFXuIoff4M 34B9jwH0dCIUzv+96xOPvX9Hyr3VbHjdx13xWIia39r817OwVdzfP5A8vnr1W4vSaLN/ JWjQ== X-Gm-Message-State: AOAM531bDQul+hbe09WGBAgPLryhodG1tVQm/fYVJJNYK1d13W+kloKR NSyzPiJS7HvNnzEYerNYy6ckBdXb8+R6XO/OoSQ= X-Received: by 2002:a81:1b97:0:b0:2db:640f:49d8 with SMTP id b145-20020a811b97000000b002db640f49d8mr83773ywb.326.1649872765056; Wed, 13 Apr 2022 10:59:25 -0700 (PDT) MIME-Version: 1.0 References: <20220407105120.1280-1-lorenzo.pieralisi@arm.com> In-Reply-To: From: "Rafael J. Wysocki" Date: Wed, 13 Apr 2022 19:59:14 +0200 Message-ID: Subject: Re: [PATCH] ACPI: osl: Fix BERT error region memory mapping To: Ard Biesheuvel , Lorenzo Pieralisi Cc: Linux Kernel Mailing List , Will Deacon , Hanjun Guo , Sudeep Holla , Catalin Marinas , "Rafael J. Wysocki" , ACPI Devel Maling List , Linux ARM , Veronika kabatova , Robin Murphy , Aristeu Rozanski Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,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 On Wed, Apr 13, 2022 at 7:41 PM Ard Biesheuvel wrote: > > On Thu, 7 Apr 2022 at 12:51, Lorenzo Pieralisi > wrote: > > > > 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" > > Acked-by: Ard Biesheuvel Applied as 5.19 material, thanks! > > --- > > 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 > >