Received: by 2002:ab2:60d1:0:b0:1f7:5705:b850 with SMTP id i17csp956312lqm; Thu, 2 May 2024 00:17:22 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUiR88ArMvwkQQkT9yr00GajQOIXJgJp7tK5RiosRWEkc0FPzsztXKkltrSS0Eb4wjQrZTLYOQMEynjdA1ikLmkYpwasZn5QP33BUGSkA== X-Google-Smtp-Source: AGHT+IGuH1g6n0VTpjXn3AICuj7RWXdbmYy254NkvqQnLd8ivPenR8rPtXEoyyEKKBj3ujVUZFZO X-Received: by 2002:a05:6359:5f93:b0:186:7ed:3ad6 with SMTP id lh19-20020a0563595f9300b0018607ed3ad6mr6198042rwc.5.1714634242092; Thu, 02 May 2024 00:17:22 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714634242; cv=pass; d=google.com; s=arc-20160816; b=bueZqltG1vczOn9t8Mi/gMVXh2vIu/jLFPaSCEwlljU3HuNVyuMO5cVEFY9inOJrGB qMJp9xSFfeZe2mhRNCMwH1+UtZ92i4QT7NhHTe/pOxFC6lJ7/f3nNVqskiybqqDnHBSp nO19GoGnsWAncJdr0+ssl3KhmnuQFQ8mruBv0qXe44JG+0O7UQQCxZpY8YFLy4a0Tb50 oR4FYZKDBomYgW3+NguQYP9L2xRx96Q1NlQ00fiXZ7qD0kDkHMEDSVFaBK0HrKvFlV1Y JzkBvKQ37P+49D/epvBFpeYEZ1MDBHXcnZQu5uznYvI4Q9WYKmUfK18ZaadHCkwcyBeO iMWg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:organization:autocrypt:from :content-language:references:to:subject:user-agent:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:date:message-id :dkim-signature; bh=OIDhyH20/Kg5nJwECZysNFVnVnJydF4EiDXJ0DvvH0A=; fh=8u5JGBzKLUnJac67SWefqN09YMqSsAUmXLMR7BBpZZs=; b=RfiLUw8yRqtuo10zFTkBSnTpzM8BQvmU23qGg3V3CYeeFXGlXOHfiQf87bkrE5fqOw 8eRu4g6t/bjB29co4h1pg2OZLs7ifHl9RgQj0RbX9bUYSc0hF8Zb8x20BlMMDg2c4I29 2TEiayPdJ3aHOgqyKm9APx++YBWYeWp9QhPW9a7yR9nt7E4mD0iGauMvze8RwMA2qSln k2A+ZanC7adQR7REwyv2ebupcCZtUWch8ti+knk7JC6hPAT88Hhj18baa0y8G+uHJ7Vc RxUbFuKZkQP96eaqPkUXm1ASwNC9u16hMjZK4HFj8d7OiGD/z1zlf9DkDGZ9wP2YjZyr tafA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="fRR2/yJX"; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-166040-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-166040-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id w19-20020a639353000000b005d8c50790d7si489879pgm.447.2024.05.02.00.17.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 May 2024 00:17:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-166040-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="fRR2/yJX"; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-166040-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-166040-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 8EE7928318C for ; Thu, 2 May 2024 07:17:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 44E0621A1C; Thu, 2 May 2024 07:17:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="fRR2/yJX" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 68B20224D7 for ; Thu, 2 May 2024 07:17:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714634234; cv=none; b=LZMdiOmDngarBnJcrNhlfRJnttboJmI+XU9ecArs4cvdJXthdVIIj2eleBEHYOs2z7Z5Uo7AxbYWgVlhhhm2xVmgQ7omuU/BfUflMhA9FUU06vKP5PpN5oqREbIjL5W3gnDaNKsRl1rF5JxVjAWy1NsU7kyfRGs6IawAA22P8Sg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714634234; c=relaxed/simple; bh=7TpwHRC8mNhefr1Z9wG9HCEWGdaojPeMn62/wY12xTI=; h=Message-ID:Date:MIME-Version:Subject:To:References:From: In-Reply-To:Content-Type; b=HcthqovfpVG/VJmzZaswpK5L6R1/2UKvGFVLXFsloGr/xEsHjQ1lXL1nwWNWq8N9QxD3VtKwhbXlN4tYXxluUM9tYNb6wiMRoL9ONPKWjXsR/BlXhTDZKdrlkBlgqjFGX5GY16K0O7H+CfMy/raH6rd0ZWu19Isfp/NpN+RS+/4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=fRR2/yJX; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1714634231; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=OIDhyH20/Kg5nJwECZysNFVnVnJydF4EiDXJ0DvvH0A=; b=fRR2/yJXEPym3jxHi0Pvjfs2itTUuoaq76aL7hmL6a8hGvGLBEJXZ4dNdTvN2Ps9l/Ir0o +N9ZKiU7Zla+0VX+4PL+DgSPEbZTd2yMisray87h6cx9rqQiu5G2qTDLkpU2ZpL29yxqUV tFC7tYelkad2i/wqYMhcCrWAgLRVe3g= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-461-NBAIsUF2NHG_pggmILh4gw-1; Thu, 02 May 2024 03:17:08 -0400 X-MC-Unique: NBAIsUF2NHG_pggmILh4gw-1 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-416e58bdc0eso34107355e9.0 for ; Thu, 02 May 2024 00:17:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714634227; x=1715239027; h=content-transfer-encoding:in-reply-to:organization:autocrypt:from :content-language:references:to:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=OIDhyH20/Kg5nJwECZysNFVnVnJydF4EiDXJ0DvvH0A=; b=RpHjdHdrSo5J7I5ONZgAHdOb8IrSnMlcO03f5J/2nONU5XOpRfV0MoYDFkT6m31NSi r9M8cVLjLvLSM/t8H6coZDrcSnTla5jHj8NCKzGjiQf6P50WIe245mj9DuTiRFdliXzh A77grLz+6uALSFaQQidxetVR/X9P0YVPUoF197t3Q084kFgWOaQJ+CSmIdkx9tX27W+2 v1YDid9DCZWcePRGABy/Fzssj3ufEp6gV7LIsZ4i2nMootWAkGN7W3ufDHV3cohX002p 4v+BVZhaH54Qexr4cGbXCXpcq7qxccSLxgtzPOtuWHuKLeNhfhfBYLOCpwESD3HWOWrP fsdA== X-Forwarded-Encrypted: i=1; AJvYcCWBRmGPB2jutRtV62b+4Qenl2x20xUsx2XihqIJh7u5eLepUXKecH3VpzEtGDTsHdRVbihero3DYXlh2kDdKqN4UXxRz6Iw5yF20nsy X-Gm-Message-State: AOJu0YzqtYJ84R2lqSfVyXZVIANVAodKEqgqPN65WTIxSmEyIN5OLVpw 4oo0C1xrpBiXnpalkg78UffUCvu4lVfd8dmsBShmcCHJ5AYfMoGLnJ+KJqFTy5tknnlM2pCSEQ/ OAl0zy0JfO8ApS8FZY55Xn9C8GM7QbT8f+e57zeyF5KkErXd67EEXfB6KY/MtOg== X-Received: by 2002:a05:600c:28f:b0:41a:5958:d6ac with SMTP id 15-20020a05600c028f00b0041a5958d6acmr3324885wmk.21.1714634227174; Thu, 02 May 2024 00:17:07 -0700 (PDT) X-Received: by 2002:a05:600c:28f:b0:41a:5958:d6ac with SMTP id 15-20020a05600c028f00b0041a5958d6acmr3324864wmk.21.1714634226701; Thu, 02 May 2024 00:17:06 -0700 (PDT) Received: from ?IPV6:2003:cb:c71e:bf00:eba1:3ab9:ab0f:d676? (p200300cbc71ebf00eba13ab9ab0fd676.dip0.t-ipconnect.de. [2003:cb:c71e:bf00:eba1:3ab9:ab0f:d676]) by smtp.gmail.com with ESMTPSA id g19-20020a05600c311300b0041496734318sm4660626wmo.24.2024.05.02.00.17.05 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 02 May 2024 00:17:06 -0700 (PDT) Message-ID: Date: Thu, 2 May 2024 09:17:05 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 2/2] hv_balloon: Enable hot-add for memblock sizes > 128 MiB To: mhklinux@outlook.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org References: <20240501151458.2807-1-mhklinux@outlook.com> <20240501151458.2807-2-mhklinux@outlook.com> Content-Language: en-US From: David Hildenbrand Autocrypt: addr=david@redhat.com; keydata= xsFNBFXLn5EBEAC+zYvAFJxCBY9Tr1xZgcESmxVNI/0ffzE/ZQOiHJl6mGkmA1R7/uUpiCjJ dBrn+lhhOYjjNefFQou6478faXE6o2AhmebqT4KiQoUQFV4R7y1KMEKoSyy8hQaK1umALTdL QZLQMzNE74ap+GDK0wnacPQFpcG1AE9RMq3aeErY5tujekBS32jfC/7AnH7I0v1v1TbbK3Gp XNeiN4QroO+5qaSr0ID2sz5jtBLRb15RMre27E1ImpaIv2Jw8NJgW0k/D1RyKCwaTsgRdwuK Kx/Y91XuSBdz0uOyU/S8kM1+ag0wvsGlpBVxRR/xw/E8M7TEwuCZQArqqTCmkG6HGcXFT0V9 PXFNNgV5jXMQRwU0O/ztJIQqsE5LsUomE//bLwzj9IVsaQpKDqW6TAPjcdBDPLHvriq7kGjt WhVhdl0qEY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6T9b+MZJk+mZuPxKNVfEQMQ a5SxUEADIPQTPNvBewdeI80yeOCrN+Zzwy/Mrx9EPeu59Y5vSJOx/z6OUImD/GhX7Xvkt3kq Er5KTrJz3++B6SH9pum9PuoE/k+nntJkNMmQpR4MCBaV/J9gIOPGodDKnjdng+mXliF3Ptu6 3oxc2RCyGzTlxyMwuc2U5Q7KtUNTdDe8T0uE+9b8BLMVQDDfJjqY0VVqSUwImzTDLX9S4g/8 kC4HRcclk8hpyhY2jKGluZO0awwTIMgVEzmTyBphDg/Gx7dZU1Xf8HFuE+UZ5UDHDTnwgv7E th6RC9+WrhDNspZ9fJjKWRbveQgUFCpe1sa77LAw+XFrKmBHXp9ZVIe90RMe2tRL06BGiRZr jPrnvUsUUsjRoRNJjKKA/REq+sAnhkNPPZ/NNMjaZ5b8Tovi8C0tmxiCHaQYqj7G2rgnT0kt WNyWQQ== Organization: Red Hat In-Reply-To: <20240501151458.2807-2-mhklinux@outlook.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 01.05.24 17:14, mhkelley58@gmail.com wrote: > From: Michael Kelley > > The Hyper-V balloon driver supports hot-add of memory in addition > to ballooning. Current code hot-adds in fixed size chunks of > 128 MiB (fixed constant HA_CHUNK in the code). While this works > in Hyper-V VMs with 64 GiB or less or memory where the Linux > memblock size is 128 MiB, the hot-add fails for larger memblock > sizes because add_memory() expects memory to be added in chunks > that match the memblock size. Messages like the following are > reported when Linux has a 256 MiB memblock size: > > [ 312.668859] Block size [0x10000000] unaligned hotplug range: > start 0x310000000, size 0x8000000 > [ 312.668880] hv_balloon: hot_add memory failed error is -22 > [ 312.668984] hv_balloon: Memory hot add failed > > Larger memblock sizes are usually used in VMs with more than > 64 GiB of memory, depending on the alignment of the VM's > physical address space. > > Fix this problem by having the Hyper-V balloon driver determine > the Linux memblock size, and process hot-add requests in that > chunk size instead of a fixed 128 MiB. Also update the hot-add > alignment requested of the Hyper-V host to match the memblock > size. > > The code changes look significant, but in fact are just a > simple text substitution of a new global variable for the > previous HA_CHUNK constant. No algorithms are changed except > to initialize the new global variable and to calculate the > alignment value to pass to Hyper-V. Testing with memblock > sizes of 256 MiB and 2 GiB shows correct operation. > > Signed-off-by: Michael Kelley > --- > Changes in v2: > * Change new global variable name from ha_chunk_pgs to > ha_pages_in_chunk [David Hildenbrand] > * Use kernel macros ALIGN(), ALIGN_DOWN(), and umin() > to simplify code and reduce references to HA_CHUNK. For > ease of review, this is done in a new patch preceeding > this one. [David Hildenbrand] > > drivers/hv/hv_balloon.c | 55 +++++++++++++++++++++++++---------------- > 1 file changed, 34 insertions(+), 21 deletions(-) > > diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c > index 9f45b8a6762c..e0a1a18041ca 100644 > --- a/drivers/hv/hv_balloon.c > +++ b/drivers/hv/hv_balloon.c > @@ -425,11 +425,11 @@ struct dm_info_msg { > * The range start_pfn : end_pfn specifies the range > * that the host has asked us to hot add. The range > * start_pfn : ha_end_pfn specifies the range that we have > - * currently hot added. We hot add in multiples of 128M > - * chunks; it is possible that we may not be able to bring > - * online all the pages in the region. The range > + * currently hot added. We hot add in chunks equal to the > + * memory block size; it is possible that we may not be able > + * to bring online all the pages in the region. The range > * covered_start_pfn:covered_end_pfn defines the pages that can > - * be brough online. > + * be brought online. > */ > > struct hv_hotadd_state { > @@ -505,8 +505,9 @@ enum hv_dm_state { > > static __u8 recv_buffer[HV_HYP_PAGE_SIZE]; > static __u8 balloon_up_send_buffer[HV_HYP_PAGE_SIZE]; > +static unsigned long ha_pages_in_chunk; > + > #define PAGES_IN_2M (2 * 1024 * 1024 / PAGE_SIZE) > -#define HA_CHUNK (128 * 1024 * 1024 / PAGE_SIZE) > > struct hv_dynmem_device { > struct hv_device *dev; > @@ -724,21 +725,21 @@ static void hv_mem_hot_add(unsigned long start, unsigned long size, > unsigned long processed_pfn; > unsigned long total_pfn = pfn_count; > > - for (i = 0; i < (size/HA_CHUNK); i++) { > - start_pfn = start + (i * HA_CHUNK); > + for (i = 0; i < (size/ha_pages_in_chunk); i++) { > + start_pfn = start + (i * ha_pages_in_chunk); > > scoped_guard(spinlock_irqsave, &dm_device.ha_lock) { > - has->ha_end_pfn += HA_CHUNK; > - processed_pfn = umin(total_pfn, HA_CHUNK); > + has->ha_end_pfn += ha_pages_in_chunk; > + processed_pfn = umin(total_pfn, ha_pages_in_chunk); > total_pfn -= processed_pfn; > - has->covered_end_pfn += processed_pfn; > + has->covered_end_pfn += processed_pfn; > } > > reinit_completion(&dm_device.ol_waitevent); > > nid = memory_add_physaddr_to_nid(PFN_PHYS(start_pfn)); > ret = add_memory(nid, PFN_PHYS((start_pfn)), > - (HA_CHUNK << PAGE_SHIFT), MHP_MERGE_RESOURCE); > + (ha_pages_in_chunk << PAGE_SHIFT), MHP_MERGE_RESOURCE); > HA_BYTES_IN_CHUNK might be reasonable to have (see below) > if (do_hot_add) > @@ -1807,10 +1808,13 @@ static int balloon_connect_vsp(struct hv_device *dev) > cap_msg.caps.cap_bits.hot_add = hot_add_enabled(); > > /* > - * Specify our alignment requirements as it relates > - * memory hot-add. Specify 128MB alignment. > + * Specify our alignment requirements for memory hot-add. The value is > + * the log base 2 of the number of megabytes in a chunk. For example, > + * with 256 MiB chunks, the value is 8. The number of MiB in a chunk > + * must be a power of 2. > */ > - cap_msg.caps.cap_bits.hot_add_alignment = 7; > + cap_msg.caps.cap_bits.hot_add_alignment = > + ilog2(ha_pages_in_chunk >> (20 - PAGE_SHIFT)); I was wondering if we can remove some of the magic here. Something along the lines of: ilog2(ha_pages_in_chunk / (SZ_1M >> PAGE_SHIFT)) or simply #define HA_BYTES_IN_CHUNK (ha_pages_in_chunk << PAGE_SHIFT) ilog2(HA_BYTES_IN_CHUNK / SZ_1M) Apart from that nothing jumped at me; looks much cleaner. Reviewed-by: David Hildenbrand -- Cheers, David / dhildenb