Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp763322ybh; Wed, 11 Mar 2020 10:17:39 -0700 (PDT) X-Google-Smtp-Source: ADFU+vvEJJ67kkn/frYzjfwduFGklMTEuacHFU5GbJ/9U/5b0n1ad2Sx0aDLMxLkquZMxH+DP6pr X-Received: by 2002:aca:ad93:: with SMTP id w141mr2796900oie.54.1583947059100; Wed, 11 Mar 2020 10:17:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1583947059; cv=none; d=google.com; s=arc-20160816; b=fqk2HrwGWreH/C0n9mdCv0lYZhNtFBgWfaYrlgJO7bkTF1WhD6z9tG6D9A/3/kxFH2 xR9GxEQnNO0tHD7DroVT8Ck3Tmn1ycZPhpJmmMvkU6RG1CTw4+RSe9Hp25B4RYlRhExg UZZt1ZLrU+8w7AptrDPCHTgE0i/d4YvEfcb3uEEQHOS0Zb29Lu7HScPazFbYLgGgfnCY qo5T8kek8R7CtZA2co8uArEq0c57j4XIRjuDDDGbTImG5yGcWFog4++I3IJsgxEQRHIj TtBou1cwT47XE/1PyRo3RxE2XF30vbnJkjxUufhdzeERLeyzMIgMz9bLd/YWOYfVJ5NR RwjQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=DoiGjgNcOxwqOQ4QGLK3eCJGLVC9kfOrCPPjHii9JB4=; b=ugAInCRbTtvh0Hu+WQE+vy6TuuWRNoA92wxvntliBXMTz+/zHeWz+Us/aQHHtTAptY qj7yYXCKuVutJuCHA73scToa/JHJ7m56SSLNQAZN3p94CtZmK+Q4YH4tLGNLSkl4pBR1 Wnrpm6DpfTBTqOmAtl+y6jcBskR8q/QC67pAjfG87WbsKbxYfEcAQPJfhbY+nW+5Gt+D pU8tXqU/4sjgWWnuOVswqiVM47+EnVS2XzuXleMA3fNVZKQb2bhM906nQCVozT/Zz3mf TNvOyXf6Uw+TyuRKIoFoBr2SYfHWhHMuahiZaRv115ZLUhjEmBPQJ2y1MSXvwbTrKaGQ /auw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=gTGls77R; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r71si1421019oie.265.2020.03.11.10.17.26; Wed, 11 Mar 2020 10:17:39 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=gTGls77R; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730471AbgCKRPn (ORCPT + 99 others); Wed, 11 Mar 2020 13:15:43 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:41087 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1730322AbgCKRPn (ORCPT ); Wed, 11 Mar 2020 13:15:43 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1583946942; 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=DoiGjgNcOxwqOQ4QGLK3eCJGLVC9kfOrCPPjHii9JB4=; b=gTGls77RkwmCQuQ2dHuKmIXcYrYVgwfpFO56kRiUYgrKqOzhQQebmZZgN4pdIsg1pw4Cc1 yBwoHg9GpMrE+wGe7zV21LuExfW8Rfc96sbt7WBynEdO/4yXEA9A09SHXnJmFCokZH/+gP t41iss99dhp9wbEIZLwCsT667yRB574= 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-373-PpHwPLyTPSGON5TanGJrtA-1; Wed, 11 Mar 2020 13:15:40 -0400 X-MC-Unique: PpHwPLyTPSGON5TanGJrtA-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4F51E107ACC9; Wed, 11 Mar 2020 17:15:38 +0000 (UTC) Received: from t480s.redhat.com (ovpn-116-132.ams2.redhat.com [10.36.116.132]) by smtp.corp.redhat.com (Postfix) with ESMTP id DD3EA91D9B; Wed, 11 Mar 2020 17:15:19 +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" , 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 v2 02/10] virtio-mem: Allow to specify an ACPI PXM as nid Date: Wed, 11 Mar 2020 18:14:14 +0100 Message-Id: <20200311171422.10484-3-david@redhat.com> In-Reply-To: <20200311171422.10484-1-david@redhat.com> References: <20200311171422.10484-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 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 | 37 +++++++++++++++++++++++++++++++-- include/uapi/linux/virtio_mem.h | 10 ++++++++- 3 files changed, 45 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 803e1426f80b..d8da656c9145 100644 --- a/drivers/virtio/virtio_mem.c +++ b/drivers/virtio/virtio_mem.c @@ -20,6 +20,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, @@ -71,6 +73,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; =20 @@ -386,7 +390,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()); @@ -404,7 +411,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()); @@ -423,6 +433,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. @@ -1266,6 +1287,7 @@ static int virtio_mem_init(struct virtio_mem *vm) { const uint64_t phys_limit =3D 1UL << MAX_PHYSMEM_BITS; uint64_t region_size; + uint16_t node_id; =20 if (!vm->vdev->config->get) { dev_err(&vm->vdev->dev, "config access disabled\n"); @@ -1286,6 +1308,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, ®ion_size); @@ -1501,12 +1526,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.24.1