From patchwork Thu Jun 29 10:19:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1801446 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=hTSa4Spc; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QsDx44qZdz20ZV for ; Thu, 29 Jun 2023 20:20:40 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qEokK-0000Bf-7b; Thu, 29 Jun 2023 06:19:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qEokI-0000AC-DB for qemu-devel@nongnu.org; Thu, 29 Jun 2023 06:19:26 -0400 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 1qEokG-0005md-WD for qemu-devel@nongnu.org; Thu, 29 Jun 2023 06:19:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1688033964; 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=2c2zkm/eZJfTbSTlhRHnPmwWrHu8YrErxYEAgI8Iwts=; b=hTSa4SpcE2czCGVGqLnsUOH/VbcXfk3ffJUHYPs6KhEucqteBnQEwMLkHIxjwT2moNGvHF uTK6St35DNJj/qm/+IvKU2qe5LBuP+htVhpWpdKECCkqbVoEIN2LUn1kdwbe+XhhatXiMR QCGhc6WZDNJ32aI2UC/4coVX+rr3BoU= 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-97-p6YomXHOMQWy5foapAK7oA-1; Thu, 29 Jun 2023 06:19:23 -0400 X-MC-Unique: p6YomXHOMQWy5foapAK7oA-1 Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-9874fbf5c95so65372566b.1 for ; Thu, 29 Jun 2023 03:19:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688033961; x=1690625961; 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=2c2zkm/eZJfTbSTlhRHnPmwWrHu8YrErxYEAgI8Iwts=; b=A9ubyHnxngeVFdReQYa0TEhAVZ7JS2XnUSQoq+sMYAQI2c5KfQSK9e94Bnr3XXuBU8 qP8mFBrjKbxxsanF8nmLtgifkUodL6UtiLqkEh7lKNlfZ5+hIU6hv7debJzZ8NoIfUcW 6Dy+BPBsTyl8OR/tCyfq9ZxyT+xfH0JsrWS05JSMwVhO4XaWDRafe3/99bRtaO83+R5L FHYeN82GXPs36mgXGdcHmZZmtqAdy5mqkUOqcRhqLk23Fgam6rCe+b/wGaOWXcXYby0/ 3sEToRVDge3ybtHMByYrSMwfWccKJVY4qoJ21tVo/YsPIVWUlyEu13JI7N/RCMI+k7L0 xBhQ== X-Gm-Message-State: AC+VfDwB7X8uSBRla7NgmvCkGCCZmIH1zXQqUEUsTz75XS3/9K6Ckorp oKaXBACIj+hS5uwYjp7QkiNMN1b8bHOg/n0VhDdZCzkm2TgVg9I0RQlvuvGOQaBaIu5+ry+AdnV touZpFIXU7vuLsKbR6Yw0FQBTs9JBDqUmxA2Re5HCv6HYyoYooFKWaGzsxfxDxRsbgyAtqj/X4k o= X-Received: by 2002:a17:906:64d4:b0:992:4723:fc81 with SMTP id p20-20020a17090664d400b009924723fc81mr3064595ejn.17.1688033961760; Thu, 29 Jun 2023 03:19:21 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5xRgDrcmxiu7iQD6dnksXvUgQkYHzQuqLUHQx5kkIVfOAql90UEwyVgc8GEllUQN/MrvnfYQ== X-Received: by 2002:a17:906:64d4:b0:992:4723:fc81 with SMTP id p20-20020a17090664d400b009924723fc81mr3064582ejn.17.1688033961402; Thu, 29 Jun 2023 03:19:21 -0700 (PDT) Received: from [192.168.10.81] ([2001:b07:6468:f312:9af8:e5f5:7516:fa89]) by smtp.gmail.com with ESMTPSA id z15-20020a17090655cf00b00992099223a0sm3099122ejp.103.2023.06.29.03.19.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Jun 2023 03:19:20 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Nicholas Piggin , qemu-stable@nongnu.org Subject: [PULL 1/5] icount: don't adjust virtual time backwards after warp Date: Thu, 29 Jun 2023 12:19:14 +0200 Message-ID: <20230629101918.9800-2-pbonzini@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230629101918.9800-1-pbonzini@redhat.com> References: <20230629101918.9800-1-pbonzini@redhat.com> MIME-Version: 1.0 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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Nicholas Piggin The icount-based QEMU_CLOCK_VIRTUAL runs ahead of the RT clock at times. When warping, it is possible it is still ahead at the end of the warp, which causes icount adaptive mode to adjust it backward. This can result in the machine observing time going backwards. Prevent this by clamping adaptive adjustment to 0 at minimum. Signed-off-by: Nicholas Piggin Message-ID: <20230627061406.241847-1-npiggin@gmail.com> Cc: qemu-stable@nongnu.org Signed-off-by: Paolo Bonzini --- softmmu/icount.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/softmmu/icount.c b/softmmu/icount.c index 4504433e168..a5cef9c60a7 100644 --- a/softmmu/icount.c +++ b/softmmu/icount.c @@ -259,11 +259,16 @@ static void icount_warp_rt(void) warp_delta = clock - timers_state.vm_clock_warp_start; if (icount_enabled() == 2) { /* - * In adaptive mode, do not let QEMU_CLOCK_VIRTUAL run too - * far ahead of real time. + * In adaptive mode, do not let QEMU_CLOCK_VIRTUAL run too far + * ahead of real time (it might already be ahead so careful not + * to go backwards). */ int64_t cur_icount = icount_get_locked(); int64_t delta = clock - cur_icount; + + if (delta < 0) { + delta = 0; + } warp_delta = MIN(warp_delta, delta); } qatomic_set_i64(&timers_state.qemu_icount_bias, From patchwork Thu Jun 29 10:19:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1801443 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=ER7/xR/m; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QsDw54ZKYz20ZC for ; Thu, 29 Jun 2023 20:19:49 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qEokK-0000DM-Pp; Thu, 29 Jun 2023 06:19:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qEokJ-0000B6-PV for qemu-devel@nongnu.org; Thu, 29 Jun 2023 06:19:27 -0400 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 1qEokI-0005mq-DL for qemu-devel@nongnu.org; Thu, 29 Jun 2023 06:19:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1688033965; 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=r6eYcQOpdQGaBIAyIqv467VGeA30T2RXy/LIF4+Ra8w=; b=ER7/xR/mf2puunsjDW52w2zNnYRFcJLl3i6jd5I4ZYCld9wj189jM4hr0ls9uXlgvLSONu myNgNW9J+i9qZFpznFtVklDZVjXJdZvf664YFtITbGcRoB4l3syE8rGBK9Tm7isK9MOjVf JXwk08PjtfNrvWAAPA8A/SJ25Li/J98= 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-65-0d4rw4wPNsGrDO2Wllt1Kw-1; Thu, 29 Jun 2023 06:19:24 -0400 X-MC-Unique: 0d4rw4wPNsGrDO2Wllt1Kw-1 Received: by mail-ed1-f71.google.com with SMTP id 4fb4d7f45d1cf-51dd16f823bso402123a12.0 for ; Thu, 29 Jun 2023 03:19:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688033963; x=1690625963; 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=r6eYcQOpdQGaBIAyIqv467VGeA30T2RXy/LIF4+Ra8w=; b=lZuaB+25lK/t866g5ST3Tzd2VKqjZQghnD1LHfNczQYLF2Uwc/UsDiM+TWWBKOJzBR VjcpDbfYIGBO2WPRPEQGy1mEZRYksLRiZ7S3s0EwOeXmfJ3GRbPRL2ywTIGpqSXXXDgo R3YTLICIOhFDwuCK8X6ARkuyiiucb/wuor7dfgJq4gTsCJQdLk8EBJBxXEk370jbfGHH rhe/QFu9Hjin2PbtZkXGrLpa97h5jGMiycfQGLUNEI1x2f4VPL1Mr6kZwEcHFCQRxiQT vUC2fjoKzbsUMahux4aFjYaJXMS+QVy0T6Y8mril+1MUgDvzaStecKplTA2G+Y9c9fBX ybTA== X-Gm-Message-State: ABy/qLZxEeuwwQ2qIX5hQ/q2LNJthnS/tWho2Xc6gVgJQKzaS596QTAm QQMNix5+73tOCvz44CyfOQEhurKWtIjzUHlmIoycxljrccgUtjFxoJ/u3Szfo1Tnu/0klPnjrVT dbjvk9IAVPAtQHzB07klMaMQbvEakN8DQKUSIFojSf43fod6eo2xGU2L5l82X7iGrFnZC0POqoT U= X-Received: by 2002:aa7:d902:0:b0:51d:e3d2:f5eb with SMTP id a2-20020aa7d902000000b0051de3d2f5ebmr608571edr.5.1688033963283; Thu, 29 Jun 2023 03:19:23 -0700 (PDT) X-Google-Smtp-Source: APBJJlEpbzJFajmdv8EKasE/kuDoXoxLquFQeAuhy41XrQvfaPBYCb81wwrVi5bu+Eonhs+d1TV70A== X-Received: by 2002:aa7:d902:0:b0:51d:e3d2:f5eb with SMTP id a2-20020aa7d902000000b0051de3d2f5ebmr608558edr.5.1688033962856; Thu, 29 Jun 2023 03:19:22 -0700 (PDT) Received: from [192.168.10.81] ([2001:b07:6468:f312:9af8:e5f5:7516:fa89]) by smtp.gmail.com with ESMTPSA id r16-20020aa7da10000000b0051d2968b26asm5668333eds.77.2023.06.29.03.19.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Jun 2023 03:19:22 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Pawan Gupta Subject: [PULL 2/5] target/i386: Export MSR_ARCH_CAPABILITIES bits to guests Date: Thu, 29 Jun 2023 12:19:15 +0200 Message-ID: <20230629101918.9800-3-pbonzini@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230629101918.9800-1-pbonzini@redhat.com> References: <20230629101918.9800-1-pbonzini@redhat.com> MIME-Version: 1.0 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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Pawan Gupta On Intel CPUs there are certain bits in MSR_ARCH_CAPABILITIES that indicates if the CPU is not affected by a vulnerability. Without these bits guests may try to deploy the mitigation even if the CPU is not affected. Export the bits to guests that indicate immunity to hardware vulnerabilities. Signed-off-by: Pawan Gupta Message-ID: <63d85cc76d4cdc51e6c732478b81d8f13be11e5a.1687551881.git.pawan.kumar.gupta@linux.intel.com> Signed-off-by: Paolo Bonzini --- target/i386/cpu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index c0fb6b3ad92..b96a609d966 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -1060,10 +1060,10 @@ FeatureWordInfo feature_word_info[FEATURE_WORDS] = { "rdctl-no", "ibrs-all", "rsba", "skip-l1dfl-vmentry", "ssb-no", "mds-no", "pschange-mc-no", "tsx-ctrl", "taa-no", NULL, NULL, NULL, - NULL, NULL, NULL, NULL, + NULL, "sbdr-ssdp-no", "fbsdp-no", "psdp-no", NULL, "fb-clear", NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, + "pbrsb-no", NULL, NULL, NULL, NULL, NULL, NULL, NULL, }, .msr = { From patchwork Thu Jun 29 10:19:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1801448 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=YM5Pnkqf; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QsDxF5RRGz20XS for ; Thu, 29 Jun 2023 20:20:49 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qEokN-0000Ey-GK; Thu, 29 Jun 2023 06:19:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qEokL-0000EH-Qj for qemu-devel@nongnu.org; Thu, 29 Jun 2023 06:19:29 -0400 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 1qEokK-0005nW-Em for qemu-devel@nongnu.org; Thu, 29 Jun 2023 06:19:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1688033967; 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=uFRGHGkRnK6rZN55uj4I58WBJn1QFObQ0AJ+4MVDMs0=; b=YM5PnkqfbfCW/uo9B8gPljA+E50UyulEjnjPJarNWkFSxL3Kpl8csWVSVjgrV0vDjLwQ6h W0i2xzZ/lDCsupKA6/VwnYRBvVcvCKFb32XxdgZOf4EK42K9lw2l+84ZapWZff35sZjpAy bnuXtNrLvWC8WkWGe0xn59sagaLPqys= 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-592--I2YZhJPOwGp76Na9WWAsQ-1; Thu, 29 Jun 2023 06:19:26 -0400 X-MC-Unique: -I2YZhJPOwGp76Na9WWAsQ-1 Received: by mail-ej1-f70.google.com with SMTP id a640c23a62f3a-97542592eb9so36325966b.2 for ; Thu, 29 Jun 2023 03:19:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688033965; x=1690625965; 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=uFRGHGkRnK6rZN55uj4I58WBJn1QFObQ0AJ+4MVDMs0=; b=h1s8xG6PG8MLHKXubq18ByGvLvTDASSzkg9BLTVOJonCMDERThugDcEavufotpyqy5 yifLrMUwEUs+NKa8Sdsg/fJvSwD/qHWWOyUc9l2h+4MM5E4ApxGxc+nNptaxL3gfZCVq ayU2Z0a3jyL7P8ZebAWfQgPix7jS2owTAVrstq33sIO62L6BYINN/VJgyi0lCVNXfCgH UJ9OnWhkBud5jkFFGGmeVsIcuo6Gzk+BO8p4OGN6osbMFKSbK+NmaTI8ewQGlslG0XqA dUaCzdkigfnEe/1VTovK7g8u7HgDdCWajpb0ur5FldsWpHNjVjFETAYNSaCAElxlwc/x XA/Q== X-Gm-Message-State: AC+VfDxKjAIP12Es7NnII5fAzFD+XQ2Rw3aflw5vXM9D7ZS0awSYj2q0 9uuvpvSQttAoITx8poccrxyFGI+P17+uOyjytj72jd8oD75G8Ey2PSh1PDRBwfo525Nd0XIIf+V I5Y5NcHosXj6iYKH76pBNxIP5tOPaFmXhJKxgyUYSGOFLxXugEHsOM976fKfJ1IO2RYkRCb85bT 4= X-Received: by 2002:aa7:ce01:0:b0:51a:5d43:ab8b with SMTP id d1-20020aa7ce01000000b0051a5d43ab8bmr21392590edv.33.1688033964828; Thu, 29 Jun 2023 03:19:24 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ57DsRcEHBw92nDzNR+lhSrOL9SjWRYHuuY1Vm3kPEMLv+D6uwZFfzAu29NWwg0hFfx6QTKKQ== X-Received: by 2002:aa7:ce01:0:b0:51a:5d43:ab8b with SMTP id d1-20020aa7ce01000000b0051a5d43ab8bmr21392571edv.33.1688033964320; Thu, 29 Jun 2023 03:19:24 -0700 (PDT) Received: from [192.168.10.81] ([2001:b07:6468:f312:9af8:e5f5:7516:fa89]) by smtp.gmail.com with ESMTPSA id r16-20020aa7da10000000b0051d2968b26asm5668357eds.77.2023.06.29.03.19.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Jun 2023 03:19:23 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 3/5] target/i386: ignore ARCH_CAPABILITIES features in user mode emulation Date: Thu, 29 Jun 2023 12:19:16 +0200 Message-ID: <20230629101918.9800-4-pbonzini@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230629101918.9800-1-pbonzini@redhat.com> References: <20230629101918.9800-1-pbonzini@redhat.com> MIME-Version: 1.0 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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org ARCH_CAPABILITIES is only accessible through a read-only MSR, so it has no impact on any user-mode operation (user-mode cannot read the MSR). So do not bother printing warnings about it in user mode emulation. Signed-off-by: Paolo Bonzini --- target/i386/cpu.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index b96a609d966..328779874f2 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -1069,6 +1069,13 @@ FeatureWordInfo feature_word_info[FEATURE_WORDS] = { .msr = { .index = MSR_IA32_ARCH_CAPABILITIES, }, + /* + * FEAT_ARCH_CAPABILITIES only affects a read-only MSR, which + * cannot be read from user mode. Therefore, it has no impact + > on any user-mode operation, and warnings about unsupported + * features do not matter. + */ + .tcg_features = ~0U, }, [FEAT_CORE_CAPABILITY] = { .type = MSR_FEATURE_WORD, From patchwork Thu Jun 29 10:19:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1801445 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=JM62kroF; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QsDw92xv5z20ZC for ; Thu, 29 Jun 2023 20:19:53 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qEokP-0000Fc-3l; Thu, 29 Jun 2023 06:19:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qEokN-0000F2-HL for qemu-devel@nongnu.org; Thu, 29 Jun 2023 06:19:31 -0400 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 1qEokL-0005nk-MQ for qemu-devel@nongnu.org; Thu, 29 Jun 2023 06:19:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1688033969; 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=W+5l3uQ4w1rclU3bnl8FcUEU2dexkvR8ceW6D8ETkRk=; b=JM62kroFeqa4lVJfj5rdMAuyaERtA9XUTCvGip5BQtBVn8UDYFpRW3J+2FfpkvAZIM2JCx bxDw8LhI7fA1rjmScDfSOYJ7sNKjWqZCxbk7WLxQe5mIf7Mi1D1gLBuo6TlTFCAjdk1XOt vIj9JR/Fq9YrrZ0nRiLVtzg5WEdywDU= 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-600-kDdWY_GmOBarK0ElIva4yg-1; Thu, 29 Jun 2023 06:19:27 -0400 X-MC-Unique: kDdWY_GmOBarK0ElIva4yg-1 Received: by mail-ed1-f69.google.com with SMTP id 4fb4d7f45d1cf-51da39aa6dcso401268a12.2 for ; Thu, 29 Jun 2023 03:19:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688033966; x=1690625966; 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=W+5l3uQ4w1rclU3bnl8FcUEU2dexkvR8ceW6D8ETkRk=; b=QgrBvGiA0d4yUdCajlgijzPwlORxz8/SiFk3CMyt6TKth0Zz1Xar1ZHIiMssFU+vfA jjYEhfzDRidQnXEYMQRcKVDC2jLgD37zVmAtXh2/0f0wKLDH5vDh4OGdjFB6EQRFUAB+ 1r++Mui80jmcvNpQ59ntnpqyclE+0oJooNG/dpP2k9BgSCVfyMsbFK707AOr9YISW0fl H4zhlfY6Tn9AOEBehESlo3vMeLwRc8wRx2qBhkqTK3WkgupY7uDXe2moJ4OP+L+HpNKb t7IKOsQMIVnsWvf1Kip2xRVY4dpumgye9d9HmXDofBSqzeKV+zoB8iyCe57Ma4VTfVMV fpog== X-Gm-Message-State: AC+VfDwZKsmOH4fRqjTa8I7RQLOBpAhNM/CgnZOo2RP6WaBOYIQfofkb zctm1rRfjCkQEtfswHPUmbCsWO2sexZLkMuwtkw8at1uF0H7JuQ6ETmn60jDchXQ9wUMnjGP/+p Gmv3E50pIAsdUyxM02siqyuGy95wq4YfTWyqIGdgu9MVwlG82Sv5IVrZGlmjKNz9VNdjD/RaZhm 4= X-Received: by 2002:a17:907:968d:b0:992:9756:6a22 with SMTP id hd13-20020a170907968d00b0099297566a22mr3108905ejc.48.1688033966071; Thu, 29 Jun 2023 03:19:26 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ74sy10mhIcE/UAauAWObu6IzRwWQxVZ5AEaWCG/oQftBFTsUaWTVLyuOKlWSbeLZIk2C+hVg== X-Received: by 2002:a17:907:968d:b0:992:9756:6a22 with SMTP id hd13-20020a170907968d00b0099297566a22mr3108885ejc.48.1688033965708; Thu, 29 Jun 2023 03:19:25 -0700 (PDT) Received: from [192.168.10.81] ([2001:b07:6468:f312:9af8:e5f5:7516:fa89]) by smtp.gmail.com with ESMTPSA id qp7-20020a170907206700b009890ab4efa9sm6613616ejb.32.2023.06.29.03.19.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Jun 2023 03:19:25 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 4/5] target/i386: ignore CPL0-specific features in user mode emulation Date: Thu, 29 Jun 2023 12:19:17 +0200 Message-ID: <20230629101918.9800-5-pbonzini@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230629101918.9800-1-pbonzini@redhat.com> References: <20230629101918.9800-1-pbonzini@redhat.com> MIME-Version: 1.0 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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01, UPPERCASE_50_75=0.008 autolearn=no 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Features such as PCID are only accessible through privileged operations, and therefore have no impact on any user-mode operation. Allow reporting them to programs running under user mode emulation, so that "-cpu" can be used with more named CPU models. XSAVES would be similar, but it doesn't make sense to provide it until XSAVEC is implemented. With this change, all CPUs up to Broadwell-v4 can be emulate. Skylake-Client requires XSAVEC, while EPYC also requires SHA-NI, MISALIGNSSE and TOPOEXT. MISALIGNSSE is not hard to implement, but I am not sure it is worth using a precious hflags bit for it. Fixes: https://gitlab.com/qemu-project/qemu/-/issues/1534 Signed-off-by: Paolo Bonzini --- target/i386/cpu.c | 83 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 76 insertions(+), 7 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 328779874f2..a3ddd1b6137 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -623,13 +623,25 @@ void x86_cpu_vendor_words2str(char *dst, uint32_t vendor1, CPUID_MTRR, CPUID_MCA, CPUID_CLFLUSH (needed for Win64) */ /* missing: CPUID_VME, CPUID_DTS, CPUID_SS, CPUID_HT, CPUID_TM, CPUID_PBE */ + +/* + * Kernel-only features that can be shown to usermode programs even if + * they aren't actually supported by TCG, because qemu-user only runs + * in CPL=3; remove them if they are ever implemented for system emulation. + */ +#if defined CONFIG_USER_ONLY +#define CPUID_EXT_KERNEL_FEATURES (CPUID_EXT_PCID | CPUID_EXT_TSC_DEADLINE_TIMER | \ + CPUID_EXT_X2APIC) +#else +#define CPUID_EXT_KERNEL_FEATURES 0 +#endif #define TCG_EXT_FEATURES (CPUID_EXT_SSE3 | CPUID_EXT_PCLMULQDQ | \ CPUID_EXT_MONITOR | CPUID_EXT_SSSE3 | CPUID_EXT_CX16 | \ CPUID_EXT_SSE41 | CPUID_EXT_SSE42 | CPUID_EXT_POPCNT | \ CPUID_EXT_XSAVE | /* CPUID_EXT_OSXSAVE is dynamic */ \ CPUID_EXT_MOVBE | CPUID_EXT_AES | CPUID_EXT_HYPERVISOR | \ CPUID_EXT_RDRAND | CPUID_EXT_AVX | CPUID_EXT_F16C | \ - CPUID_EXT_FMA) + CPUID_EXT_FMA | CPUID_EXT_KERNEL_FEATURES) /* missing: CPUID_EXT_DTES64, CPUID_EXT_DSCPL, CPUID_EXT_VMX, CPUID_EXT_SMX, CPUID_EXT_EST, CPUID_EXT_TM2, CPUID_EXT_CID, @@ -642,22 +654,63 @@ void x86_cpu_vendor_words2str(char *dst, uint32_t vendor1, #define TCG_EXT2_X86_64_FEATURES 0 #endif +/* + * CPUID_*_KERNEL_FEATURES denotes bits and features that are not usable + * in usermode or by 32-bit programs. Those are added to supported + * TCG features unconditionally in user-mode emulation mode. This may + * indeed seem strange or incorrect, but it works because code running + * under usermode emulation cannot access them. + * + * Even for long mode, qemu-i386 is not running "a userspace program on a + * 32-bit CPU"; it's running "a userspace program with a 32-bit code segment" + * and therefore using the 32-bit ABI; the CPU itself might be 64-bit + * but again the difference is only visible in kernel mode. + */ +#if defined CONFIG_USER_ONLY +#define CPUID_EXT2_KERNEL_FEATURES CPUID_EXT2_FFXSR +#else +#define CPUID_EXT2_KERNEL_FEATURES 0 +#endif + #define TCG_EXT2_FEATURES ((TCG_FEATURES & CPUID_EXT2_AMD_ALIASES) | \ CPUID_EXT2_NX | CPUID_EXT2_MMXEXT | CPUID_EXT2_RDTSCP | \ CPUID_EXT2_3DNOW | CPUID_EXT2_3DNOWEXT | CPUID_EXT2_PDPE1GB | \ - CPUID_EXT2_SYSCALL | TCG_EXT2_X86_64_FEATURES) + CPUID_EXT2_SYSCALL | TCG_EXT2_X86_64_FEATURES | \ + CPUID_EXT2_KERNEL_FEATURES) + +#if defined CONFIG_USER_ONLY +#define CPUID_EXT3_KERNEL_FEATURES CPUID_EXT3_OSVW +#else +#define CPUID_EXT3_KERNEL_FEATURES 0 +#endif + #define TCG_EXT3_FEATURES (CPUID_EXT3_LAHF_LM | CPUID_EXT3_SVM | \ CPUID_EXT3_CR8LEG | CPUID_EXT3_ABM | CPUID_EXT3_SSE4A | \ - CPUID_EXT3_3DNOWPREFETCH) + CPUID_EXT3_3DNOWPREFETCH | CPUID_EXT3_KERNEL_FEATURES) + #define TCG_EXT4_FEATURES 0 + +#if defined CONFIG_USER_ONLY +#define CPUID_SVM_KERNEL_FEATURES (CPUID_SVM_NRIPSAVE | CPUID_SVM_VNMI) +#else +#define CPUID_SVM_KERNEL_FEATURES 0 +#endif #define TCG_SVM_FEATURES (CPUID_SVM_NPT | CPUID_SVM_VGIF | \ - CPUID_SVM_SVME_ADDR_CHK) + CPUID_SVM_SVME_ADDR_CHK | CPUID_SVM_KERNEL_FEATURES) + #define TCG_KVM_FEATURES 0 + +#if defined CONFIG_USER_ONLY +#define CPUID_7_0_EBX_KERNEL_FEATURES CPUID_7_0_EBX_INVPCID +#else +#define CPUID_7_0_EBX_KERNEL_FEATURES 0 +#endif #define TCG_7_0_EBX_FEATURES (CPUID_7_0_EBX_SMEP | CPUID_7_0_EBX_SMAP | \ CPUID_7_0_EBX_BMI1 | CPUID_7_0_EBX_BMI2 | CPUID_7_0_EBX_ADX | \ CPUID_7_0_EBX_PCOMMIT | CPUID_7_0_EBX_CLFLUSHOPT | \ CPUID_7_0_EBX_CLWB | CPUID_7_0_EBX_MPX | CPUID_7_0_EBX_FSGSBASE | \ - CPUID_7_0_EBX_ERMS | CPUID_7_0_EBX_AVX2 | CPUID_7_0_EBX_RDSEED) + CPUID_7_0_EBX_ERMS | CPUID_7_0_EBX_AVX2 | CPUID_7_0_EBX_RDSEED | \ + CPUID_7_0_EBX_KERNEL_FEATURES) /* missing: CPUID_7_0_EBX_HLE CPUID_7_0_EBX_INVPCID, CPUID_7_0_EBX_RTM */ @@ -672,7 +725,14 @@ void x86_cpu_vendor_words2str(char *dst, uint32_t vendor1, CPUID_7_0_ECX_LA57 | CPUID_7_0_ECX_PKS | CPUID_7_0_ECX_VAES | \ TCG_7_0_ECX_RDPID) -#define TCG_7_0_EDX_FEATURES CPUID_7_0_EDX_FSRM +#if defined CONFIG_USER_ONLY +#define CPUID_7_0_EDX_KERNEL_FEATURES (CPUID_7_0_EDX_SPEC_CTRL | \ + CPUID_7_0_EDX_ARCH_CAPABILITIES | CPUID_7_0_EDX_SPEC_CTRL_SSBD) +#else +#define CPUID_7_0_EDX_KERNEL_FEATURES 0 +#endif +#define TCG_7_0_EDX_FEATURES (CPUID_7_0_EDX_FSRM | CPUID_7_0_EDX_KERNEL_FEATURES) + #define TCG_7_1_EAX_FEATURES (CPUID_7_1_EAX_FZRM | CPUID_7_1_EAX_FSRS | \ CPUID_7_1_EAX_FSRC) #define TCG_7_1_EDX_FEATURES 0 @@ -686,8 +746,17 @@ void x86_cpu_vendor_words2str(char *dst, uint32_t vendor1, #define TCG_SGX_12_0_EBX_FEATURES 0 #define TCG_SGX_12_1_EAX_FEATURES 0 +#if defined CONFIG_USER_ONLY +#define CPUID_8000_0008_EBX_KERNEL_FEATURES (CPUID_8000_0008_EBX_IBPB | \ + CPUID_8000_0008_EBX_IBRS | CPUID_8000_0008_EBX_STIBP | \ + CPUID_8000_0008_EBX_STIBP_ALWAYS_ON | CPUID_8000_0008_EBX_AMD_SSBD | \ + CPUID_8000_0008_EBX_AMD_PSFD) +#else +#define CPUID_8000_0008_EBX_KERNEL_FEATURES 0 +#endif + #define TCG_8000_0008_EBX (CPUID_8000_0008_EBX_XSAVEERPTR | \ - CPUID_8000_0008_EBX_WBNOINVD) + CPUID_8000_0008_EBX_WBNOINVD | CPUID_8000_0008_EBX_KERNEL_FEATURES) FeatureWordInfo feature_word_info[FEATURE_WORDS] = { [FEAT_1_EDX] = { From patchwork Thu Jun 29 10:19:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1801447 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=QEdmVDsD; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QsDx44k5cz20XS for ; Thu, 29 Jun 2023 20:20:40 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qEokQ-0000GR-So; Thu, 29 Jun 2023 06:19:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qEokO-0000Fa-Ux for qemu-devel@nongnu.org; Thu, 29 Jun 2023 06:19:32 -0400 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 1qEokN-0005nu-25 for qemu-devel@nongnu.org; Thu, 29 Jun 2023 06:19:32 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1688033970; 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=P/BPeDEyjtsQ6hPWSKw4UFehpwhBRKieWZPk05sxyLI=; b=QEdmVDsDpMOSU5DneI1+6MYFRSbH5hTKKGmOx6SXkRz0sjbNp+0eJ39URnrHW5UWyYY33q 99DiBrS64lWQxlYVhfNgNpaboGTbgAMa9BH3yj9UgCiQL//G30G7pN9JkfKOuC3GDPvyHL c5obF/9R78ZiNlAyskDqefmcAPyjuTQ= 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-275-Bboj_4itOKiousCtBEn9aQ-1; Thu, 29 Jun 2023 06:19:28 -0400 X-MC-Unique: Bboj_4itOKiousCtBEn9aQ-1 Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-9879d2fc970so46661866b.0 for ; Thu, 29 Jun 2023 03:19:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688033967; x=1690625967; 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=P/BPeDEyjtsQ6hPWSKw4UFehpwhBRKieWZPk05sxyLI=; b=V/mJSezTQeN2TkhQFFDFBVTBgdsL+cmnPP5o1B2+6XlzBSh11gkRx3FNAFWA1N6f/E 9ki5IQXE7ju+uBSYx4cmKE9BYlfzCaVR7ubjwOnDZ6IPrzcymiOWj+nG/cQ2GxiZ3+4D Icb6oPU+znjQdCAsDYxHYPS6py8yJOCB6CmPGGH+Yhcy0rZAjXo9rTpzQQ1lBAmCsc/d mhRag/B1oVjiqcki8azMI90LQiLDaQT7qo1Gs7dJtijL0FI0I66dls8PYwyVCix3sSxZ 9ftmCqRqYUm0fcqDPCzNVpG0i6UAbY+GLKxGz2XN9RTNYsTjoVXEcUXkOI6YmpHcMKuR VsZw== X-Gm-Message-State: AC+VfDwkCCZaddjinscIr9JJqvv8jj0mGFn8J9Os1xpoYJFCh6yTz+6V 5kzXnvl0liMlrRDeRFgTu7kl/ibx8zplcA8yyCdioaJVSV3PTSZoDWxqVmzmvV12AWcY/8KTcOy TPzPXh899TlhiP3w/NPX+iGxPoKePRDlL7uwfPJDRGodyUoIusuBwLhnUMpy4nPv2HOPrxOuEdj g= X-Received: by 2002:a17:906:411b:b0:992:5135:4109 with SMTP id j27-20020a170906411b00b0099251354109mr3823933ejk.28.1688033967449; Thu, 29 Jun 2023 03:19:27 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7UayXAlENu0UvUmaVp5fuWVqH2V69w6D4friirODGHt2JteCUKresv9etMGN3DsoBGWNOCSw== X-Received: by 2002:a17:906:411b:b0:992:5135:4109 with SMTP id j27-20020a170906411b00b0099251354109mr3823920ejk.28.1688033967013; Thu, 29 Jun 2023 03:19:27 -0700 (PDT) Received: from [192.168.10.81] ([2001:b07:6468:f312:9af8:e5f5:7516:fa89]) by smtp.gmail.com with ESMTPSA id gv18-20020a170906f11200b0098e0a937a6asm6127776ejb.69.2023.06.29.03.19.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Jun 2023 03:19:26 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 5/5] target/i386: emulate 64-bit ring 0 for linux-user if LM feature is set Date: Thu, 29 Jun 2023 12:19:18 +0200 Message-ID: <20230629101918.9800-6-pbonzini@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230629101918.9800-1-pbonzini@redhat.com> References: <20230629101918.9800-1-pbonzini@redhat.com> MIME-Version: 1.0 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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 32-bit binaries can run on a long mode processor even if the kernel is 64-bit, of course, and this can have slightly different behavior; for example, SYSCALL is allowed on Intel processors. Allow reporting LM to programs running under user mode emulation, so that "-cpu" can be used with named CPU models even for qemu-i386 and even without disabling LM by hand. Fortunately, most of the runtime code in QEMU has to depend on HF_LMA_MASK or on HF_CS64_MASK (which is anyway false for qemu-i386's 32-bit code segment) rather than TARGET_X86_64, therefore all that is needed is an update of linux-user's ring 0 setup. Fixes: https://gitlab.com/qemu-project/qemu/-/issues/1534 Signed-off-by: Paolo Bonzini --- linux-user/i386/cpu_loop.c | 57 ++++++++++++++++++------------------- target/i386/cpu.c | 15 ++++++++-- target/i386/tcg/translate.c | 6 ++-- 3 files changed, 44 insertions(+), 34 deletions(-) diff --git a/linux-user/i386/cpu_loop.c b/linux-user/i386/cpu_loop.c index 9eeda551eaf..ef2dcb3d767 100644 --- a/linux-user/i386/cpu_loop.c +++ b/linux-user/i386/cpu_loop.c @@ -47,7 +47,7 @@ static void write_dt(void *ptr, unsigned long addr, unsigned long limit, } static uint64_t *idt_table; -#ifdef TARGET_X86_64 + static void set_gate64(void *ptr, unsigned int type, unsigned int dpl, uint64_t addr, unsigned int sel) { @@ -60,8 +60,10 @@ static void set_gate64(void *ptr, unsigned int type, unsigned int dpl, p[2] = tswap32(addr >> 32); p[3] = 0; } + +#ifdef TARGET_X86_64 /* only dpl matters as we do only user space emulation */ -static void set_idt(int n, unsigned int dpl) +static void set_idt(int n, unsigned int dpl, bool is64) { set_gate64(idt_table + n * 2, 0, dpl, 0, 0); } @@ -78,9 +80,13 @@ static void set_gate(void *ptr, unsigned int type, unsigned int dpl, } /* only dpl matters as we do only user space emulation */ -static void set_idt(int n, unsigned int dpl) +static void set_idt(int n, unsigned int dpl, bool is64) { - set_gate(idt_table + n, 0, dpl, 0, 0); + if (is64) { + set_gate64(idt_table + n * 2, 0, dpl, 0, 0); + } else { + set_gate(idt_table + n, 0, dpl, 0, 0); + } } #endif @@ -325,6 +331,9 @@ static void target_cpu_free(void *obj) void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs) { CPUState *cpu = env_cpu(env); + bool is64 = (env->features[FEAT_8000_0001_EDX] & CPUID_EXT2_LM) != 0; + int i; + OBJECT(cpu)->free = target_cpu_free; env->cr[0] = CR0_PG_MASK | CR0_WP_MASK | CR0_PE_MASK; env->hflags |= HF_PE_MASK | HF_CPL_MASK; @@ -332,15 +341,18 @@ void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs) env->cr[4] |= CR4_OSFXSR_MASK; env->hflags |= HF_OSFXSR_MASK; } -#ifndef TARGET_ABI32 + /* enable 64 bit mode if possible */ - if (!(env->features[FEAT_8000_0001_EDX] & CPUID_EXT2_LM)) { + if (is64) { + env->cr[4] |= CR4_PAE_MASK; + env->efer |= MSR_EFER_LMA | MSR_EFER_LME; + env->hflags |= HF_LMA_MASK; + } +#ifndef TARGET_ABI32 + else { fprintf(stderr, "The selected x86 CPU does not support 64 bit mode\n"); exit(EXIT_FAILURE); } - env->cr[4] |= CR4_PAE_MASK; - env->efer |= MSR_EFER_LMA | MSR_EFER_LME; - env->hflags |= HF_LMA_MASK; #endif /* flags setup : we activate the IRQs by default as in user mode */ @@ -379,27 +391,12 @@ void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs) PROT_READ|PROT_WRITE, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); idt_table = g2h_untagged(env->idt.base); - set_idt(0, 0); - set_idt(1, 0); - set_idt(2, 0); - set_idt(3, 3); - set_idt(4, 3); - set_idt(5, 0); - set_idt(6, 0); - set_idt(7, 0); - set_idt(8, 0); - set_idt(9, 0); - set_idt(10, 0); - set_idt(11, 0); - set_idt(12, 0); - set_idt(13, 0); - set_idt(14, 0); - set_idt(15, 0); - set_idt(16, 0); - set_idt(17, 0); - set_idt(18, 0); - set_idt(19, 0); - set_idt(0x80, 3); + for (i = 0; i < 20; i++) { + set_idt(i, 0, is64); + } + set_idt(3, 3, is64); + set_idt(4, 3, is64); + set_idt(0x80, 3, is64); /* linux segment setup */ { diff --git a/target/i386/cpu.c b/target/i386/cpu.c index a3ddd1b6137..b5688cabb4f 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -666,7 +666,10 @@ void x86_cpu_vendor_words2str(char *dst, uint32_t vendor1, * and therefore using the 32-bit ABI; the CPU itself might be 64-bit * but again the difference is only visible in kernel mode. */ -#if defined CONFIG_USER_ONLY +#if defined CONFIG_LINUX_USER +#define CPUID_EXT2_KERNEL_FEATURES (CPUID_EXT2_LM | CPUID_EXT2_FFXSR) +#elif defined CONFIG_USER_ONLY +/* FIXME: Long mode not yet supported for i386 bsd-user */ #define CPUID_EXT2_KERNEL_FEATURES CPUID_EXT2_FFXSR #else #define CPUID_EXT2_KERNEL_FEATURES 0 @@ -5539,7 +5542,15 @@ uint64_t x86_cpu_get_supported_feature_word(FeatureWord w, } #ifndef TARGET_X86_64 if (w == FEAT_8000_0001_EDX) { - r &= ~CPUID_EXT2_LM; + /* + * 32-bit TCG can emulate 64-bit compatibility mode. If there is no + * way for userspace to get out of its 32-bit jail, we can leave + * the LM bit set. + */ + uint32_t unavail = tcg_enabled() + ? CPUID_EXT2_LM & ~CPUID_EXT2_KERNEL_FEATURES + : CPUID_EXT2_LM; + r &= ~unavail; } #endif if (migratable_only) { diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c index 28cb3fb7f4b..90c7b32f362 100644 --- a/target/i386/tcg/translate.c +++ b/target/i386/tcg/translate.c @@ -173,12 +173,14 @@ typedef struct DisasContext { #endif #if !defined(TARGET_X86_64) #define CODE64(S) false -#define LMA(S) false #elif defined(CONFIG_USER_ONLY) #define CODE64(S) true -#define LMA(S) true #else #define CODE64(S) (((S)->flags & HF_CS64_MASK) != 0) +#endif +#if defined(CONFIG_SOFTMMU) && !defined(TARGET_X86_64) +#define LMA(S) false +#else #define LMA(S) (((S)->flags & HF_LMA_MASK) != 0) #endif