From patchwork Thu Jun 28 20:04:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 936406 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="HuHWa8hc"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41Grbx2jdMz9ryk for ; Fri, 29 Jun 2018 06:14:53 +1000 (AEST) Received: from localhost ([::1]:38324 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYdJa-0006Qd-Vc for incoming@patchwork.ozlabs.org; Thu, 28 Jun 2018 16:14:51 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37860) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYdAS-00076x-KA for qemu-devel@nongnu.org; Thu, 28 Jun 2018 16:05:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fYdAR-0000C5-Gb for qemu-devel@nongnu.org; Thu, 28 Jun 2018 16:05:24 -0400 Received: from mail-wr0-x232.google.com ([2a00:1450:400c:c0c::232]:43337) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fYdAR-0000AL-7u for qemu-devel@nongnu.org; Thu, 28 Jun 2018 16:05:23 -0400 Received: by mail-wr0-x232.google.com with SMTP id c5-v6so6680844wrs.10 for ; Thu, 28 Jun 2018 13:05:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=26Fv7Ds6niWBbLSjOAJLcfQ5P/bjyv+RSulzBQsE2Xc=; b=HuHWa8hcaP4kdSxwLkxUsplSRYKoq3dpUyp4u1OAGZAcIcyHlOcQv5v6uWEDUvftig V+bw2UQ65OIG/eEodFUuUlWRYz8PP+E66xm4x+WBexdX/DjU24t5GyoioKDDPkIugsWD uu2dpz5wz8Zc2lbt6uU3fxUYa626nW1CtH5j/ILAqDZr/R66QVUk1qtr+fsDzzA9TKAW v3iyypUfmXrKkwzXEviSt8fAo3TgRplSUg+guM3VuLVVdRqDAqmO5k4cxHR+/xJ3X9Bi blBjm8jKUmZzXHZ0Bnf6iCUN8cwpmFx5pwazq+/HmvWWVk9fUgjto8FS9QHLMYb0CWaI nV+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=26Fv7Ds6niWBbLSjOAJLcfQ5P/bjyv+RSulzBQsE2Xc=; b=IYmeMtgB2sheTRCGiklAl2+H9z/2q2YBk2vforJA6ICeoUJHEW6iDDE3t5QdXyDwBD sezA+XPAPjUDPFJr02QbJK+jliFhQWs69G4M3D5xvq4LPsIIIejMLcuyT0YnjbxAbOKq fP2WNWcj0uqVzruLXlJJKJ2FPtzz8tp14hW3qMPko0ecuj/n1JL8LpUaeJ4EQSDs/UVu q4E8kaIuBvsFI/S3KhzXMBJ63I8Q3g3vaxgLAClvLKzY2DVR4jeRF2+ymiwmqp4tVxkW hsJIlbbbtyCltuxAuJSpDzv7+QWc8KvtiMWayRyL4enq/4Ga5C+35IOcARwnjFnWSfRt eTEw== X-Gm-Message-State: APt69E1In9rvwFNak5zOGPnkhTh/a8xe3gR38c+ISOpLAnXoFXOQie7M /mWlLkOPmUsOfkX+hvASwxZlJgNY X-Google-Smtp-Source: AAOMgpf28bfT8koqQhCNBYq4uxVbp6VjIVhM6upylBluUuRE/9KOFXgCM9EuiBs5CxQZmYVs+qiYIw== X-Received: by 2002:adf:f08e:: with SMTP id n14-v6mr10153316wro.49.1530216321842; Thu, 28 Jun 2018 13:05:21 -0700 (PDT) Received: from 640k.lan ([82.84.124.111]) by smtp.gmail.com with ESMTPSA id 127-v6sm6211110wmd.18.2018.06.28.13.05.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Jun 2018 13:05:21 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 28 Jun 2018 22:04:18 +0200 Message-Id: <1530216310-52873-9-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1530216310-52873-1-git-send-email-pbonzini@redhat.com> References: <1530216310-52873-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::232 Subject: [Qemu-devel] [PULL 08/60] memory-device: turn alignment assert into check X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: David Hildenbrand Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: David Hildenbrand The start of the address space indicates which maximum alignment is supported by our machine (e.g. ppc, x86 1GB). This is helpful to catch fragmenting guest physical memory in strange fashions. Right now we can crash QEMU by e.g. (there might be easier examples) qemu-system-x86_64 -m 256M,maxmem=20G,slots=2 \ -object memory-backend-file,id=mem0,size=8192M,mem-path=/dev/zero,align=8192M \ -device pc-dimm,id=dimm1,memdev=mem0 Signed-off-by: David Hildenbrand Message-Id: <20180607154705.6316-2-david@redhat.com> Reviewed-by: Michael S. Tsirkin Reviewed-by: Igor Mammedov Signed-off-by: Paolo Bonzini --- hw/mem/memory-device.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c index 3e04f39..6de4f70 100644 --- a/hw/mem/memory-device.c +++ b/hw/mem/memory-device.c @@ -116,9 +116,15 @@ uint64_t memory_device_get_free_addr(MachineState *ms, const uint64_t *hint, address_space_start = ms->device_memory->base; address_space_end = address_space_start + memory_region_size(&ms->device_memory->mr); - g_assert(QEMU_ALIGN_UP(address_space_start, align) == address_space_start); g_assert(address_space_end >= address_space_start); + /* address_space_start indicates the maximum alignment we expect */ + if (QEMU_ALIGN_UP(address_space_start, align) != address_space_start) { + error_setg(errp, "the alignment (0%" PRIx64 ") is not supported", + align); + return 0; + } + memory_device_check_addable(ms, size, errp); if (*errp) { return 0;