From nobody Fri May 17 11:28:58 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=163.com ARC-Seal: i=1; a=rsa-sha256; t=1690291144; cv=none; d=zohomail.com; s=zohoarc; b=R9PWc9sfQbybyyRCf69WkSSHZdBYhbra1Hh++M/ubFlVT4uTiojOwwqaesWkSmkXKjYx9MA/RIMcbjGSvrONSKuO/P8Ilx4p85E5qpTaGtDLuC/uX3riAi057zVqYQMcE1L4u3RyieSZW+W3T+UnRV4NjO+nuR3KUzJVCgFKwY8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1690291144; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=Vz5FKixIE6aCmdk5wAjaQcgYA4OVhMfXpHBQt53Sfg0=; b=ciHzj/s79qMt9Omr0C+jFvcSg/oyMTEHXLkh6OvsZOxhMVkXfvpOluPF8NawXVNHnIPXRxSezJ7Yco8yQm3OksUIkz27DN6DDnLYd/2/Tb8mSG/4YjufwlQqepAERMaZEHP6Phf7amoaJCB57u7vTucyALTjUBuVIIZKsiwEZew= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1690291144764485.5609842770832; Tue, 25 Jul 2023 06:19:04 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qOHvl-0002Pf-SA; Tue, 25 Jul 2023 09:18:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qOFfE-0003ez-41 for qemu-devel@nongnu.org; Tue, 25 Jul 2023 06:53:12 -0400 Received: from m12.mail.163.com ([220.181.12.196]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qOFfB-00051O-Go for qemu-devel@nongnu.org; Tue, 25 Jul 2023 06:53:11 -0400 Received: from localhost.localdomain (unknown [183.242.254.172]) by zwqz-smtp-mta-g5-2 (Coremail) with SMTP id _____wBXSwWEqb9k3ec2BQ--.34558S2; Tue, 25 Jul 2023 18:52:53 +0800 (CST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=Vz5FK ixIE6aCmdk5wAjaQcgYA4OVhMfXpHBQt53Sfg0=; b=MiMf8Ig7W9nIOhXY1ETPX LePhqNlOp/RPUatKyOZqXwhsWuoj80JdEPi/8YW4RLnszlydH4SSrY5SMq2uMVz6 OKT4oD0E9mq7wcPFEcpZHTKEVvPPLdeV9gu/NsIHiJBuOXroM/M/S4ry471AWkST gC1dHPf91T9cWhh4oILBkQ= From: Thiner Logoer To: qemu-devel@nongnu.org Cc: david@redhat.com, imammedo@redhat.com, Thiner Logoer Subject: [PATCH] Open file as read only on private mapping in qemu_ram_alloc_from_file Date: Tue, 25 Jul 2023 10:52:39 +0000 Message-Id: <20230725105239.2022-1-logoerthiner1@163.com> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: _____wBXSwWEqb9k3ec2BQ--.34558S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7JryUuryrGry8KF4xZr17Awb_yoW8Jry8pr Z3Grn0krnY9a92va1kt3WYqFyrGa48GFy8XFZ3uryDXFsxWw1v9F40k34FgFnFqFyxJrsx Za17Ka4DWF47C3DanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zE_OzQUUUUU= X-Originating-IP: [183.242.254.172] X-CM-SenderInfo: 5orj0vpuwkx0thurqiywtou0bp/xtbBZgS3nlaEEW9aMAAAsN 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=220.181.12.196; envelope-from=logoerthiner1@163.com; helo=m12.mail.163.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Tue, 25 Jul 2023 09:18:23 -0400 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @163.com) X-ZM-MESSAGEID: 1690291146036100001 Content-Type: text/plain; charset="utf-8" An read only file can be mapped with read write as long as the mapping is private, which is very common case. Make qemu_ram_alloc_from_file open file as read only when the mapping is private, otherwise open will fail when file does not allow write. If this file does not exist or is a directory, the flag is not used, so it should be OK. from https://gitlab.com/qemu-project/qemu/-/issues/1689 Signed-off-by: Thiner Logoer --- softmmu/physmem.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/softmmu/physmem.c b/softmmu/physmem.c index 3df73542e1..e8036ee335 100644 --- a/softmmu/physmem.c +++ b/softmmu/physmem.c @@ -1945,8 +1945,15 @@ RAMBlock *qemu_ram_alloc_from_file(ram_addr_t size, = MemoryRegion *mr, int fd; bool created; RAMBlock *block; + =20 + /* + * If map is private, the fd does not need to be writable. + * This only get effective when the file is existent. + */ + bool open_as_readonly =3D readonly || !(ram_flags & RAM_SHARED); =20 - fd =3D file_ram_open(mem_path, memory_region_name(mr), readonly, &crea= ted, + fd =3D file_ram_open(mem_path, memory_region_name(mr), + open_as_readonly, &created, errp); if (fd < 0) { return NULL; --=20 2.40.1