From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A7868C54E4A for ; Thu, 7 May 2020 10:33:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 88083207DD for ; Thu, 7 May 2020 10:33:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="CLfFWkjP" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726519AbgEGKcX (ORCPT ); Thu, 7 May 2020 06:32:23 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:38538 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725809AbgEGKcU (ORCPT ); Thu, 7 May 2020 06:32:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1588847538; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rWXWkv8vN9fjpn9UiZGTDZqowsNGIfPpltO1Iw80T6Y=; b=CLfFWkjPgRDzOOF7afMUaG6mR1FB+Duj27Bvm1UNbW2lC1JqLAnefuvX8qj+yWpTcRVsCj ErTs149j0MF3CQyYPjbIoMDighFNzhfbvebpzQ00P8ihhRIgaYmVorRGFl3N176uP3LwvH RFSJmDk0NUsJLWMZyPQogvt6rsWAH9s= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-424-V5a1ZtF1MwmggBgERMnwKw-1; Thu, 07 May 2020 06:32:14 -0400 X-MC-Unique: V5a1ZtF1MwmggBgERMnwKw-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 79C7F19200C1; Thu, 7 May 2020 10:32:12 +0000 (UTC) Received: from t480s.redhat.com (ovpn-113-245.ams2.redhat.com [10.36.113.245]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8A2155D9C5; Thu, 7 May 2020 10:32:05 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, virtio-dev@lists.oasis-open.org, virtualization@lists.linux-foundation.org, kvm@vger.kernel.org, Michal Hocko , Andrew Morton , "Michael S . Tsirkin" , David Hildenbrand , Michal Hocko , "Rafael J. Wysocki" , Pankaj Gupta , Jason Wang , Oscar Salvador , Igor Mammedov , Dave Young , Dan Williams , Pavel Tatashin , Stefan Hajnoczi , Vlastimil Babka , Len Brown , linux-acpi@vger.kernel.org Subject: [PATCH v3 02/15] virtio-mem: Allow to specify an ACPI PXM as nid Date: Thu, 7 May 2020 12:31:06 +0200 Message-Id: <20200507103119.11219-3-david@redhat.com> In-Reply-To: <20200507103119.11219-1-david@redhat.com> References: <20200507103119.11219-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Content-Transfer-Encoding: quoted-printable Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org We want to allow to specify (similar as for a DIMM), to which node a virtio-mem device (and, therefore, its memory) belongs. Add a new virtio-mem feature flag and export pxm_to_node, so it can be used in kern= el module context. Acked-by: Michal Hocko # for the export Acked-by: "Rafael J. Wysocki" # for the export Acked-by: Pankaj Gupta Tested-by: Pankaj Gupta Cc: "Michael S. Tsirkin" Cc: Jason Wang Cc: Oscar Salvador Cc: Michal Hocko Cc: Igor Mammedov Cc: Dave Young Cc: Andrew Morton Cc: Dan Williams Cc: Pavel Tatashin Cc: Stefan Hajnoczi Cc: Vlastimil Babka Cc: Len Brown Cc: linux-acpi@vger.kernel.org Signed-off-by: David Hildenbrand --- drivers/acpi/numa/srat.c | 1 + drivers/virtio/virtio_mem.c | 39 +++++++++++++++++++++++++++++++-- include/uapi/linux/virtio_mem.h | 10 ++++++++- 3 files changed, 47 insertions(+), 3 deletions(-) diff --git a/drivers/acpi/numa/srat.c b/drivers/acpi/numa/srat.c index 47b4969d9b93..5be5a977da1b 100644 --- a/drivers/acpi/numa/srat.c +++ b/drivers/acpi/numa/srat.c @@ -35,6 +35,7 @@ int pxm_to_node(int pxm) return NUMA_NO_NODE; return pxm_to_node_map[pxm]; } +EXPORT_SYMBOL(pxm_to_node); =20 int node_to_pxm(int node) { diff --git a/drivers/virtio/virtio_mem.c b/drivers/virtio/virtio_mem.c index 5d1dcaa6fc42..270ddeaec059 100644 --- a/drivers/virtio/virtio_mem.c +++ b/drivers/virtio/virtio_mem.c @@ -21,6 +21,8 @@ #include #include =20 +#include + enum virtio_mem_mb_state { /* Unplugged, not added to Linux. Can be reused later. */ VIRTIO_MEM_MB_STATE_UNUSED =3D 0, @@ -72,6 +74,8 @@ struct virtio_mem { =20 /* The device block size (for communicating with the device). */ uint32_t device_block_size; + /* The translated node id. NUMA_NO_NODE in case not specified. */ + int nid; /* Physical start address of the memory region. */ uint64_t addr; /* Maximum region size in bytes. */ @@ -389,7 +393,10 @@ static int virtio_mem_sb_bitmap_prepare_next_mb(stru= ct virtio_mem *vm) static int virtio_mem_mb_add(struct virtio_mem *vm, unsigned long mb_id) { const uint64_t addr =3D virtio_mem_mb_id_to_phys(mb_id); - int nid =3D memory_add_physaddr_to_nid(addr); + int nid =3D vm->nid; + + if (nid =3D=3D NUMA_NO_NODE) + nid =3D memory_add_physaddr_to_nid(addr); =20 dev_dbg(&vm->vdev->dev, "adding memory block: %lu\n", mb_id); return add_memory(nid, addr, memory_block_size_bytes()); @@ -407,7 +414,10 @@ static int virtio_mem_mb_add(struct virtio_mem *vm, = unsigned long mb_id) static int virtio_mem_mb_remove(struct virtio_mem *vm, unsigned long mb_= id) { const uint64_t addr =3D virtio_mem_mb_id_to_phys(mb_id); - int nid =3D memory_add_physaddr_to_nid(addr); + int nid =3D vm->nid; + + if (nid =3D=3D NUMA_NO_NODE) + nid =3D memory_add_physaddr_to_nid(addr); =20 dev_dbg(&vm->vdev->dev, "removing memory block: %lu\n", mb_id); return remove_memory(nid, addr, memory_block_size_bytes()); @@ -426,6 +436,17 @@ static void virtio_mem_retry(struct virtio_mem *vm) spin_unlock_irqrestore(&vm->removal_lock, flags); } =20 +static int virtio_mem_translate_node_id(struct virtio_mem *vm, uint16_t = node_id) +{ + int node =3D NUMA_NO_NODE; + +#if defined(CONFIG_ACPI_NUMA) + if (virtio_has_feature(vm->vdev, VIRTIO_MEM_F_ACPI_PXM)) + node =3D pxm_to_node(node_id); +#endif + return node; +} + /* * Test if a virtio-mem device overlaps with the given range. Can be cal= led * from (notifier) callbacks lockless. @@ -1267,6 +1288,7 @@ static bool virtio_mem_any_memory_present(unsigned = long start, static int virtio_mem_init(struct virtio_mem *vm) { const uint64_t phys_limit =3D 1UL << MAX_PHYSMEM_BITS; + uint16_t node_id; =20 if (!vm->vdev->config->get) { dev_err(&vm->vdev->dev, "config access disabled\n"); @@ -1287,6 +1309,9 @@ static int virtio_mem_init(struct virtio_mem *vm) &vm->plugged_size); virtio_cread(vm->vdev, struct virtio_mem_config, block_size, &vm->device_block_size); + virtio_cread(vm->vdev, struct virtio_mem_config, node_id, + &node_id); + vm->nid =3D virtio_mem_translate_node_id(vm, node_id); virtio_cread(vm->vdev, struct virtio_mem_config, addr, &vm->addr); virtio_cread(vm->vdev, struct virtio_mem_config, region_size, &vm->region_size); @@ -1365,6 +1390,8 @@ static int virtio_mem_init(struct virtio_mem *vm) memory_block_size_bytes()); dev_info(&vm->vdev->dev, "subblock size: 0x%x", vm->subblock_size); + if (vm->nid !=3D NUMA_NO_NODE) + dev_info(&vm->vdev->dev, "nid: %d", vm->nid); =20 return 0; } @@ -1508,12 +1535,20 @@ static int virtio_mem_restore(struct virtio_devic= e *vdev) } #endif =20 +static unsigned int virtio_mem_features[] =3D { +#if defined(CONFIG_NUMA) && defined(CONFIG_ACPI_NUMA) + VIRTIO_MEM_F_ACPI_PXM, +#endif +}; + static struct virtio_device_id virtio_mem_id_table[] =3D { { VIRTIO_ID_MEM, VIRTIO_DEV_ANY_ID }, { 0 }, }; =20 static struct virtio_driver virtio_mem_driver =3D { + .feature_table =3D virtio_mem_features, + .feature_table_size =3D ARRAY_SIZE(virtio_mem_features), .driver.name =3D KBUILD_MODNAME, .driver.owner =3D THIS_MODULE, .id_table =3D virtio_mem_id_table, diff --git a/include/uapi/linux/virtio_mem.h b/include/uapi/linux/virtio_= mem.h index 1bfade78bdfd..e0a9dc7397c3 100644 --- a/include/uapi/linux/virtio_mem.h +++ b/include/uapi/linux/virtio_mem.h @@ -83,6 +83,12 @@ * device is busy. */ =20 +/* --- virtio-mem: feature bits --- */ + +/* node_id is an ACPI PXM and is valid */ +#define VIRTIO_MEM_F_ACPI_PXM 0 + + /* --- virtio-mem: guest -> host requests --- */ =20 /* request to plug memory blocks */ @@ -177,7 +183,9 @@ struct virtio_mem_resp { struct virtio_mem_config { /* Block size and alignment. Cannot change. */ __u32 block_size; - __u32 padding; + /* Valid with VIRTIO_MEM_F_ACPI_PXM. Cannot change. */ + __u16 node_id; + __u16 padding; /* Start address of the memory region. Cannot change. */ __u64 addr; /* Region size (maximum). Cannot change. */ --=20 2.25.3 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: virtio-dev-return-7240-cohuck=redhat.com@lists.oasis-open.org Sender: List-Post: List-Help: List-Unsubscribe: List-Subscribe: Received: from lists.oasis-open.org (oasis-open.org [10.110.1.242]) by lists.oasis-open.org (Postfix) with ESMTP id 16410985E10 for ; Thu, 7 May 2020 10:32:18 +0000 (UTC) From: David Hildenbrand Date: Thu, 7 May 2020 12:31:06 +0200 Message-Id: <20200507103119.11219-3-david@redhat.com> In-Reply-To: <20200507103119.11219-1-david@redhat.com> References: <20200507103119.11219-1-david@redhat.com> MIME-Version: 1.0 Subject: [virtio-dev] [PATCH v3 02/15] virtio-mem: Allow to specify an ACPI PXM as nid Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, virtio-dev@lists.oasis-open.org, virtualization@lists.linux-foundation.org, kvm@vger.kernel.org, Michal Hocko , Andrew Morton , "Michael S . Tsirkin" , David Hildenbrand , Michal Hocko , "Rafael J. Wysocki" , Pankaj Gupta , Jason Wang , Oscar Salvador , Igor Mammedov , Dave Young , Dan Williams , Pavel Tatashin , Stefan Hajnoczi , Vlastimil Babka , Len Brown , linux-acpi@vger.kernel.org List-ID: We want to allow to specify (similar as for a DIMM), to which node a virtio-mem device (and, therefore, its memory) belongs. Add a new virtio-mem feature flag and export pxm_to_node, so it can be used in kernel module context. Acked-by: Michal Hocko # for the export Acked-by: "Rafael J. Wysocki" # for the export Acked-by: Pankaj Gupta Tested-by: Pankaj Gupta Cc: "Michael S. Tsirkin" Cc: Jason Wang Cc: Oscar Salvador Cc: Michal Hocko Cc: Igor Mammedov Cc: Dave Young Cc: Andrew Morton Cc: Dan Williams Cc: Pavel Tatashin Cc: Stefan Hajnoczi Cc: Vlastimil Babka Cc: Len Brown Cc: linux-acpi@vger.kernel.org Signed-off-by: David Hildenbrand --- drivers/acpi/numa/srat.c | 1 + drivers/virtio/virtio_mem.c | 39 +++++++++++++++++++++++++++++++-- include/uapi/linux/virtio_mem.h | 10 ++++++++- 3 files changed, 47 insertions(+), 3 deletions(-) diff --git a/drivers/acpi/numa/srat.c b/drivers/acpi/numa/srat.c index 47b4969d9b93..5be5a977da1b 100644 --- a/drivers/acpi/numa/srat.c +++ b/drivers/acpi/numa/srat.c @@ -35,6 +35,7 @@ int pxm_to_node(int pxm) =09=09return NUMA_NO_NODE; =09return pxm_to_node_map[pxm]; } +EXPORT_SYMBOL(pxm_to_node); =20 int node_to_pxm(int node) { diff --git a/drivers/virtio/virtio_mem.c b/drivers/virtio/virtio_mem.c index 5d1dcaa6fc42..270ddeaec059 100644 --- a/drivers/virtio/virtio_mem.c +++ b/drivers/virtio/virtio_mem.c @@ -21,6 +21,8 @@ #include #include =20 +#include + enum virtio_mem_mb_state { =09/* Unplugged, not added to Linux. Can be reused later. */ =09VIRTIO_MEM_MB_STATE_UNUSED =3D 0, @@ -72,6 +74,8 @@ struct virtio_mem { =20 =09/* The device block size (for communicating with the device). */ =09uint32_t device_block_size; +=09/* The translated node id. NUMA_NO_NODE in case not specified. */ +=09int nid; =09/* Physical start address of the memory region. */ =09uint64_t addr; =09/* Maximum region size in bytes. */ @@ -389,7 +393,10 @@ static int virtio_mem_sb_bitmap_prepare_next_mb(struct= virtio_mem *vm) static int virtio_mem_mb_add(struct virtio_mem *vm, unsigned long mb_id) { =09const uint64_t addr =3D virtio_mem_mb_id_to_phys(mb_id); -=09int nid =3D memory_add_physaddr_to_nid(addr); +=09int nid =3D vm->nid; + +=09if (nid =3D=3D NUMA_NO_NODE) +=09=09nid =3D memory_add_physaddr_to_nid(addr); =20 =09dev_dbg(&vm->vdev->dev, "adding memory block: %lu\n", mb_id); =09return add_memory(nid, addr, memory_block_size_bytes()); @@ -407,7 +414,10 @@ static int virtio_mem_mb_add(struct virtio_mem *vm, un= signed long mb_id) static int virtio_mem_mb_remove(struct virtio_mem *vm, unsigned long mb_id= ) { =09const uint64_t addr =3D virtio_mem_mb_id_to_phys(mb_id); -=09int nid =3D memory_add_physaddr_to_nid(addr); +=09int nid =3D vm->nid; + +=09if (nid =3D=3D NUMA_NO_NODE) +=09=09nid =3D memory_add_physaddr_to_nid(addr); =20 =09dev_dbg(&vm->vdev->dev, "removing memory block: %lu\n", mb_id); =09return remove_memory(nid, addr, memory_block_size_bytes()); @@ -426,6 +436,17 @@ static void virtio_mem_retry(struct virtio_mem *vm) =09spin_unlock_irqrestore(&vm->removal_lock, flags); } =20 +static int virtio_mem_translate_node_id(struct virtio_mem *vm, uint16_t no= de_id) +{ +=09int node =3D NUMA_NO_NODE; + +#if defined(CONFIG_ACPI_NUMA) +=09if (virtio_has_feature(vm->vdev, VIRTIO_MEM_F_ACPI_PXM)) +=09=09node =3D pxm_to_node(node_id); +#endif +=09return node; +} + /* * Test if a virtio-mem device overlaps with the given range. Can be calle= d * from (notifier) callbacks lockless. @@ -1267,6 +1288,7 @@ static bool virtio_mem_any_memory_present(unsigned lo= ng start, static int virtio_mem_init(struct virtio_mem *vm) { =09const uint64_t phys_limit =3D 1UL << MAX_PHYSMEM_BITS; +=09uint16_t node_id; =20 =09if (!vm->vdev->config->get) { =09=09dev_err(&vm->vdev->dev, "config access disabled\n"); @@ -1287,6 +1309,9 @@ static int virtio_mem_init(struct virtio_mem *vm) =09=09 &vm->plugged_size); =09virtio_cread(vm->vdev, struct virtio_mem_config, block_size, =09=09 &vm->device_block_size); +=09virtio_cread(vm->vdev, struct virtio_mem_config, node_id, +=09=09 &node_id); +=09vm->nid =3D virtio_mem_translate_node_id(vm, node_id); =09virtio_cread(vm->vdev, struct virtio_mem_config, addr, &vm->addr); =09virtio_cread(vm->vdev, struct virtio_mem_config, region_size, =09=09 &vm->region_size); @@ -1365,6 +1390,8 @@ static int virtio_mem_init(struct virtio_mem *vm) =09=09 memory_block_size_bytes()); =09dev_info(&vm->vdev->dev, "subblock size: 0x%x", =09=09 vm->subblock_size); +=09if (vm->nid !=3D NUMA_NO_NODE) +=09=09dev_info(&vm->vdev->dev, "nid: %d", vm->nid); =20 =09return 0; } @@ -1508,12 +1535,20 @@ static int virtio_mem_restore(struct virtio_device = *vdev) } #endif =20 +static unsigned int virtio_mem_features[] =3D { +#if defined(CONFIG_NUMA) && defined(CONFIG_ACPI_NUMA) +=09VIRTIO_MEM_F_ACPI_PXM, +#endif +}; + static struct virtio_device_id virtio_mem_id_table[] =3D { =09{ VIRTIO_ID_MEM, VIRTIO_DEV_ANY_ID }, =09{ 0 }, }; =20 static struct virtio_driver virtio_mem_driver =3D { +=09.feature_table =3D virtio_mem_features, +=09.feature_table_size =3D ARRAY_SIZE(virtio_mem_features), =09.driver.name =3D KBUILD_MODNAME, =09.driver.owner =3D THIS_MODULE, =09.id_table =3D virtio_mem_id_table, diff --git a/include/uapi/linux/virtio_mem.h b/include/uapi/linux/virtio_me= m.h index 1bfade78bdfd..e0a9dc7397c3 100644 --- a/include/uapi/linux/virtio_mem.h +++ b/include/uapi/linux/virtio_mem.h @@ -83,6 +83,12 @@ * device is busy. */ =20 +/* --- virtio-mem: feature bits --- */ + +/* node_id is an ACPI PXM and is valid */ +#define VIRTIO_MEM_F_ACPI_PXM=09=090 + + /* --- virtio-mem: guest -> host requests --- */ =20 /* request to plug memory blocks */ @@ -177,7 +183,9 @@ struct virtio_mem_resp { struct virtio_mem_config { =09/* Block size and alignment. Cannot change. */ =09__u32 block_size; -=09__u32 padding; +=09/* Valid with VIRTIO_MEM_F_ACPI_PXM. Cannot change. */ +=09__u16 node_id; +=09__u16 padding; =09/* Start address of the memory region. Cannot change. */ =09__u64 addr; =09/* Region size (maximum). Cannot change. */ --=20 2.25.3 --------------------------------------------------------------------- To unsubscribe, e-mail: virtio-dev-unsubscribe@lists.oasis-open.org For additional commands, e-mail: virtio-dev-help@lists.oasis-open.org