From nobody Tue Nov 26 06:47:38 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1709107658; cv=none; d=zohomail.com; s=zohoarc; b=htjwe8LZ4giluy2tCSSqXg9GeZsOKOBoNrf04Q9YLfrOuyAwFmF+dW/QwI+j5uSVizGK4yI+9etwQxMDbIdFDJPO164AY3OmblDopLcX8wkYFFlywpEWOBPye1TTY+2q+Kv65VpB9FquGtz6jHW+sZZij/XQQYMsR2t5jy88Lpg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709107658; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=ueI10wMn0YbFPSAUc+Z6vQJJhHpFqUppGs+kMeA8Nqg=; b=Th9LTvB6T+HclvN5/gdBd87DdDTInfctyhaHrVAYx28BYZw+4KXxPNYGbOdwlRomoWM93mmj7Le83H8WAoJf1kP/Sw3AkzulDxjlbYjDDYU30eWpwU20Mr/+9W1I32DD0Pn0MkrLPeC987wVg48s9NZMY1a+/7lGgd5wgkbkwH8= 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 1709107658280599.3040088088045; Wed, 28 Feb 2024 00:07:38 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rfEy9-0001T8-Jm; Wed, 28 Feb 2024 03:07:13 -0500 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 1rfEy6-0001SL-Qy for qemu-devel@nongnu.org; Wed, 28 Feb 2024 03:07:12 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rfEy4-0000Rt-5M for qemu-devel@nongnu.org; Wed, 28 Feb 2024 03:07:09 -0500 Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-630-gfeOS0P1O1KFqSyvxRFZ-g-1; Wed, 28 Feb 2024 03:07:04 -0500 Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-a26f2da3c7bso349012366b.0 for ; Wed, 28 Feb 2024 00:07:03 -0800 (PST) Received: from [192.168.10.118] ([93.56.170.180]) by smtp.gmail.com with ESMTPSA id rf20-20020a1709076a1400b00a43e6c2e107sm627973ejc.189.2024.02.28.00.06.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 00:06:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709107625; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ueI10wMn0YbFPSAUc+Z6vQJJhHpFqUppGs+kMeA8Nqg=; b=L+j75pYfFP05Nr8P+5NSXsILeW/WsqkfNHq8SVbtTQJ5T66alfSibYbSD2vlUTzxTF8bkU PQ+9XZznM5l6ztTf7DEsGx5jDr68kAJuiAwiJiI5BmXcATSxWA9umIMPn28bhldRHPl3vS g4hqTYcdGwIz62e8WD0iNSICT/UUdDw= X-MC-Unique: gfeOS0P1O1KFqSyvxRFZ-g-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709107621; x=1709712421; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ueI10wMn0YbFPSAUc+Z6vQJJhHpFqUppGs+kMeA8Nqg=; b=WFAuFQw2x5LQILdQt7uPqtwyZvXxUx5AfNVgTmnOWlWRbopVlNPIGqyp1IzQjVQcYR G0uydbHUUPRvPzpx1zhcMrZirYCxJ0/ZSTlOVvNT7jiaNBZlIB6jhjZDqpOeK2mo0kgN FSkck33Dtwq0sFI8AdJGz5vX84cunZopALm5fJ5Ei5AI1x+FRcv7pjzdn7E1whGfwbLV eKXbOSR+J8RFXRUiGGnvEMSw8vGiNuUGVAKHu73h5ibIhkBCVPqVBQShjwdZc8KGnWUG ziWeTKZ+nKKMk+pZgIXscpVHMCMWlZ3N1oKVvgIRSHRQC54nRiM7PWr9mmrQAuGQB1Zy anrQ== X-Gm-Message-State: AOJu0Yx0iamNzKz4polttoyF+eajcu779Mc5QEv8o7YN5zzDAYFiE4IG LGtSIRaoknpZnHhS8Tf/PF+Tt/6JrIezcsjcSHLgTpr7xMHdBhy9oY49Uat9fsi7FsXJVoH9S5n arHizjECdaGXDEssNTesbgaf2/OJvIRBBCHMdf1rWOqVQShTOFKckxQ0k/4dzqYYAyJp21QA/iP FOkTBb6naN1t0aYqVMQIF87AXWKMwUqjuDt9As X-Received: by 2002:a17:907:119b:b0:a38:916e:a4fe with SMTP id uz27-20020a170907119b00b00a38916ea4femr8208727ejb.39.1709107621307; Wed, 28 Feb 2024 00:07:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IGLbLyETl1ElnwzqODti0/JtBmXJ2jwESSsfT6xof9zgG9YRzWDCg36LCzw1BPukl+bb7HvDg== X-Received: by 2002:a17:907:119b:b0:a38:916e:a4fe with SMTP id uz27-20020a170907119b00b00a38916ea4femr8208709ejb.39.1709107620966; Wed, 28 Feb 2024 00:07:00 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PULL 01/10] vl, pc: turn -no-fd-bootchk into a machine property Date: Wed, 28 Feb 2024 09:06:37 +0100 Message-ID: <20240228080646.261365-2-pbonzini@redhat.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240228080646.261365-1-pbonzini@redhat.com> References: <20240228080646.261365-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.088, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=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 @redhat.com) X-ZM-MESSAGEID: 1709107658475100001 Add a fd-bootchk property to PC machine types, so that -no-fd-bootchk returns an error if the machine does not support booting from floppies and checking for boot signatures therein. Suggested-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Paolo Bonzini --- include/hw/i386/pc.h | 2 +- hw/i386/pc.c | 31 ++++++++++++++++++++++++++----- system/globals.c | 1 - system/vl.c | 2 +- qemu-options.hx | 2 +- 5 files changed, 29 insertions(+), 9 deletions(-) diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h index e88468131a5..034bef25f58 100644 --- a/include/hw/i386/pc.h +++ b/include/hw/i386/pc.h @@ -50,6 +50,7 @@ typedef struct PCMachineState { bool hpet_enabled; bool i8042_enabled; bool default_bus_bypass_iommu; + bool fd_bootchk; uint64_t max_fw_size; =20 /* ACPI Memory hotplug IO base address */ @@ -147,7 +148,6 @@ OBJECT_DECLARE_TYPE(PCMachineState, PCMachineClass, PC_= MACHINE) GSIState *pc_gsi_create(qemu_irq **irqs, bool pci_enabled); =20 /* pc.c */ -extern int fd_bootchk; =20 void pc_acpi_smi_interrupt(void *opaque, int irq, int level); =20 diff --git a/hw/i386/pc.c b/hw/i386/pc.c index f8eb684a492..ea3607452af 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -399,8 +399,8 @@ static int boot_device2nibble(char boot_device) return 0; } =20 -static void set_boot_dev(MC146818RtcState *s, const char *boot_device, - Error **errp) +static void set_boot_dev(PCMachineState *pcms, MC146818RtcState *s, + const char *boot_device, Error **errp) { #define PC_MAX_BOOT_DEVICES 3 int nbds, bds[3] =3D { 0, }; @@ -420,12 +420,14 @@ static void set_boot_dev(MC146818RtcState *s, const c= har *boot_device, } } mc146818rtc_set_cmos_data(s, 0x3d, (bds[1] << 4) | bds[0]); - mc146818rtc_set_cmos_data(s, 0x38, (bds[2] << 4) | (fd_bootchk ? 0x0 := 0x1)); + mc146818rtc_set_cmos_data(s, 0x38, (bds[2] << 4) | !pcms->fd_bootchk); } =20 static void pc_boot_set(void *opaque, const char *boot_device, Error **err= p) { - set_boot_dev(opaque, boot_device, errp); + PCMachineState *pcms =3D PC_MACHINE(current_machine); + + set_boot_dev(pcms, opaque, boot_device, errp); } =20 static void pc_cmos_init_floppy(MC146818RtcState *rtc_state, ISADevice *fl= oppy) @@ -619,7 +621,7 @@ void pc_cmos_init(PCMachineState *pcms, object_property_set_link(OBJECT(pcms), "rtc_state", OBJECT(s), &error_abort); =20 - set_boot_dev(s, MACHINE(pcms)->boot_config.order, &error_fatal); + set_boot_dev(pcms, s, MACHINE(pcms)->boot_config.order, &error_fatal); =20 val =3D 0; val |=3D 0x02; /* FPU is there */ @@ -1543,6 +1545,20 @@ static void pc_machine_set_vmport(Object *obj, Visit= or *v, const char *name, visit_type_OnOffAuto(v, name, &pcms->vmport, errp); } =20 +static bool pc_machine_get_fd_bootchk(Object *obj, Error **errp) +{ + PCMachineState *pcms =3D PC_MACHINE(obj); + + return pcms->fd_bootchk; +} + +static void pc_machine_set_fd_bootchk(Object *obj, bool value, Error **err= p) +{ + PCMachineState *pcms =3D PC_MACHINE(obj); + + pcms->fd_bootchk =3D value; +} + static bool pc_machine_get_smbus(Object *obj, Error **errp) { PCMachineState *pcms =3D PC_MACHINE(obj); @@ -1731,6 +1747,7 @@ static void pc_machine_initfn(Object *obj) #ifdef CONFIG_HPET pcms->hpet_enabled =3D true; #endif + pcms->fd_bootchk =3D true; pcms->default_bus_bypass_iommu =3D false; =20 pcms->pcspk =3D isa_new(TYPE_PC_SPEAKER); @@ -1878,6 +1895,10 @@ static void pc_machine_class_init(ObjectClass *oc, v= oid *data) NULL, NULL); object_class_property_set_description(oc, PC_MACHINE_SMBIOS_EP, "SMBIOS Entry Point type [32, 64]"); + + object_class_property_add_bool(oc, "fd-bootchk", + pc_machine_get_fd_bootchk, + pc_machine_set_fd_bootchk); } =20 static const TypeInfo pc_machine_info =3D { diff --git a/system/globals.c b/system/globals.c index b6d4e72530e..5d0046ba105 100644 --- a/system/globals.c +++ b/system/globals.c @@ -41,7 +41,6 @@ int vga_interface_type =3D VGA_NONE; bool vga_interface_created; Chardev *parallel_hds[MAX_PARALLEL_PORTS]; int win2k_install_hack; -int fd_bootchk =3D 1; int graphic_rotate; QEMUOptionRom option_rom[MAX_OPTION_ROMS]; int nb_option_roms; diff --git a/system/vl.c b/system/vl.c index b8469d9965d..98bf0c386b4 100644 --- a/system/vl.c +++ b/system/vl.c @@ -2927,7 +2927,7 @@ void qemu_init(int argc, char **argv) optarg, FD_OPTS); break; case QEMU_OPTION_no_fd_bootchk: - fd_bootchk =3D 0; + qdict_put_str(machine_opts_dict, "fd-bootchk", "off"); break; case QEMU_OPTION_netdev: default_net =3D 0; diff --git a/qemu-options.hx b/qemu-options.hx index 9be1e5817c7..1136642c21d 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -2650,7 +2650,7 @@ DEF("no-fd-bootchk", 0, QEMU_OPTION_no_fd_bootchk, SRST ``-no-fd-bootchk`` Disable boot signature checking for floppy disks in BIOS. May be - needed to boot from old floppy disks. + needed to boot from old floppy disks. Synonym of ``-m fd-bootchk=3Dof= f``. ERST =20 DEF("acpitable", HAS_ARG, QEMU_OPTION_acpitable, --=20 2.43.2 From nobody Tue Nov 26 06:47:38 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1709107707; cv=none; d=zohomail.com; s=zohoarc; b=jDpvWG3IHoDeutAbIOxgdv+E7r3/LLaCc+DJpI/TKc/Bfr+7RhkrNNgKw+Xrk71b/2/Qx1xdXDVcqprhRTT3Mb+m1CNCYCUGB1oJikTUc6/KERQ/kusf2ViFDYx2ZwXZGObcwWJL9xEQvgbPeW3teAbFio01nY26MpdHnAmt/nU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709107707; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=DJU9e2eU5+KH4PwxmXgA5VX7eK+RWqpGt+HRjhX9ZFY=; b=aiNuWzOLLl/6oWog5REEJjWT1s8evXWowiFDrk+2k0U3iJq2vgxBfiX78hak6nffLRNieTOuXbw8TzO6ZOZMjwzaZW1ux7lFK0+CfcPC94+WsOqpPMJIrmaEHErN3wv95vzxQE9Ts8MaaO1VMdzjN6QERx9i2wQWfBK8qn831Os= 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 1709107707928270.53127226072945; Wed, 28 Feb 2024 00:08:27 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rfEyJ-0001Vp-Rz; Wed, 28 Feb 2024 03:07:23 -0500 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 1rfEyI-0001VA-81 for qemu-devel@nongnu.org; Wed, 28 Feb 2024 03:07:22 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rfEy5-0000Tr-Hu for qemu-devel@nongnu.org; Wed, 28 Feb 2024 03:07:21 -0500 Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-397-_6Z_a9gzPDWAqYMat0g7yg-1; Wed, 28 Feb 2024 03:07:07 -0500 Received: by mail-ed1-f71.google.com with SMTP id 4fb4d7f45d1cf-56421fd7029so2821372a12.3 for ; Wed, 28 Feb 2024 00:07:07 -0800 (PST) Received: from [192.168.10.118] ([93.56.170.180]) by smtp.gmail.com with ESMTPSA id if3-20020a0564025d8300b0056659364b0fsm761821edb.51.2024.02.28.00.07.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 00:07:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709107628; 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=DJU9e2eU5+KH4PwxmXgA5VX7eK+RWqpGt+HRjhX9ZFY=; b=DYPJ6dghZnGNbO7mlcazYoxOpC3vtV9SIU4UnmXQE502oPnPhtErm65/4KVgfieDu9YwUZ YbplIDevPDg96cO4MLNEFgmxnV7Gh80tVARKmOhD7BjXTEyqNdyoqeN8MscMmafCo6r7Ud 3cSofqRlsV1pFc20zj8J/OP9KlQgnfI= X-MC-Unique: _6Z_a9gzPDWAqYMat0g7yg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709107624; x=1709712424; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DJU9e2eU5+KH4PwxmXgA5VX7eK+RWqpGt+HRjhX9ZFY=; b=fMHgYe1yvobg3sCI69StYY+QuKmPeCyxCwYJstECUC3yERcK4VUvwwX9ZudV+fo/9B 0v/xhloaGei8m7OfUkxwofR2xjWR+bImzJ5OQ46oreEuo1HryBg2GPKDR/JcysZWa65e CPaPyGch7Rjb4ifpqGiIkcVTg4bUXmjvN8/D1kfHbeCThb3uLp79T+vGncSyBNmsp64y xdm6lxQnpq54FhDZlsVKpPqBDrYnWjhfv0R/wfKHJB5ClFcD+cxdYqKL26Q0tSnHi3oO u6ng1EV7H2DWJUI4aTgMPGa0XymwHgJOaLis8I5wwjrLIuPDUSFldAfgkdktW/RRcOQ5 rKHA== X-Gm-Message-State: AOJu0YwFkoJ79cicpWXkXJOr67kOi1yj+q/Ny+mzISShsu0F4Y2Iff94 7nyq+MDgN2eSaXGfpgqQTLiM+7rOb0QkLz8k5u4pBMhKRL3IQF7I9KCQKYpkfcaNH1TiNOM04nk YGsrAHmdpRViXpcPEvTeXsj72Av3ISgOZnNh+V7MaW3xoCtQfDxT5H04W1ULob45xFOSz5T27TG JISxUC6K9CnFNTaYn2IBbHLVzsKEbMLBBYfdpT X-Received: by 2002:a05:6402:612:b0:566:1fbd:22bb with SMTP id n18-20020a056402061200b005661fbd22bbmr3741352edv.9.1709107624615; Wed, 28 Feb 2024 00:07:04 -0800 (PST) X-Google-Smtp-Source: AGHT+IFZSHbHt0TIsRSGAMsv7rhypqyj7CyxCUJLj0jvvHR0qxNOdluvwXgYZfyXgAPsBY20YDOoew== X-Received: by 2002:a05:6402:612:b0:566:1fbd:22bb with SMTP id n18-20020a056402061200b005661fbd22bbmr3741332edv.9.1709107624196; Wed, 28 Feb 2024 00:07:04 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org, Richard Henderson Subject: [PULL 02/10] target/i386: mask high bits of CR3 in 32-bit mode Date: Wed, 28 Feb 2024 09:06:38 +0100 Message-ID: <20240228080646.261365-3-pbonzini@redhat.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240228080646.261365-1-pbonzini@redhat.com> References: <20240228080646.261365-1-pbonzini@redhat.com> MIME-Version: 1.0 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=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.088, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable 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 @redhat.com) X-ZM-MESSAGEID: 1709107708589100001 Content-Type: text/plain; charset="utf-8" CR3 bits 63:32 are ignored in 32-bit mode (either legacy 2-level paging or PAE paging). Do this in mmu_translate() to remove the last where get_physical_address() meaningfully drops the high bits of the address. Cc: qemu-stable@nongnu.org Suggested-by: Richard Henderson Fixes: 4a1e9d4d11c ("target/i386: Use atomic operations for pte updates", 2= 022-10-18) Signed-off-by: Paolo Bonzini --- target/i386/tcg/sysemu/excp_helper.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/target/i386/tcg/sysemu/excp_helper.c b/target/i386/tcg/sysemu/= excp_helper.c index 5b86f439add..11126c860d4 100644 --- a/target/i386/tcg/sysemu/excp_helper.c +++ b/target/i386/tcg/sysemu/excp_helper.c @@ -238,7 +238,7 @@ static bool mmu_translate(CPUX86State *env, const Trans= lateParams *in, /* * Page table level 3 */ - pte_addr =3D ((in->cr3 & ~0x1f) + ((addr >> 27) & 0x18)) & a20= _mask; + pte_addr =3D ((in->cr3 & 0xffffffe0ULL) + ((addr >> 27) & 0x18= )) & a20_mask; if (!ptw_translate(&pte_trans, pte_addr)) { return false; } @@ -306,7 +306,7 @@ static bool mmu_translate(CPUX86State *env, const Trans= lateParams *in, /* * Page table level 2 */ - pte_addr =3D ((in->cr3 & ~0xfff) + ((addr >> 20) & 0xffc)) & a20_m= ask; + pte_addr =3D ((in->cr3 & 0xfffff000ULL) + ((addr >> 20) & 0xffc)) = & a20_mask; if (!ptw_translate(&pte_trans, pte_addr)) { return false; } --=20 2.43.2 From nobody Tue Nov 26 06:47:38 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1709107710; cv=none; d=zohomail.com; s=zohoarc; b=APkC/kCKQt+DAHteRadS9kSK2PJ9ZJQcuYUnpoTFzIjj1iF8Gn7UDcWLitEFGpC6Aib/zjKexmOsZzEm835z4oiLBWLI1jUXViV4Btoq1KJVhZSb9aowj5hHFlHAVu6L20M8xE6n/u155Rxmbyjd094xpfMZnfaEXMaiGyiIsSM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709107710; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=s1yTfF9AGvoZg3IPbtvgG6CiruJp7O4UqyUWNdatiPc=; b=YLFCIzOmc1tTabXj+/pZ1rxbZGAs0aiEMZs9pdldcTXU6tyvZxcKaFQNxwyFia7yUzfPbCZtJ2eeLHJPWVLkz1ijSUiGcXUTU0OVs052fFOFWJMp7pV0H1geh97jpS6mPzsSay21wB/M9UIKF7dP8K8qZyz5uqfbxswNVB+1FGc= 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 1709107710456797.8521232430618; Wed, 28 Feb 2024 00:08:30 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rfEyJ-0001VY-9O; Wed, 28 Feb 2024 03:07:23 -0500 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 1rfEyH-0001V0-SJ for qemu-devel@nongnu.org; Wed, 28 Feb 2024 03:07:21 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rfEy8-0000Ug-1X for qemu-devel@nongnu.org; Wed, 28 Feb 2024 03:07:21 -0500 Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-378-aD5WQxfwMl64t6Ifk6vqww-1; Wed, 28 Feb 2024 03:07:09 -0500 Received: by mail-ed1-f70.google.com with SMTP id 4fb4d7f45d1cf-56588555f0bso2381467a12.0 for ; Wed, 28 Feb 2024 00:07:09 -0800 (PST) Received: from [192.168.10.118] ([93.56.170.180]) by smtp.gmail.com with ESMTPSA id ec31-20020a0564020d5f00b0056650cd0156sm860084edb.66.2024.02.28.00.07.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 00:07:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709107630; 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=s1yTfF9AGvoZg3IPbtvgG6CiruJp7O4UqyUWNdatiPc=; b=PTQgNSVXfEnUhffUNxTpO2EPWk6XQic4Bt2W+f9jf5cTgzkc2Go8C2z/5j4FebdaicxEoc C8KywFBn1gFx1Hu+ENlzbRmq+Jd1HqRY7rDdFxly2H8PNpbdI1RGjG6YZNX4BTdRVvZ/MI cCkGG2e/TZWi8+016hTW6tnXcndgS9A= X-MC-Unique: aD5WQxfwMl64t6Ifk6vqww-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709107627; x=1709712427; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=s1yTfF9AGvoZg3IPbtvgG6CiruJp7O4UqyUWNdatiPc=; b=RxgcxTfe8VtYDEVBcOk9W15FYctybXLs1Uh0LrQSNFPk7b0yoqSYigO6D3GTXIPW5l jvlF0TFDu4cAcHj35fULYvE2OMzLSuE7G0PWiWNbdyj7PQ0cKOpPPy3fMj9o8y6gzs3C Q4zjAzY+W7oSU3ol97KVywuYDX/+dMNTWAIlumTQpJIuE1ljJY9kntLEMaQQDwv4PIK2 UB1o59mMH6kUieuSnI9qtEtwlGiiu52Q7NDH+LPGPY0k7gy0PGlNMOK9mBN2eKcqGjDG bW8KFR/jOL0/nEhDJIEZTonTxanl521PLLkAqpYvCizPx1YnKZ92UQRNe/zES7713RYz zluw== X-Gm-Message-State: AOJu0YxeNYXO8cnekLEcKMRws3sX3bRNi9+oKOCxMUwB5izXMSq8r54W 2hrtWc48VJh+EJJEc+0WIfkmMegy4Bu3RhcVdl+6qG9CsMVOaOlruHNPQnVmday1hzwR2o4F5kE nQ3xwdKwsqDNi6w7M+gB8rVw+hoq5If3gO8LTug036iqeSWTqJ1iIu+E68P7SJpI9rV30YQK+8O 0tn+VgQG/KfeOCSMeR7kRWLxhTLrYllmCsMQMz X-Received: by 2002:aa7:d512:0:b0:566:3f3e:3a23 with SMTP id y18-20020aa7d512000000b005663f3e3a23mr2669150edq.1.1709107627738; Wed, 28 Feb 2024 00:07:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IEU8vtr1k3uZioNqXPSfBOX5lv+ZTqbemj61B0odAq3Ro9tEzJOwU8X4frSry+4MkFO4l4MJg== X-Received: by 2002:aa7:d512:0:b0:566:3f3e:3a23 with SMTP id y18-20020aa7d512000000b005663f3e3a23mr2669133edq.1.1709107627360; Wed, 28 Feb 2024 00:07:07 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org Subject: [PULL 03/10] target/i386: check validity of VMCB addresses Date: Wed, 28 Feb 2024 09:06:39 +0100 Message-ID: <20240228080646.261365-4-pbonzini@redhat.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240228080646.261365-1-pbonzini@redhat.com> References: <20240228080646.261365-1-pbonzini@redhat.com> MIME-Version: 1.0 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=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.088, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=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 @redhat.com) X-ZM-MESSAGEID: 1709107712644100007 Content-Type: text/plain; charset="utf-8" MSR_VM_HSAVE_PA bits 0-11 are reserved, as are the bits above the maximum physical address width of the processor. Setting them to 1 causes a #GP (see "15.30.4 VM_HSAVE_PA MSR" in the AMD manual). The same is true of VMCB addresses passed to VMRUN/VMLOAD/VMSAVE, even though the manual is not clear on that. Cc: qemu-stable@nongnu.org Fixes: 4a1e9d4d11c ("target/i386: Use atomic operations for pte updates", 2= 022-10-18) Signed-off-by: Paolo Bonzini --- target/i386/tcg/sysemu/misc_helper.c | 3 +++ target/i386/tcg/sysemu/svm_helper.c | 27 +++++++++++++++++++++------ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/target/i386/tcg/sysemu/misc_helper.c b/target/i386/tcg/sysemu/= misc_helper.c index 7de0a6e866d..edb7c3d8940 100644 --- a/target/i386/tcg/sysemu/misc_helper.c +++ b/target/i386/tcg/sysemu/misc_helper.c @@ -212,6 +212,9 @@ void helper_wrmsr(CPUX86State *env) tlb_flush(cs); break; case MSR_VM_HSAVE_PA: + if (val & (0xfff | ((~0ULL) << env_archcpu(env)->phys_bits))) { + goto error; + } env->vm_hsave =3D val; break; #ifdef TARGET_X86_64 diff --git a/target/i386/tcg/sysemu/svm_helper.c b/target/i386/tcg/sysemu/s= vm_helper.c index 32ff0dbb13c..5d6de2294fa 100644 --- a/target/i386/tcg/sysemu/svm_helper.c +++ b/target/i386/tcg/sysemu/svm_helper.c @@ -164,14 +164,19 @@ void helper_vmrun(CPUX86State *env, int aflag, int ne= xt_eip_addend) uint64_t new_cr3; uint64_t new_cr4; =20 - cpu_svm_check_intercept_param(env, SVM_EXIT_VMRUN, 0, GETPC()); - if (aflag =3D=3D 2) { addr =3D env->regs[R_EAX]; } else { addr =3D (uint32_t)env->regs[R_EAX]; } =20 + /* Exceptions are checked before the intercept. */ + if (addr & (0xfff | ((~0ULL) << env_archcpu(env)->phys_bits))) { + raise_exception_err_ra(env, EXCP0D_GPF, 0, GETPC()); + } + + cpu_svm_check_intercept_param(env, SVM_EXIT_VMRUN, 0, GETPC()); + qemu_log_mask(CPU_LOG_TB_IN_ASM, "vmrun! " TARGET_FMT_lx "\n", addr); =20 env->vm_vmcb =3D addr; @@ -463,14 +468,19 @@ void helper_vmload(CPUX86State *env, int aflag) int mmu_idx =3D MMU_PHYS_IDX; target_ulong addr; =20 - cpu_svm_check_intercept_param(env, SVM_EXIT_VMLOAD, 0, GETPC()); - if (aflag =3D=3D 2) { addr =3D env->regs[R_EAX]; } else { addr =3D (uint32_t)env->regs[R_EAX]; } =20 + /* Exceptions are checked before the intercept. */ + if (addr & (0xfff | ((~0ULL) << env_archcpu(env)->phys_bits))) { + raise_exception_err_ra(env, EXCP0D_GPF, 0, GETPC()); + } + + cpu_svm_check_intercept_param(env, SVM_EXIT_VMLOAD, 0, GETPC()); + if (virtual_vm_load_save_enabled(env, SVM_EXIT_VMLOAD, GETPC())) { mmu_idx =3D MMU_NESTED_IDX; } @@ -519,14 +529,19 @@ void helper_vmsave(CPUX86State *env, int aflag) int mmu_idx =3D MMU_PHYS_IDX; target_ulong addr; =20 - cpu_svm_check_intercept_param(env, SVM_EXIT_VMSAVE, 0, GETPC()); - if (aflag =3D=3D 2) { addr =3D env->regs[R_EAX]; } else { addr =3D (uint32_t)env->regs[R_EAX]; } =20 + /* Exceptions are checked before the intercept. */ + if (addr & (0xfff | ((~0ULL) << env_archcpu(env)->phys_bits))) { + raise_exception_err_ra(env, EXCP0D_GPF, 0, GETPC()); + } + + cpu_svm_check_intercept_param(env, SVM_EXIT_VMSAVE, 0, GETPC()); + if (virtual_vm_load_save_enabled(env, SVM_EXIT_VMSAVE, GETPC())) { mmu_idx =3D MMU_NESTED_IDX; } --=20 2.43.2 From nobody Tue Nov 26 06:47:38 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1709107729; cv=none; d=zohomail.com; s=zohoarc; b=H6tGQCyQ7tihXg0K9fSF2CrzzvXyfamI8GtMxI0gQe+J1zLa3L974M0ii/q1ixVr56/k5pBRmVJIBmwGHtc6Ynb8HuRDwOlX7CTSUmRqzAU42yZObaKV32++0AUricrZ/oSt3AQLfEOIXVZI74zuliQHKLV2XANBuoL3rxYOUYk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709107729; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To:Cc; bh=oaaGnvOvuEg+amyykEvtj5XWm41K6EEY0fV7AH7s47U=; b=A7dINo7kOAMMMLPcq7GFi//HMO89gkCST93PyaYuiQkbeu3oVTrYBS/VlgDyCvnWizExLXNEU5YZUTeB80bPU6VgV9KjJMEXCGBcrKuAUnzW3PvmLvHZJiGjJskzgFE2MR4IsntJeaikLQrOMnx4HyPFgFMa7tw3DIsnrLEN9F8= 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 1709107729641775.8388405562066; Wed, 28 Feb 2024 00:08:49 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rfEyK-0001W0-8z; Wed, 28 Feb 2024 03:07:24 -0500 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 1rfEyJ-0001Vk-MK for qemu-devel@nongnu.org; Wed, 28 Feb 2024 03:07:23 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rfEyA-0000W1-Jc for qemu-devel@nongnu.org; Wed, 28 Feb 2024 03:07:23 -0500 Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-73-yzQfujq3PdSkvfP4B65j-w-1; Wed, 28 Feb 2024 03:07:12 -0500 Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-a3e94bbb22dso367048866b.1 for ; Wed, 28 Feb 2024 00:07:11 -0800 (PST) Received: from [192.168.10.118] ([93.56.170.180]) by smtp.gmail.com with ESMTPSA id a5-20020a170906468500b00a3fb4d11809sm1581168ejr.204.2024.02.28.00.07.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 00:07:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709107633; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oaaGnvOvuEg+amyykEvtj5XWm41K6EEY0fV7AH7s47U=; b=YoiR+JpG1S8suB6FmGh+STBI0dKCecZHB6PMCvYpR9bX711nVHnSn8hNxoJ+bi9d+HSOI1 vCwmKCbsCh0gGOAFO6vuAglxK2300pW5n/sAcuScNMYtZB/M1l14eSwnK19BQ+/+cG5c7x g+Zb8LgdtKN92TnKya5YZ8gPKfw+ZO8= X-MC-Unique: yzQfujq3PdSkvfP4B65j-w-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709107630; x=1709712430; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=oaaGnvOvuEg+amyykEvtj5XWm41K6EEY0fV7AH7s47U=; b=MHrINMftzJAsD9p2s57DKkyFVXDnJEKIRvYXrSelA9yMsMs9Sp2Gq5eOwW28eaJrzp nwM+nzarfFBC4HKJ/i9phoQrUrHnC/R+GXOrsQ8Q0R15Alyuw7pDoTJT0kPAkXgFCaee xB4mheFkM5f6L07XRPR87tb4tGbVi8bkDk5pxB8GIvZa2PjVLWV1kV2cOkFajeI4CEb+ Yx90AW1bV6Ns060f1+YTyCRPepWD6KqvO/C6O0XP3AkzazKNrWaMc2PfaZDstYG2EjSE IiDTibuuwX/8AMhBADWwsKmiNjw72xsR9KUJxwg1Im5BmqQbEi92fukQ8JsQWdMKDYkU K2dQ== X-Gm-Message-State: AOJu0Ywnak1GTam0Y9Yf1MNVl/nHZp9zvHYrFYVeRAjHhtOTTMCESZwk 8RgRUyrDWE817oWjmuM0C9Ccn0yUl672bDPRzWQoLVMdOTuEezFpTx0zEiYM2Bh+O3pUAR64DF6 Loqpf+AOqBX08DzBk9VScCTeUJShT0NZJvXbpJazGfcyYOasVh+r2RRf1uwFIrNzJCCXrqMAVCk mmXJu8tL4xY5x2JeNb6pPJo06sVq7I0kzKFafX X-Received: by 2002:a17:906:69b:b0:a42:f3a6:9f7f with SMTP id u27-20020a170906069b00b00a42f3a69f7fmr7114876ejb.13.1709107630209; Wed, 28 Feb 2024 00:07:10 -0800 (PST) X-Google-Smtp-Source: AGHT+IFSWHdk1bKJAGaPUAIqnmIiQGzY6CZeVMpweNzhyKOnG/9IKuQCDv1QWCENqS6lIHrjJi+C9g== X-Received: by 2002:a17:906:69b:b0:a42:f3a6:9f7f with SMTP id u27-20020a170906069b00b00a42f3a69f7fmr7114851ejb.13.1709107629729; Wed, 28 Feb 2024 00:07:09 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 04/10] target/i386: introduce function to query MMU indices Date: Wed, 28 Feb 2024 09:06:40 +0100 Message-ID: <20240228080646.261365-5-pbonzini@redhat.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240228080646.261365-1-pbonzini@redhat.com> References: <20240228080646.261365-1-pbonzini@redhat.com> MIME-Version: 1.0 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=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.088, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-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 @redhat.com) X-ZM-MESSAGEID: 1709107730623100009 Content-Type: text/plain; charset="utf-8" Remove knowledge of specific MMU indexes (other than MMU_NESTED_IDX and MMU_PHYS_IDX) from mmu_translate(). This will make it possible to split 32-bit and 64-bit MMU indexes. Signed-off-by: Paolo Bonzini --- target/i386/cpu.h | 10 ++++++++++ target/i386/tcg/sysemu/excp_helper.c | 4 ++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/target/i386/cpu.h b/target/i386/cpu.h index dfe43b82042..8c271ca62e5 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -2305,6 +2305,16 @@ uint64_t cpu_get_tsc(CPUX86State *env); #define MMU_NESTED_IDX 3 #define MMU_PHYS_IDX 4 =20 +static inline bool is_mmu_index_smap(int mmu_index) +{ + return mmu_index =3D=3D MMU_KSMAP_IDX; +} + +static inline bool is_mmu_index_user(int mmu_index) +{ + return mmu_index =3D=3D MMU_USER_IDX; +} + static inline int cpu_mmu_index_kernel(CPUX86State *env) { return !(env->hflags & HF_SMAP_MASK) ? MMU_KNOSMAP_IDX : diff --git a/target/i386/tcg/sysemu/excp_helper.c b/target/i386/tcg/sysemu/= excp_helper.c index 11126c860d4..a0d5ce39300 100644 --- a/target/i386/tcg/sysemu/excp_helper.c +++ b/target/i386/tcg/sysemu/excp_helper.c @@ -137,7 +137,7 @@ static bool mmu_translate(CPUX86State *env, const Trans= lateParams *in, const int32_t a20_mask =3D x86_get_a20_mask(env); const target_ulong addr =3D in->addr; const int pg_mode =3D in->pg_mode; - const bool is_user =3D (in->mmu_idx =3D=3D MMU_USER_IDX); + const bool is_user =3D is_mmu_index_user(in->mmu_idx); const MMUAccessType access_type =3D in->access_type; uint64_t ptep, pte, rsvd_mask; PTETranslate pte_trans =3D { @@ -363,7 +363,7 @@ do_check_protect_pse36: } =20 int prot =3D 0; - if (in->mmu_idx !=3D MMU_KSMAP_IDX || !(ptep & PG_USER_MASK)) { + if (!is_mmu_index_smap(in->mmu_idx) || !(ptep & PG_USER_MASK)) { prot |=3D PAGE_READ; if ((ptep & PG_RW_MASK) || !(is_user || (pg_mode & PG_MODE_WP))) { prot |=3D PAGE_WRITE; --=20 2.43.2 From nobody Tue Nov 26 06:47:38 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1709107723; cv=none; d=zohomail.com; s=zohoarc; b=Xuk2m9Yv2AiB/waJ10hhAUj/7Ov1iJSgfIpfT4i5u3+FDDkI517882r2Dq37qI0XaGncTW7oG5krZ11KGYT+nHwWPbmvlL4l02yblzArW/NDt1Ku8jXgFUn3mOOziLPvURDSneNazyUSptdxBVqkRR04Db8xDpW+PEIqKz+E4AA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709107723; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To:Cc; bh=S/Q8c4npc2nOjD6fpmMrOfyZKvHziSh6p17Z9qCoc8w=; b=iBfQi52LCnvWd5CjpmDydRJgoNmPHkMR1+KhOATYEm9TrDveIVx+g0RIy/Epipy7182vonoZFTXBVJJR1QYrV1TifUTAlutBZirai5xzLhjPpGkl+/5rzAUrzIPZxcKKnyXXQl9y6FCrbm4REXpDDmzXANRJ2u9Z3UgkBwN6zXk= 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 1709107723951391.63082846244106; Wed, 28 Feb 2024 00:08:43 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rfEyL-0001XA-TS; Wed, 28 Feb 2024 03:07:25 -0500 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 1rfEyK-0001Vy-5X for qemu-devel@nongnu.org; Wed, 28 Feb 2024 03:07:24 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rfEyD-0000WP-1m for qemu-devel@nongnu.org; Wed, 28 Feb 2024 03:07:23 -0500 Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-137-rM7LAW0pOeaWZ60iRJWbWw-1; Wed, 28 Feb 2024 03:07:14 -0500 Received: by mail-ed1-f69.google.com with SMTP id 4fb4d7f45d1cf-56451e5801dso2476837a12.3 for ; Wed, 28 Feb 2024 00:07:14 -0800 (PST) Received: from [192.168.10.118] ([93.56.170.180]) by smtp.gmail.com with ESMTPSA id s21-20020aa7cb15000000b005645961ad39sm1535566edt.47.2024.02.28.00.07.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 00:07:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709107636; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=S/Q8c4npc2nOjD6fpmMrOfyZKvHziSh6p17Z9qCoc8w=; b=dkA70K6qNasVukJSS8wi3tCOkyqlVs+SEiH1yRSPmCGmWcE69KzeeoKZjuqKIK/JwLhSkP hqZGi8v3zstLZEeTktvzQFtb6hixKSmlKg3dxRefb2z+S4WW+fGyT3RJTg5md+p9vHF1s5 Bj5qnafC01DEgQZbHWdV28UIzXUS9nc= X-MC-Unique: rM7LAW0pOeaWZ60iRJWbWw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709107633; x=1709712433; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=S/Q8c4npc2nOjD6fpmMrOfyZKvHziSh6p17Z9qCoc8w=; b=UwKUi75KLgxlww0lfbv24cjGZCk4IUnTRnlf0pgrU9f5AmmZNFQbrQY2tjUDeesbtg IabZprUzsAMtc4jrKVNGMiUhU1OFeO6Oz0S6BEqzpnSfUYsIlnMkSN16UZQdUMSNICUE 22T1FYiNmiIrzxRDtqZ+tERWZtl3OnIAXYPDV047gLG7vSEE9dc0QuMSON1RyYKvBQ42 6MNKMSOtKwi8HsFQQuey7zzX6SbRKQMs8fSFF3GHvcd1yj0fU0UJg1/vVP8XGB1JsHeH jmo47AST54Ex0BL4y9EOxuIhPPnx8U1Mm9gt2xJIu7xzXrTWl7BdWJaE6pDX6nH72ijP nEhA== X-Gm-Message-State: AOJu0YzGODCwmNXeAwkkH0XCJGfDRrDhwOOrVHwaE2BrG7AIMIPpFkfa 3Xv8VZstkqVV6Iv9MuJ3oGDB1ZnI5P60MkiYWa/BdS+vZ64T2vckSgKKZYG36L0uXLT2c9O2GpZ VsqyTXRvVRX/HAGzGxTHcK5kSF8MyHNvSRLBNyRsSeqZR/0ziFRiV29vG6EKQ0H6AehjZpgI8gT nCSHbMEkKVU5wAL6YdsMs7beKy7zn+J3JSgKFz X-Received: by 2002:a05:6402:713:b0:566:348:fc4a with SMTP id w19-20020a056402071300b005660348fc4amr5072180edx.32.1709107632783; Wed, 28 Feb 2024 00:07:12 -0800 (PST) X-Google-Smtp-Source: AGHT+IFtNxyecOQn8+QzP+khnduSvVcUXo8KLTi58N0a+Vuyd9EhjCEbYWQr4OdOMY/4U8rKUyR54Q== X-Received: by 2002:a05:6402:713:b0:566:348:fc4a with SMTP id w19-20020a056402071300b005660348fc4amr5072160edx.32.1709107632447; Wed, 28 Feb 2024 00:07:12 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 05/10] target/i386: use separate MMU indexes for 32-bit accesses Date: Wed, 28 Feb 2024 09:06:41 +0100 Message-ID: <20240228080646.261365-6-pbonzini@redhat.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240228080646.261365-1-pbonzini@redhat.com> References: <20240228080646.261365-1-pbonzini@redhat.com> MIME-Version: 1.0 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=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.088, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-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 @redhat.com) X-ZM-MESSAGEID: 1709107724603100001 Content-Type: text/plain; charset="utf-8" Accesses from a 32-bit environment (32-bit code segment for instruction accesses, EFER.LMA=3D=3D0 for processor accesses) have to mask away the upper 32 bits of the address. While a bit wasteful, the easiest way to do so is to use separate MMU indexes. These days, QEMU anyway is compiled with a fixed value for NB_MMU_MODES. Split MMU_USER_IDX, MMU_KSMAP_IDX and MMU_KNOSMAP_IDX in two. Signed-off-by: Paolo Bonzini --- target/i386/cpu.h | 34 ++++++++++++++++++++-------- target/i386/cpu.c | 11 +++++---- target/i386/tcg/sysemu/excp_helper.c | 3 ++- 3 files changed, 33 insertions(+), 15 deletions(-) diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 8c271ca62e5..ee4ad372021 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -2299,27 +2299,41 @@ uint64_t cpu_get_tsc(CPUX86State *env); #define cpu_list x86_cpu_list =20 /* MMU modes definitions */ -#define MMU_KSMAP_IDX 0 -#define MMU_USER_IDX 1 -#define MMU_KNOSMAP_IDX 2 -#define MMU_NESTED_IDX 3 -#define MMU_PHYS_IDX 4 +#define MMU_KSMAP64_IDX 0 +#define MMU_KSMAP32_IDX 1 +#define MMU_USER64_IDX 2 +#define MMU_USER32_IDX 3 +#define MMU_KNOSMAP64_IDX 4 +#define MMU_KNOSMAP32_IDX 5 +#define MMU_PHYS_IDX 6 +#define MMU_NESTED_IDX 7 + +#ifdef CONFIG_USER_ONLY +#ifdef TARGET_X86_64 +#define MMU_USER_IDX MMU_USER64_IDX +#else +#define MMU_USER_IDX MMU_USER32_IDX +#endif +#endif =20 static inline bool is_mmu_index_smap(int mmu_index) { - return mmu_index =3D=3D MMU_KSMAP_IDX; + return (mmu_index & ~1) =3D=3D MMU_KSMAP64_IDX; } =20 static inline bool is_mmu_index_user(int mmu_index) { - return mmu_index =3D=3D MMU_USER_IDX; + return (mmu_index & ~1) =3D=3D MMU_USER64_IDX; } =20 static inline int cpu_mmu_index_kernel(CPUX86State *env) { - return !(env->hflags & HF_SMAP_MASK) ? MMU_KNOSMAP_IDX : - ((env->hflags & HF_CPL_MASK) < 3 && (env->eflags & AC_MASK)) - ? MMU_KNOSMAP_IDX : MMU_KSMAP_IDX; + int mmu_index_32 =3D (env->hflags & HF_LMA_MASK) ? 1 : 0; + int mmu_index_base =3D + !(env->hflags & HF_SMAP_MASK) ? MMU_KNOSMAP64_IDX : + ((env->hflags & HF_CPL_MASK) < 3 && (env->eflags & AC_MASK)) ? MMU= _KNOSMAP64_IDX : MMU_KSMAP64_IDX; + + return mmu_index_base + mmu_index_32; } =20 #define CC_DST (env->cc_dst) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 7f908236767..647371198c7 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -7732,13 +7732,16 @@ static bool x86_cpu_has_work(CPUState *cs) return x86_cpu_pending_interrupt(cs, cs->interrupt_request) !=3D 0; } =20 -static int x86_cpu_mmu_index(CPUState *cs, bool ifetch) +static int x86_cpu_mmu_index(CPUState *env, bool ifetch) { CPUX86State *env =3D cpu_env(cs); + int mmu_index_32 =3D (env->hflags & HF_CS64_MASK) ? 1 : 0; + int mmu_index_base =3D + (env->hflags & HF_CPL_MASK) =3D=3D 3 ? MMU_USER64_IDX : + !(env->hflags & HF_SMAP_MASK) ? MMU_KNOSMAP64_IDX : + (env->eflags & AC_MASK) ? MMU_KNOSMAP64_IDX : MMU_KSMAP64_IDX; =20 - return (env->hflags & HF_CPL_MASK) =3D=3D 3 ? MMU_USER_IDX : - (!(env->hflags & HF_SMAP_MASK) || (env->eflags & AC_MASK)) - ? MMU_KNOSMAP_IDX : MMU_KSMAP_IDX; + return mmu_index_base + mmu_index_32; } =20 static void x86_disas_set_info(CPUState *cs, disassemble_info *info) diff --git a/target/i386/tcg/sysemu/excp_helper.c b/target/i386/tcg/sysemu/= excp_helper.c index a0d5ce39300..b2c525e1a92 100644 --- a/target/i386/tcg/sysemu/excp_helper.c +++ b/target/i386/tcg/sysemu/excp_helper.c @@ -545,7 +545,8 @@ static bool get_physical_address(CPUX86State *env, vadd= r addr, if (likely(use_stage2)) { in.cr3 =3D env->nested_cr3; in.pg_mode =3D env->nested_pg_mode; - in.mmu_idx =3D MMU_USER_IDX; + in.mmu_idx =3D + env->nested_pg_mode & PG_MODE_LMA ? MMU_USER64_IDX : MMU_U= SER32_IDX; in.ptw_idx =3D MMU_PHYS_IDX; =20 if (!mmu_translate(env, &in, out, err)) { --=20 2.43.2 From nobody Tue Nov 26 06:47:38 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1709107726; cv=none; d=zohomail.com; s=zohoarc; b=jhOuUZppqTVAc0aYQDHRIHBiqdMKAgocA+WvdlQNONzweM5fExLyePJste8YBmu4PJlPt/YpLcbzB9UZkGTDT9FCd83ftRBxsXzzMm7fnifp1fearkzmWr4oyg5AqLs/SMG/k4Loas8q+TKy11xUyfF9ZH+98IJfHJs42N0nV14= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709107726; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=M0RmU9OngKg8RcV23aPNFS80c5Wg/erIimeHGgM+2Pk=; b=USHjAj3fqLQuAWUy9OzfmLCRtGBG/+qsPM5Xt0dTzB8MN0gWdFG/gkh/6f0UindH3ijtQjigP5pGIFSq/a55xPwyZNfZur5v202d3GmlxW8SUfw9XCYdfAP2c+mqSTW561EkViX0hnNx5Jznyv3yYBHBsTo5pj/T3kvor6kCblc= 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 1709107726523516.2077797415458; Wed, 28 Feb 2024 00:08:46 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rfEyP-0001eB-2u; Wed, 28 Feb 2024 03:07:29 -0500 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 1rfEyL-0001Wv-I2 for qemu-devel@nongnu.org; Wed, 28 Feb 2024 03:07:25 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rfEyF-0000Wh-CU for qemu-devel@nongnu.org; Wed, 28 Feb 2024 03:07:25 -0500 Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-266-Qa32GwcwONivaVPhdJgS5w-1; Wed, 28 Feb 2024 03:07:17 -0500 Received: by mail-ej1-f70.google.com with SMTP id a640c23a62f3a-a43f3f8d7d8so26433766b.3 for ; Wed, 28 Feb 2024 00:07:17 -0800 (PST) Received: from [192.168.10.118] ([93.56.170.180]) by smtp.gmail.com with ESMTPSA id tj6-20020a170907c24600b00a43a3139b2dsm1526035ejc.225.2024.02.28.00.07.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 00:07:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709107638; 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=M0RmU9OngKg8RcV23aPNFS80c5Wg/erIimeHGgM+2Pk=; b=gDioRmbFPDKa7ZKp3LpPgOvOBRGT4ESS5iDhnrc1Hic5WmOVZQVijnTyB3zNInv/jfaGwd jNKcbSkcQjUu9drBjukxTTmYWxQAZGRgVqM1cc+WWjiUwGWXSHPgQAFucO4v7F3/MTflvR KI5mTy8eB7pdBV/UlTK7h6qUJnopRjM= X-MC-Unique: Qa32GwcwONivaVPhdJgS5w-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709107635; x=1709712435; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=M0RmU9OngKg8RcV23aPNFS80c5Wg/erIimeHGgM+2Pk=; b=NgpZ1fiRPMbrxRRvJWO9xs4OiYBy5A/1tcyM80KNL1mL7MLeOosFwpuKOA7uXE2gM1 Zxm8F/AaLizCZkEKn686jPTQWurPNPf3noRNO20ctkSU+uYgxB6CfMIAeTVyFfo6tEPj 1Wd/FHMxdV7U+ISDKkzfY130SpR5BzkSIy8PYYK7GkJg/+165WIK3tR6nQhMCQi7WEQs 1hder6TRtQaLARnOSd0ZKwQ8xhw3v5vxytA4wYWIk+D9q0dCD71uPqvl0wGK4wkXLnKT 5Vo9J0nsP4LXYFMUZ2cikL0E1iTSujSlbeTlnTCFdB+eXoL+csa5HKwHhtsUq6YsxEEJ Y5xw== X-Gm-Message-State: AOJu0YxCVEBUXJrZaBSlDbEKZ3lKzFTeo2LqWBgW/IQGQuQJ+41Hh1Qe AM1UKqDwGCTpn9G4Q2bAZ++1LLbORS35ZgblKEE79h904PzovL6XwaizqkeYoBNwUemD1ugMCxl tmvv0T/CIxT+ch44RDqMHcx1RZceH2EyF9VZbJQkJH6TO7SDt9ledotQixSZO35I+bb7XmaUOZE mSa4uJ8oIWUgctXBed6S2m+TWwIPcVlTC9a6sX X-Received: by 2002:a17:906:2b11:b0:a43:a731:956 with SMTP id a17-20020a1709062b1100b00a43a7310956mr3088434ejg.28.1709107635496; Wed, 28 Feb 2024 00:07:15 -0800 (PST) X-Google-Smtp-Source: AGHT+IF+D+tvMU3RQXHe8cpoApgkWmnNVnD9I1LxTAJLUb9GBNkqNXcb64r/v31y/05XeZlDB5ZIdg== X-Received: by 2002:a17:906:2b11:b0:a43:a731:956 with SMTP id a17-20020a1709062b1100b00a43a7310956mr3088413ejg.28.1709107635150; Wed, 28 Feb 2024 00:07:15 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org, Michael Brown Subject: [PULL 06/10] target/i386: Fix physical address truncation Date: Wed, 28 Feb 2024 09:06:42 +0100 Message-ID: <20240228080646.261365-7-pbonzini@redhat.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240228080646.261365-1-pbonzini@redhat.com> References: <20240228080646.261365-1-pbonzini@redhat.com> MIME-Version: 1.0 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=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.088, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=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 @redhat.com) X-ZM-MESSAGEID: 1709107728630100007 Content-Type: text/plain; charset="utf-8" The address translation logic in get_physical_address() will currently truncate physical addresses to 32 bits unless long mode is enabled. This is incorrect when using physical address extensions (PAE) outside of long mode, with the result that a 32-bit operating system using PAE to access memory above 4G will experience undefined behaviour. The truncation code was originally introduced in commit 33dfdb5 ("x86: only allow real mode to access 32bit without LMA"), where it applied only to translations performed while paging is disabled (and so cannot affect guests using PAE). Commit 9828198 ("target/i386: Add MMU_PHYS_IDX and MMU_NESTED_IDX") rearranged the code such that the truncation also applied to the use of MMU_PHYS_IDX and MMU_NESTED_IDX. Commit 4a1e9d4 ("target/i386: Use atomic operations for pte updates") brought this truncation into scope for page table entry accesses, and is the first commit for which a Windows 10 32-bit guest will reliably fail to boot if memory above 4G is present. The truncation code however is not completely redundant. Even though the maximum address size for any executed instruction is 32 bits, helpers for operations such as BOUND, FSAVE or XSAVE may ask get_physical_address() to translate an address outside of the 32-bit range, if invoked with an argument that is close to the 4G boundary. Likewise for processor accesses, for example TSS or IDT accesses, when EFER.LMA=3D=3D0. So, move the address truncation in get_physical_address() so that it applies to 32-bit MMU indexes, but not to MMU_PHYS_IDX and MMU_NESTED_IDX. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2040 Fixes: 4a1e9d4d11c ("target/i386: Use atomic operations for pte updates", 2= 022-10-18) Cc: qemu-stable@nongnu.org Co-developed-by: Michael Brown Signed-off-by: Michael Brown Signed-off-by: Paolo Bonzini --- target/i386/cpu.h | 6 ++++++ target/i386/cpu.c | 2 +- target/i386/tcg/sysemu/excp_helper.c | 12 +++++------- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/target/i386/cpu.h b/target/i386/cpu.h index ee4ad372021..952174bb6f5 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -2326,6 +2326,12 @@ static inline bool is_mmu_index_user(int mmu_index) return (mmu_index & ~1) =3D=3D MMU_USER64_IDX; } =20 +static inline bool is_mmu_index_32(int mmu_index) +{ + assert(mmu_index < MMU_PHYS_IDX); + return mmu_index & 1; +} + static inline int cpu_mmu_index_kernel(CPUX86State *env) { int mmu_index_32 =3D (env->hflags & HF_LMA_MASK) ? 1 : 0; diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 647371198c7..ba6d7b80a7f 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -7732,7 +7732,7 @@ static bool x86_cpu_has_work(CPUState *cs) return x86_cpu_pending_interrupt(cs, cs->interrupt_request) !=3D 0; } =20 -static int x86_cpu_mmu_index(CPUState *env, bool ifetch) +static int x86_cpu_mmu_index(CPUState *cs, bool ifetch) { CPUX86State *env =3D cpu_env(cs); int mmu_index_32 =3D (env->hflags & HF_CS64_MASK) ? 1 : 0; diff --git a/target/i386/tcg/sysemu/excp_helper.c b/target/i386/tcg/sysemu/= excp_helper.c index b2c525e1a92..8bcdd2906d5 100644 --- a/target/i386/tcg/sysemu/excp_helper.c +++ b/target/i386/tcg/sysemu/excp_helper.c @@ -558,6 +558,10 @@ static bool get_physical_address(CPUX86State *env, vad= dr addr, break; =20 default: + if (is_mmu_index_32(mmu_idx)) { + addr =3D (uint32_t)addr; + } + if (likely(env->cr[0] & CR0_PG_MASK)) { in.cr3 =3D env->cr[3]; in.mmu_idx =3D mmu_idx; @@ -581,14 +585,8 @@ static bool get_physical_address(CPUX86State *env, vad= dr addr, break; } =20 - /* Translation disabled. */ + /* No translation needed. */ out->paddr =3D addr & x86_get_a20_mask(env); -#ifdef TARGET_X86_64 - if (!(env->hflags & HF_LMA_MASK)) { - /* Without long mode we can only address 32bits in real mode */ - out->paddr =3D (uint32_t)out->paddr; - } -#endif out->prot =3D PAGE_READ | PAGE_WRITE | PAGE_EXEC; out->page_size =3D TARGET_PAGE_SIZE; return true; --=20 2.43.2 From nobody Tue Nov 26 06:47:38 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1709107740; cv=none; d=zohomail.com; s=zohoarc; b=IwerK3bdyaqNI6szvrmKldfzp3I407QfCRUKVWt/2Vkrvd3Sbco/eFDoZxx0Oi+/9bSz8PNC72zzf0+23ywRWSzJUpwWoZiTNcAfH2ohtcWFrEfLHCpoTSDPQg7THoXZKN7xNMAJEdOB8tzC9fDK9sjHIbAifVhPL4oUJ2tu5Ko= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709107740; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=vKjZSqacAB8iZPfTH6FwKVpy3pBbPqdXPJfiOVIqgCQ=; b=JjqriYzSc3Ym1S2vspf5lSYpjduyesenhJKO/S0ZwegN7NGZfRzJFnl4aJsnshiJSBqhWlNkPAmmvKLsq+UqwT+wEOJ8R0xrwF6YfSX6frEQ30v5iiNJXrf3xLVbR/iufSpf1X1Sm10y8JZSi8QDdZdIO7+w6OQv+R/520VRYv0= 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 1709107740199924.0382702213262; Wed, 28 Feb 2024 00:09:00 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rfEyO-0001al-2B; Wed, 28 Feb 2024 03:07:28 -0500 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 1rfEyL-0001Ww-Hw for qemu-devel@nongnu.org; Wed, 28 Feb 2024 03:07:25 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rfEyI-0000XY-Pf for qemu-devel@nongnu.org; Wed, 28 Feb 2024 03:07:25 -0500 Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-595-lQNm9PrsMhmg_VZDa48ynA-1; Wed, 28 Feb 2024 03:07:20 -0500 Received: by mail-ej1-f70.google.com with SMTP id a640c23a62f3a-a43381a778aso220394366b.1 for ; Wed, 28 Feb 2024 00:07:20 -0800 (PST) Received: from [192.168.10.118] ([93.56.170.180]) by smtp.gmail.com with ESMTPSA id hk12-20020a170906c9cc00b00a3e59410a75sm1583572ejb.170.2024.02.28.00.07.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 00:07:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709107642; 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=vKjZSqacAB8iZPfTH6FwKVpy3pBbPqdXPJfiOVIqgCQ=; b=PqCXt/kIOlb3X70YQvID9eaFrV4L9o2s61gnLJRHWkS2nnt1EdXZ3Lu7gdRxG57SjEO8Te F2ZmKQFoQvL2uk8emh1prLR7bJhFJwgyBVsI0+gmmrbnT5sTAgAFn2Z+RCsfADlUO6mKpk x/qeJmu9RoT37nZi7x8yaVscQScWUDs= X-MC-Unique: lQNm9PrsMhmg_VZDa48ynA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709107638; x=1709712438; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vKjZSqacAB8iZPfTH6FwKVpy3pBbPqdXPJfiOVIqgCQ=; b=wvLSPn0f6nrg6qK6MoPsQigvUKo14yxKMQiUuZmc/RbqOUpcGl+VHMEzr5Yq5t7utK 0TPEWRfun9249zdeeAWyiWykZPUbM+IUsv4LCk/7qmegpQ2BVHLRbbIXfmV7Yitc1XUg N9chn1SMmKhxhrG00N4fU32v4DR0j1ShMEQ/gt+ZG4yOXT391XCBwEBq7RYz06nKuvPw rKJj75m/8gSlWWmNST1NjmWbi7QaZMy2FgfzEq5fl6HGlmDxQX/s6og5zalu8V0Qx+YN 69iqolKyLTKyZZJUjoSH4S7cB6fCJV7yfx2Ah6B0z1/f2Fadn2owh1vavLg53Him3ahG 0U6Q== X-Gm-Message-State: AOJu0YxqcKYfU1d6XGo1vwtlNmnVEsdRSwd16GCy/eHcSDagVu+ooLHh TXyMpaUXaA7Xk4ZNrxNecAEhpRWI2n/d+bAjuG2ylJL+XGN3+HexnG9bVWeNNuO8Ra6SZr9gCEa sh3+sZ4EMs9v4QFDnOMlSWXsCjgL+6k/K1c8gEDT0AB/Jq33ViwwzLmOI5Jby4PUV+cJc/PUC8c Bz/1s9XHykrgBgfzrCMGTcaeenmiywymLCt7Ui X-Received: by 2002:a17:906:34cb:b0:a40:2999:5404 with SMTP id h11-20020a17090634cb00b00a4029995404mr8079342ejb.3.1709107638799; Wed, 28 Feb 2024 00:07:18 -0800 (PST) X-Google-Smtp-Source: AGHT+IE+S1OTiMphVSICCeIQoGoLFQE7Tny4p7dR4wGy/rDpbOBajLEH2WSBA7xIbriRLzGQYxAGrg== X-Received: by 2002:a17:906:34cb:b0:a40:2999:5404 with SMTP id h11-20020a17090634cb00b00a4029995404mr8079332ejb.3.1709107638490; Wed, 28 Feb 2024 00:07:18 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org Subject: [PULL 07/10] target/i386: remove unnecessary/wrong application of the A20 mask Date: Wed, 28 Feb 2024 09:06:43 +0100 Message-ID: <20240228080646.261365-8-pbonzini@redhat.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240228080646.261365-1-pbonzini@redhat.com> References: <20240228080646.261365-1-pbonzini@redhat.com> MIME-Version: 1.0 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=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.088, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-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 @redhat.com) X-ZM-MESSAGEID: 1709107740639100001 Content-Type: text/plain; charset="utf-8" If ptw_translate() does a MMU_PHYS_IDX access, the A20 mask is already applied in get_physical_address(), which is called via probe_access_full() and x86_cpu_tlb_fill(). If ptw_translate() on the other hand does a MMU_NESTED_IDX access, the A20 mask must not be applied to the address that is looked up in the nested page tables; it must be applied only to the addresses that hold the NPT entries (which is achieved via MMU_PHYS_IDX, per the previous paragraph). Therefore, we can remove A20 masking from the computation of the page table entry's address, and let get_physical_address() or mmu_translate() apply it when they know they are returning a host-physical address. Cc: qemu-stable@nongnu.org Fixes: 4a1e9d4d11c ("target/i386: Use atomic operations for pte updates", 2= 022-10-18) Signed-off-by: Paolo Bonzini --- target/i386/tcg/sysemu/excp_helper.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/target/i386/tcg/sysemu/excp_helper.c b/target/i386/tcg/sysemu/= excp_helper.c index 8bcdd2906d5..2ddc08b4bb6 100644 --- a/target/i386/tcg/sysemu/excp_helper.c +++ b/target/i386/tcg/sysemu/excp_helper.c @@ -164,8 +164,7 @@ static bool mmu_translate(CPUX86State *env, const Trans= lateParams *in, /* * Page table level 5 */ - pte_addr =3D ((in->cr3 & ~0xfff) + - (((addr >> 48) & 0x1ff) << 3)) & a20_mask; + pte_addr =3D (in->cr3 & ~0xfff) + (((addr >> 48) & 0x1ff) = << 3); if (!ptw_translate(&pte_trans, pte_addr)) { return false; } @@ -189,8 +188,7 @@ static bool mmu_translate(CPUX86State *env, const Trans= lateParams *in, /* * Page table level 4 */ - pte_addr =3D ((pte & PG_ADDRESS_MASK) + - (((addr >> 39) & 0x1ff) << 3)) & a20_mask; + pte_addr =3D (pte & PG_ADDRESS_MASK) + (((addr >> 39) & 0x1ff)= << 3); if (!ptw_translate(&pte_trans, pte_addr)) { return false; } @@ -210,8 +208,7 @@ static bool mmu_translate(CPUX86State *env, const Trans= lateParams *in, /* * Page table level 3 */ - pte_addr =3D ((pte & PG_ADDRESS_MASK) + - (((addr >> 30) & 0x1ff) << 3)) & a20_mask; + pte_addr =3D (pte & PG_ADDRESS_MASK) + (((addr >> 30) & 0x1ff)= << 3); if (!ptw_translate(&pte_trans, pte_addr)) { return false; } @@ -238,7 +235,7 @@ static bool mmu_translate(CPUX86State *env, const Trans= lateParams *in, /* * Page table level 3 */ - pte_addr =3D ((in->cr3 & 0xffffffe0ULL) + ((addr >> 27) & 0x18= )) & a20_mask; + pte_addr =3D (in->cr3 & 0xffffffe0ULL) + ((addr >> 27) & 0x18); if (!ptw_translate(&pte_trans, pte_addr)) { return false; } @@ -260,8 +257,7 @@ static bool mmu_translate(CPUX86State *env, const Trans= lateParams *in, /* * Page table level 2 */ - pte_addr =3D ((pte & PG_ADDRESS_MASK) + - (((addr >> 21) & 0x1ff) << 3)) & a20_mask; + pte_addr =3D (pte & PG_ADDRESS_MASK) + (((addr >> 21) & 0x1ff) << = 3); if (!ptw_translate(&pte_trans, pte_addr)) { return false; } @@ -287,8 +283,7 @@ static bool mmu_translate(CPUX86State *env, const Trans= lateParams *in, /* * Page table level 1 */ - pte_addr =3D ((pte & PG_ADDRESS_MASK) + - (((addr >> 12) & 0x1ff) << 3)) & a20_mask; + pte_addr =3D (pte & PG_ADDRESS_MASK) + (((addr >> 12) & 0x1ff) << = 3); if (!ptw_translate(&pte_trans, pte_addr)) { return false; } @@ -306,7 +301,7 @@ static bool mmu_translate(CPUX86State *env, const Trans= lateParams *in, /* * Page table level 2 */ - pte_addr =3D ((in->cr3 & 0xfffff000ULL) + ((addr >> 20) & 0xffc)) = & a20_mask; + pte_addr =3D (in->cr3 & 0xfffff000ULL) + ((addr >> 20) & 0xffc); if (!ptw_translate(&pte_trans, pte_addr)) { return false; } @@ -335,7 +330,7 @@ static bool mmu_translate(CPUX86State *env, const Trans= lateParams *in, /* * Page table level 1 */ - pte_addr =3D ((pte & ~0xfffu) + ((addr >> 10) & 0xffc)) & a20_mask; + pte_addr =3D (pte & ~0xfffu) + ((addr >> 10) & 0xffc); if (!ptw_translate(&pte_trans, pte_addr)) { return false; } --=20 2.43.2 From nobody Tue Nov 26 06:47:38 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1709107695; cv=none; d=zohomail.com; s=zohoarc; b=PnH1W2XRZeTvgH19bnSnsWqejotciUWDJolPUeyolkMj0A5W9dn7/hjBwY7JKnxLcuuYqV0oOSNShNP1wr3vWFvoaSWMPnKF6b8eflopYBsoTLi+gICxeDQWkYyItT73y9gjinCZumazb8cLSTPS1QFTQU3OH/wtMaXCvG6q/50= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709107695; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=6FOwAaHjkgtd1Obqs7Hvk+sV/XW9OPoHUZIDnhZ07Wo=; b=aa34kx7ben+UTh++0PzQ6lU4G8EKECldd0Il9uJxb1j5GyTMcdWPqiciy5xaiu7gx6sKr7wnHiSAnBw3MUnKDVGIy0yudpyJ6R9y5dZjsVLQfIBokvke6Z5AifU5Nq6zhd+KWctzO7KEDA1DLLOPVwKgZvuyER3SQSKgJP/52Pw= 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 1709107695292197.1651974076749; Wed, 28 Feb 2024 00:08:15 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rfEyS-0001fu-7r; Wed, 28 Feb 2024 03:07:33 -0500 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 1rfEyQ-0001f1-Sa for qemu-devel@nongnu.org; Wed, 28 Feb 2024 03:07:30 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rfEyM-0000YQ-G8 for qemu-devel@nongnu.org; Wed, 28 Feb 2024 03:07:30 -0500 Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-651-AphdRWmYM5ed1pCkcJHyyQ-1; Wed, 28 Feb 2024 03:07:22 -0500 Received: by mail-ed1-f71.google.com with SMTP id 4fb4d7f45d1cf-56421fd7029so2821514a12.3 for ; Wed, 28 Feb 2024 00:07:22 -0800 (PST) Received: from [192.168.10.118] ([93.56.170.180]) by smtp.gmail.com with ESMTPSA id p13-20020a056402500d00b005648b000e91sm1535758eda.92.2024.02.28.00.07.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 00:07:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709107645; 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=6FOwAaHjkgtd1Obqs7Hvk+sV/XW9OPoHUZIDnhZ07Wo=; b=TwbwWzK0XO7Cq3Y5gbmi83SG/x6HBBdO8koMmI/A98L/JmmStsrebae1cuHLBz51Ajnf6Q 7EM/WBrAvh+dieg5reOBSckLwIm6u/ZfiibIVO7ShURdI/4jQqTLDikMt/PLkhs+esOkR7 p7po8w75lt3B0UON3BudYGZySR17Olc= X-MC-Unique: AphdRWmYM5ed1pCkcJHyyQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709107641; x=1709712441; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6FOwAaHjkgtd1Obqs7Hvk+sV/XW9OPoHUZIDnhZ07Wo=; b=LHXf+d1ewjMGRwuwg24nqOj3xVX3RvzNPckWDU+avdVM3hh9hXRlCmIGNnk6J5QC+L bugeaFz2Z0sxconBYZy8lxb/nS1mojpoGG0xcxehxSdIXC1srEF2YfYI/fLhuwG5TYkM fHMNWIOUUZvWRpntDAdMYL1veqlyLIzQcmlfGqywEOmrxRRYJYAw/P+Wi7pSgVdaZFsy xqiMhtKPN/zYT4EBcc8fnPIQpIuoacl7ll/zG9t/y38Wucy3uBFlyu2rkhIDYKSMKTsM CAB+gzr25teJDSfRKbQs4Y6WAVOe76Z7NLmJdAVVGcTkp+IXMHcNn+nKxGVby6Z8Tqg9 tRMA== X-Gm-Message-State: AOJu0YyLP/N8ZpJzDdcIxTdVsxk3b8OAdcgBaEQMc6VKHvzs7ubfVeXS SSbwQe0+RI/iXkaWZh2qDNUvu+JcV7jKhoxlsj7z8VQOW/TXaoWvN093SXwzoJfSij7xWgfB3F2 Tm36JxF19Kj/ztyCYvv+gnZpL9iU5tcRawyVAHh6wTCm+wDTD+hPZ30FEQbwTV3hv9TurMhsWzi oFaJKLQh94wkZcB3ABr++dHZLAXq/0tql4u07f X-Received: by 2002:aa7:c657:0:b0:565:9b18:8af5 with SMTP id z23-20020aa7c657000000b005659b188af5mr8474053edr.39.1709107641106; Wed, 28 Feb 2024 00:07:21 -0800 (PST) X-Google-Smtp-Source: AGHT+IHYJ4jor1+MprrPcUB0AIt6MuocBS55h3tWFcoctHRgbt9LKrirvM3TAPunIaDvQZ6S+EfYlg== X-Received: by 2002:aa7:c657:0:b0:565:9b18:8af5 with SMTP id z23-20020aa7c657000000b005659b188af5mr8474035edr.39.1709107640775; Wed, 28 Feb 2024 00:07:20 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org Subject: [PULL 08/10] target/i386: leave the A20 bit set in the final NPT walk Date: Wed, 28 Feb 2024 09:06:44 +0100 Message-ID: <20240228080646.261365-9-pbonzini@redhat.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240228080646.261365-1-pbonzini@redhat.com> References: <20240228080646.261365-1-pbonzini@redhat.com> MIME-Version: 1.0 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=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.088, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable 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 @redhat.com) X-ZM-MESSAGEID: 1709107696502100003 Content-Type: text/plain; charset="utf-8" The A20 mask is only applied to the final memory access. Nested page tables are always walked with the raw guest-physical address. Unlike the previous patch, in this one the masking must be kept, but it was done too early. Cc: qemu-stable@nongnu.org Fixes: 4a1e9d4d11c ("target/i386: Use atomic operations for pte updates", 2= 022-10-18) Signed-off-by: Paolo Bonzini --- target/i386/tcg/sysemu/excp_helper.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/target/i386/tcg/sysemu/excp_helper.c b/target/i386/tcg/sysemu/= excp_helper.c index 2ddc08b4bb6..8f7011d9663 100644 --- a/target/i386/tcg/sysemu/excp_helper.c +++ b/target/i386/tcg/sysemu/excp_helper.c @@ -134,7 +134,6 @@ static inline bool ptw_setl(const PTETranslate *in, uin= t32_t old, uint32_t set) static bool mmu_translate(CPUX86State *env, const TranslateParams *in, TranslateResult *out, TranslateFault *err) { - const int32_t a20_mask =3D x86_get_a20_mask(env); const target_ulong addr =3D in->addr; const int pg_mode =3D in->pg_mode; const bool is_user =3D is_mmu_index_user(in->mmu_idx); @@ -417,10 +416,13 @@ do_check_protect_pse36: } } =20 - /* align to page_size */ - paddr =3D (pte & a20_mask & PG_ADDRESS_MASK & ~(page_size - 1)) - | (addr & (page_size - 1)); + /* merge offset within page */ + paddr =3D (pte & PG_ADDRESS_MASK & ~(page_size - 1)) | (addr & (page_s= ize - 1)); =20 + /* + * Note that NPT is walked (for both paging structures and final guest + * addresses) using the address with the A20 bit set. + */ if (in->ptw_idx =3D=3D MMU_NESTED_IDX) { CPUTLBEntryFull *full; int flags, nested_page_size; @@ -459,7 +461,7 @@ do_check_protect_pse36: } } =20 - out->paddr =3D paddr; + out->paddr =3D paddr & x86_get_a20_mask(env); out->prot =3D prot; out->page_size =3D page_size; return true; --=20 2.43.2 From nobody Tue Nov 26 06:47:38 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1709107763; cv=none; d=zohomail.com; s=zohoarc; b=Z1grfU1TBwcWuKtpXwKwpTkKDENfu5W9C93cekBvDqEUbLaqAwVXx5kBcixYSa4NuQtVKQtsQBydWum7QRduSOB/B7oFxMYMTUb5jwFetncH+dGpUPOFZlVbcZlnLvpb0BGb6ygV9mSmih0RtN3BO/AChG9EJ04JY6ryUoWBo6I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709107763; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=ImnxzicTPLHKm7joJu7uVvlR2wnz8WjZKAHxyJJxnEY=; b=fi3OkIF1hkUr6ASl59J+o50OzY1EKx+ifrF/cTR6v0kC1TowOhxd4Z82rH9FBeUD/MVGxVnez3W/stTxORBazoDytxh8AJjwLyI4tvg/tqtIqo78RAxneSPR6OYHtN/qg43JnC8pAcfcg0wXIJU9ywDOfpDkPFfM+ME93DbCY/g= 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 1709107763111353.98295523747845; Wed, 28 Feb 2024 00:09:23 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rfEyV-0001gr-2q; Wed, 28 Feb 2024 03:07:35 -0500 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 1rfEyT-0001gY-OU for qemu-devel@nongnu.org; Wed, 28 Feb 2024 03:07:33 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rfEyN-0000YY-Ts for qemu-devel@nongnu.org; Wed, 28 Feb 2024 03:07:33 -0500 Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-146-HoBdJAVNPAiglH0hAy1IIQ-1; Wed, 28 Feb 2024 03:07:26 -0500 Received: by mail-ej1-f71.google.com with SMTP id a640c23a62f3a-a3e68c15996so240051766b.3 for ; Wed, 28 Feb 2024 00:07:25 -0800 (PST) Received: from [192.168.10.118] ([93.56.170.180]) by smtp.gmail.com with ESMTPSA id lr17-20020a170906fb9100b00a440d567be7sm155221ejb.190.2024.02.28.00.07.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 00:07:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709107647; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ImnxzicTPLHKm7joJu7uVvlR2wnz8WjZKAHxyJJxnEY=; b=ZCAvpc9Xcnl8S+meQYcnuTXmlrOJAxFFx+idXhC+dVzooiDj4aKnTdTXIROBZxdF0x1ppI 7fyIoEGsQDYZLoE7UfbBP2zCM4ShD2GqBJfHlHKvMEEhQJ4TCJ6AF0xgkMgt/b5CYpePnU GoyIwMgGovq1PkxvDaKun2n7Mp9D1gI= X-MC-Unique: HoBdJAVNPAiglH0hAy1IIQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709107644; x=1709712444; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ImnxzicTPLHKm7joJu7uVvlR2wnz8WjZKAHxyJJxnEY=; b=dwDyena9H57a0kAM8RJGCAmyAG7dqFu/UDGymyOMdXbABfIQ5gc8esGXaNRRBQxZJ9 rWnaB7qzP8cUrbXyXAdlLu8VSb3c9I60rL0SQ8g19NGYhxTWwYv6kasEnL6bif6tvWw5 8As/caLm8U6+wZxyv4XtxSNhtQ738No7uLOELbsmCFG2yJ35ODjitXoXIr287NUtw4/V tt3ibiXHHddH6YPddGkjs215antr2U7+w3AHjb+cNahRpljSrMIS8zKSufAGBqVeCKA1 mWzPrWB74Ranj/AYkTgebMCsuDwZXokou0GJYloFTUN7otMhLDyf5Gxa9aQEUYpXT8pl +S8w== X-Gm-Message-State: AOJu0Yx4RaNDsda7boCLgqrK4S9pFDKO7ACP1LWkzxOvBiMDutvm+Pzs glizTz7iwc0dKoTPIT4NBzX1pdwjhoaDiAMt+eE+LQubmuWecCoYggjyCbAZqmvY8S0NjAlZebl P839IddG0Ng478YusQKUHvlDtM9G8/oQHWYDbutt6dc7VMtUrN4X/3v+1hcW5gsOn6S3qHuyp6L vm2q6iVY6vPtW+UrfvmCpaUSECHcHYOqn/LTGR X-Received: by 2002:a17:906:3b03:b0:a3e:422d:a27d with SMTP id g3-20020a1709063b0300b00a3e422da27dmr8919121ejf.47.1709107643902; Wed, 28 Feb 2024 00:07:23 -0800 (PST) X-Google-Smtp-Source: AGHT+IG/Xd2yGXGFJ8KZmxm2bK7ZTYZoQXMHabhvajGjEwW89nZ8y32K1HA2EVZtiKMwMPM1jToRBQ== X-Received: by 2002:a17:906:3b03:b0:a3e:422d:a27d with SMTP id g3-20020a1709063b0300b00a3e422da27dmr8919108ejf.47.1709107643530; Wed, 28 Feb 2024 00:07:23 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PULL 09/10] ide: collapse parameters to ide_init_drive Date: Wed, 28 Feb 2024 09:06:45 +0100 Message-ID: <20240228080646.261365-10-pbonzini@redhat.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240228080646.261365-1-pbonzini@redhat.com> References: <20240228080646.261365-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.088, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=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 @redhat.com) X-ZM-MESSAGEID: 1709107764750100003 All calls to ide_init_drive comes from ide_dev_initfn. Just pass down the IDEDevice (IDEState is kinda obsolete and should be merged into IDEDevice). Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Paolo Bonzini --- include/hw/ide/internal.h | 6 +----- hw/ide/core.c | 40 ++++++++++++++++++--------------------- hw/ide/ide-dev.c | 5 +---- 3 files changed, 20 insertions(+), 31 deletions(-) diff --git a/include/hw/ide/internal.h b/include/hw/ide/internal.h index 20dde37f458..0d64805da20 100644 --- a/include/hw/ide/internal.h +++ b/include/hw/ide/internal.h @@ -416,11 +416,7 @@ uint32_t ide_data_readw(void *opaque, uint32_t addr); void ide_data_writel(void *opaque, uint32_t addr, uint32_t val); uint32_t ide_data_readl(void *opaque, uint32_t addr); =20 -int ide_init_drive(IDEState *s, BlockBackend *blk, IDEDriveKind kind, - const char *version, const char *serial, const char *mo= del, - uint64_t wwn, - uint32_t cylinders, uint32_t heads, uint32_t secs, - int chs_trans, Error **errp); +int ide_init_drive(IDEState *s, IDEDevice *dev, IDEDriveKind kind, Error *= *errp); void ide_exit(IDEState *s); void ide_bus_init_output_irq(IDEBus *bus, qemu_irq irq_out); int ide_init_ioport(IDEBus *bus, ISADevice *isa, int iobase, int iobase2); diff --git a/hw/ide/core.c b/hw/ide/core.c index 9c4a8129028..3c42d72ac25 100644 --- a/hw/ide/core.c +++ b/hw/ide/core.c @@ -2589,24 +2589,20 @@ static const BlockDevOps ide_hd_block_ops =3D { .resize_cb =3D ide_resize_cb, }; =20 -int ide_init_drive(IDEState *s, BlockBackend *blk, IDEDriveKind kind, - const char *version, const char *serial, const char *mo= del, - uint64_t wwn, - uint32_t cylinders, uint32_t heads, uint32_t secs, - int chs_trans, Error **errp) +int ide_init_drive(IDEState *s, IDEDevice *dev, IDEDriveKind kind, Error *= *errp) { uint64_t nb_sectors; =20 - s->blk =3D blk; + s->blk =3D dev->conf.blk; s->drive_kind =3D kind; =20 - blk_get_geometry(blk, &nb_sectors); - s->cylinders =3D cylinders; - s->heads =3D s->drive_heads =3D heads; - s->sectors =3D s->drive_sectors =3D secs; - s->chs_trans =3D chs_trans; + blk_get_geometry(s->blk, &nb_sectors); + s->cylinders =3D dev->conf.cyls; + s->heads =3D s->drive_heads =3D dev->conf.heads; + s->sectors =3D s->drive_sectors =3D dev->conf.secs; + s->chs_trans =3D dev->chs_trans; s->nb_sectors =3D nb_sectors; - s->wwn =3D wwn; + s->wwn =3D dev->wwn; /* The SMART values should be preserved across power cycles but they aren't. */ s->smart_enabled =3D 1; @@ -2614,26 +2610,26 @@ int ide_init_drive(IDEState *s, BlockBackend *blk, = IDEDriveKind kind, s->smart_errors =3D 0; s->smart_selftest_count =3D 0; if (kind =3D=3D IDE_CD) { - blk_set_dev_ops(blk, &ide_cd_block_ops, s); + blk_set_dev_ops(s->blk, &ide_cd_block_ops, s); } else { if (!blk_is_inserted(s->blk)) { error_setg(errp, "Device needs media, but drive is empty"); return -1; } - if (!blk_is_writable(blk)) { + if (!blk_is_writable(s->blk)) { error_setg(errp, "Can't use a read-only drive"); return -1; } - blk_set_dev_ops(blk, &ide_hd_block_ops, s); + blk_set_dev_ops(s->blk, &ide_hd_block_ops, s); } - if (serial) { - pstrcpy(s->drive_serial_str, sizeof(s->drive_serial_str), serial); + if (dev->serial) { + pstrcpy(s->drive_serial_str, sizeof(s->drive_serial_str), dev->ser= ial); } else { snprintf(s->drive_serial_str, sizeof(s->drive_serial_str), "QM%05d", s->drive_serial); } - if (model) { - pstrcpy(s->drive_model_str, sizeof(s->drive_model_str), model); + if (dev->model) { + pstrcpy(s->drive_model_str, sizeof(s->drive_model_str), dev->model= ); } else { switch (kind) { case IDE_CD: @@ -2648,14 +2644,14 @@ int ide_init_drive(IDEState *s, BlockBackend *blk, = IDEDriveKind kind, } } =20 - if (version) { - pstrcpy(s->version, sizeof(s->version), version); + if (dev->version) { + pstrcpy(s->version, sizeof(s->version), dev->version); } else { pstrcpy(s->version, sizeof(s->version), qemu_hw_version()); } =20 ide_reset(s); - blk_iostatus_enable(blk); + blk_iostatus_enable(s->blk); return 0; } =20 diff --git a/hw/ide/ide-dev.c b/hw/ide/ide-dev.c index c8e2033469c..900f80faf19 100644 --- a/hw/ide/ide-dev.c +++ b/hw/ide/ide-dev.c @@ -118,10 +118,7 @@ void ide_dev_initfn(IDEDevice *dev, IDEDriveKind kind,= Error **errp) return; } =20 - if (ide_init_drive(s, dev->conf.blk, kind, - dev->version, dev->serial, dev->model, dev->wwn, - dev->conf.cyls, dev->conf.heads, dev->conf.secs, - dev->chs_trans, errp) < 0) { + if (ide_init_drive(s, dev, kind, errp) < 0) { return; } =20 --=20 2.43.2 From nobody Tue Nov 26 06:47:38 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1709107672; cv=none; d=zohomail.com; s=zohoarc; b=H92pIrpUfLD1wH3wkia+iuWpPI7qpNOnGTbGcF4/SQnOAHhZtdNVLrMzTjpDKkAfYpUlpH5E9mfPUTUj+eV4VdBbt7lD7lk5v7id28LiRVR/uquL+TgctjNmYu0CJJE6g/PP0YraDreAWHtKhNUGH1Dv5oHJAiLQQ4rtrnbyOlo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709107672; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=kiQu0qcepvLNgNVO8+FT105hczx+1saht4JobhIZWJ8=; b=md7wysoCNcOWt5I+r1URxGODax63di85GLSGurTyfRsPi6kOxYx/BRnvUTUlpwH0cLi9I3+VWP1pbLrwuM1vkfKaXvezWpJiLre8WU8y7YKN+jbQZcw6onaFwhkPR33mo+kYioXHl2S9Fbd6TqUzCMKe2oyu4K56T28OhrnySHc= 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 1709107672286428.2881014038545; Wed, 28 Feb 2024 00:07:52 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rfEyZ-0001lI-QP; Wed, 28 Feb 2024 03:07:39 -0500 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 1rfEyY-0001jr-83 for qemu-devel@nongnu.org; Wed, 28 Feb 2024 03:07:38 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rfEyT-0000af-PV for qemu-devel@nongnu.org; Wed, 28 Feb 2024 03:07:37 -0500 Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-609-IHiRcwyLO6uLrqyLtbNwAQ-1; Wed, 28 Feb 2024 03:07:29 -0500 Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-a3e68c15996so240054866b.3 for ; Wed, 28 Feb 2024 00:07:29 -0800 (PST) Received: from [192.168.10.118] ([93.56.170.180]) by smtp.gmail.com with ESMTPSA id r8-20020a170906c28800b00a3d2d81daafsm1587934ejz.172.2024.02.28.00.07.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 00:07:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709107652; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kiQu0qcepvLNgNVO8+FT105hczx+1saht4JobhIZWJ8=; b=fpHLjKFQTNZgnZxdx2rBsldC476qzHWysu+MAl1DJpLaBVpO3GjYc0Nmy16VJ45a8tGYGN Y3EJHV8D2CPATGuT6iCQbt+h01HKp31pNROjIMAIPbxkCbKrfQ6vHMBEewLoeye+V14SHV bcmCknxb7vfWdgdP+WMlsfveNAasTbI= X-MC-Unique: IHiRcwyLO6uLrqyLtbNwAQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709107647; x=1709712447; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kiQu0qcepvLNgNVO8+FT105hczx+1saht4JobhIZWJ8=; b=DpJfe1nELfl4fHshmDVb2hza6ONc3yXrleMOfEXr+2iin2v8GhBzDi6+ODto88TWdE Zx9O6rbVoCZdzNITlv0ZkRXjf3MeXParmUcfhG6pEf3uXdUGhm2xl5ocOR5J7GqrY8DV U0kVO2BDC6qgmiskcNBUYKTejXCXLIye+nxXYxb2yEngXG8Jv2ji3WiuO72sCmM3bbuI IQum0KO/Viilg6kApXB89o4R4YSZlpP6mWj2XhTHFu7GNVezTuqphqHG0ykageYv8GHF JxUXysmoZENHkxP5KdVpEAuJYdSFBtU6qg8XbxgnKu5kN0Sxqf5hXgE51zK+r5v3tbFO ofJw== X-Gm-Message-State: AOJu0YzFS3dQ+shLLtg3bbAHdzZt3Sq54IKLARrHmePjO32UbkjBpeoh /Rf0YraJ9huhBMZGN/Z9wCYXc4+h4INSJCpBibZ9REqr5/VpAM0beunKm2YHNEv52r84dwXeGti CEN2s6YWpG5zl3qI3WAdIOiDBfOo+54H2eV57AVyIPf/DvKMwkyMrO8Ix18a6uFfL87ircoNyLL KaNPCcjrCRZNsb8ue/20tqc9/jB9aEwwyYOUPa X-Received: by 2002:a17:906:f882:b0:a43:d063:91cd with SMTP id lg2-20020a170906f88200b00a43d06391cdmr1550683ejb.13.1709107646838; Wed, 28 Feb 2024 00:07:26 -0800 (PST) X-Google-Smtp-Source: AGHT+IE3qxGJfHwmTkrlF8u8fFbwLd3qvHSn2U9eNt4Tw8vnohb8xpbW/HKm6Jx40hhWqCzvNntGWA== X-Received: by 2002:a17:906:f882:b0:a43:d063:91cd with SMTP id lg2-20020a170906f88200b00a43d06391cdmr1550674ejb.13.1709107646570; Wed, 28 Feb 2024 00:07:26 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PULL 10/10] ide, vl: turn -win2k-hack into a property on IDE devices Date: Wed, 28 Feb 2024 09:06:46 +0100 Message-ID: <20240228080646.261365-11-pbonzini@redhat.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240228080646.261365-1-pbonzini@redhat.com> References: <20240228080646.261365-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.088, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-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 @redhat.com) X-ZM-MESSAGEID: 1709107672505100001 Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Paolo Bonzini --- include/hw/ide/ide-dev.h | 2 ++ include/sysemu/sysemu.h | 1 - hw/ide/core.c | 3 ++- hw/ide/ide-dev.c | 1 + system/globals.c | 1 - system/vl.c | 2 +- qemu-options.hx | 3 ++- 7 files changed, 8 insertions(+), 5 deletions(-) diff --git a/include/hw/ide/ide-dev.h b/include/hw/ide/ide-dev.h index 708cc0fda34..9a0d71db4e1 100644 --- a/include/hw/ide/ide-dev.h +++ b/include/hw/ide/ide-dev.h @@ -65,6 +65,7 @@ struct IDEState { int drive_serial; char drive_serial_str[21]; char drive_model_str[41]; + bool win2k_install_hack; uint64_t wwn; /* ide regs */ uint8_t feature; @@ -163,6 +164,7 @@ struct IDEDevice { * 0xffff - reserved */ uint16_t rotation_rate; + bool win2k_install_hack; }; =20 typedef struct IDEDrive { diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h index 73a37949c24..eb1dc1e4eda 100644 --- a/include/sysemu/sysemu.h +++ b/include/sysemu/sysemu.h @@ -41,7 +41,6 @@ extern int graphic_height; extern int graphic_depth; extern int display_opengl; extern const char *keyboard_layout; -extern int win2k_install_hack; extern int graphic_rotate; extern int old_param; extern uint8_t *boot_splash_filedata; diff --git a/hw/ide/core.c b/hw/ide/core.c index 3c42d72ac25..3f8c0ede2a1 100644 --- a/hw/ide/core.c +++ b/hw/ide/core.c @@ -1059,7 +1059,7 @@ static void ide_sector_write_cb(void *opaque, int ret) ide_sector_write); } =20 - if (win2k_install_hack && ((++s->irq_count % 16) =3D=3D 0)) { + if (s->win2k_install_hack && ((++s->irq_count % 16) =3D=3D 0)) { /* It seems there is a bug in the Windows 2000 installer HDD IDE driver which fills the disk with empty logs when the IDE write IRQ comes too early. This hack tries to correct @@ -2597,6 +2597,7 @@ int ide_init_drive(IDEState *s, IDEDevice *dev, IDEDr= iveKind kind, Error **errp) s->drive_kind =3D kind; =20 blk_get_geometry(s->blk, &nb_sectors); + s->win2k_install_hack =3D dev->win2k_install_hack; s->cylinders =3D dev->conf.cyls; s->heads =3D s->drive_heads =3D dev->conf.heads; s->sectors =3D s->drive_sectors =3D dev->conf.secs; diff --git a/hw/ide/ide-dev.c b/hw/ide/ide-dev.c index 900f80faf19..99f2f1226cf 100644 --- a/hw/ide/ide-dev.c +++ b/hw/ide/ide-dev.c @@ -31,6 +31,7 @@ =20 static Property ide_props[] =3D { DEFINE_PROP_UINT32("unit", IDEDevice, unit, -1), + DEFINE_PROP_BOOL("win2k-install-hack", IDEDevice, win2k_install_hack, = false), DEFINE_PROP_END_OF_LIST(), }; =20 diff --git a/system/globals.c b/system/globals.c index 5d0046ba105..e3535842010 100644 --- a/system/globals.c +++ b/system/globals.c @@ -40,7 +40,6 @@ int autostart =3D 1; int vga_interface_type =3D VGA_NONE; bool vga_interface_created; Chardev *parallel_hds[MAX_PARALLEL_PORTS]; -int win2k_install_hack; int graphic_rotate; QEMUOptionRom option_rom[MAX_OPTION_ROMS]; int nb_option_roms; diff --git a/system/vl.c b/system/vl.c index 98bf0c386b4..e480afd7a00 100644 --- a/system/vl.c +++ b/system/vl.c @@ -3265,7 +3265,7 @@ void qemu_init(int argc, char **argv) pid_file =3D optarg; break; case QEMU_OPTION_win2k_hack: - win2k_install_hack =3D 1; + object_register_sugar_prop("ide-device", "win2k-install-ha= ck", "true", true); break; case QEMU_OPTION_acpitable: opts =3D qemu_opts_parse_noisily(qemu_find_opts("acpi"), diff --git a/qemu-options.hx b/qemu-options.hx index 1136642c21d..9a47385c157 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -2641,7 +2641,8 @@ SRST ``-win2k-hack`` Use it when installing Windows 2000 to avoid a disk full bug. After Windows 2000 is installed, you no longer need this option (this - option slows down the IDE transfers). + option slows down the IDE transfers). Synonym of ``-global + ide-device.win2k-install-hack=3Don``. ERST =20 DEF("no-fd-bootchk", 0, QEMU_OPTION_no_fd_bootchk, --=20 2.43.2