From nobody Sun May 19 02:06:42 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1618481065; cv=none; d=zohomail.com; s=zohoarc; b=Nc9yKDCwc73uEpOSLy9SJ8UCA7yqFYmC0jEvX/v4h99sKYgqskR7wHjT4f5JMt6+j9DUCifNST3zqg8vVuPARPs2HuNR8jJJ5PwClolJIsjjz+ragM3i03dpifoAXfTFk2Gf5i8TYUyZpi1FJvy+De1jLMq3VLf7EGHoSUIEpKw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1618481065; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=xMCoBlScEBzYBsarVCZrwNR5sWCvV8ZrzKqBfidkwh8=; b=KZ0GrLS3TvTLftFjzsflZ+S02UJDlQgsQ4Lych98fxAf9oit6GbdsRvB+KyF5nn8ER9fz7uVZm44pVdVgvEkK0gSbfYfv7fab6FdFjJuiIbt8g9WkiK6iusI4kKSM2Hjyo/6VRntHkk7qHtSwWdLM0A5E5XBS36Cid8Y6mjvwR4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1618481065202855.1613381188738; Thu, 15 Apr 2021 03:04:25 -0700 (PDT) Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-466-YFpbi3jgN3CUAaMDQpBmDA-1; Thu, 15 Apr 2021 06:04:18 -0400 Received: by mail-wm1-f72.google.com with SMTP id x20-20020a7bc2140000b029012bb4d2b5d6so2711407wmi.1 for ; Thu, 15 Apr 2021 03:04:18 -0700 (PDT) Return-Path: Return-Path: Received: from localhost.localdomain (39.red-81-40-121.staticip.rima-tde.net. [81.40.121.39]) by smtp.gmail.com with ESMTPSA id g13sm2597085wrr.9.2021.04.15.03.04.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Apr 2021 03:04:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1618481062; 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=xMCoBlScEBzYBsarVCZrwNR5sWCvV8ZrzKqBfidkwh8=; b=BcH872qsRT4L0MDMn3AXdFhxkaMZ/UOPdkAM1DX08F6f4X15XV1xWwwXuY5FpXP1CwK5t3 T7NtFy3ZdMLbTF2EDrai0X50a2nOkrXmxlZL87k9Y/mQByV2/n8uRPoWfca5+6XKIrbx9I 7zaIYmE+qt5YAAbAtLmiIE46Ecyht2E= X-MC-Unique: YFpbi3jgN3CUAaMDQpBmDA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xMCoBlScEBzYBsarVCZrwNR5sWCvV8ZrzKqBfidkwh8=; b=PLUSspOczprEa3QMq9Mn7Hita0QH5o1tVQzNxTO9MC9WhVPpPWgFZTvLsNX1RESrP+ hUnNYN0ODFG/6BZHY8vu7fAe7Eit+JvahOcuZllw/wPHEC1QPYtJJl8NG6ryjCGBoRwn DY6lmCfuXUlFZIt9PFYbOH/eZYpGsCfc5GKsO7DUzKIZLVlSvV7APukPaHAFjRSDefg8 O8GV/ctNPdoHSt8s6SO8mAztdyhpORYnk9s/Jy5kfmGSiXdIdVOSOBKp7KakEUlsl6qL eyPHFZoavl70xxEV4lvRGG0pePpUxHjI1C+49AbURw5YTD91/biDT3CsyT7b0HSQGNpe 4qQQ== X-Gm-Message-State: AOAM533uvvDLNyZRyXXt4PgRXYlyRBtv9yQvn78wKTGt9QH5tJQoTZJl YXrc61HofJMg5Ds9ui1Yy9aaFT5gR1rqbSqrQwkGb7dbZbmyZSc2kAKHxV2MDW4sj5LwdljvzdS 98YkAQAUXkXNVgg== X-Received: by 2002:adf:fdc7:: with SMTP id i7mr2562278wrs.350.1618481057358; Thu, 15 Apr 2021 03:04:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxjBu6B+uS0BdYeredB28yoTL2k9Xydm6zXE/MxD6jA0tOwiz+IXRGgb5MOd6vBS2joTNGg/A== X-Received: by 2002:adf:fdc7:: with SMTP id i7mr2562247wrs.350.1618481057071; Thu, 15 Apr 2021 03:04:17 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: Stefano Garzarella , Laurent Vivier , qemu-devel@nongnu.org Cc: Peter Maydell , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v2 1/2] exec/memory: Extract address_space_set() from dma_memory_set() Date: Thu, 15 Apr 2021 12:04:08 +0200 Message-Id: <20210415100409.3977971-2-philmd@redhat.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210415100409.3977971-1-philmd@redhat.com> References: <20210415100409.3977971-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) dma_memory_set() does a DMA barrier, set the address space with a constant value. The constant value filling code is not specific to DMA and can be used for AddressSpace. Extract it as a new helper: address_space_set(). Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Laurent Vivier Reviewed-by: Richard Henderson Reviewed-by: Stefano Garzarella --- include/exec/memory.h | 16 ++++++++++++++++ softmmu/dma-helpers.c | 16 +--------------- softmmu/physmem.c | 19 +++++++++++++++++++ 3 files changed, 36 insertions(+), 15 deletions(-) diff --git a/include/exec/memory.h b/include/exec/memory.h index 5728a681b27..192139af58e 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -2568,6 +2568,22 @@ address_space_write_cached(MemoryRegionCache *cache,= hwaddr addr, } } =20 +/** + * address_space_set: Fill address space with a constant byte. + * + * Return a MemTxResult indicating whether the operation succeeded + * or failed (eg unassigned memory, device rejected the transaction, + * IOMMU fault). + * + * @as: #AddressSpace to be accessed + * @addr: address within that address space + * @c: constant byte to fill the memory + * @len: the number of bytes to fill with the constant byte + * @attrs: memory transaction attributes + */ +MemTxResult address_space_set(AddressSpace *as, hwaddr addr, + uint8_t c, hwaddr len, MemTxAttrs attrs); + #ifdef NEED_CPU_H /* enum device_endian to MemOp. */ static inline MemOp devend_memop(enum device_endian end) diff --git a/softmmu/dma-helpers.c b/softmmu/dma-helpers.c index 7d766a5e89a..8e1e7ad5320 100644 --- a/softmmu/dma-helpers.c +++ b/softmmu/dma-helpers.c @@ -23,21 +23,7 @@ MemTxResult dma_memory_set(AddressSpace *as, dma_addr_t = addr, { dma_barrier(as, DMA_DIRECTION_FROM_DEVICE); =20 -#define FILLBUF_SIZE 512 - uint8_t fillbuf[FILLBUF_SIZE]; - int l; - MemTxResult error =3D MEMTX_OK; - - memset(fillbuf, c, FILLBUF_SIZE); - while (len > 0) { - l =3D len < FILLBUF_SIZE ? len : FILLBUF_SIZE; - error |=3D address_space_write(as, addr, MEMTXATTRS_UNSPECIFIED, - fillbuf, l); - len -=3D l; - addr +=3D l; - } - - return error; + return address_space_set(as, addr, c, len, MEMTXATTRS_UNSPECIFIED); } =20 void qemu_sglist_init(QEMUSGList *qsg, DeviceState *dev, int alloc_hint, diff --git a/softmmu/physmem.c b/softmmu/physmem.c index 85034d9c11e..c9117527ae7 100644 --- a/softmmu/physmem.c +++ b/softmmu/physmem.c @@ -2891,6 +2891,25 @@ MemTxResult address_space_rw(AddressSpace *as, hwadd= r addr, MemTxAttrs attrs, } } =20 +MemTxResult address_space_set(AddressSpace *as, hwaddr addr, + uint8_t c, hwaddr len, MemTxAttrs attrs) +{ +#define FILLBUF_SIZE 512 + uint8_t fillbuf[FILLBUF_SIZE]; + int l; + MemTxResult error =3D MEMTX_OK; + + memset(fillbuf, c, FILLBUF_SIZE); + while (len > 0) { + l =3D len < FILLBUF_SIZE ? len : FILLBUF_SIZE; + error |=3D address_space_write(as, addr, attrs, fillbuf, l); + len -=3D l; + addr +=3D l; + } + + return error; +} + void cpu_physical_memory_rw(hwaddr addr, void *buf, hwaddr len, bool is_write) { --=20 2.26.3 From nobody Sun May 19 02:06:42 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=1618481180; cv=none; d=zohomail.com; s=zohoarc; b=UHWNXZNIjD+XTAU3/Ri/RfNNt54x2e1WcfTiDOkHIADGAYFI6Px0dl1uQdD3yx3qlkB5hPwyU5imRf2umKIixWXV0SUpN7Brs0hQe0wC8YCfVEh2t9tTbVfSJni79bUKkSWuhIEgTS/8aH5zCwIndeBqMSpplxa4w+oh1fmHIJw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1618481180; 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=Y6NcfPnX58PUNNb+XCoT+Nl0nuOTzq38YXDKZavXEJg=; b=XOU5ZQH4c4/94co+CWIRkvU4dETcAlSGM6DT1M7jdEAKhvkzVpihDcCCNr1uvq8XHcIuEWDqbB81i1GTMd/JLlII8kND3FoDoS47gV1x+Ha0RCE6QswMFfYa32DCPoBDC65qjEJSinp9v+WEL6Y5BKPGPP7hbqZK9eHIFefQasU= 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 1618481180203349.66184203979833; Thu, 15 Apr 2021 03:06:20 -0700 (PDT) Received: from localhost ([::1]:45540 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lWyt8-0002t6-Pi for importer@patchew.org; Thu, 15 Apr 2021 06:06:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38252) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lWyrM-00020y-P0 for qemu-devel@nongnu.org; Thu, 15 Apr 2021 06:04:28 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:60319) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lWyrL-000543-7z for qemu-devel@nongnu.org; Thu, 15 Apr 2021 06:04:28 -0400 Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-319-wWipi7rnM3aEEL5pYdEYRg-1; Thu, 15 Apr 2021 06:04:23 -0400 Received: by mail-wm1-f72.google.com with SMTP id g144-20020a1c20960000b029012983de0c8fso2497621wmg.7 for ; Thu, 15 Apr 2021 03:04:22 -0700 (PDT) Received: from localhost.localdomain (39.red-81-40-121.staticip.rima-tde.net. [81.40.121.39]) by smtp.gmail.com with ESMTPSA id o15sm1829263wmh.19.2021.04.15.03.04.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Apr 2021 03:04:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1618481066; 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=Y6NcfPnX58PUNNb+XCoT+Nl0nuOTzq38YXDKZavXEJg=; b=ZPk8v9NYP9AuBSNnUxl7i8ImGgNIqYy+P+/aQfs218ekxSGAH8AcL9KD+fa7ns/FYumVoI /NhR8GlgAet5Blklv5lWwEWubdkqHklppNS0zs1jJ8K0nhUvmd8+a2cv2D4mirm/S6dp8x g06LDLswDd6hpB+sgR/PE2cZ9fcjwaw= X-MC-Unique: wWipi7rnM3aEEL5pYdEYRg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Y6NcfPnX58PUNNb+XCoT+Nl0nuOTzq38YXDKZavXEJg=; b=pqOZRLfvRVaTT1hIP1dflTBl40BkxvIfsRQTBPzsERdCRTJ8F98EE9N0WdmQg1yA+J TtsUjIdJotol8+YCFqikWqGd2nKxhbekAS6cFeMVG7iEVO1IFCKHfVq5IxzCZLDRoYJ7 UUfdcBQIT0gihC2wDVMNB8VCRkYyIQ7WKxnWhJr6R5jN/3VVzCVnldMExKuNE0p9CAEC OdYFayoVCaS8zcpbmvGQJNC7CI6hEy/CCBXt8WohJnNZtB1CPQJw6iTqi9H0Np8lw7Oa yTr0/hegsS7H0VSH3A1mLrhvjCEW48GEOoUZD8Y90dIAngrXy124gjIKfLLuKeI4rdds BwDQ== X-Gm-Message-State: AOAM531i64TcBCot0pbbQ/dkMUpUcDCBLKT4aGleoD9rRmK/BzWa2Lu4 YnCQeBbKFqe1/n767rQuiSo8m3fYY3XGe5EcY7vn00RyOKunUdq5CzK7xjP2IT/uv7PNEKZUwMZ JmGtnXT3Jb5UlIRo= X-Received: by 2002:a05:6000:190:: with SMTP id p16mr2593684wrx.334.1618481061953; Thu, 15 Apr 2021 03:04:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyNYIGPADq1ypkdUhki55um+/Ri0irObaZG6eSjs5x4LofeT5JM2oEkgcXmpIEfbbZnlJzfPg== X-Received: by 2002:a05:6000:190:: with SMTP id p16mr2593667wrx.334.1618481061801; Thu, 15 Apr 2021 03:04:21 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: Stefano Garzarella , Laurent Vivier , qemu-devel@nongnu.org Subject: [PATCH v2 2/2] hw/elf_ops: clear uninitialized segment space Date: Thu, 15 Apr 2021 12:04:09 +0200 Message-Id: <20210415100409.3977971-3-philmd@redhat.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210415100409.3977971-1-philmd@redhat.com> References: <20210415100409.3977971-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" 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=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com 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.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, 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: Peter Maydell , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Laurent Vivier When the mem_size of the segment is bigger than the file_size, and if this space doesn't overlap another segment, it needs to be cleared. This bug is very similar to the one we had for linux-user, 22d113b52f41 ("linux-user: Fix loading of BSS segments"), where .bss section is encoded as an extension of the the data one by setting the segment p_memsz > p_filesz. Signed-off-by: Laurent Vivier Message-Id: <20210414105838.205019-1-laurent@vivier.eu> [PMD: Use recently added address_space_set()] Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Richard Henderson Reviewed-by: Stefano Garzarella --- include/hw/elf_ops.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/include/hw/elf_ops.h b/include/hw/elf_ops.h index 6ee458e7bc3..29f4c43e231 100644 --- a/include/hw/elf_ops.h +++ b/include/hw/elf_ops.h @@ -562,6 +562,19 @@ static int glue(load_elf, SZ)(const char *name, int fd, if (res !=3D MEMTX_OK) { goto fail; } + /* + * We need to zero'ify the space that is not copied + * from file + */ + if (file_size < mem_size) { + res =3D address_space_set(as ? as : &address_space= _memory, + addr + file_size, 0, + mem_size - file_size, + MEMTXATTRS_UNSPECIFIED); + if (res !=3D MEMTX_OK) { + goto fail; + } + } } } =20 --=20 2.26.3