From patchwork Fri Sep 22 17:09:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Reed X-Patchwork-Id: 1838383 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=185.125.189.65; helo=lists.ubuntu.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=patchwork.ozlabs.org) Received: from lists.ubuntu.com (lists.ubuntu.com [185.125.189.65]) (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 4Rsdzk2brRz1ynH for ; Sat, 23 Sep 2023 03:09:37 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1qjjeg-0005gf-Bc; Fri, 22 Sep 2023 17:09:26 +0000 Received: from smtp-relay-internal-0.internal ([10.131.114.225] helo=smtp-relay-internal-0.canonical.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1qjjea-0005fZ-Kv for kernel-team@lists.ubuntu.com; Fri, 22 Sep 2023 17:09:20 +0000 Received: from mail-oo1-f72.google.com (mail-oo1-f72.google.com [209.85.161.72]) (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 5092442187 for ; Fri, 22 Sep 2023 17:09:18 +0000 (UTC) Received: by mail-oo1-f72.google.com with SMTP id 006d021491bc7-57b7aba5002so1205349eaf.3 for ; Fri, 22 Sep 2023 10:09:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695402555; x=1696007355; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Fk6Z8uWecGKHfxPHzZIHSBqjviA1vcHsK6cFp5c95o4=; b=SsDaGSKiiRTEOZ/Gm+YwPI5XbEAm3q/V/Bj9+otvY+OGKphZclBENWo/iRoegj1l/a u8LrLt9kJkiF2U0x95MhrMUVxAxPs7tQZ4qtSj1o9PpDACo2xH0aoba9nxoHxtaVyFZF IgT4g2+W/OoD8evVBFR282U3w87+U6MKvIBw452iyjVHsMOymqeirnZo0sPu5ZvtXCaz kJtOYiag4kAN7bkXF4djMq8L6FqWp6oqcjf7PGZLGganuEgtVt7bovLEgmv5LKSy5fiC SBeq1PjmrmNOELIQ7DmbRbTtgFhhIoq/1zTWrvGMYgDH18XnZAsPgbxVI0toMBYhBoHU nuMg== X-Gm-Message-State: AOJu0YxUB0RhFGlRb1q3OvWgDxL4D2drEzTTR1XPdopXBlmsJMLnc1WX VGEfPz1axK9gWWclXSZ9V8mYWL0cFWeBweBpzL+KRv4EL0nCbMQQl3uIzLZhUNpWLMfg+zbUCk2 kkhrv7klJ/Zfs9Jirk5+LWZUx62tJFNHmvz2GEOLAbat/xlT4+g== X-Received: by 2002:a05:6870:2411:b0:1d5:a303:5f56 with SMTP id n17-20020a056870241100b001d5a3035f56mr95362oap.21.1695402555661; Fri, 22 Sep 2023 10:09:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEH2RpU1hZTHmZJGh1WwtwexMRo6a69olxzomROg0OCYb1VSk7CuqBzXD+v5ZPC57DBsYlQTQ== X-Received: by 2002:a05:6870:2411:b0:1d5:a303:5f56 with SMTP id n17-20020a056870241100b001d5a3035f56mr95341oap.21.1695402555356; Fri, 22 Sep 2023 10:09:15 -0700 (PDT) Received: from localhost ([2600:1700:1d0:5e50:10ea:d1bb:4a56:accb]) by smtp.gmail.com with ESMTPSA id g7-20020a056870a24700b001b3d67934e9sm1105617oai.26.2023.09.22.10.09.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 10:09:14 -0700 (PDT) From: Michael Reed To: kernel-team@lists.ubuntu.com Subject: [SRU J][PATCH 1/2] device-dax: Fix duplicate 'hmem' device registration Date: Fri, 22 Sep 2023 12:09:09 -0500 Message-Id: <20230922170910.12844-2-michael.reed@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230922170910.12844-1-michael.reed@canonical.com> References: <20230922170910.12844-1-michael.reed@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: Dan Williams BugLink: https://bugs.launchpad.net/bugs/2028158 So called "soft-reserved" memory is an EFI conventional memory range with the EFI_MEMORY_SP attribute set. That attribute indicates that the memory is not part of the platform general purpose memory pool and may want some consideration from the system administrator about whether to keep that memory set aside for dedicated access through device-dax (map a device file), or assigned to the page allocator as another general purpose memory node target. Absent an ACPI HMAT table the default device-dax registration creates coarse grained devices that are delineated by EFI Memory Map entries. With the HMAT the devices are delineated by the finer grained ranges associated with the proximity domain of the memory target. I.e. the HMAT describes the properties of performance differentiated memory and each unique performance description results in a unique target proximity domain where each memory proximity domain has an associated SRAT entry that delineates the address range. The intent was that SRAT-defined device-dax instances are registered first. Then any left-over address range with the EFI_MEMORY_SP attribute, but not covered by the SRAT, would have a coarse grained device-dax instance established. However, the scheme to detect what ranges are left to be assigned to a device was buggy and resulted in multiple overlapping device-dax instances. Fix this by using explicit tracking for which ranges have been handled. Now, this new approach may leave memory stranded in the presence of broken platform firmware that fails to fully describe all EFI_MEMORY_SP ranges in the HMAT. That requires a deeper fix if it becomes a problem in practice. Reported-by: "Tallam Mahendra Kumar" Reported-by: Mustafa Hajeer Debugged-by: Vishal Verma Tested-by: Vishal Verma Link: https://lore.kernel.org/r/166890823379.4183293.15333502171004313377.stgit@dwillia2-xfh.jf.intel.com Signed-off-by: Dan Williams (backported from commit 472faf72b33d80aa8e7a99c9410c1a23d3bf0cd8) [Michael Reed - Simple adjustment for location of patch] Signed-off-by: Michael Reed --- drivers/dax/hmem/device.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/drivers/dax/hmem/device.c b/drivers/dax/hmem/device.c index acf31cc1dbcc..d0f897c7f52a 100644 --- a/drivers/dax/hmem/device.c +++ b/drivers/dax/hmem/device.c @@ -8,6 +8,13 @@ static bool nohmem; module_param_named(disable, nohmem, bool, 0444); +static struct resource hmem_active = { + .name = "HMEM devices", + .start = 0, + .end = -1, + .flags = IORESOURCE_MEM, +}; + void hmem_register_device(int target_nid, struct resource *r) { /* define a clean / non-busy resource for the platform device */ @@ -41,6 +48,12 @@ void hmem_register_device(int target_nid, struct resource *r) goto out_pdev; } + if (!__request_region(&hmem_active, res.start, resource_size(&res), + dev_name(&pdev->dev), 0)) { + dev_dbg(&pdev->dev, "hmem range %pr already active\n", &res); + goto out_active; + } + pdev->dev.numa_node = numa_map_to_online_node(target_nid); info = (struct memregion_info) { .target_node = target_nid, @@ -66,22 +79,15 @@ void hmem_register_device(int target_nid, struct resource *r) return; out_resource: - put_device(&pdev->dev); + __release_region(&hmem_active, res.start, resource_size(&res)); +out_active: + platform_device_put(pdev); out_pdev: memregion_free(id); } static __init int hmem_register_one(struct resource *res, void *data) { - /* - * If the resource is not a top-level resource it was already - * assigned to a device by the HMAT parsing. - */ - if (res->parent != &iomem_resource) { - pr_info("HMEM: skip %pr, already claimed\n", res); - return 0; - } - hmem_register_device(phys_to_target_node(res->start), res); return 0;