From nobody Fri May 17 17:02:45 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602146071; cv=none; d=zohomail.com; s=zohoarc; b=RkRqV3oWes7vF8Gcb/kBwN7AGZEOdTkg3FRDPevXtvCRFVmYp+KoY6evHQKbbW5PsflqMF/DlXeWZsioW/sNiqObGtOpxN/eSrupTZBXCaBHpBuxU82Qb/f9wg1zZ1DoLakuxlUEzrE7cowzVs9t5rCzRk6sVC3FUiGP/2oCjBk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602146071; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=t6zqV+AyAhTSGtPn5qMdrNUSsD5BWWFvlLdrBa+5zcU=; b=DHspQqnOLh4Dh3rI0cIJJOG1ISi2JnlsNd/GHid4XZZmyB7fR8SaaYKQiweq8GneRbBn/ACaywvK34yt3w23DQ0Zh7ftiDxqhsUJlpWLY6sgJhHpwFggHJBMP4/AndS8zfJNpX66ISA5/brGZie9UxrOUY+dy8QvGfCCzg4DQzY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 160214607177064.9305779817031; Thu, 8 Oct 2020 01:34:31 -0700 (PDT) Received: from localhost ([::1]:35046 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQRNe-0002Yc-4F for importer@patchew.org; Thu, 08 Oct 2020 04:34:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42802) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQRK3-0007Hl-WA for qemu-devel@nongnu.org; Thu, 08 Oct 2020 04:30:48 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:46012) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kQRK0-0006NI-Rs for qemu-devel@nongnu.org; Thu, 08 Oct 2020 04:30:47 -0400 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-246-byP_qzlFOuKhRlwbuh-k6w-1; Thu, 08 Oct 2020 04:30:41 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EA345101FFA7; Thu, 8 Oct 2020 08:30:39 +0000 (UTC) Received: from t480s.redhat.com (ovpn-114-112.ams2.redhat.com [10.36.114.112]) by smtp.corp.redhat.com (Postfix) with ESMTP id 65AC75C1C2; Thu, 8 Oct 2020 08:30:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602145842; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=t6zqV+AyAhTSGtPn5qMdrNUSsD5BWWFvlLdrBa+5zcU=; b=Vb9k9Rq3uR79igiB2P/o9MUW9B8pHdMoJb2b+iXt1EWAKWT2wtwxTpHB3JPCJVppYEskxs 97ZIvRLeJYsRA9ycKZ5x9tN29/Ss05AtgOEEXPoTS4g+177X9dxJ7eicCUd7TJToIpLshB nw1pwdVhc2cPPxkq6+8nJU8MTQ603hM= X-MC-Unique: byP_qzlFOuKhRlwbuh-k6w-1 From: David Hildenbrand To: qemu-devel@nongnu.org Subject: [PATCH v3 1/6] virtio-mem: Make sure "addr" is always multiples of the block size Date: Thu, 8 Oct 2020 10:30:24 +0200 Message-Id: <20201008083029.9504-2-david@redhat.com> In-Reply-To: <20201008083029.9504-1-david@redhat.com> References: <20201008083029.9504-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=david@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=david@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/08 01:56:49 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.742, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Pankaj Gupta , "Michael S. Tsirkin" , David Hildenbrand , "Dr . David Alan Gilbert" , Wei Yang , Igor Mammedov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The spec states: "The device MUST set addr, region_size, usable_region_size, plugged_size, requested_size to multiples of block_size." In some cases, we currently don't guarantee that for "addr": For example, when starting a VM with 4 GiB boot memory and a virtio-mem device with a block size of 2 GiB, "memaddr"/"addr" will be auto-assigned to 0x140000000 (5 GiB). We'll try to improve auto-assignment for memory devices next, to avoid bailing out in case memory device code selects a bad address. Note: The Linux driver doesn't support such big block sizes yet. Reviewed-by: Pankaj Gupta Fixes: 910b25766b33 ("virtio-mem: Paravirtualized memory hot(un)plug") Cc: "Michael S. Tsirkin" Cc: Wei Yang Cc: Dr. David Alan Gilbert Cc: Igor Mammedov Cc: Pankaj Gupta Signed-off-by: David Hildenbrand --- hw/virtio/virtio-mem.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/hw/virtio/virtio-mem.c b/hw/virtio/virtio-mem.c index 7c8ca9f28b..70200b4eac 100644 --- a/hw/virtio/virtio-mem.c +++ b/hw/virtio/virtio-mem.c @@ -449,6 +449,11 @@ static void virtio_mem_device_realize(DeviceState *dev= , Error **errp) ")", VIRTIO_MEM_REQUESTED_SIZE_PROP, VIRTIO_MEM_BLOCK_SIZE_PROP, vmem->block_size); return; + } else if (!QEMU_IS_ALIGNED(vmem->addr, vmem->block_size)) { + error_setg(errp, "'%s' property has to be multiples of '%s' (0x%" = PRIx64 + ")", VIRTIO_MEM_ADDR_PROP, VIRTIO_MEM_BLOCK_SIZE_PROP, + vmem->block_size); + return; } else if (!QEMU_IS_ALIGNED(memory_region_size(&vmem->memdev->mr), vmem->block_size)) { error_setg(errp, "'%s' property memdev size has to be multiples of" --=20 2.26.2 From nobody Fri May 17 17:02:45 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602145959; cv=none; d=zohomail.com; s=zohoarc; b=WOqMjOyDHMe3jvxgdk0aA+9rN1ROc0/Y65btHiN3X3c4htJkH9FdRGkBSOdEJ7skkigOG2++S+n7O6cCGUwVB9Ymb+J+OZrPPQKayov1niK/ExX2J3H6XdLPMiQGJnjUlN2xQUnfw8I6MvGkqgBuuH562BD7fmTB1NcsF3Q0CTw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602145959; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=znSSftCiTDEJXvd3zETjilAovlbdj+oV9Iiq3iMkwc8=; b=HN+Hn0C+9hzFUicXtoH5UzPpORb5QT+nAWlYv2kURhb44gISeEjEeoN901cLP4sQp7q+oA8+ykXFLsR8noSaV5Gr7sdnCiA0qbYByLULNNfsjvmJh+YHzW2WX/OtmAoNGQLJlBskcxi2m3ZM3ybFCQNG/RL7+ZxjRaTNMNI3vGY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602145959643476.35033583589313; Thu, 8 Oct 2020 01:32:39 -0700 (PDT) Received: from localhost ([::1]:57920 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQRLq-0000GK-39 for importer@patchew.org; Thu, 08 Oct 2020 04:32:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42838) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQRK8-0007Nh-RW for qemu-devel@nongnu.org; Thu, 08 Oct 2020 04:30:52 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:51177) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kQRK7-0006QM-4D for qemu-devel@nongnu.org; Thu, 08 Oct 2020 04:30:52 -0400 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-359-I7UBe0TdNfmZ3Jpi9UoRSQ-1; Thu, 08 Oct 2020 04:30:48 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1F6FF101FFA8; Thu, 8 Oct 2020 08:30:47 +0000 (UTC) Received: from t480s.redhat.com (ovpn-114-112.ams2.redhat.com [10.36.114.112]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4ADC45C1BD; Thu, 8 Oct 2020 08:30:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602145850; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=znSSftCiTDEJXvd3zETjilAovlbdj+oV9Iiq3iMkwc8=; b=HL45feDOiP4kBkavm0DPhYCvQ1t7+s+2ZpzskaPRJuicMIKP/RUWuehxTkYimY9j94Xqoe 14WajJS7fxrqWXPV8JJxOiSvP+RgU6/DQKfdokOs34w2CFUtOBwitU3QuhV0pROZuChVKk NMB49ToWHdTlL0tYYrp2k79HQ5RIJxQ= X-MC-Unique: I7UBe0TdNfmZ3Jpi9UoRSQ-1 From: David Hildenbrand To: qemu-devel@nongnu.org Subject: [PATCH v3 2/6] virtio-mem: Make sure "usable_region_size" is always multiples of the block size Date: Thu, 8 Oct 2020 10:30:25 +0200 Message-Id: <20201008083029.9504-3-david@redhat.com> In-Reply-To: <20201008083029.9504-1-david@redhat.com> References: <20201008083029.9504-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=david@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=david@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/08 02:56:27 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.742, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Pankaj Gupta , "Michael S. Tsirkin" , David Hildenbrand , "Dr . David Alan Gilbert" , Wei Yang , Igor Mammedov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The spec states: "The device MUST set addr, region_size, usable_region_size, plugged_size, requested_size to multiples of block_size." With block sizes > 256MB, we currently wouldn't guarantee that for the usable_region_size. Note that we cannot exceed the region_size, as we already enforce the alignment there properly. Fixes: 910b25766b33 ("virtio-mem: Paravirtualized memory hot(un)plug") Cc: "Michael S. Tsirkin" Cc: Wei Yang Cc: Dr. David Alan Gilbert Cc: Igor Mammedov Cc: Pankaj Gupta Signed-off-by: David Hildenbrand --- hw/virtio/virtio-mem.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/hw/virtio/virtio-mem.c b/hw/virtio/virtio-mem.c index 70200b4eac..461ac68ee8 100644 --- a/hw/virtio/virtio-mem.c +++ b/hw/virtio/virtio-mem.c @@ -227,6 +227,9 @@ static void virtio_mem_resize_usable_region(VirtIOMEM *= vmem, uint64_t newsize =3D MIN(memory_region_size(&vmem->memdev->mr), requested_size + VIRTIO_MEM_USABLE_EXTENT); =20 + /* The usable region size always has to be multiples of the block size= . */ + newsize =3D QEMU_ALIGN_UP(newsize, vmem->block_size); + if (!requested_size) { newsize =3D 0; } --=20 2.26.2 From nobody Fri May 17 17:02:45 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602146156; cv=none; d=zohomail.com; s=zohoarc; b=kC4tHRDIMUJojjOoe6+onhPRTGG8QO6fXQjOXy9laAZX2GO2OKHoKwLtj44SPIxaX1lwK54sWrv5quOKmM53HuOz+FKsha93QTnK2x5IcN2/WCGO7yra/qmtsUa06NWI7J5VIdHoFMw5IFojP+FJYgocBmr7iPBxVzPL39DR5n8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602146156; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=9zvOsDpz0nGx5qNfhvymj/1LqA2ThYcDioxz90I6yh4=; b=BViZZ6TsmrwzZ/PLtaKhTb32asjbTTm80VBYlU6POpyJcyhYyEZOfxuNhKqqN/j8rD6YX4P2jcUWpmuhSx+Am9Spl/bwX2kndW9uFEobfwBlP6UzWFGASfOqWiDb0shEJZQI6aIzQNH2MNIG4Xk2Sw/3KdOusyXFPULFvPjZUis= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 160214615631285.11494732228289; Thu, 8 Oct 2020 01:35:56 -0700 (PDT) Received: from localhost ([::1]:39888 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQRP0-0004eB-3E for importer@patchew.org; Thu, 08 Oct 2020 04:35:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42886) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQRKH-0007Zc-Bx for qemu-devel@nongnu.org; Thu, 08 Oct 2020 04:31:01 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:58877) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kQRKF-0006Tr-BH for qemu-devel@nongnu.org; Thu, 08 Oct 2020 04:31:01 -0400 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-309-UHyC_S8XPrOAGvfDMIr_mA-1; Thu, 08 Oct 2020 04:30:54 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9FD8381EE70; Thu, 8 Oct 2020 08:30:53 +0000 (UTC) Received: from t480s.redhat.com (ovpn-114-112.ams2.redhat.com [10.36.114.112]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6D4675C1C4; Thu, 8 Oct 2020 08:30:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602145858; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9zvOsDpz0nGx5qNfhvymj/1LqA2ThYcDioxz90I6yh4=; b=QG+UsuPgSKCdn7vyn1B9PRtvjmN+DcLT/1kyGm+zGWJ3oBPjSoIzyO22VgvWFfnfA8RaRh SISeVHbEPUCMn8oPQUo74d0/ayn2wgqYs5boT9lYl83rmCl4W7uzk4gY+KAT+iSgyz8Vvr D0V2i4SoHq6m+xNu+fXxRpvDWmdliqM= X-MC-Unique: UHyC_S8XPrOAGvfDMIr_mA-1 From: David Hildenbrand To: qemu-devel@nongnu.org Subject: [PATCH v3 3/6] virtio-mem: Probe THP size to determine default block size Date: Thu, 8 Oct 2020 10:30:26 +0200 Message-Id: <20201008083029.9504-4-david@redhat.com> In-Reply-To: <20201008083029.9504-1-david@redhat.com> References: <20201008083029.9504-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=david@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=david@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/08 02:56:27 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.742, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Pankaj Gupta , "Michael S. Tsirkin" , David Hildenbrand , "Dr . David Alan Gilbert" , Wei Yang , Igor Mammedov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Let's allow a minimum block size of 1 MiB in all configurations. Select the default block size based on - The page size of the memory backend. - The THP size if the memory backend size corresponds to the real host page size. - The global minimum of 1 MiB. and warn if something smaller is configured by the user. VIRTIO_MEM only supports Linux (depends on LINUX), so we can probe the THP size unconditionally. For now we only support virtio-mem on x86-64 - there isn't a user-visible change (x86-64 only supports 2 MiB THP on the PMD level) - the default was, and will be 2 MiB. If we ever have THP on the PUD level (e.g., 1 GiB THP on x86-64), we expect it to be more transparent - e.g., to only optimize fully populated ranges unless explicitly told /configured otherwise (in contrast to PMD THP). Reviewed-by: Pankaj Gupta Cc: "Michael S. Tsirkin" Cc: Wei Yang Cc: Dr. David Alan Gilbert Cc: Igor Mammedov Cc: Pankaj Gupta Signed-off-by: David Hildenbrand --- hw/virtio/virtio-mem.c | 105 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 101 insertions(+), 4 deletions(-) diff --git a/hw/virtio/virtio-mem.c b/hw/virtio/virtio-mem.c index 461ac68ee8..655824ff81 100644 --- a/hw/virtio/virtio-mem.c +++ b/hw/virtio/virtio-mem.c @@ -33,10 +33,83 @@ #include "trace.h" =20 /* - * Use QEMU_VMALLOC_ALIGN, so no THP will have to be split when unplugging - * memory (e.g., 2MB on x86_64). + * Let's not allow blocks smaller than 1 MiB, for example, to keep the tra= cking + * bitmap small. */ -#define VIRTIO_MEM_MIN_BLOCK_SIZE ((uint32_t)QEMU_VMALLOC_ALIGN) +#define VIRTIO_MEM_MIN_BLOCK_SIZE ((uint32_t)(1 * MiB)) + +#if defined(__x86_64__) || defined(__arm__) || defined(__aarch64__) || \ + defined(__powerpc64__) +#define VIRTIO_MEM_DEFAULT_THP_SIZE ((uint32_t)(2 * MiB)) +#else + /* fallback to 1 MiB (e.g., the THP size on s390x) */ +#define VIRTIO_MEM_DEFAULT_THP_SIZE VIRTIO_MEM_MIN_BLOCK_SIZE +#endif + +/* + * We want to have a reasonable default block size such that + * 1. We avoid splitting THPs when unplugging memory, which degrades + * performance. + * 2. We avoid placing THPs for plugged blocks that also cover unplugged + * blocks. + * + * The actual THP size might differ between Linux kernels, so we try to pr= obe + * it. In the future (if we ever run into issues regarding 2.), we might w= ant + * to disable THP in case we fail to properly probe the THP size, or if the + * block size is configured smaller than the THP size. + */ +static uint32_t thp_size; + +#define HPAGE_PMD_SIZE_PATH "/sys/kernel/mm/transparent_hugepage/hpage_pmd= _size" +static uint32_t virtio_mem_thp_size(void) +{ + gchar *content =3D NULL; + const char *endptr; + uint64_t tmp; + + if (thp_size) { + return thp_size; + } + + /* + * Try to probe the actual THP size, fallback to (sane but eventually + * incorrect) default sizes. + */ + if (g_file_get_contents(HPAGE_PMD_SIZE_PATH, &content, NULL, NULL) && + !qemu_strtou64(content, &endptr, 0, &tmp) && + (!endptr || *endptr =3D=3D '\n')) { + /* + * Sanity-check the value, if it's too big (e.g., aarch64 with 64k= base + * pages) or weird, fallback to something smaller. + */ + if (!tmp || !is_power_of_2(tmp) || tmp > 16 * MiB) { + warn_report("Read unsupported THP size: %" PRIx64, tmp); + } else { + thp_size =3D tmp; + } + } + + if (!thp_size) { + thp_size =3D VIRTIO_MEM_DEFAULT_THP_SIZE; + warn_report("Could not detect THP size, falling back to %" PRIx64 + " MiB.", thp_size / MiB); + } + + g_free(content); + return thp_size; +} + +static uint64_t virtio_mem_default_block_size(RAMBlock *rb) +{ + const uint64_t page_size =3D qemu_ram_pagesize(rb); + + /* We can have hugetlbfs with a page size smaller than the THP size. */ + if (page_size =3D=3D qemu_real_host_page_size) { + return MAX(page_size, virtio_mem_thp_size()); + } + return MAX(page_size, VIRTIO_MEM_MIN_BLOCK_SIZE); +} + /* * Size the usable region bigger than the requested size if possible. Esp. * Linux guests will only add (aligned) memory blocks in case they fully @@ -443,10 +516,23 @@ static void virtio_mem_device_realize(DeviceState *de= v, Error **errp) rb =3D vmem->memdev->mr.ram_block; page_size =3D qemu_ram_pagesize(rb); =20 + /* + * If the block size wasn't configured by the user, use a sane default= . This + * allows using hugetlbfs backends of any page size without manual + * intervention. + */ + if (!vmem->block_size) { + vmem->block_size =3D virtio_mem_default_block_size(rb); + } + if (vmem->block_size < page_size) { error_setg(errp, "'%s' property has to be at least the page size (= 0x%" PRIx64 ")", VIRTIO_MEM_BLOCK_SIZE_PROP, page_size); return; + } else if (vmem->block_size < virtio_mem_default_block_size(rb)) { + warn_report("'%s' property is smaller than the default block size = (%" + PRIx64 " MiB)", VIRTIO_MEM_BLOCK_SIZE_PROP, + virtio_mem_default_block_size(rb) / MiB); } else if (!QEMU_IS_ALIGNED(vmem->requested_size, vmem->block_size)) { error_setg(errp, "'%s' property has to be multiples of '%s' (0x%" = PRIx64 ")", VIRTIO_MEM_REQUESTED_SIZE_PROP, @@ -742,6 +828,18 @@ static void virtio_mem_get_block_size(Object *obj, Vis= itor *v, const char *name, const VirtIOMEM *vmem =3D VIRTIO_MEM(obj); uint64_t value =3D vmem->block_size; =20 + /* + * If not configured by the user (and we're not realized yet), use the + * default block size we would use with the current memory backend. + */ + if (!value) { + if (vmem->memdev && memory_region_is_ram(&vmem->memdev->mr)) { + value =3D virtio_mem_default_block_size(vmem->memdev->mr.ram_b= lock); + } else { + value =3D virtio_mem_thp_size(); + } + } + visit_type_size(v, name, &value, errp); } =20 @@ -821,7 +919,6 @@ static void virtio_mem_instance_init(Object *obj) { VirtIOMEM *vmem =3D VIRTIO_MEM(obj); =20 - vmem->block_size =3D VIRTIO_MEM_MIN_BLOCK_SIZE; notifier_list_init(&vmem->size_change_notifiers); vmem->precopy_notifier.notify =3D virtio_mem_precopy_notify; =20 --=20 2.26.2 From nobody Fri May 17 17:02:45 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602145970; cv=none; d=zohomail.com; s=zohoarc; b=MScje9y6619jANYuMyz39W7cO9ie3qC5TOsaP31o5OS2AxPoOLq5z7EYM3P1GiYUdh5cDS9D4ihlHbsygd+SMgGVNtFWhdYJ9cdOvvl+XFOU+7Wie+30z5io1r15FdMK24EWPfXi8kBupnXDzUOpoK87oyKjspWKUJKCeODN0oA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602145970; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=aTdtN2zUAy19rHWMCKzZPiBGRVnWwjTvuku/uO8M91Y=; b=kFE9Mn11P/DAH8w+D/k0oWpKusK0ePfwQe7HyLjStAgyqrmOywf6dkNRR2xLCEfPPVvzU/XA3PMEvh8VOZa9Y1IwYqnTOA/pdkhpvlq579njiuEjWdZDpotuZSXPSaDFZwB7F8Uc4pWwP9oy/147bEB4JYiYP9Dw62Levh4ykmE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602145970215204.87330147557748; Thu, 8 Oct 2020 01:32:50 -0700 (PDT) Received: from localhost ([::1]:58762 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQRM1-0000ce-0e for importer@patchew.org; Thu, 08 Oct 2020 04:32:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42912) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQRKK-0007fX-OA for qemu-devel@nongnu.org; Thu, 08 Oct 2020 04:31:04 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:38138) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kQRKI-0006UL-Rs for qemu-devel@nongnu.org; Thu, 08 Oct 2020 04:31:04 -0400 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-509-DUJhYAWGMy22dKuxdOe13A-1; Thu, 08 Oct 2020 04:31:00 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B58FF18BE164; Thu, 8 Oct 2020 08:30:58 +0000 (UTC) Received: from t480s.redhat.com (ovpn-114-112.ams2.redhat.com [10.36.114.112]) by smtp.corp.redhat.com (Postfix) with ESMTP id F1DA65C1BD; Thu, 8 Oct 2020 08:30:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602145862; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=aTdtN2zUAy19rHWMCKzZPiBGRVnWwjTvuku/uO8M91Y=; b=hCsFv7GB/F1OdaLqXkz/QakpiPNdHcQr7mY9wKkVk5D3sPqv9nrd3XQMoCuVY/zUUJHnFV pe9qjOjVfihYNfKBjUMmI4mIUI6zDTO6OgiG/0eK7RD3llhG/5S1sREu4h1lJzOIjh8Suz HrnUhC6ux0xF1rHZ8kNq3ayS4oqqtGo= X-MC-Unique: DUJhYAWGMy22dKuxdOe13A-1 From: David Hildenbrand To: qemu-devel@nongnu.org Subject: [PATCH v3 4/6] memory-device: Support big alignment requirements Date: Thu, 8 Oct 2020 10:30:27 +0200 Message-Id: <20201008083029.9504-5-david@redhat.com> In-Reply-To: <20201008083029.9504-1-david@redhat.com> References: <20201008083029.9504-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=david@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=david@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/08 02:56:27 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.742, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Pankaj Gupta , "Michael S. Tsirkin" , David Hildenbrand , "Dr . David Alan Gilbert" , Wei Yang , Igor Mammedov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Let's warn instead of bailing out - the worst thing that can happen is that we'll fail hot/coldplug later. The user got warned, and this should be rare. This will be necessary for memory devices with rather big (user-defined) alignment requirements - say a virtio-mem device with a 2G block size - which will become important, for example, when supporting vfio in the future. Reviewed-by: Pankaj Gupta Cc: "Michael S. Tsirkin" Cc: Wei Yang Cc: Dr. David Alan Gilbert Cc: Igor Mammedov Cc: Pankaj Gupta Signed-off-by: David Hildenbrand --- hw/mem/memory-device.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c index 4bc9cf0917..8a736f1a26 100644 --- a/hw/mem/memory-device.c +++ b/hw/mem/memory-device.c @@ -119,9 +119,10 @@ static uint64_t memory_device_get_free_addr(MachineSta= te *ms, =20 /* start of address space indicates the maximum alignment we expect */ if (!QEMU_IS_ALIGNED(range_lob(&as), align)) { - error_setg(errp, "the alignment (0x%" PRIx64 ") is not supported", - align); - return 0; + warn_report("the alignment (0x%" PRIx64 ") exceeds the expected" + " maximum alignment, memory will get fragmented and no= t" + " all 'maxmem' might be usable for memory devices.", + align); } =20 memory_device_check_addable(ms, size, &err); @@ -151,7 +152,7 @@ static uint64_t memory_device_get_free_addr(MachineStat= e *ms, return 0; } } else { - if (range_init(&new, range_lob(&as), size)) { + if (range_init(&new, QEMU_ALIGN_UP(range_lob(&as), align), size)) { error_setg(errp, "can't add memory device, device too big"); return 0; } --=20 2.26.2 From nobody Fri May 17 17:02:45 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602146262; cv=none; d=zohomail.com; s=zohoarc; b=XQooenk/mJvhbm1F4N+FuJn7JRodhZ/n9APhIrUeASEWUqisF+8Nfx8CcixCwyW2h8iUq8POpEOYmolt1rhyX1ZgETqArRecpVdgOpvPNvpUYuKKhJHaUl4+RKlfM2dq4yuueFlI3ZUKsuym5lbmt3zuzdwN+zSf8UJqWqOcmqU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602146262; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=SQaLfRo2tu54l3MsruxQvJ4m6XbDXmEWRfBKrb12I7w=; b=KWH2epsf8FSgiN9PHmg9JnlqAxQMAZWwGPM3KFxVQ4/ylTrjMAkIgWI2zOlizrNT5QWsfgOEoSYB+W3R2RZgdlx5B4Lw6Q0N58A4Bqj/hmeph3i74FVWtzHAgNqTRV9Znpn+V2BQDh+tdlNouKe9XixGBkPN/6IS9bXWt0YjNSQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602146262155807.1788287900359; Thu, 8 Oct 2020 01:37:42 -0700 (PDT) Received: from localhost ([::1]:42006 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQRQi-0005ax-Tm for importer@patchew.org; Thu, 08 Oct 2020 04:37:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42922) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQRKM-0007hh-CT for qemu-devel@nongnu.org; Thu, 08 Oct 2020 04:31:08 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:60314) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kQRKK-0006UU-Ds for qemu-devel@nongnu.org; Thu, 08 Oct 2020 04:31:06 -0400 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-506-PK5zdy3TNdO7ZPdS3ABI8Q-1; Thu, 08 Oct 2020 04:31:01 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A359881EE69; Thu, 8 Oct 2020 08:31:00 +0000 (UTC) Received: from t480s.redhat.com (ovpn-114-112.ams2.redhat.com [10.36.114.112]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0FFA15C1BD; Thu, 8 Oct 2020 08:30:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602145863; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SQaLfRo2tu54l3MsruxQvJ4m6XbDXmEWRfBKrb12I7w=; b=gIbGTqm+3H9YkSBDBM2NXTW3uB4MluNtYlBc4pBx+4Zaisbc33d2/kdXtbvqTUvDKpMt59 GS3Oz1/vQHGJyDQaNbPAg+i2Wssg5eOLcZkUCMppCkJAo05TRq5GycKtM0f0QxyndpF2bT Qi1/6bWMjCx0TuhPCUw1NN+zxOHMbXM= X-MC-Unique: PK5zdy3TNdO7ZPdS3ABI8Q-1 From: David Hildenbrand To: qemu-devel@nongnu.org Subject: [PATCH v3 5/6] memory-device: Add get_min_alignment() callback Date: Thu, 8 Oct 2020 10:30:28 +0200 Message-Id: <20201008083029.9504-6-david@redhat.com> In-Reply-To: <20201008083029.9504-1-david@redhat.com> References: <20201008083029.9504-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=david@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=david@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/08 01:56:49 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.742, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Pankaj Gupta , "Michael S. Tsirkin" , David Hildenbrand , "Dr . David Alan Gilbert" , Wei Yang , Igor Mammedov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Add a callback that can be used to express additional alignment requirements (exceeding the ones from the memory region). Will be used by virtio-mem to express special alignment requirements due to manually configured, big block sizes (e.g., 1GB with an ordinary memory-backend-ram). This avoids failing later when realizing, because auto-detection wasn't able to assign a properly aligned address. Reviewed-by: Pankaj Gupta Cc: "Michael S. Tsirkin" Cc: Wei Yang Cc: Dr. David Alan Gilbert Cc: Igor Mammedov Cc: Pankaj Gupta Signed-off-by: David Hildenbrand --- hw/mem/memory-device.c | 11 +++++++++-- include/hw/mem/memory-device.h | 10 ++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c index 8a736f1a26..cf0627fd01 100644 --- a/hw/mem/memory-device.c +++ b/hw/mem/memory-device.c @@ -259,7 +259,7 @@ void memory_device_pre_plug(MemoryDeviceState *md, Mach= ineState *ms, { const MemoryDeviceClass *mdc =3D MEMORY_DEVICE_GET_CLASS(md); Error *local_err =3D NULL; - uint64_t addr, align; + uint64_t addr, align =3D 0; MemoryRegion *mr; =20 mr =3D mdc->get_memory_region(md, &local_err); @@ -267,7 +267,14 @@ void memory_device_pre_plug(MemoryDeviceState *md, Mac= hineState *ms, goto out; } =20 - align =3D legacy_align ? *legacy_align : memory_region_get_alignment(m= r); + if (legacy_align) { + align =3D *legacy_align; + } else { + if (mdc->get_min_alignment) { + align =3D mdc->get_min_alignment(md); + } + align =3D MAX(align, memory_region_get_alignment(mr)); + } addr =3D mdc->get_addr(md); addr =3D memory_device_get_free_addr(ms, !addr ? NULL : &addr, align, memory_region_size(mr), &local_err); diff --git a/include/hw/mem/memory-device.h b/include/hw/mem/memory-device.h index 30d7e99f52..48d2611fc5 100644 --- a/include/hw/mem/memory-device.h +++ b/include/hw/mem/memory-device.h @@ -88,6 +88,16 @@ struct MemoryDeviceClass { */ MemoryRegion *(*get_memory_region)(MemoryDeviceState *md, Error **errp= ); =20 + /* + * Optional: Return the desired minimum alignment of the device in gue= st + * physical address space. The final alignment is computed based on th= is + * alignment and the alignment requirements of the memory region. + * + * Called when plugging the memory device to detect the required align= ment + * during address assignment. + */ + uint64_t (*get_min_alignment)(const MemoryDeviceState *md); + /* * Translate the memory device into #MemoryDeviceInfo. */ --=20 2.26.2 From nobody Fri May 17 17:02:45 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602146078; cv=none; d=zohomail.com; s=zohoarc; b=hw2XaefnzCKdna4qYgE1vWGQ1u+TanxKNTzag/rp3wyacikJqAtfdKw/PUXIrcytyoDoEA6QP8m/s6iUJLi1+AY3z6/odx/rhhPWEf7iDwHDP1ARXtqM0+upDUx8S6EgfXgDSYUh1/Z0XaDFWBRkbNB2TmzIbUnHlD4R8ctBhFg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602146078; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=hVXJXNjHsvOKf6S0WioACs9CM2puZr3YT6vs5QNLmmU=; b=cxDUGiqEgjlpM72Dwc6ExZdOO55m3yw6JsgKmnm3sXZdO8r6NfAJapkicBGez55sJciyFucZyyKP0bKHDGs89ooGXgFgYqP2CIGxRiXTGsSp9uFvBEzrQS6vNo8S4S9S8CF3PyLyC6bOBexPWuUaTjnVQuVUG3cZpuh+9VZNnpM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602146078643554.3419433611409; Thu, 8 Oct 2020 01:34:38 -0700 (PDT) Received: from localhost ([::1]:35672 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQRNl-0002py-8a for importer@patchew.org; Thu, 08 Oct 2020 04:34:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42948) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQRKP-0007jo-2X for qemu-devel@nongnu.org; Thu, 08 Oct 2020 04:31:10 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:23973) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kQRKN-0006Ut-1K for qemu-devel@nongnu.org; Thu, 08 Oct 2020 04:31:08 -0400 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-477-aa_5A1E_PtaLLgJh42YEhA-1; Thu, 08 Oct 2020 04:31:03 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 88721835B67; Thu, 8 Oct 2020 08:31:02 +0000 (UTC) Received: from t480s.redhat.com (ovpn-114-112.ams2.redhat.com [10.36.114.112]) by smtp.corp.redhat.com (Postfix) with ESMTP id F01D15C1BD; Thu, 8 Oct 2020 08:31:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602145866; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hVXJXNjHsvOKf6S0WioACs9CM2puZr3YT6vs5QNLmmU=; b=Uw7OnGPxz1ClzJIW4zshAhsnJrG4KI9t4Ca8IIqwyImTlxxnxwtaVGh6blbwqfdGez6VLm nbLodZxUeiw4uuHiTvFWWwbikH1QRjrPi0NkNjDDzberVQtaM2JWWVyazQClfHejIacjqX PSXQ1XtT+1E5a6BTecPs9dTVqyTITQA= X-MC-Unique: aa_5A1E_PtaLLgJh42YEhA-1 From: David Hildenbrand To: qemu-devel@nongnu.org Subject: [PATCH v3 6/6] virito-mem: Implement get_min_alignment() Date: Thu, 8 Oct 2020 10:30:29 +0200 Message-Id: <20201008083029.9504-7-david@redhat.com> In-Reply-To: <20201008083029.9504-1-david@redhat.com> References: <20201008083029.9504-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=david@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=david@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/08 02:56:27 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.742, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Pankaj Gupta , "Michael S. Tsirkin" , David Hildenbrand , "Dr . David Alan Gilbert" , Wei Yang , Igor Mammedov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The block size determines the alignment requirements. Implement get_min_alignment() of the TYPE_MEMORY_DEVICE interface. This allows auto-assignment of a properly aligned address in guest physical address space. For example, when specifying a 2GB block size for a virtio-mem device with 10GB with a memory setup "-m 4G, 20G", we'll no longer fail when realizing. Reviewed-by: Pankaj Gupta Cc: "Michael S. Tsirkin" Cc: Wei Yang Cc: Dr. David Alan Gilbert Cc: Igor Mammedov Cc: Pankaj Gupta Signed-off-by: David Hildenbrand --- hw/virtio/virtio-mem-pci.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/hw/virtio/virtio-mem-pci.c b/hw/virtio/virtio-mem-pci.c index 913f4a3326..fa5395cd88 100644 --- a/hw/virtio/virtio-mem-pci.c +++ b/hw/virtio/virtio-mem-pci.c @@ -76,6 +76,12 @@ static void virtio_mem_pci_fill_device_info(const Memory= DeviceState *md, info->type =3D MEMORY_DEVICE_INFO_KIND_VIRTIO_MEM; } =20 +static uint64_t virtio_mem_pci_get_min_alignment(const MemoryDeviceState *= md) +{ + return object_property_get_uint(OBJECT(md), VIRTIO_MEM_BLOCK_SIZE_PROP, + &error_abort); +} + static void virtio_mem_pci_size_change_notify(Notifier *notifier, void *da= ta) { VirtIOMEMPCI *pci_mem =3D container_of(notifier, VirtIOMEMPCI, @@ -110,6 +116,7 @@ static void virtio_mem_pci_class_init(ObjectClass *klas= s, void *data) mdc->get_plugged_size =3D virtio_mem_pci_get_plugged_size; mdc->get_memory_region =3D virtio_mem_pci_get_memory_region; mdc->fill_device_info =3D virtio_mem_pci_fill_device_info; + mdc->get_min_alignment =3D virtio_mem_pci_get_min_alignment; } =20 static void virtio_mem_pci_instance_init(Object *obj) --=20 2.26.2