From nobody Sun May 19 14:40:04 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=1690386515; cv=none; d=zohomail.com; s=zohoarc; b=Xor94ZoEg1Yxkmq4ymCLS4NMwr1gTNJdU/ktcvbxb3fa36Sbpteo8DcGp+8NDXyyM93MUmgMi9OFdPYJTil3oJjjiK//G2qgPikfdM3+2+XOu6w/arHwyAjcoQZnYuFBHmk7qasWXnM/wHggkC9TmDxBFr6+EA15ncTke/BgCNI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1690386515; 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=dYdqcE4/UlRL/8jH464mNjfvncT7PDOJd3UbhFuphVo=; b=IiczYMv7qZAI8kXMKayWhA9aIxt9beHtnCIdLzF+dbI7s6PxA2GZ6YBajU/0vg1cI05SFR3kpT9TIdRRXeMioIfNzwvACFq1cP3JC5bXghNBjUeabywIgsim3H/k8XsaerrAUTNZV8uqJfXl2dOc+b8Qu3AGMtS68uk9KNtCxZc= 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 169038651520158.38984358767436; Wed, 26 Jul 2023 08:48:35 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qOfzw-00070P-0a; Wed, 26 Jul 2023 11:00:20 -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 1qOfzI-0006VN-IT for qemu-devel@nongnu.org; Wed, 26 Jul 2023 10:59:41 -0400 Received: from m12.mail.163.com ([220.181.12.217]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qOfzE-0003RU-Cn for qemu-devel@nongnu.org; Wed, 26 Jul 2023 10:59:40 -0400 Received: from localhost.localdomain (unknown [183.242.254.172]) by zwqz-smtp-mta-g2-1 (Coremail) with SMTP id _____wB3DOrNNMFkB6OIBQ--.32996S2; Wed, 26 Jul 2023 22:59:26 +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=dYdqc E4/UlRL/8jH464mNjfvncT7PDOJd3UbhFuphVo=; b=p3pkuwhMTHzO9iFANtg3p zInoFwOOORzZ28QvF/dp6LO21wtF8ONmDVOifFa2CUxeYDEAPnpVLDBM6wKP8Hpd 7hn83zSjLe4t1tDmuuNLdxP/YUzsQAwKAVEbXGEIk4PIiSRKoeguvy3XLQmxqoP4 BnGWxgz9YWISpgf7dODd7k= From: Thiner Logoer To: qemu-devel@nongnu.org Cc: david@redhat.com, imammedo@redhat.com, Thiner Logoer Subject: [PATCH v2] softmmu/physmem: try opening file readonly before failure in file_ram_open Date: Wed, 26 Jul 2023 14:59:12 +0000 Message-Id: <20230726145912.88545-1-logoerthiner1@163.com> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: _____wB3DOrNNMFkB6OIBQ--.32996S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7tFWrZF4fWw45tr13KrWxJFb_yoW8ZrWfp3 yrGrn8tr4vyr43ArsI9F9a9Fy5tr97JFn0grWrA348Gr98W3WxuFW0gr1YgFy3ZryxGFW7 Zw4UWF97u39xGrJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zij2M8UUUUU= X-Originating-IP: [183.242.254.172] X-CM-SenderInfo: 5orj0vpuwkx0thurqiywtou0bp/1tbiKRC4nlXl6l8+1wAAsz 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.217; 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, RCVD_IN_MSPIKE_BL=0.001, RCVD_IN_MSPIKE_L4=0.001, 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-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: 1690386515815100001 Content-Type: text/plain; charset="utf-8" Users may give "-mem-path" a read only file and expect the file to be mapped read-write privately. Allow this but give a warning since other users may surprise when the ram file is readonly and qemu suddenly aborts elsewhere. Suggested-by: David Hildenbrand Signed-off-by: Thiner Logoer Reported-by: Thiner Logoer --- See the previous version at: https://lore.kernel.org/qemu-devel/96a462ec-6f9d-fd83-f697-73e132432ca4@red= hat.com/T/ verified, this patch works for my setup, both functionality and the warning are expected behavior. Also another problem when I look at the file_ram_open When readonly is true and the path is a directory, the open will succeed but any later operations will fail since it is a directory fd. This may require additional commits which is out of my scope. Merely record the question her= e. softmmu/physmem.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/softmmu/physmem.c b/softmmu/physmem.c index 3df73542e1..e8279d69d4 100644 --- a/softmmu/physmem.c +++ b/softmmu/physmem.c @@ -1296,6 +1296,7 @@ static int file_ram_open(const char *path, char *sanitized_name; char *c; int fd =3D -1; + bool first_trial =3D true; =20 *created =3D false; for (;;) { @@ -1332,6 +1333,18 @@ static int file_ram_open(const char *path, break; } g_free(filename); + } else if (first_trial && !readonly && errno =3D=3D EACCES) { + /* @path may be a read only file */ + fd =3D open(path, O_RDONLY); + if (fd >=3D 0) { + /* + * Sometimes this behavior is not desired. Fire a warning = but + * continue. + */ + warn_report("backing store %s is opened readonly because t= he" + "file is not writable", path); + break; + } } if (errno !=3D EEXIST && errno !=3D EINTR) { error_setg_errno(errp, errno, @@ -1343,6 +1356,7 @@ static int file_ram_open(const char *path, * Try again on EINTR and EEXIST. The latter happens when * something else creates the file between our two open(). */ + first_trial =3D false; } =20 return fd; --=20 2.40.1