Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp3975244pxu; Mon, 12 Oct 2020 06:25:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzMfCiz/Om+UuF3TXBV2248AuT9jj+xir+SqybrPJ4PAsT0bU3L4VFiIebFI1r+aZ0RHdV2 X-Received: by 2002:a05:6402:709:: with SMTP id w9mr14117122edx.326.1602509158957; Mon, 12 Oct 2020 06:25:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602509158; cv=none; d=google.com; s=arc-20160816; b=yJ/IuUfuhhJplpOvZq6cYtrqc5Ce2GOz0VfEboGuyz5DI+WUbVJ8nGVTU9HIcV23SR Z37qDzITiUQAhpviE+oK7zpdy2l3sXzCc8jo2ctqDab4CArQFwgJICSi3iha3g9S1hGr I7ii04y1vd+BhT3AOZVFXqCGbNtCPe13xI7mJKSK/2lb0f9amqT0GsVDanWCJ8t/gXto zNHIJK1Zoq6zrRgL+pukciCp+3PD9tlFUgrmV7rhsi+sjOW5HUvYh0c8ifDkjvo8mmsL p0RNj3/1PHLCRbwLhG+guetSUhgaalxa0pDoqxwtAA/GaxAiLZHySzRKWgg6JbVqcSbx WfUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=RvlIrmP7pDfti7mpO1J7dVgqWMijPzb2nPlsVawRGOw=; b=nWP00PvWnQ2XAXALDNeiaQJL/R2uOc4ODaew4YUv0F4Wv1UI7wbCwEB3byYelz5Brh HmkCJgTKP1geUBUPISzbpf4aa6yYFEzVrxm5QTiTi6wgKJuDN2f06G97XI1ZAfpayMOf GXEymo0pXVbla2QrzZZ7sIWl0Dp3bg7jmktCOlVrzz6gqQm7Veefc0aEMfTsUdu12q+s ciaXddhM1oSaNrntRG0xSqps7Vtk08w6CZh213cX4RocUCO4IO5Jm4SxjPbefNVl9DIn NtqJb/l8eD+NQxfcrLnQype1JNFVBS2gKRRN7mHvUU1/sivSJJ53zC3zx6WFzyxYfQzV pnKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=T9JnB6yu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id a16si14825238ejk.665.2020.10.12.06.25.35; Mon, 12 Oct 2020 06:25:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=T9JnB6yu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1729925AbgJLMx6 (ORCPT + 99 others); Mon, 12 Oct 2020 08:53:58 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:36041 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725941AbgJLMx5 (ORCPT ); Mon, 12 Oct 2020 08:53:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602507236; 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=T9JnB6yu++9DISYdKtaTxFnFJFFJrsIEoLrR41nefWZ3CkMfJz6DFBuTHnvt9Y3bxXyjj4 YVJyAWSoZImiIMwXTMAYesqaKn077ZOcLIYbqnjd2kKHKE5AFLodk6kU21JSqDeooY9QKD 00vrdHe0CD1SZNM+cFDTgHl+L6zHIFk= 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 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 { /* 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(struct virtio_mem *vm) static int virtio_mem_mb_add(struct virtio_mem *vm, unsigned long mb_id) { const uint64_t addr = virtio_mem_mb_id_to_phys(mb_id); - int nid = vm->nid; - - if (nid == NUMA_NO_NODE) - nid = memory_add_physaddr_to_nid(addr); /* * 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, unsigned long mb_id) } 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 = virtio_mem_mb_id_to_phys(mb_id); - int nid = vm->nid; - - if (nid == NUMA_NO_NODE) - nid = memory_add_physaddr_to_nid(addr); 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()); } /* @@ -461,14 +454,11 @@ static int virtio_mem_mb_offline_and_remove(struct virtio_mem *vm, unsigned long mb_id) { const uint64_t addr = virtio_mem_mb_id_to_phys(mb_id); - int nid = vm->nid; - - if (nid == NUMA_NO_NODE) - nid = memory_add_physaddr_to_nid(addr); 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()); } /* @@ -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); + /* Determine the nid for the device based on the lowest address. */ + if (vm->nid == NUMA_NO_NODE) + vm->nid = 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 != NUMA_NO_NODE) + if (vm->nid != NUMA_NO_NODE && IS_ENABLED(CONFIG_NUMA)) dev_info(&vm->vdev->dev, "nid: %d", vm->nid); return 0; -- 2.26.2