From patchwork Wed Jul 12 18:01:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tim Gardner X-Patchwork-Id: 1806921 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=JZur0+BZ; dkim-atps=neutral Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4R1QYW2Xt3z20cD for ; Thu, 13 Jul 2023 04:02:07 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1qJeA5-0001mc-3v; Wed, 12 Jul 2023 18:02:01 +0000 Received: from smtp-relay-internal-0.internal ([10.131.114.225] helo=smtp-relay-internal-0.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1qJe9z-0001gq-RI for kernel-team@lists.ubuntu.com; Wed, 12 Jul 2023 18:01:55 +0000 Received: from mail-pl1-f199.google.com (mail-pl1-f199.google.com [209.85.214.199]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 6B5283F438 for ; Wed, 12 Jul 2023 18:01:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1689184915; bh=gq0+zwBcVlMSUdEk041qtKMPL4n8+YyjDGmEm2NfmFU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=JZur0+BZiVvq5HHqrveTA4VTY6VgEBQyFlKXH3osysZrL1wmcFSeQuznQwDOpF7oR AiXhq+k1Vb9Ih0KPo/X1NlTdfrciO4WWVm4nN1ZiAPyh5seMsHxir0lZJr5PuDDwim f0NagEVVbgclqFX/2eP9CcSRSjIpjP35IiwoTPR6VdiguwHJkQrg7xUUVmtmgkipR7 H17/eeMIgB0E+Rh6QtGsm2Y6Dk74Q4jxOADz9p6o9o0p7PV7qlpFuemRDeLjT17yf3 xyok/ZcMJbjAWCDtmgTWjsfEHe1RT5R4+ugPcLTNH7da6HTAdAtgPkittseGTXSwhF mk9X1kerC9Mug== Received: by mail-pl1-f199.google.com with SMTP id d9443c01a7336-1b895fa8929so73905245ad.0 for ; Wed, 12 Jul 2023 11:01:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689184913; x=1691776913; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gq0+zwBcVlMSUdEk041qtKMPL4n8+YyjDGmEm2NfmFU=; b=MiCjmaVX6fwDNZG4grlz1jAEUJVSf+CLIPqVREUR3lex6lLuOCtGw/fWJa+cMrPNo5 2tm28qnlvE/3upX+THad4/25TExG3ICnwZd3UeU1OvaePUCNl2CYnJzxoO/p6q1ntnZ2 b39lUm979+/4bD28B73M0faZgwZVpJDiG2QcGoYrJSap+j4Bf4lfQW+mEgGFE4Ukv0T0 YhLYxfxzkYOinIU2Csx5HYvz7eaiOYz2GU+SX/M++VtGorYya8ozQ2QH8STXLd8Y3xX3 xMdpRCKqLA2MRoXiaOmIo1+yLGJFqypAuGULyNkb2zliWRwwoCcQBqsuKC1pZN8+3ihM mdEQ== X-Gm-Message-State: ABy/qLbeMT6I0UMvr9QHLOrfCOJxtIHAm8XCf21eUcrNwZExTvjf2Pf2 f15O9e/yqzvJONv45qGUEvJ4PPsALIORmELDIoGIIG9/NtA3DKOo0HTFwSR65vVx0yviJBm/78J JnAiepu1adHvlxz6NvexUXcRadWHUaNvfRS0rTqXuKbYIzBWcLQ== X-Received: by 2002:a17:902:c20c:b0:1b5:1787:d23f with SMTP id 12-20020a170902c20c00b001b51787d23fmr14610331pll.5.1689184913695; Wed, 12 Jul 2023 11:01:53 -0700 (PDT) X-Google-Smtp-Source: APBJJlFeJIbEUF3tXaAkxlHoijYYuC7oer+GZqK6n+QFfQc3H6+GPV9wuzCLEvEHx+k3fYO79aO4MA== X-Received: by 2002:a17:902:c20c:b0:1b5:1787:d23f with SMTP id 12-20020a170902c20c00b001b51787d23fmr14610316pll.5.1689184913386; Wed, 12 Jul 2023 11:01:53 -0700 (PDT) Received: from smtp.gmail.com (174-045-099-030.res.spectrum.com. [174.45.99.30]) by smtp.gmail.com with ESMTPSA id n19-20020a170902969300b001b0358848b0sm4276551plp.161.2023.07.12.11.01.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jul 2023 11:01:52 -0700 (PDT) From: Tim Gardner To: kernel-team@lists.ubuntu.com Subject: [PATCH 6/6] swiotlb: relocate PageHighMem test away from rmem_swiotlb_setup Date: Wed, 12 Jul 2023 12:01:41 -0600 Message-Id: <20230712180141.713006-7-tim.gardner@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230712180141.713006-1-tim.gardner@canonical.com> References: <20230712180141.713006-1-tim.gardner@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Doug Berger BugLink: https://bugs.launchpad.net/bugs/2026736 The reservedmem_of_init_fn's are invoked very early at boot before the memory zones have even been defined. This makes it inappropriate to test whether the page corresponding to a PFN is in ZONE_HIGHMEM from within one. Removing the check allows an ARM 32-bit kernel with SPARSEMEM enabled to boot properly since otherwise we would be de-referencing an uninitialized sparsemem map to perform pfn_to_page() check. The arm64 architecture happens to work (and also has no high memory) but other 32-bit architectures could also be having similar issues. While it would be nice to provide early feedback about a reserved DMA pool residing in highmem, it is not possible to do that until the first time we try to use it, which is where the check is moved to. Fixes: 0b84e4f8b793 ("swiotlb: Add restricted DMA pool initialization") Signed-off-by: Doug Berger Signed-off-by: Florian Fainelli Signed-off-by: Christoph Hellwig (cherry picked from commit a90922fa25370902322e9de6640e58737d459a50) Signed-off-by: Tim Gardner --- kernel/dma/swiotlb.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c index 2048709cd733..6de2a907aa5f 100644 --- a/kernel/dma/swiotlb.c +++ b/kernel/dma/swiotlb.c @@ -958,6 +958,11 @@ static int rmem_swiotlb_device_init(struct reserved_mem *rmem, /* Set Per-device io tlb area to one */ unsigned int nareas = 1; + if (PageHighMem(pfn_to_page(PHYS_PFN(rmem->base)))) { + dev_err(dev, "Restricted DMA pool must be accessible within the linear mapping."); + return -EINVAL; + } + /* * Since multiple devices can share the same pool, the private data, * io_tlb_mem struct, will be initialized by the first device attached @@ -1019,11 +1024,6 @@ static int __init rmem_swiotlb_setup(struct reserved_mem *rmem) of_get_flat_dt_prop(node, "no-map", NULL)) return -EINVAL; - if (PageHighMem(pfn_to_page(PHYS_PFN(rmem->base)))) { - pr_err("Restricted DMA pool must be accessible within the linear mapping."); - return -EINVAL; - } - rmem->ops = &rmem_swiotlb_ops; pr_info("Reserved memory: created restricted DMA pool at %pa, size %ld MiB\n", &rmem->base, (unsigned long)rmem->size / SZ_1M);