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=-9.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS autolearn=ham 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 6AF12C4363A for ; Mon, 12 Oct 2020 12:54:01 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id F1E3E21BE5 for ; Mon, 12 Oct 2020 12:54:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="SX0NkIAV" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F1E3E21BE5 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 6C84A940008; Mon, 12 Oct 2020 08:54:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 67748900002; Mon, 12 Oct 2020 08:54:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 58C6E940008; Mon, 12 Oct 2020 08:54:00 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0054.hostedemail.com [216.40.44.54]) by kanga.kvack.org (Postfix) with ESMTP id 2DE81900002 for ; Mon, 12 Oct 2020 08:54:00 -0400 (EDT) Received: from smtpin03.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id BBDAB3623 for ; Mon, 12 Oct 2020 12:53:59 +0000 (UTC) X-FDA: 77363265798.03.walk41_5006b0f271fa Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin03.hostedemail.com (Postfix) with ESMTP id 968BA28A4E8 for ; Mon, 12 Oct 2020 12:53:59 +0000 (UTC) X-HE-Tag: walk41_5006b0f271fa X-Filterd-Recvd-Size: 5955 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by imf08.hostedemail.com (Postfix) with ESMTP for ; Mon, 12 Oct 2020 12:53:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602507238; 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=RvlIrmP7pDfti7mpO1J7dVgqWMijPzb2nPlsVawRGOw=; b=SX0NkIAVF1PZnR0iHoiRI9IiJwwsHmWgn/y196PAFoEFnDITiiYmwDIHfyu1jTFe6scYbp Zap6mVSMxw+ncwqXYdwfe5ud9kOv4A0KpxNQ0x2B7aS0FmZ/rHzIdzNGDvE4Nmmfjy37un mpRCzfGJeE8ZgpNP7M4raAHVTcbfsG4= 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-144-eBDLZPd9Nq2ptRftjy7E_g-1; Mon, 12 Oct 2020 08:53:54 -0400 X-MC-Unique: eBDLZPd9Nq2ptRftjy7E_g-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2F9281017DC1; Mon, 12 Oct 2020 12:53:53 +0000 (UTC) Received: from t480s.redhat.com (ovpn-113-251.ams2.redhat.com [10.36.113.251]) by smtp.corp.redhat.com (Postfix) with ESMTP id DABB960C07; Mon, 12 Oct 2020 12:53:48 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, virtualization@lists.linux-foundation.org, Andrew Morton , "Michael S . Tsirkin" , David Hildenbrand , Jason Wang , Pankaj Gupta Subject: [PATCH v1 01/29] virtio-mem: determine nid only once using memory_add_physaddr_to_nid() Date: Mon, 12 Oct 2020 14:52:55 +0200 Message-Id: <20201012125323.17509-2-david@redhat.com> In-Reply-To: <20201012125323.17509-1-david@redhat.com> References: <20201012125323.17509-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Let's determine the target nid only once in case we have none specified - usually, we'll end up with node 0 either way. Cc: "Michael S. Tsirkin" Cc: Jason Wang Cc: Pankaj Gupta Signed-off-by: David Hildenbrand --- drivers/virtio/virtio_mem.c | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/drivers/virtio/virtio_mem.c b/drivers/virtio/virtio_mem.c index ba4de598f663..a1f5bf7a571a 100644 --- a/drivers/virtio/virtio_mem.c +++ b/drivers/virtio/virtio_mem.c @@ -70,7 +70,7 @@ struct virtio_mem { =20 /* The device block size (for communicating with the device). */ uint64_t device_block_size; - /* The translated node id. NUMA_NO_NODE in case not specified. */ + /* The determined node id for all memory of the device. */ int nid; /* Physical start address of the memory region. */ uint64_t addr; @@ -406,10 +406,6 @@ 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 vm->nid; - - if (nid =3D=3D NUMA_NO_NODE) - nid =3D memory_add_physaddr_to_nid(addr); =20 /* * When force-unloading the driver and we still have memory added to @@ -423,7 +419,8 @@ static int virtio_mem_mb_add(struct virtio_mem *vm, u= nsigned long mb_id) } =20 dev_dbg(&vm->vdev->dev, "adding memory block: %lu\n", mb_id); - return add_memory_driver_managed(nid, addr, memory_block_size_bytes(), + return add_memory_driver_managed(vm->nid, addr, + memory_block_size_bytes(), vm->resource_name, MEMHP_MERGE_RESOURCE); } @@ -440,13 +437,9 @@ 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 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()); + return remove_memory(vm->nid, addr, memory_block_size_bytes()); } =20 /* @@ -461,14 +454,11 @@ static int virtio_mem_mb_offline_and_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 vm->nid; - - if (nid =3D=3D NUMA_NO_NODE) - nid =3D memory_add_physaddr_to_nid(addr); =20 dev_dbg(&vm->vdev->dev, "offlining and removing memory block: %lu\n", mb_id); - return offline_and_remove_memory(nid, addr, memory_block_size_bytes()); + return offline_and_remove_memory(vm->nid, addr, + memory_block_size_bytes()); } =20 /* @@ -1659,6 +1649,10 @@ static int virtio_mem_init(struct virtio_mem *vm) virtio_cread_le(vm->vdev, struct virtio_mem_config, region_size, &vm->region_size); =20 + /* Determine the nid for the device based on the lowest address. */ + if (vm->nid =3D=3D NUMA_NO_NODE) + vm->nid =3D memory_add_physaddr_to_nid(vm->addr); + /* * We always hotplug memory in memory block granularity. This way, * we have to wait for exactly one memory block to online. @@ -1707,7 +1701,7 @@ static int virtio_mem_init(struct virtio_mem *vm) memory_block_size_bytes()); dev_info(&vm->vdev->dev, "subblock size: 0x%llx", (unsigned long long)vm->subblock_size); - if (vm->nid !=3D NUMA_NO_NODE) + if (vm->nid !=3D NUMA_NO_NODE && IS_ENABLED(CONFIG_NUMA)) dev_info(&vm->vdev->dev, "nid: %d", vm->nid); =20 return 0; --=20 2.26.2