{"id":2215427,"url":"http://patchwork.ozlabs.org/api/patches/2215427/?format=json","web_url":"http://patchwork.ozlabs.org/project/qemu-devel/patch/20260324151323.74473-11-mohamed@unpredictable.fr/","project":{"id":14,"url":"http://patchwork.ozlabs.org/api/projects/14/?format=json","name":"QEMU Development","link_name":"qemu-devel","list_id":"qemu-devel.nongnu.org","list_email":"qemu-devel@nongnu.org","web_url":"","scm_url":"","webscm_url":"","list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<20260324151323.74473-11-mohamed@unpredictable.fr>","list_archive_url":null,"date":"2026-03-24T15:13:21","name":"[v3,10/12] target/i386: emulate: segmentation rework","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"559464fcbdb05f9d3b4030dad4c157e4c0656287","submitter":{"id":91318,"url":"http://patchwork.ozlabs.org/api/people/91318/?format=json","name":"Mohamed Mediouni","email":"mohamed@unpredictable.fr"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/qemu-devel/patch/20260324151323.74473-11-mohamed@unpredictable.fr/mbox/","series":[{"id":497303,"url":"http://patchwork.ozlabs.org/api/series/497303/?format=json","web_url":"http://patchwork.ozlabs.org/project/qemu-devel/list/?series=497303","date":"2026-03-24T15:13:13","name":"whpx: i386: Windows 10 and performance fixes","version":3,"mbox":"http://patchwork.ozlabs.org/series/497303/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2215427/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2215427/checks/","tags":{},"related":[],"headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=unpredictable.fr header.i=@unpredictable.fr\n header.a=rsa-sha256 header.s=sig1 header.b=eEZLsnY4;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org\n (client-ip=209.51.188.17; helo=lists.gnu.org;\n envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n receiver=patchwork.ozlabs.org)"],"Received":["from lists.gnu.org (lists.gnu.org [209.51.188.17])\n\t(using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fgDC64QkDz1xy1\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 25 Mar 2026 02:16:18 +1100 (AEDT)","from localhost ([::1] helo=lists1p.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.90_1)\n\t(envelope-from <qemu-devel-bounces@nongnu.org>)\n\tid 1w53U5-0007At-D6; Tue, 24 Mar 2026 11:15:57 -0400","from eggs.gnu.org ([2001:470:142:3::10])\n by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)\n (Exim 4.90_1) (envelope-from <mohamed@unpredictable.fr>)\n id 1w53T3-0005vY-Rc\n for qemu-devel@nongnu.org; Tue, 24 Mar 2026 11:14:57 -0400","from p-east2-cluster2-host8-snip4-5.eps.apple.com ([57.103.78.58]\n helo=outbound.st.icloud.com)\n by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)\n (Exim 4.90_1) (envelope-from <mohamed@unpredictable.fr>)\n id 1w53Sz-0005tL-4f\n for qemu-devel@nongnu.org; Tue, 24 Mar 2026 11:14:51 -0400","from outbound.st.icloud.com (unknown [127.0.0.2])\n by p00-icloudmta-asmtp-us-east-1a-60-percent-7 (Postfix) with ESMTPS id\n 1A4E11800348; Tue, 24 Mar 2026 15:14:35 +0000 (UTC)","from localhost.localdomain (unknown [17.42.251.67])\n by p00-icloudmta-asmtp-us-east-1a-60-percent-7 (Postfix) with ESMTPSA id\n ECE0718094D2; Tue, 24 Mar 2026 15:13:54 +0000 (UTC)"],"Dkim-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr;\n s=sig1; t=1774365276; x=1776957276;\n bh=vl9gr3/Etwc2CL3Gr9sJC1zQGi6Rjmv81TXMHG3rpEg=;\n h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme;\n b=eEZLsnY4V+sml3LuUNQkmqyIvf9YdO2d8oLs3e/zq53PUPLG0z2RLE68ebPmln6teg33CEK4JdvfNHh7gr0PxNPN1OZEyedC8t73qjgRy2Twlr8P2yQ1/Ekj6jFC2PQE1js7AAzXnvtPgjmfJ1/QXs04iC/TpYwEAYMmqTSm/howrTQ3jP6SSliMV/oDXigI/VElpbYpkMGMWFLmXnbPH1zRXl/SItG+n6d6IJHORC5klpJK7JQqX76FIFGOy3BO6pP3rOnE9HcHQ+TIDtDijyl9Mp431p0yUAG5ObJiFe84wbchom0+qsSo5vSBxxbkEViwW4l/wepD5nLWJt1KRg==","mail-alias-created-date":"1752046281608","From":"Mohamed Mediouni <mohamed@unpredictable.fr>","To":"qemu-devel@nongnu.org","Cc":"Roman Bolshakov <rbolshakov@ddn.com>,\n Mohamed Mediouni <mohamed@unpredictable.fr>, Wei Liu <wei.liu@kernel.org>,\n Phil Dennis-Jordan <phil@philjordan.eu>,\n Pedro Barbuda <pbarbuda@microsoft.com>","Subject":"[PATCH v3 10/12] target/i386: emulate: segmentation rework","Date":"Tue, 24 Mar 2026 16:13:21 +0100","Message-ID":"<20260324151323.74473-11-mohamed@unpredictable.fr>","X-Mailer":"git-send-email 2.50.1","In-Reply-To":"<20260324151323.74473-1-mohamed@unpredictable.fr>","References":"<20260324151323.74473-1-mohamed@unpredictable.fr>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","X-Proofpoint-ORIG-GUID":"OPcY04fxywMQY_h8Bqromc5U6eDJEfiv","X-Authority-Info-Out":"v=2.4 cv=bYRmkePB c=1 sm=1 tr=0 ts=69c2aa5c\n cx=c_apl:c_pps:t_out a=YrL12D//S6tul8v/L+6tKg==:117\n a=YrL12D//S6tul8v/L+6tKg==:17 a=Yq5XynenixoA:10 a=VkNPw1HP01LnGYTKEx00:22\n a=vJJf33RnEMvZLxG4ysEA:9","X-Proofpoint-GUID":"OPcY04fxywMQY_h8Bqromc5U6eDJEfiv","X-Proofpoint-Spam-Details-Enc":"AW1haW4tMjYwMzI0MDExOSBTYWx0ZWRfX8jbnFCHPqq4n\n 6P8xW1exmYdrXC1pSPyEU3hlBpQaAa83UzCX4XrrzQzajnzshNhOzK5HY/552XzTCh2spVLcjhj\n P4qZ7j4PRJYQjhtpw99IDQIQVC5XxUOJLjB+egwphNsPo6LW1zv23qLfW3q/nQ+H/gByVg5qLP/\n nn9jIQZyU2Y3TqHxoMMA/8LiZE/5bdIkX51ImYcVdMi424pPn4sbtsTrOM1d4qhCrBoP9ta7irz\n zJakLqoN8pnBJztxPwbqmIcztgXC/1ycC9bUp8PTUUALuObgcTMAXbh/Bpj75p3xA/ZkrUl/OPC\n 8EjYfpB3z9Fk9gAmvq623r3VHh+ldMqL/gnMrbxVQeD0k+LyTcMngXFT/wzFXo=","X-Proofpoint-Virus-Version":"vendor=baseguard\n engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49\n definitions=2026-03-24_03,2026-03-23_02,2025-10-01_01","X-Proofpoint-Spam-Details":"rule=notspam policy=default score=0 spamscore=0\n lowpriorityscore=0 adultscore=0 phishscore=0 bulkscore=0 malwarescore=0\n clxscore=1030 mlxlogscore=999 suspectscore=0 mlxscore=0 classifier=spam\n authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000\n definitions=main-2603240119","Received-SPF":"pass client-ip=57.103.78.58;\n envelope-from=mohamed@unpredictable.fr; helo=outbound.st.icloud.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, DKIM_SIGNED=0.1,\n DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,\n RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001,\n RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-0.001,\n 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.29","Precedence":"list","List-Id":"qemu development <qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<https://lists.nongnu.org/archive/html/qemu-devel>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n <mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org"},"content":"Make accesses to segments all go through read_segment_descriptor\nto be able to fetch segment state on-demand.\n\nSwitch away from SegmentCache to the x86_segment_descriptor\nthat is already used by read_segment_descriptor.\n\nSigned-off-by: Mohamed Mediouni <mohamed@unpredictable.fr>\n---\n target/i386/emulate/x86_helpers.c | 50 ++++++++++++-------------------\n 1 file changed, 19 insertions(+), 31 deletions(-)","diff":"diff --git a/target/i386/emulate/x86_helpers.c b/target/i386/emulate/x86_helpers.c\nindex c817015ef9..63bae3582f 100644\n--- a/target/i386/emulate/x86_helpers.c\n+++ b/target/i386/emulate/x86_helpers.c\n@@ -43,49 +43,37 @@ static CpuMode cpu_mode(CPUState *cpu)\n     return m;\n }\n \n-static bool segment_type_ro(const SegmentCache *seg)\n+static bool segment_type_ro(const x86_segment_descriptor desc)\n {\n-    uint32_t type_ = (seg->flags >> DESC_TYPE_SHIFT) & 15;\n+    uint32_t type_ = desc.type;\n     return (type_ & (~RWRX_SEGMENT_TYPE)) == 0;\n }\n \n-static bool segment_type_code(const SegmentCache *seg)\n+static bool segment_type_code(const x86_segment_descriptor desc)\n {\n-    uint32_t type_ = (seg->flags >> DESC_TYPE_SHIFT) & 15;\n+    uint32_t type_ = desc.type;\n     return (type_ & CODE_SEGMENT_TYPE) != 0;\n }\n \n-static bool segment_expands_down(const SegmentCache *seg)\n+static bool segment_expands_down(const x86_segment_descriptor desc)\n {\n-    uint32_t type_ = (seg->flags >> DESC_TYPE_SHIFT) & 15;\n+    uint32_t type_ = desc.type;\n \n-    if (segment_type_code(seg)) {\n+    if (segment_type_code(desc)) {\n         return false;\n     }\n \n     return (type_ & EXPAND_DOWN_SEGMENT_TYPE) != 0;\n }\n \n-static uint32_t segment_limit(const SegmentCache *seg)\n+static uint8_t segment_db(const x86_segment_descriptor desc)\n {\n-    uint32_t limit = seg->limit;\n-    uint32_t granularity = (seg->flags & DESC_G_MASK) != 0;\n-\n-    if (granularity != 0) {\n-        limit = (limit << 12) | 0xFFF;\n-    }\n-\n-    return limit;\n+    return desc.db;\n }\n \n-static uint8_t segment_db(const SegmentCache *seg)\n+static uint32_t segment_max_limit(const x86_segment_descriptor desc)\n {\n-    return (seg->flags >> DESC_B_SHIFT) & 1;\n-}\n-\n-static uint32_t segment_max_limit(const SegmentCache *seg)\n-{\n-    if (segment_db(seg) != 0) {\n+    if (segment_db(desc) != 0) {\n         return 0xFFFFFFFF;\n     }\n     return 0xFFFF;\n@@ -96,15 +84,15 @@ static int linearize(CPUState *cpu,\n                      X86Seg seg_idx)\n {\n     enum CpuMode mode;\n-    X86CPU *x86_cpu = X86_CPU(cpu);\n-    CPUX86State *env = &x86_cpu->env;\n-    SegmentCache *seg = &env->segs[seg_idx];\n-    target_ulong base = seg->base;\n+    struct x86_segment_descriptor desc;\n+    target_ulong base;\n     target_ulong logical_addr_32b;\n     uint32_t limit;\n     /* TODO: the emulator will not pass us \"write\" indicator yet */\n     bool write = false;\n \n+    emul_ops->read_segment_descriptor(cpu, &desc, seg_idx);\n+    base = x86_segment_base(&desc);\n     mode = cpu_mode(cpu);\n \n     switch (mode) {\n@@ -116,21 +104,21 @@ static int linearize(CPUState *cpu,\n         break;\n     case PROTECTED_MODE:\n     case REAL_MODE:\n-        if (segment_type_ro(seg) && write) {\n+        if (segment_type_ro(desc) && write) {\n             error_report(\"Cannot write to read-only segment\");\n             return -1;\n         }\n \n         logical_addr_32b = logical_addr & 0xFFFFFFFF;\n-        limit = segment_limit(seg);\n+        limit = x86_segment_limit(&desc);\n \n-        if (segment_expands_down(seg)) {\n+        if (segment_expands_down(desc)) {\n             if (logical_addr_32b >= limit) {\n                 error_report(\"Address exceeds limit (expands down)\");\n                 return -1;\n             }\n \n-            limit = segment_max_limit(seg);\n+            limit = segment_max_limit(desc);\n         }\n \n         if (logical_addr_32b > limit) {\n","prefixes":["v3","10/12"]}